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

📄 c64008.c

📁 mips架构的bootloader,99左右的版本 但源代码现在没人更新了
💻 C
字号:
/************************************************************* * File: lib/c64008.c * Purpose: Part of C runtime library * Author: Phil Bunce (pjb@carmel.com) * Revision History: *	970304	Start of revision history *	971115	Added code to set re_sonic for LE *	980615	Renamed re_sonic re_ether *	980616	Added "case 8" devinit. *	980730	Added F_MIPS for Crossview. *	980730	Fixed the HI reg #. *	980826	Added defs for outw and outh *	981107	Fixed typo for build when CLKFREQ is defined *	981214	Moved build of dcs value from setbp_target to brkInstall */#ifndef LR64008#define LR64008#endif#include <pmon.h>#include <termio.h>#include <terms.h>#define outw(a,v)	(*((volatile Ulong *)(a))=(v))#define outh(a,v)	(*((volatile Ushort *)(a))=(v))char *c64008_c0regs[] = {	"$0",     "$1",  "$2",  "$3",  	"$4",   "$5",  "$6", "C0_DCS", 	"C0_BADADDR", "C0_COUNT", "$10",  "$11", 	"C0_SR",      "C0_CAUSE", "C0_EPC",    "C0_PRID",	"$16",  "$17", "$18",    "$19", 	"$20",    "$21",  "$22",       "$23",	"$24", "$25", "$26", "$27", "$28", "$29", "C0_ERREPC", "$31"	};RegSpec c64008_cccreg[] = {	{1,25,"EVI",2,0,0},	{1,24,"CMP",2,0,0},	{1,23,"IIE",2,0,0},	{1,22,"DIE",2,0,0},	{1,21,"MUL",2,0,0},	{1,20,"MAD",2,0,0},	{1,19,"TMR",2,0,0},	{1,18,"BGE",2,0,0},	{1,17,"IE0",2,0,0},	{1,16,"IE1",2,0,0},	{2,14,"IS",10,0,0},	{1,13,"DE0",2,0,0},	{1,12,"DE1",2,0,0},	{2,10,"DS",10,0,0},	{1,9,"IPWE",2,0,0},	{2,7,"IPWS",10,0,0},	{1,6,"TE",2,0,0},	{1,5,"WB",2,0,0},	{1,4,"SR0",2,0,0},	{1,3,"SR1",2,0,0},	{1,2,"ISC",2,0,0},	{1,1,"TAG",2,0,0},	{1,0,"INV",2,0,0},	{0}};#if 0RegSpec c64008_dcsreg[] = {	{1,31,"TR",2,0,0},	{1,30,"UD",2,0,0},	{1,29,"KD",2,0,0},	{1,28,"TE",2,0,0},	{1,27,"DW",2,0,0},	{1,26,"DR",2,0,0},	{1,25,"DAE",2,0,0},	{1,24,"PCE",2,0,0},	{1,23,"DE",2,0,0},	{1,5,"T",2,0,0},	{1,4,"W",2,0,0},	{1,3,"R",2,0,0},	{1,2,"DA",2,0,0},	{1,1,"PC",2,0,0},	{1,0,"DB",2,0,0},	{0}};#endifint p8251();static struct p8251info tty0dat = {(Uchar *)l08_sio};static int brkInstall(),setbp_target(),brkRemove(),hwibReq();extern int dcache_size,icache_size,cache_line_size;static int measureFreq();/************************************************************** mXccc(write,reg,size,value)* 	must copy-back the dcache before changing BBCC_WB bit. * 	For simplicity I do it for all writes to the BBC reg.*/static mXccc(write,reg,size,value)int write,reg,size,value;{if (write == 0) /* read */ return(read_target(XT_CP0,reg,0));else {	flush_target(DCACHE);	write_target(XT_CP0,reg,value,0);	}}RegRec c64008_reglist[] = {	{mXpc,0,"PC","pc",14,(F_MIPS|F_CPU)},	{mXgpr,0,"HI","HI",32,(F_CPU|F_MIPS)},	{mXgpr,0,"LO","LO",33,(F_CPU|F_MIPS)},	/* ========== cp0 ========== */	{mXc0,mips_sr_def,"C0_SR","SR",12,(F_CP0|F_MIPS)},	{mXc0,mips_cause_def,"C0_CAUSE","CAUSE",13,(F_CP0|F_MIPS)},	{mXc0,mips_prid_def,"C0_PRID","PRID",15,(F_CP0|F_RO|F_MIPS)},	{mXc0,0,"C0_EPC","EPC",14,(F_CP0|F_MIPS)},	{mXc0,0,"C0_BADVA","BADVA",8,(F_CP0|F_MIPS)},/*--------- end of basic MIPS stuff ------------------------*/	{mXmem,c64008_cccreg,"M_BBCC","BBCC",M_08_BBCC,0},	{0}};#ifndef PMCCa64008init(type) { c64008init(type); }#endifc64008init(type)int type;{int i,cf;switch (type) {	case 1 : 		break;	case 2 :                c0regNames = c64008_c0regs;                for (i=0;c64008_reglist[i].func;i++) {                        addRegRec(&c64008_reglist[i]);                        }		icache_size = 2*1024;		dcache_size = 2*1024;		cache_line_size = 16;		brkInstall_ptr = brkInstall;		brkRemove_ptr = brkRemove;		setbp_target_ptr = setbp_target;		if ((cf=measureFreq())==0) cf = 54; /* default */		setdMonEnv("clkfreq",cf);		break;	case 3 : /* extra memory */ break;	case 4 : /* nvInfo */#ifdef PMCC		nvInfo.gap = 1;		nvInfo.width = 1;		nvInfo.nvbase = 0;		nvInfo.start = 0xa0000000;		break;#endif	case 5 :#if defined(ETHERNET) && !defined(MIPSEB)		re_ether = 1;#endif		break;	case 8 :		addDevice((Addr)&tty0dat,0,p8251,1024,DEFBAUD);		addDevice((Addr)&tty0dat,1,p8251,1024,DEFBAUD);		addDevice((Addr)&tty0dat,2,p8251,1024,DEFBAUD);#ifdef ETHERNET		ether_driver_ptr = sonic_driver;#endif		break;	}}/**************************************************************/static int measureFreq(){#ifdef CLKFREQreturn CLKFREQ; /* 981107 */#endifreturn(0);}/**************************************************************  static int setbp_target(n,type,addr,addr2,value)*       type: 1=bpc 2=bda 3=itemp 4=sstep 5=nonrt*       returns bp number, or -1 on error.*	addr2 and value are only used for BPTYPE_DATA.*	In the case of BPTYPE_DATA the access type (r/w) is encoded*	in the 2nd nibble of 'type';*/static int setbp_target(n,type,addr,addr2,value)int n,type;Ulong addr,addr2,value;{int i,method,atype,code;Ulong info;long mask; /* must be signed */ if (verbose) fprintf(dfp,"setbp_target(%d,%d,%08x,%08x,%08x)\n",		n,type,addr,addr2,value);atype = type>>4;type &= 0xf;code = 0;if (type == BPTYPE_NONRT) {        printf("Warning: This breakpoint requires non real-time execution.\n");        }else if (type == BPTYPE_PC || type == BPTYPE_ITMP || type == BPTYPE_TRACE) {        if (is_writeable_target(addr)) {		if (verbose) fprintf(dfp,"is writeable\n");		method = BRK_METHOD_RAM;		}        else if (IS_K0SEG(addr) && ilockReq400x(addr)) {		if (verbose) fprintf(dfp,"ilock avail\n");		method = BRK_METHOD_ROM;		}        else if (hwibReq(addr)) {		if (verbose) fprintf(dfp,"hwib avail\n");		method = BRK_METHOD_HW;		mask = 0xffffffff;		}        else {                printf("%08x: can't set bpt\n",addr);                return(0-BP_E_ERR);                }        }else if (type == BPTYPE_DATA) {	method = BRK_METHOD_HW;	info = 0;	if (atype&1) info |= 2;	if (atype&2) info |= 1;	if (atype&4) return(0-BP_E_VAL);	if (addr2) { /* compute mask */		for (mask=0x80000000;(addr&mask) == (addr2&mask);mask>>=1) ;		mask <<= 1; /* oops! one step too many */		code |= BP_W_MSK;		}	else mask = 0xffffffff; /* all-enable */	}if (n == -1) {        for (i=0;i<MAX_BPT;i++) if (brkList[i].type == 0) break;        if (i >= MAX_BPT) {                printf("Fatal error: out of bpts\n");                return(0-BP_E_ERR);                }        n = i;        }if (n < 0 || n >= MAX_BPT) {        printf("%d: bad bpt number\n",n);        return(0-BP_E_ERR);        }brkList[n].type = type;brkList[n].addr = addr;brkList[n].method = method;brkList[n].mask = mask;brkList[n].aux[0] = info;brkList[n].isset = 0;return((code<<16)|n);}/**************************************************************  static int brkInstall(type)*	type=1 install regular+temp bpts*	type=2 install trace bpts*/static int brkInstall(type)int type;{int i,flag;Ulong dcs,tag,vmask,addr,cfg;if (verbose) fprintf(dfp,"brkInstall(%d)\n",type);for (i=0;i<MAX_BPT;i++) {	/* first discard the entries we aren't going to handle */	if (brkList[i].type==0) continue;	if (type == 1 && brkList[i].type == BPTYPE_TRACE) continue;	if (type == 2 && brkList[i].type != BPTYPE_TRACE) continue;	addr = brkList[i].addr;	switch (brkList[i].method) {	    case BRK_METHOD_RAM :		if (verbose) fprintf(dfp,"installing ram bpt at %08x\n",addr);		if (addr&1) {			addr &= ~1;			brkList[i].val = read_target(XT_MEM,addr,2);			outh(addr,TINY_BPT_CODE);			}		else {			brkList[i].val = read_target(XT_MEM,addr,4);			outw(addr,BPT_CODE);			}		iflush_needed = 1;		brkList[i].isset = 1;		break;	    case BRK_METHOD_ROM :		if (verbose) fprintf(dfp,"installing rom bpt at %08x\n",addr);		cfg = read_target(XT_MEM,M_CFG4001,4);		if ((cfg&CFG_ISIZEMASK) == CFG_ISIZE_8) { /* 970709 */			/* handle the irefillsz=8 case */			wrrombp4101(addr);			}		else {			vmask = 1<<((addr>>2)&3);			writeLockedBpt400x(addr,vmask);			}		brkList[i].isset = 1;		break;	    case BRK_METHOD_HW :	if (verbose) fprintf(dfp,"installing hwbpt a=%08x m=%08x aux[0]=%08x\n",			addr,brkList[i].mask,brkList[i].aux[0]);		dcs = read_target(XT_DBX,DBX_DCS,0);		if (brkList[i].type==BPTYPE_DATA) {			write_target(XT_DBX,DBX_BDA,addr);			write_target(XT_DBX,DBX_BDAM,brkList[i].mask);			dcs |= DCS_TR|DCS_UD|DCS_KD|DCS_DE|DCS_DAE;			if (brkList[i].aux[0]&2) dcs |= DCS_DR;			if (brkList[i].aux[0]&1) dcs |= DCS_DW;			}		else {			write_target(XT_DBX,DBX_BPC,addr);			write_target(XT_DBX,DBX_BPCM,brkList[i].mask);			dcs |= DCS_TR|DCS_UD|DCS_KD|DCS_DE|DCS_PCE;			}		write_target(XT_DBX,DBX_DCS,dcs);		brkList[i].isset = 1;		break;	    default : 		printf("%d: error bad method\n",brkList[i].method);		return(-1);	    }	}}/**************************************************************  static int brkRemove(epc)*	returns type: 0=none 1=bpc 2=bda 3=itemp 4=sstep*/static int brkRemove(epc)Ulong epc;{int i,type;Ulong addr;type = 0;for (i=0;i<MAX_BPT;i++) {	/* first discard the entries we aren't going to handle */	if (brkList[i].type==0) continue;	if (brkList[i].isset==0) continue;	if (epc == brkList[i].addr) type = brkList[i].type;	switch (brkList[i].method) {	    case BRK_METHOD_RAM :		addr = brkList[i].addr;		if (addr&1) outh(addr&~1,brkList[i].val);		else outw(addr,brkList[i].val);		iflush_needed = 1;		break;	    case BRK_METHOD_ROM :		writeCache400x(0,ICACHETAG,brkList[i].addr,0);#if 0		/* handle the irefillsz==8 case */		if ((read_target(XT_MEM,M_CFG4001,4)&CFG_ISIZEMASK)==CFG_ISIZE_8) {			addr = brkList[i].addr;			if (addr&0x10) writeCache400x(0,ICACHETAG,addr&~0x10,0);			else writeCache400x(0,ICACHETAG,addr|0x10,0);			}#endif		break;	    case BRK_METHOD_HW :		write_target(XT_DBX,DBX_DCS,0);		break;	    }	if (brkList[i].type == BPTYPE_ITMP) brkList[i].type = 0;	if (brkList[i].type == BPTYPE_TRACE) brkList[i].type = 0;	}return(type);}/**************************************************************  static hwibReq(addr)*       verify that other hw ibpts don't conflict with this one.*       i.e. More than one.*/static hwibReq(addr)Ulong addr;{int i,n;n = 0;for (i=0;i<MAX_BPT;i++) {        if (brkList[i].type==0) continue;        if (brkList[i].method != BRK_METHOD_HW) continue;        if (brkList[i].type == BPTYPE_DATA) continue;        n++;        }   if (n > 0) return(0);return(1);}

⌨️ 快捷键说明

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