From e7dc2ce750df1c33ce97ce0a4052ab0aa55dd189 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 15 Jun 2021 09:26:22 -0500 Subject: [PATCH] arm: fixed pc and listing for thumb --- src/common/cpu/ARM.ts | 5 +++-- src/worker/workermain.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/common/cpu/ARM.ts b/src/common/cpu/ARM.ts index 8e7b92e9..13799a60 100644 --- a/src/common/cpu/ARM.ts +++ b/src/common/cpu/ARM.ts @@ -2749,7 +2749,7 @@ ARMCore.prototype.resetCPU = function(startOffset) { ARMCore.prototype.freeze = function() : ARMCoreState { return { - PC: this.gprs[15] - 4, + PC: this.gprs[15] - this.instructionWidth, SP: this.gprs[13], 'gprs': [ this.gprs[0], @@ -4097,6 +4097,7 @@ ARMCore.prototype.compileThumb = function(instruction) { op.execMode = ARMMode.MODE_THUMB; op.fixedJump = op.fixedJump || false; + //console.log(hex(instruction), op); return op; }; @@ -4137,7 +4138,7 @@ export class ARM32CPU implements CPU, InstructionBased, ARMMMUInterface, ARMIRQI return n > 0 ? n : 1; } getPC(): number { - return this.core.gprs[15] - 4; + return this.core.gprs[15] - this.core.instructionWidth; } getSP(): number { return this.core.gprs[13]; diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts index ad054812..1c0eea0e 100644 --- a/src/worker/workermain.ts +++ b/src/worker/workermain.ts @@ -2935,8 +2935,14 @@ function assembleARMIPS(step:BuildStep) { var lst = listings[path2]; if (lst == null) { lst = listings[path2] = {lines:[]}; } var ofs = parseInt(m[1], 16); - var insn = objout.slice(ofs, ofs+4); // TODO: doesn't do thumb or !=4 bytes - if (lastofs == ofs) lst.lines.pop(); else lastofs = ofs; + var insn = objout.slice(ofs, ofs+4); + if (lastofs == ofs) { + lst.lines.pop(); // get rid of duplicate offset + } else if (lastofs+2 == ofs) { + var lastline = lst.lines[lst.lines.length-1]; // convert 4-byte to 2-byte insn + if (lastline && lastline.insns) lastline.insns = lastline.insns.substring(4,8); + } + lastofs = ofs; lst.lines.push({ path: path, line: parseInt(m[4]),