traps.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517
  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. * Copyright (C) 2014, Imagination Technologies Ltd.
  14. */
  15. #include <linux/bitops.h>
  16. #include <linux/bug.h>
  17. #include <linux/compiler.h>
  18. #include <linux/context_tracking.h>
  19. #include <linux/cpu_pm.h>
  20. #include <linux/kexec.h>
  21. #include <linux/init.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/extable.h>
  25. #include <linux/mm.h>
  26. #include <linux/sched.h>
  27. #include <linux/smp.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/kallsyms.h>
  30. #include <linux/bootmem.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/ptrace.h>
  33. #include <linux/kgdb.h>
  34. #include <linux/kdebug.h>
  35. #include <linux/kprobes.h>
  36. #include <linux/notifier.h>
  37. #include <linux/kdb.h>
  38. #include <linux/irq.h>
  39. #include <linux/perf_event.h>
  40. #include <asm/addrspace.h>
  41. #include <asm/bootinfo.h>
  42. #include <asm/branch.h>
  43. #include <asm/break.h>
  44. #include <asm/cop2.h>
  45. #include <asm/cpu.h>
  46. #include <asm/cpu-type.h>
  47. #include <asm/dsp.h>
  48. #include <asm/fpu.h>
  49. #include <asm/fpu_emulator.h>
  50. #include <asm/idle.h>
  51. #include <asm/mips-cm.h>
  52. #include <asm/mips-r2-to-r6-emul.h>
  53. #include <asm/mips-cm.h>
  54. #include <asm/mipsregs.h>
  55. #include <asm/mipsmtregs.h>
  56. #include <asm/module.h>
  57. #include <asm/msa.h>
  58. #include <asm/pgtable.h>
  59. #include <asm/ptrace.h>
  60. #include <asm/sections.h>
  61. #include <asm/siginfo.h>
  62. #include <asm/tlbdebug.h>
  63. #include <asm/traps.h>
  64. #include <asm/uaccess.h>
  65. #include <asm/watch.h>
  66. #include <asm/mmu_context.h>
  67. #include <asm/types.h>
  68. #include <asm/stacktrace.h>
  69. #include <asm/uasm.h>
  70. extern void check_wait(void);
  71. extern asmlinkage void rollback_handle_int(void);
  72. extern asmlinkage void handle_int(void);
  73. extern u32 handle_tlbl[];
  74. extern u32 handle_tlbs[];
  75. extern u32 handle_tlbm[];
  76. extern asmlinkage void handle_adel(void);
  77. extern asmlinkage void handle_ades(void);
  78. extern asmlinkage void handle_ibe(void);
  79. extern asmlinkage void handle_dbe(void);
  80. extern asmlinkage void handle_sys(void);
  81. extern asmlinkage void handle_bp(void);
  82. extern asmlinkage void handle_ri(void);
  83. extern asmlinkage void handle_ri_rdhwr_tlbp(void);
  84. extern asmlinkage void handle_ri_rdhwr(void);
  85. extern asmlinkage void handle_cpu(void);
  86. extern asmlinkage void handle_ov(void);
  87. extern asmlinkage void handle_tr(void);
  88. extern asmlinkage void handle_msa_fpe(void);
  89. extern asmlinkage void handle_fpe(void);
  90. extern asmlinkage void handle_ftlb(void);
  91. extern asmlinkage void handle_msa(void);
  92. extern asmlinkage void handle_mdmx(void);
  93. extern asmlinkage void handle_watch(void);
  94. extern asmlinkage void handle_mt(void);
  95. extern asmlinkage void handle_dsp(void);
  96. extern asmlinkage void handle_mcheck(void);
  97. extern asmlinkage void handle_reserved(void);
  98. extern void tlb_do_page_fault_0(void);
  99. void (*board_be_init)(void);
  100. int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
  101. void (*board_nmi_handler_setup)(void);
  102. void (*board_ejtag_handler_setup)(void);
  103. void (*board_bind_eic_interrupt)(int irq, int regset);
  104. void (*board_ebase_setup)(void);
  105. void(*board_cache_error_setup)(void);
  106. static void show_raw_backtrace(unsigned long reg29)
  107. {
  108. unsigned long *sp = (unsigned long *)(reg29 & ~3);
  109. unsigned long addr;
  110. printk("Call Trace:");
  111. #ifdef CONFIG_KALLSYMS
  112. printk("\n");
  113. #endif
  114. while (!kstack_end(sp)) {
  115. unsigned long __user *p =
  116. (unsigned long __user *)(unsigned long)sp++;
  117. if (__get_user(addr, p)) {
  118. printk(" (Bad stack address)");
  119. break;
  120. }
  121. if (__kernel_text_address(addr))
  122. print_ip_sym(addr);
  123. }
  124. printk("\n");
  125. }
  126. #ifdef CONFIG_KALLSYMS
  127. int raw_show_trace;
  128. static int __init set_raw_show_trace(char *str)
  129. {
  130. raw_show_trace = 1;
  131. return 1;
  132. }
  133. __setup("raw_show_trace", set_raw_show_trace);
  134. #endif
  135. static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
  136. {
  137. unsigned long sp = regs->regs[29];
  138. unsigned long ra = regs->regs[31];
  139. unsigned long pc = regs->cp0_epc;
  140. if (!task)
  141. task = current;
  142. if (raw_show_trace || user_mode(regs) || !__kernel_text_address(pc)) {
  143. show_raw_backtrace(sp);
  144. return;
  145. }
  146. printk("Call Trace:\n");
  147. do {
  148. print_ip_sym(pc);
  149. pc = unwind_stack(task, &sp, pc, &ra);
  150. } while (pc);
  151. pr_cont("\n");
  152. }
  153. /*
  154. * This routine abuses get_user()/put_user() to reference pointers
  155. * with at least a bit of error checking ...
  156. */
  157. static void show_stacktrace(struct task_struct *task,
  158. const struct pt_regs *regs)
  159. {
  160. const int field = 2 * sizeof(unsigned long);
  161. long stackdata;
  162. int i;
  163. unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
  164. printk("Stack :");
  165. i = 0;
  166. while ((unsigned long) sp & (PAGE_SIZE - 1)) {
  167. if (i && ((i % (64 / field)) == 0)) {
  168. pr_cont("\n");
  169. printk(" ");
  170. }
  171. if (i > 39) {
  172. pr_cont(" ...");
  173. break;
  174. }
  175. if (__get_user(stackdata, sp++)) {
  176. pr_cont(" (Bad stack address)");
  177. break;
  178. }
  179. pr_cont(" %0*lx", field, stackdata);
  180. i++;
  181. }
  182. pr_cont("\n");
  183. show_backtrace(task, regs);
  184. }
  185. void show_stack(struct task_struct *task, unsigned long *sp)
  186. {
  187. struct pt_regs regs;
  188. mm_segment_t old_fs = get_fs();
  189. regs.cp0_status = KSU_KERNEL;
  190. if (sp) {
  191. regs.regs[29] = (unsigned long)sp;
  192. regs.regs[31] = 0;
  193. regs.cp0_epc = 0;
  194. } else {
  195. if (task && task != current) {
  196. regs.regs[29] = task->thread.reg29;
  197. regs.regs[31] = 0;
  198. regs.cp0_epc = task->thread.reg31;
  199. #ifdef CONFIG_KGDB_KDB
  200. } else if (atomic_read(&kgdb_active) != -1 &&
  201. kdb_current_regs) {
  202. memcpy(&regs, kdb_current_regs, sizeof(regs));
  203. #endif /* CONFIG_KGDB_KDB */
  204. } else {
  205. prepare_frametrace(&regs);
  206. }
  207. }
  208. /*
  209. * show_stack() deals exclusively with kernel mode, so be sure to access
  210. * the stack in the kernel (not user) address space.
  211. */
  212. set_fs(KERNEL_DS);
  213. show_stacktrace(task, &regs);
  214. set_fs(old_fs);
  215. }
  216. static void show_code(unsigned int __user *pc)
  217. {
  218. long i;
  219. unsigned short __user *pc16 = NULL;
  220. printk("Code:");
  221. if ((unsigned long)pc & 1)
  222. pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
  223. for(i = -3 ; i < 6 ; i++) {
  224. unsigned int insn;
  225. if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
  226. pr_cont(" (Bad address in epc)\n");
  227. break;
  228. }
  229. pr_cont("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
  230. }
  231. pr_cont("\n");
  232. }
  233. static void __show_regs(const struct pt_regs *regs)
  234. {
  235. const int field = 2 * sizeof(unsigned long);
  236. unsigned int cause = regs->cp0_cause;
  237. unsigned int exccode;
  238. int i;
  239. show_regs_print_info(KERN_DEFAULT);
  240. /*
  241. * Saved main processor registers
  242. */
  243. for (i = 0; i < 32; ) {
  244. if ((i % 4) == 0)
  245. printk("$%2d :", i);
  246. if (i == 0)
  247. pr_cont(" %0*lx", field, 0UL);
  248. else if (i == 26 || i == 27)
  249. pr_cont(" %*s", field, "");
  250. else
  251. pr_cont(" %0*lx", field, regs->regs[i]);
  252. i++;
  253. if ((i % 4) == 0)
  254. pr_cont("\n");
  255. }
  256. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  257. printk("Acx : %0*lx\n", field, regs->acx);
  258. #endif
  259. printk("Hi : %0*lx\n", field, regs->hi);
  260. printk("Lo : %0*lx\n", field, regs->lo);
  261. /*
  262. * Saved cp0 registers
  263. */
  264. printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
  265. (void *) regs->cp0_epc);
  266. printk("ra : %0*lx %pS\n", field, regs->regs[31],
  267. (void *) regs->regs[31]);
  268. printk("Status: %08x ", (uint32_t) regs->cp0_status);
  269. if (cpu_has_3kex) {
  270. if (regs->cp0_status & ST0_KUO)
  271. pr_cont("KUo ");
  272. if (regs->cp0_status & ST0_IEO)
  273. pr_cont("IEo ");
  274. if (regs->cp0_status & ST0_KUP)
  275. pr_cont("KUp ");
  276. if (regs->cp0_status & ST0_IEP)
  277. pr_cont("IEp ");
  278. if (regs->cp0_status & ST0_KUC)
  279. pr_cont("KUc ");
  280. if (regs->cp0_status & ST0_IEC)
  281. pr_cont("IEc ");
  282. } else if (cpu_has_4kex) {
  283. if (regs->cp0_status & ST0_KX)
  284. pr_cont("KX ");
  285. if (regs->cp0_status & ST0_SX)
  286. pr_cont("SX ");
  287. if (regs->cp0_status & ST0_UX)
  288. pr_cont("UX ");
  289. switch (regs->cp0_status & ST0_KSU) {
  290. case KSU_USER:
  291. pr_cont("USER ");
  292. break;
  293. case KSU_SUPERVISOR:
  294. pr_cont("SUPERVISOR ");
  295. break;
  296. case KSU_KERNEL:
  297. pr_cont("KERNEL ");
  298. break;
  299. default:
  300. pr_cont("BAD_MODE ");
  301. break;
  302. }
  303. if (regs->cp0_status & ST0_ERL)
  304. pr_cont("ERL ");
  305. if (regs->cp0_status & ST0_EXL)
  306. pr_cont("EXL ");
  307. if (regs->cp0_status & ST0_IE)
  308. pr_cont("IE ");
  309. }
  310. pr_cont("\n");
  311. exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
  312. printk("Cause : %08x (ExcCode %02x)\n", cause, exccode);
  313. if (1 <= exccode && exccode <= 5)
  314. printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
  315. printk("PrId : %08x (%s)\n", read_c0_prid(),
  316. cpu_name_string());
  317. }
  318. /*
  319. * FIXME: really the generic show_regs should take a const pointer argument.
  320. */
  321. void show_regs(struct pt_regs *regs)
  322. {
  323. __show_regs((struct pt_regs *)regs);
  324. dump_stack();
  325. }
  326. void show_registers(struct pt_regs *regs)
  327. {
  328. const int field = 2 * sizeof(unsigned long);
  329. mm_segment_t old_fs = get_fs();
  330. __show_regs(regs);
  331. print_modules();
  332. printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
  333. current->comm, current->pid, current_thread_info(), current,
  334. field, current_thread_info()->tp_value);
  335. if (cpu_has_userlocal) {
  336. unsigned long tls;
  337. tls = read_c0_userlocal();
  338. if (tls != current_thread_info()->tp_value)
  339. printk("*HwTLS: %0*lx\n", field, tls);
  340. }
  341. if (!user_mode(regs))
  342. /* Necessary for getting the correct stack content */
  343. set_fs(KERNEL_DS);
  344. show_stacktrace(current, regs);
  345. show_code((unsigned int __user *) regs->cp0_epc);
  346. printk("\n");
  347. set_fs(old_fs);
  348. }
  349. static DEFINE_RAW_SPINLOCK(die_lock);
  350. void __noreturn die(const char *str, struct pt_regs *regs)
  351. {
  352. static int die_counter;
  353. int sig = SIGSEGV;
  354. oops_enter();
  355. if (notify_die(DIE_OOPS, str, regs, 0, current->thread.trap_nr,
  356. SIGSEGV) == NOTIFY_STOP)
  357. sig = 0;
  358. console_verbose();
  359. raw_spin_lock_irq(&die_lock);
  360. bust_spinlocks(1);
  361. printk("%s[#%d]:\n", str, ++die_counter);
  362. show_registers(regs);
  363. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  364. raw_spin_unlock_irq(&die_lock);
  365. oops_exit();
  366. if (in_interrupt())
  367. panic("Fatal exception in interrupt");
  368. if (panic_on_oops)
  369. panic("Fatal exception");
  370. if (regs && kexec_should_crash(current))
  371. crash_kexec(regs);
  372. do_exit(sig);
  373. }
  374. extern struct exception_table_entry __start___dbe_table[];
  375. extern struct exception_table_entry __stop___dbe_table[];
  376. __asm__(
  377. " .section __dbe_table, \"a\"\n"
  378. " .previous \n");
  379. /* Given an address, look for it in the exception tables. */
  380. static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
  381. {
  382. const struct exception_table_entry *e;
  383. e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
  384. if (!e)
  385. e = search_module_dbetables(addr);
  386. return e;
  387. }
  388. asmlinkage void do_be(struct pt_regs *regs)
  389. {
  390. const int field = 2 * sizeof(unsigned long);
  391. const struct exception_table_entry *fixup = NULL;
  392. int data = regs->cp0_cause & 4;
  393. int action = MIPS_BE_FATAL;
  394. enum ctx_state prev_state;
  395. prev_state = exception_enter();
  396. /* XXX For now. Fixme, this searches the wrong table ... */
  397. if (data && !user_mode(regs))
  398. fixup = search_dbe_tables(exception_epc(regs));
  399. if (fixup)
  400. action = MIPS_BE_FIXUP;
  401. if (board_be_handler)
  402. action = board_be_handler(regs, fixup != NULL);
  403. else
  404. mips_cm_error_report();
  405. switch (action) {
  406. case MIPS_BE_DISCARD:
  407. goto out;
  408. case MIPS_BE_FIXUP:
  409. if (fixup) {
  410. regs->cp0_epc = fixup->nextinsn;
  411. goto out;
  412. }
  413. break;
  414. default:
  415. break;
  416. }
  417. /*
  418. * Assume it would be too dangerous to continue ...
  419. */
  420. printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
  421. data ? "Data" : "Instruction",
  422. field, regs->cp0_epc, field, regs->regs[31]);
  423. if (notify_die(DIE_OOPS, "bus error", regs, 0, current->thread.trap_nr,
  424. SIGBUS) == NOTIFY_STOP)
  425. goto out;
  426. die_if_kernel("Oops", regs);
  427. force_sig(SIGBUS, current);
  428. out:
  429. exception_exit(prev_state);
  430. }
  431. /*
  432. * ll/sc, rdhwr, sync emulation
  433. */
  434. #define OPCODE 0xfc000000
  435. #define BASE 0x03e00000
  436. #define RT 0x001f0000
  437. #define OFFSET 0x0000ffff
  438. #define LL 0xc0000000
  439. #define SC 0xe0000000
  440. #define SPEC0 0x00000000
  441. #define SPEC3 0x7c000000
  442. #define RD 0x0000f800
  443. #define FUNC 0x0000003f
  444. #define SYNC 0x0000000f
  445. #define RDHWR 0x0000003b
  446. /* microMIPS definitions */
  447. #define MM_POOL32A_FUNC 0xfc00ffff
  448. #define MM_RDHWR 0x00006b3c
  449. #define MM_RS 0x001f0000
  450. #define MM_RT 0x03e00000
  451. /*
  452. * The ll_bit is cleared by r*_switch.S
  453. */
  454. unsigned int ll_bit;
  455. struct task_struct *ll_task;
  456. static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
  457. {
  458. unsigned long value, __user *vaddr;
  459. long offset;
  460. /*
  461. * analyse the ll instruction that just caused a ri exception
  462. * and put the referenced address to addr.
  463. */
  464. /* sign extend offset */
  465. offset = opcode & OFFSET;
  466. offset <<= 16;
  467. offset >>= 16;
  468. vaddr = (unsigned long __user *)
  469. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  470. if ((unsigned long)vaddr & 3)
  471. return SIGBUS;
  472. if (get_user(value, vaddr))
  473. return SIGSEGV;
  474. preempt_disable();
  475. if (ll_task == NULL || ll_task == current) {
  476. ll_bit = 1;
  477. } else {
  478. ll_bit = 0;
  479. }
  480. ll_task = current;
  481. preempt_enable();
  482. regs->regs[(opcode & RT) >> 16] = value;
  483. return 0;
  484. }
  485. static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
  486. {
  487. unsigned long __user *vaddr;
  488. unsigned long reg;
  489. long offset;
  490. /*
  491. * analyse the sc instruction that just caused a ri exception
  492. * and put the referenced address to addr.
  493. */
  494. /* sign extend offset */
  495. offset = opcode & OFFSET;
  496. offset <<= 16;
  497. offset >>= 16;
  498. vaddr = (unsigned long __user *)
  499. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  500. reg = (opcode & RT) >> 16;
  501. if ((unsigned long)vaddr & 3)
  502. return SIGBUS;
  503. preempt_disable();
  504. if (ll_bit == 0 || ll_task != current) {
  505. regs->regs[reg] = 0;
  506. preempt_enable();
  507. return 0;
  508. }
  509. preempt_enable();
  510. if (put_user(regs->regs[reg], vaddr))
  511. return SIGSEGV;
  512. regs->regs[reg] = 1;
  513. return 0;
  514. }
  515. /*
  516. * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
  517. * opcodes are supposed to result in coprocessor unusable exceptions if
  518. * executed on ll/sc-less processors. That's the theory. In practice a
  519. * few processors such as NEC's VR4100 throw reserved instruction exceptions
  520. * instead, so we're doing the emulation thing in both exception handlers.
  521. */
  522. static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
  523. {
  524. if ((opcode & OPCODE) == LL) {
  525. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  526. 1, regs, 0);
  527. return simulate_ll(regs, opcode);
  528. }
  529. if ((opcode & OPCODE) == SC) {
  530. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  531. 1, regs, 0);
  532. return simulate_sc(regs, opcode);
  533. }
  534. return -1; /* Must be something else ... */
  535. }
  536. /*
  537. * Simulate trapping 'rdhwr' instructions to provide user accessible
  538. * registers not implemented in hardware.
  539. */
  540. static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
  541. {
  542. struct thread_info *ti = task_thread_info(current);
  543. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  544. 1, regs, 0);
  545. switch (rd) {
  546. case MIPS_HWR_CPUNUM: /* CPU number */
  547. regs->regs[rt] = smp_processor_id();
  548. return 0;
  549. case MIPS_HWR_SYNCISTEP: /* SYNCI length */
  550. regs->regs[rt] = min(current_cpu_data.dcache.linesz,
  551. current_cpu_data.icache.linesz);
  552. return 0;
  553. case MIPS_HWR_CC: /* Read count register */
  554. regs->regs[rt] = read_c0_count();
  555. return 0;
  556. case MIPS_HWR_CCRES: /* Count register resolution */
  557. switch (current_cpu_type()) {
  558. case CPU_20KC:
  559. case CPU_25KF:
  560. regs->regs[rt] = 1;
  561. break;
  562. default:
  563. regs->regs[rt] = 2;
  564. }
  565. return 0;
  566. case MIPS_HWR_ULR: /* Read UserLocal register */
  567. regs->regs[rt] = ti->tp_value;
  568. return 0;
  569. default:
  570. return -1;
  571. }
  572. }
  573. static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
  574. {
  575. if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
  576. int rd = (opcode & RD) >> 11;
  577. int rt = (opcode & RT) >> 16;
  578. simulate_rdhwr(regs, rd, rt);
  579. return 0;
  580. }
  581. /* Not ours. */
  582. return -1;
  583. }
  584. static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned int opcode)
  585. {
  586. if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
  587. int rd = (opcode & MM_RS) >> 16;
  588. int rt = (opcode & MM_RT) >> 21;
  589. simulate_rdhwr(regs, rd, rt);
  590. return 0;
  591. }
  592. /* Not ours. */
  593. return -1;
  594. }
  595. static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
  596. {
  597. if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
  598. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  599. 1, regs, 0);
  600. return 0;
  601. }
  602. return -1; /* Must be something else ... */
  603. }
  604. asmlinkage void do_ov(struct pt_regs *regs)
  605. {
  606. enum ctx_state prev_state;
  607. siginfo_t info = {
  608. .si_signo = SIGFPE,
  609. .si_code = FPE_INTOVF,
  610. .si_addr = (void __user *)regs->cp0_epc,
  611. };
  612. prev_state = exception_enter();
  613. die_if_kernel("Integer overflow", regs);
  614. force_sig_info(SIGFPE, &info, current);
  615. exception_exit(prev_state);
  616. }
  617. /*
  618. * Send SIGFPE according to FCSR Cause bits, which must have already
  619. * been masked against Enable bits. This is impotant as Inexact can
  620. * happen together with Overflow or Underflow, and `ptrace' can set
  621. * any bits.
  622. */
  623. void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
  624. struct task_struct *tsk)
  625. {
  626. struct siginfo si = { .si_addr = fault_addr, .si_signo = SIGFPE };
  627. if (fcr31 & FPU_CSR_INV_X)
  628. si.si_code = FPE_FLTINV;
  629. else if (fcr31 & FPU_CSR_DIV_X)
  630. si.si_code = FPE_FLTDIV;
  631. else if (fcr31 & FPU_CSR_OVF_X)
  632. si.si_code = FPE_FLTOVF;
  633. else if (fcr31 & FPU_CSR_UDF_X)
  634. si.si_code = FPE_FLTUND;
  635. else if (fcr31 & FPU_CSR_INE_X)
  636. si.si_code = FPE_FLTRES;
  637. else
  638. si.si_code = __SI_FAULT;
  639. force_sig_info(SIGFPE, &si, tsk);
  640. }
  641. int process_fpemu_return(int sig, void __user *fault_addr, unsigned long fcr31)
  642. {
  643. struct siginfo si = { 0 };
  644. struct vm_area_struct *vma;
  645. switch (sig) {
  646. case 0:
  647. return 0;
  648. case SIGFPE:
  649. force_fcr31_sig(fcr31, fault_addr, current);
  650. return 1;
  651. case SIGBUS:
  652. si.si_addr = fault_addr;
  653. si.si_signo = sig;
  654. si.si_code = BUS_ADRERR;
  655. force_sig_info(sig, &si, current);
  656. return 1;
  657. case SIGSEGV:
  658. si.si_addr = fault_addr;
  659. si.si_signo = sig;
  660. down_read(&current->mm->mmap_sem);
  661. vma = find_vma(current->mm, (unsigned long)fault_addr);
  662. if (vma && (vma->vm_start <= (unsigned long)fault_addr))
  663. si.si_code = SEGV_ACCERR;
  664. else
  665. si.si_code = SEGV_MAPERR;
  666. up_read(&current->mm->mmap_sem);
  667. force_sig_info(sig, &si, current);
  668. return 1;
  669. default:
  670. force_sig(sig, current);
  671. return 1;
  672. }
  673. }
  674. static int simulate_fp(struct pt_regs *regs, unsigned int opcode,
  675. unsigned long old_epc, unsigned long old_ra)
  676. {
  677. union mips_instruction inst = { .word = opcode };
  678. void __user *fault_addr;
  679. unsigned long fcr31;
  680. int sig;
  681. /* If it's obviously not an FP instruction, skip it */
  682. switch (inst.i_format.opcode) {
  683. case cop1_op:
  684. case cop1x_op:
  685. case lwc1_op:
  686. case ldc1_op:
  687. case swc1_op:
  688. case sdc1_op:
  689. break;
  690. default:
  691. return -1;
  692. }
  693. /*
  694. * do_ri skipped over the instruction via compute_return_epc, undo
  695. * that for the FPU emulator.
  696. */
  697. regs->cp0_epc = old_epc;
  698. regs->regs[31] = old_ra;
  699. /* Save the FP context to struct thread_struct */
  700. lose_fpu(1);
  701. /* Run the emulator */
  702. sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
  703. &fault_addr);
  704. /*
  705. * We can't allow the emulated instruction to leave any
  706. * enabled Cause bits set in $fcr31.
  707. */
  708. fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
  709. current->thread.fpu.fcr31 &= ~fcr31;
  710. /* Restore the hardware register state */
  711. own_fpu(1);
  712. /* Send a signal if required. */
  713. process_fpemu_return(sig, fault_addr, fcr31);
  714. return 0;
  715. }
  716. /*
  717. * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
  718. */
  719. asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
  720. {
  721. enum ctx_state prev_state;
  722. void __user *fault_addr;
  723. int sig;
  724. prev_state = exception_enter();
  725. if (notify_die(DIE_FP, "FP exception", regs, 0, current->thread.trap_nr,
  726. SIGFPE) == NOTIFY_STOP)
  727. goto out;
  728. /* Clear FCSR.Cause before enabling interrupts */
  729. write_32bit_cp1_register(CP1_STATUS, fcr31 & ~mask_fcr31_x(fcr31));
  730. local_irq_enable();
  731. die_if_kernel("FP exception in kernel code", regs);
  732. if (fcr31 & FPU_CSR_UNI_X) {
  733. /*
  734. * Unimplemented operation exception. If we've got the full
  735. * software emulator on-board, let's use it...
  736. *
  737. * Force FPU to dump state into task/thread context. We're
  738. * moving a lot of data here for what is probably a single
  739. * instruction, but the alternative is to pre-decode the FP
  740. * register operands before invoking the emulator, which seems
  741. * a bit extreme for what should be an infrequent event.
  742. */
  743. /* Ensure 'resume' not overwrite saved fp context again. */
  744. lose_fpu(1);
  745. /* Run the emulator */
  746. sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
  747. &fault_addr);
  748. /*
  749. * We can't allow the emulated instruction to leave any
  750. * enabled Cause bits set in $fcr31.
  751. */
  752. fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
  753. current->thread.fpu.fcr31 &= ~fcr31;
  754. /* Restore the hardware register state */
  755. own_fpu(1); /* Using the FPU again. */
  756. } else {
  757. sig = SIGFPE;
  758. fault_addr = (void __user *) regs->cp0_epc;
  759. }
  760. /* Send a signal if required. */
  761. process_fpemu_return(sig, fault_addr, fcr31);
  762. out:
  763. exception_exit(prev_state);
  764. }
  765. void do_trap_or_bp(struct pt_regs *regs, unsigned int code, int si_code,
  766. const char *str)
  767. {
  768. siginfo_t info = { 0 };
  769. char b[40];
  770. #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
  771. if (kgdb_ll_trap(DIE_TRAP, str, regs, code, current->thread.trap_nr,
  772. SIGTRAP) == NOTIFY_STOP)
  773. return;
  774. #endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
  775. if (notify_die(DIE_TRAP, str, regs, code, current->thread.trap_nr,
  776. SIGTRAP) == NOTIFY_STOP)
  777. return;
  778. /*
  779. * A short test says that IRIX 5.3 sends SIGTRAP for all trap
  780. * insns, even for trap and break codes that indicate arithmetic
  781. * failures. Weird ...
  782. * But should we continue the brokenness??? --macro
  783. */
  784. switch (code) {
  785. case BRK_OVERFLOW:
  786. case BRK_DIVZERO:
  787. scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
  788. die_if_kernel(b, regs);
  789. if (code == BRK_DIVZERO)
  790. info.si_code = FPE_INTDIV;
  791. else
  792. info.si_code = FPE_INTOVF;
  793. info.si_signo = SIGFPE;
  794. info.si_addr = (void __user *) regs->cp0_epc;
  795. force_sig_info(SIGFPE, &info, current);
  796. break;
  797. case BRK_BUG:
  798. die_if_kernel("Kernel bug detected", regs);
  799. force_sig(SIGTRAP, current);
  800. break;
  801. case BRK_MEMU:
  802. /*
  803. * This breakpoint code is used by the FPU emulator to retake
  804. * control of the CPU after executing the instruction from the
  805. * delay slot of an emulated branch.
  806. *
  807. * Terminate if exception was recognized as a delay slot return
  808. * otherwise handle as normal.
  809. */
  810. if (do_dsemulret(regs))
  811. return;
  812. die_if_kernel("Math emu break/trap", regs);
  813. force_sig(SIGTRAP, current);
  814. break;
  815. default:
  816. scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
  817. die_if_kernel(b, regs);
  818. if (si_code) {
  819. info.si_signo = SIGTRAP;
  820. info.si_code = si_code;
  821. force_sig_info(SIGTRAP, &info, current);
  822. } else {
  823. force_sig(SIGTRAP, current);
  824. }
  825. }
  826. }
  827. asmlinkage void do_bp(struct pt_regs *regs)
  828. {
  829. unsigned long epc = msk_isa16_mode(exception_epc(regs));
  830. unsigned int opcode, bcode;
  831. enum ctx_state prev_state;
  832. mm_segment_t seg;
  833. seg = get_fs();
  834. if (!user_mode(regs))
  835. set_fs(KERNEL_DS);
  836. prev_state = exception_enter();
  837. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  838. if (get_isa16_mode(regs->cp0_epc)) {
  839. u16 instr[2];
  840. if (__get_user(instr[0], (u16 __user *)epc))
  841. goto out_sigsegv;
  842. if (!cpu_has_mmips) {
  843. /* MIPS16e mode */
  844. bcode = (instr[0] >> 5) & 0x3f;
  845. } else if (mm_insn_16bit(instr[0])) {
  846. /* 16-bit microMIPS BREAK */
  847. bcode = instr[0] & 0xf;
  848. } else {
  849. /* 32-bit microMIPS BREAK */
  850. if (__get_user(instr[1], (u16 __user *)(epc + 2)))
  851. goto out_sigsegv;
  852. opcode = (instr[0] << 16) | instr[1];
  853. bcode = (opcode >> 6) & ((1 << 20) - 1);
  854. }
  855. } else {
  856. if (__get_user(opcode, (unsigned int __user *)epc))
  857. goto out_sigsegv;
  858. bcode = (opcode >> 6) & ((1 << 20) - 1);
  859. }
  860. /*
  861. * There is the ancient bug in the MIPS assemblers that the break
  862. * code starts left to bit 16 instead to bit 6 in the opcode.
  863. * Gas is bug-compatible, but not always, grrr...
  864. * We handle both cases with a simple heuristics. --macro
  865. */
  866. if (bcode >= (1 << 10))
  867. bcode = ((bcode & ((1 << 10) - 1)) << 10) | (bcode >> 10);
  868. /*
  869. * notify the kprobe handlers, if instruction is likely to
  870. * pertain to them.
  871. */
  872. switch (bcode) {
  873. case BRK_UPROBE:
  874. if (notify_die(DIE_UPROBE, "uprobe", regs, bcode,
  875. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  876. goto out;
  877. else
  878. break;
  879. case BRK_UPROBE_XOL:
  880. if (notify_die(DIE_UPROBE_XOL, "uprobe_xol", regs, bcode,
  881. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  882. goto out;
  883. else
  884. break;
  885. case BRK_KPROBE_BP:
  886. if (notify_die(DIE_BREAK, "debug", regs, bcode,
  887. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  888. goto out;
  889. else
  890. break;
  891. case BRK_KPROBE_SSTEPBP:
  892. if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode,
  893. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  894. goto out;
  895. else
  896. break;
  897. default:
  898. break;
  899. }
  900. do_trap_or_bp(regs, bcode, TRAP_BRKPT, "Break");
  901. out:
  902. set_fs(seg);
  903. exception_exit(prev_state);
  904. return;
  905. out_sigsegv:
  906. force_sig(SIGSEGV, current);
  907. goto out;
  908. }
  909. asmlinkage void do_tr(struct pt_regs *regs)
  910. {
  911. u32 opcode, tcode = 0;
  912. enum ctx_state prev_state;
  913. u16 instr[2];
  914. mm_segment_t seg;
  915. unsigned long epc = msk_isa16_mode(exception_epc(regs));
  916. seg = get_fs();
  917. if (!user_mode(regs))
  918. set_fs(get_ds());
  919. prev_state = exception_enter();
  920. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  921. if (get_isa16_mode(regs->cp0_epc)) {
  922. if (__get_user(instr[0], (u16 __user *)(epc + 0)) ||
  923. __get_user(instr[1], (u16 __user *)(epc + 2)))
  924. goto out_sigsegv;
  925. opcode = (instr[0] << 16) | instr[1];
  926. /* Immediate versions don't provide a code. */
  927. if (!(opcode & OPCODE))
  928. tcode = (opcode >> 12) & ((1 << 4) - 1);
  929. } else {
  930. if (__get_user(opcode, (u32 __user *)epc))
  931. goto out_sigsegv;
  932. /* Immediate versions don't provide a code. */
  933. if (!(opcode & OPCODE))
  934. tcode = (opcode >> 6) & ((1 << 10) - 1);
  935. }
  936. do_trap_or_bp(regs, tcode, 0, "Trap");
  937. out:
  938. set_fs(seg);
  939. exception_exit(prev_state);
  940. return;
  941. out_sigsegv:
  942. force_sig(SIGSEGV, current);
  943. goto out;
  944. }
  945. asmlinkage void do_ri(struct pt_regs *regs)
  946. {
  947. unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
  948. unsigned long old_epc = regs->cp0_epc;
  949. unsigned long old31 = regs->regs[31];
  950. enum ctx_state prev_state;
  951. unsigned int opcode = 0;
  952. int status = -1;
  953. /*
  954. * Avoid any kernel code. Just emulate the R2 instruction
  955. * as quickly as possible.
  956. */
  957. if (mipsr2_emulation && cpu_has_mips_r6 &&
  958. likely(user_mode(regs)) &&
  959. likely(get_user(opcode, epc) >= 0)) {
  960. unsigned long fcr31 = 0;
  961. status = mipsr2_decoder(regs, opcode, &fcr31);
  962. switch (status) {
  963. case 0:
  964. case SIGEMT:
  965. task_thread_info(current)->r2_emul_return = 1;
  966. return;
  967. case SIGILL:
  968. goto no_r2_instr;
  969. default:
  970. process_fpemu_return(status,
  971. &current->thread.cp0_baduaddr,
  972. fcr31);
  973. task_thread_info(current)->r2_emul_return = 1;
  974. return;
  975. }
  976. }
  977. no_r2_instr:
  978. prev_state = exception_enter();
  979. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  980. if (notify_die(DIE_RI, "RI Fault", regs, 0, current->thread.trap_nr,
  981. SIGILL) == NOTIFY_STOP)
  982. goto out;
  983. die_if_kernel("Reserved instruction in kernel code", regs);
  984. if (unlikely(compute_return_epc(regs) < 0))
  985. goto out;
  986. if (!get_isa16_mode(regs->cp0_epc)) {
  987. if (unlikely(get_user(opcode, epc) < 0))
  988. status = SIGSEGV;
  989. if (!cpu_has_llsc && status < 0)
  990. status = simulate_llsc(regs, opcode);
  991. if (status < 0)
  992. status = simulate_rdhwr_normal(regs, opcode);
  993. if (status < 0)
  994. status = simulate_sync(regs, opcode);
  995. if (status < 0)
  996. status = simulate_fp(regs, opcode, old_epc, old31);
  997. } else if (cpu_has_mmips) {
  998. unsigned short mmop[2] = { 0 };
  999. if (unlikely(get_user(mmop[0], (u16 __user *)epc + 0) < 0))
  1000. status = SIGSEGV;
  1001. if (unlikely(get_user(mmop[1], (u16 __user *)epc + 1) < 0))
  1002. status = SIGSEGV;
  1003. opcode = mmop[0];
  1004. opcode = (opcode << 16) | mmop[1];
  1005. if (status < 0)
  1006. status = simulate_rdhwr_mm(regs, opcode);
  1007. }
  1008. if (status < 0)
  1009. status = SIGILL;
  1010. if (unlikely(status > 0)) {
  1011. regs->cp0_epc = old_epc; /* Undo skip-over. */
  1012. regs->regs[31] = old31;
  1013. force_sig(status, current);
  1014. }
  1015. out:
  1016. exception_exit(prev_state);
  1017. }
  1018. /*
  1019. * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
  1020. * emulated more than some threshold number of instructions, force migration to
  1021. * a "CPU" that has FP support.
  1022. */
  1023. static void mt_ase_fp_affinity(void)
  1024. {
  1025. #ifdef CONFIG_MIPS_MT_FPAFF
  1026. if (mt_fpemul_threshold > 0 &&
  1027. ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
  1028. /*
  1029. * If there's no FPU present, or if the application has already
  1030. * restricted the allowed set to exclude any CPUs with FPUs,
  1031. * we'll skip the procedure.
  1032. */
  1033. if (cpumask_intersects(&current->cpus_allowed, &mt_fpu_cpumask)) {
  1034. cpumask_t tmask;
  1035. current->thread.user_cpus_allowed
  1036. = current->cpus_allowed;
  1037. cpumask_and(&tmask, &current->cpus_allowed,
  1038. &mt_fpu_cpumask);
  1039. set_cpus_allowed_ptr(current, &tmask);
  1040. set_thread_flag(TIF_FPUBOUND);
  1041. }
  1042. }
  1043. #endif /* CONFIG_MIPS_MT_FPAFF */
  1044. }
  1045. /*
  1046. * No lock; only written during early bootup by CPU 0.
  1047. */
  1048. static RAW_NOTIFIER_HEAD(cu2_chain);
  1049. int __ref register_cu2_notifier(struct notifier_block *nb)
  1050. {
  1051. return raw_notifier_chain_register(&cu2_chain, nb);
  1052. }
  1053. int cu2_notifier_call_chain(unsigned long val, void *v)
  1054. {
  1055. return raw_notifier_call_chain(&cu2_chain, val, v);
  1056. }
  1057. static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
  1058. void *data)
  1059. {
  1060. struct pt_regs *regs = data;
  1061. die_if_kernel("COP2: Unhandled kernel unaligned access or invalid "
  1062. "instruction", regs);
  1063. force_sig(SIGILL, current);
  1064. return NOTIFY_OK;
  1065. }
  1066. static int wait_on_fp_mode_switch(atomic_t *p)
  1067. {
  1068. /*
  1069. * The FP mode for this task is currently being switched. That may
  1070. * involve modifications to the format of this tasks FP context which
  1071. * make it unsafe to proceed with execution for the moment. Instead,
  1072. * schedule some other task.
  1073. */
  1074. schedule();
  1075. return 0;
  1076. }
  1077. static int enable_restore_fp_context(int msa)
  1078. {
  1079. int err, was_fpu_owner, prior_msa;
  1080. /*
  1081. * If an FP mode switch is currently underway, wait for it to
  1082. * complete before proceeding.
  1083. */
  1084. wait_on_atomic_t(&current->mm->context.fp_mode_switching,
  1085. wait_on_fp_mode_switch, TASK_KILLABLE);
  1086. if (!used_math()) {
  1087. /* First time FP context user. */
  1088. preempt_disable();
  1089. err = init_fpu();
  1090. if (msa && !err) {
  1091. enable_msa();
  1092. init_msa_upper();
  1093. set_thread_flag(TIF_USEDMSA);
  1094. set_thread_flag(TIF_MSA_CTX_LIVE);
  1095. }
  1096. preempt_enable();
  1097. if (!err)
  1098. set_used_math();
  1099. return err;
  1100. }
  1101. /*
  1102. * This task has formerly used the FP context.
  1103. *
  1104. * If this thread has no live MSA vector context then we can simply
  1105. * restore the scalar FP context. If it has live MSA vector context
  1106. * (that is, it has or may have used MSA since last performing a
  1107. * function call) then we'll need to restore the vector context. This
  1108. * applies even if we're currently only executing a scalar FP
  1109. * instruction. This is because if we were to later execute an MSA
  1110. * instruction then we'd either have to:
  1111. *
  1112. * - Restore the vector context & clobber any registers modified by
  1113. * scalar FP instructions between now & then.
  1114. *
  1115. * or
  1116. *
  1117. * - Not restore the vector context & lose the most significant bits
  1118. * of all vector registers.
  1119. *
  1120. * Neither of those options is acceptable. We cannot restore the least
  1121. * significant bits of the registers now & only restore the most
  1122. * significant bits later because the most significant bits of any
  1123. * vector registers whose aliased FP register is modified now will have
  1124. * been zeroed. We'd have no way to know that when restoring the vector
  1125. * context & thus may load an outdated value for the most significant
  1126. * bits of a vector register.
  1127. */
  1128. if (!msa && !thread_msa_context_live())
  1129. return own_fpu(1);
  1130. /*
  1131. * This task is using or has previously used MSA. Thus we require
  1132. * that Status.FR == 1.
  1133. */
  1134. preempt_disable();
  1135. was_fpu_owner = is_fpu_owner();
  1136. err = own_fpu_inatomic(0);
  1137. if (err)
  1138. goto out;
  1139. enable_msa();
  1140. write_msa_csr(current->thread.fpu.msacsr);
  1141. set_thread_flag(TIF_USEDMSA);
  1142. /*
  1143. * If this is the first time that the task is using MSA and it has
  1144. * previously used scalar FP in this time slice then we already nave
  1145. * FP context which we shouldn't clobber. We do however need to clear
  1146. * the upper 64b of each vector register so that this task has no
  1147. * opportunity to see data left behind by another.
  1148. */
  1149. prior_msa = test_and_set_thread_flag(TIF_MSA_CTX_LIVE);
  1150. if (!prior_msa && was_fpu_owner) {
  1151. init_msa_upper();
  1152. goto out;
  1153. }
  1154. if (!prior_msa) {
  1155. /*
  1156. * Restore the least significant 64b of each vector register
  1157. * from the existing scalar FP context.
  1158. */
  1159. _restore_fp(current);
  1160. /*
  1161. * The task has not formerly used MSA, so clear the upper 64b
  1162. * of each vector register such that it cannot see data left
  1163. * behind by another task.
  1164. */
  1165. init_msa_upper();
  1166. } else {
  1167. /* We need to restore the vector context. */
  1168. restore_msa(current);
  1169. /* Restore the scalar FP control & status register */
  1170. if (!was_fpu_owner)
  1171. write_32bit_cp1_register(CP1_STATUS,
  1172. current->thread.fpu.fcr31);
  1173. }
  1174. out:
  1175. preempt_enable();
  1176. return 0;
  1177. }
  1178. asmlinkage void do_cpu(struct pt_regs *regs)
  1179. {
  1180. enum ctx_state prev_state;
  1181. unsigned int __user *epc;
  1182. unsigned long old_epc, old31;
  1183. void __user *fault_addr;
  1184. unsigned int opcode;
  1185. unsigned long fcr31;
  1186. unsigned int cpid;
  1187. int status, err;
  1188. int sig;
  1189. prev_state = exception_enter();
  1190. cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
  1191. if (cpid != 2)
  1192. die_if_kernel("do_cpu invoked from kernel context!", regs);
  1193. switch (cpid) {
  1194. case 0:
  1195. epc = (unsigned int __user *)exception_epc(regs);
  1196. old_epc = regs->cp0_epc;
  1197. old31 = regs->regs[31];
  1198. opcode = 0;
  1199. status = -1;
  1200. if (unlikely(compute_return_epc(regs) < 0))
  1201. break;
  1202. if (!get_isa16_mode(regs->cp0_epc)) {
  1203. if (unlikely(get_user(opcode, epc) < 0))
  1204. status = SIGSEGV;
  1205. if (!cpu_has_llsc && status < 0)
  1206. status = simulate_llsc(regs, opcode);
  1207. }
  1208. if (status < 0)
  1209. status = SIGILL;
  1210. if (unlikely(status > 0)) {
  1211. regs->cp0_epc = old_epc; /* Undo skip-over. */
  1212. regs->regs[31] = old31;
  1213. force_sig(status, current);
  1214. }
  1215. break;
  1216. case 3:
  1217. /*
  1218. * The COP3 opcode space and consequently the CP0.Status.CU3
  1219. * bit and the CP0.Cause.CE=3 encoding have been removed as
  1220. * of the MIPS III ISA. From the MIPS IV and MIPS32r2 ISAs
  1221. * up the space has been reused for COP1X instructions, that
  1222. * are enabled by the CP0.Status.CU1 bit and consequently
  1223. * use the CP0.Cause.CE=1 encoding for Coprocessor Unusable
  1224. * exceptions. Some FPU-less processors that implement one
  1225. * of these ISAs however use this code erroneously for COP1X
  1226. * instructions. Therefore we redirect this trap to the FP
  1227. * emulator too.
  1228. */
  1229. if (raw_cpu_has_fpu || !cpu_has_mips_4_5_64_r2_r6) {
  1230. force_sig(SIGILL, current);
  1231. break;
  1232. }
  1233. /* Fall through. */
  1234. case 1:
  1235. err = enable_restore_fp_context(0);
  1236. if (raw_cpu_has_fpu && !err)
  1237. break;
  1238. sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 0,
  1239. &fault_addr);
  1240. /*
  1241. * We can't allow the emulated instruction to leave
  1242. * any enabled Cause bits set in $fcr31.
  1243. */
  1244. fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
  1245. current->thread.fpu.fcr31 &= ~fcr31;
  1246. /* Send a signal if required. */
  1247. if (!process_fpemu_return(sig, fault_addr, fcr31) && !err)
  1248. mt_ase_fp_affinity();
  1249. break;
  1250. case 2:
  1251. raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
  1252. break;
  1253. }
  1254. exception_exit(prev_state);
  1255. }
  1256. asmlinkage void do_msa_fpe(struct pt_regs *regs, unsigned int msacsr)
  1257. {
  1258. enum ctx_state prev_state;
  1259. prev_state = exception_enter();
  1260. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  1261. if (notify_die(DIE_MSAFP, "MSA FP exception", regs, 0,
  1262. current->thread.trap_nr, SIGFPE) == NOTIFY_STOP)
  1263. goto out;
  1264. /* Clear MSACSR.Cause before enabling interrupts */
  1265. write_msa_csr(msacsr & ~MSA_CSR_CAUSEF);
  1266. local_irq_enable();
  1267. die_if_kernel("do_msa_fpe invoked from kernel context!", regs);
  1268. force_sig(SIGFPE, current);
  1269. out:
  1270. exception_exit(prev_state);
  1271. }
  1272. asmlinkage void do_msa(struct pt_regs *regs)
  1273. {
  1274. enum ctx_state prev_state;
  1275. int err;
  1276. prev_state = exception_enter();
  1277. if (!cpu_has_msa || test_thread_flag(TIF_32BIT_FPREGS)) {
  1278. force_sig(SIGILL, current);
  1279. goto out;
  1280. }
  1281. die_if_kernel("do_msa invoked from kernel context!", regs);
  1282. err = enable_restore_fp_context(1);
  1283. if (err)
  1284. force_sig(SIGILL, current);
  1285. out:
  1286. exception_exit(prev_state);
  1287. }
  1288. asmlinkage void do_mdmx(struct pt_regs *regs)
  1289. {
  1290. enum ctx_state prev_state;
  1291. prev_state = exception_enter();
  1292. force_sig(SIGILL, current);
  1293. exception_exit(prev_state);
  1294. }
  1295. /*
  1296. * Called with interrupts disabled.
  1297. */
  1298. asmlinkage void do_watch(struct pt_regs *regs)
  1299. {
  1300. siginfo_t info = { .si_signo = SIGTRAP, .si_code = TRAP_HWBKPT };
  1301. enum ctx_state prev_state;
  1302. prev_state = exception_enter();
  1303. /*
  1304. * Clear WP (bit 22) bit of cause register so we don't loop
  1305. * forever.
  1306. */
  1307. clear_c0_cause(CAUSEF_WP);
  1308. /*
  1309. * If the current thread has the watch registers loaded, save
  1310. * their values and send SIGTRAP. Otherwise another thread
  1311. * left the registers set, clear them and continue.
  1312. */
  1313. if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
  1314. mips_read_watch_registers();
  1315. local_irq_enable();
  1316. force_sig_info(SIGTRAP, &info, current);
  1317. } else {
  1318. mips_clear_watch_registers();
  1319. local_irq_enable();
  1320. }
  1321. exception_exit(prev_state);
  1322. }
  1323. asmlinkage void do_mcheck(struct pt_regs *regs)
  1324. {
  1325. int multi_match = regs->cp0_status & ST0_TS;
  1326. enum ctx_state prev_state;
  1327. mm_segment_t old_fs = get_fs();
  1328. prev_state = exception_enter();
  1329. show_regs(regs);
  1330. if (multi_match) {
  1331. dump_tlb_regs();
  1332. pr_info("\n");
  1333. dump_tlb_all();
  1334. }
  1335. if (!user_mode(regs))
  1336. set_fs(KERNEL_DS);
  1337. show_code((unsigned int __user *) regs->cp0_epc);
  1338. set_fs(old_fs);
  1339. /*
  1340. * Some chips may have other causes of machine check (e.g. SB1
  1341. * graduation timer)
  1342. */
  1343. panic("Caught Machine Check exception - %scaused by multiple "
  1344. "matching entries in the TLB.",
  1345. (multi_match) ? "" : "not ");
  1346. }
  1347. asmlinkage void do_mt(struct pt_regs *regs)
  1348. {
  1349. int subcode;
  1350. subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
  1351. >> VPECONTROL_EXCPT_SHIFT;
  1352. switch (subcode) {
  1353. case 0:
  1354. printk(KERN_DEBUG "Thread Underflow\n");
  1355. break;
  1356. case 1:
  1357. printk(KERN_DEBUG "Thread Overflow\n");
  1358. break;
  1359. case 2:
  1360. printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
  1361. break;
  1362. case 3:
  1363. printk(KERN_DEBUG "Gating Storage Exception\n");
  1364. break;
  1365. case 4:
  1366. printk(KERN_DEBUG "YIELD Scheduler Exception\n");
  1367. break;
  1368. case 5:
  1369. printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
  1370. break;
  1371. default:
  1372. printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
  1373. subcode);
  1374. break;
  1375. }
  1376. die_if_kernel("MIPS MT Thread exception in kernel", regs);
  1377. force_sig(SIGILL, current);
  1378. }
  1379. asmlinkage void do_dsp(struct pt_regs *regs)
  1380. {
  1381. if (cpu_has_dsp)
  1382. panic("Unexpected DSP exception");
  1383. force_sig(SIGILL, current);
  1384. }
  1385. asmlinkage void do_reserved(struct pt_regs *regs)
  1386. {
  1387. /*
  1388. * Game over - no way to handle this if it ever occurs. Most probably
  1389. * caused by a new unknown cpu type or after another deadly
  1390. * hard/software error.
  1391. */
  1392. show_regs(regs);
  1393. panic("Caught reserved exception %ld - should not happen.",
  1394. (regs->cp0_cause & 0x7f) >> 2);
  1395. }
  1396. static int __initdata l1parity = 1;
  1397. static int __init nol1parity(char *s)
  1398. {
  1399. l1parity = 0;
  1400. return 1;
  1401. }
  1402. __setup("nol1par", nol1parity);
  1403. static int __initdata l2parity = 1;
  1404. static int __init nol2parity(char *s)
  1405. {
  1406. l2parity = 0;
  1407. return 1;
  1408. }
  1409. __setup("nol2par", nol2parity);
  1410. /*
  1411. * Some MIPS CPUs can enable/disable for cache parity detection, but do
  1412. * it different ways.
  1413. */
  1414. static inline void parity_protection_init(void)
  1415. {
  1416. #define ERRCTL_PE 0x80000000
  1417. #define ERRCTL_L2P 0x00800000
  1418. if (mips_cm_revision() >= CM_REV_CM3) {
  1419. ulong gcr_ectl, cp0_ectl;
  1420. /*
  1421. * With CM3 systems we need to ensure that the L1 & L2
  1422. * parity enables are set to the same value, since this
  1423. * is presumed by the hardware engineers.
  1424. *
  1425. * If the user disabled either of L1 or L2 ECC checking,
  1426. * disable both.
  1427. */
  1428. l1parity &= l2parity;
  1429. l2parity &= l1parity;
  1430. /* Probe L1 ECC support */
  1431. cp0_ectl = read_c0_ecc();
  1432. write_c0_ecc(cp0_ectl | ERRCTL_PE);
  1433. back_to_back_c0_hazard();
  1434. cp0_ectl = read_c0_ecc();
  1435. /* Probe L2 ECC support */
  1436. gcr_ectl = read_gcr_err_control();
  1437. if (!(gcr_ectl & CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT_MSK) ||
  1438. !(cp0_ectl & ERRCTL_PE)) {
  1439. /*
  1440. * One of L1 or L2 ECC checking isn't supported,
  1441. * so we cannot enable either.
  1442. */
  1443. l1parity = l2parity = 0;
  1444. }
  1445. /* Configure L1 ECC checking */
  1446. if (l1parity)
  1447. cp0_ectl |= ERRCTL_PE;
  1448. else
  1449. cp0_ectl &= ~ERRCTL_PE;
  1450. write_c0_ecc(cp0_ectl);
  1451. back_to_back_c0_hazard();
  1452. WARN_ON(!!(read_c0_ecc() & ERRCTL_PE) != l1parity);
  1453. /* Configure L2 ECC checking */
  1454. if (l2parity)
  1455. gcr_ectl |= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
  1456. else
  1457. gcr_ectl &= ~CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
  1458. write_gcr_err_control(gcr_ectl);
  1459. gcr_ectl = read_gcr_err_control();
  1460. gcr_ectl &= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
  1461. WARN_ON(!!gcr_ectl != l2parity);
  1462. pr_info("Cache parity protection %sabled\n",
  1463. l1parity ? "en" : "dis");
  1464. return;
  1465. }
  1466. switch (current_cpu_type()) {
  1467. case CPU_24K:
  1468. case CPU_34K:
  1469. case CPU_74K:
  1470. case CPU_1004K:
  1471. case CPU_1074K:
  1472. case CPU_INTERAPTIV:
  1473. case CPU_PROAPTIV:
  1474. case CPU_P5600:
  1475. case CPU_QEMU_GENERIC:
  1476. case CPU_P6600:
  1477. {
  1478. unsigned long errctl;
  1479. unsigned int l1parity_present, l2parity_present;
  1480. errctl = read_c0_ecc();
  1481. errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
  1482. /* probe L1 parity support */
  1483. write_c0_ecc(errctl | ERRCTL_PE);
  1484. back_to_back_c0_hazard();
  1485. l1parity_present = (read_c0_ecc() & ERRCTL_PE);
  1486. /* probe L2 parity support */
  1487. write_c0_ecc(errctl|ERRCTL_L2P);
  1488. back_to_back_c0_hazard();
  1489. l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
  1490. if (l1parity_present && l2parity_present) {
  1491. if (l1parity)
  1492. errctl |= ERRCTL_PE;
  1493. if (l1parity ^ l2parity)
  1494. errctl |= ERRCTL_L2P;
  1495. } else if (l1parity_present) {
  1496. if (l1parity)
  1497. errctl |= ERRCTL_PE;
  1498. } else if (l2parity_present) {
  1499. if (l2parity)
  1500. errctl |= ERRCTL_L2P;
  1501. } else {
  1502. /* No parity available */
  1503. }
  1504. printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
  1505. write_c0_ecc(errctl);
  1506. back_to_back_c0_hazard();
  1507. errctl = read_c0_ecc();
  1508. printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
  1509. if (l1parity_present)
  1510. printk(KERN_INFO "Cache parity protection %sabled\n",
  1511. (errctl & ERRCTL_PE) ? "en" : "dis");
  1512. if (l2parity_present) {
  1513. if (l1parity_present && l1parity)
  1514. errctl ^= ERRCTL_L2P;
  1515. printk(KERN_INFO "L2 cache parity protection %sabled\n",
  1516. (errctl & ERRCTL_L2P) ? "en" : "dis");
  1517. }
  1518. }
  1519. break;
  1520. case CPU_5KC:
  1521. case CPU_5KE:
  1522. case CPU_LOONGSON1:
  1523. write_c0_ecc(0x80000000);
  1524. back_to_back_c0_hazard();
  1525. /* Set the PE bit (bit 31) in the c0_errctl register. */
  1526. printk(KERN_INFO "Cache parity protection %sabled\n",
  1527. (read_c0_ecc() & 0x80000000) ? "en" : "dis");
  1528. break;
  1529. case CPU_20KC:
  1530. case CPU_25KF:
  1531. /* Clear the DE bit (bit 16) in the c0_status register. */
  1532. printk(KERN_INFO "Enable cache parity protection for "
  1533. "MIPS 20KC/25KF CPUs.\n");
  1534. clear_c0_status(ST0_DE);
  1535. break;
  1536. default:
  1537. break;
  1538. }
  1539. }
  1540. asmlinkage void cache_parity_error(void)
  1541. {
  1542. const int field = 2 * sizeof(unsigned long);
  1543. unsigned int reg_val;
  1544. /* For the moment, report the problem and hang. */
  1545. printk("Cache error exception:\n");
  1546. printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
  1547. reg_val = read_c0_cacheerr();
  1548. printk("c0_cacheerr == %08x\n", reg_val);
  1549. printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
  1550. reg_val & (1<<30) ? "secondary" : "primary",
  1551. reg_val & (1<<31) ? "data" : "insn");
  1552. if ((cpu_has_mips_r2_r6) &&
  1553. ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS)) {
  1554. pr_err("Error bits: %s%s%s%s%s%s%s%s\n",
  1555. reg_val & (1<<29) ? "ED " : "",
  1556. reg_val & (1<<28) ? "ET " : "",
  1557. reg_val & (1<<27) ? "ES " : "",
  1558. reg_val & (1<<26) ? "EE " : "",
  1559. reg_val & (1<<25) ? "EB " : "",
  1560. reg_val & (1<<24) ? "EI " : "",
  1561. reg_val & (1<<23) ? "E1 " : "",
  1562. reg_val & (1<<22) ? "E0 " : "");
  1563. } else {
  1564. pr_err("Error bits: %s%s%s%s%s%s%s\n",
  1565. reg_val & (1<<29) ? "ED " : "",
  1566. reg_val & (1<<28) ? "ET " : "",
  1567. reg_val & (1<<26) ? "EE " : "",
  1568. reg_val & (1<<25) ? "EB " : "",
  1569. reg_val & (1<<24) ? "EI " : "",
  1570. reg_val & (1<<23) ? "E1 " : "",
  1571. reg_val & (1<<22) ? "E0 " : "");
  1572. }
  1573. printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
  1574. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  1575. if (reg_val & (1<<22))
  1576. printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
  1577. if (reg_val & (1<<23))
  1578. printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
  1579. #endif
  1580. panic("Can't handle the cache error!");
  1581. }
  1582. asmlinkage void do_ftlb(void)
  1583. {
  1584. const int field = 2 * sizeof(unsigned long);
  1585. unsigned int reg_val;
  1586. /* For the moment, report the problem and hang. */
  1587. if ((cpu_has_mips_r2_r6) &&
  1588. (((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS) ||
  1589. ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_LOONGSON))) {
  1590. pr_err("FTLB error exception, cp0_ecc=0x%08x:\n",
  1591. read_c0_ecc());
  1592. pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
  1593. reg_val = read_c0_cacheerr();
  1594. pr_err("c0_cacheerr == %08x\n", reg_val);
  1595. if ((reg_val & 0xc0000000) == 0xc0000000) {
  1596. pr_err("Decoded c0_cacheerr: FTLB parity error\n");
  1597. } else {
  1598. pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
  1599. reg_val & (1<<30) ? "secondary" : "primary",
  1600. reg_val & (1<<31) ? "data" : "insn");
  1601. }
  1602. } else {
  1603. pr_err("FTLB error exception\n");
  1604. }
  1605. /* Just print the cacheerr bits for now */
  1606. cache_parity_error();
  1607. }
  1608. /*
  1609. * SDBBP EJTAG debug exception handler.
  1610. * We skip the instruction and return to the next instruction.
  1611. */
  1612. void ejtag_exception_handler(struct pt_regs *regs)
  1613. {
  1614. const int field = 2 * sizeof(unsigned long);
  1615. unsigned long depc, old_epc, old_ra;
  1616. unsigned int debug;
  1617. printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
  1618. depc = read_c0_depc();
  1619. debug = read_c0_debug();
  1620. printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
  1621. if (debug & 0x80000000) {
  1622. /*
  1623. * In branch delay slot.
  1624. * We cheat a little bit here and use EPC to calculate the
  1625. * debug return address (DEPC). EPC is restored after the
  1626. * calculation.
  1627. */
  1628. old_epc = regs->cp0_epc;
  1629. old_ra = regs->regs[31];
  1630. regs->cp0_epc = depc;
  1631. compute_return_epc(regs);
  1632. depc = regs->cp0_epc;
  1633. regs->cp0_epc = old_epc;
  1634. regs->regs[31] = old_ra;
  1635. } else
  1636. depc += 4;
  1637. write_c0_depc(depc);
  1638. #if 0
  1639. printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
  1640. write_c0_debug(debug | 0x100);
  1641. #endif
  1642. }
  1643. /*
  1644. * NMI exception handler.
  1645. * No lock; only written during early bootup by CPU 0.
  1646. */
  1647. static RAW_NOTIFIER_HEAD(nmi_chain);
  1648. int register_nmi_notifier(struct notifier_block *nb)
  1649. {
  1650. return raw_notifier_chain_register(&nmi_chain, nb);
  1651. }
  1652. void __noreturn nmi_exception_handler(struct pt_regs *regs)
  1653. {
  1654. char str[100];
  1655. nmi_enter();
  1656. raw_notifier_call_chain(&nmi_chain, 0, regs);
  1657. bust_spinlocks(1);
  1658. snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n",
  1659. smp_processor_id(), regs->cp0_epc);
  1660. regs->cp0_epc = read_c0_errorepc();
  1661. die(str, regs);
  1662. nmi_exit();
  1663. }
  1664. #define VECTORSPACING 0x100 /* for EI/VI mode */
  1665. unsigned long ebase;
  1666. EXPORT_SYMBOL_GPL(ebase);
  1667. unsigned long exception_handlers[32];
  1668. unsigned long vi_handlers[64];
  1669. void __init *set_except_vector(int n, void *addr)
  1670. {
  1671. unsigned long handler = (unsigned long) addr;
  1672. unsigned long old_handler;
  1673. #ifdef CONFIG_CPU_MICROMIPS
  1674. /*
  1675. * Only the TLB handlers are cache aligned with an even
  1676. * address. All other handlers are on an odd address and
  1677. * require no modification. Otherwise, MIPS32 mode will
  1678. * be entered when handling any TLB exceptions. That
  1679. * would be bad...since we must stay in microMIPS mode.
  1680. */
  1681. if (!(handler & 0x1))
  1682. handler |= 1;
  1683. #endif
  1684. old_handler = xchg(&exception_handlers[n], handler);
  1685. if (n == 0 && cpu_has_divec) {
  1686. #ifdef CONFIG_CPU_MICROMIPS
  1687. unsigned long jump_mask = ~((1 << 27) - 1);
  1688. #else
  1689. unsigned long jump_mask = ~((1 << 28) - 1);
  1690. #endif
  1691. u32 *buf = (u32 *)(ebase + 0x200);
  1692. unsigned int k0 = 26;
  1693. if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
  1694. uasm_i_j(&buf, handler & ~jump_mask);
  1695. uasm_i_nop(&buf);
  1696. } else {
  1697. UASM_i_LA(&buf, k0, handler);
  1698. uasm_i_jr(&buf, k0);
  1699. uasm_i_nop(&buf);
  1700. }
  1701. local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
  1702. }
  1703. return (void *)old_handler;
  1704. }
  1705. static void do_default_vi(void)
  1706. {
  1707. show_regs(get_irq_regs());
  1708. panic("Caught unexpected vectored interrupt.");
  1709. }
  1710. static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
  1711. {
  1712. unsigned long handler;
  1713. unsigned long old_handler = vi_handlers[n];
  1714. int srssets = current_cpu_data.srsets;
  1715. u16 *h;
  1716. unsigned char *b;
  1717. BUG_ON(!cpu_has_veic && !cpu_has_vint);
  1718. if (addr == NULL) {
  1719. handler = (unsigned long) do_default_vi;
  1720. srs = 0;
  1721. } else
  1722. handler = (unsigned long) addr;
  1723. vi_handlers[n] = handler;
  1724. b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
  1725. if (srs >= srssets)
  1726. panic("Shadow register set %d not supported", srs);
  1727. if (cpu_has_veic) {
  1728. if (board_bind_eic_interrupt)
  1729. board_bind_eic_interrupt(n, srs);
  1730. } else if (cpu_has_vint) {
  1731. /* SRSMap is only defined if shadow sets are implemented */
  1732. if (srssets > 1)
  1733. change_c0_srsmap(0xf << n*4, srs << n*4);
  1734. }
  1735. if (srs == 0) {
  1736. /*
  1737. * If no shadow set is selected then use the default handler
  1738. * that does normal register saving and standard interrupt exit
  1739. */
  1740. extern char except_vec_vi, except_vec_vi_lui;
  1741. extern char except_vec_vi_ori, except_vec_vi_end;
  1742. extern char rollback_except_vec_vi;
  1743. char *vec_start = using_rollback_handler() ?
  1744. &rollback_except_vec_vi : &except_vec_vi;
  1745. #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
  1746. const int lui_offset = &except_vec_vi_lui - vec_start + 2;
  1747. const int ori_offset = &except_vec_vi_ori - vec_start + 2;
  1748. #else
  1749. const int lui_offset = &except_vec_vi_lui - vec_start;
  1750. const int ori_offset = &except_vec_vi_ori - vec_start;
  1751. #endif
  1752. const int handler_len = &except_vec_vi_end - vec_start;
  1753. if (handler_len > VECTORSPACING) {
  1754. /*
  1755. * Sigh... panicing won't help as the console
  1756. * is probably not configured :(
  1757. */
  1758. panic("VECTORSPACING too small");
  1759. }
  1760. set_handler(((unsigned long)b - ebase), vec_start,
  1761. #ifdef CONFIG_CPU_MICROMIPS
  1762. (handler_len - 1));
  1763. #else
  1764. handler_len);
  1765. #endif
  1766. h = (u16 *)(b + lui_offset);
  1767. *h = (handler >> 16) & 0xffff;
  1768. h = (u16 *)(b + ori_offset);
  1769. *h = (handler & 0xffff);
  1770. local_flush_icache_range((unsigned long)b,
  1771. (unsigned long)(b+handler_len));
  1772. }
  1773. else {
  1774. /*
  1775. * In other cases jump directly to the interrupt handler. It
  1776. * is the handler's responsibility to save registers if required
  1777. * (eg hi/lo) and return from the exception using "eret".
  1778. */
  1779. u32 insn;
  1780. h = (u16 *)b;
  1781. /* j handler */
  1782. #ifdef CONFIG_CPU_MICROMIPS
  1783. insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
  1784. #else
  1785. insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
  1786. #endif
  1787. h[0] = (insn >> 16) & 0xffff;
  1788. h[1] = insn & 0xffff;
  1789. h[2] = 0;
  1790. h[3] = 0;
  1791. local_flush_icache_range((unsigned long)b,
  1792. (unsigned long)(b+8));
  1793. }
  1794. return (void *)old_handler;
  1795. }
  1796. void *set_vi_handler(int n, vi_handler_t addr)
  1797. {
  1798. return set_vi_srs_handler(n, addr, 0);
  1799. }
  1800. extern void tlb_init(void);
  1801. /*
  1802. * Timer interrupt
  1803. */
  1804. int cp0_compare_irq;
  1805. EXPORT_SYMBOL_GPL(cp0_compare_irq);
  1806. int cp0_compare_irq_shift;
  1807. /*
  1808. * Performance counter IRQ or -1 if shared with timer
  1809. */
  1810. int cp0_perfcount_irq;
  1811. EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
  1812. /*
  1813. * Fast debug channel IRQ or -1 if not present
  1814. */
  1815. int cp0_fdc_irq;
  1816. EXPORT_SYMBOL_GPL(cp0_fdc_irq);
  1817. static int noulri;
  1818. static int __init ulri_disable(char *s)
  1819. {
  1820. pr_info("Disabling ulri\n");
  1821. noulri = 1;
  1822. return 1;
  1823. }
  1824. __setup("noulri", ulri_disable);
  1825. /* configure STATUS register */
  1826. static void configure_status(void)
  1827. {
  1828. /*
  1829. * Disable coprocessors and select 32-bit or 64-bit addressing
  1830. * and the 16/32 or 32/32 FPR register model. Reset the BEV
  1831. * flag that some firmware may have left set and the TS bit (for
  1832. * IP27). Set XX for ISA IV code to work.
  1833. */
  1834. unsigned int status_set = ST0_CU0;
  1835. #ifdef CONFIG_64BIT
  1836. status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
  1837. #endif
  1838. if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
  1839. status_set |= ST0_XX;
  1840. if (cpu_has_dsp)
  1841. status_set |= ST0_MX;
  1842. change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
  1843. status_set);
  1844. }
  1845. unsigned int hwrena;
  1846. EXPORT_SYMBOL_GPL(hwrena);
  1847. /* configure HWRENA register */
  1848. static void configure_hwrena(void)
  1849. {
  1850. hwrena = cpu_hwrena_impl_bits;
  1851. if (cpu_has_mips_r2_r6)
  1852. hwrena |= MIPS_HWRENA_CPUNUM |
  1853. MIPS_HWRENA_SYNCISTEP |
  1854. MIPS_HWRENA_CC |
  1855. MIPS_HWRENA_CCRES;
  1856. if (!noulri && cpu_has_userlocal)
  1857. hwrena |= MIPS_HWRENA_ULR;
  1858. if (hwrena)
  1859. write_c0_hwrena(hwrena);
  1860. }
  1861. static void configure_exception_vector(void)
  1862. {
  1863. if (cpu_has_veic || cpu_has_vint) {
  1864. unsigned long sr = set_c0_status(ST0_BEV);
  1865. /* If available, use WG to set top bits of EBASE */
  1866. if (cpu_has_ebase_wg) {
  1867. #ifdef CONFIG_64BIT
  1868. write_c0_ebase_64(ebase | MIPS_EBASE_WG);
  1869. #else
  1870. write_c0_ebase(ebase | MIPS_EBASE_WG);
  1871. #endif
  1872. }
  1873. write_c0_ebase(ebase);
  1874. write_c0_status(sr);
  1875. /* Setting vector spacing enables EI/VI mode */
  1876. change_c0_intctl(0x3e0, VECTORSPACING);
  1877. }
  1878. if (cpu_has_divec) {
  1879. if (cpu_has_mipsmt) {
  1880. unsigned int vpflags = dvpe();
  1881. set_c0_cause(CAUSEF_IV);
  1882. evpe(vpflags);
  1883. } else
  1884. set_c0_cause(CAUSEF_IV);
  1885. }
  1886. }
  1887. void per_cpu_trap_init(bool is_boot_cpu)
  1888. {
  1889. unsigned int cpu = smp_processor_id();
  1890. configure_status();
  1891. configure_hwrena();
  1892. configure_exception_vector();
  1893. /*
  1894. * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
  1895. *
  1896. * o read IntCtl.IPTI to determine the timer interrupt
  1897. * o read IntCtl.IPPCI to determine the performance counter interrupt
  1898. * o read IntCtl.IPFDC to determine the fast debug channel interrupt
  1899. */
  1900. if (cpu_has_mips_r2_r6) {
  1901. /*
  1902. * We shouldn't trust a secondary core has a sane EBASE register
  1903. * so use the one calculated by the boot CPU.
  1904. */
  1905. if (!is_boot_cpu) {
  1906. /* If available, use WG to set top bits of EBASE */
  1907. if (cpu_has_ebase_wg) {
  1908. #ifdef CONFIG_64BIT
  1909. write_c0_ebase_64(ebase | MIPS_EBASE_WG);
  1910. #else
  1911. write_c0_ebase(ebase | MIPS_EBASE_WG);
  1912. #endif
  1913. }
  1914. write_c0_ebase(ebase);
  1915. }
  1916. cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
  1917. cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
  1918. cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
  1919. cp0_fdc_irq = (read_c0_intctl() >> INTCTLB_IPFDC) & 7;
  1920. if (!cp0_fdc_irq)
  1921. cp0_fdc_irq = -1;
  1922. } else {
  1923. cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
  1924. cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
  1925. cp0_perfcount_irq = -1;
  1926. cp0_fdc_irq = -1;
  1927. }
  1928. if (!cpu_data[cpu].asid_cache)
  1929. cpu_data[cpu].asid_cache = asid_first_version(cpu);
  1930. atomic_inc(&init_mm.mm_count);
  1931. current->active_mm = &init_mm;
  1932. BUG_ON(current->mm);
  1933. enter_lazy_tlb(&init_mm, current);
  1934. /* Boot CPU's cache setup in setup_arch(). */
  1935. if (!is_boot_cpu)
  1936. cpu_cache_init();
  1937. tlb_init();
  1938. TLBMISS_HANDLER_SETUP();
  1939. }
  1940. /* Install CPU exception handler */
  1941. void set_handler(unsigned long offset, void *addr, unsigned long size)
  1942. {
  1943. #ifdef CONFIG_CPU_MICROMIPS
  1944. memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
  1945. #else
  1946. memcpy((void *)(ebase + offset), addr, size);
  1947. #endif
  1948. local_flush_icache_range(ebase + offset, ebase + offset + size);
  1949. }
  1950. static char panic_null_cerr[] =
  1951. "Trying to set NULL cache error exception handler";
  1952. /*
  1953. * Install uncached CPU exception handler.
  1954. * This is suitable only for the cache error exception which is the only
  1955. * exception handler that is being run uncached.
  1956. */
  1957. void set_uncached_handler(unsigned long offset, void *addr,
  1958. unsigned long size)
  1959. {
  1960. unsigned long uncached_ebase = CKSEG1ADDR(ebase);
  1961. if (!addr)
  1962. panic(panic_null_cerr);
  1963. memcpy((void *)(uncached_ebase + offset), addr, size);
  1964. }
  1965. static int __initdata rdhwr_noopt;
  1966. static int __init set_rdhwr_noopt(char *str)
  1967. {
  1968. rdhwr_noopt = 1;
  1969. return 1;
  1970. }
  1971. __setup("rdhwr_noopt", set_rdhwr_noopt);
  1972. void __init trap_init(void)
  1973. {
  1974. extern char except_vec3_generic;
  1975. extern char except_vec4;
  1976. extern char except_vec3_r4000;
  1977. unsigned long i;
  1978. check_wait();
  1979. if (cpu_has_veic || cpu_has_vint) {
  1980. unsigned long size = 0x200 + VECTORSPACING*64;
  1981. phys_addr_t ebase_pa;
  1982. ebase = (unsigned long)
  1983. __alloc_bootmem(size, 1 << fls(size), 0);
  1984. /*
  1985. * Try to ensure ebase resides in KSeg0 if possible.
  1986. *
  1987. * It shouldn't generally be in XKPhys on MIPS64 to avoid
  1988. * hitting a poorly defined exception base for Cache Errors.
  1989. * The allocation is likely to be in the low 512MB of physical,
  1990. * in which case we should be able to convert to KSeg0.
  1991. *
  1992. * EVA is special though as it allows segments to be rearranged
  1993. * and to become uncached during cache error handling.
  1994. */
  1995. ebase_pa = __pa(ebase);
  1996. if (!IS_ENABLED(CONFIG_EVA) && !WARN_ON(ebase_pa >= 0x20000000))
  1997. ebase = CKSEG0ADDR(ebase_pa);
  1998. } else {
  1999. ebase = CAC_BASE;
  2000. if (cpu_has_mips_r2_r6) {
  2001. if (cpu_has_ebase_wg) {
  2002. #ifdef CONFIG_64BIT
  2003. ebase = (read_c0_ebase_64() & ~0xfff);
  2004. #else
  2005. ebase = (read_c0_ebase() & ~0xfff);
  2006. #endif
  2007. } else {
  2008. ebase += (read_c0_ebase() & 0x3ffff000);
  2009. }
  2010. }
  2011. }
  2012. if (cpu_has_mmips) {
  2013. unsigned int config3 = read_c0_config3();
  2014. if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
  2015. write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
  2016. else
  2017. write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
  2018. }
  2019. if (board_ebase_setup)
  2020. board_ebase_setup();
  2021. per_cpu_trap_init(true);
  2022. /*
  2023. * Copy the generic exception handlers to their final destination.
  2024. * This will be overridden later as suitable for a particular
  2025. * configuration.
  2026. */
  2027. set_handler(0x180, &except_vec3_generic, 0x80);
  2028. /*
  2029. * Setup default vectors
  2030. */
  2031. for (i = 0; i <= 31; i++)
  2032. set_except_vector(i, handle_reserved);
  2033. /*
  2034. * Copy the EJTAG debug exception vector handler code to it's final
  2035. * destination.
  2036. */
  2037. if (cpu_has_ejtag && board_ejtag_handler_setup)
  2038. board_ejtag_handler_setup();
  2039. /*
  2040. * Only some CPUs have the watch exceptions.
  2041. */
  2042. if (cpu_has_watch)
  2043. set_except_vector(EXCCODE_WATCH, handle_watch);
  2044. /*
  2045. * Initialise interrupt handlers
  2046. */
  2047. if (cpu_has_veic || cpu_has_vint) {
  2048. int nvec = cpu_has_veic ? 64 : 8;
  2049. for (i = 0; i < nvec; i++)
  2050. set_vi_handler(i, NULL);
  2051. }
  2052. else if (cpu_has_divec)
  2053. set_handler(0x200, &except_vec4, 0x8);
  2054. /*
  2055. * Some CPUs can enable/disable for cache parity detection, but does
  2056. * it different ways.
  2057. */
  2058. parity_protection_init();
  2059. /*
  2060. * The Data Bus Errors / Instruction Bus Errors are signaled
  2061. * by external hardware. Therefore these two exceptions
  2062. * may have board specific handlers.
  2063. */
  2064. if (board_be_init)
  2065. board_be_init();
  2066. set_except_vector(EXCCODE_INT, using_rollback_handler() ?
  2067. rollback_handle_int : handle_int);
  2068. set_except_vector(EXCCODE_MOD, handle_tlbm);
  2069. set_except_vector(EXCCODE_TLBL, handle_tlbl);
  2070. set_except_vector(EXCCODE_TLBS, handle_tlbs);
  2071. set_except_vector(EXCCODE_ADEL, handle_adel);
  2072. set_except_vector(EXCCODE_ADES, handle_ades);
  2073. set_except_vector(EXCCODE_IBE, handle_ibe);
  2074. set_except_vector(EXCCODE_DBE, handle_dbe);
  2075. set_except_vector(EXCCODE_SYS, handle_sys);
  2076. set_except_vector(EXCCODE_BP, handle_bp);
  2077. if (rdhwr_noopt)
  2078. set_except_vector(EXCCODE_RI, handle_ri);
  2079. else {
  2080. if (cpu_has_vtag_icache)
  2081. set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
  2082. else if (current_cpu_type() == CPU_LOONGSON3)
  2083. set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
  2084. else
  2085. set_except_vector(EXCCODE_RI, handle_ri_rdhwr);
  2086. }
  2087. set_except_vector(EXCCODE_CPU, handle_cpu);
  2088. set_except_vector(EXCCODE_OV, handle_ov);
  2089. set_except_vector(EXCCODE_TR, handle_tr);
  2090. set_except_vector(EXCCODE_MSAFPE, handle_msa_fpe);
  2091. if (current_cpu_type() == CPU_R6000 ||
  2092. current_cpu_type() == CPU_R6000A) {
  2093. /*
  2094. * The R6000 is the only R-series CPU that features a machine
  2095. * check exception (similar to the R4000 cache error) and
  2096. * unaligned ldc1/sdc1 exception. The handlers have not been
  2097. * written yet. Well, anyway there is no R6000 machine on the
  2098. * current list of targets for Linux/MIPS.
  2099. * (Duh, crap, there is someone with a triple R6k machine)
  2100. */
  2101. //set_except_vector(14, handle_mc);
  2102. //set_except_vector(15, handle_ndc);
  2103. }
  2104. if (board_nmi_handler_setup)
  2105. board_nmi_handler_setup();
  2106. if (cpu_has_fpu && !cpu_has_nofpuex)
  2107. set_except_vector(EXCCODE_FPE, handle_fpe);
  2108. set_except_vector(MIPS_EXCCODE_TLBPAR, handle_ftlb);
  2109. if (cpu_has_rixiex) {
  2110. set_except_vector(EXCCODE_TLBRI, tlb_do_page_fault_0);
  2111. set_except_vector(EXCCODE_TLBXI, tlb_do_page_fault_0);
  2112. }
  2113. set_except_vector(EXCCODE_MSADIS, handle_msa);
  2114. set_except_vector(EXCCODE_MDMX, handle_mdmx);
  2115. if (cpu_has_mcheck)
  2116. set_except_vector(EXCCODE_MCHECK, handle_mcheck);
  2117. if (cpu_has_mipsmt)
  2118. set_except_vector(EXCCODE_THREAD, handle_mt);
  2119. set_except_vector(EXCCODE_DSPDIS, handle_dsp);
  2120. if (board_cache_error_setup)
  2121. board_cache_error_setup();
  2122. if (cpu_has_vce)
  2123. /* Special exception: R4[04]00 uses also the divec space. */
  2124. set_handler(0x180, &except_vec3_r4000, 0x100);
  2125. else if (cpu_has_4kex)
  2126. set_handler(0x180, &except_vec3_generic, 0x80);
  2127. else
  2128. set_handler(0x080, &except_vec3_generic, 0x80);
  2129. local_flush_icache_range(ebase, ebase + 0x400);
  2130. sort_extable(__start___dbe_table, __stop___dbe_table);
  2131. cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
  2132. }
  2133. static int trap_pm_notifier(struct notifier_block *self, unsigned long cmd,
  2134. void *v)
  2135. {
  2136. switch (cmd) {
  2137. case CPU_PM_ENTER_FAILED:
  2138. case CPU_PM_EXIT:
  2139. configure_status();
  2140. configure_hwrena();
  2141. configure_exception_vector();
  2142. /* Restore register with CPU number for TLB handlers */
  2143. TLBMISS_HANDLER_RESTORE();
  2144. break;
  2145. }
  2146. return NOTIFY_OK;
  2147. }
  2148. static struct notifier_block trap_pm_notifier_block = {
  2149. .notifier_call = trap_pm_notifier,
  2150. };
  2151. static int __init trap_pm_init(void)
  2152. {
  2153. return cpu_pm_register_notifier(&trap_pm_notifier_block);
  2154. }
  2155. arch_initcall(trap_pm_init);