diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-20 17:30:19 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-20 17:30:19 +0200 |
| commit | 8e4528d5ab4fd29adf3c0290c94defc99d04547c (patch) | |
| tree | 74a22abebcff87a9411bd2d9195a3ea83ae129b4 /Sources | |
| parent | 7a9b0bc9858ffa49687f240535c76328417bc648 (diff) | |
MHR-4: MHR-7: Task completed.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Sources')
| -rw-r--r-- | Sources/Detail/asmutils.h | 50 | ||||
| -rw-r--r-- | Sources/ppcasm.cc | 31 |
2 files changed, 55 insertions, 26 deletions
diff --git a/Sources/Detail/asmutils.h b/Sources/Detail/asmutils.h index 6a7d055..4718412 100644 --- a/Sources/Detail/asmutils.h +++ b/Sources/Detail/asmutils.h @@ -2,85 +2,85 @@ using namespace CompilerKit; -/// @brief Get Number from line. -/// @param line -/// @param name +/// @brief Get Number from lineBuffer. +/// @param lineBuffer the lineBuffer to fetch from. +/// @param numberKey where to seek that number. /// @return -static NumberCast32 GetNumber32(std::string line, std::string name) { - auto pos = line.find(name) + name.size(); +static NumberCast32 GetNumber32(std::string lineBuffer, std::string numberKey) { + auto pos = lineBuffer.find(numberKey) + numberKey.size(); - if (line.find(",") != std::string::npos) line.erase(line.find(","), 1); + if (lineBuffer.find(",") != std::string::npos) lineBuffer.erase(lineBuffer.find(","), 1); - while (line[pos] == ' ') ++pos; + while (lineBuffer[pos] == ' ') ++pos; - switch (line[pos + 1]) { + switch (lineBuffer[pos + 1]) { case 'x': { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 16); !res) { + if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 16); !res) { if (errno != 0) { - detail::print_error("invalid hex number: " + line, "ppcasm"); + detail::print_error("invalid hex number: " + lineBuffer, "ppcasm"); throw std::runtime_error("invalid_hex"); } } - NumberCast32 numOffset(strtol(line.substr(pos).c_str(), nullptr, 16)); + NumberCast32 numOffset(strtol(lineBuffer.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: " << lineBuffer.substr(pos) << "\n"; } return numOffset; } case 'b': { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 2); !res) { + if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 2); !res) { if (errno != 0) { - detail::print_error("invalid binary number:" + line, "ppcasm"); + detail::print_error("invalid binary number:" + lineBuffer, "ppcasm"); throw std::runtime_error("invalid_bin"); } } - NumberCast32 numOffset(strtol(line.substr(pos).c_str(), nullptr, 2)); + NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 2)); if (kVerbose) { - kStdOut << "ppcasm: found a base 2 number here:" << line.substr(pos) + kStdOut << "ppcasm: found a base 2 number here:" << lineBuffer.substr(pos) << "\n"; } return numOffset; } case 'o': { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 7); !res) { + if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 7); !res) { if (errno != 0) { - detail::print_error("invalid octal number: " + line, "ppcasm"); + detail::print_error("invalid octal number: " + lineBuffer, "ppcasm"); throw std::runtime_error("invalid_octal"); } } - NumberCast32 numOffset(strtol(line.substr(pos).c_str(), nullptr, 7)); + NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 7)); if (kVerbose) { - kStdOut << "ppcasm: found a base 8 number here:" << line.substr(pos) + kStdOut << "ppcasm: found a base 8 number here:" << lineBuffer.substr(pos) << "\n"; } return numOffset; } default: { - if (auto res = strtol(line.substr(pos).c_str(), nullptr, 10); !res) { + if (auto res = strtol(lineBuffer.substr(pos).c_str(), nullptr, 10); !res) { if (errno != 0) { - detail::print_error("invalid hex number: " + line, "ppcasm"); + detail::print_error("invalid hex number: " + lineBuffer, "ppcasm"); throw std::runtime_error("invalid_hex"); } } - NumberCast32 numOffset(strtol(line.substr(pos).c_str(), nullptr, 10)); + NumberCast32 numOffset(strtol(lineBuffer.substr(pos).c_str(), nullptr, 10)); if (kVerbose) { - kStdOut << "ppcasm: found a base 10 number here:" << line.substr(pos) + kStdOut << "ppcasm: found a base 10 number here:" << lineBuffer.substr(pos) << "\n"; } return numOffset; } } -}
\ No newline at end of file +} diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc index d2551e4..f83af8a 100644 --- a/Sources/ppcasm.cc +++ b/Sources/ppcasm.cc @@ -710,6 +710,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, std::size_t found_some_count = 0UL; std::size_t register_count = 0UL; std::string opcodeName = opcodePPC.name; + std::size_t register_sum = 0; NumberCast64 num(opcodePPC.opcode); @@ -776,6 +777,18 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, break; } + if ((opcodeName[0] == 's' && opcodeName[1] == 't')) { + if (register_sum == 0) { + for (size_t indexReg = 0UL; indexReg < reg_index; ++indexReg) { + register_sum += 0x20; + + } + } + else { + register_sum += reg_index; + } + } + if (opcodeName == "mr") { switch (register_count) { case 0: { @@ -884,6 +897,22 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, if (opcodeName == "addi") { kBytes.emplace_back(0x38); } + if ((opcodeName[0] == 's' && + opcodeName[1] == 't') + ) { + size_t offset = 0UL; + + if (line.find('+') != std::string::npos) { + auto number = GetNumber32(line.substr(line.find("+")), "+"); + offset = number.raw; + } + + kBytes.push_back(offset); + kBytes.push_back(0x00); + kBytes.push_back(register_sum); + + kBytes.emplace_back(0x90); + } if (opcodeName == "mr") { if (register_count == 1) { @@ -907,7 +936,7 @@ bool CompilerKit::EncoderPowerPC::WriteLine(std::string &line, } } - if (found_some_count < 1 && name[0] != 'l' && name[0] == 's') { + if (found_some_count < 1 && name[0] != 'l' && name[0] != 's') { detail::print_error( "invalid combination of opcode and registers.\nline: " + line, file); |
