From 1a62e61df42bfdf001010700c1e1042c67d62ec2 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 7 Sep 2018 22:20:29 -0700 Subject: 4538 --- subx/011run.cc | 6 +++--- subx/014indirect_addressing.cc | 4 ++-- subx/015immediate_addressing.cc | 18 +++++++++--------- subx/016index_addressing.cc | 2 +- subx/019functions.cc | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'subx') diff --git a/subx/011run.cc b/subx/011run.cc index bca04289..e8c7c4a6 100644 --- a/subx/011run.cc +++ b/subx/011run.cc @@ -288,15 +288,15 @@ put(name, "05", "add imm32 to R0 (EAX)"); //: our first opcode :(before "End Single-Byte Opcodes") case 0x05: { // add imm32 to EAX - int32_t arg2 = imm32(); + int32_t arg2 = next32(); trace(90, "run") << "add imm32 0x" << HEXWORD << arg2 << " to reg EAX" << end(); BINARY_ARITHMETIC_OP(+, Reg[EAX].i, arg2); break; } :(code) -// read a 32-bit immediate in little-endian order from the instruction stream -int32_t imm32() { +// read a 32-bit int in little-endian order from the instruction stream +int32_t next32() { int32_t result = next(); result |= (next()<<8); result |= (next()<<16); diff --git a/subx/014indirect_addressing.cc b/subx/014indirect_addressing.cc index 22a3c179..bb102dfd 100644 --- a/subx/014indirect_addressing.cc +++ b/subx/014indirect_addressing.cc @@ -554,7 +554,7 @@ case 0x8f: { // pop stack into r/m32 :(before "End Mod 0 Special-cases(addr)") case 5: // exception: mod 0b00 rm 0b101 => incoming disp32 - addr = imm32(); + addr = next32(); trace(90, "run") << "effective address is 0x" << std::hex << addr << " (disp32)" << end(); break; @@ -629,7 +629,7 @@ case 2: // indirect + disp32 addressing // End Mod 2 Special-cases(addr) } if (addr > 0) { - addr += imm32(); + addr += next32(); trace(90, "run") << "effective address is 0x" << std::hex << addr << " (after adding disp32)" << end(); } break; diff --git a/subx/015immediate_addressing.cc b/subx/015immediate_addressing.cc index b1d97f1e..c6cf843b 100644 --- a/subx/015immediate_addressing.cc +++ b/subx/015immediate_addressing.cc @@ -20,7 +20,7 @@ case 0x81: { // combine imm32 with r/m32 trace(90, "run") << "combine imm32 with r/m32" << end(); uint8_t modrm = next(); int32_t* arg1 = effective_address(modrm); - int32_t arg2 = imm32(); + int32_t arg2 = next32(); trace(90, "run") << "imm32 is 0x" << HEXWORD << arg2 << end(); uint8_t subop = (modrm>>3)&0x7; // middle 3 'reg opcode' bits switch (subop) { @@ -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 = imm32(); + 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 = imm32(); + 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 = imm32(); + 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 = imm32(); + int32_t arg2 = next32(); trace(90, "run") << "xor imm32 0x" << HEXWORD << arg2 << " with EAX" << end(); BINARY_BITWISE_OP(^, Reg[EAX].i, arg2); break; @@ -296,7 +296,7 @@ put(name, "3d", "subtract imm32 from R0 (EAX)"); :(before "End Single-Byte Opcodes") case 0x3d: { // subtract imm32 from EAX int32_t arg1 = Reg[EAX].i; - int32_t arg2 = imm32(); + int32_t arg2 = next32(); trace(90, "run") << "compare EAX and imm32 0x" << HEXWORD << arg2 << end(); int32_t tmp1 = arg1 - arg2; SF = (tmp1 < 0); @@ -438,7 +438,7 @@ case 0xbd: case 0xbe: case 0xbf: { // copy imm32 to r32 uint8_t reg1 = op & 0x7; - int32_t arg2 = imm32(); + int32_t arg2 = next32(); trace(90, "run") << "copy imm32 0x" << HEXWORD << arg2 << " to " << rname(reg1) << end(); Reg[reg1].i = arg2; break; @@ -464,7 +464,7 @@ case 0xc7: { // copy imm32 to r32 uint8_t modrm = next(); trace(90, "run") << "copy imm32 to r/m32" << end(); int32_t* arg1 = effective_address(modrm); - int32_t arg2 = imm32(); + int32_t arg2 = next32(); trace(90, "run") << "imm32 is 0x" << HEXWORD << arg2 << end(); *arg1 = arg2; break; @@ -486,7 +486,7 @@ put(name, "68", "push imm32 to stack"); :(before "End Single-Byte Opcodes") case 0x68: { - uint32_t val = static_cast(imm32()); + uint32_t val = static_cast(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 b1b7e563..58169083 100644 --- a/subx/016index_addressing.cc +++ b/subx/016index_addressing.cc @@ -30,7 +30,7 @@ uint32_t effective_address_from_sib(uint8_t mod) { } else { // base == EBP && mod == 0 - addr = imm32(); // ignore base + addr = next32(); // ignore base trace(90, "run") << "effective address is initially 0x" << std::hex << addr << " (disp32)" << end(); } uint8_t index = (sib>>3)&0x7; diff --git a/subx/019functions.cc b/subx/019functions.cc index 964ca977..fbc7e605 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 = imm32(); + int32_t offset = next32(); trace(90, "run") << "call imm32 0x" << HEXWORD << offset << end(); //? cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n'; push(EIP); -- cgit 1.4.1-2-gfad0