OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [linux-2.6/] [linux-2.6.24/] [arch/] [or32/] [kernel/] [traps.c] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 xianfeng
/*
2
 *  linux/arch/or32/kernel/traps.c
3
 *
4
 *  or32 version
5
 *    author(s): Matjaz Breskvar (phoenix@bsemi.com)
6
 *
7
 *  derived from cris, i386, m68k, ppc, sh ports.
8
 *
9
 *  changes:
10
 *  18. 11. 2003: Matjaz Breskvar (phoenix@bsemi.com)
11
 *    initial port to or32 architecture
12
 *
13
 *  based on: linux/arch/cris/kernel/traps.c
14
 *  Copyright (C) 2000,2001 Axis Communications AB
15
 *
16
 *  Authors:   Bjorn Wesen
17
 *             Hans-Peter Nilsson
18
 *
19
 *  Here we handle the break vectors not used by the system call
20
 *  mechanism, as well as some general stack/register dumping
21
 *  things.
22
 *
23
 */
24
 
25
 
26
#include <linux/init.h>
27
#include <linux/sched.h>
28
#include <linux/kernel.h>
29
#include <linux/module.h>
30
#include <linux/kmod.h>
31
#include <linux/string.h>
32
#include <linux/errno.h>
33
#include <linux/ptrace.h>
34
#include <linux/timer.h>
35
#include <linux/mm.h>
36
#include <linux/kallsyms.h>
37
#include <asm/uaccess.h>
38
 
39
#include <asm/system.h>
40
#include <asm/segment.h>
41
#include <asm/io.h>
42
#include <asm/pgtable.h>
43
 
44
/* __PHX__ asm/hw_irq.h missing */
45
// #include <linux/irq.h>
46
 
47
extern char _etext, _stext;
48
 
49
int kstack_depth_to_print = 0x180;
50
 
51
static inline int valid_stack_ptr(struct thread_info *tinfo, void *p)
52
{
53
        return  p > (void *)tinfo &&
54
                p < (void *)tinfo + THREAD_SIZE - 3;
55
}
56
 
57
void show_trace(struct task_struct *task, unsigned long * stack)
58
{
59
        struct thread_info *context;
60
        unsigned long addr;
61
 
62
 
63
        context = (struct thread_info *)
64
                ((unsigned long)stack & (~(THREAD_SIZE - 1)));
65
 
66
        while (valid_stack_ptr(context, stack)) {
67
                addr = *stack++;
68
                if (__kernel_text_address(addr)) {
69
                        printk(" [<%08lx>]", addr);
70
                        print_symbol(" %s", addr);
71
                        printk("\n");
72
                }
73
        }
74
        printk(" =======================\n");
75
}
76
 
77
/* displays a short stack trace */
78
void show_stack(struct task_struct *task, unsigned long *esp)
79
{
80
        unsigned long addr, *stack;
81
        int i;
82
 
83
        // debugging aid: "show_stack(NULL);" prints the
84
        // back trace for this cpu.
85
 
86
        if(esp==NULL)
87
                esp=(unsigned long*)&esp;
88
 
89
        stack = esp;
90
 
91
        printk("Stack dump [0x%08lx]:\n", (unsigned long)esp);
92
        for(i = 0; i < kstack_depth_to_print; i++) {
93
                if (kstack_end(stack))
94
                        break;
95
                if (__get_user (addr, stack)) {
96
                        /* This message matches "failing address" marked
97
                           s390 in ksymoops, so lines containing it will
98
                           not be filtered out by ksymoops.  */
99
                        printk ("Failing address 0x%lx\n", (unsigned long)stack);
100
                        break;
101
                }
102
                stack++;
103
 
104
                printk("sp + %02d: 0x%08lx\n", i*4, addr);
105
        }
106
        printk("\n");
107
 
108
        show_trace(task, esp);
109
 
110
        return;
111
}
112
 
113
void show_trace_task(struct task_struct *tsk)
114
{
115
        /*
116
         * __PHX__: TODO: SysRq-T trace dump...
117
         */
118
}
119
 
120
/*
121
 * The architecture-independent backtrace generator
122
 */
123
void dump_stack(void)
124
{
125
        unsigned long stack;
126
 
127
        show_stack(current, &stack);
128
}
129
 
