traps.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 - 1999, 2000, 01, 06 Ralf Baechle
  7. * Copyright (C) 1995, 1996 Paul M. Antoine
  8. * Copyright (C) 1998 Ulf Carlsson
  9. * Copyright (C) 1999 Silicon Graphics, Inc.
  10. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  11. * Copyright (C) 2000, 01 MIPS Technologies, Inc.
  12. * Copyright (C) 2002, 2003, 2004, 2005 Maciej W. Rozycki
  13. */
  14. #include <linux/config.h>
  15. #include <linux/init.h>
  16. #include <linux/mm.h>
  17. #include <linux/module.h>
  18. #include <linux/sched.h>
  19. #include <linux/smp.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/kallsyms.h>
  23. #include <linux/bootmem.h>
  24. #include <asm/bootinfo.h>
  25. #include <asm/branch.h>
  26. #include <asm/break.h>
  27. #include <asm/cpu.h>
  28. #include <asm/dsp.h>
  29. #include <asm/fpu.h>
  30. #include <asm/mipsregs.h>
  31. #include <asm/mipsmtregs.h>
  32. #include <asm/module.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/ptrace.h>
  35. #include <asm/sections.h>
  36. #include <asm/system.h>
  37. #include <asm/tlbdebug.h>
  38. #include <asm/traps.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/mmu_context.h>
  41. #include <asm/watch.h>
  42. #include <asm/types.h>
  43. extern asmlinkage void handle_int(void);
  44. extern asmlinkage void handle_tlbm(void);
  45. extern asmlinkage void handle_tlbl(void);
  46. extern asmlinkage void handle_tlbs(void);
  47. extern asmlinkage void handle_adel(void);
  48. extern asmlinkage void handle_ades(void);
  49. extern asmlinkage void handle_ibe(void);
  50. extern asmlinkage void handle_dbe(void);
  51. extern asmlinkage void handle_sys(void);
  52. extern asmlinkage void handle_bp(void);
  53. extern asmlinkage void handle_ri(void);
  54. extern asmlinkage void handle_cpu(void);
  55. extern asmlinkage void handle_ov(void);
  56. extern asmlinkage void handle_tr(void);
  57. extern asmlinkage void handle_fpe(void);
  58. extern asmlinkage void handle_mdmx(void);
  59. extern asmlinkage void handle_watch(void);
  60. extern asmlinkage void handle_mt(void);
  61. extern asmlinkage void handle_dsp(void);
  62. extern asmlinkage void handle_mcheck(void);
  63. extern asmlinkage void handle_reserved(void);
  64. extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
  65. struct mips_fpu_struct *ctx);
  66. void (*board_be_init)(void);
  67. int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
  68. void (*board_nmi_handler_setup)(void);
  69. void (*board_ejtag_handler_setup)(void);
  70. void (*board_bind_eic_interrupt)(int irq, int regset);
  71. /*
  72. * These constant is for searching for possible module text segments.
  73. * MODULE_RANGE is a guess of how much space is likely to be vmalloced.
  74. */
  75. #define MODULE_RANGE (8*1024*1024)
  76. /*
  77. * This routine abuses get_user()/put_user() to reference pointers
  78. * with at least a bit of error checking ...
  79. */
  80. void show_stack(struct task_struct *task, unsigned long *sp)
  81. {
  82. const int field = 2 * sizeof(unsigned long);
  83. long stackdata;
  84. int i;
  85. if (!sp) {
  86. if (task && task != current)
  87. sp = (unsigned long *) task->thread.reg29;
  88. else
  89. sp = (unsigned long *) &sp;
  90. }
  91. printk("Stack :");
  92. i = 0;
  93. while ((unsigned long) sp & (PAGE_SIZE - 1)) {
  94. if (i && ((i % (64 / field)) == 0))
  95. printk("\n ");
  96. if (i > 39) {
  97. printk(" ...");
  98. break;
  99. }
  100. if (__get_user(stackdata, sp++)) {
  101. printk(" (Bad stack address)");
  102. break;
  103. }
  104. printk(" %0*lx", field, stackdata);
  105. i++;
  106. }
  107. printk("\n");
  108. }
  109. void show_trace(struct task_struct *task, unsigned long *stack)
  110. {
  111. const int field = 2 * sizeof(unsigned long);
  112. unsigned long addr;
  113. if (!stack) {
  114. if (task && task != current)
  115. stack = (unsigned long *) task->thread.reg29;
  116. else
  117. stack = (unsigned long *) &stack;
  118. }
  119. printk("Call Trace:");
  120. #ifdef CONFIG_KALLSYMS
  121. printk("\n");
  122. #endif
  123. while (!kstack_end(stack)) {
  124. addr = *stack++;
  125. if (__kernel_text_address(addr)) {
  126. printk(" [<%0*lx>] ", field, addr);
  127. print_symbol("%s\n", addr);
  128. }
  129. }
  130. printk("\n");
  131. }
  132. /*
  133. * The architecture-independent dump_stack generator
  134. */
  135. void dump_stack(void)
  136. {
  137. unsigned long stack;
  138. show_trace(current, &stack);
  139. }
  140. EXPORT_SYMBOL(dump_stack);
  141. void show_code(unsigned int *pc)
  142. {
  143. long i;
  144. printk("\nCode:");
  145. for(i = -3 ; i < 6 ; i++) {
  146. unsigned int insn;
  147. if (__get_user(insn, pc + i)) {
  148. printk(" (Bad address in epc)\n");
  149. break;
  150. }
  151. printk("%c%08x%c", (i?' ':'<'), insn, (i?' ':'>'));
  152. }
  153. }
  154. void show_regs(struct pt_regs *regs)
  155. {
  156. const int field = 2 * sizeof(unsigned long);
  157. unsigned int cause = regs->cp0_cause;
  158. int i;
  159. printk("Cpu %d\n", smp_processor_id());
  160. /*
  161. * Saved main processor registers
  162. */
  163. for (i = 0; i < 32; ) {
  164. if ((i % 4) == 0)
  165. printk("$%2d :", i);
  166. if (i == 0)
  167. printk(" %0*lx", field, 0UL);
  168. else if (i == 26 || i == 27)
  169. printk(" %*s", field, "");
  170. else
  171. printk(" %0*lx", field, regs->regs[i]);
  172. i++;
  173. if ((i % 4) == 0)
  174. printk("\n");
  175. }
  176. printk("Hi : %0*lx\n", field, regs->hi);
  177. printk("Lo : %0*lx\n", field, regs->lo);
  178. /*
  179. * Saved cp0 registers
  180. */
  181. printk("epc : %0*lx ", field, regs->cp0_epc);
  182. print_symbol("%s ", regs->cp0_epc);
  183. printk(" %s\n", print_tainted());
  184. printk("ra : %0*lx ", field, regs->regs[31]);
  185. print_symbol("%s\n", regs->regs[31]);
  186. printk("Status: %08x ", (uint32_t) regs->cp0_status);
  187. if (current_cpu_data.isa_level == MIPS_CPU_ISA_I) {
  188. if (regs->cp0_status & ST0_KUO)
  189. printk("KUo ");
  190. if (regs->cp0_status & ST0_IEO)
  191. printk("IEo ");
  192. if (regs->cp0_status & ST0_KUP)
  193. printk("KUp ");
  194. if (regs->cp0_status & ST0_IEP)
  195. printk("IEp ");
  196. if (regs->cp0_status & ST0_KUC)
  197. printk("KUc ");
  198. if (regs->cp0_status & ST0_IEC)
  199. printk("IEc ");
  200. } else {
  201. if (regs->cp0_status & ST0_KX)
  202. printk("KX ");
  203. if (regs->cp0_status & ST0_SX)
  204. printk("SX ");
  205. if (regs->cp0_status & ST0_UX)
  206. printk("UX ");
  207. switch (regs->cp0_status & ST0_KSU) {
  208. case KSU_USER:
  209. printk("USER ");
  210. break;
  211. case KSU_SUPERVISOR:
  212. printk("SUPERVISOR ");
  213. break;
  214. case KSU_KERNEL:
  215. printk("KERNEL ");
  216. break;
  217. default:
  218. printk("BAD_MODE ");
  219. break;
  220. }
  221. if (regs->cp0_status & ST0_ERL)
  222. printk("ERL ");
  223. if (regs->cp0_status & ST0_EXL)
  224. printk("EXL ");
  225. if (regs->cp0_status & ST0_IE)
  226. printk("IE ");
  227. }
  228. printk("\n");
  229. printk("Cause : %08x\n", cause);
  230. cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
  231. if (1 <= cause && cause <= 5)
  232. printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
  233. printk("PrId : %08x\n", read_c0_prid());
  234. }
  235. void show_registers(struct pt_regs *regs)
  236. {
  237. show_regs(regs);
  238. print_modules();
  239. printk("Process %s (pid: %d, threadinfo=%p, task=%p)\n",
  240. current->comm, current->pid, current_thread_info(), current);
  241. show_stack(current, (long *) regs->regs[29]);
  242. show_trace(current, (long *) regs->regs[29]);
  243. show_code((unsigned int *) regs->cp0_epc);
  244. printk("\n");
  245. }
  246. static DEFINE_SPINLOCK(die_lock);
  247. NORET_TYPE void ATTRIB_NORET die(const char * str, struct pt_regs * regs)
  248. {
  249. static int die_counter;
  250. #ifdef CONFIG_MIPS_MT_SMTC
  251. unsigned long dvpret = dvpe();
  252. #endif /* CONFIG_MIPS_MT_SMTC */
  253. console_verbose();
  254. spin_lock_irq(&die_lock);
  255. bust_spinlocks(1);
  256. #ifdef CONFIG_MIPS_MT_SMTC
  257. mips_mt_regdump(dvpret);
  258. #endif /* CONFIG_MIPS_MT_SMTC */
  259. printk("%s[#%d]:\n", str, ++die_counter);
  260. show_registers(regs);
  261. spin_unlock_irq(&die_lock);
  262. do_exit(SIGSEGV);
  263. }
  264. extern const struct exception_table_entry __start___dbe_table[];
  265. extern const struct exception_table_entry __stop___dbe_table[];
  266. void __declare_dbe_table(void)
  267. {
  268. __asm__ __volatile__(
  269. ".section\t__dbe_table,\"a\"\n\t"
  270. ".previous"
  271. );
  272. }
  273. /* Given an address, look for it in the exception tables. */
  274. static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
  275. {
  276. const struct exception_table_entry *e;
  277. e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
  278. if (!e)
  279. e = search_module_dbetables(addr);
  280. return e;
  281. }
  282. asmlinkage void do_be(struct pt_regs *regs)
  283. {
  284. const int field = 2 * sizeof(unsigned long);
  285. const struct exception_table_entry *fixup = NULL;
  286. int data = regs->cp0_cause & 4;
  287. int action = MIPS_BE_FATAL;
  288. /* XXX For now. Fixme, this searches the wrong table ... */
  289. if (data && !user_mode(regs))
  290. fixup = search_dbe_tables(exception_epc(regs));
  291. if (fixup)
  292. action = MIPS_BE_FIXUP;
  293. if (board_be_handler)
  294. action = board_be_handler(regs, fixup != 0);
  295. switch (action) {
  296. case MIPS_BE_DISCARD:
  297. return;
  298. case MIPS_BE_FIXUP:
  299. if (fixup) {
  300. regs->cp0_epc = fixup->nextinsn;
  301. return;
  302. }
  303. break;
  304. default:
  305. break;
  306. }
  307. /*
  308. * Assume it would be too dangerous to continue ...
  309. */
  310. printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
  311. data ? "Data" : "Instruction",
  312. field, regs->cp0_epc, field, regs->regs[31]);
  313. die_if_kernel("Oops", regs);
  314. force_sig(SIGBUS, current);
  315. }
  316. static inline int get_insn_opcode(struct pt_regs *regs, unsigned int *opcode)
  317. {
  318. unsigned int __user *epc;
  319. epc = (unsigned int __user *) regs->cp0_epc +
  320. ((regs->cp0_cause & CAUSEF_BD) != 0);
  321. if (!get_user(*opcode, epc))
  322. return 0;
  323. force_sig(SIGSEGV, current);
  324. return 1;
  325. }
  326. /*
  327. * ll/sc emulation
  328. */
  329. #define OPCODE 0xfc000000
  330. #define BASE 0x03e00000
  331. #define RT 0x001f0000
  332. #define OFFSET 0x0000ffff
  333. #define LL 0xc0000000
  334. #define SC 0xe0000000
  335. #define SPEC3 0x7c000000
  336. #define RD 0x0000f800
  337. #define FUNC 0x0000003f
  338. #define RDHWR 0x0000003b
  339. /*
  340. * The ll_bit is cleared by r*_switch.S
  341. */
  342. unsigned long ll_bit;
  343. static struct task_struct *ll_task = NULL;
  344. static inline void simulate_ll(struct pt_regs *regs, unsigned int opcode)
  345. {
  346. unsigned long value, __user *vaddr;
  347. long offset;
  348. int signal = 0;
  349. /*
  350. * analyse the ll instruction that just caused a ri exception
  351. * and put the referenced address to addr.
  352. */
  353. /* sign extend offset */
  354. offset = opcode & OFFSET;
  355. offset <<= 16;
  356. offset >>= 16;
  357. vaddr = (unsigned long __user *)
  358. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  359. if ((unsigned long)vaddr & 3) {
  360. signal = SIGBUS;
  361. goto sig;
  362. }
  363. if (get_user(value, vaddr)) {
  364. signal = SIGSEGV;
  365. goto sig;
  366. }
  367. preempt_disable();
  368. if (ll_task == NULL || ll_task == current) {
  369. ll_bit = 1;
  370. } else {
  371. ll_bit = 0;
  372. }
  373. ll_task = current;
  374. preempt_enable();
  375. compute_return_epc(regs);
  376. regs->regs[(opcode & RT) >> 16] = value;
  377. return;
  378. sig:
  379. force_sig(signal, current);
  380. }
  381. static inline void simulate_sc(struct pt_regs *regs, unsigned int opcode)
  382. {
  383. unsigned long __user *vaddr;
  384. unsigned long reg;
  385. long offset;
  386. int signal = 0;
  387. /*
  388. * analyse the sc instruction that just caused a ri exception
  389. * and put the referenced address to addr.
  390. */
  391. /* sign extend offset */
  392. offset = opcode & OFFSET;
  393. offset <<= 16;
  394. offset >>= 16;
  395. vaddr = (unsigned long __user *)
  396. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  397. reg = (opcode & RT) >> 16;
  398. if ((unsigned long)vaddr & 3) {
  399. signal = SIGBUS;
  400. goto sig;
  401. }
  402. preempt_disable();
  403. if (ll_bit == 0 || ll_task != current) {
  404. compute_return_epc(regs);
  405. regs->regs[reg] = 0;
  406. preempt_enable();
  407. return;
  408. }
  409. preempt_enable();
  410. if (put_user(regs->regs[reg], vaddr)) {
  411. signal = SIGSEGV;
  412. goto sig;
  413. }
  414. compute_return_epc(regs);
  415. regs->regs[reg] = 1;
  416. return;
  417. sig:
  418. force_sig(signal, current);
  419. }
  420. /*
  421. * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
  422. * opcodes are supposed to result in coprocessor unusable exceptions if
  423. * executed on ll/sc-less processors. That's the theory. In practice a
  424. * few processors such as NEC's VR4100 throw reserved instruction exceptions
  425. * instead, so we're doing the emulation thing in both exception handlers.
  426. */
  427. static inline int simulate_llsc(struct pt_regs *regs)
  428. {
  429. unsigned int opcode;
  430. if (unlikely(get_insn_opcode(regs, &opcode)))
  431. return -EFAULT;
  432. if ((opcode & OPCODE) == LL) {
  433. simulate_ll(regs, opcode);
  434. return 0;
  435. }
  436. if ((opcode & OPCODE) == SC) {
  437. simulate_sc(regs, opcode);
  438. return 0;
  439. }
  440. return -EFAULT; /* Strange things going on ... */
  441. }
  442. /*
  443. * Simulate trapping 'rdhwr' instructions to provide user accessible
  444. * registers not implemented in hardware. The only current use of this
  445. * is the thread area pointer.
  446. */
  447. static inline int simulate_rdhwr(struct pt_regs *regs)
  448. {
  449. struct thread_info *ti = task_thread_info(current);
  450. unsigned int opcode;
  451. if (unlikely(get_insn_opcode(regs, &opcode)))
  452. return -EFAULT;
  453. if (unlikely(compute_return_epc(regs)))
  454. return -EFAULT;
  455. if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
  456. int rd = (opcode & RD) >> 11;
  457. int rt = (opcode & RT) >> 16;
  458. switch (rd) {
  459. case 29:
  460. regs->regs[rt] = ti->tp_value;
  461. return 0;
  462. default:
  463. return -EFAULT;
  464. }
  465. }
  466. /* Not ours. */
  467. return -EFAULT;
  468. }
  469. asmlinkage void do_ov(struct pt_regs *regs)
  470. {
  471. siginfo_t info;
  472. die_if_kernel("Integer overflow", regs);
  473. info.si_code = FPE_INTOVF;
  474. info.si_signo = SIGFPE;
  475. info.si_errno = 0;
  476. info.si_addr = (void __user *) regs->cp0_epc;
  477. force_sig_info(SIGFPE, &info, current);
  478. }
  479. /*
  480. * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
  481. */
  482. asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
  483. {
  484. if (fcr31 & FPU_CSR_UNI_X) {
  485. int sig;
  486. preempt_disable();
  487. #ifdef CONFIG_PREEMPT
  488. if (!is_fpu_owner()) {
  489. /* We might lose fpu before disabling preempt... */
  490. own_fpu();
  491. BUG_ON(!used_math());
  492. restore_fp(current);
  493. }
  494. #endif
  495. /*
  496. * Unimplemented operation exception. If we've got the full
  497. * software emulator on-board, let's use it...
  498. *
  499. * Force FPU to dump state into task/thread context. We're
  500. * moving a lot of data here for what is probably a single
  501. * instruction, but the alternative is to pre-decode the FP
  502. * register operands before invoking the emulator, which seems
  503. * a bit extreme for what should be an infrequent event.
  504. */
  505. save_fp(current);
  506. /* Ensure 'resume' not overwrite saved fp context again. */
  507. lose_fpu();
  508. preempt_enable();
  509. /* Run the emulator */
  510. sig = fpu_emulator_cop1Handler (regs, &current->thread.fpu);
  511. preempt_disable();
  512. own_fpu(); /* Using the FPU again. */
  513. /*
  514. * We can't allow the emulated instruction to leave any of
  515. * the cause bit set in $fcr31.
  516. */
  517. current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
  518. /* Restore the hardware register state */
  519. restore_fp(current);
  520. preempt_enable();
  521. /* If something went wrong, signal */
  522. if (sig)
  523. force_sig(sig, current);
  524. return;
  525. }
  526. force_sig(SIGFPE, current);
  527. }
  528. asmlinkage void do_bp(struct pt_regs *regs)
  529. {
  530. unsigned int opcode, bcode;
  531. siginfo_t info;
  532. die_if_kernel("Break instruction in kernel code", regs);
  533. if (get_insn_opcode(regs, &opcode))
  534. return;
  535. /*
  536. * There is the ancient bug in the MIPS assemblers that the break
  537. * code starts left to bit 16 instead to bit 6 in the opcode.
  538. * Gas is bug-compatible, but not always, grrr...
  539. * We handle both cases with a simple heuristics. --macro
  540. */
  541. bcode = ((opcode >> 6) & ((1 << 20) - 1));
  542. if (bcode < (1 << 10))
  543. bcode <<= 10;
  544. /*
  545. * (A short test says that IRIX 5.3 sends SIGTRAP for all break
  546. * insns, even for break codes that indicate arithmetic failures.
  547. * Weird ...)
  548. * But should we continue the brokenness??? --macro
  549. */
  550. switch (bcode) {
  551. case BRK_OVERFLOW << 10:
  552. case BRK_DIVZERO << 10:
  553. if (bcode == (BRK_DIVZERO << 10))
  554. info.si_code = FPE_INTDIV;
  555. else
  556. info.si_code = FPE_INTOVF;
  557. info.si_signo = SIGFPE;
  558. info.si_errno = 0;
  559. info.si_addr = (void __user *) regs->cp0_epc;
  560. force_sig_info(SIGFPE, &info, current);
  561. break;
  562. default:
  563. force_sig(SIGTRAP, current);
  564. }
  565. }
  566. asmlinkage void do_tr(struct pt_regs *regs)
  567. {
  568. unsigned int opcode, tcode = 0;
  569. siginfo_t info;
  570. die_if_kernel("Trap instruction in kernel code", regs);
  571. if (get_insn_opcode(regs, &opcode))
  572. return;
  573. /* Immediate versions don't provide a code. */
  574. if (!(opcode & OPCODE))
  575. tcode = ((opcode >> 6) & ((1 << 10) - 1));
  576. /*
  577. * (A short test says that IRIX 5.3 sends SIGTRAP for all trap
  578. * insns, even for trap codes that indicate arithmetic failures.
  579. * Weird ...)
  580. * But should we continue the brokenness??? --macro
  581. */
  582. switch (tcode) {
  583. case BRK_OVERFLOW:
  584. case BRK_DIVZERO:
  585. if (tcode == BRK_DIVZERO)
  586. info.si_code = FPE_INTDIV;
  587. else
  588. info.si_code = FPE_INTOVF;
  589. info.si_signo = SIGFPE;
  590. info.si_errno = 0;
  591. info.si_addr = (void __user *) regs->cp0_epc;
  592. force_sig_info(SIGFPE, &info, current);
  593. break;
  594. default:
  595. force_sig(SIGTRAP, current);
  596. }
  597. }
  598. asmlinkage void do_ri(struct pt_regs *regs)
  599. {
  600. die_if_kernel("Reserved instruction in kernel code", regs);
  601. if (!cpu_has_llsc)
  602. if (!simulate_llsc(regs))
  603. return;
  604. if (!simulate_rdhwr(regs))
  605. return;
  606. force_sig(SIGILL, current);
  607. }
  608. asmlinkage void do_cpu(struct pt_regs *regs)
  609. {
  610. unsigned int cpid;
  611. die_if_kernel("do_cpu invoked from kernel context!", regs);
  612. cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
  613. switch (cpid) {
  614. case 0:
  615. if (!cpu_has_llsc)
  616. if (!simulate_llsc(regs))
  617. return;
  618. if (!simulate_rdhwr(regs))
  619. return;
  620. break;
  621. case 1:
  622. preempt_disable();
  623. own_fpu();
  624. if (used_math()) { /* Using the FPU again. */
  625. restore_fp(current);
  626. } else { /* First time FPU user. */
  627. init_fpu();
  628. set_used_math();
  629. }
  630. preempt_enable();
  631. if (!cpu_has_fpu) {
  632. int sig = fpu_emulator_cop1Handler(regs,
  633. &current->thread.fpu);
  634. if (sig)
  635. force_sig(sig, current);
  636. #ifdef CONFIG_MIPS_MT_FPAFF
  637. else {
  638. /*
  639. * MIPS MT processors may have fewer FPU contexts
  640. * than CPU threads. If we've emulated more than
  641. * some threshold number of instructions, force
  642. * migration to a "CPU" that has FP support.
  643. */
  644. if(mt_fpemul_threshold > 0
  645. && ((current->thread.emulated_fp++
  646. > mt_fpemul_threshold))) {
  647. /*
  648. * If there's no FPU present, or if the
  649. * application has already restricted
  650. * the allowed set to exclude any CPUs
  651. * with FPUs, we'll skip the procedure.
  652. */
  653. if (cpus_intersects(current->cpus_allowed,
  654. mt_fpu_cpumask)) {
  655. cpumask_t tmask;
  656. cpus_and(tmask,
  657. current->thread.user_cpus_allowed,
  658. mt_fpu_cpumask);
  659. set_cpus_allowed(current, tmask);
  660. current->thread.mflags |= MF_FPUBOUND;
  661. }
  662. }
  663. }
  664. #endif /* CONFIG_MIPS_MT_FPAFF */
  665. }
  666. return;
  667. case 2:
  668. case 3:
  669. die_if_kernel("do_cpu invoked from kernel context!", regs);
  670. break;
  671. }
  672. force_sig(SIGILL, current);
  673. }
  674. asmlinkage void do_mdmx(struct pt_regs *regs)
  675. {
  676. force_sig(SIGILL, current);
  677. }
  678. asmlinkage void do_watch(struct pt_regs *regs)
  679. {
  680. /*
  681. * We use the watch exception where available to detect stack
  682. * overflows.
  683. */
  684. dump_tlb_all();
  685. show_regs(regs);
  686. panic("Caught WATCH exception - probably caused by stack overflow.");
  687. }
  688. asmlinkage void do_mcheck(struct pt_regs *regs)
  689. {
  690. const int field = 2 * sizeof(unsigned long);
  691. int multi_match = regs->cp0_status & ST0_TS;
  692. show_regs(regs);
  693. if (multi_match) {
  694. printk("Index : %0x\n", read_c0_index());
  695. printk("Pagemask: %0x\n", read_c0_pagemask());
  696. printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
  697. printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
  698. printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
  699. printk("\n");
  700. dump_tlb_all();
  701. }
  702. show_code((unsigned int *) regs->cp0_epc);
  703. /*
  704. * Some chips may have other causes of machine check (e.g. SB1
  705. * graduation timer)
  706. */
  707. panic("Caught Machine Check exception - %scaused by multiple "
  708. "matching entries in the TLB.",
  709. (multi_match) ? "" : "not ");
  710. }
  711. asmlinkage void do_mt(struct pt_regs *regs)
  712. {
  713. int subcode;
  714. die_if_kernel("MIPS MT Thread exception in kernel", regs);
  715. subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
  716. >> VPECONTROL_EXCPT_SHIFT;
  717. switch (subcode) {
  718. case 0:
  719. printk(KERN_ERR "Thread Underflow\n");
  720. break;
  721. case 1:
  722. printk(KERN_ERR "Thread Overflow\n");
  723. break;
  724. case 2:
  725. printk(KERN_ERR "Invalid YIELD Qualifier\n");
  726. break;
  727. case 3:
  728. printk(KERN_ERR "Gating Storage Exception\n");
  729. break;
  730. case 4:
  731. printk(KERN_ERR "YIELD Scheduler Exception\n");
  732. break;
  733. case 5:
  734. printk(KERN_ERR "Gating Storage Schedulier Exception\n");
  735. break;
  736. default:
  737. printk(KERN_ERR "*** UNKNOWN THREAD EXCEPTION %d ***\n",
  738. subcode);
  739. break;
  740. }
  741. die_if_kernel("MIPS MT Thread exception in kernel", regs);
  742. force_sig(SIGILL, current);
  743. }
  744. asmlinkage void do_dsp(struct pt_regs *regs)
  745. {
  746. if (cpu_has_dsp)
  747. panic("Unexpected DSP exception\n");
  748. force_sig(SIGILL, current);
  749. }
  750. asmlinkage void do_reserved(struct pt_regs *regs)
  751. {
  752. /*
  753. * Game over - no way to handle this if it ever occurs. Most probably
  754. * caused by a new unknown cpu type or after another deadly
  755. * hard/software error.
  756. */
  757. show_regs(regs);
  758. panic("Caught reserved exception %ld - should not happen.",
  759. (regs->cp0_cause & 0x7f) >> 2);
  760. }
  761. asmlinkage void do_default_vi(struct pt_regs *regs)
  762. {
  763. show_regs(regs);
  764. panic("Caught unexpected vectored interrupt.");
  765. }
  766. /*
  767. * Some MIPS CPUs can enable/disable for cache parity detection, but do
  768. * it different ways.
  769. */
  770. static inline void parity_protection_init(void)
  771. {
  772. switch (current_cpu_data.cputype) {
  773. case CPU_24K:
  774. case CPU_34K:
  775. case CPU_5KC:
  776. write_c0_ecc(0x80000000);
  777. back_to_back_c0_hazard();
  778. /* Set the PE bit (bit 31) in the c0_errctl register. */
  779. printk(KERN_INFO "Cache parity protection %sabled\n",
  780. (read_c0_ecc() & 0x80000000) ? "en" : "dis");
  781. break;
  782. case CPU_20KC:
  783. case CPU_25KF:
  784. /* Clear the DE bit (bit 16) in the c0_status register. */
  785. printk(KERN_INFO "Enable cache parity protection for "
  786. "MIPS 20KC/25KF CPUs.\n");
  787. clear_c0_status(ST0_DE);
  788. break;
  789. default:
  790. break;
  791. }
  792. }
  793. asmlinkage void cache_parity_error(void)
  794. {
  795. const int field = 2 * sizeof(unsigned long);
  796. unsigned int reg_val;
  797. /* For the moment, report the problem and hang. */
  798. printk("Cache error exception:\n");
  799. printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
  800. reg_val = read_c0_cacheerr();
  801. printk("c0_cacheerr == %08x\n", reg_val);
  802. printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
  803. reg_val & (1<<30) ? "secondary" : "primary",
  804. reg_val & (1<<31) ? "data" : "insn");
  805. printk("Error bits: %s%s%s%s%s%s%s\n",
  806. reg_val & (1<<29) ? "ED " : "",
  807. reg_val & (1<<28) ? "ET " : "",
  808. reg_val & (1<<26) ? "EE " : "",
  809. reg_val & (1<<25) ? "EB " : "",
  810. reg_val & (1<<24) ? "EI " : "",
  811. reg_val & (1<<23) ? "E1 " : "",
  812. reg_val & (1<<22) ? "E0 " : "");
  813. printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
  814. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  815. if (reg_val & (1<<22))
  816. printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
  817. if (reg_val & (1<<23))
  818. printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
  819. #endif
  820. panic("Can't handle the cache error!");
  821. }
  822. /*
  823. * SDBBP EJTAG debug exception handler.
  824. * We skip the instruction and return to the next instruction.
  825. */
  826. void ejtag_exception_handler(struct pt_regs *regs)
  827. {
  828. const int field = 2 * sizeof(unsigned long);
  829. unsigned long depc, old_epc;
  830. unsigned int debug;
  831. printk("SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
  832. depc = read_c0_depc();
  833. debug = read_c0_debug();
  834. printk("c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
  835. if (debug & 0x80000000) {
  836. /*
  837. * In branch delay slot.
  838. * We cheat a little bit here and use EPC to calculate the
  839. * debug return address (DEPC). EPC is restored after the
  840. * calculation.
  841. */
  842. old_epc = regs->cp0_epc;
  843. regs->cp0_epc = depc;
  844. __compute_return_epc(regs);
  845. depc = regs->cp0_epc;
  846. regs->cp0_epc = old_epc;
  847. } else
  848. depc += 4;
  849. write_c0_depc(depc);
  850. #if 0
  851. printk("\n\n----- Enable EJTAG single stepping ----\n\n");
  852. write_c0_debug(debug | 0x100);
  853. #endif
  854. }
  855. /*
  856. * NMI exception handler.
  857. */
  858. void nmi_exception_handler(struct pt_regs *regs)
  859. {
  860. #ifdef CONFIG_MIPS_MT_SMTC
  861. unsigned long dvpret = dvpe();
  862. bust_spinlocks(1);
  863. printk("NMI taken!!!!\n");
  864. mips_mt_regdump(dvpret);
  865. #else
  866. bust_spinlocks(1);
  867. printk("NMI taken!!!!\n");
  868. #endif /* CONFIG_MIPS_MT_SMTC */
  869. die("NMI", regs);
  870. while(1) ;
  871. }
  872. #define VECTORSPACING 0x100 /* for EI/VI mode */
  873. unsigned long ebase;
  874. unsigned long exception_handlers[32];
  875. unsigned long vi_handlers[64];
  876. /*
  877. * As a side effect of the way this is implemented we're limited
  878. * to interrupt handlers in the address range from
  879. * KSEG0 <= x < KSEG0 + 256mb on the Nevada. Oh well ...
  880. */
  881. void *set_except_vector(int n, void *addr)
  882. {
  883. unsigned long handler = (unsigned long) addr;
  884. unsigned long old_handler = exception_handlers[n];
  885. exception_handlers[n] = handler;
  886. if (n == 0 && cpu_has_divec) {
  887. *(volatile u32 *)(ebase + 0x200) = 0x08000000 |
  888. (0x03ffffff & (handler >> 2));
  889. flush_icache_range(ebase + 0x200, ebase + 0x204);
  890. }
  891. return (void *)old_handler;
  892. }
  893. #ifdef CONFIG_CPU_MIPSR2
  894. /*
  895. * MIPSR2 shadow register set allocation
  896. * FIXME: SMP...
  897. */
  898. static struct shadow_registers {
  899. /*
  900. * Number of shadow register sets supported
  901. */
  902. unsigned long sr_supported;
  903. /*
  904. * Bitmap of allocated shadow registers
  905. */
  906. unsigned long sr_allocated;
  907. } shadow_registers;
  908. static void mips_srs_init(void)
  909. {
  910. #ifdef CONFIG_CPU_MIPSR2_SRS
  911. shadow_registers.sr_supported = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  912. printk(KERN_INFO "%d MIPSR2 register sets available\n",
  913. shadow_registers.sr_supported);
  914. #endif
  915. shadow_registers.sr_allocated = 1; /* Set 0 used by kernel */
  916. }
  917. int mips_srs_max(void)
  918. {
  919. return shadow_registers.sr_supported;
  920. }
  921. int mips_srs_alloc(void)
  922. {
  923. struct shadow_registers *sr = &shadow_registers;
  924. int set;
  925. again:
  926. set = find_first_zero_bit(&sr->sr_allocated, sr->sr_supported);
  927. if (set >= sr->sr_supported)
  928. return -1;
  929. if (test_and_set_bit(set, &sr->sr_allocated))
  930. goto again;
  931. return set;
  932. }
  933. void mips_srs_free(int set)
  934. {
  935. struct shadow_registers *sr = &shadow_registers;
  936. clear_bit(set, &sr->sr_allocated);
  937. }
  938. static void *set_vi_srs_handler(int n, void *addr, int srs)
  939. {
  940. unsigned long handler;
  941. unsigned long old_handler = vi_handlers[n];
  942. u32 *w;
  943. unsigned char *b;
  944. if (!cpu_has_veic && !cpu_has_vint)
  945. BUG();
  946. if (addr == NULL) {
  947. handler = (unsigned long) do_default_vi;
  948. srs = 0;
  949. } else
  950. handler = (unsigned long) addr;
  951. vi_handlers[n] = (unsigned long) addr;
  952. b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
  953. if (srs >= mips_srs_max())
  954. panic("Shadow register set %d not supported", srs);
  955. if (cpu_has_veic) {
  956. if (board_bind_eic_interrupt)
  957. board_bind_eic_interrupt (n, srs);
  958. } else if (cpu_has_vint) {
  959. /* SRSMap is only defined if shadow sets are implemented */
  960. if (mips_srs_max() > 1)
  961. change_c0_srsmap (0xf << n*4, srs << n*4);
  962. }
  963. if (srs == 0) {
  964. /*
  965. * If no shadow set is selected then use the default handler
  966. * that does normal register saving and a standard interrupt exit
  967. */
  968. extern char except_vec_vi, except_vec_vi_lui;
  969. extern char except_vec_vi_ori, except_vec_vi_end;
  970. #ifdef CONFIG_MIPS_MT_SMTC
  971. /*
  972. * We need to provide the SMTC vectored interrupt handler
  973. * not only with the address of the handler, but with the
  974. * Status.IM bit to be masked before going there.
  975. */
  976. extern char except_vec_vi_mori;
  977. const int mori_offset = &except_vec_vi_mori - &except_vec_vi;
  978. #endif /* CONFIG_MIPS_MT_SMTC */
  979. const int handler_len = &except_vec_vi_end - &except_vec_vi;
  980. const int lui_offset = &except_vec_vi_lui - &except_vec_vi;
  981. const int ori_offset = &except_vec_vi_ori - &except_vec_vi;
  982. if (handler_len > VECTORSPACING) {
  983. /*
  984. * Sigh... panicing won't help as the console
  985. * is probably not configured :(
  986. */
  987. panic ("VECTORSPACING too small");
  988. }
  989. memcpy (b, &except_vec_vi, handler_len);
  990. #ifdef CONFIG_MIPS_MT_SMTC
  991. if (n > 7)
  992. printk("Vector index %d exceeds SMTC maximum\n", n);
  993. w = (u32 *)(b + mori_offset);
  994. *w = (*w & 0xffff0000) | (0x100 << n);
  995. #endif /* CONFIG_MIPS_MT_SMTC */
  996. w = (u32 *)(b + lui_offset);
  997. *w = (*w & 0xffff0000) | (((u32)handler >> 16) & 0xffff);
  998. w = (u32 *)(b + ori_offset);
  999. *w = (*w & 0xffff0000) | ((u32)handler & 0xffff);
  1000. flush_icache_range((unsigned long)b, (unsigned long)(b+handler_len));
  1001. }
  1002. else {
  1003. /*
  1004. * In other cases jump directly to the interrupt handler
  1005. *
  1006. * It is the handlers responsibility to save registers if required
  1007. * (eg hi/lo) and return from the exception using "eret"
  1008. */
  1009. w = (u32 *)b;
  1010. *w++ = 0x08000000 | (((u32)handler >> 2) & 0x03fffff); /* j handler */
  1011. *w = 0;
  1012. flush_icache_range((unsigned long)b, (unsigned long)(b+8));
  1013. }
  1014. return (void *)old_handler;
  1015. }
  1016. void *set_vi_handler(int n, void *addr)
  1017. {
  1018. return set_vi_srs_handler(n, addr, 0);
  1019. }
  1020. #endif
  1021. /*
  1022. * This is used by native signal handling
  1023. */
  1024. asmlinkage int (*save_fp_context)(struct sigcontext *sc);
  1025. asmlinkage int (*restore_fp_context)(struct sigcontext *sc);
  1026. extern asmlinkage int _save_fp_context(struct sigcontext *sc);
  1027. extern asmlinkage int _restore_fp_context(struct sigcontext *sc);
  1028. extern asmlinkage int fpu_emulator_save_context(struct sigcontext *sc);
  1029. extern asmlinkage int fpu_emulator_restore_context(struct sigcontext *sc);
  1030. #ifdef CONFIG_SMP
  1031. static int smp_save_fp_context(struct sigcontext *sc)
  1032. {
  1033. return cpu_has_fpu
  1034. ? _save_fp_context(sc)
  1035. : fpu_emulator_save_context(sc);
  1036. }
  1037. static int smp_restore_fp_context(struct sigcontext *sc)
  1038. {
  1039. return cpu_has_fpu
  1040. ? _restore_fp_context(sc)
  1041. : fpu_emulator_restore_context(sc);
  1042. }
  1043. #endif
  1044. static inline void signal_init(void)
  1045. {
  1046. #ifdef CONFIG_SMP
  1047. /* For now just do the cpu_has_fpu check when the functions are invoked */
  1048. save_fp_context = smp_save_fp_context;
  1049. restore_fp_context = smp_restore_fp_context;
  1050. #else
  1051. if (cpu_has_fpu) {
  1052. save_fp_context = _save_fp_context;
  1053. restore_fp_context = _restore_fp_context;
  1054. } else {
  1055. save_fp_context = fpu_emulator_save_context;
  1056. restore_fp_context = fpu_emulator_restore_context;
  1057. }
  1058. #endif
  1059. }
  1060. #ifdef CONFIG_MIPS32_COMPAT
  1061. /*
  1062. * This is used by 32-bit signal stuff on the 64-bit kernel
  1063. */
  1064. asmlinkage int (*save_fp_context32)(struct sigcontext32 *sc);
  1065. asmlinkage int (*restore_fp_context32)(struct sigcontext32 *sc);
  1066. extern asmlinkage int _save_fp_context32(struct sigcontext32 *sc);
  1067. extern asmlinkage int _restore_fp_context32(struct sigcontext32 *sc);
  1068. extern asmlinkage int fpu_emulator_save_context32(struct sigcontext32 *sc);
  1069. extern asmlinkage int fpu_emulator_restore_context32(struct sigcontext32 *sc);
  1070. static inline void signal32_init(void)
  1071. {
  1072. if (cpu_has_fpu) {
  1073. save_fp_context32 = _save_fp_context32;
  1074. restore_fp_context32 = _restore_fp_context32;
  1075. } else {
  1076. save_fp_context32 = fpu_emulator_save_context32;
  1077. restore_fp_context32 = fpu_emulator_restore_context32;
  1078. }
  1079. }
  1080. #endif
  1081. extern void cpu_cache_init(void);
  1082. extern void tlb_init(void);
  1083. extern void flush_tlb_handlers(void);
  1084. void __init per_cpu_trap_init(void)
  1085. {
  1086. unsigned int cpu = smp_processor_id();
  1087. unsigned int status_set = ST0_CU0;
  1088. #ifdef CONFIG_MIPS_MT_SMTC
  1089. int secondaryTC = 0;
  1090. int bootTC = (cpu == 0);
  1091. /*
  1092. * Only do per_cpu_trap_init() for first TC of Each VPE.
  1093. * Note that this hack assumes that the SMTC init code
  1094. * assigns TCs consecutively and in ascending order.
  1095. */
  1096. if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
  1097. ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
  1098. secondaryTC = 1;
  1099. #endif /* CONFIG_MIPS_MT_SMTC */
  1100. /*
  1101. * Disable coprocessors and select 32-bit or 64-bit addressing
  1102. * and the 16/32 or 32/32 FPR register model. Reset the BEV
  1103. * flag that some firmware may have left set and the TS bit (for
  1104. * IP27). Set XX for ISA IV code to work.
  1105. */
  1106. #ifdef CONFIG_64BIT
  1107. status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
  1108. #endif
  1109. if (current_cpu_data.isa_level == MIPS_CPU_ISA_IV)
  1110. status_set |= ST0_XX;
  1111. change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
  1112. status_set);
  1113. if (cpu_has_dsp)
  1114. set_c0_status(ST0_MX);
  1115. #ifdef CONFIG_CPU_MIPSR2
  1116. write_c0_hwrena (0x0000000f); /* Allow rdhwr to all registers */
  1117. #endif
  1118. #ifdef CONFIG_MIPS_MT_SMTC
  1119. if (!secondaryTC) {
  1120. #endif /* CONFIG_MIPS_MT_SMTC */
  1121. /*
  1122. * Interrupt handling.
  1123. */
  1124. if (cpu_has_veic || cpu_has_vint) {
  1125. write_c0_ebase (ebase);
  1126. /* Setting vector spacing enables EI/VI mode */
  1127. change_c0_intctl (0x3e0, VECTORSPACING);
  1128. }
  1129. if (cpu_has_divec) {
  1130. if (cpu_has_mipsmt) {
  1131. unsigned int vpflags = dvpe();
  1132. set_c0_cause(CAUSEF_IV);
  1133. evpe(vpflags);
  1134. } else
  1135. set_c0_cause(CAUSEF_IV);
  1136. }
  1137. #ifdef CONFIG_MIPS_MT_SMTC
  1138. }
  1139. #endif /* CONFIG_MIPS_MT_SMTC */
  1140. cpu_data[cpu].asid_cache = ASID_FIRST_VERSION;
  1141. TLBMISS_HANDLER_SETUP();
  1142. atomic_inc(&init_mm.mm_count);
  1143. current->active_mm = &init_mm;
  1144. BUG_ON(current->mm);
  1145. enter_lazy_tlb(&init_mm, current);
  1146. #ifdef CONFIG_MIPS_MT_SMTC
  1147. if (bootTC) {
  1148. #endif /* CONFIG_MIPS_MT_SMTC */
  1149. cpu_cache_init();
  1150. tlb_init();
  1151. #ifdef CONFIG_MIPS_MT_SMTC
  1152. }
  1153. #endif /* CONFIG_MIPS_MT_SMTC */
  1154. }
  1155. /* Install CPU exception handler */
  1156. void __init set_handler (unsigned long offset, void *addr, unsigned long size)
  1157. {
  1158. memcpy((void *)(ebase + offset), addr, size);
  1159. flush_icache_range(ebase + offset, ebase + offset + size);
  1160. }
  1161. /* Install uncached CPU exception handler */
  1162. void __init set_uncached_handler (unsigned long offset, void *addr, unsigned long size)
  1163. {
  1164. #ifdef CONFIG_32BIT
  1165. unsigned long uncached_ebase = KSEG1ADDR(ebase);
  1166. #endif
  1167. #ifdef CONFIG_64BIT
  1168. unsigned long uncached_ebase = TO_UNCAC(ebase);
  1169. #endif
  1170. memcpy((void *)(uncached_ebase + offset), addr, size);
  1171. }
  1172. void __init trap_init(void)
  1173. {
  1174. extern char except_vec3_generic, except_vec3_r4000;
  1175. extern char except_vec4;
  1176. unsigned long i;
  1177. if (cpu_has_veic || cpu_has_vint)
  1178. ebase = (unsigned long) alloc_bootmem_low_pages (0x200 + VECTORSPACING*64);
  1179. else
  1180. ebase = CAC_BASE;
  1181. #ifdef CONFIG_CPU_MIPSR2
  1182. mips_srs_init();
  1183. #endif
  1184. per_cpu_trap_init();
  1185. /*
  1186. * Copy the generic exception handlers to their final destination.
  1187. * This will be overriden later as suitable for a particular
  1188. * configuration.
  1189. */
  1190. set_handler(0x180, &except_vec3_generic, 0x80);
  1191. /*
  1192. * Setup default vectors
  1193. */
  1194. for (i = 0; i <= 31; i++)
  1195. set_except_vector(i, handle_reserved);
  1196. /*
  1197. * Copy the EJTAG debug exception vector handler code to it's final
  1198. * destination.
  1199. */
  1200. if (cpu_has_ejtag && board_ejtag_handler_setup)
  1201. board_ejtag_handler_setup ();
  1202. /*
  1203. * Only some CPUs have the watch exceptions.
  1204. */
  1205. if (cpu_has_watch)
  1206. set_except_vector(23, handle_watch);
  1207. /*
  1208. * Initialise interrupt handlers
  1209. */
  1210. if (cpu_has_veic || cpu_has_vint) {
  1211. int nvec = cpu_has_veic ? 64 : 8;
  1212. for (i = 0; i < nvec; i++)
  1213. set_vi_handler(i, NULL);
  1214. }
  1215. else if (cpu_has_divec)
  1216. set_handler(0x200, &except_vec4, 0x8);
  1217. /*
  1218. * Some CPUs can enable/disable for cache parity detection, but does
  1219. * it different ways.
  1220. */
  1221. parity_protection_init();
  1222. /*
  1223. * The Data Bus Errors / Instruction Bus Errors are signaled
  1224. * by external hardware. Therefore these two exceptions
  1225. * may have board specific handlers.
  1226. */
  1227. if (board_be_init)
  1228. board_be_init();
  1229. set_except_vector(0, handle_int);
  1230. set_except_vector(1, handle_tlbm);
  1231. set_except_vector(2, handle_tlbl);
  1232. set_except_vector(3, handle_tlbs);
  1233. set_except_vector(4, handle_adel);
  1234. set_except_vector(5, handle_ades);
  1235. set_except_vector(6, handle_ibe);
  1236. set_except_vector(7, handle_dbe);
  1237. set_except_vector(8, handle_sys);
  1238. set_except_vector(9, handle_bp);
  1239. set_except_vector(10, handle_ri);
  1240. set_except_vector(11, handle_cpu);
  1241. set_except_vector(12, handle_ov);
  1242. set_except_vector(13, handle_tr);
  1243. if (current_cpu_data.cputype == CPU_R6000 ||
  1244. current_cpu_data.cputype == CPU_R6000A) {
  1245. /*
  1246. * The R6000 is the only R-series CPU that features a machine
  1247. * check exception (similar to the R4000 cache error) and
  1248. * unaligned ldc1/sdc1 exception. The handlers have not been
  1249. * written yet. Well, anyway there is no R6000 machine on the
  1250. * current list of targets for Linux/MIPS.
  1251. * (Duh, crap, there is someone with a triple R6k machine)
  1252. */
  1253. //set_except_vector(14, handle_mc);
  1254. //set_except_vector(15, handle_ndc);
  1255. }
  1256. if (board_nmi_handler_setup)
  1257. board_nmi_handler_setup();
  1258. if (cpu_has_fpu && !cpu_has_nofpuex)
  1259. set_except_vector(15, handle_fpe);
  1260. set_except_vector(22, handle_mdmx);
  1261. if (cpu_has_mcheck)
  1262. set_except_vector(24, handle_mcheck);
  1263. if (cpu_has_mipsmt)
  1264. set_except_vector(25, handle_mt);
  1265. if (cpu_has_dsp)
  1266. set_except_vector(26, handle_dsp);
  1267. if (cpu_has_vce)
  1268. /* Special exception: R4[04]00 uses also the divec space. */
  1269. memcpy((void *)(CAC_BASE + 0x180), &except_vec3_r4000, 0x100);
  1270. else if (cpu_has_4kex)
  1271. memcpy((void *)(CAC_BASE + 0x180), &except_vec3_generic, 0x80);
  1272. else
  1273. memcpy((void *)(CAC_BASE + 0x080), &except_vec3_generic, 0x80);
  1274. signal_init();
  1275. #ifdef CONFIG_MIPS32_COMPAT
  1276. signal32_init();
  1277. #endif
  1278. flush_icache_range(ebase, ebase + 0x400);
  1279. flush_tlb_handlers();
  1280. }