Don't disassemble beyond end of memory when showing regs.

This commit is contained in:
Daniel Beer 2010-05-13 16:57:32 +12:00
parent c84f2ab579
commit 2a7a7189ae
1 changed files with 5 additions and 2 deletions

View File

@ -36,16 +36,19 @@ static int cmd_regs(cproc_t cp, char **arg)
device_t dev = cproc_device(cp); device_t dev = cproc_device(cp);
uint16_t regs[DEVICE_NUM_REGS]; uint16_t regs[DEVICE_NUM_REGS];
uint8_t code[16]; uint8_t code[16];
int len = sizeof(code);
if (dev->getregs(dev, regs) < 0) if (dev->getregs(dev, regs) < 0)
return -1; return -1;
cproc_regs(cp, regs); cproc_regs(cp, regs);
/* Try to disassemble the instruction at PC */ /* Try to disassemble the instruction at PC */
if (dev->readmem(dev, regs[0], code, sizeof(code)) < 0) if (len > 0x10000 - regs[0])
len = 0x10000 - regs[0];
if (dev->readmem(dev, regs[0], code, len) < 0)
return 0; return 0;
cproc_disassemble(cp, regs[0], (uint8_t *)code, sizeof(code)); cproc_disassemble(cp, regs[0], (uint8_t *)code, len);
return 0; return 0;
} }