123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517 |
- #include <linux/bitops.h>
- #include <linux/bug.h>
- #include <linux/compiler.h>
- #include <linux/context_tracking.h>
- #include <linux/cpu_pm.h>
- #include <linux/kexec.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/extable.h>
- #include <linux/mm.h>
- #include <linux/sched.h>
- #include <linux/smp.h>
- #include <linux/spinlock.h>
- #include <linux/kallsyms.h>
- #include <linux/bootmem.h>
- #include <linux/interrupt.h>
- #include <linux/ptrace.h>
- #include <linux/kgdb.h>
- #include <linux/kdebug.h>
- #include <linux/kprobes.h>
- #include <linux/notifier.h>
- #include <linux/kdb.h>
- #include <linux/irq.h>
- #include <linux/perf_event.h>
- #include <asm/addrspace.h>
- #include <asm/bootinfo.h>
- #include <asm/branch.h>
- #include <asm/break.h>
- #include <asm/cop2.h>
- #include <asm/cpu.h>
- #include <asm/cpu-type.h>
- #include <asm/dsp.h>
- #include <asm/fpu.h>
- #include <asm/fpu_emulator.h>
- #include <asm/idle.h>
- #include <asm/mips-cm.h>
- #include <asm/mips-r2-to-r6-emul.h>
- #include <asm/mips-cm.h>
- #include <asm/mipsregs.h>
- #include <asm/mipsmtregs.h>
- #include <asm/module.h>
- #include <asm/msa.h>
- #include <asm/pgtable.h>
- #include <asm/ptrace.h>
- #include <asm/sections.h>
- #include <asm/siginfo.h>
- #include <asm/tlbdebug.h>
- #include <asm/traps.h>
- #include <asm/uaccess.h>
- #include <asm/watch.h>
- #include <asm/mmu_context.h>
- #include <asm/types.h>
- #include <asm/stacktrace.h>
- #include <asm/uasm.h>
- extern void check_wait(void);
- extern asmlinkage void rollback_handle_int(void);
- extern asmlinkage void handle_int(void);
- extern u32 handle_tlbl[];
- extern u32 handle_tlbs[];
- extern u32 handle_tlbm[];
- extern asmlinkage void handle_adel(void);
- extern asmlinkage void handle_ades(void);
- extern asmlinkage void handle_ibe(void);
- extern asmlinkage void handle_dbe(void);
- extern asmlinkage void handle_sys(void);
- extern asmlinkage void handle_bp(void);
- extern asmlinkage void handle_ri(void);
- extern asmlinkage void handle_ri_rdhwr_tlbp(void);
- extern asmlinkage void handle_ri_rdhwr(void);
- extern asmlinkage void handle_cpu(void);
- extern asmlinkage void handle_ov(void);
- extern asmlinkage void handle_tr(void);
- extern asmlinkage void handle_msa_fpe(void);
- extern asmlinkage void handle_fpe(void);
- extern asmlinkage void handle_ftlb(void);
- extern asmlinkage void handle_msa(void);
- extern asmlinkage void handle_mdmx(void);
- extern asmlinkage void handle_watch(void);
- extern asmlinkage void handle_mt(void);
- extern asmlinkage void handle_dsp(void);
- extern asmlinkage void handle_mcheck(void);
- extern asmlinkage void handle_reserved(void);
- extern void tlb_do_page_fault_0(void);
- void (*board_be_init)(void);
- int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
- void (*board_nmi_handler_setup)(void);
- void (*board_ejtag_handler_setup)(void);
- void (*board_bind_eic_interrupt)(int irq, int regset);
- void (*board_ebase_setup)(void);
- void(*board_cache_error_setup)(void);
- static void show_raw_backtrace(unsigned long reg29)
- {
- unsigned long *sp = (unsigned long *)(reg29 & ~3);
- unsigned long addr;
- printk("Call Trace:");
- #ifdef CONFIG_KALLSYMS
- printk("\n");
- #endif
- while (!kstack_end(sp)) {
- unsigned long __user *p =
- (unsigned long __user *)(unsigned long)sp++;
- if (__get_user(addr, p)) {
- printk(" (Bad stack address)");
- break;
- }
- if (__kernel_text_address(addr))
- print_ip_sym(addr);
- }
- printk("\n");
- }
- #ifdef CONFIG_KALLSYMS
- int raw_show_trace;
- static int __init set_raw_show_trace(char *str)
- {
- raw_show_trace = 1;
- return 1;
- }
- __setup("raw_show_trace", set_raw_show_trace);
- #endif
- static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
- {
- unsigned long sp = regs->regs[29];
- unsigned long ra = regs->regs[31];
- unsigned long pc = regs->cp0_epc;
- if (!task)
- task = current;
- if (raw_show_trace || user_mode(regs) || !__kernel_text_address(pc)) {
- show_raw_backtrace(sp);
- return;
- }
- printk("Call Trace:\n");
- do {
- print_ip_sym(pc);
- pc = unwind_stack(task, &sp, pc, &ra);
- } while (pc);
- pr_cont("\n");
- }
- static void show_stacktrace(struct task_struct *task,
- const struct pt_regs *regs)
- {
- const int field = 2 * sizeof(unsigned long);
- long stackdata;
- int i;
- unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
- printk("Stack :");
- i = 0;
- while ((unsigned long) sp & (PAGE_SIZE - 1)) {
- if (i && ((i % (64 / field)) == 0)) {
- pr_cont("\n");
- printk(" ");
- }
- if (i > 39) {
- pr_cont(" ...");
- break;
- }
- if (__get_user(stackdata, sp++)) {
- pr_cont(" (Bad stack address)");
- break;
- }
- pr_cont(" %0*lx", field, stackdata);
- i++;
- }
- pr_cont("\n");
- show_backtrace(task, regs);
- }
- void show_stack(struct task_struct *task, unsigned long *sp)
- {
- struct pt_regs regs;
- mm_segment_t old_fs = get_fs();
- regs.cp0_status = KSU_KERNEL;
- if (sp) {
- regs.regs[29] = (unsigned long)sp;
- regs.regs[31] = 0;
- regs.cp0_epc = 0;
- } else {
- if (task && task != current) {
- regs.regs[29] = task->thread.reg29;
- regs.regs[31] = 0;
- regs.cp0_epc = task->thread.reg31;
- #ifdef CONFIG_KGDB_KDB
- } else if (atomic_read(&kgdb_active) != -1 &&
- kdb_current_regs) {
- memcpy(®s, kdb_current_regs, sizeof(regs));
- #endif
- } else {
- prepare_frametrace(®s);
- }
- }
-
- set_fs(KERNEL_DS);
- show_stacktrace(task, ®s);
- set_fs(old_fs);
- }
- static void show_code(unsigned int __user *pc)
- {
- long i;
- unsigned short __user *pc16 = NULL;
- printk("Code:");
- if ((unsigned long)pc & 1)
- pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
- for(i = -3 ; i < 6 ; i++) {
- unsigned int insn;
- if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
- pr_cont(" (Bad address in epc)\n");
- break;
- }
- pr_cont("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
- }
- pr_cont("\n");
- }
- static void __show_regs(const struct pt_regs *regs)
- {
- const int field = 2 * sizeof(unsigned long);
- unsigned int cause = regs->cp0_cause;
- unsigned int exccode;
- int i;
- show_regs_print_info(KERN_DEFAULT);
-
- for (i = 0; i < 32; ) {
- if ((i % 4) == 0)
- printk("$%2d :", i);
- if (i == 0)
- pr_cont(" %0*lx", field, 0UL);
- else if (i == 26 || i == 27)
- pr_cont(" %*s", field, "");
- else
- pr_cont(" %0*lx", field, regs->regs[i]);
- i++;
- if ((i % 4) == 0)
- pr_cont("\n");
- }
- #ifdef CONFIG_CPU_HAS_SMARTMIPS
- printk("Acx : %0*lx\n", field, regs->acx);
- #endif
- printk("Hi : %0*lx\n", field, regs->hi);
- printk("Lo : %0*lx\n", field, regs->lo);
-
- printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
- (void *) regs->cp0_epc);
- printk("ra : %0*lx %pS\n", field, regs->regs[31],
- (void *) regs->regs[31]);
- printk("Status: %08x ", (uint32_t) regs->cp0_status);
- if (cpu_has_3kex) {
- if (regs->cp0_status & ST0_KUO)
- pr_cont("KUo ");
- if (regs->cp0_status & ST0_IEO)
- pr_cont("IEo ");
- if (regs->cp0_status & ST0_KUP)
- pr_cont("KUp ");
- if (regs->cp0_status & ST0_IEP)
- pr_cont("IEp ");
- if (regs->cp0_status & ST0_KUC)
- pr_cont("KUc ");
- if (regs->cp0_status & ST0_IEC)
- pr_cont("IEc ");
- } else if (cpu_has_4kex) {
- if (regs->cp0_status & ST0_KX)
- pr_cont("KX ");
- if (regs->cp0_status & ST0_SX)
- pr_cont("SX ");
- if (regs->cp0_status & ST0_UX)
- pr_cont("UX ");
- switch (regs->cp0_status & ST0_KSU) {
- case KSU_USER:
- pr_cont("USER ");
- break;
- case KSU_SUPERVISOR:
- pr_cont("SUPERVISOR ");
- break;
- case KSU_KERNEL:
- pr_cont("KERNEL ");
- break;
- default:
- pr_cont("BAD_MODE ");
- break;
- }
- if (regs->cp0_status & ST0_ERL)
- pr_cont("ERL ");
- if (regs->cp0_status & ST0_EXL)
- pr_cont("EXL ");
- if (regs->cp0_status & ST0_IE)
- pr_cont("IE ");
- }
- pr_cont("\n");
- exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
- printk("Cause : %08x (ExcCode %02x)\n", cause, exccode);
- if (1 <= exccode && exccode <= 5)
- printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
- printk("PrId : %08x (%s)\n", read_c0_prid(),
- cpu_name_string());
- }
- void show_regs(struct pt_regs *regs)
- {
- __show_regs((struct pt_regs *)regs);
- dump_stack();
- }
- void show_registers(struct pt_regs *regs)
- {
- const int field = 2 * sizeof(unsigned long);
- mm_segment_t old_fs = get_fs();
- __show_regs(regs);
- print_modules();
- printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
- current->comm, current->pid, current_thread_info(), current,
- field, current_thread_info()->tp_value);
- if (cpu_has_userlocal) {
- unsigned long tls;
- tls = read_c0_userlocal();
- if (tls != current_thread_info()->tp_value)
- printk("*HwTLS: %0*lx\n", field, tls);
- }
- if (!user_mode(regs))
-
- set_fs(KERNEL_DS);
- show_stacktrace(current, regs);
- show_code((unsigned int __user *) regs->cp0_epc);
- printk("\n");
- set_fs(old_fs);
- }
- static DEFINE_RAW_SPINLOCK(die_lock);
- void __noreturn die(const char *str, struct pt_regs *regs)
- {
- static int die_counter;
- int sig = SIGSEGV;
- oops_enter();
- if (notify_die(DIE_OOPS, str, regs, 0, current->thread.trap_nr,
- SIGSEGV) == NOTIFY_STOP)
- sig = 0;
- console_verbose();
- raw_spin_lock_irq(&die_lock);
- bust_spinlocks(1);
- printk("%s[#%d]:\n", str, ++die_counter);
- show_registers(regs);
- add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
- raw_spin_unlock_irq(&die_lock);
- oops_exit();
- if (in_interrupt())
- panic("Fatal exception in interrupt");
- if (panic_on_oops)
- panic("Fatal exception");
- if (regs && kexec_should_crash(current))
- crash_kexec(regs);
- do_exit(sig);
- }
- extern struct exception_table_entry __start___dbe_table[];
- extern struct exception_table_entry __stop___dbe_table[];
- __asm__(
- " .section __dbe_table, \"a\"\n"
- " .previous \n");
- static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
- {
- const struct exception_table_entry *e;
- e = search_extable(__start___dbe_table, __stop___dbe_table - 1, addr);
- if (!e)
- e = search_module_dbetables(addr);
- return e;
- }
- asmlinkage void do_be(struct pt_regs *regs)
- {
- const int field = 2 * sizeof(unsigned long);
- const struct exception_table_entry *fixup = NULL;
- int data = regs->cp0_cause & 4;
- int action = MIPS_BE_FATAL;
- enum ctx_state prev_state;
- prev_state = exception_enter();
-
- if (data && !user_mode(regs))
- fixup = search_dbe_tables(exception_epc(regs));
- if (fixup)
- action = MIPS_BE_FIXUP;
- if (board_be_handler)
- action = board_be_handler(regs, fixup != NULL);
- else
- mips_cm_error_report();
- switch (action) {
- case MIPS_BE_DISCARD:
- goto out;
- case MIPS_BE_FIXUP:
- if (fixup) {
- regs->cp0_epc = fixup->nextinsn;
- goto out;
- }
- break;
- default:
- break;
- }
-
- printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
- data ? "Data" : "Instruction",
- field, regs->cp0_epc, field, regs->regs[31]);
- if (notify_die(DIE_OOPS, "bus error", regs, 0, current->thread.trap_nr,
- SIGBUS) == NOTIFY_STOP)
- goto out;
- die_if_kernel("Oops", regs);
- force_sig(SIGBUS, current);
- out:
- exception_exit(prev_state);
- }
- #define OPCODE 0xfc000000
- #define BASE 0x03e00000
- #define RT 0x001f0000
- #define OFFSET 0x0000ffff
- #define LL 0xc0000000
- #define SC 0xe0000000
- #define SPEC0 0x00000000
- #define SPEC3 0x7c000000
- #define RD 0x0000f800
- #define FUNC 0x0000003f
- #define SYNC 0x0000000f
- #define RDHWR 0x0000003b
- #define MM_POOL32A_FUNC 0xfc00ffff
- #define MM_RDHWR 0x00006b3c
- #define MM_RS 0x001f0000
- #define MM_RT 0x03e00000
- unsigned int ll_bit;
- struct task_struct *ll_task;
- static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
- {
- unsigned long value, __user *vaddr;
- long offset;
-
-
- offset = opcode & OFFSET;
- offset <<= 16;
- offset >>= 16;
- vaddr = (unsigned long __user *)
- ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
- if ((unsigned long)vaddr & 3)
- return SIGBUS;
- if (get_user(value, vaddr))
- return SIGSEGV;
- preempt_disable();
- if (ll_task == NULL || ll_task == current) {
- ll_bit = 1;
- } else {
- ll_bit = 0;
- }
- ll_task = current;
- preempt_enable();
- regs->regs[(opcode & RT) >> 16] = value;
- return 0;
- }
- static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
- {
- unsigned long __user *vaddr;
- unsigned long reg;
- long offset;
-
-
- offset = opcode & OFFSET;
- offset <<= 16;
- offset >>= 16;
- vaddr = (unsigned long __user *)
- ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
- reg = (opcode & RT) >> 16;
- if ((unsigned long)vaddr & 3)
- return SIGBUS;
- preempt_disable();
- if (ll_bit == 0 || ll_task != current) {
- regs->regs[reg] = 0;
- preempt_enable();
- return 0;
- }
- preempt_enable();
- if (put_user(regs->regs[reg], vaddr))
- return SIGSEGV;
- regs->regs[reg] = 1;
- return 0;
- }
- static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
- {
- if ((opcode & OPCODE) == LL) {
- perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
- 1, regs, 0);
- return simulate_ll(regs, opcode);
- }
- if ((opcode & OPCODE) == SC) {
- perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
- 1, regs, 0);
- return simulate_sc(regs, opcode);
- }
- return -1;
- }
- static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
- {
- struct thread_info *ti = task_thread_info(current);
- perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
- 1, regs, 0);
- switch (rd) {
- case MIPS_HWR_CPUNUM:
- regs->regs[rt] = smp_processor_id();
- return 0;
- case MIPS_HWR_SYNCISTEP:
- regs->regs[rt] = min(current_cpu_data.dcache.linesz,
- current_cpu_data.icache.linesz);
- return 0;
- case MIPS_HWR_CC:
- regs->regs[rt] = read_c0_count();
- return 0;
- case MIPS_HWR_CCRES:
- switch (current_cpu_type()) {
- case CPU_20KC:
- case CPU_25KF:
- regs->regs[rt] = 1;
- break;
- default:
- regs->regs[rt] = 2;
- }
- return 0;
- case MIPS_HWR_ULR:
- regs->regs[rt] = ti->tp_value;
- return 0;
- default:
- return -1;
- }
- }
- static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
- {
- if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
- int rd = (opcode & RD) >> 11;
- int rt = (opcode & RT) >> 16;
- simulate_rdhwr(regs, rd, rt);
- return 0;
- }
-
- return -1;
- }
- static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned int opcode)
- {
- if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
- int rd = (opcode & MM_RS) >> 16;
- int rt = (opcode & MM_RT) >> 21;
- simulate_rdhwr(regs, rd, rt);
- return 0;
- }
-
- return -1;
- }
- static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
- {
- if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
- perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
- 1, regs, 0);
- return 0;
- }
- return -1;
- }
- asmlinkage void do_ov(struct pt_regs *regs)
- {
- enum ctx_state prev_state;
- siginfo_t info = {
- .si_signo = SIGFPE,
- .si_code = FPE_INTOVF,
- .si_addr = (void __user *)regs->cp0_epc,
- };
- prev_state = exception_enter();
- die_if_kernel("Integer overflow", regs);
- force_sig_info(SIGFPE, &info, current);
- exception_exit(prev_state);
- }
- void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
- struct task_struct *tsk)
- {
- struct siginfo si = { .si_addr = fault_addr, .si_signo = SIGFPE };
- if (fcr31 & FPU_CSR_INV_X)
- si.si_code = FPE_FLTINV;
- else if (fcr31 & FPU_CSR_DIV_X)
- si.si_code = FPE_FLTDIV;
- else if (fcr31 & FPU_CSR_OVF_X)
- si.si_code = FPE_FLTOVF;
- else if (fcr31 & FPU_CSR_UDF_X)
- si.si_code = FPE_FLTUND;
- else if (fcr31 & FPU_CSR_INE_X)
- si.si_code = FPE_FLTRES;
- else
- si.si_code = __SI_FAULT;
- force_sig_info(SIGFPE, &si, tsk);
- }
- int process_fpemu_return(int sig, void __user *fault_addr, unsigned long fcr31)
- {
- struct siginfo si = { 0 };
- struct vm_area_struct *vma;
- switch (sig) {
- case 0:
- return 0;
- case SIGFPE:
- force_fcr31_sig(fcr31, fault_addr, current);
- return 1;
- case SIGBUS:
- si.si_addr = fault_addr;
- si.si_signo = sig;
- si.si_code = BUS_ADRERR;
- force_sig_info(sig, &si, current);
- return 1;
- case SIGSEGV:
- si.si_addr = fault_addr;
- si.si_signo = sig;
- down_read(¤t->mm->mmap_sem);
- vma = find_vma(current->mm, (unsigned long)fault_addr);
- if (vma && (vma->vm_start <= (unsigned long)fault_addr))
- si.si_code = SEGV_ACCERR;
- else
- si.si_code = SEGV_MAPERR;
- up_read(¤t->mm->mmap_sem);
- force_sig_info(sig, &si, current);
- return 1;
- default:
- force_sig(sig, current);
- return 1;
- }
- }
- static int simulate_fp(struct pt_regs *regs, unsigned int opcode,
- unsigned long old_epc, unsigned long old_ra)
- {
- union mips_instruction inst = { .word = opcode };
- void __user *fault_addr;
- unsigned long fcr31;
- int sig;
-
- switch (inst.i_format.opcode) {
- case cop1_op:
- case cop1x_op:
- case lwc1_op:
- case ldc1_op:
- case swc1_op:
- case sdc1_op:
- break;
- default:
- return -1;
- }
-
- regs->cp0_epc = old_epc;
- regs->regs[31] = old_ra;
-
- lose_fpu(1);
-
- sig = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 1,
- &fault_addr);
-
- fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
- current->thread.fpu.fcr31 &= ~fcr31;
-
- own_fpu(1);
-
- process_fpemu_return(sig, fault_addr, fcr31);
- return 0;
- }
- asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
- {
- enum ctx_state prev_state;
- void __user *fault_addr;
- int sig;
- prev_state = exception_enter();
- if (notify_die(DIE_FP, "FP exception", regs, 0, current->thread.trap_nr,
- SIGFPE) == NOTIFY_STOP)
- goto out;
-
- write_32bit_cp1_register(CP1_STATUS, fcr31 & ~mask_fcr31_x(fcr31));
- local_irq_enable();
- die_if_kernel("FP exception in kernel code", regs);
- if (fcr31 & FPU_CSR_UNI_X) {
-
-
- lose_fpu(1);
-
- sig = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 1,
- &fault_addr);
-
- fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
- current->thread.fpu.fcr31 &= ~fcr31;
-
- own_fpu(1);
- } else {
- sig = SIGFPE;
- fault_addr = (void __user *) regs->cp0_epc;
- }
-
- process_fpemu_return(sig, fault_addr, fcr31);
- out:
- exception_exit(prev_state);
- }
- void do_trap_or_bp(struct pt_regs *regs, unsigned int code, int si_code,
- const char *str)
- {
- siginfo_t info = { 0 };
- char b[40];
- #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
- if (kgdb_ll_trap(DIE_TRAP, str, regs, code, current->thread.trap_nr,
- SIGTRAP) == NOTIFY_STOP)
- return;
- #endif
- if (notify_die(DIE_TRAP, str, regs, code, current->thread.trap_nr,
- SIGTRAP) == NOTIFY_STOP)
- return;
-
- switch (code) {
- case BRK_OVERFLOW:
- case BRK_DIVZERO:
- scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
- die_if_kernel(b, regs);
- if (code == BRK_DIVZERO)
- info.si_code = FPE_INTDIV;
- else
- info.si_code = FPE_INTOVF;
- info.si_signo = SIGFPE;
- info.si_addr = (void __user *) regs->cp0_epc;
- force_sig_info(SIGFPE, &info, current);
- break;
- case BRK_BUG:
- die_if_kernel("Kernel bug detected", regs);
- force_sig(SIGTRAP, current);
- break;
- case BRK_MEMU:
-
- if (do_dsemulret(regs))
- return;
- die_if_kernel("Math emu break/trap", regs);
- force_sig(SIGTRAP, current);
- break;
- default:
- scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
- die_if_kernel(b, regs);
- if (si_code) {
- info.si_signo = SIGTRAP;
- info.si_code = si_code;
- force_sig_info(SIGTRAP, &info, current);
- } else {
- force_sig(SIGTRAP, current);
- }
- }
- }
- asmlinkage void do_bp(struct pt_regs *regs)
- {
- unsigned long epc = msk_isa16_mode(exception_epc(regs));
- unsigned int opcode, bcode;
- enum ctx_state prev_state;
- mm_segment_t seg;
- seg = get_fs();
- if (!user_mode(regs))
- set_fs(KERNEL_DS);
- prev_state = exception_enter();
- current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
- if (get_isa16_mode(regs->cp0_epc)) {
- u16 instr[2];
- if (__get_user(instr[0], (u16 __user *)epc))
- goto out_sigsegv;
- if (!cpu_has_mmips) {
-
- bcode = (instr[0] >> 5) & 0x3f;
- } else if (mm_insn_16bit(instr[0])) {
-
- bcode = instr[0] & 0xf;
- } else {
-
- if (__get_user(instr[1], (u16 __user *)(epc + 2)))
- goto out_sigsegv;
- opcode = (instr[0] << 16) | instr[1];
- bcode = (opcode >> 6) & ((1 << 20) - 1);
- }
- } else {
- if (__get_user(opcode, (unsigned int __user *)epc))
- goto out_sigsegv;
- bcode = (opcode >> 6) & ((1 << 20) - 1);
- }
-
- if (bcode >= (1 << 10))
- bcode = ((bcode & ((1 << 10) - 1)) << 10) | (bcode >> 10);
-
- switch (bcode) {
- case BRK_UPROBE:
- if (notify_die(DIE_UPROBE, "uprobe", regs, bcode,
- current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
- goto out;
- else
- break;
- case BRK_UPROBE_XOL:
- if (notify_die(DIE_UPROBE_XOL, "uprobe_xol", regs, bcode,
- current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
- goto out;
- else
- break;
- case BRK_KPROBE_BP:
- if (notify_die(DIE_BREAK, "debug", regs, bcode,
- current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
- goto out;
- else
- break;
- case BRK_KPROBE_SSTEPBP:
- if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode,
- current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
- goto out;
- else
- break;
- default:
- break;
- }
- do_trap_or_bp(regs, bcode, TRAP_BRKPT, "Break");
- out:
- set_fs(seg);
- exception_exit(prev_state);
- return;
- out_sigsegv:
- force_sig(SIGSEGV, current);
- goto out;
- }
- asmlinkage void do_tr(struct pt_regs *regs)
- {
- u32 opcode, tcode = 0;
- enum ctx_state prev_state;
- u16 instr[2];
- mm_segment_t seg;
- unsigned long epc = msk_isa16_mode(exception_epc(regs));
- seg = get_fs();
- if (!user_mode(regs))
- set_fs(get_ds());
- prev_state = exception_enter();
- current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
- if (get_isa16_mode(regs->cp0_epc)) {
- if (__get_user(instr[0], (u16 __user *)(epc + 0)) ||
- __get_user(instr[1], (u16 __user *)(epc + 2)))
- goto out_sigsegv;
- opcode = (instr[0] << 16) | instr[1];
-
- if (!(opcode & OPCODE))
- tcode = (opcode >> 12) & ((1 << 4) - 1);
- } else {
- if (__get_user(opcode, (u32 __user *)epc))
- goto out_sigsegv;
-
- if (!(opcode & OPCODE))
- tcode = (opcode >> 6) & ((1 << 10) - 1);
- }
- do_trap_or_bp(regs, tcode, 0, "Trap");
- out:
- set_fs(seg);
- exception_exit(prev_state);
- return;
- out_sigsegv:
- force_sig(SIGSEGV, current);
- goto out;
- }
- asmlinkage void do_ri(struct pt_regs *regs)
- {
- unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
- unsigned long old_epc = regs->cp0_epc;
- unsigned long old31 = regs->regs[31];
- enum ctx_state prev_state;
- unsigned int opcode = 0;
- int status = -1;
-
- if (mipsr2_emulation && cpu_has_mips_r6 &&
- likely(user_mode(regs)) &&
- likely(get_user(opcode, epc) >= 0)) {
- unsigned long fcr31 = 0;
- status = mipsr2_decoder(regs, opcode, &fcr31);
- switch (status) {
- case 0:
- case SIGEMT:
- task_thread_info(current)->r2_emul_return = 1;
- return;
- case SIGILL:
- goto no_r2_instr;
- default:
- process_fpemu_return(status,
- ¤t->thread.cp0_baduaddr,
- fcr31);
- task_thread_info(current)->r2_emul_return = 1;
- return;
- }
- }
- no_r2_instr:
- prev_state = exception_enter();
- current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
- if (notify_die(DIE_RI, "RI Fault", regs, 0, current->thread.trap_nr,
- SIGILL) == NOTIFY_STOP)
- goto out;
- die_if_kernel("Reserved instruction in kernel code", regs);
- if (unlikely(compute_return_epc(regs) < 0))
- goto out;
- if (!get_isa16_mode(regs->cp0_epc)) {
- if (unlikely(get_user(opcode, epc) < 0))
- status = SIGSEGV;
- if (!cpu_has_llsc && status < 0)
- status = simulate_llsc(regs, opcode);
- if (status < 0)
- status = simulate_rdhwr_normal(regs, opcode);
- if (status < 0)
- status = simulate_sync(regs, opcode);
- if (status < 0)
- status = simulate_fp(regs, opcode, old_epc, old31);
- } else if (cpu_has_mmips) {
- unsigned short mmop[2] = { 0 };
- if (unlikely(get_user(mmop[0], (u16 __user *)epc + 0) < 0))
- status = SIGSEGV;
- if (unlikely(get_user(mmop[1], (u16 __user *)epc + 1) < 0))
- status = SIGSEGV;
- opcode = mmop[0];
- opcode = (opcode << 16) | mmop[1];
- if (status < 0)
- status = simulate_rdhwr_mm(regs, opcode);
- }
- if (status < 0)
- status = SIGILL;
- if (unlikely(status > 0)) {
- regs->cp0_epc = old_epc;
- regs->regs[31] = old31;
- force_sig(status, current);
- }
- out:
- exception_exit(prev_state);
- }
- static void mt_ase_fp_affinity(void)
- {
- #ifdef CONFIG_MIPS_MT_FPAFF
- if (mt_fpemul_threshold > 0 &&
- ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
-
- if (cpumask_intersects(¤t->cpus_allowed, &mt_fpu_cpumask)) {
- cpumask_t tmask;
- current->thread.user_cpus_allowed
- = current->cpus_allowed;
- cpumask_and(&tmask, ¤t->cpus_allowed,
- &mt_fpu_cpumask);
- set_cpus_allowed_ptr(current, &tmask);
- set_thread_flag(TIF_FPUBOUND);
- }
- }
- #endif
- }
- static RAW_NOTIFIER_HEAD(cu2_chain);
- int __ref register_cu2_notifier(struct notifier_block *nb)
- {
- return raw_notifier_chain_register(&cu2_chain, nb);
- }
- int cu2_notifier_call_chain(unsigned long val, void *v)
- {
- return raw_notifier_call_chain(&cu2_chain, val, v);
- }
- static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
- void *data)
- {
- struct pt_regs *regs = data;
- die_if_kernel("COP2: Unhandled kernel unaligned access or invalid "
- "instruction", regs);
- force_sig(SIGILL, current);
- return NOTIFY_OK;
- }
- static int wait_on_fp_mode_switch(atomic_t *p)
- {
-
- schedule();
- return 0;
- }
- static int enable_restore_fp_context(int msa)
- {
- int err, was_fpu_owner, prior_msa;
-
- wait_on_atomic_t(¤t->mm->context.fp_mode_switching,
- wait_on_fp_mode_switch, TASK_KILLABLE);
- if (!used_math()) {
-
- preempt_disable();
- err = init_fpu();
- if (msa && !err) {
- enable_msa();
- init_msa_upper();
- set_thread_flag(TIF_USEDMSA);
- set_thread_flag(TIF_MSA_CTX_LIVE);
- }
- preempt_enable();
- if (!err)
- set_used_math();
- return err;
- }
-
- if (!msa && !thread_msa_context_live())
- return own_fpu(1);
-
- preempt_disable();
- was_fpu_owner = is_fpu_owner();
- err = own_fpu_inatomic(0);
- if (err)
- goto out;
- enable_msa();
- write_msa_csr(current->thread.fpu.msacsr);
- set_thread_flag(TIF_USEDMSA);
-
- prior_msa = test_and_set_thread_flag(TIF_MSA_CTX_LIVE);
- if (!prior_msa && was_fpu_owner) {
- init_msa_upper();
- goto out;
- }
- if (!prior_msa) {
-
- _restore_fp(current);
-
- init_msa_upper();
- } else {
-
- restore_msa(current);
-
- if (!was_fpu_owner)
- write_32bit_cp1_register(CP1_STATUS,
- current->thread.fpu.fcr31);
- }
- out:
- preempt_enable();
- return 0;
- }
- asmlinkage void do_cpu(struct pt_regs *regs)
- {
- enum ctx_state prev_state;
- unsigned int __user *epc;
- unsigned long old_epc, old31;
- void __user *fault_addr;
- unsigned int opcode;
- unsigned long fcr31;
- unsigned int cpid;
- int status, err;
- int sig;
- prev_state = exception_enter();
- cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
- if (cpid != 2)
- die_if_kernel("do_cpu invoked from kernel context!", regs);
- switch (cpid) {
- case 0:
- epc = (unsigned int __user *)exception_epc(regs);
- old_epc = regs->cp0_epc;
- old31 = regs->regs[31];
- opcode = 0;
- status = -1;
- if (unlikely(compute_return_epc(regs) < 0))
- break;
- if (!get_isa16_mode(regs->cp0_epc)) {
- if (unlikely(get_user(opcode, epc) < 0))
- status = SIGSEGV;
- if (!cpu_has_llsc && status < 0)
- status = simulate_llsc(regs, opcode);
- }
- if (status < 0)
- status = SIGILL;
- if (unlikely(status > 0)) {
- regs->cp0_epc = old_epc;
- regs->regs[31] = old31;
- force_sig(status, current);
- }
- break;
- case 3:
-
- if (raw_cpu_has_fpu || !cpu_has_mips_4_5_64_r2_r6) {
- force_sig(SIGILL, current);
- break;
- }
-
- case 1:
- err = enable_restore_fp_context(0);
- if (raw_cpu_has_fpu && !err)
- break;
- sig = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 0,
- &fault_addr);
-
- fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
- current->thread.fpu.fcr31 &= ~fcr31;
-
- if (!process_fpemu_return(sig, fault_addr, fcr31) && !err)
- mt_ase_fp_affinity();
- break;
- case 2:
- raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
- break;
- }
- exception_exit(prev_state);
- }
- asmlinkage void do_msa_fpe(struct pt_regs *regs, unsigned int msacsr)
- {
- enum ctx_state prev_state;
- prev_state = exception_enter();
- current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
- if (notify_die(DIE_MSAFP, "MSA FP exception", regs, 0,
- current->thread.trap_nr, SIGFPE) == NOTIFY_STOP)
- goto out;
-
- write_msa_csr(msacsr & ~MSA_CSR_CAUSEF);
- local_irq_enable();
- die_if_kernel("do_msa_fpe invoked from kernel context!", regs);
- force_sig(SIGFPE, current);
- out:
- exception_exit(prev_state);
- }
- asmlinkage void do_msa(struct pt_regs *regs)
- {
- enum ctx_state prev_state;
- int err;
- prev_state = exception_enter();
- if (!cpu_has_msa || test_thread_flag(TIF_32BIT_FPREGS)) {
- force_sig(SIGILL, current);
- goto out;
- }
- die_if_kernel("do_msa invoked from kernel context!", regs);
- err = enable_restore_fp_context(1);
- if (err)
- force_sig(SIGILL, current);
- out:
- exception_exit(prev_state);
- }
- asmlinkage void do_mdmx(struct pt_regs *regs)
- {
- enum ctx_state prev_state;
- prev_state = exception_enter();
- force_sig(SIGILL, current);
- exception_exit(prev_state);
- }
- asmlinkage void do_watch(struct pt_regs *regs)
- {
- siginfo_t info = { .si_signo = SIGTRAP, .si_code = TRAP_HWBKPT };
- enum ctx_state prev_state;
- prev_state = exception_enter();
-
- clear_c0_cause(CAUSEF_WP);
-
- if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
- mips_read_watch_registers();
- local_irq_enable();
- force_sig_info(SIGTRAP, &info, current);
- } else {
- mips_clear_watch_registers();
- local_irq_enable();
- }
- exception_exit(prev_state);
- }
- asmlinkage void do_mcheck(struct pt_regs *regs)
- {
- int multi_match = regs->cp0_status & ST0_TS;
- enum ctx_state prev_state;
- mm_segment_t old_fs = get_fs();
- prev_state = exception_enter();
- show_regs(regs);
- if (multi_match) {
- dump_tlb_regs();
- pr_info("\n");
- dump_tlb_all();
- }
- if (!user_mode(regs))
- set_fs(KERNEL_DS);
- show_code((unsigned int __user *) regs->cp0_epc);
- set_fs(old_fs);
-
- panic("Caught Machine Check exception - %scaused by multiple "
- "matching entries in the TLB.",
- (multi_match) ? "" : "not ");
- }
- asmlinkage void do_mt(struct pt_regs *regs)
- {
- int subcode;
- subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
- >> VPECONTROL_EXCPT_SHIFT;
- switch (subcode) {
- case 0:
- printk(KERN_DEBUG "Thread Underflow\n");
- break;
- case 1:
- printk(KERN_DEBUG "Thread Overflow\n");
- break;
- case 2:
- printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
- break;
- case 3:
- printk(KERN_DEBUG "Gating Storage Exception\n");
- break;
- case 4:
- printk(KERN_DEBUG "YIELD Scheduler Exception\n");
- break;
- case 5:
- printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
- break;
- default:
- printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
- subcode);
- break;
- }
- die_if_kernel("MIPS MT Thread exception in kernel", regs);
- force_sig(SIGILL, current);
- }
- asmlinkage void do_dsp(struct pt_regs *regs)
- {
- if (cpu_has_dsp)
- panic("Unexpected DSP exception");
- force_sig(SIGILL, current);
- }
- asmlinkage void do_reserved(struct pt_regs *regs)
- {
-
- show_regs(regs);
- panic("Caught reserved exception %ld - should not happen.",
- (regs->cp0_cause & 0x7f) >> 2);
- }
- static int __initdata l1parity = 1;
- static int __init nol1parity(char *s)
- {
- l1parity = 0;
- return 1;
- }
- __setup("nol1par", nol1parity);
- static int __initdata l2parity = 1;
- static int __init nol2parity(char *s)
- {
- l2parity = 0;
- return 1;
- }
- __setup("nol2par", nol2parity);
- static inline void parity_protection_init(void)
- {
- #define ERRCTL_PE 0x80000000
- #define ERRCTL_L2P 0x00800000
- if (mips_cm_revision() >= CM_REV_CM3) {
- ulong gcr_ectl, cp0_ectl;
-
- l1parity &= l2parity;
- l2parity &= l1parity;
-
- cp0_ectl = read_c0_ecc();
- write_c0_ecc(cp0_ectl | ERRCTL_PE);
- back_to_back_c0_hazard();
- cp0_ectl = read_c0_ecc();
-
- gcr_ectl = read_gcr_err_control();
- if (!(gcr_ectl & CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT_MSK) ||
- !(cp0_ectl & ERRCTL_PE)) {
-
- l1parity = l2parity = 0;
- }
-
- if (l1parity)
- cp0_ectl |= ERRCTL_PE;
- else
- cp0_ectl &= ~ERRCTL_PE;
- write_c0_ecc(cp0_ectl);
- back_to_back_c0_hazard();
- WARN_ON(!!(read_c0_ecc() & ERRCTL_PE) != l1parity);
-
- if (l2parity)
- gcr_ectl |= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
- else
- gcr_ectl &= ~CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
- write_gcr_err_control(gcr_ectl);
- gcr_ectl = read_gcr_err_control();
- gcr_ectl &= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
- WARN_ON(!!gcr_ectl != l2parity);
- pr_info("Cache parity protection %sabled\n",
- l1parity ? "en" : "dis");
- return;
- }
- switch (current_cpu_type()) {
- case CPU_24K:
- case CPU_34K:
- case CPU_74K:
- case CPU_1004K:
- case CPU_1074K:
- case CPU_INTERAPTIV:
- case CPU_PROAPTIV:
- case CPU_P5600:
- case CPU_QEMU_GENERIC:
- case CPU_P6600:
- {
- unsigned long errctl;
- unsigned int l1parity_present, l2parity_present;
- errctl = read_c0_ecc();
- errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
-
- write_c0_ecc(errctl | ERRCTL_PE);
- back_to_back_c0_hazard();
- l1parity_present = (read_c0_ecc() & ERRCTL_PE);
-
- write_c0_ecc(errctl|ERRCTL_L2P);
- back_to_back_c0_hazard();
- l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
- if (l1parity_present && l2parity_present) {
- if (l1parity)
- errctl |= ERRCTL_PE;
- if (l1parity ^ l2parity)
- errctl |= ERRCTL_L2P;
- } else if (l1parity_present) {
- if (l1parity)
- errctl |= ERRCTL_PE;
- } else if (l2parity_present) {
- if (l2parity)
- errctl |= ERRCTL_L2P;
- } else {
-
- }
- printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
- write_c0_ecc(errctl);
- back_to_back_c0_hazard();
- errctl = read_c0_ecc();
- printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
- if (l1parity_present)
- printk(KERN_INFO "Cache parity protection %sabled\n",
- (errctl & ERRCTL_PE) ? "en" : "dis");
- if (l2parity_present) {
- if (l1parity_present && l1parity)
- errctl ^= ERRCTL_L2P;
- printk(KERN_INFO "L2 cache parity protection %sabled\n",
- (errctl & ERRCTL_L2P) ? "en" : "dis");
- }
- }
- break;
- case CPU_5KC:
- case CPU_5KE:
- case CPU_LOONGSON1:
- write_c0_ecc(0x80000000);
- back_to_back_c0_hazard();
-
- printk(KERN_INFO "Cache parity protection %sabled\n",
- (read_c0_ecc() & 0x80000000) ? "en" : "dis");
- break;
- case CPU_20KC:
- case CPU_25KF:
-
- printk(KERN_INFO "Enable cache parity protection for "
- "MIPS 20KC/25KF CPUs.\n");
- clear_c0_status(ST0_DE);
- break;
- default:
- break;
- }
- }
- asmlinkage void cache_parity_error(void)
- {
- const int field = 2 * sizeof(unsigned long);
- unsigned int reg_val;
-
- printk("Cache error exception:\n");
- printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
- reg_val = read_c0_cacheerr();
- printk("c0_cacheerr == %08x\n", reg_val);
- printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
- reg_val & (1<<30) ? "secondary" : "primary",
- reg_val & (1<<31) ? "data" : "insn");
- if ((cpu_has_mips_r2_r6) &&
- ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS)) {
- pr_err("Error bits: %s%s%s%s%s%s%s%s\n",
- reg_val & (1<<29) ? "ED " : "",
- reg_val & (1<<28) ? "ET " : "",
- reg_val & (1<<27) ? "ES " : "",
- reg_val & (1<<26) ? "EE " : "",
- reg_val & (1<<25) ? "EB " : "",
- reg_val & (1<<24) ? "EI " : "",
- reg_val & (1<<23) ? "E1 " : "",
- reg_val & (1<<22) ? "E0 " : "");
- } else {
- pr_err("Error bits: %s%s%s%s%s%s%s\n",
- reg_val & (1<<29) ? "ED " : "",
- reg_val & (1<<28) ? "ET " : "",
- reg_val & (1<<26) ? "EE " : "",
- reg_val & (1<<25) ? "EB " : "",
- reg_val & (1<<24) ? "EI " : "",
- reg_val & (1<<23) ? "E1 " : "",
- reg_val & (1<<22) ? "E0 " : "");
- }
- printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
- #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
- if (reg_val & (1<<22))
- printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
- if (reg_val & (1<<23))
- printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
- #endif
- panic("Can't handle the cache error!");
- }
- asmlinkage void do_ftlb(void)
- {
- const int field = 2 * sizeof(unsigned long);
- unsigned int reg_val;
-
- if ((cpu_has_mips_r2_r6) &&
- (((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS) ||
- ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_LOONGSON))) {
- pr_err("FTLB error exception, cp0_ecc=0x%08x:\n",
- read_c0_ecc());
- pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
- reg_val = read_c0_cacheerr();
- pr_err("c0_cacheerr == %08x\n", reg_val);
- if ((reg_val & 0xc0000000) == 0xc0000000) {
- pr_err("Decoded c0_cacheerr: FTLB parity error\n");
- } else {
- pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
- reg_val & (1<<30) ? "secondary" : "primary",
- reg_val & (1<<31) ? "data" : "insn");
- }
- } else {
- pr_err("FTLB error exception\n");
- }
-
- cache_parity_error();
- }
- void ejtag_exception_handler(struct pt_regs *regs)
- {
- const int field = 2 * sizeof(unsigned long);
- unsigned long depc, old_epc, old_ra;
- unsigned int debug;
- printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
- depc = read_c0_depc();
- debug = read_c0_debug();
- printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
- if (debug & 0x80000000) {
-
- old_epc = regs->cp0_epc;
- old_ra = regs->regs[31];
- regs->cp0_epc = depc;
- compute_return_epc(regs);
- depc = regs->cp0_epc;
- regs->cp0_epc = old_epc;
- regs->regs[31] = old_ra;
- } else
- depc += 4;
- write_c0_depc(depc);
- #if 0
- printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
- write_c0_debug(debug | 0x100);
- #endif
- }
- static RAW_NOTIFIER_HEAD(nmi_chain);
- int register_nmi_notifier(struct notifier_block *nb)
- {
- return raw_notifier_chain_register(&nmi_chain, nb);
- }
- void __noreturn nmi_exception_handler(struct pt_regs *regs)
- {
- char str[100];
- nmi_enter();
- raw_notifier_call_chain(&nmi_chain, 0, regs);
- bust_spinlocks(1);
- snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n",
- smp_processor_id(), regs->cp0_epc);
- regs->cp0_epc = read_c0_errorepc();
- die(str, regs);
- nmi_exit();
- }
- #define VECTORSPACING 0x100
- unsigned long ebase;
- EXPORT_SYMBOL_GPL(ebase);
- unsigned long exception_handlers[32];
- unsigned long vi_handlers[64];
- void __init *set_except_vector(int n, void *addr)
- {
- unsigned long handler = (unsigned long) addr;
- unsigned long old_handler;
- #ifdef CONFIG_CPU_MICROMIPS
-
- if (!(handler & 0x1))
- handler |= 1;
- #endif
- old_handler = xchg(&exception_handlers[n], handler);
- if (n == 0 && cpu_has_divec) {
- #ifdef CONFIG_CPU_MICROMIPS
- unsigned long jump_mask = ~((1 << 27) - 1);
- #else
- unsigned long jump_mask = ~((1 << 28) - 1);
- #endif
- u32 *buf = (u32 *)(ebase + 0x200);
- unsigned int k0 = 26;
- if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
- uasm_i_j(&buf, handler & ~jump_mask);
- uasm_i_nop(&buf);
- } else {
- UASM_i_LA(&buf, k0, handler);
- uasm_i_jr(&buf, k0);
- uasm_i_nop(&buf);
- }
- local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
- }
- return (void *)old_handler;
- }
- static void do_default_vi(void)
- {
- show_regs(get_irq_regs());
- panic("Caught unexpected vectored interrupt.");
- }
- static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
- {
- unsigned long handler;
- unsigned long old_handler = vi_handlers[n];
- int srssets = current_cpu_data.srsets;
- u16 *h;
- unsigned char *b;
- BUG_ON(!cpu_has_veic && !cpu_has_vint);
- if (addr == NULL) {
- handler = (unsigned long) do_default_vi;
- srs = 0;
- } else
- handler = (unsigned long) addr;
- vi_handlers[n] = handler;
- b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
- if (srs >= srssets)
- panic("Shadow register set %d not supported", srs);
- if (cpu_has_veic) {
- if (board_bind_eic_interrupt)
- board_bind_eic_interrupt(n, srs);
- } else if (cpu_has_vint) {
-
- if (srssets > 1)
- change_c0_srsmap(0xf << n*4, srs << n*4);
- }
- if (srs == 0) {
-
- extern char except_vec_vi, except_vec_vi_lui;
- extern char except_vec_vi_ori, except_vec_vi_end;
- extern char rollback_except_vec_vi;
- char *vec_start = using_rollback_handler() ?
- &rollback_except_vec_vi : &except_vec_vi;
- #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
- const int lui_offset = &except_vec_vi_lui - vec_start + 2;
- const int ori_offset = &except_vec_vi_ori - vec_start + 2;
- #else
- const int lui_offset = &except_vec_vi_lui - vec_start;
- const int ori_offset = &except_vec_vi_ori - vec_start;
- #endif
- const int handler_len = &except_vec_vi_end - vec_start;
- if (handler_len > VECTORSPACING) {
-
- panic("VECTORSPACING too small");
- }
- set_handler(((unsigned long)b - ebase), vec_start,
- #ifdef CONFIG_CPU_MICROMIPS
- (handler_len - 1));
- #else
- handler_len);
- #endif
- h = (u16 *)(b + lui_offset);
- *h = (handler >> 16) & 0xffff;
- h = (u16 *)(b + ori_offset);
- *h = (handler & 0xffff);
- local_flush_icache_range((unsigned long)b,
- (unsigned long)(b+handler_len));
- }
- else {
-
- u32 insn;
- h = (u16 *)b;
-
- #ifdef CONFIG_CPU_MICROMIPS
- insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
- #else
- insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
- #endif
- h[0] = (insn >> 16) & 0xffff;
- h[1] = insn & 0xffff;
- h[2] = 0;
- h[3] = 0;
- local_flush_icache_range((unsigned long)b,
- (unsigned long)(b+8));
- }
- return (void *)old_handler;
- }
- void *set_vi_handler(int n, vi_handler_t addr)
- {
- return set_vi_srs_handler(n, addr, 0);
- }
- extern void tlb_init(void);
- int cp0_compare_irq;
- EXPORT_SYMBOL_GPL(cp0_compare_irq);
- int cp0_compare_irq_shift;
- int cp0_perfcount_irq;
- EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
- int cp0_fdc_irq;
- EXPORT_SYMBOL_GPL(cp0_fdc_irq);
- static int noulri;
- static int __init ulri_disable(char *s)
- {
- pr_info("Disabling ulri\n");
- noulri = 1;
- return 1;
- }
- __setup("noulri", ulri_disable);
- static void configure_status(void)
- {
-
- unsigned int status_set = ST0_CU0;
- #ifdef CONFIG_64BIT
- status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
- #endif
- if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
- status_set |= ST0_XX;
- if (cpu_has_dsp)
- status_set |= ST0_MX;
- change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
- status_set);
- }
- unsigned int hwrena;
- EXPORT_SYMBOL_GPL(hwrena);
- static void configure_hwrena(void)
- {
- hwrena = cpu_hwrena_impl_bits;
- if (cpu_has_mips_r2_r6)
- hwrena |= MIPS_HWRENA_CPUNUM |
- MIPS_HWRENA_SYNCISTEP |
- MIPS_HWRENA_CC |
- MIPS_HWRENA_CCRES;
- if (!noulri && cpu_has_userlocal)
- hwrena |= MIPS_HWRENA_ULR;
- if (hwrena)
- write_c0_hwrena(hwrena);
- }
- static void configure_exception_vector(void)
- {
- if (cpu_has_veic || cpu_has_vint) {
- unsigned long sr = set_c0_status(ST0_BEV);
-
- if (cpu_has_ebase_wg) {
- #ifdef CONFIG_64BIT
- write_c0_ebase_64(ebase | MIPS_EBASE_WG);
- #else
- write_c0_ebase(ebase | MIPS_EBASE_WG);
- #endif
- }
- write_c0_ebase(ebase);
- write_c0_status(sr);
-
- change_c0_intctl(0x3e0, VECTORSPACING);
- }
- if (cpu_has_divec) {
- if (cpu_has_mipsmt) {
- unsigned int vpflags = dvpe();
- set_c0_cause(CAUSEF_IV);
- evpe(vpflags);
- } else
- set_c0_cause(CAUSEF_IV);
- }
- }
- void per_cpu_trap_init(bool is_boot_cpu)
- {
- unsigned int cpu = smp_processor_id();
- configure_status();
- configure_hwrena();
- configure_exception_vector();
-
- if (cpu_has_mips_r2_r6) {
-
- if (!is_boot_cpu) {
-
- if (cpu_has_ebase_wg) {
- #ifdef CONFIG_64BIT
- write_c0_ebase_64(ebase | MIPS_EBASE_WG);
- #else
- write_c0_ebase(ebase | MIPS_EBASE_WG);
- #endif
- }
- write_c0_ebase(ebase);
- }
- cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
- cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
- cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
- cp0_fdc_irq = (read_c0_intctl() >> INTCTLB_IPFDC) & 7;
- if (!cp0_fdc_irq)
- cp0_fdc_irq = -1;
- } else {
- cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
- cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
- cp0_perfcount_irq = -1;
- cp0_fdc_irq = -1;
- }
- if (!cpu_data[cpu].asid_cache)
- cpu_data[cpu].asid_cache = asid_first_version(cpu);
- atomic_inc(&init_mm.mm_count);
- current->active_mm = &init_mm;
- BUG_ON(current->mm);
- enter_lazy_tlb(&init_mm, current);
-
- if (!is_boot_cpu)
- cpu_cache_init();
- tlb_init();
- TLBMISS_HANDLER_SETUP();
- }
- void set_handler(unsigned long offset, void *addr, unsigned long size)
- {
- #ifdef CONFIG_CPU_MICROMIPS
- memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
- #else
- memcpy((void *)(ebase + offset), addr, size);
- #endif
- local_flush_icache_range(ebase + offset, ebase + offset + size);
- }
- static char panic_null_cerr[] =
- "Trying to set NULL cache error exception handler";
- void set_uncached_handler(unsigned long offset, void *addr,
- unsigned long size)
- {
- unsigned long uncached_ebase = CKSEG1ADDR(ebase);
- if (!addr)
- panic(panic_null_cerr);
- memcpy((void *)(uncached_ebase + offset), addr, size);
- }
- static int __initdata rdhwr_noopt;
- static int __init set_rdhwr_noopt(char *str)
- {
- rdhwr_noopt = 1;
- return 1;
- }
- __setup("rdhwr_noopt", set_rdhwr_noopt);
- void __init trap_init(void)
- {
- extern char except_vec3_generic;
- extern char except_vec4;
- extern char except_vec3_r4000;
- unsigned long i;
- check_wait();
- if (cpu_has_veic || cpu_has_vint) {
- unsigned long size = 0x200 + VECTORSPACING*64;
- phys_addr_t ebase_pa;
- ebase = (unsigned long)
- __alloc_bootmem(size, 1 << fls(size), 0);
-
- ebase_pa = __pa(ebase);
- if (!IS_ENABLED(CONFIG_EVA) && !WARN_ON(ebase_pa >= 0x20000000))
- ebase = CKSEG0ADDR(ebase_pa);
- } else {
- ebase = CAC_BASE;
- if (cpu_has_mips_r2_r6) {
- if (cpu_has_ebase_wg) {
- #ifdef CONFIG_64BIT
- ebase = (read_c0_ebase_64() & ~0xfff);
- #else
- ebase = (read_c0_ebase() & ~0xfff);
- #endif
- } else {
- ebase += (read_c0_ebase() & 0x3ffff000);
- }
- }
- }
- if (cpu_has_mmips) {
- unsigned int config3 = read_c0_config3();
- if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
- write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
- else
- write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
- }
- if (board_ebase_setup)
- board_ebase_setup();
- per_cpu_trap_init(true);
-
- set_handler(0x180, &except_vec3_generic, 0x80);
-
- for (i = 0; i <= 31; i++)
- set_except_vector(i, handle_reserved);
-
- if (cpu_has_ejtag && board_ejtag_handler_setup)
- board_ejtag_handler_setup();
-
- if (cpu_has_watch)
- set_except_vector(EXCCODE_WATCH, handle_watch);
-
- if (cpu_has_veic || cpu_has_vint) {
- int nvec = cpu_has_veic ? 64 : 8;
- for (i = 0; i < nvec; i++)
- set_vi_handler(i, NULL);
- }
- else if (cpu_has_divec)
- set_handler(0x200, &except_vec4, 0x8);
-
- parity_protection_init();
-
- if (board_be_init)
- board_be_init();
- set_except_vector(EXCCODE_INT, using_rollback_handler() ?
- rollback_handle_int : handle_int);
- set_except_vector(EXCCODE_MOD, handle_tlbm);
- set_except_vector(EXCCODE_TLBL, handle_tlbl);
- set_except_vector(EXCCODE_TLBS, handle_tlbs);
- set_except_vector(EXCCODE_ADEL, handle_adel);
- set_except_vector(EXCCODE_ADES, handle_ades);
- set_except_vector(EXCCODE_IBE, handle_ibe);
- set_except_vector(EXCCODE_DBE, handle_dbe);
- set_except_vector(EXCCODE_SYS, handle_sys);
- set_except_vector(EXCCODE_BP, handle_bp);
- if (rdhwr_noopt)
- set_except_vector(EXCCODE_RI, handle_ri);
- else {
- if (cpu_has_vtag_icache)
- set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
- else if (current_cpu_type() == CPU_LOONGSON3)
- set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
- else
- set_except_vector(EXCCODE_RI, handle_ri_rdhwr);
- }
- set_except_vector(EXCCODE_CPU, handle_cpu);
- set_except_vector(EXCCODE_OV, handle_ov);
- set_except_vector(EXCCODE_TR, handle_tr);
- set_except_vector(EXCCODE_MSAFPE, handle_msa_fpe);
- if (current_cpu_type() == CPU_R6000 ||
- current_cpu_type() == CPU_R6000A) {
-
-
-
- }
- if (board_nmi_handler_setup)
- board_nmi_handler_setup();
- if (cpu_has_fpu && !cpu_has_nofpuex)
- set_except_vector(EXCCODE_FPE, handle_fpe);
- set_except_vector(MIPS_EXCCODE_TLBPAR, handle_ftlb);
- if (cpu_has_rixiex) {
- set_except_vector(EXCCODE_TLBRI, tlb_do_page_fault_0);
- set_except_vector(EXCCODE_TLBXI, tlb_do_page_fault_0);
- }
- set_except_vector(EXCCODE_MSADIS, handle_msa);
- set_except_vector(EXCCODE_MDMX, handle_mdmx);
- if (cpu_has_mcheck)
- set_except_vector(EXCCODE_MCHECK, handle_mcheck);
- if (cpu_has_mipsmt)
- set_except_vector(EXCCODE_THREAD, handle_mt);
- set_except_vector(EXCCODE_DSPDIS, handle_dsp);
- if (board_cache_error_setup)
- board_cache_error_setup();
- if (cpu_has_vce)
-
- set_handler(0x180, &except_vec3_r4000, 0x100);
- else if (cpu_has_4kex)
- set_handler(0x180, &except_vec3_generic, 0x80);
- else
- set_handler(0x080, &except_vec3_generic, 0x80);
- local_flush_icache_range(ebase, ebase + 0x400);
- sort_extable(__start___dbe_table, __stop___dbe_table);
- cu2_notifier(default_cu2_call, 0x80000000);
- }
- static int trap_pm_notifier(struct notifier_block *self, unsigned long cmd,
- void *v)
- {
- switch (cmd) {
- case CPU_PM_ENTER_FAILED:
- case CPU_PM_EXIT:
- configure_status();
- configure_hwrena();
- configure_exception_vector();
-
- TLBMISS_HANDLER_RESTORE();
- break;
- }
- return NOTIFY_OK;
- }
- static struct notifier_block trap_pm_notifier_block = {
- .notifier_call = trap_pm_notifier,
- };
- static int __init trap_pm_init(void)
- {
- return cpu_pm_register_notifier(&trap_pm_notifier_block);
- }
- arch_initcall(trap_pm_init);
|