📄 traps.c
字号:
/* * NMI exception handler. */void nmi_exception_handler(struct pt_regs *regs){#ifdef CONFIG_MIPS_MT_SMTC unsigned long dvpret = dvpe(); bust_spinlocks(1); printk("NMI taken!!!!\n"); mips_mt_regdump(dvpret);#else bust_spinlocks(1); printk("NMI taken!!!!\n");#endif /* CONFIG_MIPS_MT_SMTC */ die("NMI", regs); while(1) ;}#define VECTORSPACING 0x100 /* for EI/VI mode */unsigned long ebase;unsigned long exception_handlers[32];unsigned long vi_handlers[64];/* * As a side effect of the way this is implemented we're limited * to interrupt handlers in the address range from * KSEG0 <= x < KSEG0 + 256mb on the Nevada. Oh well ... */void *set_except_vector(int n, void *addr){ unsigned long handler = (unsigned long) addr; unsigned long old_handler = exception_handlers[n]; exception_handlers[n] = handler; if (n == 0 && cpu_has_divec) { *(volatile u32 *)(ebase + 0x200) = 0x08000000 | (0x03ffffff & (handler >> 2)); flush_icache_range(ebase + 0x200, ebase + 0x204); } return (void *)old_handler;}#ifdef CONFIG_CPU_MIPSR2/* * MIPSR2 shadow register set allocation * FIXME: SMP... */static struct shadow_registers { /* * Number of shadow register sets supported */ unsigned long sr_supported; /* * Bitmap of allocated shadow registers */ unsigned long sr_allocated;} shadow_registers;static void mips_srs_init(void){#ifdef CONFIG_CPU_MIPSR2_SRS shadow_registers.sr_supported = ((read_c0_srsctl() >> 26) & 0x0f) + 1; printk(KERN_INFO "%d MIPSR2 register sets available\n", shadow_registers.sr_supported);#endif shadow_registers.sr_allocated = 1; /* Set 0 used by kernel */}int mips_srs_max(void){ return shadow_registers.sr_supported;}int mips_srs_alloc(void){ struct shadow_registers *sr = &shadow_registers; int set;again: set = find_first_zero_bit(&sr->sr_allocated, sr->sr_supported); if (set >= sr->sr_supported) return -1; if (test_and_set_bit(set, &sr->sr_allocated)) goto again; return set;}void mips_srs_free(int set){ struct shadow_registers *sr = &shadow_registers; clear_bit(set, &sr->sr_allocated);}static void *set_vi_srs_handler(int n, void *addr, int srs){ unsigned long handler; unsigned long old_handler = vi_handlers[n]; u32 *w; unsigned char *b; if (!cpu_has_veic && !cpu_has_vint) BUG(); if (addr == NULL) { handler = (unsigned long) do_default_vi; srs = 0; } else handler = (unsigned long) addr; vi_handlers[n] = (unsigned long) addr; b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING); if (srs >= mips_srs_max()) 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) { /* SRSMap is only defined if shadow sets are implemented */ if (mips_srs_max() > 1) change_c0_srsmap (0xf << n*4, srs << n*4); } if (srs == 0) { /* * If no shadow set is selected then use the default handler * that does normal register saving and a standard interrupt exit */ extern char except_vec_vi, except_vec_vi_lui; extern char except_vec_vi_ori, except_vec_vi_end;#ifdef CONFIG_MIPS_MT_SMTC /* * We need to provide the SMTC vectored interrupt handler * not only with the address of the handler, but with the * Status.IM bit to be masked before going there. */ extern char except_vec_vi_mori; const int mori_offset = &except_vec_vi_mori - &except_vec_vi;#endif /* CONFIG_MIPS_MT_SMTC */ const int handler_len = &except_vec_vi_end - &except_vec_vi; const int lui_offset = &except_vec_vi_lui - &except_vec_vi; const int ori_offset = &except_vec_vi_ori - &except_vec_vi; if (handler_len > VECTORSPACING) { /* * Sigh... panicing won't help as the console * is probably not configured :( */ panic ("VECTORSPACING too small"); } memcpy (b, &except_vec_vi, handler_len);#ifdef CONFIG_MIPS_MT_SMTC if (n > 7) printk("Vector index %d exceeds SMTC maximum\n", n); w = (u32 *)(b + mori_offset); *w = (*w & 0xffff0000) | (0x100 << n);#endif /* CONFIG_MIPS_MT_SMTC */ w = (u32 *)(b + lui_offset); *w = (*w & 0xffff0000) | (((u32)handler >> 16) & 0xffff); w = (u32 *)(b + ori_offset); *w = (*w & 0xffff0000) | ((u32)handler & 0xffff); flush_icache_range((unsigned long)b, (unsigned long)(b+handler_len)); } else { /* * In other cases jump directly to the interrupt handler * * It is the handlers responsibility to save registers if required * (eg hi/lo) and return from the exception using "eret" */ w = (u32 *)b; *w++ = 0x08000000 | (((u32)handler >> 2) & 0x03fffff); /* j handler */ *w = 0; flush_icache_range((unsigned long)b, (unsigned long)(b+8)); } return (void *)old_handler;}void *set_vi_handler(int n, void *addr){ return set_vi_srs_handler(n, addr, 0);}#endif/* * This is used by native signal handling */asmlinkage int (*save_fp_context)(struct sigcontext *sc);asmlinkage int (*restore_fp_context)(struct sigcontext *sc);extern asmlinkage int _save_fp_context(struct sigcontext *sc);extern asmlinkage int _restore_fp_context(struct sigcontext *sc);extern asmlinkage int fpu_emulator_save_context(struct sigcontext *sc);extern asmlinkage int fpu_emulator_restore_context(struct sigcontext *sc);#ifdef CONFIG_SMPstatic int smp_save_fp_context(struct sigcontext *sc){ return cpu_has_fpu ? _save_fp_context(sc) : fpu_emulator_save_context(sc);}static int smp_restore_fp_context(struct sigcontext *sc){ return cpu_has_fpu ? _restore_fp_context(sc) : fpu_emulator_restore_context(sc);}#endifstatic inline void signal_init(void){#ifdef CONFIG_SMP /* For now just do the cpu_has_fpu check when the functions are invoked */ save_fp_context = smp_save_fp_context; restore_fp_context = smp_restore_fp_context;#else if (cpu_has_fpu) { save_fp_context = _save_fp_context; restore_fp_context = _restore_fp_context; } else { save_fp_context = fpu_emulator_save_context; restore_fp_context = fpu_emulator_restore_context; }#endif}#ifdef CONFIG_MIPS32_COMPAT/* * This is used by 32-bit signal stuff on the 64-bit kernel */asmlinkage int (*save_fp_context32)(struct sigcontext32 *sc);asmlinkage int (*restore_fp_context32)(struct sigcontext32 *sc);extern asmlinkage int _save_fp_context32(struct sigcontext32 *sc);extern asmlinkage int _restore_fp_context32(struct sigcontext32 *sc);extern asmlinkage int fpu_emulator_save_context32(struct sigcontext32 *sc);extern asmlinkage int fpu_emulator_restore_context32(struct sigcontext32 *sc);static inline void signal32_init(void){ if (cpu_has_fpu) { save_fp_context32 = _save_fp_context32; restore_fp_context32 = _restore_fp_context32; } else { save_fp_context32 = fpu_emulator_save_context32; restore_fp_context32 = fpu_emulator_restore_context32; }}#endifextern void cpu_cache_init(void);extern void tlb_init(void);extern void flush_tlb_handlers(void);void __init per_cpu_trap_init(void){ unsigned int cpu = smp_processor_id(); unsigned int status_set = ST0_CU0;#ifdef CONFIG_MIPS_MT_SMTC int secondaryTC = 0; int bootTC = (cpu == 0); /* * Only do per_cpu_trap_init() for first TC of Each VPE. * Note that this hack assumes that the SMTC init code * assigns TCs consecutively and in ascending order. */ if (((read_c0_tcbind() & TCBIND_CURTC) != 0) && ((read_c0_tcbind() & TCBIND_CURVPE) == cpu_data[cpu - 1].vpe_id)) secondaryTC = 1;#endif /* CONFIG_MIPS_MT_SMTC */ /* * Disable coprocessors and select 32-bit or 64-bit addressing * and the 16/32 or 32/32 FPR register model. Reset the BEV * flag that some firmware may have left set and the TS bit (for * IP27). Set XX for ISA IV code to work. */#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; change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX, status_set); if (cpu_has_dsp) set_c0_status(ST0_MX);#ifdef CONFIG_CPU_MIPSR2 write_c0_hwrena (0x0000000f); /* Allow rdhwr to all registers */#endif#ifdef CONFIG_MIPS_MT_SMTC if (!secondaryTC) {#endif /* CONFIG_MIPS_MT_SMTC */ /* * Interrupt handling. */ if (cpu_has_veic || cpu_has_vint) { write_c0_ebase (ebase); /* Setting vector spacing enables EI/VI mode */ 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); }#ifdef CONFIG_MIPS_MT_SMTC }#endif /* CONFIG_MIPS_MT_SMTC */ cpu_data[cpu].asid_cache = ASID_FIRST_VERSION; TLBMISS_HANDLER_SETUP(); atomic_inc(&init_mm.mm_count); current->active_mm = &init_mm; BUG_ON(current->mm); enter_lazy_tlb(&init_mm, current);#ifdef CONFIG_MIPS_MT_SMTC if (bootTC) {#endif /* CONFIG_MIPS_MT_SMTC */ cpu_cache_init(); tlb_init();#ifdef CONFIG_MIPS_MT_SMTC }#endif /* CONFIG_MIPS_MT_SMTC */}/* Install CPU exception handler */void __init set_handler (unsigned long offset, void *addr, unsigned long size){ memcpy((void *)(ebase + offset), addr, size); flush_icache_range(ebase + offset, ebase + offset + size);}/* Install uncached CPU exception handler */void __init set_uncached_handler (unsigned long offset, void *addr, unsigned long size){#ifdef CONFIG_32BIT unsigned long uncached_ebase = KSEG1ADDR(ebase);#endif#ifdef CONFIG_64BIT unsigned long uncached_ebase = TO_UNCAC(ebase);#endif memcpy((void *)(uncached_ebase + offset), addr, size);}void __init trap_init(void){ extern char except_vec3_generic, except_vec3_r4000; extern char except_vec4; unsigned long i; if (cpu_has_veic || cpu_has_vint) ebase = (unsigned long) alloc_bootmem_low_pages (0x200 + VECTORSPACING*64); else ebase = CAC_BASE;#ifdef CONFIG_CPU_MIPSR2 mips_srs_init();#endif per_cpu_trap_init(); /* * Copy the generic exception handlers to their final destination. * This will be overriden later as suitable for a particular * configuration. */ set_handler(0x180, &except_vec3_generic, 0x80); /* * Setup default vectors */ for (i = 0; i <= 31; i++) set_except_vector(i, handle_reserved); /* * Copy the EJTAG debug exception vector handler code to it's final * destination. */ if (cpu_has_ejtag && board_ejtag_handler_setup) board_ejtag_handler_setup (); /* * Only some CPUs have the watch exceptions. */ if (cpu_has_watch) set_except_vector(23, handle_watch); /* * Initialise interrupt handlers */ 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); /* * Some CPUs can enable/disable for cache parity detection, but does * it different ways. */ parity_protection_init(); /* * The Data Bus Errors / Instruction Bus Errors are signaled * by external hardware. Therefore these two exceptions * may have board specific handlers. */ if (board_be_init) board_be_init(); set_except_vector(0, handle_int); set_except_vector(1, handle_tlbm); set_except_vector(2, handle_tlbl); set_except_vector(3, handle_tlbs); set_except_vector(4, handle_adel); set_except_vector(5, handle_ades); set_except_vector(6, handle_ibe); set_except_vector(7, handle_dbe); set_except_vector(8, handle_sys); set_except_vector(9, handle_bp); set_except_vector(10, handle_ri); set_except_vector(11, handle_cpu); set_except_vector(12, handle_ov); set_except_vector(13, handle_tr); if (current_cpu_data.cputype == CPU_R6000 || current_cpu_data.cputype == CPU_R6000A) { /* * The R6000 is the only R-series CPU that features a machine * check exception (similar to the R4000 cache error) and * unaligned ldc1/sdc1 exception. The handlers have not been * written yet. Well, anyway there is no R6000 machine on the * current list of targets for Linux/MIPS. * (Duh, crap, there is someone with a triple R6k machine) */ //set_except_vector(14, handle_mc); //set_except_vector(15, handle_ndc); } if (board_nmi_handler_setup) board_nmi_handler_setup(); if (cpu_has_fpu && !cpu_has_nofpuex) set_except_vector(15, handle_fpe); set_except_vector(22, handle_mdmx); if (cpu_has_mcheck) set_except_vector(24, handle_mcheck); if (cpu_has_mipsmt) set_except_vector(25, handle_mt); if (cpu_has_dsp) set_except_vector(26, handle_dsp); if (cpu_has_vce) /* Special exception: R4[04]00 uses also the divec space. */ memcpy((void *)(CAC_BASE + 0x180), &except_vec3_r4000, 0x100); else if (cpu_has_4kex) memcpy((void *)(CAC_BASE + 0x180), &except_vec3_generic, 0x80); else memcpy((void *)(CAC_BASE + 0x080), &except_vec3_generic, 0x80); signal_init();#ifdef CONFIG_MIPS32_COMPAT signal32_init();#endif flush_icache_range(ebase, ebase + 0x400); flush_tlb_handlers();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -