From 488fceb42bd532a33ed275294e7bad8200099ebc Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 5 Oct 2023 11:23:58 -0400 Subject: [PATCH] Clean up, add a TODO. --- InstructionSets/x86/DataPointerResolver.hpp | 70 ++++++++++--------- .../Clock Signal.xcodeproj/project.pbxproj | 2 + 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/InstructionSets/x86/DataPointerResolver.hpp b/InstructionSets/x86/DataPointerResolver.hpp index 056aa9476..306c87e4c 100644 --- a/InstructionSets/x86/DataPointerResolver.hpp +++ b/InstructionSets/x86/DataPointerResolver.hpp @@ -215,44 +215,45 @@ template uint32_t DataPointerResolver::effective_address( RegistersT ®isters, const Instruction &instruction, - DataPointer pointer) { - using AddressT = typename Instruction::AddressT; - AddressT base = 0, index = 0; + DataPointer pointer +) { + using AddressT = typename Instruction::AddressT; + AddressT base = 0, index = 0; - if constexpr (has_base) { - switch(pointer.base()) { - default: break; - ALLREGS(base, false); - } - } - - switch(pointer.index()) { + if constexpr (has_base) { + switch(pointer.base()) { default: break; - ALLREGS(index, false); + ALLREGS(base, false); } - - uint32_t address = index; - if constexpr (model >= Model::i80386) { - address <<= pointer.scale(); - } else { - assert(!pointer.scale()); - } - - // Always compute address as 32-bit. - // TODO: verify use of memory_mask around here. - // Also I think possibly an exception is supposed to be generated - // if the programmer is in 32-bit mode and has asked for 16-bit - // address computation but generated e.g. a 17-bit result. Look into - // that when working on execution. For now the goal is merely decoding - // and this code exists both to verify the presence of all necessary - // fields and to help to explore the best breakdown of storage - // within Instruction. - constexpr uint32_t memory_masks[] = {0x0000'ffff, 0xffff'ffff}; - const uint32_t memory_mask = memory_masks[int(instruction.address_size())]; - address = (address & memory_mask) + (base & memory_mask) + instruction.displacement(); - return address; } + switch(pointer.index()) { + default: break; + ALLREGS(index, false); + } + + uint32_t address = index; + if constexpr (model >= Model::i80386) { + address <<= pointer.scale(); + } else { + assert(!pointer.scale()); + } + + // Always compute address as 32-bit. + // TODO: verify use of memory_mask around here. + // Also I think possibly an exception is supposed to be generated + // if the programmer is in 32-bit mode and has asked for 16-bit + // address computation but generated e.g. a 17-bit result. Look into + // that when working on execution. For now the goal is merely decoding + // and this code exists both to verify the presence of all necessary + // fields and to help to explore the best breakdown of storage + // within Instruction. + constexpr uint32_t memory_masks[] = {0x0000'ffff, 0xffff'ffff}; + const uint32_t memory_mask = memory_masks[int(instruction.address_size())]; + address = (address & memory_mask) + (base & memory_mask) + instruction.displacement(); + return address; +} + template template void DataPointerResolver::access( RegistersT ®isters, @@ -282,6 +283,9 @@ template void DataPointerResolver \ (registers, instruction, pointer); \ diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index a79d0850e..a285bc85d 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -1127,6 +1127,7 @@ /* Begin PBXFileReference section */ 423BDC492AB24699008E37B6 /* 8088Tests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = 8088Tests.mm; sourceTree = ""; }; 42437B342ACF02A9006DFED1 /* Status.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Status.hpp; sourceTree = ""; }; + 42437B352ACF0AA2006DFED1 /* Perform.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Perform.hpp; sourceTree = ""; }; 4281572E2AA0334300E16AA1 /* Carry.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Carry.hpp; sourceTree = ""; }; 428168372A16C25C008ECD27 /* LineLayout.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = LineLayout.hpp; sourceTree = ""; }; 428168392A37AFB4008ECD27 /* DispatcherTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DispatcherTests.mm; sourceTree = ""; }; @@ -4995,6 +4996,7 @@ 4BEDA3DB25B2588F000C2DBD /* Instruction.hpp */, 4BE3C69527CBC540000EAD28 /* Model.hpp */, 42437B342ACF02A9006DFED1 /* Status.hpp */, + 42437B352ACF0AA2006DFED1 /* Perform.hpp */, ); path = x86; sourceTree = "";