traps.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972
  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) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
  12. * Copyright (C) 2000, 2001, 2012 MIPS Technologies, Inc. All rights reserved.
  13. */
  14. #include <linux/bug.h>
  15. #include <linux/compiler.h>
  16. #include <linux/kexec.h>
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/mm.h>
  21. #include <linux/sched.h>
  22. #include <linux/smp.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/kallsyms.h>
  25. #include <linux/bootmem.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/ptrace.h>
  28. #include <linux/kgdb.h>
  29. #include <linux/kdebug.h>
  30. #include <linux/kprobes.h>
  31. #include <linux/notifier.h>
  32. #include <linux/kdb.h>
  33. #include <linux/irq.h>
  34. #include <linux/perf_event.h>
  35. #include <asm/bootinfo.h>
  36. #include <asm/branch.h>
  37. #include <asm/break.h>
  38. #include <asm/cop2.h>
  39. #include <asm/cpu.h>
  40. #include <asm/dsp.h>
  41. #include <asm/fpu.h>
  42. #include <asm/fpu_emulator.h>
  43. #include <asm/mipsregs.h>
  44. #include <asm/mipsmtregs.h>
  45. #include <asm/module.h>
  46. #include <asm/pgtable.h>
  47. #include <asm/ptrace.h>
  48. #include <asm/sections.h>
  49. #include <asm/tlbdebug.h>
  50. #include <asm/traps.h>
  51. #include <asm/uaccess.h>
  52. #include <asm/watch.h>
  53. #include <asm/mmu_context.h>
  54. #include <asm/types.h>
  55. #include <asm/stacktrace.h>
  56. #include <asm/uasm.h>
  57. extern void check_wait(void);
  58. extern asmlinkage void r4k_wait(void);
  59. extern asmlinkage void rollback_handle_int(void);
  60. extern asmlinkage void handle_int(void);
  61. extern asmlinkage void handle_tlbm(void);
  62. extern asmlinkage void handle_tlbl(void);
  63. extern asmlinkage void handle_tlbs(void);
  64. extern asmlinkage void handle_adel(void);
  65. extern asmlinkage void handle_ades(void);
  66. extern asmlinkage void handle_ibe(void);
  67. extern asmlinkage void handle_dbe(void);
  68. extern asmlinkage void handle_sys(void);
  69. extern asmlinkage void handle_bp(void);
  70. extern asmlinkage void handle_ri(void);
  71. extern asmlinkage void handle_ri_rdhwr_vivt(void);
  72. extern asmlinkage void handle_ri_rdhwr(void);
  73. extern asmlinkage void handle_cpu(void);
  74. extern asmlinkage void handle_ov(void);
  75. extern asmlinkage void handle_tr(void);
  76. extern asmlinkage void handle_fpe(void);
  77. extern asmlinkage void handle_mdmx(void);
  78. extern asmlinkage void handle_watch(void);
  79. extern asmlinkage void handle_mt(void);
  80. extern asmlinkage void handle_dsp(void);
  81. extern asmlinkage void handle_mcheck(void);
  82. extern asmlinkage void handle_reserved(void);
  83. void (*board_be_init)(void);
  84. int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
  85. void (*board_nmi_handler_setup)(void);
  86. void (*board_ejtag_handler_setup)(void);
  87. void (*board_bind_eic_interrupt)(int irq, int regset);
  88. void (*board_ebase_setup)(void);
  89. void __cpuinitdata(*board_cache_error_setup)(void);
  90. static void show_raw_backtrace(unsigned long reg29)
  91. {
  92. unsigned long *sp = (unsigned long *)(reg29 & ~3);
  93. unsigned long addr;
  94. printk("Call Trace:");
  95. #ifdef CONFIG_KALLSYMS
  96. printk("\n");
  97. #endif
  98. while (!kstack_end(sp)) {
  99. unsigned long __user *p =
  100. (unsigned long __user *)(unsigned long)sp++;
  101. if (__get_user(addr, p)) {
  102. printk(" (Bad stack address)");
  103. break;
  104. }
  105. if (__kernel_text_address(addr))
  106. print_ip_sym(addr);
  107. }
  108. printk("\n");
  109. }
  110. #ifdef CONFIG_KALLSYMS
  111. int raw_show_trace;
  112. static int __init set_raw_show_trace(char *str)
  113. {
  114. raw_show_trace = 1;
  115. return 1;
  116. }
  117. __setup("raw_show_trace", set_raw_show_trace);
  118. #endif
  119. static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
  120. {
  121. unsigned long sp = regs->regs[29];
  122. unsigned long ra = regs->regs[31];
  123. unsigned long pc = regs->cp0_epc;
  124. if (!task)
  125. task = current;
  126. if (raw_show_trace || !__kernel_text_address(pc)) {
  127. show_raw_backtrace(sp);
  128. return;
  129. }
  130. printk("Call Trace:\n");
  131. do {
  132. print_ip_sym(pc);
  133. pc = unwind_stack(task, &sp, pc, &ra);
  134. } while (pc);
  135. printk("\n");
  136. }
  137. /*
  138. * This routine abuses get_user()/put_user() to reference pointers
  139. * with at least a bit of error checking ...
  140. */
  141. static void show_stacktrace(struct task_struct *task,
  142. const struct pt_regs *regs)
  143. {
  144. const int field = 2 * sizeof(unsigned long);
  145. long stackdata;
  146. int i;
  147. unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
  148. printk("Stack :");
  149. i = 0;
  150. while ((unsigned long) sp & (PAGE_SIZE - 1)) {
  151. if (i && ((i % (64 / field)) == 0))
  152. printk("\n ");
  153. if (i > 39) {
  154. printk(" ...");
  155. break;
  156. }
  157. if (__get_user(stackdata, sp++)) {
  158. printk(" (Bad stack address)");
  159. break;
  160. }
  161. printk(" %0*lx", field, stackdata);
  162. i++;
  163. }
  164. printk("\n");
  165. show_backtrace(task, regs);
  166. }
  167. void show_stack(struct task_struct *task, unsigned long *sp)
  168. {
  169. struct pt_regs regs;
  170. if (sp) {
  171. regs.regs[29] = (unsigned long)sp;
  172. regs.regs[31] = 0;
  173. regs.cp0_epc = 0;
  174. } else {
  175. if (task && task != current) {
  176. regs.regs[29] = task->thread.reg29;
  177. regs.regs[31] = 0;
  178. regs.cp0_epc = task->thread.reg31;
  179. #ifdef CONFIG_KGDB_KDB
  180. } else if (atomic_read(&kgdb_active) != -1 &&
  181. kdb_current_regs) {
  182. memcpy(&regs, kdb_current_regs, sizeof(regs));
  183. #endif /* CONFIG_KGDB_KDB */
  184. } else {
  185. prepare_frametrace(&regs);
  186. }
  187. }
  188. show_stacktrace(task, &regs);
  189. }
  190. /*
  191. * The architecture-independent dump_stack generator
  192. */
  193. void dump_stack(void)
  194. {
  195. struct pt_regs regs;
  196. prepare_frametrace(&regs);
  197. show_backtrace(current, &regs);
  198. }
  199. EXPORT_SYMBOL(dump_stack);
  200. static void show_code(unsigned int __user *pc)
  201. {
  202. long i;
  203. unsigned short __user *pc16 = NULL;
  204. printk("\nCode:");
  205. if ((unsigned long)pc & 1)
  206. pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
  207. for(i = -3 ; i < 6 ; i++) {
  208. unsigned int insn;
  209. if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
  210. printk(" (Bad address in epc)\n");
  211. break;
  212. }
  213. printk("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
  214. }
  215. }
  216. static void __show_regs(const struct pt_regs *regs)
  217. {
  218. const int field = 2 * sizeof(unsigned long);
  219. unsigned int cause = regs->cp0_cause;
  220. int i;
  221. printk("Cpu %d\n", smp_processor_id());
  222. /*
  223. * Saved main processor registers
  224. */
  225. for (i = 0; i < 32; ) {
  226. if ((i % 4) == 0)
  227. printk("$%2d :", i);
  228. if (i == 0)
  229. printk(" %0*lx", field, 0UL);
  230. else if (i == 26 || i == 27)
  231. printk(" %*s", field, "");
  232. else
  233. printk(" %0*lx", field, regs->regs[i]);
  234. i++;
  235. if ((i % 4) == 0)
  236. printk("\n");
  237. }
  238. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  239. printk("Acx : %0*lx\n", field, regs->acx);
  240. #endif
  241. printk("Hi : %0*lx\n", field, regs->hi);
  242. printk("Lo : %0*lx\n", field, regs->lo);
  243. /*
  244. * Saved cp0 registers
  245. */
  246. printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
  247. (void *) regs->cp0_epc);
  248. printk(" %s\n", print_tainted());
  249. printk("ra : %0*lx %pS\n", field, regs->regs[31],
  250. (void *) regs->regs[31]);
  251. printk("Status: %08x ", (uint32_t) regs->cp0_status);
  252. if (current_cpu_data.isa_level == MIPS_CPU_ISA_I) {
  253. if (regs->cp0_status & ST0_KUO)
  254. printk("KUo ");
  255. if (regs->cp0_status & ST0_IEO)
  256. printk("IEo ");
  257. if (regs->cp0_status & ST0_KUP)
  258. printk("KUp ");
  259. if (regs->cp0_status & ST0_IEP)
  260. printk("IEp ");
  261. if (regs->cp0_status & ST0_KUC)
  262. printk("KUc ");
  263. if (regs->cp0_status & ST0_IEC)
  264. printk("IEc ");
  265. } else {
  266. if (regs->cp0_status & ST0_KX)
  267. printk("KX ");
  268. if (regs->cp0_status & ST0_SX)
  269. printk("SX ");
  270. if (regs->cp0_status & ST0_UX)
  271. printk("UX ");
  272. switch (regs->cp0_status & ST0_KSU) {
  273. case KSU_USER:
  274. printk("USER ");
  275. break;
  276. case KSU_SUPERVISOR:
  277. printk("SUPERVISOR ");
  278. break;
  279. case KSU_KERNEL:
  280. printk("KERNEL ");
  281. break;
  282. default:
  283. printk("BAD_MODE ");
  284. break;
  285. }
  286. if (regs->cp0_status & ST0_ERL)
  287. printk("ERL ");
  288. if (regs->cp0_status & ST0_EXL)
  289. printk("EXL ");
  290. if (regs->cp0_status & ST0_IE)
  291. printk("IE ");
  292. }
  293. printk("\n");
  294. printk("Cause : %08x\n", cause);
  295. cause = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
  296. if (1 <= cause && cause <= 5)
  297. printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
  298. printk("PrId : %08x (%s)\n", read_c0_prid(),
  299. cpu_name_string());
  300. }
  301. /*
  302. * FIXME: really the generic show_regs should take a const pointer argument.
  303. */
  304. void show_regs(struct pt_regs *regs)
  305. {
  306. __show_regs((struct pt_regs *)regs);
  307. }
  308. void show_registers(struct pt_regs *regs)
  309. {
  310. const int field = 2 * sizeof(unsigned long);
  311. __show_regs(regs);
  312. print_modules();
  313. printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
  314. current->comm, current->pid, current_thread_info(), current,
  315. field, current_thread_info()->tp_value);
  316. if (cpu_has_userlocal) {
  317. unsigned long tls;
  318. tls = read_c0_userlocal();
  319. if (tls != current_thread_info()->tp_value)
  320. printk("*HwTLS: %0*lx\n", field, tls);
  321. }
  322. show_stacktrace(current, regs);
  323. show_code((unsigned int __user *) regs->cp0_epc);
  324. printk("\n");
  325. }
  326. static int regs_to_trapnr(struct pt_regs *regs)
  327. {
  328. return (regs->cp0_cause >> 2) & 0x1f;
  329. }
  330. static DEFINE_RAW_SPINLOCK(die_lock);
  331. void __noreturn die(const char *str, struct pt_regs *regs)
  332. {
  333. static int die_counter;
  334. int sig = SIGSEGV;
  335. #ifdef CONFIG_MIPS_MT_SMTC
  336. unsigned long dvpret;
  337. #endif /* CONFIG_MIPS_MT_SMTC */
  338. oops_enter();
  339. if (notify_die(DIE_OOPS, str, regs, 0, regs_to_trapnr(regs), SIGSEGV) == NOTIFY_STOP)
  340. sig = 0;
  341. console_verbose();
  342. raw_spin_lock_irq(&die_lock);
  343. #ifdef CONFIG_MIPS_MT_SMTC
  344. dvpret = dvpe();
  345. #endif /* CONFIG_MIPS_MT_SMTC */
  346. bust_spinlocks(1);
  347. #ifdef CONFIG_MIPS_MT_SMTC
  348. mips_mt_regdump(dvpret);
  349. #endif /* CONFIG_MIPS_MT_SMTC */
  350. printk("%s[#%d]:\n", str, ++die_counter);
  351. show_registers(regs);
  352. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  353. raw_spin_unlock_irq(&die_lock);
  354. oops_exit();
  355. if (in_interrupt())
  356. panic("Fatal exception in interrupt");
  357. if (panic_on_oops) {
  358. printk(KERN_EMERG "Fatal exception: panic in 5 seconds");
  359. ssleep(5);
  360. panic("Fatal exception");
  361. }
  362. if (regs && kexec_should_crash(current))
  363. crash_kexec(regs);
  364. do_exit(sig);
  365. }
  366. extern struct exception_table_entry __start___dbe_table[];
  367. extern struct exception_table_entry __stop___dbe_table[];
  368. __asm__(
  369. " .section __dbe_table, \"a\"\n"
  370. " .previous \n");
  371. /* Given an address, look for it in the exception tables. */
  372. static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
  373. {
  374. const struct exception_table_entry *e;
  375. e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
  376. if (!e)
  377. e = search_module_dbetables(addr);
  378. return e;
  379. }
  380. asmlinkage void do_be(struct pt_regs *regs)
  381. {
  382. const int field = 2 * sizeof(unsigned long);
  383. const struct exception_table_entry *fixup = NULL;
  384. int data = regs->cp0_cause & 4;
  385. int action = MIPS_BE_FATAL;
  386. /* XXX For now. Fixme, this searches the wrong table ... */
  387. if (data && !user_mode(regs))
  388. fixup = search_dbe_tables(exception_epc(regs));
  389. if (fixup)
  390. action = MIPS_BE_FIXUP;
  391. if (board_be_handler)
  392. action = board_be_handler(regs, fixup != NULL);
  393. switch (action) {
  394. case MIPS_BE_DISCARD:
  395. return;
  396. case MIPS_BE_FIXUP:
  397. if (fixup) {
  398. regs->cp0_epc = fixup->nextinsn;
  399. return;
  400. }
  401. break;
  402. default:
  403. break;
  404. }
  405. /*
  406. * Assume it would be too dangerous to continue ...
  407. */
  408. printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
  409. data ? "Data" : "Instruction",
  410. field, regs->cp0_epc, field, regs->regs[31]);
  411. if (notify_die(DIE_OOPS, "bus error", regs, 0, regs_to_trapnr(regs), SIGBUS)
  412. == NOTIFY_STOP)
  413. return;
  414. die_if_kernel("Oops", regs);
  415. force_sig(SIGBUS, current);
  416. }
  417. /*
  418. * ll/sc, rdhwr, sync emulation
  419. */
  420. #define OPCODE 0xfc000000
  421. #define BASE 0x03e00000
  422. #define RT 0x001f0000
  423. #define OFFSET 0x0000ffff
  424. #define LL 0xc0000000
  425. #define SC 0xe0000000
  426. #define SPEC0 0x00000000
  427. #define SPEC3 0x7c000000
  428. #define RD 0x0000f800
  429. #define FUNC 0x0000003f
  430. #define SYNC 0x0000000f
  431. #define RDHWR 0x0000003b
  432. /* microMIPS definitions */
  433. #define MM_POOL32A_FUNC 0xfc00ffff
  434. #define MM_RDHWR 0x00006b3c
  435. #define MM_RS 0x001f0000
  436. #define MM_RT 0x03e00000
  437. /*
  438. * The ll_bit is cleared by r*_switch.S
  439. */
  440. unsigned int ll_bit;
  441. struct task_struct *ll_task;
  442. static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
  443. {
  444. unsigned long value, __user *vaddr;
  445. long offset;
  446. /*
  447. * analyse the ll instruction that just caused a ri exception
  448. * and put the referenced address to addr.
  449. */
  450. /* sign extend offset */
  451. offset = opcode & OFFSET;
  452. offset <<= 16;
  453. offset >>= 16;
  454. vaddr = (unsigned long __user *)
  455. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  456. if ((unsigned long)vaddr & 3)
  457. return SIGBUS;
  458. if (get_user(value, vaddr))
  459. return SIGSEGV;
  460. preempt_disable();
  461. if (ll_task == NULL || ll_task == current) {
  462. ll_bit = 1;
  463. } else {
  464. ll_bit = 0;
  465. }
  466. ll_task = current;
  467. preempt_enable();
  468. regs->regs[(opcode & RT) >> 16] = value;
  469. return 0;
  470. }
  471. static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
  472. {
  473. unsigned long __user *vaddr;
  474. unsigned long reg;
  475. long offset;
  476. /*
  477. * analyse the sc instruction that just caused a ri exception
  478. * and put the referenced address to addr.
  479. */
  480. /* sign extend offset */
  481. offset = opcode & OFFSET;
  482. offset <<= 16;
  483. offset >>= 16;
  484. vaddr = (unsigned long __user *)
  485. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  486. reg = (opcode & RT) >> 16;
  487. if ((unsigned long)vaddr & 3)
  488. return SIGBUS;
  489. preempt_disable();
  490. if (ll_bit == 0 || ll_task != current) {
  491. regs->regs[reg] = 0;
  492. preempt_enable();
  493. return 0;
  494. }
  495. preempt_enable();
  496. if (put_user(regs->regs[reg], vaddr))
  497. return SIGSEGV;
  498. regs->regs[reg] = 1;
  499. return 0;
  500. }
  501. /*
  502. * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
  503. * opcodes are supposed to result in coprocessor unusable exceptions if
  504. * executed on ll/sc-less processors. That's the theory. In practice a
  505. * few processors such as NEC's VR4100 throw reserved instruction exceptions
  506. * instead, so we're doing the emulation thing in both exception handlers.
  507. */
  508. static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
  509. {
  510. if ((opcode & OPCODE) == LL) {
  511. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  512. 1, regs, 0);
  513. return simulate_ll(regs, opcode);
  514. }
  515. if ((opcode & OPCODE) == SC) {
  516. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  517. 1, regs, 0);
  518. return simulate_sc(regs, opcode);
  519. }
  520. return -1; /* Must be something else ... */
  521. }
  522. /*
  523. * Simulate trapping 'rdhwr' instructions to provide user accessible
  524. * registers not implemented in hardware.
  525. */
  526. static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
  527. {
  528. struct thread_info *ti = task_thread_info(current);
  529. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  530. 1, regs, 0);
  531. switch (rd) {
  532. case 0: /* CPU number */
  533. regs->regs[rt] = smp_processor_id();
  534. return 0;
  535. case 1: /* SYNCI length */
  536. regs->regs[rt] = min(current_cpu_data.dcache.linesz,
  537. current_cpu_data.icache.linesz);
  538. return 0;
  539. case 2: /* Read count register */
  540. regs->regs[rt] = read_c0_count();
  541. return 0;
  542. case 3: /* Count register resolution */
  543. switch (current_cpu_data.cputype) {
  544. case CPU_20KC:
  545. case CPU_25KF:
  546. regs->regs[rt] = 1;
  547. break;
  548. default:
  549. regs->regs[rt] = 2;
  550. }
  551. return 0;
  552. case 29:
  553. regs->regs[rt] = ti->tp_value;
  554. return 0;
  555. default:
  556. return -1;
  557. }
  558. }
  559. static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
  560. {
  561. if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
  562. int rd = (opcode & RD) >> 11;
  563. int rt = (opcode & RT) >> 16;
  564. simulate_rdhwr(regs, rd, rt);
  565. return 0;
  566. }
  567. /* Not ours. */
  568. return -1;
  569. }
  570. static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned short opcode)
  571. {
  572. if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
  573. int rd = (opcode & MM_RS) >> 16;
  574. int rt = (opcode & MM_RT) >> 21;
  575. simulate_rdhwr(regs, rd, rt);
  576. return 0;
  577. }
  578. /* Not ours. */
  579. return -1;
  580. }
  581. static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
  582. {
  583. if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
  584. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  585. 1, regs, 0);
  586. return 0;
  587. }
  588. return -1; /* Must be something else ... */
  589. }
  590. asmlinkage void do_ov(struct pt_regs *regs)
  591. {
  592. siginfo_t info;
  593. die_if_kernel("Integer overflow", regs);
  594. info.si_code = FPE_INTOVF;
  595. info.si_signo = SIGFPE;
  596. info.si_errno = 0;
  597. info.si_addr = (void __user *) regs->cp0_epc;
  598. force_sig_info(SIGFPE, &info, current);
  599. }
  600. int process_fpemu_return(int sig, void __user *fault_addr)
  601. {
  602. if (sig == SIGSEGV || sig == SIGBUS) {
  603. struct siginfo si = {0};
  604. si.si_addr = fault_addr;
  605. si.si_signo = sig;
  606. if (sig == SIGSEGV) {
  607. if (find_vma(current->mm, (unsigned long)fault_addr))
  608. si.si_code = SEGV_ACCERR;
  609. else
  610. si.si_code = SEGV_MAPERR;
  611. } else {
  612. si.si_code = BUS_ADRERR;
  613. }
  614. force_sig_info(sig, &si, current);
  615. return 1;
  616. } else if (sig) {
  617. force_sig(sig, current);
  618. return 1;
  619. } else {
  620. return 0;
  621. }
  622. }
  623. /*
  624. * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
  625. */
  626. asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
  627. {
  628. siginfo_t info = {0};
  629. if (notify_die(DIE_FP, "FP exception", regs, 0, regs_to_trapnr(regs), SIGFPE)
  630. == NOTIFY_STOP)
  631. return;
  632. die_if_kernel("FP exception in kernel code", regs);
  633. if (fcr31 & FPU_CSR_UNI_X) {
  634. int sig;
  635. void __user *fault_addr = NULL;
  636. /*
  637. * Unimplemented operation exception. If we've got the full
  638. * software emulator on-board, let's use it...
  639. *
  640. * Force FPU to dump state into task/thread context. We're
  641. * moving a lot of data here for what is probably a single
  642. * instruction, but the alternative is to pre-decode the FP
  643. * register operands before invoking the emulator, which seems
  644. * a bit extreme for what should be an infrequent event.
  645. */
  646. /* Ensure 'resume' not overwrite saved fp context again. */
  647. lose_fpu(1);
  648. /* Run the emulator */
  649. sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
  650. &fault_addr);
  651. /*
  652. * We can't allow the emulated instruction to leave any of
  653. * the cause bit set in $fcr31.
  654. */
  655. current->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
  656. /* Restore the hardware register state */
  657. own_fpu(1); /* Using the FPU again. */
  658. /* If something went wrong, signal */
  659. process_fpemu_return(sig, fault_addr);
  660. return;
  661. } else if (fcr31 & FPU_CSR_INV_X)
  662. info.si_code = FPE_FLTINV;
  663. else if (fcr31 & FPU_CSR_DIV_X)
  664. info.si_code = FPE_FLTDIV;
  665. else if (fcr31 & FPU_CSR_OVF_X)
  666. info.si_code = FPE_FLTOVF;
  667. else if (fcr31 & FPU_CSR_UDF_X)
  668. info.si_code = FPE_FLTUND;
  669. else if (fcr31 & FPU_CSR_INE_X)
  670. info.si_code = FPE_FLTRES;
  671. else
  672. info.si_code = __SI_FAULT;
  673. info.si_signo = SIGFPE;
  674. info.si_errno = 0;
  675. info.si_addr = (void __user *) regs->cp0_epc;
  676. force_sig_info(SIGFPE, &info, current);
  677. }
  678. static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
  679. const char *str)
  680. {
  681. siginfo_t info;
  682. char b[40];
  683. #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
  684. if (kgdb_ll_trap(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
  685. return;
  686. #endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
  687. if (notify_die(DIE_TRAP, str, regs, code, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
  688. return;
  689. /*
  690. * A short test says that IRIX 5.3 sends SIGTRAP for all trap
  691. * insns, even for trap and break codes that indicate arithmetic
  692. * failures. Weird ...
  693. * But should we continue the brokenness??? --macro
  694. */
  695. switch (code) {
  696. case BRK_OVERFLOW:
  697. case BRK_DIVZERO:
  698. scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
  699. die_if_kernel(b, regs);
  700. if (code == BRK_DIVZERO)
  701. info.si_code = FPE_INTDIV;
  702. else
  703. info.si_code = FPE_INTOVF;
  704. info.si_signo = SIGFPE;
  705. info.si_errno = 0;
  706. info.si_addr = (void __user *) regs->cp0_epc;
  707. force_sig_info(SIGFPE, &info, current);
  708. break;
  709. case BRK_BUG:
  710. die_if_kernel("Kernel bug detected", regs);
  711. force_sig(SIGTRAP, current);
  712. break;
  713. case BRK_MEMU:
  714. /*
  715. * Address errors may be deliberately induced by the FPU
  716. * emulator to retake control of the CPU after executing the
  717. * instruction in the delay slot of an emulated branch.
  718. *
  719. * Terminate if exception was recognized as a delay slot return
  720. * otherwise handle as normal.
  721. */
  722. if (do_dsemulret(regs))
  723. return;
  724. die_if_kernel("Math emu break/trap", regs);
  725. force_sig(SIGTRAP, current);
  726. break;
  727. default:
  728. scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
  729. die_if_kernel(b, regs);
  730. force_sig(SIGTRAP, current);
  731. }
  732. }
  733. asmlinkage void do_bp(struct pt_regs *regs)
  734. {
  735. unsigned int opcode, bcode;
  736. unsigned long epc;
  737. u16 instr[2];
  738. if (get_isa16_mode(regs->cp0_epc)) {
  739. /* Calculate EPC. */
  740. epc = exception_epc(regs);
  741. if (cpu_has_mmips) {
  742. if ((__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc)) ||
  743. (__get_user(instr[1], (u16 __user *)msk_isa16_mode(epc + 2)))))
  744. goto out_sigsegv;
  745. opcode = (instr[0] << 16) | instr[1];
  746. } else {
  747. /* MIPS16e mode */
  748. if (__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc)))
  749. goto out_sigsegv;
  750. bcode = (instr[0] >> 6) & 0x3f;
  751. do_trap_or_bp(regs, bcode, "Break");
  752. return;
  753. }
  754. } else {
  755. if (__get_user(opcode, (unsigned int __user *) exception_epc(regs)))
  756. goto out_sigsegv;
  757. }
  758. /*
  759. * There is the ancient bug in the MIPS assemblers that the break
  760. * code starts left to bit 16 instead to bit 6 in the opcode.
  761. * Gas is bug-compatible, but not always, grrr...
  762. * We handle both cases with a simple heuristics. --macro
  763. */
  764. bcode = ((opcode >> 6) & ((1 << 20) - 1));
  765. if (bcode >= (1 << 10))
  766. bcode >>= 10;
  767. /*
  768. * notify the kprobe handlers, if instruction is likely to
  769. * pertain to them.
  770. */
  771. switch (bcode) {
  772. case BRK_KPROBE_BP:
  773. if (notify_die(DIE_BREAK, "debug", regs, bcode, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
  774. return;
  775. else
  776. break;
  777. case BRK_KPROBE_SSTEPBP:
  778. if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode, regs_to_trapnr(regs), SIGTRAP) == NOTIFY_STOP)
  779. return;
  780. else
  781. break;
  782. default:
  783. break;
  784. }
  785. do_trap_or_bp(regs, bcode, "Break");
  786. return;
  787. out_sigsegv:
  788. force_sig(SIGSEGV, current);
  789. }
  790. asmlinkage void do_tr(struct pt_regs *regs)
  791. {
  792. unsigned int opcode, tcode = 0;
  793. u16 instr[2];
  794. unsigned long epc = exception_epc(regs);
  795. if ((__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc))) ||
  796. (__get_user(instr[1], (u16 __user *)msk_isa16_mode(epc + 2))))
  797. goto out_sigsegv;
  798. opcode = (instr[0] << 16) | instr[1];
  799. /* Immediate versions don't provide a code. */
  800. if (!(opcode & OPCODE)) {
  801. if (get_isa16_mode(regs->cp0_epc))
  802. /* microMIPS */
  803. tcode = (opcode >> 12) & 0x1f;
  804. else
  805. tcode = ((opcode >> 6) & ((1 << 10) - 1));
  806. }
  807. do_trap_or_bp(regs, tcode, "Trap");
  808. return;
  809. out_sigsegv:
  810. force_sig(SIGSEGV, current);
  811. }
  812. asmlinkage void do_ri(struct pt_regs *regs)
  813. {
  814. unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
  815. unsigned long old_epc = regs->cp0_epc;
  816. unsigned long old31 = regs->regs[31];
  817. unsigned int opcode = 0;
  818. int status = -1;
  819. if (notify_die(DIE_RI, "RI Fault", regs, 0, regs_to_trapnr(regs), SIGILL)
  820. == NOTIFY_STOP)
  821. return;
  822. die_if_kernel("Reserved instruction in kernel code", regs);
  823. if (unlikely(compute_return_epc(regs) < 0))
  824. return;
  825. if (get_isa16_mode(regs->cp0_epc)) {
  826. unsigned short mmop[2] = { 0 };
  827. if (unlikely(get_user(mmop[0], epc) < 0))
  828. status = SIGSEGV;
  829. if (unlikely(get_user(mmop[1], epc) < 0))
  830. status = SIGSEGV;
  831. opcode = (mmop[0] << 16) | mmop[1];
  832. if (status < 0)
  833. status = simulate_rdhwr_mm(regs, opcode);
  834. } else {
  835. if (unlikely(get_user(opcode, epc) < 0))
  836. status = SIGSEGV;
  837. if (!cpu_has_llsc && status < 0)
  838. status = simulate_llsc(regs, opcode);
  839. if (status < 0)
  840. status = simulate_rdhwr_normal(regs, opcode);
  841. if (status < 0)
  842. status = simulate_sync(regs, opcode);
  843. }
  844. if (status < 0)
  845. status = SIGILL;
  846. if (unlikely(status > 0)) {
  847. regs->cp0_epc = old_epc; /* Undo skip-over. */
  848. regs->regs[31] = old31;
  849. force_sig(status, current);
  850. }
  851. }
  852. /*
  853. * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
  854. * emulated more than some threshold number of instructions, force migration to
  855. * a "CPU" that has FP support.
  856. */
  857. static void mt_ase_fp_affinity(void)
  858. {
  859. #ifdef CONFIG_MIPS_MT_FPAFF
  860. if (mt_fpemul_threshold > 0 &&
  861. ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
  862. /*
  863. * If there's no FPU present, or if the application has already
  864. * restricted the allowed set to exclude any CPUs with FPUs,
  865. * we'll skip the procedure.
  866. */
  867. if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
  868. cpumask_t tmask;
  869. current->thread.user_cpus_allowed
  870. = current->cpus_allowed;
  871. cpus_and(tmask, current->cpus_allowed,
  872. mt_fpu_cpumask);
  873. set_cpus_allowed_ptr(current, &tmask);
  874. set_thread_flag(TIF_FPUBOUND);
  875. }
  876. }
  877. #endif /* CONFIG_MIPS_MT_FPAFF */
  878. }
  879. /*
  880. * No lock; only written during early bootup by CPU 0.
  881. */
  882. static RAW_NOTIFIER_HEAD(cu2_chain);
  883. int __ref register_cu2_notifier(struct notifier_block *nb)
  884. {
  885. return raw_notifier_chain_register(&cu2_chain, nb);
  886. }
  887. int cu2_notifier_call_chain(unsigned long val, void *v)
  888. {
  889. return raw_notifier_call_chain(&cu2_chain, val, v);
  890. }
  891. static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
  892. void *data)
  893. {
  894. struct pt_regs *regs = data;
  895. switch (action) {
  896. default:
  897. die_if_kernel("Unhandled kernel unaligned access or invalid "
  898. "instruction", regs);
  899. /* Fall through */
  900. case CU2_EXCEPTION:
  901. force_sig(SIGILL, current);
  902. }
  903. return NOTIFY_OK;
  904. }
  905. asmlinkage void do_cpu(struct pt_regs *regs)
  906. {
  907. unsigned int __user *epc;
  908. unsigned long old_epc, old31;
  909. unsigned int opcode;
  910. unsigned int cpid;
  911. int status;
  912. unsigned long __maybe_unused flags;
  913. die_if_kernel("do_cpu invoked from kernel context!", regs);
  914. cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
  915. switch (cpid) {
  916. case 0:
  917. epc = (unsigned int __user *)exception_epc(regs);
  918. old_epc = regs->cp0_epc;
  919. old31 = regs->regs[31];
  920. opcode = 0;
  921. status = -1;
  922. if (unlikely(compute_return_epc(regs) < 0))
  923. return;
  924. if (get_isa16_mode(regs->cp0_epc)) {
  925. unsigned short mmop[2] = { 0 };
  926. if (unlikely(get_user(mmop[0], epc) < 0))
  927. status = SIGSEGV;
  928. if (unlikely(get_user(mmop[1], epc) < 0))
  929. status = SIGSEGV;
  930. opcode = (mmop[0] << 16) | mmop[1];
  931. if (status < 0)
  932. status = simulate_rdhwr_mm(regs, opcode);
  933. } else {
  934. if (unlikely(get_user(opcode, epc) < 0))
  935. status = SIGSEGV;
  936. if (!cpu_has_llsc && status < 0)
  937. status = simulate_llsc(regs, opcode);
  938. if (status < 0)
  939. status = simulate_rdhwr_normal(regs, opcode);
  940. }
  941. if (status < 0)
  942. status = SIGILL;
  943. if (unlikely(status > 0)) {
  944. regs->cp0_epc = old_epc; /* Undo skip-over. */
  945. regs->regs[31] = old31;
  946. force_sig(status, current);
  947. }
  948. return;
  949. case 3:
  950. /*
  951. * Old (MIPS I and MIPS II) processors will set this code
  952. * for COP1X opcode instructions that replaced the original
  953. * COP3 space. We don't limit COP1 space instructions in
  954. * the emulator according to the CPU ISA, so we want to
  955. * treat COP1X instructions consistently regardless of which
  956. * code the CPU chose. Therefore we redirect this trap to
  957. * the FP emulator too.
  958. *
  959. * Then some newer FPU-less processors use this code
  960. * erroneously too, so they are covered by this choice
  961. * as well.
  962. */
  963. if (raw_cpu_has_fpu)
  964. break;
  965. /* Fall through. */
  966. case 1:
  967. if (used_math()) /* Using the FPU again. */
  968. own_fpu(1);
  969. else { /* First time FPU user. */
  970. init_fpu();
  971. set_used_math();
  972. }
  973. if (!raw_cpu_has_fpu) {
  974. int sig;
  975. void __user *fault_addr = NULL;
  976. sig = fpu_emulator_cop1Handler(regs,
  977. &current->thread.fpu,
  978. 0, &fault_addr);
  979. if (!process_fpemu_return(sig, fault_addr))
  980. mt_ase_fp_affinity();
  981. }
  982. return;
  983. case 2:
  984. raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
  985. return;
  986. }
  987. force_sig(SIGILL, current);
  988. }
  989. asmlinkage void do_mdmx(struct pt_regs *regs)
  990. {
  991. force_sig(SIGILL, current);
  992. }
  993. /*
  994. * Called with interrupts disabled.
  995. */
  996. asmlinkage void do_watch(struct pt_regs *regs)
  997. {
  998. u32 cause;
  999. /*
  1000. * Clear WP (bit 22) bit of cause register so we don't loop
  1001. * forever.
  1002. */
  1003. cause = read_c0_cause();
  1004. cause &= ~(1 << 22);
  1005. write_c0_cause(cause);
  1006. /*
  1007. * If the current thread has the watch registers loaded, save
  1008. * their values and send SIGTRAP. Otherwise another thread
  1009. * left the registers set, clear them and continue.
  1010. */
  1011. if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
  1012. mips_read_watch_registers();
  1013. local_irq_enable();
  1014. force_sig(SIGTRAP, current);
  1015. } else {
  1016. mips_clear_watch_registers();
  1017. local_irq_enable();
  1018. }
  1019. }
  1020. asmlinkage void do_mcheck(struct pt_regs *regs)
  1021. {
  1022. const int field = 2 * sizeof(unsigned long);
  1023. int multi_match = regs->cp0_status & ST0_TS;
  1024. show_regs(regs);
  1025. if (multi_match) {
  1026. printk("Index : %0x\n", read_c0_index());
  1027. printk("Pagemask: %0x\n", read_c0_pagemask());
  1028. printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
  1029. printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
  1030. printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
  1031. printk("\n");
  1032. dump_tlb_all();
  1033. }
  1034. show_code((unsigned int __user *) regs->cp0_epc);
  1035. /*
  1036. * Some chips may have other causes of machine check (e.g. SB1
  1037. * graduation timer)
  1038. */
  1039. panic("Caught Machine Check exception - %scaused by multiple "
  1040. "matching entries in the TLB.",
  1041. (multi_match) ? "" : "not ");
  1042. }
  1043. asmlinkage void do_mt(struct pt_regs *regs)
  1044. {
  1045. int subcode;
  1046. subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
  1047. >> VPECONTROL_EXCPT_SHIFT;
  1048. switch (subcode) {
  1049. case 0:
  1050. printk(KERN_DEBUG "Thread Underflow\n");
  1051. break;
  1052. case 1:
  1053. printk(KERN_DEBUG "Thread Overflow\n");
  1054. break;
  1055. case 2:
  1056. printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
  1057. break;
  1058. case 3:
  1059. printk(KERN_DEBUG "Gating Storage Exception\n");
  1060. break;
  1061. case 4:
  1062. printk(KERN_DEBUG "YIELD Scheduler Exception\n");
  1063. break;
  1064. case 5:
  1065. printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
  1066. break;
  1067. default:
  1068. printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
  1069. subcode);
  1070. break;
  1071. }
  1072. die_if_kernel("MIPS MT Thread exception in kernel", regs);
  1073. force_sig(SIGILL, current);
  1074. }
  1075. asmlinkage void do_dsp(struct pt_regs *regs)
  1076. {
  1077. if (cpu_has_dsp)
  1078. panic("Unexpected DSP exception");
  1079. force_sig(SIGILL, current);
  1080. }
  1081. asmlinkage void do_reserved(struct pt_regs *regs)
  1082. {
  1083. /*
  1084. * Game over - no way to handle this if it ever occurs. Most probably
  1085. * caused by a new unknown cpu type or after another deadly
  1086. * hard/software error.
  1087. */
  1088. show_regs(regs);
  1089. panic("Caught reserved exception %ld - should not happen.",
  1090. (regs->cp0_cause & 0x7f) >> 2);
  1091. }
  1092. static int __initdata l1parity = 1;
  1093. static int __init nol1parity(char *s)
  1094. {
  1095. l1parity = 0;
  1096. return 1;
  1097. }
  1098. __setup("nol1par", nol1parity);
  1099. static int __initdata l2parity = 1;
  1100. static int __init nol2parity(char *s)
  1101. {
  1102. l2parity = 0;
  1103. return 1;
  1104. }
  1105. __setup("nol2par", nol2parity);
  1106. /*
  1107. * Some MIPS CPUs can enable/disable for cache parity detection, but do
  1108. * it different ways.
  1109. */
  1110. static inline void parity_protection_init(void)
  1111. {
  1112. switch (current_cpu_type()) {
  1113. case CPU_24K:
  1114. case CPU_34K:
  1115. case CPU_74K:
  1116. case CPU_1004K:
  1117. {
  1118. #define ERRCTL_PE 0x80000000
  1119. #define ERRCTL_L2P 0x00800000
  1120. unsigned long errctl;
  1121. unsigned int l1parity_present, l2parity_present;
  1122. errctl = read_c0_ecc();
  1123. errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
  1124. /* probe L1 parity support */
  1125. write_c0_ecc(errctl | ERRCTL_PE);
  1126. back_to_back_c0_hazard();
  1127. l1parity_present = (read_c0_ecc() & ERRCTL_PE);
  1128. /* probe L2 parity support */
  1129. write_c0_ecc(errctl|ERRCTL_L2P);
  1130. back_to_back_c0_hazard();
  1131. l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
  1132. if (l1parity_present && l2parity_present) {
  1133. if (l1parity)
  1134. errctl |= ERRCTL_PE;
  1135. if (l1parity ^ l2parity)
  1136. errctl |= ERRCTL_L2P;
  1137. } else if (l1parity_present) {
  1138. if (l1parity)
  1139. errctl |= ERRCTL_PE;
  1140. } else if (l2parity_present) {
  1141. if (l2parity)
  1142. errctl |= ERRCTL_L2P;
  1143. } else {
  1144. /* No parity available */
  1145. }
  1146. printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
  1147. write_c0_ecc(errctl);
  1148. back_to_back_c0_hazard();
  1149. errctl = read_c0_ecc();
  1150. printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
  1151. if (l1parity_present)
  1152. printk(KERN_INFO "Cache parity protection %sabled\n",
  1153. (errctl & ERRCTL_PE) ? "en" : "dis");
  1154. if (l2parity_present) {
  1155. if (l1parity_present && l1parity)
  1156. errctl ^= ERRCTL_L2P;
  1157. printk(KERN_INFO "L2 cache parity protection %sabled\n",
  1158. (errctl & ERRCTL_L2P) ? "en" : "dis");
  1159. }
  1160. }
  1161. break;
  1162. case CPU_5KC:
  1163. case CPU_5KE:
  1164. case CPU_LOONGSON1:
  1165. write_c0_ecc(0x80000000);
  1166. back_to_back_c0_hazard();
  1167. /* Set the PE bit (bit 31) in the c0_errctl register. */
  1168. printk(KERN_INFO "Cache parity protection %sabled\n",
  1169. (read_c0_ecc() & 0x80000000) ? "en" : "dis");
  1170. break;
  1171. case CPU_20KC:
  1172. case CPU_25KF:
  1173. /* Clear the DE bit (bit 16) in the c0_status register. */
  1174. printk(KERN_INFO "Enable cache parity protection for "
  1175. "MIPS 20KC/25KF CPUs.\n");
  1176. clear_c0_status(ST0_DE);
  1177. break;
  1178. default:
  1179. break;
  1180. }
  1181. }
  1182. asmlinkage void cache_parity_error(void)
  1183. {
  1184. const int field = 2 * sizeof(unsigned long);
  1185. unsigned int reg_val;
  1186. /* For the moment, report the problem and hang. */
  1187. printk("Cache error exception:\n");
  1188. printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
  1189. reg_val = read_c0_cacheerr();
  1190. printk("c0_cacheerr == %08x\n", reg_val);
  1191. printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
  1192. reg_val & (1<<30) ? "secondary" : "primary",
  1193. reg_val & (1<<31) ? "data" : "insn");
  1194. printk("Error bits: %s%s%s%s%s%s%s\n",
  1195. reg_val & (1<<29) ? "ED " : "",
  1196. reg_val & (1<<28) ? "ET " : "",
  1197. reg_val & (1<<26) ? "EE " : "",
  1198. reg_val & (1<<25) ? "EB " : "",
  1199. reg_val & (1<<24) ? "EI " : "",
  1200. reg_val & (1<<23) ? "E1 " : "",
  1201. reg_val & (1<<22) ? "E0 " : "");
  1202. printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
  1203. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  1204. if (reg_val & (1<<22))
  1205. printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
  1206. if (reg_val & (1<<23))
  1207. printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
  1208. #endif
  1209. panic("Can't handle the cache error!");
  1210. }
  1211. /*
  1212. * SDBBP EJTAG debug exception handler.
  1213. * We skip the instruction and return to the next instruction.
  1214. */
  1215. void ejtag_exception_handler(struct pt_regs *regs)
  1216. {
  1217. const int field = 2 * sizeof(unsigned long);
  1218. unsigned long depc, old_epc, old_ra;
  1219. unsigned int debug;
  1220. printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
  1221. depc = read_c0_depc();
  1222. debug = read_c0_debug();
  1223. printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
  1224. if (debug & 0x80000000) {
  1225. /*
  1226. * In branch delay slot.
  1227. * We cheat a little bit here and use EPC to calculate the
  1228. * debug return address (DEPC). EPC is restored after the
  1229. * calculation.
  1230. */
  1231. old_epc = regs->cp0_epc;
  1232. old_ra = regs->regs[31];
  1233. regs->cp0_epc = depc;
  1234. compute_return_epc(regs);
  1235. depc = regs->cp0_epc;
  1236. regs->cp0_epc = old_epc;
  1237. regs->regs[31] = old_ra;
  1238. } else
  1239. depc += 4;
  1240. write_c0_depc(depc);
  1241. #if 0
  1242. printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
  1243. write_c0_debug(debug | 0x100);
  1244. #endif
  1245. }
  1246. /*
  1247. * NMI exception handler.
  1248. * No lock; only written during early bootup by CPU 0.
  1249. */
  1250. static RAW_NOTIFIER_HEAD(nmi_chain);
  1251. int register_nmi_notifier(struct notifier_block *nb)
  1252. {
  1253. return raw_notifier_chain_register(&nmi_chain, nb);
  1254. }
  1255. void __noreturn nmi_exception_handler(struct pt_regs *regs)
  1256. {
  1257. raw_notifier_call_chain(&nmi_chain, 0, regs);
  1258. bust_spinlocks(1);
  1259. printk("NMI taken!!!!\n");
  1260. die("NMI", regs);
  1261. }
  1262. #define VECTORSPACING 0x100 /* for EI/VI mode */
  1263. unsigned long ebase;
  1264. unsigned long exception_handlers[32];
  1265. unsigned long vi_handlers[64];
  1266. void __init *set_except_vector(int n, void *addr)
  1267. {
  1268. unsigned long handler = (unsigned long) addr;
  1269. unsigned long old_handler = exception_handlers[n];
  1270. #ifdef CONFIG_CPU_MICROMIPS
  1271. /*
  1272. * Only the TLB handlers are cache aligned with an even
  1273. * address. All other handlers are on an odd address and
  1274. * require no modification. Otherwise, MIPS32 mode will
  1275. * be entered when handling any TLB exceptions. That
  1276. * would be bad...since we must stay in microMIPS mode.
  1277. */
  1278. if (!(handler & 0x1))
  1279. handler |= 1;
  1280. #endif
  1281. exception_handlers[n] = handler;
  1282. if (n == 0 && cpu_has_divec) {
  1283. #ifdef CONFIG_CPU_MICROMIPS
  1284. unsigned long jump_mask = ~((1 << 27) - 1);
  1285. #else
  1286. unsigned long jump_mask = ~((1 << 28) - 1);
  1287. #endif
  1288. u32 *buf = (u32 *)(ebase + 0x200);
  1289. unsigned int k0 = 26;
  1290. if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
  1291. uasm_i_j(&buf, handler & ~jump_mask);
  1292. uasm_i_nop(&buf);
  1293. } else {
  1294. UASM_i_LA(&buf, k0, handler);
  1295. uasm_i_jr(&buf, k0);
  1296. uasm_i_nop(&buf);
  1297. }
  1298. local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
  1299. }
  1300. return (void *)old_handler;
  1301. }
  1302. static asmlinkage void do_default_vi(void)
  1303. {
  1304. show_regs(get_irq_regs());
  1305. panic("Caught unexpected vectored interrupt.");
  1306. }
  1307. static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
  1308. {
  1309. unsigned long handler;
  1310. unsigned long old_handler = vi_handlers[n];
  1311. int srssets = current_cpu_data.srsets;
  1312. u16 *h;
  1313. unsigned char *b;
  1314. BUG_ON(!cpu_has_veic && !cpu_has_vint);
  1315. BUG_ON((n < 0) && (n > 9));
  1316. if (addr == NULL) {
  1317. handler = (unsigned long) do_default_vi;
  1318. srs = 0;
  1319. } else
  1320. handler = (unsigned long) addr;
  1321. vi_handlers[n] = handler;
  1322. b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
  1323. if (srs >= srssets)
  1324. panic("Shadow register set %d not supported", srs);
  1325. if (cpu_has_veic) {
  1326. if (board_bind_eic_interrupt)
  1327. board_bind_eic_interrupt(n, srs);
  1328. } else if (cpu_has_vint) {
  1329. /* SRSMap is only defined if shadow sets are implemented */
  1330. if (srssets > 1)
  1331. change_c0_srsmap(0xf << n*4, srs << n*4);
  1332. }
  1333. if (srs == 0) {
  1334. /*
  1335. * If no shadow set is selected then use the default handler
  1336. * that does normal register saving and standard interrupt exit
  1337. */
  1338. extern char except_vec_vi, except_vec_vi_lui;
  1339. extern char except_vec_vi_ori, except_vec_vi_end;
  1340. extern char rollback_except_vec_vi;
  1341. char *vec_start = (cpu_wait == r4k_wait) ?
  1342. &rollback_except_vec_vi : &except_vec_vi;
  1343. #ifdef CONFIG_MIPS_MT_SMTC
  1344. /*
  1345. * We need to provide the SMTC vectored interrupt handler
  1346. * not only with the address of the handler, but with the
  1347. * Status.IM bit to be masked before going there.
  1348. */
  1349. extern char except_vec_vi_mori;
  1350. #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
  1351. const int mori_offset = &except_vec_vi_mori - vec_start + 2;
  1352. #else
  1353. const int mori_offset = &except_vec_vi_mori - vec_start;
  1354. #endif
  1355. #endif /* CONFIG_MIPS_MT_SMTC */
  1356. #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
  1357. const int lui_offset = &except_vec_vi_lui - vec_start + 2;
  1358. const int ori_offset = &except_vec_vi_ori - vec_start + 2;
  1359. #else
  1360. const int lui_offset = &except_vec_vi_lui - vec_start;
  1361. const int ori_offset = &except_vec_vi_ori - vec_start;
  1362. #endif
  1363. const int handler_len = &except_vec_vi_end - vec_start;
  1364. if (handler_len > VECTORSPACING) {
  1365. /*
  1366. * Sigh... panicing won't help as the console
  1367. * is probably not configured :(
  1368. */
  1369. panic("VECTORSPACING too small");
  1370. }
  1371. set_handler(((unsigned long)b - ebase), vec_start,
  1372. #ifdef CONFIG_CPU_MICROMIPS
  1373. (handler_len - 1));
  1374. #else
  1375. handler_len);
  1376. #endif
  1377. #ifdef CONFIG_MIPS_MT_SMTC
  1378. BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */
  1379. h = (u16 *)(b + mori_offset);
  1380. *h = (0x100 << n);
  1381. #endif /* CONFIG_MIPS_MT_SMTC */
  1382. h = (u16 *)(b + lui_offset);
  1383. *h = (handler >> 16) & 0xffff;
  1384. h = (u16 *)(b + ori_offset);
  1385. *h = (handler & 0xffff);
  1386. local_flush_icache_range((unsigned long)b,
  1387. (unsigned long)(b+handler_len));
  1388. }
  1389. else {
  1390. /*
  1391. * In other cases jump directly to the interrupt handler. It
  1392. * is the handler's responsibility to save registers if required
  1393. * (eg hi/lo) and return from the exception using "eret".
  1394. */
  1395. u32 insn;
  1396. h = (u16 *)b;
  1397. /* j handler */
  1398. #ifdef CONFIG_CPU_MICROMIPS
  1399. insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
  1400. #else
  1401. insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
  1402. #endif
  1403. h[0] = (insn >> 16) & 0xffff;
  1404. h[1] = insn & 0xffff;
  1405. h[2] = 0;
  1406. h[3] = 0;
  1407. local_flush_icache_range((unsigned long)b,
  1408. (unsigned long)(b+8));
  1409. }
  1410. return (void *)old_handler;
  1411. }
  1412. void *set_vi_handler(int n, vi_handler_t addr)
  1413. {
  1414. return set_vi_srs_handler(n, addr, 0);
  1415. }
  1416. extern void tlb_init(void);
  1417. extern void flush_tlb_handlers(void);
  1418. /*
  1419. * Timer interrupt
  1420. */
  1421. int cp0_compare_irq;
  1422. EXPORT_SYMBOL_GPL(cp0_compare_irq);
  1423. int cp0_compare_irq_shift;
  1424. /*
  1425. * Performance counter IRQ or -1 if shared with timer
  1426. */
  1427. int cp0_perfcount_irq;
  1428. EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
  1429. static int __cpuinitdata noulri;
  1430. static int __init ulri_disable(char *s)
  1431. {
  1432. pr_info("Disabling ulri\n");
  1433. noulri = 1;
  1434. return 1;
  1435. }
  1436. __setup("noulri", ulri_disable);
  1437. void __cpuinit per_cpu_trap_init(bool is_boot_cpu)
  1438. {
  1439. unsigned int cpu = smp_processor_id();
  1440. unsigned int status_set = ST0_CU0;
  1441. unsigned int hwrena = cpu_hwrena_impl_bits;
  1442. unsigned long asid = 0;
  1443. #ifdef CONFIG_MIPS_MT_SMTC
  1444. int secondaryTC = 0;
  1445. int bootTC = (cpu == 0);
  1446. /*
  1447. * Only do per_cpu_trap_init() for first TC of Each VPE.
  1448. * Note that this hack assumes that the SMTC init code
  1449. * assigns TCs consecutively and in ascending order.
  1450. */
  1451. if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
  1452. ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
  1453. secondaryTC = 1;
  1454. #endif /* CONFIG_MIPS_MT_SMTC */
  1455. /*
  1456. * Disable coprocessors and select 32-bit or 64-bit addressing
  1457. * and the 16/32 or 32/32 FPR register model. Reset the BEV
  1458. * flag that some firmware may have left set and the TS bit (for
  1459. * IP27). Set XX for ISA IV code to work.
  1460. */
  1461. #ifdef CONFIG_64BIT
  1462. status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
  1463. #endif
  1464. if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
  1465. status_set |= ST0_XX;
  1466. if (cpu_has_dsp)
  1467. status_set |= ST0_MX;
  1468. change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
  1469. status_set);
  1470. if (cpu_has_mips_r2)
  1471. hwrena |= 0x0000000f;
  1472. if (!noulri && cpu_has_userlocal)
  1473. hwrena |= (1 << 29);
  1474. if (hwrena)
  1475. write_c0_hwrena(hwrena);
  1476. #ifdef CONFIG_MIPS_MT_SMTC
  1477. if (!secondaryTC) {
  1478. #endif /* CONFIG_MIPS_MT_SMTC */
  1479. if (cpu_has_veic || cpu_has_vint) {
  1480. unsigned long sr = set_c0_status(ST0_BEV);
  1481. write_c0_ebase(ebase);
  1482. write_c0_status(sr);
  1483. /* Setting vector spacing enables EI/VI mode */
  1484. change_c0_intctl(0x3e0, VECTORSPACING);
  1485. }
  1486. if (cpu_has_divec) {
  1487. if (cpu_has_mipsmt) {
  1488. unsigned int vpflags = dvpe();
  1489. set_c0_cause(CAUSEF_IV);
  1490. evpe(vpflags);
  1491. } else
  1492. set_c0_cause(CAUSEF_IV);
  1493. }
  1494. /*
  1495. * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
  1496. *
  1497. * o read IntCtl.IPTI to determine the timer interrupt
  1498. * o read IntCtl.IPPCI to determine the performance counter interrupt
  1499. */
  1500. if (cpu_has_mips_r2) {
  1501. cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
  1502. cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
  1503. cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
  1504. if (cp0_perfcount_irq == cp0_compare_irq)
  1505. cp0_perfcount_irq = -1;
  1506. } else {
  1507. cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
  1508. cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
  1509. cp0_perfcount_irq = -1;
  1510. }
  1511. #ifdef CONFIG_MIPS_MT_SMTC
  1512. }
  1513. #endif /* CONFIG_MIPS_MT_SMTC */
  1514. asid = ASID_FIRST_VERSION;
  1515. cpu_data[cpu].asid_cache = asid;
  1516. TLBMISS_HANDLER_SETUP();
  1517. atomic_inc(&init_mm.mm_count);
  1518. current->active_mm = &init_mm;
  1519. BUG_ON(current->mm);
  1520. enter_lazy_tlb(&init_mm, current);
  1521. #ifdef CONFIG_MIPS_MT_SMTC
  1522. if (bootTC) {
  1523. #endif /* CONFIG_MIPS_MT_SMTC */
  1524. /* Boot CPU's cache setup in setup_arch(). */
  1525. if (!is_boot_cpu)
  1526. cpu_cache_init();
  1527. tlb_init();
  1528. #ifdef CONFIG_MIPS_MT_SMTC
  1529. } else if (!secondaryTC) {
  1530. /*
  1531. * First TC in non-boot VPE must do subset of tlb_init()
  1532. * for MMU countrol registers.
  1533. */
  1534. write_c0_pagemask(PM_DEFAULT_MASK);
  1535. write_c0_wired(0);
  1536. }
  1537. #endif /* CONFIG_MIPS_MT_SMTC */
  1538. TLBMISS_HANDLER_SETUP();
  1539. }
  1540. /* Install CPU exception handler */
  1541. void __cpuinit set_handler(unsigned long offset, void *addr, unsigned long size)
  1542. {
  1543. #ifdef CONFIG_CPU_MICROMIPS
  1544. memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
  1545. #else
  1546. memcpy((void *)(ebase + offset), addr, size);
  1547. #endif
  1548. local_flush_icache_range(ebase + offset, ebase + offset + size);
  1549. }
  1550. static char panic_null_cerr[] __cpuinitdata =
  1551. "Trying to set NULL cache error exception handler";
  1552. /*
  1553. * Install uncached CPU exception handler.
  1554. * This is suitable only for the cache error exception which is the only
  1555. * exception handler that is being run uncached.
  1556. */
  1557. void __cpuinit set_uncached_handler(unsigned long offset, void *addr,
  1558. unsigned long size)
  1559. {
  1560. unsigned long uncached_ebase = CKSEG1ADDR(ebase);
  1561. if (!addr)
  1562. panic(panic_null_cerr);
  1563. memcpy((void *)(uncached_ebase + offset), addr, size);
  1564. }
  1565. static int __initdata rdhwr_noopt;
  1566. static int __init set_rdhwr_noopt(char *str)
  1567. {
  1568. rdhwr_noopt = 1;
  1569. return 1;
  1570. }
  1571. __setup("rdhwr_noopt", set_rdhwr_noopt);
  1572. void __init trap_init(void)
  1573. {
  1574. extern char except_vec3_generic;
  1575. extern char except_vec4;
  1576. extern char except_vec3_r4000;
  1577. unsigned long i;
  1578. int rollback;
  1579. check_wait();
  1580. rollback = (cpu_wait == r4k_wait);
  1581. #if defined(CONFIG_KGDB)
  1582. if (kgdb_early_setup)
  1583. return; /* Already done */
  1584. #endif
  1585. if (cpu_has_veic || cpu_has_vint) {
  1586. unsigned long size = 0x200 + VECTORSPACING*64;
  1587. ebase = (unsigned long)
  1588. __alloc_bootmem(size, 1 << fls(size), 0);
  1589. } else {
  1590. ebase = CKSEG0;
  1591. if (cpu_has_mips_r2)
  1592. ebase += (read_c0_ebase() & 0x3ffff000);
  1593. }
  1594. if (board_ebase_setup)
  1595. board_ebase_setup();
  1596. per_cpu_trap_init(true);
  1597. /*
  1598. * Copy the generic exception handlers to their final destination.
  1599. * This will be overriden later as suitable for a particular
  1600. * configuration.
  1601. */
  1602. set_handler(0x180, &except_vec3_generic, 0x80);
  1603. /*
  1604. * Setup default vectors
  1605. */
  1606. for (i = 0; i <= 31; i++)
  1607. set_except_vector(i, handle_reserved);
  1608. /*
  1609. * Copy the EJTAG debug exception vector handler code to it's final
  1610. * destination.
  1611. */
  1612. if (cpu_has_ejtag && board_ejtag_handler_setup)
  1613. board_ejtag_handler_setup();
  1614. /*
  1615. * Only some CPUs have the watch exceptions.
  1616. */
  1617. if (cpu_has_watch)
  1618. set_except_vector(23, handle_watch);
  1619. /*
  1620. * Initialise interrupt handlers
  1621. */
  1622. if (cpu_has_veic || cpu_has_vint) {
  1623. int nvec = cpu_has_veic ? 64 : 8;
  1624. for (i = 0; i < nvec; i++)
  1625. set_vi_handler(i, NULL);
  1626. }
  1627. else if (cpu_has_divec)
  1628. set_handler(0x200, &except_vec4, 0x8);
  1629. /*
  1630. * Some CPUs can enable/disable for cache parity detection, but does
  1631. * it different ways.
  1632. */
  1633. parity_protection_init();
  1634. /*
  1635. * The Data Bus Errors / Instruction Bus Errors are signaled
  1636. * by external hardware. Therefore these two exceptions
  1637. * may have board specific handlers.
  1638. */
  1639. if (board_be_init)
  1640. board_be_init();
  1641. set_except_vector(0, rollback ? rollback_handle_int : handle_int);
  1642. set_except_vector(1, handle_tlbm);
  1643. set_except_vector(2, handle_tlbl);
  1644. set_except_vector(3, handle_tlbs);
  1645. set_except_vector(4, handle_adel);
  1646. set_except_vector(5, handle_ades);
  1647. set_except_vector(6, handle_ibe);
  1648. set_except_vector(7, handle_dbe);
  1649. set_except_vector(8, handle_sys);
  1650. set_except_vector(9, handle_bp);
  1651. set_except_vector(10, rdhwr_noopt ? handle_ri :
  1652. (cpu_has_vtag_icache ?
  1653. handle_ri_rdhwr_vivt : handle_ri_rdhwr));
  1654. set_except_vector(11, handle_cpu);
  1655. set_except_vector(12, handle_ov);
  1656. set_except_vector(13, handle_tr);
  1657. if (current_cpu_type() == CPU_R6000 ||
  1658. current_cpu_type() == CPU_R6000A) {
  1659. /*
  1660. * The R6000 is the only R-series CPU that features a machine
  1661. * check exception (similar to the R4000 cache error) and
  1662. * unaligned ldc1/sdc1 exception. The handlers have not been
  1663. * written yet. Well, anyway there is no R6000 machine on the
  1664. * current list of targets for Linux/MIPS.
  1665. * (Duh, crap, there is someone with a triple R6k machine)
  1666. */
  1667. //set_except_vector(14, handle_mc);
  1668. //set_except_vector(15, handle_ndc);
  1669. }
  1670. if (board_nmi_handler_setup)
  1671. board_nmi_handler_setup();
  1672. if (cpu_has_fpu && !cpu_has_nofpuex)
  1673. set_except_vector(15, handle_fpe);
  1674. set_except_vector(22, handle_mdmx);
  1675. if (cpu_has_mcheck)
  1676. set_except_vector(24, handle_mcheck);
  1677. if (cpu_has_mipsmt)
  1678. set_except_vector(25, handle_mt);
  1679. set_except_vector(26, handle_dsp);
  1680. if (board_cache_error_setup)
  1681. board_cache_error_setup();
  1682. if (cpu_has_vce)
  1683. /* Special exception: R4[04]00 uses also the divec space. */
  1684. set_handler(0x180, &except_vec3_r4000, 0x100);
  1685. else if (cpu_has_4kex)
  1686. set_handler(0x180, &except_vec3_generic, 0x80);
  1687. else
  1688. set_handler(0x080, &except_vec3_generic, 0x80);
  1689. local_flush_icache_range(ebase, ebase + 0x400);
  1690. flush_tlb_handlers();
  1691. sort_extable(__start___dbe_table, __stop___dbe_table);
  1692. cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
  1693. }