diff options
| author | Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com> | 2024-04-08 23:18:11 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com> | 2024-04-08 23:18:11 +0200 |
| commit | 59c1a314fd058111acd428d0625d98e4531fdb5c (patch) | |
| tree | b097435475bbca8eef84c009d778cf3da37cb18f /Sources | |
| parent | 91465412c388dbbff1b956330eb19e43e2e41b0f (diff) | |
PowerPCAsm: Adding 'addi' and more error handling.
Signed-off-by: Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>
Diffstat (limited to 'Sources')
| -rw-r--r-- | Sources/64asm.cc | 2 | ||||
| -rw-r--r-- | Sources/ppcasm.cc | 46 |
2 files changed, 39 insertions, 9 deletions
diff --git a/Sources/64asm.cc b/Sources/64asm.cc index a89fbb6..564542f 100644 --- a/Sources/64asm.cc +++ b/Sources/64asm.cc @@ -735,7 +735,7 @@ bool CompilerKit::Encoder64x0::WriteLine(std::string &line, // remember! register to register! if (found_some == 1) { detail::print_error( - "Unrecognized register found.\ntip: each 64asm register " + "Too few registers.\ntip: each 64asm register " "starts with 'r'.\nline: " + line, file); diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc index 7a253a7..ade0272 100644 --- a/Sources/ppcasm.cc +++ b/Sources/ppcasm.cc @@ -684,7 +684,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, case BADDR: case PCREL: { auto num = GetNumber32(line, name); - + kBytes.emplace_back(num.number[0]); kBytes.emplace_back(num.number[1]); kBytes.emplace_back(num.number[2]); @@ -692,7 +692,8 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, break; } - /// General purpose, float, vector operations. Everything that involve registers. + /// General purpose, float, vector operations. Everything that involve + /// registers. case G0REG: case FREG: case VREG: @@ -802,7 +803,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, else if (reg_index >= 20 && reg_index < 30) kBytes.push_back(0x7e); else if (reg_index >= 30) - kBytes.push_back(0x7e); + kBytes.push_back(0x7f); else kBytes.push_back(0x7c); @@ -815,6 +816,21 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, ++register_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); + else if (found_some_count == 1) kBytes.emplace_back(0x00); + + ++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; @@ -827,6 +843,11 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, ++found_some_count; + if (found_some_count > 1) { + detail::print_error("Too much registers. -> " + line, file); + throw std::runtime_error("too_much_regs"); + } + if (kVerbose) { kStdOut << "ppcasm: Found register: " << register_syntax << "\n"; @@ -834,6 +855,15 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, << found_some_count << "\n"; } + if (reg_index >= 10 && reg_index < 20) + num.number[3] = 0x7d; + else if (reg_index >= 20 && reg_index < 30) + num.number[3] = 0x7e; + else if (reg_index >= 30) + num.number[3] = 0x7f; + else + num.number[3] = 0x7c; + for (auto ch : num.number) { kBytes.emplace_back(ch); } @@ -843,13 +873,13 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, } } + if (opcodeName == "addi") { + kBytes.emplace_back(0x38); + } + if (opcodeName == "mr") { if (register_count == 1) { - detail::print_error( - "Unrecognized register found.\ntip: each ppcasm register " - "starts with 'r'.\nline: " + - line, - file); + detail::print_error("Too few registers. -> " + line, file); throw std::runtime_error("not_a_register"); } |
