From 6cba6e5d4fe1d24c0cc00a28219d739281892ec0 Mon Sep 17 00:00:00 2001 From: Guy Perfect Date: Wed, 30 Oct 2024 10:22:49 -0500 Subject: [PATCH] Prevent disassembling over PC --- util/disassembler.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/util/disassembler.c b/util/disassembler.c index ce0c60f..721499a 100644 --- a/util/disassembler.c +++ b/util/disassembler.c @@ -489,8 +489,9 @@ static OpDef* dasmSETF(VBU_DasmConfig *config, } /* Disassemble one instruction */ -static int dasmLine(VB *sim, uint32_t *address, VBU_DasmConfig *config, - VBU_DasmLine **lines, size_t *size, size_t *offset, unsigned index) { +static int dasmLine(VB *sim, uint32_t *address, uint32_t pc, + VBU_DasmConfig *config, VBU_DasmLine **lines, size_t *size, size_t *offset, + unsigned index) { char *dest; /* Text output pointer */ char *format; /* Hexadecimal format string */ VBU_DasmLine *line; /* Output line */ @@ -501,15 +502,17 @@ static int dasmLine(VB *sim, uint32_t *address, VBU_DasmConfig *config, char tCode[4][3]; /* Code display text */ char tMnemonic[8]; /* Mnemonic display text */ char tOperands[3][15]; /* Operands display text */ - unsigned x; /* Scratch and iterator */ + uint32_t x; /* Scratch and iterator */ /* Process non-text members */ line = &(*lines)[index]; line->address = *address; line->codeLength = dasmInstSize(sim, *address); - line->isPC = vbGetProgramCounter(sim) - *address < line->codeLength; - for (x = 0; x < line->codeLength; x++, (*address)++) - line->code[x] = vbRead(sim, *address, VB_U8); + line->isPC = *address == pc; + for (x = 0; x < line->codeLength; x++) + line->code[x] = vbRead(sim, *address + x, VB_U8); + *address += pc - *address < line->codeLength ? + pc - *address : line->codeLength; /* Do not process text members */ if (config == NULL) { @@ -674,7 +677,7 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address, /* Process output lines */ for (x = 0; x < length; x++) { - if (dasmLine(sim, &addr, config, &lines, &size, &offset, x)) + if (dasmLine(sim, &addr, pc, config, &lines, &size, &offset, x)) goto catch; } return lines;