/********************************************************************* * ターゲット側メモリーを逆アセンブルする. ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) * int cnt :読み取りサイズ. */ int UsbDisasm (int adr, int arena, int cnt) { unsigned char buf[16]; int size = 8; int done = 0; int endadr = adr + cnt; int rc,disbytes; code_buf_init(); while(adr < endadr) { int rsize = check_region(adr,4); if( rsize < 0) break; #if USE_CODE_BUF rc = code_buf_read(adr,size,buf); //メモリー内容の読み出し. #else rc = dumpmem(adr,AREA_PGMEM,size,buf); //メモリー内容の読み出し. #endif if(rc != size) return done; disbytes = disasm_print(buf,size,adr); //結果印字. adr += disbytes; done+= disbytes; } return done; }
static int ui_cmd_memdump(ui_cmdline_t *cmd,int argc,char *argv[]) { long addr; int res; getaddrargs(cmd,&prev_wtype,&prev_addr,&prev_length); addr = prev_addr; if ((prev_wtype & ATYPE_TYPE_MASK) == ATYPE_TYPE_PHYS) { addr = UNCADDR(addr); } res = dumpmem(addr, prev_addr, prev_length, prev_wtype & ATYPE_SIZE_MASK); if (res < 0) { ui_showerror(res,"Could not display memory"); } else { prev_addr += prev_length; } return res; }
void cmdFlash(char *buf) { unsigned char buf2[10240]; int size=128; int n = get_arg(buf); //引数の数. if( n != 0 ) { size = arg_val[0]; } if(size) { dumpmem(0x1000,0,size,buf2); } #if 0 unsigned char data[128]; int size = 32; int n = get_arg(buf); //引数の数. if(n != 0) { int i; for(i=0;i<64;i++) data[i]=i; UsbFlash(adrs,AREA_PGMEM,data,size); } #endif }
/********************************************************************* * ターゲット側メモリーをダンプする. ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) * int cnt :読み取りサイズ. */ void UsbDump(int adr,int arena,int cnt) { unsigned char buf[16]; int size; int rc; while(cnt) { size = cnt; if(size>=16) size = 16; rc = dumpmem(adr,arena,size,buf); //メモリー内容の読み出し. if(rc !=size) return; memdump_print(buf,size,adr); //結果印字. adr += size; cnt -= size; } }
/********************************************************************* * ターゲット側メモリーを逆アセンブルする. ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) * int cnt :読み取りサイズ. */ int UsbDisasm (int adr, int arena, int cnt) { unsigned char buf[16]; int size = 8; int done = 0; int endadr = adr + cnt; int rc,disbytes; while(adr < endadr) { rc = dumpmem(adr,AREA_PGMEM,size,buf); //メモリー内容の読み出し. if(rc != size) return done; disbytes = disasm_print(buf,size,adr); //結果印字. adr += disbytes; done+= disbytes; } return done; }
void regdump(int *rp /* must not be register */, int sbytes) { static int doingdump = 0; int i; int s; if (doingdump) return; s = splhigh(); doingdump = 1; /* printf("pid = %d, pc = %s, ", u.u_procp->p_pid, hexstr(rp[PC], 8)); */ printf("pc = %s, ", hexstr(rp[PC], 8)); printf("ps = %s, ", hexstr(rp[PS], 4)); printf("sfc = %s, ", hexstr(getsfc(), 4)); printf("dfc = %s\n", hexstr(getdfc(), 4)); /* printf("p0 = %x@%s, ", u.u_pcb.pcb_p0lr, hexstr((int)u.u_pcb.pcb_p0br, 8)); printf("p1 = %x@%s\n\n", u.u_pcb.pcb_p1lr, hexstr((int)u.u_pcb.pcb_p1br, 8)); */ printf("Registers:\n "); for (i = 0; i < 8; i++) printf(" %d", i); printf("\ndreg:"); for (i = 0; i < 8; i++) printf(" %s", hexstr(rp[i], 8)); printf("\nareg:"); for (i = 0; i < 8; i++) printf(" %s", hexstr(rp[i+8], 8)); if (sbytes > 0) { /* if (rp[PS] & PSL_S) { */ printf("\n\nKernel stack (%s):", hexstr((int)(((int *)&rp)-1), 8)); dumpmem(((int *)&rp)-1, sbytes, 0); /* } else { printf("\n\nUser stack (%s):", hexstr(rp[SP], 8)); dumpmem((int *)rp[SP], sbytes, 1); } */ } doingdump = 0; splx(s); }
/********************************************************************* * ターゲット側メモリー連続読み出し ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) * uchar *buf :読み取りバッファ. * int size :読み取りサイズ. *戻り値 * -1 : 失敗 * 正の値: 成功. */ int UsbRead(int adr,int arena,uchar *buf,int size) { int rc = size; int len; while(size) { len = size; if(len >= 8) len = 8; int rc = dumpmem(adr,arena,len,buf); if( rc!= len) { return -1; } adr += len; // ターゲットアドレスを進める. buf += len; // 読み込み先バッファを進める. size -= len; // 残りサイズを減らす. } return rc; }
/********************************************************************* * ターゲット側メモリーをダンプする. ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) * int cnt :読み取りサイズ. */ void UsbDump(int adr,int arena,int cnt) { unsigned char buf[16]; int size; int rc,rsize; while(cnt) { size = cnt; if(size>=16) size = 16; rsize = check_region(adr,size); if( rsize <= 0) break; rc = dumpmem(adr,arena,rsize,buf); //メモリー内容の読み出し. memdump_print(buf,rsize,adr); //結果印字. adr += size; cnt -= size; } }
int main(void) { init(1024); dumpmem(); void *a = smalloc(sizeof(int)); dumpmem(); void *b = smalloc(3); dumpmem(); void *c = smalloc(3); dumpmem(); sfree(c); dumpmem(); sfree(b); dumpmem(); sfree(a); dumpmem(); unsigned int *d = (unsigned int*) a; printf("%u\n", *d); }
void dumppkt(void) { uint8_t *a = uip_buf; DC('e');DC(' '); DU(uip_len,5); display_channel &= ~DISPLAY_TCP; uint8_t ole = log_enabled; log_enabled = 0; DC(' '); DC('d'); DC(' '); display_mac(a); a+= sizeof(struct uip_eth_addr); DC(' '); DC('s'); DC(' '); display_mac(a); a+= sizeof(struct uip_eth_addr); DC(' '); DC('t'); DH2(*a++); DH2(*a++); DNL(); if(eth_debug > 2) dumpmem(a, uip_len - sizeof(struct uip_eth_hdr)); display_channel |= DISPLAY_TCP; log_enabled = ole; }
int main() { SDL_Event ev; SDL_MouseButtonEvent *mbev; SDL_MouseMotionEvent *mmev; SDL_Surface *op_surf, *ind_surf, *extra_surf; SDL_Rect op_panel = { 0, 274, 1280, 210 }; SDL_Rect ind_panel = { 0, 64, 1280, 210 }; SDL_Rect extra_panel = { 0, 0, 1280, 210 }; int i; Light *l; Switch *sw; // void testinst(Apr*); // testinst(&apr); if(SDL_Init(SDL_INIT_VIDEO) < 0){ error: fprintf(stderr, "error: %s\n", SDL_GetError()); return 1; } screen = SDL_SetVideoMode(1280, 484, 32, SDL_DOUBLEBUF); if(screen == NULL) goto error; if((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG){ fprintf(stderr, "error: init SDL_Image: %s\n", IMG_GetError()); return 1; } op_surf = IMG_Load("op_panel.png"); if(op_surf == NULL){ fprintf(stderr, "Couldn't load op_panel.png\n"); return 1; } ind_surf = IMG_Load("ind_panel.png"); if(ind_surf == NULL){ fprintf(stderr, "Couldn't load ind_panel.png\n"); return 1; } extra_surf = IMG_Load("extra_panel.png"); if(extra_surf == NULL){ fprintf(stderr, "Couldn't load extra_panel.png\n"); return 1; } keysurf[0] = IMG_Load("key_n.png"); if(keysurf[0] == NULL){ fprintf(stderr, "Couldn't load key_n.png\n"); return 1; } keysurf[1] = IMG_Load("key_d.png"); if(keysurf[1] == NULL){ fprintf(stderr, "Couldn't load key_d.png\n"); return 1; } keysurf[2] = IMG_Load("key_u.png"); if(keysurf[2] == NULL){ fprintf(stderr, "Couldn't load key_u.png\n"); return 1; } lampsurf[0] = IMG_Load("lamp_off.png"); if(lampsurf[0] == NULL){ fprintf(stderr, "Couldn't load lamp_off.png\n"); return 1; } lampsurf[1] = IMG_Load("lamp_on.png"); if(lampsurf[1] == NULL){ fprintf(stderr, "Couldn't load lamp_on.png\n"); return 1; } switchsurf[0] = IMG_Load("switch_d.png"); if(switchsurf[0] == NULL){ fprintf(stderr, "Couldn't load switch_d.png\n"); return 1; } switchsurf[1] = IMG_Load("switch_u.png"); if(switchsurf[1] == NULL){ fprintf(stderr, "Couldn't load switch_u.png\n"); return 1; } l = op_lights; ir_lght = l; l += 18; mi_lght = l; l += 36; pc_lght = l; l += 18; ma_lght = l; l += 18; pih_lght = l; l += 7; pir_lght = l; l += 7; pio_lght = l; l += 7; rest_lght = l; sw = switches; data_sw = sw; sw += 36; ma_sw = sw; sw += 18; rest_sw = sw; sw += 4; rim_maint_sw = sw; l = ind_lights; mb_lght = l; l += 36; ar_lght = l; l += 36; mq_lght = l; l += 36; fe_lght = l; l += 9; sc_lght = l; l += 9; ff_lght = l; l = extra_lights; membus_lght = l; l += 36; pr_lght = l; l += 8; rlr_lght = l; l += 8; rla_lght = l; for(i = 0; i < nelem(keys); i++){ keys[i].r.x += op_panel.x; keys[i].r.y += op_panel.y; } for(i = 0; i < nelem(op_lights); i++){ op_lights[i].r.x += op_panel.x; op_lights[i].r.y += op_panel.y; } for(i = 0; i < nelem(ind_lights); i++){ ind_lights[i].r.x += ind_panel.x; ind_lights[i].r.y += ind_panel.y; } for(i = 0; i < nelem(extra_lights); i++){ extra_lights[i].r.x += extra_panel.x; extra_lights[i].r.y += extra_panel.y; } for(i = 0; i < nelem(switches)-1; i++){ switches[i].r.x += op_panel.x; switches[i].r.y += op_panel.y; } rim_maint_sw->r.x += extra_panel.x; rim_maint_sw->r.y += extra_panel.y; initmem(); inittty(); memset(&apr, 0xff, sizeof apr); apr.extpulse = 0; /* int frm = 0; time_t tm, tm2; tm = time(nil);*/ for(;;){ /* frm++; tm2 = time(nil); if((tm2 - tm) > 5){ print("fps: %f\n", (float)frm/(tm2-tm)); tm = tm2; frm = 0; } */ // usleep(1000); while(SDL_PollEvent(&ev)) switch(ev.type){ case SDL_MOUSEMOTION: mmev = (SDL_MouseMotionEvent*)&ev; mouse(0, mmev->state, mmev->x, mmev->y); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: mbev = (SDL_MouseButtonEvent*)&ev; mouse(mbev->button, mbev->state, mbev->x, mbev->y); break; case SDL_QUIT: dumpmem(); SDL_Quit(); return 0; case SDL_USEREVENT: print("user\n"); break; } setlights(apr.ir, ir_lght, 18); setlights(apr.mi, mi_lght, 36); setlights(apr.pc, pc_lght, 18); setlights(apr.ma, ma_lght, 18); setlights(apr.pih, pih_lght, 7); setlights(apr.pio, pio_lght, 7); setlights(apr.pir, pir_lght, 7); rest_lght[4].state = apr.run; rest_lght[5].state = apr.mc_stop; rest_lght[6].state = apr.pi_active; rest_lght[0].state = apr.sw_addr_stop = rest_sw[0].state; rest_lght[1].state = apr.sw_repeat = rest_sw[1].state; rest_lght[2].state = apr.sw_mem_disable = rest_sw[2].state; rest_lght[3].state = apr.sw_power = rest_sw[3].state; apr.sw_rim_maint = rim_maint_sw->state; apr.data = getswitches(data_sw, 36); apr.mas = getswitches(ma_sw, 18); apr.key_start = keys[0].state == 1; apr.key_readin = keys[0].state == 2; apr.key_inst_cont = keys[1].state == 1; apr.key_mem_cont = keys[1].state == 2; apr.key_inst_stop = keys[2].state == 1; apr.key_mem_stop = keys[2].state == 2; apr.key_io_reset = keys[3].state == 1; apr.key_exec = keys[3].state == 2; apr.key_dep = keys[4].state == 1; apr.key_dep_nxt = keys[4].state == 2; apr.key_ex = keys[5].state == 1; apr.key_ex_nxt = keys[5].state == 2; apr.key_rd_off = keys[6].state == 1; apr.key_rd_on = keys[6].state == 2; apr.key_pt_rd = keys[7].state == 1; apr.key_pt_wr = keys[7].state == 2; setlights(apr.mb, mb_lght, 36); setlights(apr.ar, ar_lght, 36); setlights(apr.mq, mq_lght, 36); setlights(apr.fe, fe_lght, 9); setlights(apr.sc, sc_lght, 9); ff_lght[0].state = apr.key_ex_st; ff_lght[1].state = apr.key_ex_sync; ff_lght[2].state = apr.key_dep_st; ff_lght[3].state = apr.key_dep_sync; ff_lght[4].state = apr.key_rd_wr; ff_lght[5].state = apr.mc_rd; ff_lght[6].state = apr.mc_wr; ff_lght[7].state = apr.mc_rq; ff_lght[8].state = apr.if1a; ff_lght[9].state = apr.af0; ff_lght[10].state = apr.af3; ff_lght[11].state = apr.af3a; ff_lght[12].state = apr.et4_ar_pse; ff_lght[13].state = apr.f1a; ff_lght[14].state = apr.f4a; ff_lght[15].state = apr.f6a; ff_lght[16].state = apr.sf3; ff_lght[17].state = apr.sf5a; ff_lght[18].state = apr.sf7; ff_lght[19].state = apr.ar_com_cont; ff_lght[20].state = apr.blt_f0a; ff_lght[21].state = apr.blt_f3a; ff_lght[22].state = apr.blt_f5a; ff_lght[23].state = apr.iot_f0a; ff_lght[24].state = apr.fpf1; ff_lght[25].state = apr.fpf2; ff_lght[26].state = apr.faf1; ff_lght[27].state = apr.faf2; ff_lght[28].state = apr.faf3; ff_lght[29].state = apr.faf4; ff_lght[30].state = apr.fmf1; ff_lght[31].state = apr.fmf2; ff_lght[32].state = apr.fdf1; ff_lght[33].state = apr.fdf2; ff_lght[34].state = apr.ir & H6 && apr.mq & F1 && !apr.nrf3; ff_lght[35].state = apr.nrf1; ff_lght[36].state = apr.nrf2; ff_lght[37].state = apr.nrf3; ff_lght[38].state = apr.fsf1; ff_lght[39].state = apr.chf7; ff_lght[40].state = apr.dsf1; ff_lght[41].state = apr.dsf2; ff_lght[42].state = apr.dsf3; ff_lght[43].state = apr.dsf4; ff_lght[44].state = apr.dsf5; ff_lght[45].state = apr.dsf6; ff_lght[46].state = apr.dsf7; ff_lght[47].state = apr.dsf8; ff_lght[48].state = apr.dsf9; ff_lght[49].state = apr.msf1; ff_lght[50].state = apr.mpf1; ff_lght[51].state = apr.mpf2; ff_lght[52].state = apr.mc_split_cyc_sync; ff_lght[53].state = apr.mc_stop_sync; ff_lght[54].state = apr.shf1; ff_lght[55].state = apr.sc == 0777; ff_lght[56].state = apr.chf1; ff_lght[57].state = apr.chf2; ff_lght[58].state = apr.chf3; ff_lght[59].state = apr.chf4; ff_lght[60].state = apr.chf5; ff_lght[61].state = apr.chf6; ff_lght[62].state = apr.lcf1; ff_lght[63].state = apr.dcf1; ff_lght[64].state = apr.pi_ov; ff_lght[65].state = apr.pi_cyc; ff_lght[66].state = !!apr.pi_req; ff_lght[67].state = apr.iot_go; ff_lght[68].state = apr.a_long; ff_lght[69].state = apr.ma == apr.mas; ff_lght[70].state = apr.uuo_f1; ff_lght[71].state = apr.cpa_pdl_ov; ff_lght[72].state = !apr.ex_user; ff_lght[73].state = apr.cpa_illeg_op; ff_lght[74].state = apr.ex_ill_op; ff_lght[75].state = apr.ex_uuo_sync; ff_lght[76].state = apr.ex_pi_sync; ff_lght[77].state = apr.mq36; ff_lght[78].state = apr.key_rim_sbr; ff_lght[79].state = apr.ar_cry0_xor_cry1; ff_lght[80].state = apr.ar_cry0; ff_lght[81].state = apr.ar_cry1; ff_lght[82].state = apr.ar_ov_flag; ff_lght[83].state = apr.ar_cry0_flag; ff_lght[84].state = apr.ar_cry1_flag; ff_lght[85].state = apr.ar_pc_chg_flag; ff_lght[86].state = apr.cpa_non_exist_mem; ff_lght[87].state = apr.cpa_clock_enable; ff_lght[88].state = apr.cpa_clock_flag; ff_lght[89].state = apr.cpa_pc_chg_enable; ff_lght[90].state = apr.cpa_arov_enable; ff_lght[91].state = !!(apr.cpa_pia&4); ff_lght[92].state = !!(apr.cpa_pia&2); ff_lght[93].state = !!(apr.cpa_pia&1); setlights(membus0, membus_lght, 36); setlights(apr.pr, pr_lght, 8); setlights(apr.rlr, rlr_lght, 8); setlights(apr.rla, rla_lght, 8); SDL_BlitSurface(op_surf, NULL, screen, &op_panel); SDL_BlitSurface(ind_surf, NULL, screen, &ind_panel); SDL_BlitSurface(extra_surf, NULL, screen, &extra_panel); for(i = 0; i < nelem(keys); i++) SDL_BlitSurface(keys[i].surfs[keys[i].state], NULL, screen, &keys[i].r); for(i = 0; i < nelem(op_lights); i++) SDL_BlitSurface(op_lights[i].surfs[op_lights[i].state && apr.sw_power], NULL, screen, &op_lights[i].r); for(i = 0; i < nelem(ind_lights); i++) SDL_BlitSurface(ind_lights[i].surfs[ind_lights[i].state && apr.sw_power], NULL, screen, &ind_lights[i].r); for(i = 0; i < nelem(extra_lights); i++) SDL_BlitSurface(extra_lights[i].surfs[extra_lights[i].state && apr.sw_power], NULL, screen, &extra_lights[i].r); for(i = 0; i < nelem(switches); i++) SDL_BlitSurface(switches[i].surfs[switches[i].state], NULL, screen, &switches[i].r); SDL_Flip(screen); } }
static void InitBoard(struct net_device *dev) { int camcnt; camentry_t cams[16]; u32 cammask; struct dev_mc_list *mcptr; u16 rcrval; /* reset the SONIC */ outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG); udelay(10); /* clear all spurious interrupts */ outw(inw(dev->base_addr + SONIC_ISREG), dev->base_addr + SONIC_ISREG); /* set up the SONIC's bus interface - constant for this adapter - must be done while the SONIC is in reset */ outw(DCREG_USR1 | DCREG_USR0 | DCREG_WC1 | DCREG_DW32, dev->base_addr + SONIC_DCREG); outw(0, dev->base_addr + SONIC_DCREG2); /* remove reset form the SONIC */ outw(0, dev->base_addr + SONIC_CMDREG); udelay(10); /* data sheet requires URRA to be programmed before setting up the CAM contents */ outw(0, dev->base_addr + SONIC_URRA); /* program the CAM entry 0 to the device address */ camcnt = 0; putcam(cams, &camcnt, dev->dev_addr); /* start putting the multicast addresses into the CAM list. Stop if it is full. */ for (mcptr = dev->mc_list; mcptr != NULL; mcptr = mcptr->next) { putcam(cams, &camcnt, mcptr->dmi_addr); if (camcnt == 16) break; } /* calculate CAM mask */ cammask = (1 << camcnt) - 1; /* feed CDA into SONIC, initialize RCR value (always get broadcasts) */ isa_memcpy_toio(dev->mem_start, cams, sizeof(camentry_t) * camcnt); isa_memcpy_toio(dev->mem_start + (sizeof(camentry_t) * camcnt), &cammask, sizeof(cammask)); #ifdef DEBUG printk("CAM setup:\n"); dumpmem(dev, 0, sizeof(camentry_t) * camcnt + sizeof(cammask)); #endif outw(0, dev->base_addr + SONIC_CAMPTR); outw(camcnt, dev->base_addr + SONIC_CAMCNT); outw(CMDREG_LCAM, dev->base_addr + SONIC_CMDREG); if (!wait_timeout(dev, SONIC_CMDREG, CMDREG_LCAM, 0, 2)) { printk(KERN_ERR "%s:SONIC did not respond on LCAM command - giving up.", dev->name); return; } else { /* clear interrupt condition */ outw(ISREG_LCD, dev->base_addr + SONIC_ISREG); #ifdef DEBUG printk("Loading CAM done, address pointers %04x:%04x\n", inw(dev->base_addr + SONIC_URRA), inw(dev->base_addr + SONIC_CAMPTR)); { int z; printk("\n-->CAM: PTR %04x CNT %04x\n", inw(dev->base_addr + SONIC_CAMPTR), inw(dev->base_addr + SONIC_CAMCNT)); outw(CMDREG_RST, dev->base_addr + SONIC_CMDREG); for (z = 0; z < camcnt; z++) { outw(z, dev->base_addr + SONIC_CAMEPTR); printk("Entry %d: %04x %04x %04x\n", z, inw(dev->base_addr + SONIC_CAMADDR0), inw(dev->base_addr + SONIC_CAMADDR1), inw(dev->base_addr + SONIC_CAMADDR2)); } outw(0, dev->base_addr + SONIC_CMDREG); } #endif } rcrval = RCREG_BRD | RCREG_LB_NONE; /* if still multicast addresses left or ALLMULTI is set, set the multicast enable bit */ if ((dev->flags & IFF_ALLMULTI) || (mcptr != NULL)) rcrval |= RCREG_AMC; /* promiscous mode ? */ if (dev->flags & IFF_PROMISC) rcrval |= RCREG_PRO; /* program receive mode */ outw(rcrval, dev->base_addr + SONIC_RCREG); #ifdef DEBUG printk("\nRCRVAL: %04x\n", rcrval); #endif /* set up descriptors in shared memory + feed them into SONIC registers */ InitDscrs(dev); if (!InitSONIC(dev)) return; /* reset all pending interrupts */ outw(0xffff, dev->base_addr + SONIC_ISREG); /* enable transmitter + receiver interrupts */ outw(CMDREG_RXEN, dev->base_addr + SONIC_CMDREG); outw(IMREG_PRXEN | IMREG_RBEEN | IMREG_PTXEN | IMREG_TXEREN, dev->base_addr + SONIC_IMREG); /* turn on card interrupts */ outb(inb(dev->base_addr + BCMREG) | BCMREG_IEN, dev->base_addr + BCMREG); #ifdef DEBUG printk("Register dump after initialization:\n"); dumpregs(dev); #endif }
int main(void) { init(4); dumpmem(); int *a = imalloc(); *a = 7; dumpmem(); int *b = imalloc(); *b = 8; dumpmem(); int *c = imalloc(); *c = 9; dumpmem(); printf("Releasing %d, status %d\n", *c, release(c)); dumpmem(); retain(b); printf("Releasing %d, status %d\n", *b, release(b)); dumpmem(); printf("Releasing %d, status %d\n", *a, release(a)); dumpmem(); int *d = imalloc(); *d = 6; dumpmem(); int *e = imalloc(); *e = 5; dumpmem(); int *f = imalloc(); *f = 4; dumpmem(); int *g = imalloc(); printf(g ? "got something\n" : "got null\n"); dumpmem(); return 0; }
static int ui_cmd_memedit(ui_cmdline_t *cmd,int argc,char *argv[]) { uint8_t b; uint16_t h; uint32_t w; uint64_t q; long addr; char *vtext; int wlen; int count; int idx = 1; int stuffed = 0; int res = 0; getaddrargs(cmd,&prev_wtype,&prev_addr,NULL); wlen = prev_wtype & ATYPE_SIZE_MASK; vtext = cmd_getarg(cmd,idx++); addr = prev_addr; while (vtext) { count = stuffmem(addr,wlen,vtext); if (count < 0) { ui_showerror(count,"Could not modify memory"); return count; /* error */ } addr += count*wlen; prev_addr += count*wlen; stuffed += count; vtext = cmd_getarg(cmd,idx++); } if (stuffed == 0) { char line[256]; char prompt[32]; xprintf("Type '.' to exit, '-' to back up, '=' to dump memory.\n"); for (;;) { addr = prev_addr; if ((prev_wtype & ATYPE_TYPE_MASK) == ATYPE_TYPE_PHYS) { addr = UNCADDR(addr); } xprintf("%P%c ",prev_addr,(addr != prev_addr) ? '%' : ':'); switch (wlen) { default: case 1: if ((res = mem_peek(&b, addr, MEM_BYTE))) { return res; } xsprintf(prompt,"[%02X]: ", b); break; case 2: if ((res = mem_peek(&h, addr, MEM_HALFWORD))) { return res; } xsprintf(prompt,"[%04X]: ",h); break; case 4: if ((res = mem_peek(&w, addr, MEM_WORD))) { return res; } xsprintf(prompt,"[%08X]: ",w); break; case 8: if ((res = mem_peek(&q, addr, MEM_QUADWORD))) { return res; } xsprintf(prompt,"[%016llX]: ",q); break; } console_readline(prompt,line,sizeof(line)); if (line[0] == '-') { prev_addr -= wlen; continue; } if (line[0] == '=') { dumpmem(prev_addr,prev_addr,16,wlen); continue; } if (line[0] == '.') { break; } if (line[0] == '\0') { prev_addr += wlen; continue; } count = stuffmem(addr,wlen,line); if (count < 0) return count; if (count == 0) break; prev_addr += count*wlen; } } return 0; }