summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-06-03 20:22:01 +0300
committerOxore <oxore@protonmail.com>2023-06-03 20:25:19 +0300
commitb5c24afbc10a36f65e73d5ef2100da4ff173a109 (patch)
treee770a62f7b0f46ded2ab96f20010a26d376f26ce
parent5c010acbd7291482ce953a2d9a9b857772b695d6 (diff)
Impl -fimm-hex
-rw-r--r--Readme.md2
-rw-r--r--common.h3
-rw-r--r--disasm.cpp5
-rw-r--r--disasm.h1
-rw-r--r--main.cpp9
-rw-r--r--test.bash2
-rw-r--r--test_random.bash2
7 files changed, 15 insertions, 9 deletions
diff --git a/Readme.md b/Readme.md
index 5d3242f..1ba2198 100644
--- a/Readme.md
+++ b/Readme.md
@@ -94,7 +94,7 @@ trace table.
Or better with labeled locations analysis and some fancy raw comments:
```
-./cmake-build/m68k-disasm -frdc -fxrefs-to -fxrefs-from -flabels -fabs-labels -frel-labels -fexport-labels -fexport-functions -t pc-trace.txt -o disasm.S rom.bin
+./cmake-build/m68k-disasm -frdc -fxrefs-to -fxrefs-from -flabels -fabs-labels -frel-labels -fexport-labels -fexport-functions -fimm-hex -t pc-trace.txt -o disasm.S rom.bin
```
It will produce `disasm.S` which you can modify and assemble as shown in
diff --git a/common.h b/common.h
index 73689ba..97dfe7c 100644
--- a/common.h
+++ b/common.h
@@ -4,6 +4,7 @@
#pragma once
struct Settings {
+ bool raw_data_comment{};
bool labels{};
bool rel_labels{};
bool abs_labels{};
@@ -14,7 +15,7 @@ struct Settings {
bool export_functions{};
bool xrefs_to{};
bool xrefs_from{};
- bool raw_data_comment{};
+ bool imm_hex{};
const char *indent{"\t"};
};
diff --git a/disasm.cpp b/disasm.cpp
index 3755e39..01af6ea 100644
--- a/disasm.cpp
+++ b/disasm.cpp
@@ -1932,6 +1932,7 @@ int Arg::SNPrint(
int Op::FPrint(
FILE *const stream,
const char *const indent,
+ const bool imm_as_hex,
const RefKindMask ref_kinds,
const char *const ref1_label,
const char *const ref2_label,
@@ -1949,14 +1950,14 @@ int Op::FPrint(
// argument is plain address register, status register or condition code
// register. USP is not the case because it's value may be moved only to
// or from An register.
- const bool imm_as_hex =
+ const bool imm_as_hex_2 = imm_as_hex ||
arg2.type == ArgType::kAn ||
arg2.type == ArgType::kCCR ||
arg2.type == ArgType::kSR;
arg1.SNPrint(
arg1_str,
kArgsBufferSize,
- imm_as_hex,
+ imm_as_hex_2,
ref1_kinds,
ref1_label,
self_addr,
diff --git a/disasm.h b/disasm.h
index 9228ffb..07640dc 100644
--- a/disasm.h
+++ b/disasm.h
@@ -355,6 +355,7 @@ struct Op {
int FPrint(
FILE *,
const char *indent,
+ bool imm_as_hex,
RefKindMask ref_kinds = 0,
const char *ref1_label = nullptr,
const char *ref2_label = nullptr,
diff --git a/main.cpp b/main.cpp
index 349b5f2..217766a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -367,7 +367,7 @@ static void RenderNodeDisassembly(
assert(node.op.opcode != OpCode::kNone);
if (ShouldPrintAsRaw(node.op)) {
auto raw = Op::Raw(GetU16BE(code.buffer + node.address));
- raw.FPrint(output, s.indent);
+ raw.FPrint(output, s.indent, s.imm_hex);
uint32_t i = kInstructionSizeStepBytes;
for (; i < node.size; i += kInstructionSizeStepBytes) {
char arg_str[kArgsBufferSize]{};
@@ -419,6 +419,7 @@ static void RenderNodeDisassembly(
node.op.FPrint(
output,
s.indent,
+ s.imm_hex,
ref_kinds,
ref1_label,
ref2_label,
@@ -434,7 +435,7 @@ static void RenderNodeDisassembly(
fprintf(output, " | L%08x", ref2_addr);
}
} else {
- node.op.FPrint(output, s.indent);
+ node.op.FPrint(output, s.indent, s.imm_hex);
}
}
if (s.raw_data_comment) {
@@ -459,7 +460,7 @@ static void RenderDisassembly(
i += node->size;
} else {
auto raw = Op::Raw(GetU16BE(code.buffer + i));
- raw.FPrint(output, s.indent);
+ raw.FPrint(output, s.indent, s.imm_hex);
fprintf(output, "\n");
i += kInstructionSizeStepBytes;
}
@@ -616,6 +617,7 @@ static bool ApplyFeature(Settings& s, const char *feature_arg)
{ &Settings::export_functions, "export-functions" },
{ &Settings::xrefs_from, "xrefs-from" },
{ &Settings::xrefs_to, "xrefs-to" },
+ { &Settings::imm_hex, "imm-hex" },
};
constexpr size_t sizeof_no_prefix = (sizeof "no-") - 1;
const bool disable = FeatureStringHasPrefixNo(feature_arg);
@@ -663,6 +665,7 @@ static void PrintUsage(FILE *s, const char *argv0)
fprintf(s, " referenced as a call.\n");
fprintf(s, " xrefs-from Print xrefs comments above all places that have xrefs.\n");
fprintf(s, " xrefs-to Print xrefs comments after all branch instructions.\n");
+ fprintf(s, " imm-hex Print all immediate values as hexadecimal numbers.\n");
}
int main(int, char* argv[])
diff --git a/test.bash b/test.bash
index 9cfcfab..9336edc 100644
--- a/test.bash
+++ b/test.bash
@@ -7,7 +7,7 @@
AS=m68k-none-elf-as
OBJCOPY=m68k-none-elf-objcopy
LD="m68k-none-elf-ld -Ttest.ld"
-DISASM="./cmake-build/m68k-disasm -fabs-labels -frel-labels -flabels"
+DISASM="./cmake-build/m68k-disasm -fabs-labels -frel-labels -flabels -fimm-hex"
TEST_DIR=/tmp/m68k-disasm-tests
set -e
diff --git a/test_random.bash b/test_random.bash
index 735cd86..accb975 100644
--- a/test_random.bash
+++ b/test_random.bash
@@ -7,7 +7,7 @@
AS=m68k-none-elf-as
OBJCOPY=m68k-none-elf-objcopy
LD="m68k-none-elf-ld -Ttest.ld"
-DISASM="./cmake-build/m68k-disasm -frdc -fxrefs-to -fxrefs-from -flabels -frel-labels -fabs-labels -fshort-ref-local-labels"
+DISASM="./cmake-build/m68k-disasm -frdc -fxrefs-to -fxrefs-from -flabels -frel-labels -fabs-labels -fshort-ref-local-labels -fimm-hex"
TEST_DIR=/tmp/m68k-disasm-random-tests
set -e