summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-05-20 18:46:37 +0300
committerOxore <oxore@protonmail.com>2023-05-20 18:47:34 +0300
commitc9f5a5810435bfc1ce0d231b34628ba12609115c (patch)
tree2c4fe01d90ffe02a62398bcf074d092f432943f7
parent25bf809a867720399cf12f8c0efec86eaeec26c5 (diff)
Impl marks referencing for CMP, ADD and SUB
-rw-r--r--disasm.cpp13
-rw-r--r--test_marks_referencing.bash10
2 files changed, 18 insertions, 5 deletions
diff --git a/disasm.cpp b/disasm.cpp
index 8be3058..b20fd03 100644
--- a/disasm.cpp
+++ b/disasm.cpp
@@ -1290,8 +1290,16 @@ static size_t disasm_add_sub_cmp(
case AddrMode::kAnAddrDecr:
case AddrMode::kD16AnAddr:
case AddrMode::kD8AnXiAddr:
+ break;
case AddrMode::kWord:
case AddrMode::kLong:
+ if (dir_to_addr) {
+ node.ref2_addr = static_cast<uint32_t>(addr.lword);
+ node.ref_kinds = kRef2AbsMask | kRef2ReadMask;
+ } else {
+ node.ref1_addr = static_cast<uint32_t>(addr.lword);
+ node.ref_kinds = kRef1AbsMask | kRef1ReadMask;
+ }
break;
case AddrMode::kD16PCAddr:
case AddrMode::kD8PCXiAddr:
@@ -1299,6 +1307,11 @@ static size_t disasm_add_sub_cmp(
// PC relative cannot be destination
return disasm_verbatim(node, instr);
}
+ if (addr.mode == AddrMode::kD16PCAddr) {
+ node.ref1_addr = node.offset + kInstructionSizeStepBytes +
+ static_cast<uint32_t>(addr.d16_pc.d16);
+ node.ref_kinds = kRef1RelMask | kRef1ReadMask;
+ }
break;
case AddrMode::kImmediate:
if (dir_to_addr) {
diff --git a/test_marks_referencing.bash b/test_marks_referencing.bash
index f7dc40f..9efb42b 100644
--- a/test_marks_referencing.bash
+++ b/test_marks_referencing.bash
@@ -62,7 +62,7 @@ run_check_rdisp() {
}
run_check_r() {
- if grep -e "[^0-9a-zA-Z_(+][0-9]\+" ${file_asm} >/dev/null 2>&1; then
+ if grep -e "[^0-9a-zA-Z_+][0-9]\+" ${file_asm} >/dev/null 2>&1; then
echo -e "${CRED}FAIL${CRST}: raw number or displacement emitted"
cat ${file_asm}
exit
@@ -77,10 +77,6 @@ run_test_rword() {
run_test_r "$1" "$2" "-fmarks -fabs-marks" run_check_r
}
-run_test_rlong() {
- run_test_r "$1" "$2" "-fmarks -fabs-marks" run_check_r
-}
-
run_test_rpcrel() {
run_test_r "$1" "$2" "-fmarks -frel-marks" run_check_r
}
@@ -100,3 +96,7 @@ run_test_rword "peal 0x0:l" "\x48\x79\x00\x00\x00\x00"
run_test_rpcrel "peal (0,PC)" "\x48\x7a\x00\x00"
run_test_rword "nbcd 0x0:w" "\x48\x38\x00\x00"
run_test_rword "nbcd 0x6:l with nop" "\x48\x39\x00\x00\x00\x06\x4e\x71"
+run_test_rword "cmpl 0x4:w, D2 with nop" "\xb4\xb8\x00\x04\x4e\x71"
+run_test_rword "cmpw 0x0:l, D2" "\xb4\x79\x00\x00\x00\x00"
+run_test_rpcrel "cmpl (0,PC), D2" "\xb4\xba\x00\x00"
+run_test_rpcrel "cmpl (-2,PC), D2" "\xb4\xba\xff\xfe"