From 83f2218e2750e3b419507c9f0496d48508de2dae Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Fri, 8 May 2015 12:58:53 -0700 Subject: [PATCH] More debugger paging improvements --- modules/pcjs/bin/romtests.json | 2 +- modules/pcjs/lib/debugger.js | 14 ++++++++------ modules/pcjs/lib/x86cpu.js | 19 ++++++++++++------- tests/pc/80386/tests.nasm | 4 +++- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/modules/pcjs/bin/romtests.json b/modules/pcjs/bin/romtests.json index a40b43ce4..168d9ef63 100644 --- a/modules/pcjs/bin/romtests.json +++ b/modules/pcjs/bin/romtests.json @@ -78,7 +78,7 @@ "debugger": { "id": "pc386.debugger", "name": "", - "commands": "", + "commands": "bp F000:825F;g", "messages": "" } } diff --git a/modules/pcjs/lib/debugger.js b/modules/pcjs/lib/debugger.js index 653493f86..c5e8de92c 100644 --- a/modules/pcjs/lib/debugger.js +++ b/modules/pcjs/lib/debugger.js @@ -2688,12 +2688,14 @@ if (DEBUGGER) { if (nState >= 0 && this.aaOpcodeCounts.length) { this.cInstructions++; var bOpcode = this.cpu.probeAddr(addr); - this.aaOpcodeCounts[bOpcode][1]++; - var a = this.aOpcodeHistory[this.iOpcodeHistory]; - a[0] = this.cpu.getIP(); - a[1] = this.cpu.getCS(); - a[2] = addr; - if (++this.iOpcodeHistory == this.aOpcodeHistory.length) this.iOpcodeHistory = 0; + if (bOpcode != null) { + this.aaOpcodeCounts[bOpcode][1]++; + var a = this.aOpcodeHistory[this.iOpcodeHistory]; + a[0] = this.cpu.getIP(); + a[1] = this.cpu.getCS(); + a[2] = addr; + if (++this.iOpcodeHistory == this.aOpcodeHistory.length) this.iOpcodeHistory = 0; + } } return false; }; diff --git a/modules/pcjs/lib/x86cpu.js b/modules/pcjs/lib/x86cpu.js index 8a20013bc..ef563a359 100644 --- a/modules/pcjs/lib/x86cpu.js +++ b/modules/pcjs/lib/x86cpu.js @@ -737,9 +737,10 @@ X86CPU.prototype.enablePageBlocks = function() * @this {X86CPU} * @param {number} addr is a linear address * @param {boolean} fWrite (true if called for a write, false if for a read) + * @param {boolean} [fSuppress] (true if any faults, remapping, etc should be suppressed) * @return {Memory|null} */ -X86CPU.prototype.mapPageBlock = function(addr, fWrite) +X86CPU.prototype.mapPageBlock = function(addr, fWrite, fSuppress) { var offPDE = (addr & X86.LADDR.PDE.MASK) >>> X86.LADDR.PDE.SHIFT; var addrPDE = this.regCR3 + offPDE; @@ -752,12 +753,12 @@ X86CPU.prototype.mapPageBlock = function(addr, fWrite) var pde = blockPDE.readLong(offPDE); if (!(pde & X86.PTE.PRESENT)) { - X86.fnPageFault.call(this, addr, false, fWrite); + if (!fSuppress) X86.fnPageFault.call(this, addr, false, fWrite); return null; } if (!(pde & X86.PTE.USER) && this.segCS.cpl == 3) { - X86.fnPageFault.call(this, addr, true, fWrite); + if (!fSuppress) X86.fnPageFault.call(this, addr, true, fWrite); return null; } @@ -771,13 +772,13 @@ X86CPU.prototype.mapPageBlock = function(addr, fWrite) var blockPTE = this.aBusBlocks[(addrPTE & this.busMask) >>> this.blockShift]; var pte = blockPTE.readLong(offPTE); - if (!(pte & X86.PTE.PRESENT)) { - X86.fnPageFault.call(this, addr, false, fWrite); + if (!(pte & X86.PTE.PRESENT) && !fSuppress) { + if (!fSuppress) X86.fnPageFault.call(this, addr, false, fWrite); return null; } if (!(pte & X86.PTE.USER) && this.segCS.cpl == 3) { - X86.fnPageFault.call(this, addr, true, fWrite); + if (!fSuppress) X86.fnPageFault.call(this, addr, true, fWrite); return null; } @@ -786,6 +787,7 @@ X86CPU.prototype.mapPageBlock = function(addr, fWrite) * TODO: Since we're immediately shifting addrPhys by blockShift, we could also skip adding the addr's offset. */ var blockPhys = this.aBusBlocks[(addrPhys & this.busMask) >>> this.blockShift]; + if (fSuppress) return blockPhys; /* * So we have the block containing the physical memory corresponding to the given linear address. @@ -2717,7 +2719,10 @@ X86CPU.prototype.setBinding = function(sHTMLType, sBinding, control) X86CPU.prototype.probeAddr = function(addr) { var block = this.aMemBlocks[(addr & this.memMask) >>> this.blockShift]; - if (block.type == Memory.TYPE.UNPAGED) return null; + if (block.type == Memory.TYPE.UNPAGED) { + block = this.mapPageBlock(addr, false, true); + if (!block) return null; + } return block.readByteDirect(addr & this.blockLimit, addr); }; diff --git a/tests/pc/80386/tests.nasm b/tests/pc/80386/tests.nasm index 7f398a52b..03a290849 100644 --- a/tests/pc/80386/tests.nasm +++ b/tests/pc/80386/tests.nasm @@ -39,6 +39,8 @@ bits 16 +PAGING equ 1 + ; ; If we built our data structures in RAM, we might use the first page of RAM (0x0000-0x0fff) like so: ; @@ -264,7 +266,7 @@ initPT: stosd goProt: o32 lgdt [cs:addrGDT] mov cr3,esi mov eax,cr0 - %ifdef PAGING + %if PAGING or eax,CR0_MSW_PE | CR0_PG %else or eax,CR0_MSW_PE