📄 c64388.c
字号:
/************************************************************* * File: lib/c64388.c * Purpose: Init code for 64388 RAP * Author: Phil Bunce (pjb@carmel.com) * Revision History: * 980701 Created from c4011.c * 980730 Added F_MIPS for Crossview * 980730 Fixed the HI reg #. * 980828 Applied outw fix to brkRemove. * 981214 Moved build of dcs value from setbp_target to brkInstall */#ifndef LR64388#define LR64388#endif#include "mips.h"#include <termio.h>#include <terms.h>#include <pmon.h>#define VALID_BIT (1<<1)#define outw(a,v) (*((volatile Ulong *)(a))=(v))#define inw(a) (*((volatile Ulong *)(a)))static Ulong mXccc();static char *c0_regs[] = { "$0", "$1", "$2", "C0_BPC", "$4", "$5", "$6", "C0_DCS", "C0_BADADDR", "C0_COUNT", "$10", "C0_COMPARE", "C0_SR", "C0_CAUSE", "C0_EPC", "C0_PRID", "C0_CONFIG", "C0_LLADR", "C0_BPC", "C0_BDA", "C0_BPCM", "C0_BDAM", "$22", "C0_ROTATE", "C0_CMASK", "$25", "$26", "$27", "$28", "$29", "C0_ERREPC", "$31" };static RegSpec CCCreg[] = { {1,28,"EWP",2,0,0}, {1,26,"ISR1",2,0,0}, {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}};static RegSpec 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}};static RegRec 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 ------------------------*/ {mXccc,CCCreg,"C0_CCC","CCC",C0_CCC,0}, {mXc0,DCSreg,"C0_DCS","DCS",C0_DCS,0}, {mXc0,0,"C0_BPC","BPC",18,0}, {mXc0,0,"C0_BDA","BDA",19,0}, {mXc0,0,"C0_BPCM","BPCM",20,0}, {mXc0,0,"C0_BDAM","BDAM",21,0}, {mXc0,0,"C0_COUNT","COUNT",C0_COUNT,0}, {mXc0,0,"C0_COMPARE","COMPARE",C0_COMPARE,0}, {mXc0,0,"C0_LLADR","LLADR",C0_LLADR,0}, {mXc0,0,"C0_ROTATE","ROTATE",C0_ROTATE,0}, {mXc0,0,"C0_CMASK","CMASK",C0_CMASK,0}, {mXc0,0,"C0_ERREPC","ERREPC",C0_ERREPC,0}, {0}};int do_cache401x();extern Optdesc cache_opts401x[];int rpr_cmd();extern Optdesc rpr_opts[];static CmdRec cmds[] = { {"cache",cache_opts401x,do_cache401x}, {"rpr",rpr_opts,rpr_cmd}, {0}};static int setbp_target(),brkInstall(),brkRemove();static int hwibReq();extern int iflush_needed,dflush_needed;extern int icache_size,dcache_size,cache_line_size;int iceport();static struct iceportinfo iceportdat = {0xb0ff0000};int p16550u();/************************************************************** c64388init(type)*/c64388init(type)int type;{int cf,i;Ulong modVal,avgVal;char tmp[10];switch (type) { case 0 : /* hostInit(0) */ break; case 1 : /* */ break; case 2 : /* cpuInit(2) */ c0regNames = c0_regs; for (i=0;reglist[i].func;i++) addRegRec(®list[i]); for (i=0;cmds[i].name;i++) addCmdRec(&cmds[i]); icache_size = 8*1024; cache_line_size = 32; brkInstall_ptr = brkInstall; brkRemove_ptr = brkRemove; setbp_target_ptr = setbp_target; avgVal = getRAPClkFreq(); /* round up if necessary */ modVal = avgVal%1000000; if(modVal >= 500000) avgVal = (avgVal/1000000) + 1; else avgVal = avgVal/1000000; sprintf(tmp,"%d",avgVal); setenv("clkfreq",tmp); break; case 3 : /* hostInit(3) extra memory */ break; case 4 : /* hostInit(4) */#ifdef NVRAM nvInfo.start = 0xb8000000; nvInfo.width = 1; nvInfo.gap = 1; nvInfo.nvbase = 0; #endif break; case 5 : /* hostInit(5) */#if defined(ETHERNET) && defined(MIPSEB) re_ether = 1;#endif break; case 6 : break; case 7 : /* hostInit(7) */#ifdef NVRAM nvInfo.start = 0xb8100000;#endif break; case 8 : addDevice(0xb0008600,0,p16550u,1024,DEFBAUD);#ifdef ETHERNET ether_driver_ptr = sonic_driver;#endif break; }}/************************************************************** Ulong mXccc(write,reg,size,value)* must copy-back the dcache before changing CCC_WB bit. * For simplicity I do it for all writes to the CCC reg.*/static Ulong 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); sw2kseg1(); write_target(XT_CP0,reg,value); }}/************************************************************** 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 0printf("setbp_target(%d,%d,%08x,%08x,%08x)\n",n,type,addr,addr2,value);#endifatype = 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)) method = BRK_METHOD_RAM; else if (IS_K0SEG(addr) && ilockReq401x(addr)) method = BRK_METHOD_ROM; else if (hwibReq(addr)) { 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);}/************************************************************** brkInstall(type)* type=1 install regular+temp bpts* type=2 install trace bpts*/static brkInstall(type)int type;{int i,flag;Ulong dcs,tag,vmask,addr;if (verbose) printf("\nbrkInstall(%d)\n",type);flag = 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 (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) printf("installing ram bpt at %08x\n",addr); brkList[i].val = read_target(XT_MEM,addr,4); outw(addr,BPT_CODE); iflush_needed = dflush_needed = 1; flush_target(ICACHE); flush_target(DCACHE); brkList[i].isset = 1; break; case BRK_METHOD_ROM : if (verbose) printf("installing rom bpt at %08x\n",addr); if (!flag) flush_target(ICACHE); flag = 1; if (!(readCache401x(1,ICACHETAG,addr)&VALID_BIT)) initIsp401x(addr); wrIsp401x(addr,BPT_CODE); brkList[i].isset = 1; break; case BRK_METHOD_HW : dcs = read_target(XT_CP0,DBX_DCS,0); if (brkList[i].type == BPTYPE_DATA) { if (verbose) printf("installing hwdb bpt at %08x\n",addr); write_target(XT_CP0,DBX_BDA,addr); write_target(XT_CP0,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 { if (verbose) printf("installing hwib bpt at %08x\n",addr); write_target(XT_CP0,DBX_BPC,addr); write_target(XT_CP0,DBX_BPCM,brkList[i].mask); dcs |= DCS_TR|DCS_UD|DCS_KD|DCS_DE|DCS_PCE; } write_target(XT_CP0,DBX_DCS,dcs); brkList[i].isset = 1; break; default : printf("%d: error bad method\n",brkList[i].method); return(-1); } }}/************************************************************** int brkRemove(epc)* returns type: 0=none 1=bpc 2=bda 3=itemp 4=sstep*/static int brkRemove(epc)Ulong epc;{int i,type,flag;Ulong ccc;type = flag = 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 : outw(brkList[i].addr,brkList[i].val); iflush_needed = dflush_needed = 1; flush_target(ICACHE); flush_target(DCACHE); break; case BRK_METHOD_ROM : if (!flag) { ccc = read_target(XT_CP0,C0_CCC,0); write_target(XT_CP0,C0_CCC,ccc&~CCC_ISR1); iflush_needed=1; flush_target(ICACHE); flag = 1; } break; case BRK_METHOD_HW : write_target(XT_CP0,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);}/************************************************************** Command to execute code out of RAM.*/ Optdesc rpr_opts[] = { {"","Relocate PMON to RAM"}, {0}};rpr_cmd(int ac,char *av[]){ if (((*((Ulong *)0xB0008400)) & 0x7FF) == 0x600) { printf("Relocating PMON code from 0x%x to 0x80040000\n\n", FTEXT); memcpy((unsigned char *)0x80040000, (unsigned char *)FTEXT, 0x40000); flush_cache(DCACHE); flush_cache(ICACHE); *((Ulong *)0xB0008400) = 1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -