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

📄 r4xx0.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	unsigned long daddr, iaddr;	daddr = addr & ~(dc_lsize - 1);	__asm__ __volatile__("nop;nop;nop;nop");	/* R4600 V1.7 */	protected_writeback_dcache_line(daddr);	protected_writeback_dcache_line(daddr + dc_lsize);	iaddr = addr & ~(ic_lsize - 1);	protected_flush_icache_line(iaddr);	protected_flush_icache_line(iaddr + ic_lsize);}static void r4600v20k_flush_cache_sigtramp(unsigned long addr){	unsigned long daddr, iaddr;	unsigned int flags;	daddr = addr & ~(dc_lsize - 1);	__save_and_cli(flags);	/* Clear internal cache refill buffer */	*(volatile unsigned int *)KSEG1;	protected_writeback_dcache_line(daddr);	protected_writeback_dcache_line(daddr + dc_lsize);	iaddr = addr & ~(ic_lsize - 1);	protected_flush_icache_line(iaddr);	protected_flush_icache_line(iaddr + ic_lsize);	__restore_flags(flags);}#undef DEBUG_TLB#undef DEBUG_TLBUPDATE#define NTLB_ENTRIES       48  /* Fixed on all R4XX0 variants... */#define NTLB_ENTRIES_HALF  24  /* Fixed on all R4XX0 variants... */void flush_tlb_all(void){	unsigned long flags;	unsigned long old_ctx;	int entry;#ifdef DEBUG_TLB	printk("[tlball]");#endif	save_and_cli(flags);	/* Save old context and create impossible VPN2 value */	old_ctx = (get_entryhi() & 0xff);	set_entryhi(KSEG0);	set_entrylo0(0);	set_entrylo1(0);	BARRIER;	entry = get_wired();	/* Blast 'em all away. */	while(entry < NTLB_ENTRIES) {		set_index(entry);		BARRIER;		tlb_write_indexed();		BARRIER;		entry++;	}	BARRIER;	set_entryhi(old_ctx);	restore_flags(flags);}void flush_tlb_mm(struct mm_struct *mm){	if (mm->context != 0) {		unsigned long flags;#ifdef DEBUG_TLB		printk("[tlbmm<%d>]", mm->context);#endif		save_and_cli(flags);		get_new_mmu_context(mm, asid_cache);		if (mm == current->active_mm)			set_entryhi(mm->context & 0xff);		restore_flags(flags);	}}void flush_tlb_range(struct mm_struct *mm, unsigned long start,				unsigned long end){	if(mm->context != 0) {		unsigned long flags;		int size;#ifdef DEBUG_TLB		printk("[tlbrange<%02x,%08lx,%08lx>]", (mm->context & 0xff),		       start, end);#endif		save_and_cli(flags);		size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;		size = (size + 1) >> 1;		if(size <= NTLB_ENTRIES_HALF) {			int oldpid = (get_entryhi() & 0xff);			int newpid = (mm->context & 0xff);			start &= (PAGE_MASK << 1);			end += ((PAGE_SIZE << 1) - 1);			end &= (PAGE_MASK << 1);			while(start < end) {				int idx;				set_entryhi(start | newpid);				start += (PAGE_SIZE << 1);				BARRIER;				tlb_probe();				BARRIER;				idx = get_index();				set_entrylo0(0);				set_entrylo1(0);				set_entryhi(KSEG0);				BARRIER;				if(idx < 0)					continue;				tlb_write_indexed();				BARRIER;			}			set_entryhi(oldpid);		} else {			get_new_mmu_context(mm, asid_cache);			if (mm == current->active_mm)				set_entryhi(mm->context & 0xff);		}		restore_flags(flags);	}}void flush_tlb_page(struct vm_area_struct *vma, unsigned long page){	if (vma->vm_mm->context != 0) {		unsigned long flags;		int oldpid, newpid, idx;#ifdef DEBUG_TLB		printk("[tlbpage<%d,%08lx>]", vma->vm_mm->context, page);#endif		newpid = (vma->vm_mm->context & 0xff);		page &= (PAGE_MASK << 1);		save_and_cli(flags);		oldpid = (get_entryhi() & 0xff);		set_entryhi(page | newpid);		BARRIER;		tlb_probe();		BARRIER;		idx = get_index();		set_entrylo0(0);		set_entrylo1(0);		set_entryhi(KSEG0);		if(idx < 0)			goto finish;		BARRIER;		tlb_write_indexed();	finish:		BARRIER;		set_entryhi(oldpid);		restore_flags(flags);	}}/* Load a new root pointer into the TLB. */void load_pgd(unsigned long pg_dir){}void pgd_init(unsigned long page){	unsigned long *p = (unsigned long *) page;	int i;	for(i = 0; i < USER_PTRS_PER_PGD; i+=8) {		p[i + 0] = (unsigned long) invalid_pte_table;		p[i + 1] = (unsigned long) invalid_pte_table;		p[i + 2] = (unsigned long) invalid_pte_table;		p[i + 3] = (unsigned long) invalid_pte_table;		p[i + 4] = (unsigned long) invalid_pte_table;		p[i + 5] = (unsigned long) invalid_pte_table;		p[i + 6] = (unsigned long) invalid_pte_table;		p[i + 7] = (unsigned long) invalid_pte_table;	}}#ifdef DEBUG_TLBUPDATEstatic unsigned long ehi_debug[NTLB_ENTRIES];static unsigned long el0_debug[NTLB_ENTRIES];static unsigned long el1_debug[NTLB_ENTRIES];#endif/* We will need multiple versions of update_mmu_cache(), one that just * updates the TLB with the new pte(s), and another which also checks * for the R4k "end of page" hardware bug and does the needy. */void update_mmu_cache(struct vm_area_struct * vma,				 unsigned long address, pte_t pte){	unsigned long flags;	pgd_t *pgdp;	pmd_t *pmdp;	pte_t *ptep;	int idx, pid;	/*	 * Handle debugger faulting in for debugee.	 */	if (current->active_mm != vma->vm_mm)		return;	pid = get_entryhi() & 0xff;#ifdef DEBUG_TLB	if((pid != (vma->vm_mm->context & 0xff)) || (vma->vm_mm->context == 0)) {		printk("update_mmu_cache: Wheee, bogus tlbpid mmpid=%d tlbpid=%d\n",		       (int) (vma->vm_mm->context & 0xff), pid);	}#endif	save_and_cli(flags);	address &= (PAGE_MASK << 1);	set_entryhi(address | (pid));	pgdp = pgd_offset(vma->vm_mm, address);	BARRIER;	tlb_probe();	BARRIER;	pmdp = pmd_offset(pgdp, address);	idx = get_index();	ptep = pte_offset(pmdp, address);	BARRIER;	set_entrylo0(pte_val(*ptep++) >> 6);	set_entrylo1(pte_val(*ptep) >> 6);	set_entryhi(address | (pid));	BARRIER;	if(idx < 0) {		tlb_write_random();	} else {		tlb_write_indexed();	}	BARRIER;	set_entryhi(pid);	BARRIER;	restore_flags(flags);}#if 0static void r4k_update_mmu_cache_hwbug(struct vm_area_struct * vma,				       unsigned long address, pte_t pte){	unsigned long flags;	pgd_t *pgdp;	pmd_t *pmdp;	pte_t *ptep;	int idx;	save_and_cli(flags);	address &= (PAGE_MASK << 1);	set_entryhi(address | (get_entryhi() & 0xff));	pgdp = pgd_offset(vma->vm_mm, address);	tlb_probe();	pmdp = pmd_offset(pgdp, address);	idx = get_index();	ptep = pte_offset(pmdp, address);	set_entrylo0(pte_val(*ptep++) >> 6);	set_entrylo1(pte_val(*ptep) >> 6);	BARRIER;	if(idx < 0)		tlb_write_random();	else		tlb_write_indexed();	BARRIER;	restore_flags(flags);}#endifvoid show_regs(struct pt_regs * regs){	/* Saved main processor registers. */	printk("$0 : %08lx %08lx %08lx %08lx\n",	       0UL, regs->regs[1], regs->regs[2], regs->regs[3]);	printk("$4 : %08lx %08lx %08lx %08lx\n",               regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]);	printk("$8 : %08lx %08lx %08lx %08lx\n",	       regs->regs[8], regs->regs[9], regs->regs[10], regs->regs[11]);	printk("$12: %08lx %08lx %08lx %08lx\n",               regs->regs[12], regs->regs[13], regs->regs[14], regs->regs[15]);	printk("$16: %08lx %08lx %08lx %08lx\n",	       regs->regs[16], regs->regs[17], regs->regs[18], regs->regs[19]);	printk("$20: %08lx %08lx %08lx %08lx\n",               regs->regs[20], regs->regs[21], regs->regs[22], regs->regs[23]);	printk("$24: %08lx %08lx\n",	       regs->regs[24], regs->regs[25]);	printk("$28: %08lx %08lx %08lx %08lx\n",	       regs->regs[28], regs->regs[29], regs->regs[30], regs->regs[31]);	/* Saved cp0 registers. */	printk("epc   : %08lx\nStatus: %08lx\nCause : %08lx\n",	       regs->cp0_epc, regs->cp0_status, regs->cp0_cause);}			void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,				      unsigned long entryhi, unsigned long pagemask){        unsigned long flags;        unsigned long wired;        unsigned long old_pagemask;        unsigned long old_ctx;        save_and_cli(flags);        /* Save old context and create impossible VPN2 value */        old_ctx = (get_entryhi() & 0xff);        old_pagemask = get_pagemask();        wired = get_wired();        set_wired (wired + 1);        set_index (wired);        BARRIER;            set_pagemask (pagemask);        set_entryhi(entryhi);        set_entrylo0(entrylo0);        set_entrylo1(entrylo1);        BARRIER;            tlb_write_indexed();        BARRIER;                set_entryhi(old_ctx);        BARRIER;            set_pagemask (old_pagemask);        flush_tlb_all();            restore_flags(flags);}/* Detect and size the various r4k caches. */static void __init probe_icache(unsigned long config){	icache_size = 1 << (12 + ((config >> 9) & 7));	ic_lsize = 16 << ((config >> 5) & 1);	printk("Primary instruction cache %dkb, linesize %d bytes)\n",	       icache_size >> 10, ic_lsize);}static void __init probe_dcache(unsigned long config){	dcache_size = 1 << (12 + ((config >> 6) & 7));	dc_lsize = 16 << ((config >> 4) & 1);	printk("Primary data cache %dkb, linesize %d bytes)\n",	       dcache_size >> 10, dc_lsize);}/* If you even _breathe_ on this function, look at the gcc output * and make sure it does not pop things on and off the stack for * the cache sizing loop that executes in KSEG1 space or else * you will crash and burn badly.  You have been warned. */static int __init probe_scache(unsigned long config){	extern unsigned long stext;	unsigned long flags, addr, begin, end, pow2;	int tmp;	tmp = ((config >> 17) & 1);	if(tmp)		return 0;	tmp = ((config >> 22) & 3);	switch(tmp) {	case 0:		sc_lsize = 16;		break;	case 1:		sc_lsize = 32;		break;	case 2:		sc_lsize = 64;		break;	case 3:		sc_lsize = 128;		break;	}	begin = (unsigned long) &stext;	begin &= ~((4 * 1024 * 1024) - 1);	end = begin + (4 * 1024 * 1024);	/* This is such a bitch, you'd think they would make it	 * easy to do this.  Away you daemons of stupidity!	 */	save_and_cli(flags);	/* Fill each size-multiple cache line with a valid tag. */	pow2 = (64 * 1024);	for(addr = begin; addr < end; addr = (begin + pow2)) {		unsigned long *p = (unsigned long *) addr;		__asm__ __volatile__("nop" : : "r" (*p)); /* whee... */		pow2 <<= 1;	}	/* Load first line with zero (therefore invalid) tag. */	set_taglo(0);	set_taghi(0);	__asm__ __volatile__("nop; nop; nop; nop;"); /* avoid the hazard */	__asm__ __volatile__("\n\t.set noreorder\n\t"			     ".set mips3\n\t"			     "cache 8, (%0)\n\t"			     ".set mips0\n\t"			     ".set reorder\n\t" : : "r" (begin));	__asm__ __volatile__("\n\t.set noreorder\n\t"			     ".set mips3\n\t"			     "cache 9, (%0)\n\t"			     ".set mips0\n\t"			     ".set reorder\n\t" : : "r" (begin));	__asm__ __volatile__("\n\t.set noreorder\n\t"			     ".set mips3\n\t"			     "cache 11, (%0)\n\t"			     ".set mips0\n\t"			     ".set reorder\n\t" : : "r" (begin));	/* Now search for the wrap around point. */	pow2 = (128 * 1024);	tmp = 0;	for(addr = (begin + (128 * 1024)); addr < (end); addr = (begin + pow2)) {		__asm__ __volatile__("\n\t.set noreorder\n\t"				     ".set mips3\n\t"				     "cache 7, (%0)\n\t"				     ".set mips0\n\t"				     ".set reorder\n\t" : : "r" (addr));		__asm__ __volatile__("nop; nop; nop; nop;"); /* hazard... */		if(!get_taglo())			break;		pow2 <<= 1;	}	restore_flags(flags);	addr -= begin;	printk("Secondary cache sized at %dK linesize %d\n",	       (int) (addr >> 10), sc_lsize);	scache_size = addr;	return 1;}static void __init setup_noscache_funcs(void){	unsigned int prid;	switch(dc_lsize) {	case 16:		_clear_page = r4k_clear_page_d16;		_copy_page = r4k_copy_page_d16;		_flush_cache_all = r4k_flush_cache_all_d16i16;		_flush_cache_mm = r4k_flush_cache_mm_d16i16;		_flush_cache_range = r4k_flush_cache_range_d16i16;		_flush_cache_page = r4k_flush_cache_page_d16i16;		_flush_page_to_ram = r4k_flush_page_to_ram_d16i16;		break;	case 32:		prid = read_32bit_cp0_register(CP0_PRID) & 0xfff0;		if (prid == 0x2010) {			/* R4600 V1.7 */			_clear_page = r4k_clear_page_r4600_v1;			_copy_page = r4k_copy_page_r4600_v1;		} else if (prid == 0x2020) {		/* R4600 V2.0 */			_clear_page = r4k_clear_page_r4600_v2;			_copy_page = r4k_copy_page_r4600_v2;		} else {			_clear_page = r4k_clear_page_d32;			_copy_page = r4k_copy_page_d32;		}		_flush_cache_all = r4k_flush_cache_all_d32i32;		_flush_cache_mm = r4k_flush_cache_mm_d32i32;		_flush_cache_range = r4k_flush_cache_range_d32i32;		_flush_cache_page = r4k_flush_cache_page_d32i32;		_flush_page_to_ram = r4k_flush_page_to_ram_d32i32;		break;	}	_dma_cache_wback_inv = r4k_dma_cache_wback_inv_pc;	_dma_cache_wback = r4k_dma_cache_wback;	_dma_cache_inv = r4k_dma_cache_inv_pc;}static void __init setup_scache_funcs(void){	switch(sc_lsize) {	case 16:		switch(dc_lsize) {		case 16:			_flush_cache_all = r4k_flush_cache_all_s16d16i16;			_flush_cache_mm = r4k_flush_cache_mm_s16d16i16;			_flush_cache_range = r4k_flush_cache_range_s16d16i16;			_flush_cache_page = r4k_flush_cache_page_s16d16i16;			_flush_page_to_ram = r4k_flush_page_to_ram_s16d16i16;			break;		case 32:			panic("Invalid cache configuration detected");		};		_clear_page = r4k_clear_page_s16;		_copy_page = r4k_copy_page_s16;		break;	case 32:		switch(dc_lsize) {		case 16:			_flush_cache_all = r4k_flush_cache_all_s32d16i16;			_flush_cache_mm = r4k_flush_cache_mm_s32d16i16;			_flush_cache_range = r4k_flush_cache_range_s32d16i16;			_flush_cache_page = r4k_flush_cache_page_s32d16i16;			_flush_page_to_ram = r4k_flush_page_to_ram_s32d16i16;			break;		case 32:			_flush_cache_all = r4k_flush_cache_all_s32d32i32;			_flush_cache_mm = r4k_flush_cache_mm_s32d32i32;			_flush_cache_range = r4k_flush_cache_range_s32d32i32;			_flush_cache_page = r4k_flush_cache_page_s32d32i32;			_flush_page_to_ram = r4k_flush_page_to_ram_s32d32i32;			break;		};		_clear_page = r4k_clear_page_s32;		_copy_page = r4k_copy_page_s32;		break;	case 64:		switch(dc_lsize) {		case 16:			_flush_cache_all = r4k_flush_cache_all_s64d16i16;			_flush_cache_mm = r4k_flush_cache_mm_s64d16i16;			_flush_cache_range = r4k_flush_cache_range_s64d16i16;			_flush_cache_page = r4k_flush_cache_page_s64d16i16;			_flush_page_to_ram = r4k_flush_page_to_ram_s64d16i16;			break;		case 32:			_flush_cache_all = r4k_flush_cache_all_s64d32i32;			_flush_cache_mm = r4k_flush_cache_mm_s64d32i32;			_flush_cache_range = r4k_flush_cache_range_s64d32i32;			_flush_cache_page = r4k_flush_cache_page_s64d32i32;			_flush_page_to_ram = r4k_flush_page_to_ram_s64d32i32;			break;		};		_clear_page = r4k_clear_page_s64;		_copy_page = r4k_copy_page_s64;		break;	case 128:		switch(dc_lsize) {		case 16:			_flush_cache_all = r4k_flush_cache_all_s128d16i16;			_flush_cache_mm = r4k_flush_cache_mm_s128d16i

⌨️ 快捷键说明

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