[UNTESTED] complete initial disassembler structure for ARM

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-09-15 05:23:07 +05:30
parent 169723275e
commit 7fc6876264
9 changed files with 701 additions and 149 deletions

View File

@@ -35,13 +35,45 @@ operator<<(std::ostream& os, const Condition cond) {
return os;
}
std::ostream&
operator<<(std::ostream& os, const OpCode opcode) {
#define CASE(opcode) \
case OpCode::opcode: \
os << #opcode; \
break;
switch (opcode) {
CASE(AND)
CASE(EOR)
CASE(SUB)
CASE(RSB)
CASE(ADD)
CASE(ADC)
CASE(SBC)
CASE(RSC)
CASE(TST)
CASE(TEQ)
CASE(CMP)
CASE(CMN)
CASE(ORR)
CASE(MOV)
CASE(BIC)
CASE(MVN)
}
#undef CASE
return os;
}
uint32_t
eval_shift(ShiftType shift_type, uint32_t value, uint8_t amount, bool& carry) {
switch (shift_type) {
case ShiftType::LSL:
if (amount > 0 && amount <= 32)
carry = get_nth_bit(value, 32 - amount);
carry = get_bit(value, 32 - amount);
else if (amount > 32)
carry = 0;
@@ -49,28 +81,28 @@ eval_shift(ShiftType shift_type, uint32_t value, uint8_t amount, bool& carry) {
case ShiftType::LSR:
if (amount > 0 && amount <= 32)
carry = get_nth_bit(value, amount - 1);
carry = get_bit(value, amount - 1);
else if (amount > 32)
carry = 0;
else
carry = get_nth_bit(value, 31);
carry = get_bit(value, 31);
return value >> amount;
case ShiftType::ASR:
if (amount > 0 && amount <= 32)
carry = get_nth_bit(value, amount - 1);
carry = get_bit(value, amount - 1);
else
carry = get_nth_bit(value, 31);
carry = get_bit(value, 31);
return static_cast<int32_t>(value) >> amount;
case ShiftType::ROR:
if (amount == 0) {
bool old_carry = carry;
carry = get_nth_bit(value, 0);
carry = get_bit(value, 0);
return (value >> 1) | (old_carry << 31);
} else {
carry = get_nth_bit(value, (amount % 32 + 31) % 32);
carry = get_bit(value, (amount % 32 + 31) % 32);
return std::rotr(value, amount);
}
}