diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-02-18 10:50:14 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-02-18 10:51:55 +0100 |
| commit | 17ac46af6cafd437dce47808db357b2c6fb40146 (patch) | |
| tree | 78f5ed82118e89b24245538d29375934e682e1d1 | |
| parent | a7686350855be22e3322f0df6ceb22964bf75965 (diff) | |
i64asm: WiP: mov instruction implementation, also set structures to big-endian only.
Set assert(false) if 16 bit register, it is unimplemented.
For now.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | Private/CompilerKit/Defines.hpp | 2 | ||||
| -rw-r--r-- | Private/Toolchain/bin/Source/hello_amd64.masm | 2 | ||||
| -rw-r--r-- | Private/Toolchain/i64asm.cc | 43 |
3 files changed, 38 insertions, 9 deletions
diff --git a/Private/CompilerKit/Defines.hpp b/Private/CompilerKit/Defines.hpp index 15d5ad8..a356a9f 100644 --- a/Private/CompilerKit/Defines.hpp +++ b/Private/CompilerKit/Defines.hpp @@ -133,4 +133,6 @@ typedef char char_type; #define MPCC_MODULE(name) int main(int argc, char **argv) #endif /* ifdef __MODULE_NEED__ */ +#pragma scalar_storage_order big-endian + #endif /* ifndef __MPCC_DEFINES_HPP__ */ diff --git a/Private/Toolchain/bin/Source/hello_amd64.masm b/Private/Toolchain/bin/Source/hello_amd64.masm index 2223305..da77b1b 100644 --- a/Private/Toolchain/bin/Source/hello_amd64.masm +++ b/Private/Toolchain/bin/Source/hello_amd64.masm @@ -11,7 +11,7 @@ retf export .text __start cli -mov rsp, rdx +mov rdx, rsi int 0x80 jmp 0x100000 sti diff --git a/Private/Toolchain/i64asm.cc b/Private/Toolchain/i64asm.cc index 55719cf..cd441a0 100644 --- a/Private/Toolchain/i64asm.cc +++ b/Private/Toolchain/i64asm.cc @@ -987,7 +987,7 @@ bool CompilerKit::PlatformAssemblerAMD64::WriteLine(std::string &line, e64_byte_t fModRM; }; - std::vector<RegMapAMD64> regsPt2{ + std::vector<RegMapAMD64> regs{ {.fName = "ax", .fModRM = 0b000}, {.fName = "cx", .fModRM = 0b001}, {.fName = "dx", .fModRM = 0b010}, {.fName = "bx", .fModRM = 0b011}, {.fName = "sp", .fModRM = 0b100}, {.fName = "bp", .fModRM = 0b101}, @@ -1011,10 +1011,35 @@ bool CompilerKit::PlatformAssemblerAMD64::WriteLine(std::string &line, throw std::runtime_error("comb_op_reg"); } - bits = 64; - bool noRightRegister = false; + std::vector<RegMapAMD64> currentRegList; + + for (auto& reg : regs) { + std::vector<char> regExt = { 'e', 'r' }; + + for (auto& ext : regExt) { + std::string registerName; + registerName.push_back(ext); + registerName += reg.fName; + + while (line.find(registerName) != std::string::npos) { + if (ext == 'r') + bits = 64; + else if (ext == 'e') + bits = 32; + + line.erase(line.find(registerName), registerName.size()); + std::cout << registerName << std::endl; + + currentRegList.push_back({ .fName = registerName, .fModRM = reg.fModRM }); + } + } + } + + if (currentRegList.size() > 1) + noRightRegister = false; + if (!noRightRegister) { if (bits == 64 || bits == 32) @@ -1024,23 +1049,25 @@ bool CompilerKit::PlatformAssemblerAMD64::WriteLine(std::string &line, kBytes.emplace_back(0x89); - // TODO + auto byte = 0xe0; + + - this->WriteNumber32(line.find(name) + name.size() + 2, line); + kBytes.push_back(byte); } else if (bits == 16) { kBytes.emplace_back(0x66); kBytes.emplace_back(0x89); - // TODO - - this->WriteNumber16(line.find(name) + name.size() + 2, line); + assert(false); } else { detail::print_error("Invalid combination of operands and registers.", "i64asm"); throw std::runtime_error("comb_op_reg"); } + } else { + } break; |
