⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tlbex.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
L_LA(_split)L_LA(_nopage_tlbl)L_LA(_nopage_tlbs)L_LA(_nopage_tlbm)L_LA(_smp_pgtable_change)L_LA(_r3000_write_probe_fail)/* convenience macros for instructions */#ifdef CONFIG_64BIT# define i_LW(buf, rs, rt, off) i_ld(buf, rs, rt, off)# define i_SW(buf, rs, rt, off) i_sd(buf, rs, rt, off)# define i_SLL(buf, rs, rt, sh) i_dsll(buf, rs, rt, sh)# define i_SRA(buf, rs, rt, sh) i_dsra(buf, rs, rt, sh)# define i_SRL(buf, rs, rt, sh) i_dsrl(buf, rs, rt, sh)# define i_MFC0(buf, rt, rd...) i_dmfc0(buf, rt, rd)# define i_MTC0(buf, rt, rd...) i_dmtc0(buf, rt, rd)# define i_ADDIU(buf, rs, rt, val) i_daddiu(buf, rs, rt, val)# define i_ADDU(buf, rs, rt, rd) i_daddu(buf, rs, rt, rd)# define i_SUBU(buf, rs, rt, rd) i_dsubu(buf, rs, rt, rd)# define i_LL(buf, rs, rt, off) i_lld(buf, rs, rt, off)# define i_SC(buf, rs, rt, off) i_scd(buf, rs, rt, off)#else# define i_LW(buf, rs, rt, off) i_lw(buf, rs, rt, off)# define i_SW(buf, rs, rt, off) i_sw(buf, rs, rt, off)# define i_SLL(buf, rs, rt, sh) i_sll(buf, rs, rt, sh)# define i_SRA(buf, rs, rt, sh) i_sra(buf, rs, rt, sh)# define i_SRL(buf, rs, rt, sh) i_srl(buf, rs, rt, sh)# define i_MFC0(buf, rt, rd...) i_mfc0(buf, rt, rd)# define i_MTC0(buf, rt, rd...) i_mtc0(buf, rt, rd)# define i_ADDIU(buf, rs, rt, val) i_addiu(buf, rs, rt, val)# define i_ADDU(buf, rs, rt, rd) i_addu(buf, rs, rt, rd)# define i_SUBU(buf, rs, rt, rd) i_subu(buf, rs, rt, rd)# define i_LL(buf, rs, rt, off) i_ll(buf, rs, rt, off)# define i_SC(buf, rs, rt, off) i_sc(buf, rs, rt, off)#endif#define i_b(buf, off) i_beq(buf, 0, 0, off)#define i_beqz(buf, rs, off) i_beq(buf, rs, 0, off)#define i_beqzl(buf, rs, off) i_beql(buf, rs, 0, off)#define i_bnez(buf, rs, off) i_bne(buf, rs, 0, off)#define i_bnezl(buf, rs, off) i_bnel(buf, rs, 0, off)#define i_move(buf, a, b) i_ADDU(buf, a, 0, b)#define i_nop(buf) i_sll(buf, 0, 0, 0)#define i_ssnop(buf) i_sll(buf, 0, 0, 1)#define i_ehb(buf) i_sll(buf, 0, 0, 3)#ifdef CONFIG_64BITstatic __init int __maybe_unused in_compat_space_p(long addr){	/* Is this address in 32bit compat space? */	return (((addr) & 0xffffffff00000000L) == 0xffffffff00000000L);}static __init int __maybe_unused rel_highest(long val){	return ((((val + 0x800080008000L) >> 48) & 0xffff) ^ 0x8000) - 0x8000;}static __init int __maybe_unused rel_higher(long val){	return ((((val + 0x80008000L) >> 32) & 0xffff) ^ 0x8000) - 0x8000;}#endifstatic __init int rel_hi(long val){	return ((((val + 0x8000L) >> 16) & 0xffff) ^ 0x8000) - 0x8000;}static __init int rel_lo(long val){	return ((val & 0xffff) ^ 0x8000) - 0x8000;}static __init void i_LA_mostly(u32 **buf, unsigned int rs, long addr){#ifdef CONFIG_64BIT	if (!in_compat_space_p(addr)) {		i_lui(buf, rs, rel_highest(addr));		if (rel_higher(addr))			i_daddiu(buf, rs, rs, rel_higher(addr));		if (rel_hi(addr)) {			i_dsll(buf, rs, rs, 16);			i_daddiu(buf, rs, rs, rel_hi(addr));			i_dsll(buf, rs, rs, 16);		} else			i_dsll32(buf, rs, rs, 0);	} else#endif		i_lui(buf, rs, rel_hi(addr));}static __init void __maybe_unused i_LA(u32 **buf, unsigned int rs,					     long addr){	i_LA_mostly(buf, rs, addr);	if (rel_lo(addr))		i_ADDIU(buf, rs, rs, rel_lo(addr));}/* * handle relocations */struct reloc {	u32 *addr;	unsigned int type;	enum label_id lab;};static __init void r_mips_pc16(struct reloc **rel, u32 *addr,			       enum label_id l){	(*rel)->addr = addr;	(*rel)->type = R_MIPS_PC16;	(*rel)->lab = l;	(*rel)++;}static inline void __resolve_relocs(struct reloc *rel, struct label *lab){	long laddr = (long)lab->addr;	long raddr = (long)rel->addr;	switch (rel->type) {	case R_MIPS_PC16:		*rel->addr |= build_bimm(laddr - (raddr + 4));		break;	default:		panic("Unsupported TLB synthesizer relocation %d",		      rel->type);	}}static __init void resolve_relocs(struct reloc *rel, struct label *lab){	struct label *l;	for (; rel->lab != label_invalid; rel++)		for (l = lab; l->lab != label_invalid; l++)			if (rel->lab == l->lab)				__resolve_relocs(rel, l);}static __init void move_relocs(struct reloc *rel, u32 *first, u32 *end,			       long off){	for (; rel->lab != label_invalid; rel++)		if (rel->addr >= first && rel->addr < end)			rel->addr += off;}static __init void move_labels(struct label *lab, u32 *first, u32 *end,			       long off){	for (; lab->lab != label_invalid; lab++)		if (lab->addr >= first && lab->addr < end)			lab->addr += off;}static __init void copy_handler(struct reloc *rel, struct label *lab,				u32 *first, u32 *end, u32 *target){	long off = (long)(target - first);	memcpy(target, first, (end - first) * sizeof(u32));	move_relocs(rel, first, end, off);	move_labels(lab, first, end, off);}static __init int __maybe_unused insn_has_bdelay(struct reloc *rel,						       u32 *addr){	for (; rel->lab != label_invalid; rel++) {		if (rel->addr == addr		    && (rel->type == R_MIPS_PC16			|| rel->type == R_MIPS_26))			return 1;	}	return 0;}/* convenience functions for labeled branches */static void __init __maybe_unused	il_bltz(u32 **p, struct reloc **r, unsigned int reg, enum label_id l){	r_mips_pc16(r, *p, l);	i_bltz(p, reg, 0);}static void __init __maybe_unused il_b(u32 **p, struct reloc **r,					     enum label_id l){	r_mips_pc16(r, *p, l);	i_b(p, 0);}static void __init il_beqz(u32 **p, struct reloc **r, unsigned int reg,		    enum label_id l){	r_mips_pc16(r, *p, l);	i_beqz(p, reg, 0);}static void __init __maybe_unusedil_beqzl(u32 **p, struct reloc **r, unsigned int reg, enum label_id l){	r_mips_pc16(r, *p, l);	i_beqzl(p, reg, 0);}static void __init il_bnez(u32 **p, struct reloc **r, unsigned int reg,		    enum label_id l){	r_mips_pc16(r, *p, l);	i_bnez(p, reg, 0);}static void __init il_bgezl(u32 **p, struct reloc **r, unsigned int reg,		     enum label_id l){	r_mips_pc16(r, *p, l);	i_bgezl(p, reg, 0);}static void __init __maybe_unusedil_bgez(u32 **p, struct reloc **r, unsigned int reg, enum label_id l){	r_mips_pc16(r, *p, l);	i_bgez(p, reg, 0);}/* The only general purpose registers allowed in TLB handlers. */#define K0		26#define K1		27/* Some CP0 registers */#define C0_INDEX	0, 0#define C0_ENTRYLO0	2, 0#define C0_TCBIND	2, 2#define C0_ENTRYLO1	3, 0#define C0_CONTEXT	4, 0#define C0_BADVADDR	8, 0#define C0_ENTRYHI	10, 0#define C0_EPC		14, 0#define C0_XCONTEXT	20, 0#ifdef CONFIG_64BIT# define GET_CONTEXT(buf, reg) i_MFC0(buf, reg, C0_XCONTEXT)#else# define GET_CONTEXT(buf, reg) i_MFC0(buf, reg, C0_CONTEXT)#endif/* The worst case length of the handler is around 18 instructions for * R3000-style TLBs and up to 63 instructions for R4000-style TLBs. * Maximum space available is 32 instructions for R3000 and 64 * instructions for R4000. * * We deliberately chose a buffer size of 128, so we won't scribble * over anything important on overflow before we panic. */static __initdata u32 tlb_handler[128];/* simply assume worst case size for labels and relocs */static __initdata struct label labels[128];static __initdata struct reloc relocs[128];/* * The R3000 TLB handler is simple. */static void __init build_r3000_tlb_refill_handler(void){	long pgdc = (long)pgd_current;	u32 *p;	int i;	memset(tlb_handler, 0, sizeof(tlb_handler));	p = tlb_handler;	i_mfc0(&p, K0, C0_BADVADDR);	i_lui(&p, K1, rel_hi(pgdc)); /* cp0 delay */	i_lw(&p, K1, rel_lo(pgdc), K1);	i_srl(&p, K0, K0, 22); /* load delay */	i_sll(&p, K0, K0, 2);	i_addu(&p, K1, K1, K0);	i_mfc0(&p, K0, C0_CONTEXT);	i_lw(&p, K1, 0, K1); /* cp0 delay */	i_andi(&p, K0, K0, 0xffc); /* load delay */	i_addu(&p, K1, K1, K0);	i_lw(&p, K0, 0, K1);	i_nop(&p); /* load delay */	i_mtc0(&p, K0, C0_ENTRYLO0);	i_mfc0(&p, K1, C0_EPC); /* cp0 delay */	i_tlbwr(&p); /* cp0 delay */	i_jr(&p, K1);	i_rfe(&p); /* branch delay */	if (p > tlb_handler + 32)		panic("TLB refill handler space exceeded");	pr_info("Synthesized TLB refill handler (%u instructions).\n",		(unsigned int)(p - tlb_handler));	pr_debug("\t.set push\n");	pr_debug("\t.set noreorder\n");	for (i = 0; i < (p - tlb_handler); i++)		pr_debug("\t.word 0x%08x\n", tlb_handler[i]);	pr_debug("\t.set pop\n");	memcpy((void *)ebase, tlb_handler, 0x80);}/* * The R4000 TLB handler is much more complicated. We have two * consecutive handler areas with 32 instructions space each. * Since they aren't used at the same time, we can overflow in the * other one.To keep things simple, we first assume linear space, * then we relocate it to the final handler layout as needed. */static __initdata u32 final_handler[64];/* * Hazards * * From the IDT errata for the QED RM5230 (Nevada), processor revision 1.0: * 2. A timing hazard exists for the TLBP instruction. * *      stalling_instruction *      TLBP * * The JTLB is being read for the TLBP throughout the stall generated by the * previous instruction. This is not really correct as the stalling instruction * can modify the address used to access the JTLB.  The failure symptom is that * the TLBP instruction will use an address created for the stalling instruction * and not the address held in C0_ENHI and thus report the wrong results. * * The software work-around is to not allow the instruction preceding the TLBP * to stall - make it an NOP or some other instruction guaranteed not to stall. * * Errata 2 will not be fixed.  This errata is also on the R5000. * * As if we MIPS hackers wouldn't know how to nop pipelines happy ... */static __init void __maybe_unused build_tlb_probe_entry(u32 **p){	switch (current_cpu_type()) {	/* Found by experiment: R4600 v2.0 needs this, too.  */	case CPU_R4600:	case CPU_R5000:	case CPU_R5000A:	case CPU_NEVADA:		i_nop(p);		i_tlbp(p);		break;	default:		i_tlbp(p);		break;	}}/* * Write random or indexed TLB entry, and care about the hazards from * the preceeding mtc0 and for the following eret. */enum tlb_write_entry { tlb_random, tlb_indexed };static __init void build_tlb_write_entry(u32 **p, struct label **l,					 struct reloc **r,					 enum tlb_write_entry wmode){	void(*tlbw)(u32 **) = NULL;	switch (wmode) {	case tlb_random: tlbw = i_tlbwr; break;	case tlb_indexed: tlbw = i_tlbwi; break;	}	switch (current_cpu_type()) {	case CPU_R4000PC:	case CPU_R4000SC:	case CPU_R4000MC:	case CPU_R4400PC:	case CPU_R4400SC:	case CPU_R4400MC:		/*		 * This branch uses up a mtc0 hazard nop slot and saves		 * two nops after the tlbw instruction.		 */		il_bgezl(p, r, 0, label_tlbw_hazard);		tlbw(p);		l_tlbw_hazard(l, *p);		i_nop(p);		break;	case CPU_R4600:	case CPU_R4700:	case CPU_R5000:	case CPU_R5000A:		i_nop(p);		tlbw(p);		i_nop(p);		break;	case CPU_R4300:	case CPU_5KC:	case CPU_TX49XX:	case CPU_AU1000:	case CPU_AU1100:	case CPU_AU1500:	case CPU_AU1550:	case CPU_AU1200:	case CPU_PR4450:		i_nop(p);		tlbw(p);		break;	case CPU_R10000:	case CPU_R12000:	case CPU_R14000:	case CPU_4KC:	case CPU_SB1:	case CPU_SB1A:	case CPU_4KSC:	case CPU_20KC:	case CPU_25KF:	case CPU_BCM3302:	case CPU_BCM4710:	case CPU_LOONGSON2:		if (m4kc_tlbp_war())			i_nop(p);		tlbw(p);		break;	case CPU_NEVADA:		i_nop(p); /* QED specifies 2 nops hazard */		/*		 * This branch uses up a mtc0 hazard nop slot and saves		 * a nop after the tlbw instruction.		 */		il_bgezl(p, r, 0, label_tlbw_hazard);		tlbw(p);		l_tlbw_hazard(l, *p);		break;	case CPU_RM7000:		i_nop(p);		i_nop(p);		i_nop(p);		i_nop(p);		tlbw(p);		break;	case CPU_4KEC:	case CPU_24K:	case CPU_34K:	case CPU_74K:		i_ehb(p);		tlbw(p);		break;	case CPU_RM9000:		/*		 * When the JTLB is updated by tlbwi or tlbwr, a subsequent		 * use of the JTLB for instructions should not occur for 4		 * cpu cycles and use for data translations should not occur		 * for 3 cpu cycles.		 */		i_ssnop(p);		i_ssnop(p);		i_ssnop(p);		i_ssnop(p);		tlbw(p);		i_ssnop(p);		i_ssnop(p);		i_ssnop(p);		i_ssnop(p);		break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -