traps.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  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 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. unsigned int opcode, tcode = 0;
  783. u16 instr[2];
  784. unsigned long epc = exception_epc(regs);
  785. if ((__get_user(instr[0], (u16 __user *)msk_isa16_mode(epc))) ||
  786. (__get_user(instr[1], (u16 __user *)msk_isa16_mode(epc + 2))))
  787. goto out_sigsegv;
  788. opcode = (instr[0] << 16) | instr[1];
  789. /* Immediate versions don't provide a code. */
  790. if (!(opcode & OPCODE)) {
  791. if (get_isa16_mode(regs->cp0_epc))
  792. /* microMIPS */
  793. tcode = (opcode >> 12) & 0x1f;
  794. else
  795. tcode = ((opcode >> 6) & ((1 << 10) - 1));
  796. }
  797. do_trap_or_bp(regs, tcode, "Trap");
  798. return;
  799. out_sigsegv:
  800. force_sig(SIGSEGV, current);
  801. }
  802. asmlinkage void do_ri(struct pt_regs *regs)
  803. {
  804. unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
  805. unsigned long old_epc = regs->cp0_epc;
  806. unsigned long old31 = regs->regs[31];
  807. unsigned int opcode = 0;
  808. int status = -1;
  809. if (notify_die(DIE_RI, "RI Fault", regs, 0, regs_to_trapnr(regs), SIGILL)
  810. == NOTIFY_STOP)
  811. return;
  812. die_if_kernel("Reserved instruction in kernel code", regs);
  813. if (unlikely(compute_return_epc(regs) < 0))
  814. return;
  815. if (get_isa16_mode(regs->cp0_epc)) {
  816. unsigned short mmop[2] = { 0 };
  817. if (unlikely(get_user(mmop[0], epc) < 0))
  818. status = SIGSEGV;
  819. if (unlikely(get_user(mmop[1], epc) < 0))
  820. status = SIGSEGV;
  821. opcode = (mmop[0] << 16) | mmop[1];
  822. if (status < 0)
  823. status = simulate_rdhwr_mm(regs, opcode);
  824. } else {
  825. if (unlikely(get_user(opcode, epc) < 0))
  826. status = SIGSEGV;
  827. if (!cpu_has_llsc && status < 0)
  828. status = simulate_llsc(regs, opcode);
  829. if (status < 0)
  830. status = simulate_rdhwr_normal(regs, opcode);
  831. if (status < 0)
  832. status = simulate_sync(regs, opcode);
  833. }
  834. if (status < 0)
  835. status = SIGILL;
  836. if (unlikely(status > 0)) {
  837. regs->cp0_epc = old_epc; /* Undo skip-over. */
  838. regs->regs[31] = old31;
  839. force_sig(status, current);
  840. }
  841. }
  842. /*
  843. * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
  844. * emulated more than some threshold number of instructions, force migration to
  845. * a "CPU" that has FP support.
  846. */
  847. static void mt_ase_fp_affinity(void)
  848. {
  849. #ifdef CONFIG_MIPS_MT_FPAFF
  850. if (mt_fpemul_threshold > 0 &&
  851. ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
  852. /*
  853. * If there's no FPU present, or if the application has already
  854. * restricted the allowed set to exclude any CPUs with FPUs,
  855. * we'll skip the procedure.
  856. */
  857. if (cpus_intersects(current->cpus_allowed, mt_fpu_cpumask)) {
  858. cpumask_t tmask;
  859. current->thread.user_cpus_allowed
  860. = current->cpus_allowed;
  861. cpus_and(tmask, current->cpus_allowed,
  862. mt_fpu_cpumask);
  863. set_cpus_allowed_ptr(current, &tmask);
  864. set_thread_flag(TIF_FPUBOUND);
  865. }
  866. }
  867. #endif /* CONFIG_MIPS_MT_FPAFF */
  868. }
  869. /*
  870. * No lock; only written during early bootup by CPU 0.
  871. */
  872. static RAW_NOTIFIER_HEAD(cu2_chain);
  873. int __ref register_cu2_notifier(struct notifier_block *nb)
  874. {
  875. return raw_notifier_chain_register(&cu2_chain, nb);
  876. }
  877. int cu2_notifier_call_chain(unsigned long val, void *v)
  878. {
  879. return raw_notifier_call_chain(&cu2_chain, val, v);
  880. }
  881. static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
  882. void *data)
  883. {
  884. struct pt_regs *regs = data;
  885. switch (action) {
  886. default:
  887. die_if_kernel("Unhandled kernel unaligned access or invalid "
  888. "instruction", regs);
  889. /* Fall through */
  890. case CU2_EXCEPTION:
  891. force_sig(SIGILL, current);
  892. }
  893. return NOTIFY_OK;
  894. }
  895. asmlinkage void do_cpu(struct pt_regs *regs)
  896. {
  897. unsigned int __user *epc;
  898. unsigned long old_epc, old31;
  899. unsigned int opcode;
  900. unsigned int cpid;
  901. int status;
  902. unsigned long __maybe_unused flags;
  903. die_if_kernel("do_cpu invoked from kernel context!", regs);
  904. cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
  905. switch (cpid) {
  906. case 0:
  907. epc = (unsigned int __user *)exception_epc(regs);
  908. old_epc = regs->cp0_epc;
  909. old31 = regs->regs[31];
  910. opcode = 0;
  911. status = -1;
  912. if (unlikely(compute_return_epc(regs) < 0))
  913. return;
  914. if (get_isa16_mode(regs->cp0_epc)) {
  915. unsigned short mmop[2] = { 0 };
  916. if (unlikely(get_user(mmop[0], epc) < 0))
  917. status = SIGSEGV;
  918. if (unlikely(get_user(mmop[1], epc) < 0))
  919. status = SIGSEGV;
  920. opcode = (mmop[0] << 16) | mmop[1];
  921. if (status < 0)
  922. status = simulate_rdhwr_mm(regs, opcode);
  923. } else {
  924. if (unlikely(get_user(opcode, epc) < 0))
  925. status = SIGSEGV;
  926. if (!cpu_has_llsc && status < 0)
  927. status = simulate_llsc(regs, opcode);
  928. if (status < 0)
  929. status = simulate_rdhwr_normal(regs, opcode);
  930. }
  931. if (status < 0)
  932. status = SIGILL;
  933. if (unlikely(status > 0)) {
  934. regs->cp0_epc = old_epc; /* Undo skip-over. */
  935. regs->regs[31] = old31;
  936. force_sig(status, current);
  937. }
  938. return;
  939. case 3:
  940. /*
  941. * Old (MIPS I and MIPS II) processors will set this code
  942. * for COP1X opcode instructions that replaced the original
  943. * COP3 space. We don't limit COP1 space instructions in
  944. * the emulator according to the CPU ISA, so we want to
  945. * treat COP1X instructions consistently regardless of which
  946. * code the CPU chose. Therefore we redirect this trap to
  947. * the FP emulator too.
  948. *
  949. * Then some newer FPU-less processors use this code
  950. * erroneously too, so they are covered by this choice
  951. * as well.
  952. */
  953. if (raw_cpu_has_fpu)
  954. break;
  955. /* Fall through. */
  956. case 1:
  957. if (used_math()) /* Using the FPU again. */
  958. own_fpu(1);
  959. else { /* First time FPU user. */
  960. init_fpu();
  961. set_used_math();
  962. }
  963. if (!raw_cpu_has_fpu) {
  964. int sig;
  965. void __user *fault_addr = NULL;
  966. sig = fpu_emulator_cop1Handler(regs,
  967. &current->thread.fpu,
  968. 0, &fault_addr);
  969. if (!process_fpemu_return(sig, fault_addr))
  970. mt_ase_fp_affinity();
  971. }
  972. return;
  973. case 2:
  974. raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
  975. return;
  976. }
  977. force_sig(SIGILL, current);
  978. }
  979. asmlinkage void do_mdmx(struct pt_regs *regs)
  980. {
  981. force_sig(SIGILL, current);
  982. }
  983. /*
  984. * Called with interrupts disabled.
  985. */
  986. asmlinkage void do_watch(struct pt_regs *regs)
  987. {
  988. u32 cause;
  989. /*
  990. * Clear WP (bit 22) bit of cause register so we don't loop
  991. * forever.
  992. */
  993. cause = read_c0_cause();
  994. cause &= ~(1 << 22);
  995. write_c0_cause(cause);
  996. /*
  997. * If the current thread has the watch registers loaded, save
  998. * their values and send SIGTRAP. Otherwise another thread
  999. * left the registers set, clear them and continue.
  1000. */
  1001. if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
  1002. mips_read_watch_registers();
  1003. local_irq_enable();
  1004. force_sig(SIGTRAP, current);
  1005. } else {
  1006. mips_clear_watch_registers();
  1007. local_irq_enable();
  1008. }
  1009. }
  1010. asmlinkage void do_mcheck(struct pt_regs *regs)
  1011. {
  1012. const int field = 2 * sizeof(unsigned long);
  1013. int multi_match = regs->cp0_status & ST0_TS;
  1014. show_regs(regs);
  1015. if (multi_match) {
  1016. printk("Index : %0x\n", read_c0_index());
  1017. printk("Pagemask: %0x\n", read_c0_pagemask());
  1018. printk("EntryHi : %0*lx\n", field, read_c0_entryhi());
  1019. printk("EntryLo0: %0*lx\n", field, read_c0_entrylo0());
  1020. printk("EntryLo1: %0*lx\n", field, read_c0_entrylo1());
  1021. printk("\n");
  1022. dump_tlb_all();
  1023. }
  1024. show_code((unsigned int __user *) regs->cp0_epc);
  1025. /*
  1026. * Some chips may have other causes of machine check (e.g. SB1
  1027. * graduation timer)
  1028. */
  1029. panic("Caught Machine Check exception - %scaused by multiple "
  1030. "matching entries in the TLB.",
  1031. (multi_match) ? "" : "not ");
  1032. }
  1033. asmlinkage void do_mt(struct pt_regs *regs)
  1034. {
  1035. int subcode;
  1036. subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
  1037. >> VPECONTROL_EXCPT_SHIFT;
  1038. switch (subcode) {
  1039. case 0:
  1040. printk(KERN_DEBUG "Thread Underflow\n");
  1041. break;
  1042. case 1:
  1043. printk(KERN_DEBUG "Thread Overflow\n");
  1044. break;
  1045. case 2:
  1046. printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
  1047. break;
  1048. case 3:
  1049. printk(KERN_DEBUG "Gating Storage Exception\n");
  1050. break;
  1051. case 4:
  1052. printk(KERN_DEBUG "YIELD Scheduler Exception\n");
  1053. break;
  1054. case 5:
  1055. printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
  1056. break;
  1057. default:
  1058. printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
  1059. subcode);
  1060. break;
  1061. }
  1062. die_if_kernel("MIPS MT Thread exception in kernel", regs);
  1063. force_sig(SIGILL, current);
  1064. }
  1065. asmlinkage void do_dsp(struct pt_regs *regs)
  1066. {
  1067. if (cpu_has_dsp)
  1068. panic("Unexpected DSP exception");
  1069. force_sig(SIGILL, current);
  1070. }
  1071. asmlinkage void do_reserved(struct pt_regs *regs)
  1072. {
  1073. /*
  1074. * Game over - no way to handle this if it ever occurs. Most probably
  1075. * caused by a new unknown cpu type or after another deadly
  1076. * hard/software error.
  1077. */
  1078. show_regs(regs);
  1079. panic("Caught reserved exception %ld - should not happen.",
  1080. (regs->cp0_cause & 0x7f) >> 2);
  1081. }
  1082. static int __initdata l1parity = 1;
  1083. static int __init nol1parity(char *s)
  1084. {
  1085. l1parity = 0;
  1086. return 1;
  1087. }
  1088. __setup("nol1par", nol1parity);
  1089. static int __initdata l2parity = 1;
  1090. static int __init nol2parity(char *s)
  1091. {
  1092. l2parity = 0;
  1093. return 1;
  1094. }
  1095. __setup("nol2par", nol2parity);
  1096. /*
  1097. * Some MIPS CPUs can enable/disable for cache parity detection, but do
  1098. * it different ways.
  1099. */
  1100. static inline void parity_protection_init(void)
  1101. {
  1102. switch (current_cpu_type()) {
  1103. case CPU_24K:
  1104. case CPU_34K:
  1105. case CPU_74K:
  1106. case CPU_1004K:
  1107. {
  1108. #define ERRCTL_PE 0x80000000
  1109. #define ERRCTL_L2P 0x00800000
  1110. unsigned long errctl;
  1111. unsigned int l1parity_present, l2parity_present;
  1112. errctl = read_c0_ecc();
  1113. errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
  1114. /* probe L1 parity support */
  1115. write_c0_ecc(errctl | ERRCTL_PE);
  1116. back_to_back_c0_hazard();
  1117. l1parity_present = (read_c0_ecc() & ERRCTL_PE);
  1118. /* probe L2 parity support */
  1119. write_c0_ecc(errctl|ERRCTL_L2P);
  1120. back_to_back_c0_hazard();
  1121. l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
  1122. if (l1parity_present && l2parity_present) {
  1123. if (l1parity)
  1124. errctl |= ERRCTL_PE;
  1125. if (l1parity ^ l2parity)
  1126. errctl |= ERRCTL_L2P;
  1127. } else if (l1parity_present) {
  1128. if (l1parity)
  1129. errctl |= ERRCTL_PE;
  1130. } else if (l2parity_present) {
  1131. if (l2parity)
  1132. errctl |= ERRCTL_L2P;
  1133. } else {
  1134. /* No parity available */
  1135. }
  1136. printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
  1137. write_c0_ecc(errctl);
  1138. back_to_back_c0_hazard();
  1139. errctl = read_c0_ecc();
  1140. printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
  1141. if (l1parity_present)
  1142. printk(KERN_INFO "Cache parity protection %sabled\n",
  1143. (errctl & ERRCTL_PE) ? "en" : "dis");
  1144. if (l2parity_present) {
  1145. if (l1parity_present && l1parity)
  1146. errctl ^= ERRCTL_L2P;
  1147. printk(KERN_INFO "L2 cache parity protection %sabled\n",
  1148. (errctl & ERRCTL_L2P) ? "en" : "dis");
  1149. }
  1150. }
  1151. break;
  1152. case CPU_5KC:
  1153. case CPU_5KE:
  1154. case CPU_LOONGSON1:
  1155. write_c0_ecc(0x80000000);
  1156. back_to_back_c0_hazard();
  1157. /* Set the PE bit (bit 31) in the c0_errctl register. */
  1158. printk(KERN_INFO "Cache parity protection %sabled\n",
  1159. (read_c0_ecc() & 0x80000000) ? "en" : "dis");
  1160. break;
  1161. case CPU_20KC:
  1162. case CPU_25KF:
  1163. /* Clear the DE bit (bit 16) in the c0_status register. */
  1164. printk(KERN_INFO "Enable cache parity protection for "
  1165. "MIPS 20KC/25KF CPUs.\n");
  1166. clear_c0_status(ST0_DE);
  1167. break;
  1168. default:
  1169. break;
  1170. }
  1171. }
  1172. asmlinkage void cache_parity_error(void)
  1173. {
  1174. const int field = 2 * sizeof(unsigned long);
  1175. unsigned int reg_val;
  1176. /* For the moment, report the problem and hang. */
  1177. printk("Cache error exception:\n");
  1178. printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
  1179. reg_val = read_c0_cacheerr();
  1180. printk("c0_cacheerr == %08x\n", reg_val);
  1181. printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
  1182. reg_val & (1<<30) ? "secondary" : "primary",
  1183. reg_val & (1<<31) ? "data" : "insn");
  1184. printk("Error bits: %s%s%s%s%s%s%s\n",
  1185. reg_val & (1<<29) ? "ED " : "",
  1186. reg_val & (1<<28) ? "ET " : "",
  1187. reg_val & (1<<26) ? "EE " : "",
  1188. reg_val & (1<<25) ? "EB " : "",
  1189. reg_val & (1<<24) ? "EI " : "",
  1190. reg_val & (1<<23) ? "E1 " : "",
  1191. reg_val & (1<<22) ? "E0 " : "");
  1192. printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
  1193. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  1194. if (reg_val & (1<<22))
  1195. printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
  1196. if (reg_val & (1<<23))
  1197. printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
  1198. #endif
  1199. panic("Can't handle the cache error!");
  1200. }
  1201. /*
  1202. * SDBBP EJTAG debug exception handler.
  1203. * We skip the instruction and return to the next instruction.
  1204. */
  1205. void ejtag_exception_handler(struct pt_regs *regs)
  1206. {
  1207. const int field = 2 * sizeof(unsigned long);
  1208. unsigned long depc, old_epc, old_ra;
  1209. unsigned int debug;
  1210. printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
  1211. depc = read_c0_depc();
  1212. debug = read_c0_debug();
  1213. printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
  1214. if (debug & 0x80000000) {
  1215. /*
  1216. * In branch delay slot.
  1217. * We cheat a little bit here and use EPC to calculate the
  1218. * debug return address (DEPC). EPC is restored after the
  1219. * calculation.
  1220. */
  1221. old_epc = regs->cp0_epc;
  1222. old_ra = regs->regs[31];
  1223. regs->cp0_epc = depc;
  1224. compute_return_epc(regs);
  1225. depc = regs->cp0_epc;
  1226. regs->cp0_epc = old_epc;
  1227. regs->regs[31] = old_ra;
  1228. } else
  1229. depc += 4;
  1230. write_c0_depc(depc);
  1231. #if 0
  1232. printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
  1233. write_c0_debug(debug | 0x100);
  1234. #endif
  1235. }
  1236. /*
  1237. * NMI exception handler.
  1238. * No lock; only written during early bootup by CPU 0.
  1239. */
  1240. static RAW_NOTIFIER_HEAD(nmi_chain);
  1241. int register_nmi_notifier(struct notifier_block *nb)
  1242. {
  1243. return raw_notifier_chain_register(&nmi_chain, nb);
  1244. }
  1245. void __noreturn nmi_exception_handler(struct pt_regs *regs)
  1246. {
  1247. raw_notifier_call_chain(&nmi_chain, 0, regs);
  1248. bust_spinlocks(1);
  1249. printk("NMI taken!!!!\n");
  1250. die("NMI", regs);
  1251. }
  1252. #define VECTORSPACING 0x100 /* for EI/VI mode */
  1253. unsigned long ebase;
  1254. unsigned long exception_handlers[32];
  1255. unsigned long vi_handlers[64];
  1256. void __init *set_except_vector(int n, void *addr)
  1257. {
  1258. unsigned long handler = (unsigned long) addr;
  1259. unsigned long old_handler;
  1260. #ifdef CONFIG_CPU_MICROMIPS
  1261. /*
  1262. * Only the TLB handlers are cache aligned with an even
  1263. * address. All other handlers are on an odd address and
  1264. * require no modification. Otherwise, MIPS32 mode will
  1265. * be entered when handling any TLB exceptions. That
  1266. * would be bad...since we must stay in microMIPS mode.
  1267. */
  1268. if (!(handler & 0x1))
  1269. handler |= 1;
  1270. #endif
  1271. old_handler = xchg(&exception_handlers[n], handler);
  1272. if (n == 0 && cpu_has_divec) {
  1273. #ifdef CONFIG_CPU_MICROMIPS
  1274. unsigned long jump_mask = ~((1 << 27) - 1);
  1275. #else
  1276. unsigned long jump_mask = ~((1 << 28) - 1);
  1277. #endif
  1278. u32 *buf = (u32 *)(ebase + 0x200);
  1279. unsigned int k0 = 26;
  1280. if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
  1281. uasm_i_j(&buf, handler & ~jump_mask);
  1282. uasm_i_nop(&buf);
  1283. } else {
  1284. UASM_i_LA(&buf, k0, handler);
  1285. uasm_i_jr(&buf, k0);
  1286. uasm_i_nop(&buf);
  1287. }
  1288. local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
  1289. }
  1290. return (void *)old_handler;
  1291. }
  1292. static void do_default_vi(void)
  1293. {
  1294. show_regs(get_irq_regs());
  1295. panic("Caught unexpected vectored interrupt.");
  1296. }
  1297. static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
  1298. {
  1299. unsigned long handler;
  1300. unsigned long old_handler = vi_handlers[n];
  1301. int srssets = current_cpu_data.srsets;
  1302. u16 *h;
  1303. unsigned char *b;
  1304. BUG_ON(!cpu_has_veic && !cpu_has_vint);
  1305. BUG_ON((n < 0) && (n > 9));
  1306. if (addr == NULL) {
  1307. handler = (unsigned long) do_default_vi;
  1308. srs = 0;
  1309. } else
  1310. handler = (unsigned long) addr;
  1311. vi_handlers[n] = handler;
  1312. b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
  1313. if (srs >= srssets)
  1314. panic("Shadow register set %d not supported", srs);
  1315. if (cpu_has_veic) {
  1316. if (board_bind_eic_interrupt)
  1317. board_bind_eic_interrupt(n, srs);
  1318. } else if (cpu_has_vint) {
  1319. /* SRSMap is only defined if shadow sets are implemented */
  1320. if (srssets > 1)
  1321. change_c0_srsmap(0xf << n*4, srs << n*4);
  1322. }
  1323. if (srs == 0) {
  1324. /*
  1325. * If no shadow set is selected then use the default handler
  1326. * that does normal register saving and standard interrupt exit
  1327. */
  1328. extern char except_vec_vi, except_vec_vi_lui;
  1329. extern char except_vec_vi_ori, except_vec_vi_end;
  1330. extern char rollback_except_vec_vi;
  1331. char *vec_start = (cpu_wait == r4k_wait) ?
  1332. &rollback_except_vec_vi : &except_vec_vi;
  1333. #ifdef CONFIG_MIPS_MT_SMTC
  1334. /*
  1335. * We need to provide the SMTC vectored interrupt handler
  1336. * not only with the address of the handler, but with the
  1337. * Status.IM bit to be masked before going there.
  1338. */
  1339. extern char except_vec_vi_mori;
  1340. #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
  1341. const int mori_offset = &except_vec_vi_mori - vec_start + 2;
  1342. #else
  1343. const int mori_offset = &except_vec_vi_mori - vec_start;
  1344. #endif
  1345. #endif /* CONFIG_MIPS_MT_SMTC */
  1346. #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
  1347. const int lui_offset = &except_vec_vi_lui - vec_start + 2;
  1348. const int ori_offset = &except_vec_vi_ori - vec_start + 2;
  1349. #else
  1350. const int lui_offset = &except_vec_vi_lui - vec_start;
  1351. const int ori_offset = &except_vec_vi_ori - vec_start;
  1352. #endif
  1353. const int handler_len = &except_vec_vi_end - vec_start;
  1354. if (handler_len > VECTORSPACING) {
  1355. /*
  1356. * Sigh... panicing won't help as the console
  1357. * is probably not configured :(
  1358. */
  1359. panic("VECTORSPACING too small");
  1360. }
  1361. set_handler(((unsigned long)b - ebase), vec_start,
  1362. #ifdef CONFIG_CPU_MICROMIPS
  1363. (handler_len - 1));
  1364. #else
  1365. handler_len);
  1366. #endif
  1367. #ifdef CONFIG_MIPS_MT_SMTC
  1368. BUG_ON(n > 7); /* Vector index %d exceeds SMTC maximum. */
  1369. h = (u16 *)(b + mori_offset);
  1370. *h = (0x100 << n);
  1371. #endif /* CONFIG_MIPS_MT_SMTC */
  1372. h = (u16 *)(b + lui_offset);
  1373. *h = (handler >> 16) & 0xffff;
  1374. h = (u16 *)(b + ori_offset);
  1375. *h = (handler & 0xffff);
  1376. local_flush_icache_range((unsigned long)b,
  1377. (unsigned long)(b+handler_len));
  1378. }
  1379. else {
  1380. /*
  1381. * In other cases jump directly to the interrupt handler. It
  1382. * is the handler's responsibility to save registers if required
  1383. * (eg hi/lo) and return from the exception using "eret".
  1384. */
  1385. u32 insn;
  1386. h = (u16 *)b;
  1387. /* j handler */
  1388. #ifdef CONFIG_CPU_MICROMIPS
  1389. insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
  1390. #else
  1391. insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
  1392. #endif
  1393. h[0] = (insn >> 16) & 0xffff;
  1394. h[1] = insn & 0xffff;
  1395. h[2] = 0;
  1396. h[3] = 0;
  1397. local_flush_icache_range((unsigned long)b,
  1398. (unsigned long)(b+8));
  1399. }
  1400. return (void *)old_handler;
  1401. }
  1402. void *set_vi_handler(int n, vi_handler_t addr)
  1403. {
  1404. return set_vi_srs_handler(n, addr, 0);
  1405. }
  1406. extern void tlb_init(void);
  1407. extern void flush_tlb_handlers(void);
  1408. /*
  1409. * Timer interrupt
  1410. */
  1411. int cp0_compare_irq;
  1412. EXPORT_SYMBOL_GPL(cp0_compare_irq);
  1413. int cp0_compare_irq_shift;
  1414. /*
  1415. * Performance counter IRQ or -1 if shared with timer
  1416. */
  1417. int cp0_perfcount_irq;
  1418. EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
  1419. static int __cpuinitdata noulri;
  1420. static int __init ulri_disable(char *s)
  1421. {
  1422. pr_info("Disabling ulri\n");
  1423. noulri = 1;
  1424. return 1;
  1425. }
  1426. __setup("noulri", ulri_disable);
  1427. void __cpuinit per_cpu_trap_init(bool is_boot_cpu)
  1428. {
  1429. unsigned int cpu = smp_processor_id();
  1430. unsigned int status_set = ST0_CU0;
  1431. unsigned int hwrena = cpu_hwrena_impl_bits;
  1432. unsigned long asid = 0;
  1433. #ifdef CONFIG_MIPS_MT_SMTC
  1434. int secondaryTC = 0;
  1435. int bootTC = (cpu == 0);
  1436. /*
  1437. * Only do per_cpu_trap_init() for first TC of Each VPE.
  1438. * Note that this hack assumes that the SMTC init code
  1439. * assigns TCs consecutively and in ascending order.
  1440. */
  1441. if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
  1442. ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id))
  1443. secondaryTC = 1;
  1444. #endif /* CONFIG_MIPS_MT_SMTC */
  1445. /*
  1446. * Disable coprocessors and select 32-bit or 64-bit addressing
  1447. * and the 16/32 or 32/32 FPR register model. Reset the BEV
  1448. * flag that some firmware may have left set and the TS bit (for
  1449. * IP27). Set XX for ISA IV code to work.
  1450. */
  1451. #ifdef CONFIG_64BIT
  1452. status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
  1453. #endif
  1454. if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
  1455. status_set |= ST0_XX;
  1456. if (cpu_has_dsp)
  1457. status_set |= ST0_MX;
  1458. change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
  1459. status_set);
  1460. if (cpu_has_mips_r2)
  1461. hwrena |= 0x0000000f;
  1462. if (!noulri && cpu_has_userlocal)
  1463. hwrena |= (1 << 29);
  1464. if (hwrena)
  1465. write_c0_hwrena(hwrena);
  1466. #ifdef CONFIG_MIPS_MT_SMTC
  1467. if (!secondaryTC) {
  1468. #endif /* CONFIG_MIPS_MT_SMTC */
  1469. if (cpu_has_veic || cpu_has_vint) {
  1470. unsigned long sr = set_c0_status(ST0_BEV);
  1471. write_c0_ebase(ebase);
  1472. write_c0_status(sr);
  1473. /* Setting vector spacing enables EI/VI mode */
  1474. change_c0_intctl(0x3e0, VECTORSPACING);
  1475. }
  1476. if (cpu_has_divec) {
  1477. if (cpu_has_mipsmt) {
  1478. unsigned int vpflags = dvpe();
  1479. set_c0_cause(CAUSEF_IV);
  1480. evpe(vpflags);
  1481. } else
  1482. set_c0_cause(CAUSEF_IV);
  1483. }
  1484. /*
  1485. * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
  1486. *
  1487. * o read IntCtl.IPTI to determine the timer interrupt
  1488. * o read IntCtl.IPPCI to determine the performance counter interrupt
  1489. */
  1490. if (cpu_has_mips_r2) {
  1491. cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
  1492. cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
  1493. cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
  1494. if (cp0_perfcount_irq == cp0_compare_irq)
  1495. cp0_perfcount_irq = -1;
  1496. } else {
  1497. cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
  1498. cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
  1499. cp0_perfcount_irq = -1;
  1500. }
  1501. #ifdef CONFIG_MIPS_MT_SMTC
  1502. }
  1503. #endif /* CONFIG_MIPS_MT_SMTC */
  1504. asid = ASID_FIRST_VERSION;
  1505. cpu_data[cpu].asid_cache = asid;
  1506. TLBMISS_HANDLER_SETUP();
  1507. atomic_inc(&init_mm.mm_count);
  1508. current->active_mm = &init_mm;
  1509. BUG_ON(current->mm);
  1510. enter_lazy_tlb(&init_mm, current);
  1511. #ifdef CONFIG_MIPS_MT_SMTC
  1512. if (bootTC) {
  1513. #endif /* CONFIG_MIPS_MT_SMTC */
  1514. /* Boot CPU's cache setup in setup_arch(). */
  1515. if (!is_boot_cpu)
  1516. cpu_cache_init();
  1517. tlb_init();
  1518. #ifdef CONFIG_MIPS_MT_SMTC
  1519. } else if (!secondaryTC) {
  1520. /*
  1521. * First TC in non-boot VPE must do subset of tlb_init()
  1522. * for MMU countrol registers.
  1523. */
  1524. write_c0_pagemask(PM_DEFAULT_MASK);
  1525. write_c0_wired(0);
  1526. }
  1527. #endif /* CONFIG_MIPS_MT_SMTC */
  1528. TLBMISS_HANDLER_SETUP();
  1529. }
  1530. /* Install CPU exception handler */
  1531. void __cpuinit set_handler(unsigned long offset, void *addr, unsigned long size)
  1532. {
  1533. #ifdef CONFIG_CPU_MICROMIPS
  1534. memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
  1535. #else
  1536. memcpy((void *)(ebase + offset), addr, size);
  1537. #endif
  1538. local_flush_icache_range(ebase + offset, ebase + offset + size);
  1539. }
  1540. static char panic_null_cerr[] __cpuinitdata =
  1541. "Trying to set NULL cache error exception handler";
  1542. /*
  1543. * Install uncached CPU exception handler.
  1544. * This is suitable only for the cache error exception which is the only
  1545. * exception handler that is being run uncached.
  1546. */
  1547. void __cpuinit set_uncached_handler(unsigned long offset, void *addr,
  1548. unsigned long size)
  1549. {
  1550. unsigned long uncached_ebase = CKSEG1ADDR(ebase);
  1551. if (!addr)
  1552. panic(panic_null_cerr);
  1553. memcpy((void *)(uncached_ebase + offset), addr, size);
  1554. }
  1555. static int __initdata rdhwr_noopt;
  1556. static int __init set_rdhwr_noopt(char *str)
  1557. {
  1558. rdhwr_noopt = 1;
  1559. return 1;
  1560. }
  1561. __setup("rdhwr_noopt", set_rdhwr_noopt);
  1562. void __init trap_init(void)
  1563. {
  1564. extern char except_vec3_generic;
  1565. extern char except_vec4;
  1566. extern char except_vec3_r4000;
  1567. unsigned long i;
  1568. int rollback;
  1569. check_wait();
  1570. rollback = (cpu_wait == r4k_wait);
  1571. #if defined(CONFIG_KGDB)
  1572. if (kgdb_early_setup)
  1573. return; /* Already done */
  1574. #endif
  1575. if (cpu_has_veic || cpu_has_vint) {
  1576. unsigned long size = 0x200 + VECTORSPACING*64;
  1577. ebase = (unsigned long)
  1578. __alloc_bootmem(size, 1 << fls(size), 0);
  1579. } else {
  1580. #ifdef CONFIG_KVM_GUEST
  1581. #define KVM_GUEST_KSEG0 0x40000000
  1582. ebase = KVM_GUEST_KSEG0;
  1583. #else
  1584. ebase = CKSEG0;
  1585. #endif
  1586. if (cpu_has_mips_r2)
  1587. ebase += (read_c0_ebase() & 0x3ffff000);
  1588. }
  1589. if (board_ebase_setup)
  1590. board_ebase_setup();
  1591. per_cpu_trap_init(true);
  1592. /*
  1593. * Copy the generic exception handlers to their final destination.
  1594. * This will be overriden later as suitable for a particular
  1595. * configuration.
  1596. */
  1597. set_handler(0x180, &except_vec3_generic, 0x80);
  1598. /*
  1599. * Setup default vectors
  1600. */
  1601. for (i = 0; i <= 31; i++)
  1602. set_except_vector(i, handle_reserved);
  1603. /*
  1604. * Copy the EJTAG debug exception vector handler code to it's final
  1605. * destination.
  1606. */
  1607. if (cpu_has_ejtag && board_ejtag_handler_setup)
  1608. board_ejtag_handler_setup();
  1609. /*
  1610. * Only some CPUs have the watch exceptions.
  1611. */
  1612. if (cpu_has_watch)
  1613. set_except_vector(23, handle_watch);
  1614. /*
  1615. * Initialise interrupt handlers
  1616. */
  1617. if (cpu_has_veic || cpu_has_vint) {
  1618. int nvec = cpu_has_veic ? 64 : 8;
  1619. for (i = 0; i < nvec; i++)
  1620. set_vi_handler(i, NULL);
  1621. }
  1622. else if (cpu_has_divec)
  1623. set_handler(0x200, &except_vec4, 0x8);
  1624. /*
  1625. * Some CPUs can enable/disable for cache parity detection, but does
  1626. * it different ways.
  1627. */
  1628. parity_protection_init();
  1629. /*
  1630. * The Data Bus Errors / Instruction Bus Errors are signaled
  1631. * by external hardware. Therefore these two exceptions
  1632. * may have board specific handlers.
  1633. */
  1634. if (board_be_init)
  1635. board_be_init();
  1636. set_except_vector(0, rollback ? rollback_handle_int : 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. }