From c431e5dde84dc2c88e1b8b8566c7e700b6868f70 Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Thu, 14 May 2015 13:11:46 -0700 Subject: [PATCH] Future-proof ADDR_INVALID checks by using strict [in]equality --- modules/pcjs/lib/debugger.js | 7 +++---- modules/pcjs/lib/x86func.js | 12 ++++++------ modules/pcjs/lib/x86seg.js | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/pcjs/lib/debugger.js b/modules/pcjs/lib/debugger.js index 9522674ec..f0b53b552 100644 --- a/modules/pcjs/lib/debugger.js +++ b/modules/pcjs/lib/debugger.js @@ -410,9 +410,8 @@ if (DEBUGGER) { Debugger.TYPE_OTHER = 0xF000; // "other" field /* - * TYPE_SIZE values. Note that some of the values (eg, TYPE_WORDIB - * and TYPE_WORDIW) imply the presence of a third operand, for those - * weird cases.... + * TYPE_SIZE values. Some of the values (eg, TYPE_WORDIB and TYPE_WORDIW) + * imply the presence of a third operand, for those weird cases.... */ Debugger.TYPE_NONE = 0x0000; // (all other TYPE fields ignored) Debugger.TYPE_BYTE = 0x0001; // (b) byte, regardless of operand size @@ -428,7 +427,7 @@ if (DEBUGGER) { Debugger.TYPE_PREFIX = 0x000F; // (treat similarly to TYPE_NONE) /* - * TYPE_MODE values. Note that order is somewhat important, as all values implying + * TYPE_MODE values. Order is somewhat important, as all values implying * the presence of a ModRM byte are assumed to be >= TYPE_MODRM. */ Debugger.TYPE_IMM = 0x0000; // (I) immediate data diff --git a/modules/pcjs/lib/x86func.js b/modules/pcjs/lib/x86func.js index a75899445..e213db598 100644 --- a/modules/pcjs/lib/x86func.js +++ b/modules/pcjs/lib/x86func.js @@ -1216,7 +1216,7 @@ X86.fnINT = function INT(nIDT, nError, nCycles) var oldCS = this.getCS(); var oldIP = this.getIP(); var addr = this.segCS.loadIDT(nIDT); - if (addr != X86.ADDR_INVALID) { + if (addr !== X86.ADDR_INVALID) { this.regLIP = addr; if (PREFETCH) this.flushPrefetch(this.regLIP); this.pushWord(oldPS); @@ -1311,7 +1311,7 @@ X86.fnLAR = function LAR(dst, src) * TODO: This instruction's 80286 documentation does not discuss conforming code segments; determine * if we need a special check for them. */ - if (this.segVER.load(src, true) != X86.ADDR_INVALID) { + if (this.segVER.load(src, true) !== X86.ADDR_INVALID) { if (this.segVER.dpl >= this.segCS.cpl && this.segVER.dpl >= (src & X86.SEL.RPL)) { this.setZF(); return this.segVER.acc & X86.DESC.ACC.MASK; @@ -1600,7 +1600,7 @@ X86.fnLSL = function LSL(dst, src) * TODO: LSL is explicitly documented as ALSO requiring a non-null selector, so we check X86.SEL.MASK; * are there any other instructions that were, um, less explicit but also require a non-null selector? */ - if ((src & X86.SEL.MASK) && this.segVER.load(src, true) != X86.ADDR_INVALID) { + if ((src & X86.SEL.MASK) && this.segVER.load(src, true) !== X86.ADDR_INVALID) { var fConforming = ((this.segVER.acc & X86.DESC.ACC.TYPE.CODE_CONFORMING) == X86.DESC.ACC.TYPE.CODE_CONFORMING); if ((fConforming || this.segVER.dpl >= this.segCS.cpl) && this.segVER.dpl >= (src & X86.SEL.RPL)) { this.setZF(); @@ -1643,7 +1643,7 @@ X86.fnLSS = function LSS(dst, src) X86.fnLTR = function LTR(dst, src) { this.opFlags |= X86.OPFLAG.NOWRITE; - if (this.segTSS.load(dst) != X86.ADDR_INVALID) { + if (this.segTSS.load(dst) !== X86.ADDR_INVALID) { this.setShort(this.segTSS.addrDesc + X86.DESC.ACC.OFFSET, this.segTSS.acc |= X86.DESC.ACC.TYPE.LDT); this.segTSS.type = X86.DESC.ACC.TYPE.TSS_BUSY; } @@ -3237,7 +3237,7 @@ X86.fnVERR = function VERR(dst, src) * descriptor table or the descriptor is not for a segment. */ this.nStepCycles -= (14 + (this.regEA === X86.ADDR_INVALID? 0 : 2)); - if (this.segVER.load(dst, true) != X86.ADDR_INVALID) { + if (this.segVER.load(dst, true) !== X86.ADDR_INVALID) { /* * Verify that this is a readable segment; that is, of these four combinations (code+readable, * code+nonreadable, data+writable, date+nonwritable), make sure we're not the second combination. @@ -3279,7 +3279,7 @@ X86.fnVERW = function VERW(dst, src) * descriptor table or the descriptor is not for a segment. */ this.nStepCycles -= (14 + (this.regEA === X86.ADDR_INVALID? 0 : 2)); - if (this.segVER.load(dst, true) != X86.ADDR_INVALID) { + if (this.segVER.load(dst, true) !== X86.ADDR_INVALID) { /* * Verify that this is a writable data segment */ diff --git a/modules/pcjs/lib/x86seg.js b/modules/pcjs/lib/x86seg.js index a38d4b4b9..1ac96eaf1 100644 --- a/modules/pcjs/lib/x86seg.js +++ b/modules/pcjs/lib/x86seg.js @@ -982,7 +982,7 @@ X86Seg.prototype.updateMode = function(fLoad, fProt) * hardware does not update it either. In fact, I've seen code that uses the null GDT descriptor * for other purposes, on the assumption that that descriptor is completely unused. */ - if ((this.sel & ~X86.SEL.RPL) && this.addrDesc != X86.ADDR_INVALID) { + if ((this.sel & ~X86.SEL.RPL) && this.addrDesc !== X86.ADDR_INVALID) { var addrACC = this.addrDesc + X86.DESC.ACC.TYPE.OFFSET; this.cpu.setByte(addrACC, this.cpu.getByte(addrACC) | (X86.DESC.ACC.TYPE.ACCESSED >> 8)); }