diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-28 08:17:02 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-28 08:17:02 +0200 |
| commit | f84498ff447cc4bf891999e782ef90bfbc9577bd (patch) | |
| tree | a29aac9395fb9fc068b59942bf6befb1fb02f3b9 | |
| parent | c18972980351335ef65029aae677bac76c70d161 (diff) | |
MHR-21: Add support for cmp* instructions in POWER, fix AMD64 assembler,
the origin doesn't get incremented.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | Examples/ExampleCDialect.S | 7 | ||||
| -rw-r--r-- | Sources/64asm.cc | 4 | ||||
| -rw-r--r-- | Sources/64x0-cc.cc | 4 | ||||
| -rw-r--r-- | Sources/i64asm.cc | 4 | ||||
| -rw-r--r-- | Sources/ppc-cc.cc | 6 | ||||
| -rw-r--r-- | Sources/ppcasm.cc | 37 |
6 files changed, 47 insertions, 15 deletions
diff --git a/Examples/ExampleCDialect.S b/Examples/ExampleCDialect.S index 5182381..d937aed 100644 --- a/Examples/ExampleCDialect.S +++ b/Examples/ExampleCDialect.S @@ -1,6 +1,6 @@ # Path: Examples/ExampleCDialect.c # Language: POWER Assembly (Generated from C) -# Build Date: 2024-4-16 +# Build Date: 2024-4-28 @@ -14,8 +14,8 @@ dword export .code64 __ImageStart li r3,0x1000 cmpw r10, r11 - beq import__MPCC_IF_PROC_6168864856 -dword export .code64 __MPCC_IF_PROC_6168864856 + beq import __MPCC_IF_PROC_6099380296 +dword export .code64 __MPCC_IF_PROC_6099380296 @@ -25,3 +25,4 @@ dword export .code64 __MPCC_IF_PROC_6168864856 mr r31, r0 blr + diff --git a/Sources/64asm.cc b/Sources/64asm.cc index a3b3f00..d2568e2 100644 --- a/Sources/64asm.cc +++ b/Sources/64asm.cc @@ -50,6 +50,8 @@ static Boolean kOutputAsBinary = false; static UInt32 kErrorLimit = 10; static UInt32 kAcceptableErrors = 0; +constexpr auto c64x0IPAlignment = 0x4U; + static std::size_t kCounter = 1UL; static std::uintptr_t kOrigin = kPefBaseOrigin; @@ -940,7 +942,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string &line, } asm_end_label_cpy: - kOrigin += 0x04; + kOrigin += c64x0IPAlignment; break; } diff --git a/Sources/64x0-cc.cc b/Sources/64x0-cc.cc index 9492b6e..b56ad86 100644 --- a/Sources/64x0-cc.cc +++ b/Sources/64x0-cc.cc @@ -28,11 +28,11 @@ /// TODO: support structures, else if, else, ., -> /* C driver */ -/* This is part of MultiProcessor C SDK. */ +/* This is part of CodeTools C SDK. */ /* (c) Mahrouss Logic */ /// @author Amlal El Mahrouss (amlel) -/// @file cc.cc +/// @file 64x0-cc.cc /// @brief 64x0 C Compiler. ///////////////////// diff --git a/Sources/i64asm.cc b/Sources/i64asm.cc index 67e4c42..dee3053 100644 --- a/Sources/i64asm.cc +++ b/Sources/i64asm.cc @@ -59,6 +59,8 @@ static Boolean kOutputAsBinary = false; static UInt32 kErrorLimit = 10; static UInt32 kAcceptableErrors = 0; +constexpr auto cAMD64IPAlignment = 0x4U; + static std::size_t kCounter = 1UL; static std::uintptr_t kOrigin = kPefBaseOrigin; @@ -1237,6 +1239,8 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string &line, this->WriteNumber16(line.find(".word") + strlen(".word") + 1, line); } + kOrigin += cAMD64IPAlignment; + return true; } diff --git a/Sources/ppc-cc.cc b/Sources/ppc-cc.cc index 5b0c334..8c8909c 100644 --- a/Sources/ppc-cc.cc +++ b/Sources/ppc-cc.cc @@ -28,7 +28,7 @@ /// TODO: support structures, else if, else, ., -> /* C driver */ -/* This is part of MultiProcessor C SDK. */ +/* This is part of CodeTools C SDK. */ /* (c) Mahrouss Logic */ /// @author Amlal El Mahrouss (amlel) @@ -370,7 +370,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { "\tcmpw " "r10, r11"; - syntaxLeaf.fUserValue += "\n\tbeq import" + kIfFunction + + syntaxLeaf.fUserValue += "\n\tbeq import " + kIfFunction + " \ndword export .code64 " + kIfFunction + "\n"; kState.fSyntaxTree->fLeafList.push_back(syntaxLeaf); @@ -601,7 +601,7 @@ bool CompilerBackendCLang::Compile(const std::string &text, const char *file) { } args += args_buffer; - args += "\n\tli r19, "; + args += "\n\tli r31, "; } } diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc index f95020e..9d12922 100644 --- a/Sources/ppcasm.cc +++ b/Sources/ppcasm.cc @@ -48,6 +48,8 @@ static CharType kOutputArch = CompilerKit::kPefArchPowerPC; static Boolean kOutputAsBinary = false; +constexpr auto cPowerIPAlignment = 0x4U; + static UInt32 kErrorLimit = 10; static UInt32 kAcceptableErrors = 0; @@ -677,6 +679,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, if (ParserKit::find_word(line, opcodePPC.name)) { std::string name(opcodePPC.name); std::string jump_label, cpy_jump_label; + std::vector<size_t> found_registers_index; // check funct7 type. switch (opcodePPC.ops->type) { @@ -833,9 +836,9 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, } ++register_count; + ++found_some_count; } - /// FIXME: Prompt correct opcode in little endian. if (opcodeName == "addi") { if (found_some_count == 2 || found_some_count == 0) kBytes.emplace_back(reg_index); @@ -850,6 +853,15 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, } } + if (opcodeName.find("cmp") != std::string::npos) { + ++found_some_count; + + if (found_some_count > 3) { + detail::print_error("Too much registers. -> " + line, file); + throw std::runtime_error("too_much_regs"); + } + } + if (opcodeName.find("mf") != std::string::npos || opcodeName.find("mt") != std::string::npos) { char numIndex = 0; @@ -886,15 +898,29 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, for (auto ch : num.number) { kBytes.emplace_back(ch); } - - break; } + + found_registers_index.push_back(reg_index); } } if (opcodeName == "addi") { kBytes.emplace_back(0x38); } + + if (opcodeName.find("cmp") != std::string::npos) { + char rightReg = 0; + + for (size_t i = 0; i != found_registers_index[0]; i++) { + rightReg += 0x08; + } + + kBytes.emplace_back(0x00); + kBytes.emplace_back(rightReg); + kBytes.emplace_back(found_registers_index[1]); + kBytes.emplace_back(0x7c); + } + if ((opcodeName[0] == 's' && opcodeName[1] == 't')) { size_t offset = 0UL; @@ -913,8 +939,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, if (opcodeName == "mr") { if (register_count == 1) { detail::print_error("Too few registers. -> " + line, file); - - throw std::runtime_error("not_a_register"); + throw std::runtime_error("too_few_registers"); } } @@ -943,7 +968,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, } } - kOrigin += 0x04; + kOrigin += cPowerIPAlignment; break; } } |
