diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-10-12 23:41:43 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-10-12 23:41:43 -0700 |
commit | 222c31db2102daecd1e77d66299a3ea01982ec35 (patch) | |
tree | 25930bd76874e16651774ba1fd0988397dda5a12 | |
parent | 01dada15c33dff954f3b76406fd9ed09ef4834c8 (diff) | |
download | mu-222c31db2102daecd1e77d66299a3ea01982ec35.tar.gz |
4688
-rw-r--r-- | subx/013direct_addressing.cc | 70 | ||||
-rw-r--r-- | subx/014indirect_addressing.cc | 56 | ||||
-rw-r--r-- | subx/015immediate_addressing.cc | 36 | ||||
-rw-r--r-- | subx/016index_addressing.cc | 8 | ||||
-rw-r--r-- | subx/017jump_disp8.cc | 12 | ||||
-rw-r--r-- | subx/018jump_disp16.cc | 14 | ||||
-rw-r--r-- | subx/019functions.cc | 4 |
7 files changed, 100 insertions, 100 deletions
diff --git a/subx/013direct_addressing.cc b/subx/013direct_addressing.cc index c97fd833..5f44d49d 100644 --- a/subx/013direct_addressing.cc +++ b/subx/013direct_addressing.cc @@ -29,9 +29,9 @@ case 0x01: { // add r32 to r/m32 // We return a pointer so that instructions can write to multiple bytes in // 'Mem' at once. int32_t* effective_address(uint8_t modrm) { - uint8_t mod = (modrm>>6); + const uint8_t mod = (modrm>>6); // ignore middle 3 'reg opcode' bits - uint8_t rm = modrm & 0x7; + const uint8_t rm = modrm & 0x7; if (mod == 3) { // mod 3 is just register direct addressing trace(90, "run") << "r/m32 is " << rname(rm) << end(); @@ -41,9 +41,9 @@ int32_t* effective_address(uint8_t modrm) { } uint32_t effective_address_number(uint8_t modrm) { - uint8_t mod = (modrm>>6); + const uint8_t mod = (modrm>>6); // ignore middle 3 'reg opcode' bits - uint8_t rm = modrm & 0x7; + const uint8_t rm = modrm & 0x7; uint32_t addr = 0; switch (mod) { case 3: @@ -91,8 +91,8 @@ put(name, "29", "subtract r32 from rm32"); :(before "End Single-Byte Opcodes") case 0x29: { // subtract r32 from r/m32 - uint8_t modrm = next(); - uint8_t arg2 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg2 = (modrm>>3)&0x7; trace(90, "run") << "subtract " << rname(arg2) << " from r/m32" << end(); int32_t* arg1 = effective_address(modrm); BINARY_ARITHMETIC_OP(-, *arg1, Reg[arg2].i); @@ -118,14 +118,14 @@ put(name, "f7", "test/negate/mul/div rm32 (with EAX if necessary) depending on s :(before "End Single-Byte Opcodes") case 0xf7: { // xor r32 with r/m32 - uint8_t modrm = next(); + const uint8_t modrm = next(); trace(90, "run") << "operate on r/m32" << end(); int32_t* arg1 = effective_address(modrm); - uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits + const uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits switch (subop) { case 4: { // mul unsigned EAX by r/m32 trace(90, "run") << "subop: multiply EAX by r/m32" << end(); - uint64_t result = Reg[EAX].u * static_cast<uint32_t>(*arg1); + const uint64_t result = Reg[EAX].u * static_cast<uint32_t>(*arg1); Reg[EAX].u = result & 0xffffffff; Reg[EDX].u = result >> 32; OF = (Reg[EDX].u != 0); @@ -158,10 +158,10 @@ put(name_0f, "af", "multiply rm32 into r32"); :(before "End Two-Byte Opcodes Starting With 0f") case 0xaf: { // multiply r32 into r/m32 - uint8_t modrm = next(); - uint8_t arg2 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg2 = (modrm>>3)&0x7; trace(90, "run") << "multiply r/m32 into " << rname(arg2) << end(); - int32_t* arg1 = effective_address(modrm); + const int32_t* arg1 = effective_address(modrm); BINARY_ARITHMETIC_OP(*, Reg[arg2].i, *arg1); break; } @@ -184,8 +184,8 @@ put(name, "21", "rm32 = bitwise AND of r32 with rm32"); :(before "End Single-Byte Opcodes") case 0x21: { // and r32 with r/m32 - uint8_t modrm = next(); - uint8_t arg2 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg2 = (modrm>>3)&0x7; trace(90, "run") << "and " << rname(arg2) << " with r/m32" << end(); int32_t* arg1 = effective_address(modrm); BINARY_BITWISE_OP(&, *arg1, Reg[arg2].u); @@ -210,8 +210,8 @@ put(name, "09", "rm32 = bitwise OR of r32 with rm32"); :(before "End Single-Byte Opcodes") case 0x09: { // or r32 with r/m32 - uint8_t modrm = next(); - uint8_t arg2 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg2 = (modrm>>3)&0x7; trace(90, "run") << "or " << rname(arg2) << " with r/m32" << end(); int32_t* arg1 = effective_address(modrm); BINARY_BITWISE_OP(|, *arg1, Reg[arg2].u); @@ -236,8 +236,8 @@ put(name, "31", "rm32 = bitwise XOR of r32 with rm32"); :(before "End Single-Byte Opcodes") case 0x31: { // xor r32 with r/m32 - uint8_t modrm = next(); - uint8_t arg2 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg2 = (modrm>>3)&0x7; trace(90, "run") << "xor " << rname(arg2) << " with r/m32" << end(); int32_t* arg1 = effective_address(modrm); BINARY_BITWISE_OP(^, *arg1, Reg[arg2].u); @@ -289,15 +289,15 @@ put(name, "39", "compare: set SF if rm32 < r32"); :(before "End Single-Byte Opcodes") case 0x39: { // set SF if r/m32 < r32 - uint8_t modrm = next(); - uint8_t reg2 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t reg2 = (modrm>>3)&0x7; trace(90, "run") << "compare " << rname(reg2) << " with r/m32" << end(); - int32_t* arg1 = effective_address(modrm); - int32_t arg2 = Reg[reg2].i; - int32_t tmp1 = *arg1 - arg2; + const int32_t* arg1 = effective_address(modrm); + const int32_t arg2 = Reg[reg2].i; + const int32_t tmp1 = *arg1 - arg2; SF = (tmp1 < 0); ZF = (tmp1 == 0); - int64_t tmp2 = *arg1 - arg2; + const int64_t tmp2 = *arg1 - arg2; OF = (tmp1 != tmp2); trace(90, "run") << "SF=" << SF << "; ZF=" << ZF << "; OF=" << OF << end(); break; @@ -342,8 +342,8 @@ put(name, "89", "copy r32 to rm32"); :(before "End Single-Byte Opcodes") case 0x89: { // copy r32 to r/m32 - uint8_t modrm = next(); - uint8_t rsrc = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t rsrc = (modrm>>3)&0x7; trace(90, "run") << "copy " << rname(rsrc) << " to r/m32" << end(); int32_t* dest = effective_address(modrm); *dest = Reg[rsrc].i; @@ -370,11 +370,11 @@ put(name, "87", "swap the contents of r32 and rm32"); :(before "End Single-Byte Opcodes") case 0x87: { // exchange r32 with r/m32 - uint8_t modrm = next(); - uint8_t reg2 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t reg2 = (modrm>>3)&0x7; trace(90, "run") << "exchange " << rname(reg2) << " with r/m32" << end(); int32_t* arg1 = effective_address(modrm); - int32_t tmp = *arg1; + const int32_t tmp = *arg1; *arg1 = Reg[reg2].i; Reg[reg2].i = tmp; trace(90, "run") << "storing 0x" << HEXWORD << *arg1 << " in r/m32" << end(); @@ -411,7 +411,7 @@ case 0x44: case 0x45: case 0x46: case 0x47: { // increment r32 - uint8_t reg = op & 0x7; + const uint8_t reg = op & 0x7; trace(90, "run") << "increment " << rname(reg) << end(); ++Reg[reg].u; trace(90, "run") << "storing value 0x" << HEXWORD << Reg[reg].u << end(); @@ -433,8 +433,8 @@ put(name, "ff", "inc/dec/jump/push/call rm32 based on subop"); :(before "End Single-Byte Opcodes") case 0xff: { - uint8_t modrm = next(); - uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits + const uint8_t modrm = next(); + const uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits switch (subop) { case 0: { // increment r/m32 trace(90, "run") << "increment r/m32" << end(); @@ -477,7 +477,7 @@ case 0x4c: case 0x4d: case 0x4e: case 0x4f: { // decrement r32 - uint8_t reg = op & 0x7; + const uint8_t reg = op & 0x7; trace(90, "run") << "decrement " << rname(reg) << end(); --Reg[reg].u; trace(90, "run") << "storing value 0x" << HEXWORD << Reg[reg].u << end(); @@ -575,7 +575,7 @@ case 0x5c: case 0x5d: case 0x5e: case 0x5f: { // pop stack into r32 - uint8_t reg = op & 0x7; + const uint8_t reg = op & 0x7; trace(90, "run") << "pop into " << rname(reg) << end(); //? cerr << "pop from " << Reg[ESP].u << '\n'; Reg[reg].u = pop(); @@ -584,7 +584,7 @@ case 0x5f: { // pop stack into r32 } :(code) uint32_t pop() { - uint32_t result = read_mem_u32(Reg[ESP].u); + const uint32_t result = read_mem_u32(Reg[ESP].u); trace(90, "run") << "popping value 0x" << HEXWORD << result << end(); Reg[ESP].u += 4; trace(90, "run") << "incrementing ESP to 0x" << HEXWORD << Reg[ESP].u << end(); diff --git a/subx/014indirect_addressing.cc b/subx/014indirect_addressing.cc index 2355273d..c6bedace 100644 --- a/subx/014indirect_addressing.cc +++ b/subx/014indirect_addressing.cc @@ -45,8 +45,8 @@ put(name, "03", "add rm32 to r32"); :(before "End Single-Byte Opcodes") case 0x03: { // add r/m32 to r32 - uint8_t modrm = next(); - uint8_t arg1 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg1 = (modrm>>3)&0x7; trace(90, "run") << "add r/m32 to " << rname(arg1) << end(); const int32_t* arg2 = effective_address(modrm); BINARY_ARITHMETIC_OP(+, Reg[arg1].i, *arg2); @@ -88,8 +88,8 @@ put(name, "2b", "subtract rm32 from r32"); :(before "End Single-Byte Opcodes") case 0x2b: { // subtract r/m32 from r32 - uint8_t modrm = next(); - uint8_t arg1 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg1 = (modrm>>3)&0x7; trace(90, "run") << "subtract r/m32 from " << rname(arg1) << end(); const int32_t* arg2 = effective_address(modrm); BINARY_ARITHMETIC_OP(-, Reg[arg1].i, *arg2); @@ -131,8 +131,8 @@ ff 00 00 00 # 0xff :(before "End Single-Byte Opcodes") case 0x23: { // and r/m32 with r32 - uint8_t modrm = next(); - uint8_t arg1 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg1 = (modrm>>3)&0x7; trace(90, "run") << "and r/m32 with " << rname(arg1) << end(); const int32_t* arg2 = effective_address(modrm); BINARY_BITWISE_OP(&, Reg[arg1].u, *arg2); @@ -174,8 +174,8 @@ put(name, "0b", "r32 = bitwise OR of r32 with rm32"); :(before "End Single-Byte Opcodes") case 0x0b: { // or r/m32 with r32 - uint8_t modrm = next(); - uint8_t arg1 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg1 = (modrm>>3)&0x7; trace(90, "run") << "or r/m32 with " << rname(arg1) << end(); const int32_t* arg2 = effective_address(modrm); BINARY_BITWISE_OP(|, Reg[arg1].u, *arg2); @@ -217,8 +217,8 @@ put(name, "33", "r32 = bitwise XOR of r32 with rm32"); :(before "End Single-Byte Opcodes") case 0x33: { // xor r/m32 with r32 - uint8_t modrm = next(); - uint8_t arg1 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg1 = (modrm>>3)&0x7; trace(90, "run") << "xor r/m32 with " << rname(arg1) << end(); const int32_t* arg2 = effective_address(modrm); BINARY_BITWISE_OP(|, Reg[arg1].u, *arg2); @@ -301,12 +301,12 @@ put(name, "3b", "compare: set SF if r32 < rm32"); :(before "End Single-Byte Opcodes") case 0x3b: { // set SF if r32 < r/m32 - uint8_t modrm = next(); - uint8_t reg1 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t reg1 = (modrm>>3)&0x7; trace(90, "run") << "compare r/m32 with " << rname(reg1) << end(); - int32_t arg1 = Reg[reg1].i; - int32_t* arg2 = effective_address(modrm); - int32_t tmp1 = arg1 - *arg2; + const int32_t arg1 = Reg[reg1].i; + const int32_t* arg2 = effective_address(modrm); + const int32_t tmp1 = arg1 - *arg2; SF = (tmp1 < 0); ZF = (tmp1 == 0); int64_t tmp2 = arg1 - *arg2; @@ -373,10 +373,10 @@ af 00 00 00 # 0xaf :(before "End Single-Byte Opcodes") case 0x8b: { // copy r32 to r/m32 - uint8_t modrm = next(); - uint8_t rdest = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t rdest = (modrm>>3)&0x7; trace(90, "run") << "copy r/m32 to " << rname(rdest) << end(); - int32_t* src = effective_address(modrm); + const int32_t* src = effective_address(modrm); Reg[rdest].i = *src; trace(90, "run") << "storing 0x" << HEXWORD << *src << end(); break; @@ -403,8 +403,8 @@ f0 cc bb aa # 0xf0 with more data in following bytes :(before "End Single-Byte Opcodes") case 0x88: { // copy r8 to r/m8 - uint8_t modrm = next(); - uint8_t rsrc = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t rsrc = (modrm>>3)&0x7; trace(90, "run") << "copy lowermost byte of " << rname(rsrc) << " to r8/m8-at-r32" << end(); // use unsigned to zero-extend 8-bit value to 32 bits uint8_t* dest = reinterpret_cast<uint8_t*>(effective_address(modrm)); @@ -435,11 +435,11 @@ ab ff ff ff # 0xab with more data in following bytes :(before "End Single-Byte Opcodes") case 0x8a: { // copy r/m8 to r8 - uint8_t modrm = next(); - uint8_t rdest = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t rdest = (modrm>>3)&0x7; trace(90, "run") << "copy r8/m8-at-r32 to lowermost byte of " << rname(rdest) << end(); // use unsigned to zero-extend 8-bit value to 32 bits - uint8_t* src = reinterpret_cast<uint8_t*>(effective_address(modrm)); + const uint8_t* src = reinterpret_cast<uint8_t*>(effective_address(modrm)); trace(90, "run") << "storing 0x" << HEXBYTE << NUM(*src) << end(); *reinterpret_cast<uint8_t*>(&Reg[rdest].u) = *src; // assumes host is little-endian trace(90, "run") << rname(rdest) << " now contains 0x" << HEXWORD << Reg[rdest].u << end(); @@ -468,7 +468,7 @@ case 0x8a: { // copy r/m8 to r8 :(before "End Op ff Subops") case 4: { // jump to r/m32 trace(90, "run") << "jump to r/m32" << end(); - int32_t* arg2 = effective_address(modrm); + const int32_t* arg2 = effective_address(modrm); EIP = *arg2; trace(90, "run") << "jumping to 0x" << HEXWORD << EIP << end(); break; @@ -519,8 +519,8 @@ put(name, "8f", "pop top of stack to rm32"); :(before "End Single-Byte Opcodes") case 0x8f: { // pop stack into r/m32 - uint8_t modrm = next(); - uint8_t subop = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t subop = (modrm>>3)&0x7; switch (subop) { case 0: { trace(90, "run") << "pop into r/m32" << end(); @@ -658,8 +658,8 @@ put(name, "8d", "load effective address of memory in rm32 into r32"); :(before "End Single-Byte Opcodes") case 0x8d: { // lea m32 to r32 - uint8_t modrm = next(); - uint8_t arg1 = (modrm>>3)&0x7; + const uint8_t modrm = next(); + const uint8_t arg1 = (modrm>>3)&0x7; trace(90, "run") << "lea into " << rname(arg1) << end(); Reg[arg1].u = effective_address_number(modrm); break; diff --git a/subx/015immediate_addressing.cc b/subx/015immediate_addressing.cc index b5acc2cb..01f7e040 100644 --- a/subx/015immediate_addressing.cc +++ b/subx/015immediate_addressing.cc @@ -18,11 +18,11 @@ put(name, "81", "combine rm32 with imm32 based on subop"); :(before "End Single-Byte Opcodes") case 0x81: { // combine imm32 with r/m32 trace(90, "run") << "combine imm32 with r/m32" << end(); - uint8_t modrm = next(); + const uint8_t modrm = next(); int32_t* arg1 = effective_address(modrm); - int32_t arg2 = next32(); + const int32_t arg2 = next32(); trace(90, "run") << "imm32 is 0x" << HEXWORD << arg2 << end(); - uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits + const uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits switch (subop) { case 0: trace(90, "run") << "subop add" << end(); @@ -67,7 +67,7 @@ put(name, "2d", "subtract imm32 from R0 (EAX)"); :(before "End Single-Byte Opcodes") case 0x2d: { // subtract imm32 from EAX - int32_t arg2 = next32(); + const int32_t arg2 = next32(); trace(90, "run") << "subtract imm32 0x" << HEXWORD << arg2 << " from EAX" << end(); BINARY_ARITHMETIC_OP(-, Reg[EAX].i, arg2); break; @@ -125,7 +125,7 @@ put(name, "25", "R0 = bitwise AND of imm32 with R0 (EAX)"); :(before "End Single-Byte Opcodes") case 0x25: { // and imm32 with EAX - int32_t arg2 = next32(); + const int32_t arg2 = next32(); trace(90, "run") << "and imm32 0x" << HEXWORD << arg2 << " with EAX" << end(); BINARY_BITWISE_OP(&, Reg[EAX].i, arg2); break; @@ -183,7 +183,7 @@ put(name, "0d", "R0 = bitwise OR of imm32 with R0 (EAX)"); :(before "End Single-Byte Opcodes") case 0x0d: { // or imm32 with EAX - int32_t arg2 = next32(); + const int32_t arg2 = next32(); trace(90, "run") << "or imm32 0x" << HEXWORD << arg2 << " with EAX" << end(); BINARY_BITWISE_OP(|, Reg[EAX].i, arg2); break; @@ -239,7 +239,7 @@ put(name, "35", "R0 = bitwise XOR of imm32 with R0 (EAX)"); :(before "End Single-Byte Opcodes") case 0x35: { // xor imm32 with EAX - int32_t arg2 = next32(); + const int32_t arg2 = next32(); trace(90, "run") << "xor imm32 0x" << HEXWORD << arg2 << " with EAX" << end(); BINARY_BITWISE_OP(^, Reg[EAX].i, arg2); break; @@ -295,13 +295,13 @@ put(name, "3d", "compare: set SF if R0 < imm32"); :(before "End Single-Byte Opcodes") case 0x3d: { // compare EAX with imm32 - int32_t arg1 = Reg[EAX].i; - int32_t arg2 = next32(); + const int32_t arg1 = Reg[EAX].i; + const int32_t arg2 = next32(); trace(90, "run") << "compare EAX and imm32 0x" << HEXWORD << arg2 << end(); - int32_t tmp1 = arg1 - arg2; + const int32_t tmp1 = arg1 - arg2; SF = (tmp1 < 0); ZF = (tmp1 == 0); - int64_t tmp2 = arg1 - arg2; + const int64_t tmp2 = arg1 - arg2; OF = (tmp1 != tmp2); trace(90, "run") << "SF=" << SF << "; ZF=" << ZF << "; OF=" << OF << end(); break; @@ -339,10 +339,10 @@ case 0x3d: { // compare EAX with imm32 :(before "End Op 81 Subops") case 7: { trace(90, "run") << "subop compare" << end(); - int32_t tmp1 = *arg1 - arg2; + const int32_t tmp1 = *arg1 - arg2; SF = (tmp1 < 0); ZF = (tmp1 == 0); - int64_t tmp2 = *arg1 - arg2; + const int64_t tmp2 = *arg1 - arg2; OF = (tmp1 != tmp2); trace(90, "run") << "SF=" << SF << "; ZF=" << ZF << "; OF=" << OF << end(); break; @@ -437,8 +437,8 @@ case 0xbc: case 0xbd: case 0xbe: case 0xbf: { // copy imm32 to r32 - uint8_t rdest = op & 0x7; - int32_t src = next32(); + const uint8_t rdest = op & 0x7; + const int32_t src = next32(); trace(90, "run") << "copy imm32 0x" << HEXWORD << src << " to " << rname(rdest) << end(); Reg[rdest].i = src; break; @@ -461,10 +461,10 @@ put(name, "c7", "copy imm32 to rm32"); :(before "End Single-Byte Opcodes") case 0xc7: { // copy imm32 to r32 - uint8_t modrm = next(); + const uint8_t modrm = next(); trace(90, "run") << "copy imm32 to r/m32" << end(); int32_t* dest = effective_address(modrm); - int32_t src = next32(); + const int32_t src = next32(); trace(90, "run") << "imm32 is 0x" << HEXWORD << src << end(); *dest = src; break; @@ -486,7 +486,7 @@ put(name, "68", "push imm32 to stack"); :(before "End Single-Byte Opcodes") case 0x68: { - uint32_t val = static_cast<uint32_t>(next32()); + const uint32_t val = static_cast<uint32_t>(next32()); trace(90, "run") << "push imm32 0x" << HEXWORD << val << end(); //? cerr << "push: " << val << " => " << Reg[ESP].u << '\n'; push(val); diff --git a/subx/016index_addressing.cc b/subx/016index_addressing.cc index f98d4c0d..3501a522 100644 --- a/subx/016index_addressing.cc +++ b/subx/016index_addressing.cc @@ -21,8 +21,8 @@ case 4: // exception: mod 0b00 rm 0b100 => incoming SIB (scale-index-base) byte break; :(code) uint32_t effective_address_from_sib(uint8_t mod) { - uint8_t sib = next(); - uint8_t base = sib&0x7; + const uint8_t sib = next(); + const uint8_t base = sib&0x7; uint32_t addr = 0; if (base != EBP || mod != 0) { addr = Reg[base].u; @@ -33,13 +33,13 @@ uint32_t effective_address_from_sib(uint8_t mod) { addr = next32(); // ignore base trace(90, "run") << "effective address is initially 0x" << std::hex << addr << " (disp32)" << end(); } - uint8_t index = (sib>>3)&0x7; + const uint8_t index = (sib>>3)&0x7; if (index == ESP) { // ignore index and scale trace(90, "run") << "effective address is 0x" << std::hex << addr << end(); } else { - uint8_t scale = (1 << (sib>>6)); + const uint8_t scale = (1 << (sib>>6)); addr += Reg[index].i*scale; // treat index register as signed. Maybe base as well? But we'll always ensure it's non-negative. trace(90, "run") << "effective address is 0x" << std::hex << addr << " (after adding " << rname(index) << "*" << NUM(scale) << ")" << end(); } diff --git a/subx/017jump_disp8.cc b/subx/017jump_disp8.cc index 57424215..b60d69b6 100644 --- a/subx/017jump_disp8.cc +++ b/subx/017jump_disp8.cc @@ -43,7 +43,7 @@ put(name, "74", "jump disp8 bytes away if ZF is set"); :(before "End Single-Byte Opcodes") case 0x74: { // jump rel8 if ZF - int8_t offset = static_cast<int>(next()); + const int8_t offset = static_cast<int>(next()); if (ZF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -82,7 +82,7 @@ put(name, "75", "jump disp8 bytes away if ZF is not set"); :(before "End Single-Byte Opcodes") case 0x75: { // jump rel8 unless ZF - int8_t offset = static_cast<int>(next()); + const int8_t offset = static_cast<int>(next()); if (!ZF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -123,7 +123,7 @@ put(name, "7f", "jump disp8 bytes away if greater (ZF is unset, SF == OF)"); :(before "End Single-Byte Opcodes") case 0x7f: { // jump rel8 if !SF and !ZF - int8_t offset = static_cast<int>(next()); + const int8_t offset = static_cast<int>(next()); if (!ZF && SF == OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -165,7 +165,7 @@ put(name, "7d", "jump disp8 bytes away if greater or equal (SF == OF)"); :(before "End Single-Byte Opcodes") case 0x7d: { // jump rel8 if !SF - int8_t offset = static_cast<int>(next()); + const int8_t offset = static_cast<int>(next()); if (SF == OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -207,7 +207,7 @@ put(name, "7c", "jump disp8 bytes away if lesser (SF != OF)"); :(before "End Single-Byte Opcodes") case 0x7c: { // jump rel8 if SF and !ZF - int8_t offset = static_cast<int>(next()); + const int8_t offset = static_cast<int>(next()); if (SF != OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -264,7 +264,7 @@ put(name, "7e", "jump disp8 bytes away if lesser or equal (ZF is set or SF != OF :(before "End Single-Byte Opcodes") case 0x7e: { // jump rel8 if SF or ZF - int8_t offset = static_cast<int>(next()); + const int8_t offset = static_cast<int>(next()); if (ZF || SF != OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; diff --git a/subx/018jump_disp16.cc b/subx/018jump_disp16.cc index 1cbb50a4..7adb2321 100644 --- a/subx/018jump_disp16.cc +++ b/subx/018jump_disp16.cc @@ -18,7 +18,7 @@ put(name, "e9", "jump disp16 bytes away"); :(before "End Single-Byte Opcodes") case 0xe9: { // jump rel8 - int16_t offset = imm16(); + const int16_t offset = imm16(); trace(90, "run") << "jump " << offset << end(); EIP += offset; break; @@ -49,7 +49,7 @@ put(name_0f, "84", "jump disp16 bytes away if ZF is set"); :(before "End Two-Byte Opcodes Starting With 0f") case 0x84: { // jump rel16 if ZF - int8_t offset = imm16(); + const int8_t offset = imm16(); if (ZF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -88,7 +88,7 @@ put(name_0f, "85", "jump disp16 bytes away if ZF is not set"); :(before "End Two-Byte Opcodes Starting With 0f") case 0x85: { // jump rel16 unless ZF - int8_t offset = imm16(); + const int8_t offset = imm16(); if (!ZF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -129,7 +129,7 @@ put(name_0f, "8f", "jump disp16 bytes away if greater (ZF is unset, SF == OF)"); :(before "End Two-Byte Opcodes Starting With 0f") case 0x8f: { // jump rel16 if !SF and !ZF - int8_t offset = imm16(); + const int8_t offset = imm16(); if (!ZF && SF == OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -171,7 +171,7 @@ put(name_0f, "8d", "jump disp16 bytes away if greater or equal (SF == OF)"); :(before "End Two-Byte Opcodes Starting With 0f") case 0x8d: { // jump rel16 if !SF - int8_t offset = imm16(); + const int8_t offset = imm16(); if (SF == OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -213,7 +213,7 @@ put(name_0f, "8c", "jump disp16 bytes away if lesser (SF != OF)"); :(before "End Two-Byte Opcodes Starting With 0f") case 0x8c: { // jump rel16 if SF and !ZF - int8_t offset = imm16(); + const int8_t offset = imm16(); if (SF != OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; @@ -270,7 +270,7 @@ put(name_0f, "8e", "jump disp16 bytes away if lesser or equal (ZF is set or SF ! :(before "End Two-Byte Opcodes Starting With 0f") case 0x8e: { // jump rel16 if SF or ZF - int8_t offset = imm16(); + const int8_t offset = imm16(); if (ZF || SF != OF) { trace(90, "run") << "jump " << NUM(offset) << end(); EIP += offset; diff --git a/subx/019functions.cc b/subx/019functions.cc index 18887d27..09f4d690 100644 --- a/subx/019functions.cc +++ b/subx/019functions.cc @@ -16,7 +16,7 @@ put(name, "e8", "call disp32"); :(before "End Single-Byte Opcodes") case 0xe8: { // call disp32 relative to next EIP - int32_t offset = next32(); + const int32_t offset = next32(); trace(90, "run") << "call imm32 0x" << HEXWORD << offset << end(); //? cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n'; push(EIP); @@ -43,7 +43,7 @@ case 0xe8: { // call disp32 relative to next EIP :(before "End Op ff Subops") case 2: { // call function pointer at r/m32 trace(90, "run") << "call to r/m32" << end(); - int32_t* offset = effective_address(modrm); + const int32_t* offset = effective_address(modrm); push(EIP); EIP += *offset; trace(90, "run") << "jumping to 0x" << HEXWORD << EIP << end(); |