130
void show_registers(struct pt_regs *regs)
131
{
132
        int i;
133
        int in_kernel = 1;
134
        unsigned long esp;
135
 
136
        esp = (unsigned long) (&regs->sp);
137
        if (user_mode(regs))
138
                in_kernel = 0;
139
 
140
        printk("CPU #: %d\n"
141
               "   PC: %08lx    SR: %08lx    SP: %08lx\n",
142
               smp_processor_id(), regs->pc, regs->sr, regs->sp);
143
        printk("GPR00: %08lx GPR01: %08lx GPR02: %08lx GPR03: %08lx\n",
144
               0L, regs->sp, regs->gprs[0], regs->gprs[1]);
145
        printk("GPR04: %08lx GPR05: %08lx GPR06: %08lx GPR07: %08lx\n",
146
               regs->gprs[2], regs->gprs[3], regs->gprs[4], regs->gprs[5]);
147
        printk("GPR08: %08lx GPR09: %08lx GPR10: %08lx GPR11: %08lx\n",
148
               regs->gprs[6], regs->gprs[7], regs->gprs[8], regs->gprs[9]);
149
        printk("GPR12: %08lx GPR13: %08lx GPR14: %08lx GPR15: %08lx\n",
150
               regs->gprs[10], regs->gprs[11], regs->gprs[12], regs->gprs[13]);
151
        printk("GPR16: %08lx GPR17: %08lx GPR18: %08lx GPR19: %08lx\n",
152
               regs->gprs[14], regs->gprs[15], regs->gprs[16], regs->gprs[17]);
153
        printk("GPR20: %08lx GPR21: %08lx GPR22: %08lx GPR23: %08lx\n",
154
               regs->gprs[18], regs->gprs[19], regs->gprs[20], regs->gprs[21]);
155
        printk("GPR24: %08lx GPR25: %08lx GPR26: %08lx GPR27: %08lx\n",
156
               regs->gprs[22], regs->gprs[23], regs->gprs[24], regs->gprs[25]);
157
        printk("GPR28: %08lx GPR29: %08lx GPR30: %08lx GPR31: %08lx\n",
158
               regs->gprs[26], regs->gprs[27], regs->gprs[28], regs->gprs[29]);
159
        printk("  RES: %08lx oGPR3: %08lx syscallno: %08lx\n",
160
               regs->result, regs->orig_gpr3, regs->syscallno);
161
 
162
        printk("Process %s (pid: %d, stackpage=%08lx)\n",
163
               current->comm, current->pid, (unsigned long)current);
164
        /*
165
         * When in-kernel, we also print out the stack and code at the
166
         * time of the fault..
167
         */
168
        if (in_kernel) {
169
 
170
                printk("\nStack: ");
171
                show_stack(NULL, (unsigned long*)esp);
172
 
173
                printk("\nCode: ");
174
                if(regs->pc < PAGE_OFFSET)
175
                        goto bad;
176
 
177
                for(i=-24;i<24;i++)
178
                {
179
                        unsigned char c;
180
                        if(__get_user(c, &((unsigned char*)regs->pc)[i])) {
181
bad:
182
                                printk(" Bad PC value.");
183
                                break;
184
                        }
185
 
186
                        if (i == 0)
187
                          printk("(%02x) ", c);
188
                        else
189
                          printk("%02x ", c);
190
                }
191
        }
192
        printk("\n");
193
}
194
 
195
void nommu_dump_state(struct pt_regs *regs,
196
                      unsigned long ea, unsigned long vector)
