static int cmd_x(char* args){ //扫描内存 int n; char expre[32]; if(args == NULL){ printf("please input arguments\ntype 'help' to get more informations\n"); return 0; } if(sscanf(args,"%d %s",&n,expre) != 2){ printf("wrong arguments\n"); return 0; } bool success = true; hwaddr_t address = expr(expre, &success); if(!success) return 0; int i; for(i = 0;i < n; ++i){ printf("%x:\t",address); int j; for(j = 0;j < 4; ++j){ uint8_t memory = dram_read(address, 8); printf("%02x ",memory); address += 1; } printf("\n"); } return 0; }
uint32_t cache_read_L2(hwaddr_t addr,size_t len){ uint32_t gi; uint32_t t; uint32_t off; uint32_t count; gi=(addr&0x1ffc0)>>6; t=(addr&0xfffc0000)>>18; off=addr&0x3f; if(len==2&&off==(1<<BLOCK_OFFSET)-1) return cache_read_L2(addr,1)+(cache_read_L2(addr+1,1)<<8); else if(len==4&&off==(1<<BLOCK_OFFSET)-1) return cache_read_L2(addr,1)+(cache_read_L2(addr+1,2)<<8)+(cache_read_L2(addr+3,1)<<24); else if(len==4&&off==(1<<BLOCK_OFFSET)-2) return cache_read_L2(addr,2)+(cache_read_L2(addr+2,2)<<16); else if(len==4&&off==(1<<BLOCK_OFFSET)-3) return cache_read_L2(addr,2)+(cache_read_L2(addr+2,1)<<16)+(cache_read_L2(addr+3,1)<<24); else{ for(count=0;count<WAYS;count++){ if(cachemem[gi][count].valid==1&&cachemem[gi][count].tag==t){ if(len==1) return cachemem[gi][count].data[off]; else if(len==2) return cachemem[gi][count].data[off]+(cachemem[gi][count].data[off+1]<<8); else return cachemem[gi][count].data[off]+(cachemem[gi][count].data[off+1]<<8)+(cachemem[gi][count].data[off+2]<<16)+(cachemem[gi][count].data[off+3]<<24); } } load_cache_L2(addr); return dram_read(addr,len); } }
static int cmd_x(char *args) { int N = 0; uint32_t tmpAddr; char *tmpCharP = NULL; tmpCharP = strtok(args, " "); if(tmpCharP) { N = atoi(tmpCharP); } tmpCharP = tmpCharP + strlen(tmpCharP) + 1; if(tmpCharP) { /* if(strlen(tmpCharP) > 1 && tmpCharP[0] == '0' && tmpCharP[1] == 'x') { tmpAddr = 0; int tmpPow = 1; int i = strlen(tmpCharP) - 1; for( ; i > 1; i--) { char c = tmpCharP[i]; if(c >= '0' && c <= '9') c -= '0'; else if(c >= 'a' && c <= 'f') c = c -'a' + 10; else if(c >= 'A' && c <= 'F') c = c - 'A' + 10; else { printf("input Error!\n"); return 0; } tmpAddr += c * tmpPow; tmpPow *= 16; } } else { tmpAddr = atoi(tmpCharP); }*/ bool success; tmpAddr = expr(tmpCharP, &success); printf("N:%d, addr:0x%x\n", N, tmpAddr); int i = 0; for(i = 0; i < N; i++) { printf("the %d line: ", i); //printf("%x\n", hwaddr_read(tmpAddr + i * 4, 4)); printf("%x\n", dram_read(tmpAddr + i * 4, 4)); } } else { printf("Error: input error!!\n"); } return 0; }
void load_cache_L2(hwaddr_t addr){ uint32_t gi; uint32_t t; uint32_t count; int i; gi=(addr&0x1ffc0)>>6; t=(addr&0xfffc0000)>>18; for(count=0;count<WAYS;count++) if(cachemem[gi][count].valid==0) break; if(count==WAYS&&cachemem[gi][count-1].valid==1) count=rand()%WAYS; cachemem[gi][count].tag=t; cachemem[gi][count].valid=1; cachemem[gi][count].dirty=0; for(i=0;i<(1<<BLOCK_OFFSET);i++){ cachemem[gi][count].data[i]=dram_read((addr&0xffffffc0)+i,1); } }