traps.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /* $Id: traps.c,v 1.17 2004/05/02 01:46:30 sugioka Exp $
  2. *
  3. * linux/arch/sh/traps.c
  4. *
  5. * SuperH version: Copyright (C) 1999 Niibe Yutaka
  6. * Copyright (C) 2000 Philipp Rumpf
  7. * Copyright (C) 2000 David Howells
  8. * Copyright (C) 2002, 2003 Paul Mundt
  9. */
  10. /*
  11. * 'Traps.c' handles hardware traps and faults after we have saved some
  12. * state in 'entry.S'.
  13. */
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/string.h>
  17. #include <linux/errno.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/timer.h>
  20. #include <linux/mm.h>
  21. #include <linux/smp.h>
  22. #include <linux/smp_lock.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/module.h>
  27. #include <linux/kallsyms.h>
  28. #include <asm/system.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/io.h>
  31. #include <asm/atomic.h>
  32. #include <asm/processor.h>
  33. #include <asm/sections.h>
  34. #ifdef CONFIG_SH_KGDB
  35. #include <asm/kgdb.h>
  36. #define CHK_REMOTE_DEBUG(regs) \
  37. { \
  38. if (kgdb_debug_hook && !user_mode(regs))\
  39. (*kgdb_debug_hook)(regs); \
  40. }
  41. #else
  42. #define CHK_REMOTE_DEBUG(regs)
  43. #endif
  44. #ifdef CONFIG_CPU_SH2
  45. #define TRAP_RESERVED_INST 4
  46. #define TRAP_ILLEGAL_SLOT_INST 6
  47. #else
  48. #define TRAP_RESERVED_INST 12
  49. #define TRAP_ILLEGAL_SLOT_INST 13
  50. #endif
  51. /*
  52. * These constants are for searching for possible module text
  53. * segments. VMALLOC_OFFSET comes from mm/vmalloc.c; MODULE_RANGE is
  54. * a guess of how much space is likely to be vmalloced.
  55. */
  56. #define VMALLOC_OFFSET (8*1024*1024)
  57. #define MODULE_RANGE (8*1024*1024)
  58. DEFINE_SPINLOCK(die_lock);
  59. void die(const char * str, struct pt_regs * regs, long err)
  60. {
  61. static int die_counter;
  62. console_verbose();
  63. spin_lock_irq(&die_lock);
  64. printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
  65. CHK_REMOTE_DEBUG(regs);
  66. show_regs(regs);
  67. spin_unlock_irq(&die_lock);
  68. do_exit(SIGSEGV);
  69. }
  70. static inline void die_if_kernel(const char * str, struct pt_regs * regs, long err)
  71. {
  72. if (!user_mode(regs))
  73. die(str, regs, err);
  74. }
  75. static int handle_unaligned_notify_count = 10;
  76. /*
  77. * try and fix up kernelspace address errors
  78. * - userspace errors just cause EFAULT to be returned, resulting in SEGV
  79. * - kernel/userspace interfaces cause a jump to an appropriate handler
  80. * - other kernel errors are bad
  81. * - return 0 if fixed-up, -EFAULT if non-fatal (to the kernel) fault
  82. */
  83. static int die_if_no_fixup(const char * str, struct pt_regs * regs, long err)
  84. {
  85. if (!user_mode(regs))
  86. {
  87. const struct exception_table_entry *fixup;
  88. fixup = search_exception_tables(regs->pc);
  89. if (fixup) {
  90. regs->pc = fixup->fixup;
  91. return 0;
  92. }
  93. die(str, regs, err);
  94. }
  95. return -EFAULT;
  96. }
  97. /*
  98. * handle an instruction that does an unaligned memory access by emulating the
  99. * desired behaviour
  100. * - note that PC _may not_ point to the faulting instruction
  101. * (if that instruction is in a branch delay slot)
  102. * - return 0 if emulation okay, -EFAULT on existential error
  103. */
  104. static int handle_unaligned_ins(u16 instruction, struct pt_regs *regs)
  105. {
  106. int ret, index, count;
  107. unsigned long *rm, *rn;
  108. unsigned char *src, *dst;
  109. index = (instruction>>8)&15; /* 0x0F00 */
  110. rn = &regs->regs[index];
  111. index = (instruction>>4)&15; /* 0x00F0 */
  112. rm = &regs->regs[index];
  113. count = 1<<(instruction&3);
  114. ret = -EFAULT;
  115. switch (instruction>>12) {
  116. case 0: /* mov.[bwl] to/from memory via r0+rn */
  117. if (instruction & 8) {
  118. /* from memory */
  119. src = (unsigned char*) *rm;
  120. src += regs->regs[0];
  121. dst = (unsigned char*) rn;
  122. *(unsigned long*)dst = 0;
  123. #ifdef __LITTLE_ENDIAN__
  124. if (copy_from_user(dst, src, count))
  125. goto fetch_fault;
  126. if ((count == 2) && dst[1] & 0x80) {
  127. dst[2] = 0xff;
  128. dst[3] = 0xff;
  129. }
  130. #else
  131. dst += 4-count;
  132. if (__copy_user(dst, src, count))
  133. goto fetch_fault;
  134. if ((count == 2) && dst[2] & 0x80) {
  135. dst[0] = 0xff;
  136. dst[1] = 0xff;
  137. }
  138. #endif
  139. } else {
  140. /* to memory */
  141. src = (unsigned char*) rm;
  142. #if !defined(__LITTLE_ENDIAN__)
  143. src += 4-count;
  144. #endif
  145. dst = (unsigned char*) *rn;
  146. dst += regs->regs[0];
  147. if (copy_to_user(dst, src, count))
  148. goto fetch_fault;
  149. }
  150. ret = 0;
  151. break;
  152. case 1: /* mov.l Rm,@(disp,Rn) */
  153. src = (unsigned char*) rm;
  154. dst = (unsigned char*) *rn;
  155. dst += (instruction&0x000F)<<2;
  156. if (copy_to_user(dst,src,4))
  157. goto fetch_fault;
  158. ret = 0;
  159. break;
  160. case 2: /* mov.[bwl] to memory, possibly with pre-decrement */
  161. if (instruction & 4)
  162. *rn -= count;
  163. src = (unsigned char*) rm;
  164. dst = (unsigned char*) *rn;
  165. #if !defined(__LITTLE_ENDIAN__)
  166. src += 4-count;
  167. #endif
  168. if (copy_to_user(dst, src, count))
  169. goto fetch_fault;
  170. ret = 0;
  171. break;
  172. case 5: /* mov.l @(disp,Rm),Rn */
  173. src = (unsigned char*) *rm;
  174. src += (instruction&0x000F)<<2;
  175. dst = (unsigned char*) rn;
  176. *(unsigned long*)dst = 0;
  177. if (copy_from_user(dst,src,4))
  178. goto fetch_fault;
  179. ret = 0;
  180. break;
  181. case 6: /* mov.[bwl] from memory, possibly with post-increment */
  182. src = (unsigned char*) *rm;
  183. if (instruction & 4)
  184. *rm += count;
  185. dst = (unsigned char*) rn;
  186. *(unsigned long*)dst = 0;
  187. #ifdef __LITTLE_ENDIAN__
  188. if (copy_from_user(dst, src, count))
  189. goto fetch_fault;
  190. if ((count == 2) && dst[1] & 0x80) {
  191. dst[2] = 0xff;
  192. dst[3] = 0xff;
  193. }
  194. #else
  195. dst += 4-count;
  196. if (copy_from_user(dst, src, count))
  197. goto fetch_fault;
  198. if ((count == 2) && dst[2] & 0x80) {
  199. dst[0] = 0xff;
  200. dst[1] = 0xff;
  201. }
  202. #endif
  203. ret = 0;
  204. break;
  205. case 8:
  206. switch ((instruction&0xFF00)>>8) {
  207. case 0x81: /* mov.w R0,@(disp,Rn) */
  208. src = (unsigned char*) &regs->regs[0];
  209. #if !defined(__LITTLE_ENDIAN__)
  210. src += 2;
  211. #endif
  212. dst = (unsigned char*) *rm; /* called Rn in the spec */
  213. dst += (instruction&0x000F)<<1;
  214. if (copy_to_user(dst, src, 2))
  215. goto fetch_fault;
  216. ret = 0;
  217. break;
  218. case 0x85: /* mov.w @(disp,Rm),R0 */
  219. src = (unsigned char*) *rm;
  220. src += (instruction&0x000F)<<1;
  221. dst = (unsigned char*) &regs->regs[0];
  222. *(unsigned long*)dst = 0;
  223. #if !defined(__LITTLE_ENDIAN__)
  224. dst += 2;
  225. #endif
  226. if (copy_from_user(dst, src, 2))
  227. goto fetch_fault;
  228. #ifdef __LITTLE_ENDIAN__
  229. if (dst[1] & 0x80) {
  230. dst[2] = 0xff;
  231. dst[3] = 0xff;
  232. }
  233. #else
  234. if (dst[2] & 0x80) {
  235. dst[0] = 0xff;
  236. dst[1] = 0xff;
  237. }
  238. #endif
  239. ret = 0;
  240. break;
  241. }
  242. break;
  243. }
  244. return ret;
  245. fetch_fault:
  246. /* Argh. Address not only misaligned but also non-existent.
  247. * Raise an EFAULT and see if it's trapped
  248. */
  249. return die_if_no_fixup("Fault in unaligned fixup", regs, 0);
  250. }
  251. /*
  252. * emulate the instruction in the delay slot
  253. * - fetches the instruction from PC+2
  254. */
  255. static inline int handle_unaligned_delayslot(struct pt_regs *regs)
  256. {
  257. u16 instruction;
  258. if (copy_from_user(&instruction, (u16 *)(regs->pc+2), 2)) {
  259. /* the instruction-fetch faulted */
  260. if (user_mode(regs))
  261. return -EFAULT;
  262. /* kernel */
  263. die("delay-slot-insn faulting in handle_unaligned_delayslot", regs, 0);
  264. }
  265. return handle_unaligned_ins(instruction,regs);
  266. }
  267. /*
  268. * handle an instruction that does an unaligned memory access
  269. * - have to be careful of branch delay-slot instructions that fault
  270. * SH3:
  271. * - if the branch would be taken PC points to the branch
  272. * - if the branch would not be taken, PC points to delay-slot
  273. * SH4:
  274. * - PC always points to delayed branch
  275. * - return 0 if handled, -EFAULT if failed (may not return if in kernel)
  276. */
  277. /* Macros to determine offset from current PC for branch instructions */
  278. /* Explicit type coercion is used to force sign extension where needed */
  279. #define SH_PC_8BIT_OFFSET(instr) ((((signed char)(instr))*2) + 4)
  280. #define SH_PC_12BIT_OFFSET(instr) ((((signed short)(instr<<4))>>3) + 4)
  281. static int handle_unaligned_access(u16 instruction, struct pt_regs *regs)
  282. {
  283. u_int rm;
  284. int ret, index;
  285. index = (instruction>>8)&15; /* 0x0F00 */
  286. rm = regs->regs[index];
  287. /* shout about the first ten userspace fixups */
  288. if (user_mode(regs) && handle_unaligned_notify_count>0) {
  289. handle_unaligned_notify_count--;
  290. printk("Fixing up unaligned userspace access in \"%s\" pid=%d pc=0x%p ins=0x%04hx\n",
  291. current->comm,current->pid,(u16*)regs->pc,instruction);
  292. }
  293. ret = -EFAULT;
  294. switch (instruction&0xF000) {
  295. case 0x0000:
  296. if (instruction==0x000B) {
  297. /* rts */
  298. ret = handle_unaligned_delayslot(regs);
  299. if (ret==0)
  300. regs->pc = regs->pr;
  301. }
  302. else if ((instruction&0x00FF)==0x0023) {
  303. /* braf @Rm */
  304. ret = handle_unaligned_delayslot(regs);
  305. if (ret==0)
  306. regs->pc += rm + 4;
  307. }
  308. else if ((instruction&0x00FF)==0x0003) {
  309. /* bsrf @Rm */
  310. ret = handle_unaligned_delayslot(regs);
  311. if (ret==0) {
  312. regs->pr = regs->pc + 4;
  313. regs->pc += rm + 4;
  314. }
  315. }
  316. else {
  317. /* mov.[bwl] to/from memory via r0+rn */
  318. goto simple;
  319. }
  320. break;
  321. case 0x1000: /* mov.l Rm,@(disp,Rn) */
  322. goto simple;
  323. case 0x2000: /* mov.[bwl] to memory, possibly with pre-decrement */
  324. goto simple;
  325. case 0x4000:
  326. if ((instruction&0x00FF)==0x002B) {
  327. /* jmp @Rm */
  328. ret = handle_unaligned_delayslot(regs);
  329. if (ret==0)
  330. regs->pc = rm;
  331. }
  332. else if ((instruction&0x00FF)==0x000B) {
  333. /* jsr @Rm */
  334. ret = handle_unaligned_delayslot(regs);
  335. if (ret==0) {
  336. regs->pr = regs->pc + 4;
  337. regs->pc = rm;
  338. }
  339. }
  340. else {
  341. /* mov.[bwl] to/from memory via r0+rn */
  342. goto simple;
  343. }
  344. break;
  345. case 0x5000: /* mov.l @(disp,Rm),Rn */
  346. goto simple;
  347. case 0x6000: /* mov.[bwl] from memory, possibly with post-increment */
  348. goto simple;
  349. case 0x8000: /* bf lab, bf/s lab, bt lab, bt/s lab */
  350. switch (instruction&0x0F00) {
  351. case 0x0100: /* mov.w R0,@(disp,Rm) */
  352. goto simple;
  353. case 0x0500: /* mov.w @(disp,Rm),R0 */
  354. goto simple;
  355. case 0x0B00: /* bf lab - no delayslot*/
  356. break;
  357. case 0x0F00: /* bf/s lab */
  358. ret = handle_unaligned_delayslot(regs);
  359. if (ret==0) {
  360. #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
  361. if ((regs->sr & 0x00000001) != 0)
  362. regs->pc += 4; /* next after slot */
  363. else
  364. #endif
  365. regs->pc += SH_PC_8BIT_OFFSET(instruction);
  366. }
  367. break;
  368. case 0x0900: /* bt lab - no delayslot */
  369. break;
  370. case 0x0D00: /* bt/s lab */
  371. ret = handle_unaligned_delayslot(regs);
  372. if (ret==0) {
  373. #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
  374. if ((regs->sr & 0x00000001) == 0)
  375. regs->pc += 4; /* next after slot */
  376. else
  377. #endif
  378. regs->pc += SH_PC_8BIT_OFFSET(instruction);
  379. }
  380. break;
  381. }
  382. break;
  383. case 0xA000: /* bra label */
  384. ret = handle_unaligned_delayslot(regs);
  385. if (ret==0)
  386. regs->pc += SH_PC_12BIT_OFFSET(instruction);
  387. break;
  388. case 0xB000: /* bsr label */
  389. ret = handle_unaligned_delayslot(regs);
  390. if (ret==0) {
  391. regs->pr = regs->pc + 4;
  392. regs->pc += SH_PC_12BIT_OFFSET(instruction);
  393. }
  394. break;
  395. }
  396. return ret;
  397. /* handle non-delay-slot instruction */
  398. simple:
  399. ret = handle_unaligned_ins(instruction,regs);
  400. if (ret==0)
  401. regs->pc += 2;
  402. return ret;
  403. }
  404. /*
  405. * Handle various address error exceptions
  406. */
  407. asmlinkage void do_address_error(struct pt_regs *regs,
  408. unsigned long writeaccess,
  409. unsigned long address)
  410. {
  411. unsigned long error_code;
  412. mm_segment_t oldfs;
  413. u16 instruction;
  414. int tmp;
  415. asm volatile("stc r2_bank,%0": "=r" (error_code));
  416. oldfs = get_fs();
  417. if (user_mode(regs)) {
  418. local_irq_enable();
  419. current->thread.error_code = error_code;
  420. current->thread.trap_no = (writeaccess) ? 8 : 7;
  421. /* bad PC is not something we can fix */
  422. if (regs->pc & 1)
  423. goto uspace_segv;
  424. set_fs(USER_DS);
  425. if (copy_from_user(&instruction, (u16 *)(regs->pc), 2)) {
  426. /* Argh. Fault on the instruction itself.
  427. This should never happen non-SMP
  428. */
  429. set_fs(oldfs);
  430. goto uspace_segv;
  431. }
  432. tmp = handle_unaligned_access(instruction, regs);
  433. set_fs(oldfs);
  434. if (tmp==0)
  435. return; /* sorted */
  436. uspace_segv:
  437. printk(KERN_NOTICE "Killing process \"%s\" due to unaligned access\n", current->comm);
  438. force_sig(SIGSEGV, current);
  439. } else {
  440. if (regs->pc & 1)
  441. die("unaligned program counter", regs, error_code);
  442. set_fs(KERNEL_DS);
  443. if (copy_from_user(&instruction, (u16 *)(regs->pc), 2)) {
  444. /* Argh. Fault on the instruction itself.
  445. This should never happen non-SMP
  446. */
  447. set_fs(oldfs);
  448. die("insn faulting in do_address_error", regs, 0);
  449. }
  450. handle_unaligned_access(instruction, regs);
  451. set_fs(oldfs);
  452. }
  453. }
  454. #ifdef CONFIG_SH_DSP
  455. /*
  456. * SH-DSP support gerg@snapgear.com.
  457. */
  458. int is_dsp_inst(struct pt_regs *regs)
  459. {
  460. unsigned short inst;
  461. /*
  462. * Safe guard if DSP mode is already enabled or we're lacking
  463. * the DSP altogether.
  464. */
  465. if (!(cpu_data->flags & CPU_HAS_DSP) || (regs->sr & SR_DSP))
  466. return 0;
  467. get_user(inst, ((unsigned short *) regs->pc));
  468. inst &= 0xf000;
  469. /* Check for any type of DSP or support instruction */
  470. if ((inst == 0xf000) || (inst == 0x4000))
  471. return 1;
  472. return 0;
  473. }
  474. #else
  475. #define is_dsp_inst(regs) (0)
  476. #endif /* CONFIG_SH_DSP */
  477. extern int do_fpu_inst(unsigned short, struct pt_regs*);
  478. asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5,
  479. unsigned long r6, unsigned long r7,
  480. struct pt_regs regs)
  481. {
  482. unsigned long error_code;
  483. struct task_struct *tsk = current;
  484. #ifdef CONFIG_SH_FPU_EMU
  485. unsigned short inst;
  486. int err;
  487. get_user(inst, (unsigned short*)regs.pc);
  488. err = do_fpu_inst(inst, &regs);
  489. if (!err) {
  490. regs.pc += 2;
  491. return;
  492. }
  493. /* not a FPU inst. */
  494. #endif
  495. #ifdef CONFIG_SH_DSP
  496. /* Check if it's a DSP instruction */
  497. if (is_dsp_inst(&regs)) {
  498. /* Enable DSP mode, and restart instruction. */
  499. regs.sr |= SR_DSP;
  500. return;
  501. }
  502. #endif
  503. asm volatile("stc r2_bank, %0": "=r" (error_code));
  504. local_irq_enable();
  505. tsk->thread.error_code = error_code;
  506. tsk->thread.trap_no = TRAP_RESERVED_INST;
  507. CHK_REMOTE_DEBUG(&regs);
  508. force_sig(SIGILL, tsk);
  509. die_if_no_fixup("reserved instruction", &regs, error_code);
  510. }
  511. #ifdef CONFIG_SH_FPU_EMU
  512. static int emulate_branch(unsigned short inst, struct pt_regs* regs)
  513. {
  514. /*
  515. * bfs: 8fxx: PC+=d*2+4;
  516. * bts: 8dxx: PC+=d*2+4;
  517. * bra: axxx: PC+=D*2+4;
  518. * bsr: bxxx: PC+=D*2+4 after PR=PC+4;
  519. * braf:0x23: PC+=Rn*2+4;
  520. * bsrf:0x03: PC+=Rn*2+4 after PR=PC+4;
  521. * jmp: 4x2b: PC=Rn;
  522. * jsr: 4x0b: PC=Rn after PR=PC+4;
  523. * rts: 000b: PC=PR;
  524. */
  525. if ((inst & 0xfd00) == 0x8d00) {
  526. regs->pc += SH_PC_8BIT_OFFSET(inst);
  527. return 0;
  528. }
  529. if ((inst & 0xe000) == 0xa000) {
  530. regs->pc += SH_PC_12BIT_OFFSET(inst);
  531. return 0;
  532. }
  533. if ((inst & 0xf0df) == 0x0003) {
  534. regs->pc += regs->regs[(inst & 0x0f00) >> 8] + 4;
  535. return 0;
  536. }
  537. if ((inst & 0xf0df) == 0x400b) {
  538. regs->pc = regs->regs[(inst & 0x0f00) >> 8];
  539. return 0;
  540. }
  541. if ((inst & 0xffff) == 0x000b) {
  542. regs->pc = regs->pr;
  543. return 0;
  544. }
  545. return 1;
  546. }
  547. #endif
  548. asmlinkage void do_illegal_slot_inst(unsigned long r4, unsigned long r5,
  549. unsigned long r6, unsigned long r7,
  550. struct pt_regs regs)
  551. {
  552. unsigned long error_code;
  553. struct task_struct *tsk = current;
  554. #ifdef CONFIG_SH_FPU_EMU
  555. unsigned short inst;
  556. get_user(inst, (unsigned short *)regs.pc + 1);
  557. if (!do_fpu_inst(inst, &regs)) {
  558. get_user(inst, (unsigned short *)regs.pc);
  559. if (!emulate_branch(inst, &regs))
  560. return;
  561. /* fault in branch.*/
  562. }
  563. /* not a FPU inst. */
  564. #endif
  565. asm volatile("stc r2_bank, %0": "=r" (error_code));
  566. local_irq_enable();
  567. tsk->thread.error_code = error_code;
  568. tsk->thread.trap_no = TRAP_RESERVED_INST;
  569. CHK_REMOTE_DEBUG(&regs);
  570. force_sig(SIGILL, tsk);
  571. die_if_no_fixup("illegal slot instruction", &regs, error_code);
  572. }
  573. asmlinkage void do_exception_error(unsigned long r4, unsigned long r5,
  574. unsigned long r6, unsigned long r7,
  575. struct pt_regs regs)
  576. {
  577. long ex;
  578. asm volatile("stc r2_bank, %0" : "=r" (ex));
  579. die_if_kernel("exception", &regs, ex);
  580. }
  581. #if defined(CONFIG_SH_STANDARD_BIOS)
  582. void *gdb_vbr_vector;
  583. static inline void __init gdb_vbr_init(void)
  584. {
  585. register unsigned long vbr;
  586. /*
  587. * Read the old value of the VBR register to initialise
  588. * the vector through which debug and BIOS traps are
  589. * delegated by the Linux trap handler.
  590. */
  591. asm volatile("stc vbr, %0" : "=r" (vbr));
  592. gdb_vbr_vector = (void *)(vbr + 0x100);
  593. printk("Setting GDB trap vector to 0x%08lx\n",
  594. (unsigned long)gdb_vbr_vector);
  595. }
  596. #endif
  597. void __init per_cpu_trap_init(void)
  598. {
  599. extern void *vbr_base;
  600. #ifdef CONFIG_SH_STANDARD_BIOS
  601. gdb_vbr_init();
  602. #endif
  603. /* NOTE: The VBR value should be at P1
  604. (or P2, virtural "fixed" address space).
  605. It's definitely should not in physical address. */
  606. asm volatile("ldc %0, vbr"
  607. : /* no output */
  608. : "r" (&vbr_base)
  609. : "memory");
  610. }
  611. void __init trap_init(void)
  612. {
  613. extern void *exception_handling_table[];
  614. exception_handling_table[TRAP_RESERVED_INST]
  615. = (void *)do_reserved_inst;
  616. exception_handling_table[TRAP_ILLEGAL_SLOT_INST]
  617. = (void *)do_illegal_slot_inst;
  618. #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_FPU) || \
  619. defined(CONFIG_SH_FPU_EMU)
  620. /*
  621. * For SH-4 lacking an FPU, treat floating point instructions as
  622. * reserved. They'll be handled in the math-emu case, or faulted on
  623. * otherwise.
  624. */
  625. /* entry 64 corresponds to EXPEVT=0x800 */
  626. exception_handling_table[64] = (void *)do_reserved_inst;
  627. exception_handling_table[65] = (void *)do_illegal_slot_inst;
  628. #endif
  629. /* Setup VBR for boot cpu */
  630. per_cpu_trap_init();
  631. }
  632. void show_stack(struct task_struct *tsk, unsigned long *sp)
  633. {
  634. unsigned long *stack, addr;
  635. unsigned long module_start = VMALLOC_START;
  636. unsigned long module_end = VMALLOC_END;
  637. int i = 1;
  638. if (!tsk)
  639. tsk = current;
  640. if (tsk == current)
  641. sp = (unsigned long *)current_stack_pointer;
  642. else
  643. sp = (unsigned long *)tsk->thread.sp;
  644. stack = sp;
  645. printk("\nCall trace: ");
  646. #ifdef CONFIG_KALLSYMS
  647. printk("\n");
  648. #endif
  649. while (!kstack_end(stack)) {
  650. addr = *stack++;
  651. if (((addr >= (unsigned long)_text) &&
  652. (addr <= (unsigned long)_etext)) ||
  653. ((addr >= module_start) && (addr <= module_end))) {
  654. /*
  655. * For 80-columns display, 6 entry is maximum.
  656. * NOTE: '[<8c00abcd>] ' consumes 13 columns .
  657. */
  658. #ifndef CONFIG_KALLSYMS
  659. if (i && ((i % 6) == 0))
  660. printk("\n ");
  661. #endif
  662. printk("[<%08lx>] ", addr);
  663. print_symbol("%s\n", addr);
  664. i++;
  665. }
  666. }
  667. printk("\n");
  668. }
  669. void show_task(unsigned long *sp)
  670. {
  671. show_stack(NULL, sp);
  672. }
  673. void dump_stack(void)
  674. {
  675. show_stack(NULL, NULL);
  676. }
  677. EXPORT_SYMBOL(dump_stack);