197
{
198
        int i;
199
        unsigned long addr, stack = regs->sp;
200
 
201
        printk("\n\r[nommu_dump_state] :: ea %lx, vector %lx\n\r",
202
               ea, vector);
203
 
204
        printk("CPU #: %d\n"
205
               "   PC: %08lx    SR: %08lx    SP: %08lx\n",
206
               0, regs->pc, regs->sr, regs->sp);
207
        printk("GPR00: %08lx GPR01: %08lx GPR02: %08lx GPR03: %08lx\n",
208
               0L, regs->sp, regs->gprs[0], regs->gprs[1]);
209
        printk("GPR04: %08lx GPR05: %08lx GPR06: %08lx GPR07: %08lx\n",
210
               regs->gprs[2], regs->gprs[3], regs->gprs[4], regs->gprs[5]);
211
        printk("GPR08: %08lx GPR09: %08lx GPR10: %08lx GPR11: %08lx\n",
212
               regs->gprs[6], regs->gprs[7], regs->gprs[8], regs->gprs[9]);
213
        printk("GPR12: %08lx GPR13: %08lx GPR14: %08lx GPR15: %08lx\n",
214
               regs->gprs[10], regs->gprs[11], regs->gprs[12], regs->gprs[13]);
215
        printk("GPR16: %08lx GPR17: %08lx GPR18: %08lx GPR19: %08lx\n",
216
               regs->gprs[14], regs->gprs[15], regs->gprs[16], regs->gprs[17]);
217
        printk("GPR20: %08lx GPR21: %08lx GPR22: %08lx GPR23: %08lx\n",
218
               regs->gprs[18], regs->gprs[19], regs->gprs[20], regs->gprs[21]);
219
        printk("GPR24: %08lx GPR25: %08lx GPR26: %08lx GPR27: %08lx\n",
220
               regs->gprs[22], regs->gprs[23], regs->gprs[24], regs->gprs[25]);
221
        printk("GPR28: %08lx GPR29: %08lx GPR30: %08lx GPR31: %08lx\n",
222
               regs->gprs[26], regs->gprs[27], regs->gprs[28], regs->gprs[29]);
223
        printk("  RES: %08lx oGPR3: %08lx syscallno: %08lx\n",
224
               regs->result, regs->orig_gpr3, regs->syscallno);
225
 
226
        printk("Process %s (pid: %d, stackpage=%08lx)\n",
227
               ((struct task_struct*)(__pa(current)))->comm,
228
               ((struct task_struct*)(__pa(current)))->pid,
229
               (unsigned long)current);
230
 
231
        printk("\nStack: ");
232
        printk("Stack dump [0x%08lx]:\n", (unsigned long)stack);
233
        for(i = 0; i < kstack_depth_to_print; i++) {
234
                if (((long) stack & (THREAD_SIZE-1)) == 0)
235
                        break;
236
                stack++;
237
 
238
                printk("%lx :: sp + %02d: 0x%08lx\n", stack, i*4,
239
                       *((unsigned long*)(__pa(stack))));
240
        }
241
        printk("\n");
242
 
243
        printk("Call Trace:   ");
244
        i = 1;
245
        while (((long) stack & (THREAD_SIZE-1)) != 0) {
246
                addr = *((unsigned long*)__pa(stack));
247
                stack++;
248
 
249
                if (kernel_text_address(addr)) {
250
                        if (i && ((i % 6) == 0))
251
                                printk("\n ");
252
                        printk(" [<%08lx>]", addr);
253
                        i++;
254
                }
255
        }
256
        printk("\n");
257
 
258
        printk("\nCode: ");
259
 
260
        for(i=-24;i<24;i++)
261
        {
262
                unsigned char c;
263
                c = ((unsigned char*)(__pa(regs->pc)))[i];
264
 
265
                if (i == 0)
266
                        printk("(%02x) ", c);
267
                else
268
                        printk("%02x ", c);
269
        }
270
        printk("\n");
271
}
272
 
273
 
274
/* This is normally the 'Oops' routine */
275
void die(const char * str, struct pt_regs * regs, long err)
276
{
277
 
278
        console_verbose();
279
        printk("\n%s#: %04lx\n", str, err & 0xffff);
280
        show_registers(regs);
281
#ifdef CONFIG_JUMP_UPON_UNHANDLED_EXCEPTION
282
        printk("\n\nUNHANDLED_EXCEPTION: entering infinite loop\n");
283
 
284
        /* shut down interrupts */
285
        local_irq_disable();
286
 
287
/*
288
 * this doesn't work
289
 *
290
 */
291
#if 0
292
        /* stop the simulator */
293
        __asm__ __volatile__(
294
                "l.nop   1                     ;"
295
                "l.ori   r3,r0,0x8001          ;"
296
                "l.mtspr r0,r3,64              ;" /* SPR_ESR_BASE */
297
                "l.movhi r3,hi(0xf0000100)     ;"
298
                "l.ori   r3,r3,lo(0xf0000100)  ;"
299
                "l.mtspr r0,r3,32              ;" /* SPR_EPCR_BASE */
300
                "l.nop   1                     ;"
301
                "l.nop   1                     ;"
302
                "l.nop   1                     ;"
303
                "l.nop   1                     ;"
304
                "l.rfe");
305
#endif
306
 
307
        __asm__ __volatile__(
308
                "l.nop   1");
309
        for (;;)
310
                ;
311
#endif
312
        do_exit(SIGSEGV);
313
}
314
 
315
/* This is normally the 'Oops' routine */
316
void die_if_kernel(const char * str, struct pt_regs * regs, long err)
317
{
318
        if(user_mode(regs))
319
                return;
320
 
321
        die(str, regs, err);
322
}
323
 
324
void unhandled_exception(struct pt_regs *regs, int ea, int vector)
325
{
326
        printk("Unable to handle exception at EA =0x%x, vector 0x%x",
327
                ea, vector);
328
        die("Oops", regs, 9);
329
}
330
 
331
void __init trap_init(void)
332
{
333
        /* Nothing needs to be done */
334
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.