diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-12-28 20:01:47 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-12-28 20:01:47 -0800 |
commit | 83bec4a59eec5a704aab037ca0d2fd6ebcd0dbc0 (patch) | |
tree | eab790ca2dc543b21eab553175a1a16bdc6279c1 | |
parent | 6e79e84a72fac33a4f83e3dbd595888d10c22c54 (diff) | |
download | mu-83bec4a59eec5a704aab037ca0d2fd6ebcd0dbc0.tar.gz |
7449
There's an ambiguity in how x86 interprets disp32 fields: - For jumps and calls they're displacements from the starting address of the next instruction. So far so good. - However, when the ModR/M requires them they can also be absolute addresses. Ideally I'd take the presence of the ModR/M byte into account in interpreting them. However, it's easier to assume relative addressing only for labels in the code segment. This commit raises an error if we ever refer to labels in the code segment in instructions with a ModR/M byte. (I'm assuming that no instruction with a ModR/M byte will ever use a displacement without the ModR/M byte requiring it.)
-rw-r--r-- | 036labels.cc | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/036labels.cc b/036labels.cc index c269538a..dbecef7e 100644 --- a/036labels.cc +++ b/036labels.cc @@ -223,6 +223,9 @@ void replace_labels_with_displacements(segment& code, const map<string, int32_t> for (int j = 0; j < SIZE(inst.words); ++j) { const word& curr = inst.words.at(j); if (contains_key(byte_index, curr.data)) { + if (has_argument_metadata(inst, "mod")) { + raise << "'" << to_string(inst) << "' don't pass references to labels around like data\n" << end(); + } int32_t displacement = static_cast<int32_t>(get(byte_index, curr.data)) - byte_index_next_instruction_starts_at; if (has_argument_metadata(curr, "disp8")) { if (displacement > 0x7f || displacement < -0x7f) |