]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/openrisc/kernel/traps.c
4 * Linux architectural port borrowing liberally from similar works of
5 * others. All original copyrights apply as per the original source
8 * Modifications for the OpenRISC architecture:
9 * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
10 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
17 * Here we handle the break vectors not used by the system call
18 * mechanism, as well as some general stack/register dumping
23 #include <linux/init.h>
24 #include <linux/sched.h>
25 #include <linux/kernel.h>
26 #include <linux/extable.h>
27 #include <linux/kmod.h>
28 #include <linux/string.h>
29 #include <linux/errno.h>
30 #include <linux/ptrace.h>
31 #include <linux/timer.h>
33 #include <linux/kallsyms.h>
34 #include <linux/uaccess.h>
36 #include <asm/segment.h>
38 #include <asm/pgtable.h>
40 extern char _etext
, _stext
;
42 int kstack_depth_to_print
= 0x180;
44 unsigned long __user
*lwa_addr
;
46 static inline int valid_stack_ptr(struct thread_info
*tinfo
, void *p
)
48 return p
> (void *)tinfo
&& p
< (void *)tinfo
+ THREAD_SIZE
- 3;
51 void show_trace(struct task_struct
*task
, unsigned long *stack
)
53 struct thread_info
*context
;
56 context
= (struct thread_info
*)
57 ((unsigned long)stack
& (~(THREAD_SIZE
- 1)));
59 while (valid_stack_ptr(context
, stack
)) {
61 if (__kernel_text_address(addr
)) {
62 printk(" [<%08lx>]", addr
);
63 print_symbol(" %s", addr
);
67 printk(" =======================\n");
70 /* displays a short stack trace */
71 void show_stack(struct task_struct
*task
, unsigned long *esp
)
73 unsigned long addr
, *stack
;
77 esp
= (unsigned long *)&esp
;
81 printk("Stack dump [0x%08lx]:\n", (unsigned long)esp
);
82 for (i
= 0; i
< kstack_depth_to_print
; i
++) {
83 if (kstack_end(stack
))
85 if (__get_user(addr
, stack
)) {
86 /* This message matches "failing address" marked
87 s390 in ksymoops, so lines containing it will
88 not be filtered out by ksymoops. */
89 printk("Failing address 0x%lx\n", (unsigned long)stack
);
94 printk("sp + %02d: 0x%08lx\n", i
* 4, addr
);
98 show_trace(task
, esp
);
103 void show_trace_task(struct task_struct
*tsk
)
106 * TODO: SysRq-T trace dump...
110 void show_registers(struct pt_regs
*regs
)
116 esp
= (unsigned long)(®s
->sp
);
121 " PC: %08lx SR: %08lx SP: %08lx\n",
122 smp_processor_id(), regs
->pc
, regs
->sr
, regs
->sp
);
123 printk("GPR00: %08lx GPR01: %08lx GPR02: %08lx GPR03: %08lx\n",
124 0L, regs
->gpr
[1], regs
->gpr
[2], regs
->gpr
[3]);
125 printk("GPR04: %08lx GPR05: %08lx GPR06: %08lx GPR07: %08lx\n",
126 regs
->gpr
[4], regs
->gpr
[5], regs
->gpr
[6], regs
->gpr
[7]);
127 printk("GPR08: %08lx GPR09: %08lx GPR10: %08lx GPR11: %08lx\n",
128 regs
->gpr
[8], regs
->gpr
[9], regs
->gpr
[10], regs
->gpr
[11]);
129 printk("GPR12: %08lx GPR13: %08lx GPR14: %08lx GPR15: %08lx\n",
130 regs
->gpr
[12], regs
->gpr
[13], regs
->gpr
[14], regs
->gpr
[15]);
131 printk("GPR16: %08lx GPR17: %08lx GPR18: %08lx GPR19: %08lx\n",
132 regs
->gpr
[16], regs
->gpr
[17], regs
->gpr
[18], regs
->gpr
[19]);
133 printk("GPR20: %08lx GPR21: %08lx GPR22: %08lx GPR23: %08lx\n",
134 regs
->gpr
[20], regs
->gpr
[21], regs
->gpr
[22], regs
->gpr
[23]);
135 printk("GPR24: %08lx GPR25: %08lx GPR26: %08lx GPR27: %08lx\n",
136 regs
->gpr
[24], regs
->gpr
[25], regs
->gpr
[26], regs
->gpr
[27]);
137 printk("GPR28: %08lx GPR29: %08lx GPR30: %08lx GPR31: %08lx\n",
138 regs
->gpr
[28], regs
->gpr
[29], regs
->gpr
[30], regs
->gpr
[31]);
139 printk(" RES: %08lx oGPR11: %08lx\n",
140 regs
->gpr
[11], regs
->orig_gpr11
);
142 printk("Process %s (pid: %d, stackpage=%08lx)\n",
143 current
->comm
, current
->pid
, (unsigned long)current
);
145 * When in-kernel, we also print out the stack and code at the
146 * time of the fault..
151 show_stack(NULL
, (unsigned long *)esp
);
154 if (regs
->pc
< PAGE_OFFSET
)
157 for (i
= -24; i
< 24; i
++) {
159 if (__get_user(c
, &((unsigned char *)regs
->pc
)[i
])) {
161 printk(" Bad PC value.");
166 printk("(%02x) ", c
);
174 void nommu_dump_state(struct pt_regs
*regs
,
175 unsigned long ea
, unsigned long vector
)
178 unsigned long addr
, stack
= regs
->sp
;
180 printk("\n\r[nommu_dump_state] :: ea %lx, vector %lx\n\r", ea
, vector
);
183 " PC: %08lx SR: %08lx SP: %08lx\n",
184 0, regs
->pc
, regs
->sr
, regs
->sp
);
185 printk("GPR00: %08lx GPR01: %08lx GPR02: %08lx GPR03: %08lx\n",
186 0L, regs
->gpr
[1], regs
->gpr
[2], regs
->gpr
[3]);
187 printk("GPR04: %08lx GPR05: %08lx GPR06: %08lx GPR07: %08lx\n",
188 regs
->gpr
[4], regs
->gpr
[5], regs
->gpr
[6], regs
->gpr
[7]);
189 printk("GPR08: %08lx GPR09: %08lx GPR10: %08lx GPR11: %08lx\n",
190 regs
->gpr
[8], regs
->gpr
[9], regs
->gpr
[10], regs
->gpr
[11]);
191 printk("GPR12: %08lx GPR13: %08lx GPR14: %08lx GPR15: %08lx\n",
192 regs
->gpr
[12], regs
->gpr
[13], regs
->gpr
[14], regs
->gpr
[15]);
193 printk("GPR16: %08lx GPR17: %08lx GPR18: %08lx GPR19: %08lx\n",
194 regs
->gpr
[16], regs
->gpr
[17], regs
->gpr
[18], regs
->gpr
[19]);
195 printk("GPR20: %08lx GPR21: %08lx GPR22: %08lx GPR23: %08lx\n",
196 regs
->gpr
[20], regs
->gpr
[21], regs
->gpr
[22], regs
->gpr
[23]);
197 printk("GPR24: %08lx GPR25: %08lx GPR26: %08lx GPR27: %08lx\n",
198 regs
->gpr
[24], regs
->gpr
[25], regs
->gpr
[26], regs
->gpr
[27]);
199 printk("GPR28: %08lx GPR29: %08lx GPR30: %08lx GPR31: %08lx\n",
200 regs
->gpr
[28], regs
->gpr
[29], regs
->gpr
[30], regs
->gpr
[31]);
201 printk(" RES: %08lx oGPR11: %08lx\n",
202 regs
->gpr
[11], regs
->orig_gpr11
);
204 printk("Process %s (pid: %d, stackpage=%08lx)\n",
205 ((struct task_struct
*)(__pa(current
)))->comm
,
206 ((struct task_struct
*)(__pa(current
)))->pid
,
207 (unsigned long)current
);
210 printk("Stack dump [0x%08lx]:\n", (unsigned long)stack
);
211 for (i
= 0; i
< kstack_depth_to_print
; i
++) {
212 if (((long)stack
& (THREAD_SIZE
- 1)) == 0)
216 printk("%lx :: sp + %02d: 0x%08lx\n", stack
, i
* 4,
217 *((unsigned long *)(__pa(stack
))));
221 printk("Call Trace: ");
223 while (((long)stack
& (THREAD_SIZE
- 1)) != 0) {
224 addr
= *((unsigned long *)__pa(stack
));
227 if (kernel_text_address(addr
)) {
228 if (i
&& ((i
% 6) == 0))
230 printk(" [<%08lx>]", addr
);
238 for (i
= -24; i
< 24; i
++) {
240 c
= ((unsigned char *)(__pa(regs
->pc
)))[i
];
243 printk("(%02x) ", c
);
250 /* This is normally the 'Oops' routine */
251 void die(const char *str
, struct pt_regs
*regs
, long err
)
255 printk("\n%s#: %04lx\n", str
, err
& 0xffff);
256 show_registers(regs
);
257 #ifdef CONFIG_JUMP_UPON_UNHANDLED_EXCEPTION
258 printk("\n\nUNHANDLED_EXCEPTION: entering infinite loop\n");
260 /* shut down interrupts */
263 __asm__
__volatile__("l.nop 1");
269 /* This is normally the 'Oops' routine */
270 void die_if_kernel(const char *str
, struct pt_regs
*regs
, long err
)
278 void unhandled_exception(struct pt_regs
*regs
, int ea
, int vector
)
280 printk("Unable to handle exception at EA =0x%x, vector 0x%x",
282 die("Oops", regs
, 9);
285 void __init
trap_init(void)
287 /* Nothing needs to be done */
290 asmlinkage
void do_trap(struct pt_regs
*regs
, unsigned long address
)
293 memset(&info
, 0, sizeof(info
));
294 info
.si_signo
= SIGTRAP
;
295 info
.si_code
= TRAP_TRACE
;
296 info
.si_addr
= (void *)address
;
297 force_sig_info(SIGTRAP
, &info
, current
);
302 asmlinkage
void do_unaligned_access(struct pt_regs
*regs
, unsigned long address
)
306 if (user_mode(regs
)) {
308 info
.si_signo
= SIGSEGV
;
310 /* info.si_code has been set above */
311 info
.si_addr
= (void *)address
;
312 force_sig_info(SIGSEGV
, &info
, current
);
314 printk("KERNEL: Unaligned Access 0x%.8lx\n", address
);
315 show_registers(regs
);
316 die("Die:", regs
, address
);
321 asmlinkage
void do_bus_fault(struct pt_regs
*regs
, unsigned long address
)
325 if (user_mode(regs
)) {
327 info
.si_signo
= SIGBUS
;
329 info
.si_code
= BUS_ADRERR
;
330 info
.si_addr
= (void *)address
;
331 force_sig_info(SIGBUS
, &info
, current
);
332 } else { /* Kernel mode */
333 printk("KERNEL: Bus error (SIGBUS) 0x%.8lx\n", address
);
334 show_registers(regs
);
335 die("Die:", regs
, address
);
339 static inline int in_delay_slot(struct pt_regs
*regs
)
341 #ifdef CONFIG_OPENRISC_NO_SPR_SR_DSX
342 /* No delay slot flag, do the old way */
343 unsigned int op
, insn
;
345 insn
= *((unsigned int *)regs
->pc
);
349 case 0x01: /* l.jal */
350 case 0x03: /* l.bnf */
351 case 0x04: /* l.bf */
352 case 0x11: /* l.jr */
353 case 0x12: /* l.jalr */
359 return regs
->sr
& SPR_SR_DSX
;
363 static inline void adjust_pc(struct pt_regs
*regs
, unsigned long address
)
366 unsigned int rb
, op
, jmp
;
368 if (unlikely(in_delay_slot(regs
))) {
369 /* In delay slot, instruction at pc is a branch, simulate it */
370 jmp
= *((unsigned int *)regs
->pc
);
372 displacement
= sign_extend32(((jmp
) & 0x3ffffff) << 2, 27);
373 rb
= (jmp
& 0x0000ffff) >> 11;
378 regs
->pc
+= displacement
;
380 case 0x01: /* l.jal */
381 regs
->pc
+= displacement
;
382 regs
->gpr
[9] = regs
->pc
+ 8;
384 case 0x03: /* l.bnf */
385 if (regs
->sr
& SPR_SR_F
)
388 regs
->pc
+= displacement
;
390 case 0x04: /* l.bf */
391 if (regs
->sr
& SPR_SR_F
)
392 regs
->pc
+= displacement
;
396 case 0x11: /* l.jr */
397 regs
->pc
= regs
->gpr
[rb
];
399 case 0x12: /* l.jalr */
400 regs
->pc
= regs
->gpr
[rb
];
401 regs
->gpr
[9] = regs
->pc
+ 8;
411 static inline void simulate_lwa(struct pt_regs
*regs
, unsigned long address
,
416 unsigned long orig_pc
;
419 const struct exception_table_entry
*entry
;
422 adjust_pc(regs
, address
);
424 ra
= (insn
>> 16) & 0x1f;
425 rd
= (insn
>> 21) & 0x1f;
427 lwa_addr
= (unsigned long __user
*)(regs
->gpr
[ra
] + imm
);
429 if ((unsigned long)lwa_addr
& 0x3) {
430 do_unaligned_access(regs
, address
);
434 if (get_user(value
, lwa_addr
)) {
435 if (user_mode(regs
)) {
436 force_sig(SIGSEGV
, current
);
440 if ((entry
= search_exception_tables(orig_pc
))) {
441 regs
->pc
= entry
->fixup
;
445 /* kernel access in kernel space, load it directly */
446 value
= *((unsigned long *)lwa_addr
);
450 regs
->gpr
[rd
] = value
;
453 static inline void simulate_swa(struct pt_regs
*regs
, unsigned long address
,
456 unsigned long __user
*vaddr
;
457 unsigned long orig_pc
;
461 const struct exception_table_entry
*entry
;
464 adjust_pc(regs
, address
);
466 ra
= (insn
>> 16) & 0x1f;
467 rb
= (insn
>> 11) & 0x1f;
468 imm
= (short)(((insn
& 0x2200000) >> 10) | (insn
& 0x7ff));
469 vaddr
= (unsigned long __user
*)(regs
->gpr
[ra
] + imm
);
471 if (!lwa_flag
|| vaddr
!= lwa_addr
) {
472 regs
->sr
&= ~SPR_SR_F
;
476 if ((unsigned long)vaddr
& 0x3) {
477 do_unaligned_access(regs
, address
);
481 if (put_user(regs
->gpr
[rb
], vaddr
)) {
482 if (user_mode(regs
)) {
483 force_sig(SIGSEGV
, current
);
487 if ((entry
= search_exception_tables(orig_pc
))) {
488 regs
->pc
= entry
->fixup
;
492 /* kernel access in kernel space, store it directly */
493 *((unsigned long *)vaddr
) = regs
->gpr
[rb
];
497 regs
->sr
|= SPR_SR_F
;
500 #define INSN_LWA 0x1b
501 #define INSN_SWA 0x33
503 asmlinkage
void do_illegal_instruction(struct pt_regs
*regs
,
504 unsigned long address
)
508 unsigned int insn
= *((unsigned int *)address
);
514 simulate_lwa(regs
, address
, insn
);
518 simulate_swa(regs
, address
, insn
);
525 if (user_mode(regs
)) {
527 info
.si_signo
= SIGILL
;
529 info
.si_code
= ILL_ILLOPC
;
530 info
.si_addr
= (void *)address
;
531 force_sig_info(SIGBUS
, &info
, current
);
532 } else { /* Kernel mode */
533 printk("KERNEL: Illegal instruction (SIGILL) 0x%.8lx\n",
535 show_registers(regs
);
536 die("Die:", regs
, address
);