traps.c 48 KB

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