summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--disasm.cpp64
-rw-r--r--test.bash16
-rw-r--r--test.ld16
3 files changed, 61 insertions, 35 deletions
diff --git a/disasm.cpp b/disasm.cpp
index ebf3926..9c3ea5b 100644
--- a/disasm.cpp
+++ b/disasm.cpp
@@ -28,20 +28,20 @@ static void disasm_jsr_jmp(
const int m = (addrmode >> 3) & 0x7;
const int xn = addrmode & 0x7;
switch (m) {
- case 0: // 4e80 .. 4e87
- case 1: // 4e88 .. 4e8f
+ case 0: // 4e80..4e87 / 4ec0..4ec7
+ case 1: // 4e88..4e8f / 4ec8..4ecf
break;
- case 2: // 4e90 .. 4e97
+ case 2: // 4e90..4e97 / 4ed0..4ed7
// NOTE: dynamic jump, branch_addr may possibly be obtained during the
// trace
node.size = kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "%s", mnemonic);
snprintf(node.arguments, kArgsBufferSize, "%%a%d@", xn);
return;
- case 3: // 4e98 .. 4e9f
- case 4: // 4ea0 .. 4ea7
+ case 3: // 4e98..4e9f / 4ed8..4edf
+ case 4: // 4ea0..4ea7 / 4ee0..4ee7
break;
- case 5: // 4ea8 .. 4eaf, Displacement
+ case 5: // 4ea8..4eaf / 4ee8..4eef, Displacement
{
// NOTE: dynamic jump, branch_addr may possibly be obtained during
// the trace
@@ -51,7 +51,7 @@ static void disasm_jsr_jmp(
snprintf(node.arguments, kArgsBufferSize, "%%a%d@(%d:w)", xn, dispmt);
return;
}
- case 6: // 4eb0 .. 4eb7, Brief Extension Word
+ case 6: // 4eb0..4eb7 / 4ef0..4ef7, Brief Extension Word
{
// NOTE: dynamic jump, branch_addr may possibly be obtained during
// the trace
@@ -66,9 +66,9 @@ static void disasm_jsr_jmp(
"%%a%d@(%d,%%%c%d:%c)", xn, dispmt, reg, xn2, size_spec);
return;
}
- case 7: // 4eb8 .. 4ebf, some are with Brief Extension Word
+ case 7: // 4eb8..4ebf / 4ef8..4eff, some are with Brief Extension Word
switch (xn) {
- case 0: // 4eb8 (xxx).W
+ case 0: // 4eb8 / 4ef8 (xxx).W
{
node.size = kInstructionSizeStepBytes * 2;
// This shit is real: it is sign extend value
@@ -77,37 +77,41 @@ static void disasm_jsr_jmp(
// 0xffff8a0c, effectively making jump possible only to lowest
// 32K range 0..0x7fff and highest 32K range
// 0xffff8000...0xffffffff
- node.branch_addr = static_cast<uint32_t>(dispmt);
+ const uint32_t branch_addr = static_cast<uint32_t>(dispmt);
+ node.branch_addr = branch_addr;
node.has_branch_addr = true;
snprintf(node.mnemonic, kMnemonicBufferSize, "%s", mnemonic);
- // FIXME support s.abs_marks option
+ // FIXME support s.abs_marks option for this instruction
snprintf(node.arguments, kArgsBufferSize, "0x%x:w", dispmt);
return;
}
- case 1: // 4eb9 (xxx).L
+ case 1: // 4eb9 / 4ef9 (xxx).L
{
node.size = kInstructionSizeStepBytes * 3;
const int32_t dispmt = GetI32BE(code.buffer + node.offset + kInstructionSizeStepBytes);
- node.branch_addr = static_cast<uint32_t>(dispmt);
+ const uint32_t branch_addr = static_cast<uint32_t>(dispmt);
+ node.branch_addr = branch_addr;
node.has_branch_addr = true;
snprintf(node.mnemonic, kMnemonicBufferSize, "%s", mnemonic);
- // FIXME support s.abs_marks option
+ // FIXME support s.abs_marks option for this instruction
snprintf(node.arguments, kArgsBufferSize, "0x%x:l", dispmt);
return;
}
- case 2: // 4eba, Displacement
+ case 2: // 4eba / 4efa, Displacement
{
const int16_t dispmt = GetI16BE(code.buffer + node.offset + kInstructionSizeStepBytes);
// Add 2 to current PC, as usual
- node.branch_addr = node.offset + dispmt + kInstructionSizeStepBytes;
+ const uint32_t branch_addr = static_cast<uint32_t>(
+ node.offset + dispmt + kInstructionSizeStepBytes);
+ node.branch_addr = branch_addr;
node.has_branch_addr = true;
node.size = kInstructionSizeStepBytes * 2;
snprintf(node.mnemonic, kMnemonicBufferSize, "%s", mnemonic);
- // FIXME support s.rel_marks option
+ // FIXME support s.abs_marks option for this instruction
snprintf(node.arguments, kArgsBufferSize, "%%pc@(%d:w)", dispmt);
return;
}
- case 3: // 4ebb
+ case 3: // 4ebb / 4efb
{
// NOTE: dynamic jump, branch_addr may possibly be obtained
// during the trace
@@ -123,9 +127,9 @@ static void disasm_jsr_jmp(
"%%pc@(%d,%%%c%d:%c)", dispmt, reg, xn2, size_spec);
return;
}
- case 4: // 4ebc
- case 5: // 4ebd
- case 6: // 4ebe
+ case 4: // 4ebc / 4efb
+ case 5: // 4ebd / 4efd
+ case 6: // 4ebe / 4efe
break;
}
break;
@@ -205,11 +209,12 @@ static void disasm_bra_bsr_bcc(
node.size = kInstructionSizeStepBytes;
}
dispmt += kInstructionSizeStepBytes;
- node.branch_addr = node.offset + dispmt;
+ const uint32_t branch_addr = static_cast<uint32_t>(node.offset + dispmt);
+ node.branch_addr = branch_addr;
node.has_branch_addr = true;
- const char * const sign = dispmt >= 0 ? "+" : "";
snprintf(node.mnemonic, kMnemonicBufferSize, "%s%s", mnemonic, size_spec);
- // FIXME support s.rel_marks option
+ const char * const sign = dispmt >= 0 ? "+" : "";
+ // FIXME support s.rel_marks option for this instruction
snprintf(node.arguments, kArgsBufferSize, ".%s%d", sign, dispmt);
return;
}
@@ -327,13 +332,14 @@ static void disasm_dbcc(DisasmNode& node, uint16_t instr, const DataBuffer &code
Condition condition = static_cast<Condition>((instr >> 8) & 0xf);
const char *mnemonic = dbcc_mnemonic_by_condition(condition);
const int regnum = (instr & 7);
- const int16_t dispmt = GetI16BE(code.buffer + node.offset + kInstructionSizeStepBytes) +
- kInstructionSizeStepBytes;
- node.branch_addr = node.offset + dispmt;
+ int16_t dispmt = GetI16BE(code.buffer + node.offset + kInstructionSizeStepBytes);
+ const uint32_t branch_addr = static_cast<uint32_t>(node.offset + dispmt);
+ node.branch_addr = branch_addr;
node.has_branch_addr = true;
- const char * const sign = dispmt >= 0 ? "+" : "";
+ dispmt += kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "%s", mnemonic);
- // FIXME support s.rel_marks option
+ const char * const sign = dispmt >= 0 ? "+" : "";
+ // FIXME support s.rel_marks option for this instruction
snprintf(node.arguments, kArgsBufferSize, "%%d%d,.%s%d", regnum, sign, dispmt);
return;
}
diff --git a/test.bash b/test.bash
index 5b35eec..5e5d183 100644
--- a/test.bash
+++ b/test.bash
@@ -6,6 +6,8 @@
AS=m68k-none-elf-as
OBJCOPY=m68k-none-elf-objcopy
+LD="m68k-none-elf-ld -Ttest.ld"
+DISASM="./cmake-build/m68k-disasm -fabs-marks -frel-marks -fmarks"
TEST_DIR=/tmp/m68k-disasm-tests
TRACE_FILE=${TEST_DIR}/trace.txt
@@ -25,12 +27,14 @@ run_test_simple() {
local file_orig_bin=${TEST_DIR}/${test_name_sanitized}.orig.bin
local file_asm=${TEST_DIR}/${test_name_sanitized}.S
local file_as_o=${TEST_DIR}/${test_name_sanitized}.as.o
+ local file_as_elf=${TEST_DIR}/${test_name_sanitized}.as.elf
local file_as_bin=${TEST_DIR}/${test_name_sanitized}.as.bin
echo -ne "Test \"${test_name}\"... "
echo -ne "${data}" >${file_orig_bin}
- ./cmake-build/m68k-disasm -t ${TRACE_FILE} -o ${file_asm} ${file_orig_bin}
+ ${DISASM} -t ${TRACE_FILE} -o ${file_asm} ${file_orig_bin}
${AS} -o ${file_as_o} ${file_asm}
- ${OBJCOPY} ${file_as_o} -O binary ${file_as_bin}
+ ${LD} -o ${file_as_elf} ${file_as_o}
+ ${OBJCOPY} ${file_as_elf} -O binary ${file_as_bin}
if ! cmp ${file_orig_bin} ${file_as_bin} >/dev/null 2>&1; then
echo -e "${CRED}FAIL${CRST}: output and input binaries do not match"
cat ${file_asm}
@@ -148,25 +152,25 @@ run_test_simple "jsr M6 long displacement positive" "\x4e\xb0\x08\x0c"
run_test_simple "jsr M6 long displacement negative" "\x4e\xb0\x08\xb0"
run_test_iterative "jsr M6 arbitrary Xn2" "\x4e\xb0" 0x00 8 0x10 "\x0f"
-# 43b8 xxxx Word displacement
+# 4eb8 xxxx Word displacement
#
run_test_simple "jsr M7 Xn0 zero" "\x4e\xb8\x00\x00"
run_test_simple "jsr M7 Xn0 positive" "\x4e\xb8\x00\x1f"
run_test_simple "jsr M7 Xn0 negative" "\x4e\xb8\x8a\x0c"
-# 43b9 xxxx Long displacement
+# 4eb9 xxxx Long displacement
#
run_test_simple "jsr M7 X1 zero" "\x4e\xb9\x00\x00\x00\x00"
run_test_simple "jsr M7 X1 positive" "\x4e\xb9\x10\xbb\x43\x1f"
run_test_simple "jsr M7 X1 negative" "\x4e\xb9\x80\xcc\xd9\x8a"
-# 43ba xxxx
+# 4eba xxxx
#
run_test_simple "jsr M7 X2 zero value" "\x4e\xba\x00\x00"
run_test_simple "jsr M7 X2 positive value" "\x4e\xba\x00\x1f"
run_test_simple "jsr M7 X2 negative value" "\x4e\xba\x8a\x0c"
-# 43bb xxxx
+# 4ebb xxxx
#
run_test_simple "jsr M7 X3 negative" "\x4e\xbb\x00\xf0"
run_test_simple "jsr M7 X3 zero displacement" "\x4e\xbb\x00\x00"
diff --git a/test.ld b/test.ld
new file mode 100644
index 0000000..22a08e2
--- /dev/null
+++ b/test.ld
@@ -0,0 +1,16 @@
+MEMORY {
+ ROM(rx) : ORIGIN = 0x00000000, LENGTH = 4M
+}
+
+SECTIONS {
+ . = ORIGIN(ROM);
+ .text : {
+ KEEP(*(.text))
+ . = ALIGN(2);
+ *(.text*)
+ . = ALIGN(2);
+ KEEP(*(.rodata))
+ *(.rodata*)
+ . = ALIGN(2);
+ } >ROM
+}