summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-05-26 23:48:24 +0300
committerOxore <oxore@protonmail.com>2023-05-26 23:48:24 +0300
commitedfe901ba751f4fcdf287102037eb36bf28cfa2a (patch)
tree1895037219c090c9123a48e4cb7cd6b4217910c5
parent4f89cdd326fbc9cc1fbd75879d67b462b76bd7c3 (diff)
Change all `mark` wording to `label` wording
-rw-r--r--Readme.md21
-rw-r--r--common.h17
-rw-r--r--disasm.cpp8
-rw-r--r--main.cpp74
-rw-r--r--test.bash2
-rw-r--r--test_labels_referencing.bash (renamed from test_marks_referencing.bash)8
-rw-r--r--test_random.bash2
-rw-r--r--todo.md9
8 files changed, 66 insertions, 75 deletions
diff --git a/Readme.md b/Readme.md
index 6b5c3d2..5d3242f 100644
--- a/Readme.md
+++ b/Readme.md
@@ -91,10 +91,10 @@ trace table.
./cmake-build/m68k-disasm -t pc-trace.txt -o disasm.S rom.bin
```
-Or better with marks analysis and some fancy raw comments:
+Or better with labeled locations analysis and some fancy raw comments:
```
-./cmake-build/m68k-disasm -frdc -fxrefs-to -fxrefs-from -fmarks -fabs-marks -frel-marks -fexport-marks -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 -t pc-trace.txt -o disasm.S rom.bin
```
It will produce `disasm.S` which you can modify and assemble as shown in
@@ -116,8 +116,8 @@ Goals of this Motorola 68000 disassembler project in this particular repo:
- Support PC trace tables. With trace tables it will disassemble traced PC
locations only, without attempt to disassemble everything, because not
everything is instruction, some code is just data.
-- Mark jump locations and bind jumps and calls to them. Mark obvious ROM read
- accessed locations and bind the instructions to the marked locations. To make
+- Label jump locations and bind jumps and calls to them. Label obvious ROM read
+ accessed locations and bind the instructions to the labeled locations. To make
it possible to split and reorganize the binary.
What could become a goal (possible features):
@@ -146,10 +146,10 @@ What is **not** the goal (at least not in this repo):
- It generates GNU AS compatible listing, that may be translated back to machine
code using `m68k-none-elf-as` in the way that it matches original binary file,
no matter what.
-- It generates labels (marks) for all jump instructions (JSR, JMP, BRA, Bcc and
- DBcc) if jump location is inside the code being disassembled. This feature can
- be enabled with `-fmarks`, `-frel-marks` and `-fabs-marks` options, all at
- once. It also generates marks for some data accessing instructions (namely:
+- It generates labels for all jump instructions (JSR, JMP, BRA, Bcc and DBcc) if
+ jump location is inside the code being disassembled. This feature can be
+ enabled with `-flabels`, `-frel-labels` and `-fabs-labels` options, all at
+ once. It also generates labels for some data accessing instructions (namely:
NBCD, PEA, LEA, CMP, SUB, ADD, MOVEM and MOVE) and this behavior enabled with
the same options as per jump instructions. It is possible to implement this
for all of the rest instructions, but it just has to be done if someone needs
@@ -170,9 +170,8 @@ What is **not** the goal (at least not in this repo):
variations.
- Base address is always assumed to be `0x00000000`.
- Maximum binary size is 4MiB.
-- Labels/marks for locations outside of the code being disassembled are not
- generated, they remain as raw address arguments and/or PC-relative offset
- arguments.
+- Labels for locations outside of the code being disassembled are not generated,
+ they remain as raw address arguments and/or PC-relative offset arguments.
## Meta
diff --git a/common.h b/common.h
index 4a976aa..36a5ba3 100644
--- a/common.h
+++ b/common.h
@@ -4,12 +4,12 @@
#pragma once
struct Settings {
- bool marks{};
- bool rel_marks{};
- bool abs_marks{};
- bool imm_marks{};
- bool export_marks{};
- bool export_all_marks{};
+ bool labels{};
+ bool rel_labels{};
+ bool abs_labels{};
+ bool imm_labels{};
+ bool export_labels{};
+ bool export_all_labels{};
bool export_functions{};
bool xrefs_to{};
bool xrefs_from{};
@@ -30,9 +30,10 @@ constexpr RefKindMask kRef2WriteMask = (1 << 7); // For second argument
/// Indicates whether instruction is a call or just a branch, for any argument.
/// Calls are BSR and JSR, branches are DBcc, Bcc and JMP.
constexpr RefKindMask kRefCallMask = (1 << 8);
-/// Hack flag for MOVEM with PC relative value when -frel-marks is set
+/// Hack flag for MOVEM with PC relative value when -frel-labels is set
constexpr RefKindMask kRefPcRelFix2Bytes = (1 << 9);
-/// Register 1 may have immediate moving to address register which may be a mark
+/// Register 1 may have immediate moving to address register which may be a
+/// labeled location
constexpr RefKindMask kRef1ImmMask = (1 << 10);
/// Everything for first argument
constexpr RefKindMask kRef1Mask = kRef1RelMask | kRef1AbsMask | kRef1ReadMask | kRef1WriteMask | kRef1ImmMask;
diff --git a/disasm.cpp b/disasm.cpp
index dba933a..6179c8d 100644
--- a/disasm.cpp
+++ b/disasm.cpp
@@ -274,8 +274,8 @@ static size_t disasm_ext_movem(
return disasm_verbatim(node, instr);
} else if (a.mode == AddrMode::kD16PCAddr) {
// XXX: kRefPcRelFix2Bytes flag is a hack that needed to correctly
- // print PC relative mark referenced value for MOVEM. Alongside with
- // *NOT* adding kInstructionSizeStepBytes to ref1_addr. Still
+ // print label for PC relative referenced value of MOVEM. Alongside
+ // with *NOT* adding kInstructionSizeStepBytes to ref1_addr. Still
// figuring that out.
node.ref1_addr = node.offset + kInstructionSizeStepBytes * 2 +
static_cast<uint32_t>(a.d16_pc.d16);
@@ -1859,7 +1859,7 @@ int Arg::SNPrint(
if (static_cast<uint32_t>(lword) == ref_addr) {
return snprintf(buf, bufsz, "L%08x:%c", ref_addr, c);
} else {
- // It has to be AFTER the mark we are gonna reference here
+ // It has to be AFTER the label we are gonna reference here
assert(static_cast<uint32_t>(lword) > ref_addr);
return snprintf(buf, bufsz, "L%08x+%d:%c", ref_addr, lword - ref_addr, c);
}
@@ -1894,7 +1894,7 @@ int Arg::SNPrint(
if (static_cast<uint32_t>(lword) == ref_addr) {
return snprintf(buf, bufsz, "#L%08x", ref_addr);
} else {
- // It has to be AFTER the mark we are gonna reference here
+ // It has to be AFTER the label we are gonna reference here
assert(static_cast<uint32_t>(lword) > ref_addr);
return snprintf(buf, bufsz, "#L%08x+%d", ref_addr, lword - ref_addr);
}
diff --git a/main.cpp b/main.cpp
index 4a8e1ac..e2e4191 100644
--- a/main.cpp
+++ b/main.cpp
@@ -266,12 +266,12 @@ static void RenderNodeDisassembly(
const DisasmNode &node)
{
if (node.ref_by) {
- if (s.marks) {
+ if (s.labels) {
const bool export_this_function = s.export_functions && HasCallReference(node);
- const bool export_this_mark = s.export_all_marks ||
- (s.export_marks && node.ref_by && (node.ref_by->refs_count > 1)) ||
+ const bool export_this_label = s.export_all_labels ||
+ (s.export_labels && node.ref_by && (node.ref_by->refs_count > 1)) ||
export_this_function;
- if (export_this_mark) {
+ if (export_this_label) {
fprintf(output, "\n%s.globl\tL%08x\n", s.indent, node.offset);
if (export_this_function) {
fprintf(output, "%s.type\tL%08x, @function\n", s.indent, node.offset);
@@ -292,7 +292,7 @@ static void RenderNodeDisassembly(
fprintf(output, "\n");
}
}
- if (s.marks) {
+ if (s.labels) {
fprintf(output, "L%08x:\n", node.offset);
}
}
@@ -309,7 +309,7 @@ static void RenderNodeDisassembly(
}
fprintf(output, "\n");
} else {
- const bool with_ref = node.ref_kinds && s.marks && (s.abs_marks || s.rel_marks);
+ const bool with_ref = node.ref_kinds && s.labels && (s.abs_labels || s.rel_labels);
const auto *ref1 = (node.ref_kinds & kRef1Mask)
? disasm_map.FindNodeByOffset(node.ref1_addr) : nullptr;
const auto *ref2 = (node.ref_kinds & kRef2Mask)
@@ -318,15 +318,15 @@ static void RenderNodeDisassembly(
const uint32_t ref2_addr = (with_ref && ref2) ? ref2->offset : 0;
if (with_ref && (ref1 || ref2)) {
const RefKindMask ref_kinds =
- (s.abs_marks
+ (s.abs_labels
? ((ref1 ? (node.ref_kinds & kRef1AbsMask) : 0) |
(ref2 ? (node.ref_kinds & kRef2AbsMask) : 0))
: 0) |
- (s.rel_marks
+ (s.rel_labels
? ((ref1 ? (node.ref_kinds & kRef1RelMask) : 0) |
(ref2 ? (node.ref_kinds & kRef2RelMask) : 0))
: 0) |
- ((s.imm_marks && ref1) ? (node.ref_kinds & kRef1ImmMask) : 0) |
+ ((s.imm_labels && ref1) ? (node.ref_kinds & kRef1ImmMask) : 0) |
(node.ref_kinds & (kRefDataMask | kRefPcRelFix2Bytes));
node.op.FPrint(output, s.indent, ref_kinds, node.offset, ref1_addr, ref2_addr);
if (s.xrefs_to && ref1) {
@@ -503,17 +503,17 @@ static bool IsValidFeature(const char *feature)
}
if (0 == strcmp(feature, "rdc")) {
return true;
- } else if (0 == strcmp(feature, "marks")) {
+ } else if (0 == strcmp(feature, "labels")) {
return true;
- } else if (0 == strcmp(feature, "rel-marks")) {
+ } else if (0 == strcmp(feature, "rel-labels")) {
return true;
- } else if (0 == strcmp(feature, "abs-marks")) {
+ } else if (0 == strcmp(feature, "abs-labels")) {
return true;
- } else if (0 == strcmp(feature, "imm-marks")) {
+ } else if (0 == strcmp(feature, "imm-labels")) {
return true;
- } else if (0 == strcmp(feature, "export-marks")) {
+ } else if (0 == strcmp(feature, "export-labels")) {
return true;
- } else if (0 == strcmp(feature, "export-all-marks")) {
+ } else if (0 == strcmp(feature, "export-all-labels")) {
return true;
} else if (0 == strcmp(feature, "export-functions")) {
return true;
@@ -532,18 +532,18 @@ static void ApplyFeature(Settings& s, const char *feature_arg)
const char *const feature = feature_arg + (disable ? sizeof_no_prefix : 0);
if (0 == strcmp(feature, "rdc")) {
s.raw_data_comment = !disable;
- } else if (0 == strcmp(feature, "marks")) {
- s.marks = !disable;
- } else if (0 == strcmp(feature, "rel-marks")) {
- s.rel_marks = !disable;
- } else if (0 == strcmp(feature, "abs-marks")) {
- s.abs_marks = !disable;
- } else if (0 == strcmp(feature, "imm-marks")) {
- s.imm_marks = !disable;
- } else if (0 == strcmp(feature, "export-marks")) {
- s.export_marks = !disable;
- } else if (0 == strcmp(feature, "export-all-marks")) {
- s.export_all_marks = !disable;
+ } else if (0 == strcmp(feature, "labels")) {
+ s.labels = !disable;
+ } else if (0 == strcmp(feature, "rel-labels")) {
+ s.rel_labels = !disable;
+ } else if (0 == strcmp(feature, "abs-labels")) {
+ s.abs_labels = !disable;
+ } else if (0 == strcmp(feature, "imm-labels")) {
+ s.imm_labels = !disable;
+ } else if (0 == strcmp(feature, "export-labels")) {
+ s.export_labels = !disable;
+ } else if (0 == strcmp(feature, "export-all-labels")) {
+ s.export_all_labels = !disable;
} else if (0 == strcmp(feature, "export-functions")) {
s.export_functions = !disable;
} else if (0 == strcmp(feature, "xrefs-from")) {
@@ -566,21 +566,21 @@ static void PrintUsage(FILE *s, const char *argv0)
fprintf(s, " -f, --feature=[no-]<feature>\n");
fprintf(s, " Enable or disable (with \"no-\" prefix) a feature.\n");
fprintf(s, " Available features described below under the\n");
- fprintf(s, " \"Feature flags\" mark.\n");
+ fprintf(s, " \"Feature flags\" section.\n");
fprintf(s, " <input_file_name> Binary file with machine code (stdin if not set)\n");
fprintf(s, "Feature flags:\n");
fprintf(s, " rdc Print raw data comment.\n");
- fprintf(s, " marks Print marks above all places that have jumps from\n");
+ fprintf(s, " labels Print labels above all places that have jumps from\n");
fprintf(s, " somewhere.\n");
- fprintf(s, " rel-marks Use mark instead of number on relative branch or call.\n");
- fprintf(s, " abs-marks Use mark instead of number on absolute branch or call.\n");
- fprintf(s, " imm-marks Use mark instead of number when immediate value moved to\n");
- fprintf(s, " address register.\n");
- fprintf(s, " export-marks Add `.globl` preamble to marks referenced two or more\n");
+ fprintf(s, " rel-labels Use label instead of number on relative branch or call.\n");
+ fprintf(s, " abs-labels Use label instead of number on absolute branch or call.\n");
+ fprintf(s, " imm-labels Use label instead of number when immediate value moved\n");
+ fprintf(s, " to address register.\n");
+ fprintf(s, " export-labels Add `.globl` preamble to labels referenced two or more\n");
fprintf(s, " times.\n");
- fprintf(s, " export-all-marks Add `.globl` preamble to all marks.\n");
- fprintf(s, " export-functions Add `.globl` and `.type @funciton` preamble to marks\n");
- fprintf(s, " referenced as call.\n");
+ fprintf(s, " export-all-labels Add `.globl` preamble to all labels.\n");
+ fprintf(s, " export-functions Add `.globl` and `.type @funciton` preamble to a label\n");
+ 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");
}
diff --git a/test.bash b/test.bash
index 2bbb5dc..9cfcfab 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-marks -frel-marks -fmarks"
+DISASM="./cmake-build/m68k-disasm -fabs-labels -frel-labels -flabels"
TEST_DIR=/tmp/m68k-disasm-tests
set -e
diff --git a/test_marks_referencing.bash b/test_labels_referencing.bash
index 9efb42b..0cedc13 100644
--- a/test_marks_referencing.bash
+++ b/test_labels_referencing.bash
@@ -8,7 +8,7 @@ AS=m68k-none-elf-as
OBJCOPY=m68k-none-elf-objcopy
LD="m68k-none-elf-ld -Ttest.ld"
DISASM="./cmake-build/m68k-disasm"
-TEST_DIR=/tmp/m68k-disasm-tests-marks-referencing
+TEST_DIR=/tmp/m68k-disasm-tests-labels-referencing
set -e
CRED="\033[31m"
@@ -70,15 +70,15 @@ run_check_r() {
}
run_test_rdisp() {
- run_test_r "$1" "$2" "-fmarks -frel-marks" run_check_rdisp
+ run_test_r "$1" "$2" "-flabels -frel-labels" run_check_rdisp
}
run_test_rword() {
- run_test_r "$1" "$2" "-fmarks -fabs-marks" run_check_r
+ run_test_r "$1" "$2" "-flabels -fabs-labels" run_check_r
}
run_test_rpcrel() {
- run_test_r "$1" "$2" "-fmarks -frel-marks" run_check_r
+ run_test_r "$1" "$2" "-flabels -frel-labels" run_check_r
}
run_test_rdisp "bras ." "\x60\xfe"
diff --git a/test_random.bash b/test_random.bash
index daf5a5b..9bc318f 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 -fabs-marks -frel-marks -fmarks -frdc"
+DISASM="./cmake-build/m68k-disasm -fabs-labels -frel-labels -flabels -frdc"
TEST_DIR=/tmp/m68k-disasm-random-tests
set -e
diff --git a/todo.md b/todo.md
index bc0c74e..6b22d23 100644
--- a/todo.md
+++ b/todo.md
@@ -1,14 +1,5 @@
# TODO
-- Automatically export functions, i.e. all marks with CALL xref have to have the
- following preamble:
-
-```
-
- .global L000015de
- .type L000015de, @function
-```
-
- Implement CLI option that can be used to specify regions of RAM and IO
registers. Custom ROM location and size is still not the case, only 4MiB at
the base `0x00000000` is supported and it remains.