diff options
| author | Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com> | 2024-04-08 01:44:07 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com> | 2024-04-08 01:44:07 +0200 |
| commit | d014d88a360fdf8fcff52ec3c771f4af707e1831 (patch) | |
| tree | 5d68534e5acd98c31ee65314e60ce7e65e426531 | |
| parent | 5cf92b502d4d2bd026f580dc93ba243f657b0e79 (diff) | |
Fix PowerPC branch instructions; using our new GetNumber32, fix li instruction (was big endian thus
mixed)
Signed-off-by: Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>
| -rw-r--r-- | Examples/ExamplePowerPC.S.pp | 8 | ||||
| -rw-r--r-- | Examples/ExamplePowerPC.dmp | 5 | ||||
| -rw-r--r-- | Sources/Detail/asmutils.h | 2 | ||||
| -rw-r--r-- | Sources/ppcasm.cc | 113 |
4 files changed, 21 insertions, 107 deletions
diff --git a/Examples/ExamplePowerPC.S.pp b/Examples/ExamplePowerPC.S.pp index bc4d6a1..0f7acf3 100644 --- a/Examples/ExamplePowerPC.S.pp +++ b/Examples/ExamplePowerPC.S.pp @@ -2,4 +2,10 @@ # Language: PowerPC Assembly # Build Date: 2024-6-4 -li r2, 0x1055
\ No newline at end of file +bl 0x1000 + + +li r1, 0x500 +mr r2, r1 +sc +blr diff --git a/Examples/ExamplePowerPC.dmp b/Examples/ExamplePowerPC.dmp new file mode 100644 index 0000000..5986d03 --- /dev/null +++ b/Examples/ExamplePowerPC.dmp @@ -0,0 +1,5 @@ +0x0000000000000000: 00 10 00 48 b 0x1000 +0x0000000000000004: 00 05 20 38 li r1, 0x500 +0x0000000000000008: 78 13 21 7C or r1, r1, r2 +0x000000000000000c: 02 00 00 44 sc +0x0000000000000010: 20 00 80 4E blr
\ No newline at end of file diff --git a/Sources/Detail/asmutils.h b/Sources/Detail/asmutils.h index 06209a5..00d4daa 100644 --- a/Sources/Detail/asmutils.h +++ b/Sources/Detail/asmutils.h @@ -25,7 +25,7 @@ static NumberCast32 GetNumber32(std::string line, std::string name) { NumberCast32 numOffset(strtol(line.substr(pos).c_str(), nullptr, 16)); if (kVerbose) { - kStdOut << "ppcasm: found a base 16 number here:" << line.substr(pos) + kStdOut << "ppcasm: found a base 16 number here: " << line.substr(pos) << "\n"; } diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc index 45e407e..5ba3ff0 100644 --- a/Sources/ppcasm.cc +++ b/Sources/ppcasm.cc @@ -683,108 +683,12 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, } case BADDR: case PCREL: { - auto pos = line.find(opcodePPC.name) + strlen(opcodePPC.name); - - switch (line[pos + 1]) { - case 'x': { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 16); - !res) { - if (errno != 0) { - detail::print_error("invalid hex number: " + line, "ppcasm"); - throw std::runtime_error("invalid_hex"); - } - } - - NumberCast32 numOffset( - strtol(line.substr(pos).c_str(), nullptr, 16)); - - if (kVerbose) { - kStdOut << "ppcasm: found a base 16 number here:" - << line.substr(pos) << "\n"; - } - - kBytes.emplace_back(numOffset.number[0]); - kBytes.emplace_back(numOffset.number[1]); - kBytes.emplace_back(numOffset.number[2]); - kBytes.emplace_back(0x48); - - break; - } - case 'b': { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 2); - !res) { - if (errno != 0) { - detail::print_error("invalid binary number:" + line, - "ppcasm"); - throw std::runtime_error("invalid_bin"); - } - } - - NumberCast32 numOffset( - strtol(line.substr(pos).c_str(), nullptr, 2)); - - if (kVerbose) { - kStdOut << "ppcasm: found a base 2 number here:" - << line.substr(pos) << "\n"; - } - - kBytes.emplace_back(numOffset.number[0]); - kBytes.emplace_back(numOffset.number[1]); - kBytes.emplace_back(numOffset.number[2]); - kBytes.emplace_back(0x48); - - break; - } - case 'o': { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 7); - !res) { - if (errno != 0) { - detail::print_error("invalid octal number: " + line, - "ppcasm"); - throw std::runtime_error("invalid_octal"); - } - } - - NumberCast32 numOffset( - strtol(line.substr(pos).c_str(), nullptr, 7)); - - if (kVerbose) { - kStdOut << "ppcasm: found a base 8 number here:" - << line.substr(pos) << "\n"; - } - - kBytes.emplace_back(numOffset.number[0]); - kBytes.emplace_back(numOffset.number[1]); - kBytes.emplace_back(numOffset.number[2]); - kBytes.emplace_back(0x48); - - break; - } - default: { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 10); - !res) { - if (errno != 0) { - detail::print_error("invalid hex number: " + line, "ppcasm"); - throw std::runtime_error("invalid_hex"); - } - } - - NumberCast32 numOffset( - strtol(line.substr(pos).c_str(), nullptr, 10)); - - if (kVerbose) { - kStdOut << "ppcasm: found a base 10 number here:" - << line.substr(pos) << "\n"; - } - - kBytes.emplace_back(numOffset.number[0]); - kBytes.emplace_back(numOffset.number[1]); - kBytes.emplace_back(numOffset.number[2]); - kBytes.emplace_back(0x48); - - break; - } - } + auto num = GetNumber32(line, name); + + kBytes.emplace_back(num.number[0]); + kBytes.emplace_back(num.number[1]); + kBytes.emplace_back(num.number[2]); + kBytes.emplace_back(0x48); break; } @@ -844,13 +748,12 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, numIndex += 0x20; } - kBytes.push_back(0x38); - kBytes.push_back(numIndex); - auto num = GetNumber32(line, reg_str); kBytes.push_back(num.number[0]); kBytes.push_back(num.number[1]); + kBytes.push_back(numIndex); + kBytes.push_back(0x38); // check if bigger than two. for (size_t i = 2; i < 4; i++) { |
