From 4718a77ce26c02bac7cfe28637c2892091ac0075 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 27 Jul 2018 12:33:08 -0700 Subject: 4444 More tracing reorg. --- subx/011run.cc | 6 ++ subx/022check_instruction.cc | 1 + subx/023check_operand_bounds.cc | 66 ++++++++++++ subx/023check_operand_sizes.cc | 65 ------------ subx/024pack_instructions.cc | 214 --------------------------------------- subx/024pack_operands.cc | 215 ++++++++++++++++++++++++++++++++++++++++ subx/025non_code_segment.cc | 5 +- subx/026labels.cc | 15 +-- 8 files changed, 299 insertions(+), 288 deletions(-) create mode 100644 subx/023check_operand_bounds.cc delete mode 100644 subx/023check_operand_sizes.cc delete mode 100644 subx/024pack_instructions.cc create mode 100644 subx/024pack_operands.cc diff --git a/subx/011run.cc b/subx/011run.cc index 4a754a09..218f4e16 100644 --- a/subx/011run.cc +++ b/subx/011run.cc @@ -121,6 +121,7 @@ struct word { :(code) void parse(istream& fin, program& out) { vector l; + trace(99, "parse") << "begin" << end(); while (has_data(fin)) { string line_data; getline(fin, line_data); @@ -172,6 +173,7 @@ void parse(istream& fin, program& out) { trace(99, "parse") << "flushing to segment" << end(); out.segments.back().lines.swap(l); } + trace(99, "parse") << "done" << end(); } //:: transform @@ -182,13 +184,16 @@ typedef void (*transform_fn)(program&); vector Transform; void transform(program& p) { + trace(99, "transform") << "begin" << end(); for (int t = 0; t < SIZE(Transform); ++t) (*Transform.at(t))(p); + trace(99, "transform") << "done" << end(); } //:: load void load(const program& p) { + trace(99, "load") << "begin" << end(); if (p.segments.empty()) { raise << "no code to run\n" << end(); return; @@ -211,6 +216,7 @@ void load(const program& p) { if (i == 0) End_of_program = addr; } EIP = p.segments.at(0).start; + trace(99, "load") << "done" << end(); } uint8_t hex_byte(const string& s) { diff --git a/subx/022check_instruction.cc b/subx/022check_instruction.cc index 5eb21136..31834b38 100644 --- a/subx/022check_instruction.cc +++ b/subx/022check_instruction.cc @@ -66,6 +66,7 @@ Transform.push_back(check_operands); :(code) void check_operands(/*const*/ program& p) { + trace(99, "transform") << "-- check operands" << end(); if (p.segments.empty()) return; const segment& code = p.segments.at(0); for (int i = 0; i < SIZE(code.lines); ++i) { diff --git a/subx/023check_operand_bounds.cc b/subx/023check_operand_bounds.cc new file mode 100644 index 00000000..c868603a --- /dev/null +++ b/subx/023check_operand_bounds.cc @@ -0,0 +1,66 @@ +//:: Check that the different operands of an instruction aren't too large for their bitfields. + +:(scenario check_bitfield_sizes) +% Hide_errors = true; +== 0x1 +01/add 4/mod ++error: '4/mod' too large to fit in bitfield mod + +:(before "End Globals") +map Operand_bound; +:(before "End One-time Setup") +put(Operand_bound, "subop", 1<<3); +put(Operand_bound, "mod", 1<<2); +put(Operand_bound, "rm32", 1<<3); +put(Operand_bound, "base", 1<<3); +put(Operand_bound, "index", 1<<3); +put(Operand_bound, "scale", 1<<2); +put(Operand_bound, "r32", 1<<3); +put(Operand_bound, "disp8", 1<<8); +put(Operand_bound, "disp16", 1<<16); +// no bound needed for disp32 +put(Operand_bound, "imm8", 1<<8); +// no bound needed for imm32 + +:(before "End One-time Setup") +Transform.push_back(check_operand_bounds); +:(code) +void check_operand_bounds(/*const*/ program& p) { + trace(99, "transform") << "-- check operand bounds" << end(); + if (p.segments.empty()) return; + const segment& code = p.segments.at(0); + for (int i = 0; i < SIZE(code.lines); ++i) { + const line& inst = code.lines.at(i); + for (int j = first_operand(inst); j < SIZE(inst.words); ++j) + check_operand_bounds(inst.words.at(j)); + if (trace_contains_errors()) return; // stop at the first mal-formed instruction + } +} + +void check_operand_bounds(const word& w) { + for (map::iterator p = Operand_bound.begin(); p != Operand_bound.end(); ++p) { + if (has_metadata(w, p->first)) { + int32_t x = parse_int(w.data); + if (x >= 0) { + if (static_cast(x) >= p->second) + raise << "'" << w.original << "' too large to fit in bitfield " << p->first << '\n' << end(); + } + else { + // hacky? assuming bound is a power of 2 + if (x < -1*static_cast(p->second/2)) + raise << "'" << w.original << "' too large to fit in bitfield " << p->first << '\n' << end(); + } + } + } +} + +int32_t parse_int(const string& s) { + istringstream in(s); + int32_t result = 0; + in >> std::hex >> result; + if (!in || !in.eof()) { + raise << "not a number: " << s << '\n' << end(); + return 0; + } + return result; +} diff --git a/subx/023check_operand_sizes.cc b/subx/023check_operand_sizes.cc deleted file mode 100644 index 048cc28a..00000000 --- a/subx/023check_operand_sizes.cc +++ /dev/null @@ -1,65 +0,0 @@ -//:: Check that the different operands of an instruction aren't too large for their bitfields. - -:(scenario check_bitfield_sizes) -% Hide_errors = true; -== 0x1 -01/add 4/mod -+error: '4/mod' too large to fit in bitfield mod - -:(before "End Globals") -map Operand_bound; -:(before "End One-time Setup") -put(Operand_bound, "subop", 1<<3); -put(Operand_bound, "mod", 1<<2); -put(Operand_bound, "rm32", 1<<3); -put(Operand_bound, "base", 1<<3); -put(Operand_bound, "index", 1<<3); -put(Operand_bound, "scale", 1<<2); -put(Operand_bound, "r32", 1<<3); -put(Operand_bound, "disp8", 1<<8); -put(Operand_bound, "disp16", 1<<16); -// no bound needed for disp32 -put(Operand_bound, "imm8", 1<<8); -// no bound needed for imm32 - -:(before "End One-time Setup") -Transform.push_back(check_operand_bounds); -:(code) -void check_operand_bounds(/*const*/ program& p) { - if (p.segments.empty()) return; - const segment& code = p.segments.at(0); - for (int i = 0; i < SIZE(code.lines); ++i) { - const line& inst = code.lines.at(i); - for (int j = first_operand(inst); j < SIZE(inst.words); ++j) - check_operand_bounds(inst.words.at(j)); - if (trace_contains_errors()) return; // stop at the first mal-formed instruction - } -} - -void check_operand_bounds(const word& w) { - for (map::iterator p = Operand_bound.begin(); p != Operand_bound.end(); ++p) { - if (has_metadata(w, p->first)) { - int32_t x = parse_int(w.data); - if (x >= 0) { - if (static_cast(x) >= p->second) - raise << "'" << w.original << "' too large to fit in bitfield " << p->first << '\n' << end(); - } - else { - // hacky? assuming bound is a power of 2 - if (x < -1*static_cast(p->second/2)) - raise << "'" << w.original << "' too large to fit in bitfield " << p->first << '\n' << end(); - } - } - } -} - -int32_t parse_int(const string& s) { - istringstream in(s); - int32_t result = 0; - in >> std::hex >> result; - if (!in || !in.eof()) { - raise << "not a number: " << s << '\n' << end(); - return 0; - } - return result; -} diff --git a/subx/024pack_instructions.cc b/subx/024pack_instructions.cc deleted file mode 100644 index 62d47d22..00000000 --- a/subx/024pack_instructions.cc +++ /dev/null @@ -1,214 +0,0 @@ -//: Operands can refer to bitfields smaller than a byte. This layer packs -//: operands into their containing bytes in the right order. - -:(scenario pack_immediate_constants) -== 0x1 -# instruction effective address operand displacement immediate -# op subop mod rm32 base index scale r32 -# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes - bb 0x2a/imm32 # copy 42 to EBX -+translate: packing instruction 'bb 0x2a/imm32' -+translate: instruction after packing: 'bb 2a 00 00 00' -+run: copy imm32 0x0000002a to EBX - -:(scenario pack_disp8) -== 0x1 -74 2/disp8 # jump 2 bytes away if ZF is set -+translate: packing instruction '74 2/disp8' -+translate: instruction after packing: '74 02' - -:(scenarios transform) -:(scenario pack_disp8_negative) -== 0x1 -# running this will cause an infinite loop -74 -1/disp8 # jump 1 byte before if ZF is set -+translate: packing instruction '74 -1/disp8' -+translate: instruction after packing: '74 ff' -:(scenarios run) - -:(scenario pack_modrm_imm32) -== 0x1 -# instruction effective address operand displacement immediate -# op subop mod rm32 base index scale r32 -# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes - 81 0/add/subop 3/mod/direct 3/ebx/rm32 1/imm32 # add 1 to EBX -+translate: packing instruction '81 0/add/subop 3/mod/direct 3/ebx/rm32 1/imm32' -+translate: instruction after packing: '81 c3 01 00 00 00' - -:(scenario pack_imm32_large) -== 0x1 -b9 0x080490a7/imm32 # copy to ECX -+translate: packing instruction 'b9 0x080490a7/imm32' -+translate: instruction after packing: 'b9 a7 90 04 08' - -:(before "End One-time Setup") -Transform.push_back(pack_instructions); - -:(code) -void pack_instructions(program& p) { - if (p.segments.empty()) return; - segment& code = p.segments.at(0); - for (int i = 0; i < SIZE(code.lines); ++i) { - line& inst = code.lines.at(i); - if (all_hex_bytes(inst)) continue; - trace(99, "translate") << "packing instruction '" << to_string(/*with metadata*/inst) << "'" << end(); - pack_instruction(inst); - trace(99, "translate") << "instruction after packing: '" << to_string(/*without metadata*/inst.words) << "'" << end(); - } -} - -void pack_instruction(line& inst) { - line new_inst; - add_opcodes(inst, new_inst); - add_modrm_byte(inst, new_inst); - add_sib_byte(inst, new_inst); - add_disp_bytes(inst, new_inst); - add_imm_bytes(inst, new_inst); - inst.words.swap(new_inst.words); -} - -void add_opcodes(const line& in, line& out) { - out.words.push_back(in.words.at(0)); - if (in.words.at(0).data == "0f" || in.words.at(0).data == "f3") - out.words.push_back(in.words.at(1)); - if (in.words.at(0).data == "f3" && in.words.at(1).data == "0f") - out.words.push_back(in.words.at(2)); -} - -void add_modrm_byte(const line& in, line& out) { - uint8_t mod=0, reg_subop=0, rm32=0; - bool emit = false; - for (int i = 0; i < SIZE(in.words); ++i) { - const word& curr = in.words.at(i); - if (has_metadata(curr, "mod")) { - mod = hex_byte(curr.data); - emit = true; - } - else if (has_metadata(curr, "rm32")) { - rm32 = hex_byte(curr.data); - emit = true; - } - else if (has_metadata(curr, "r32")) { - reg_subop = hex_byte(curr.data); - emit = true; - } - else if (has_metadata(curr, "subop")) { - reg_subop = hex_byte(curr.data); - emit = true; - } - } - if (emit) - out.words.push_back(hex_byte_text((mod << 6) | (reg_subop << 3) | rm32)); -} - -void add_sib_byte(const line& in, line& out) { - uint8_t scale=0, index=0, base=0; - bool emit = false; - for (int i = 0; i < SIZE(in.words); ++i) { - const word& curr = in.words.at(i); - if (has_metadata(curr, "scale")) { - scale = hex_byte(curr.data); - emit = true; - } - else if (has_metadata(curr, "index")) { - index = hex_byte(curr.data); - emit = true; - } - else if (has_metadata(curr, "base")) { - base = hex_byte(curr.data); - emit = true; - } - } - if (emit) - out.words.push_back(hex_byte_text((scale << 6) | (index << 3) | base)); -} - -void add_disp_bytes(const line& in, line& out) { - for (int i = 0; i < SIZE(in.words); ++i) { - const word& curr = in.words.at(i); - if (has_metadata(curr, "disp8")) - emit_hex_bytes(out, curr, 1); - else if (has_metadata(curr, "disp32")) - emit_hex_bytes(out, curr, 4); - } -} - -void add_imm_bytes(const line& in, line& out) { - for (int i = 0; i < SIZE(in.words); ++i) { - const word& curr = in.words.at(i); - if (has_metadata(curr, "imm8")) - emit_hex_bytes(out, curr, 1); - else if (has_metadata(curr, "imm32")) - emit_hex_bytes(out, curr, 4); - } -} - -void emit_hex_bytes(line& out, const word& w, int num) { - assert(num <= 4); - if (!is_hex_int(w.data)) { - out.words.push_back(w); - return; - } - uint32_t val = static_cast(parse_int(w.data)); - for (int i = 0; i < num; ++i) { - out.words.push_back(hex_byte_text(val & 0xff)); - val = val >> 8; - } -} - -bool is_hex_int(const string& s) { - if (s.empty()) return false; - size_t pos = 0; - if (s.at(0) == '-' || s.at(0) == '+') pos++; - if (s.substr(pos, pos+2) == "0x") pos += 2; - return s.find_first_not_of("0123456789abcdefABCDEF", pos) == string::npos; -} - -word hex_byte_text(uint8_t val) { - ostringstream out; - out << HEXBYTE << NUM(val); - word result; - result.data = out.str(); - return result; -} - -string to_string(const vector& in) { - ostringstream out; - for (int i = 0; i < SIZE(in); ++i) { - if (i > 0) out << ' '; - out << in.at(i).data; - } - return out.str(); -} - -// helper -void transform(const string& text_bytes) { - program p; - istringstream in(text_bytes); - parse(in, p); - if (trace_contains_errors()) return; - transform(p); -} - -:(scenario pack_immediate_constants_hex) -== 0x1 -# instruction effective address operand displacement immediate -# op subop mod rm32 base index scale r32 -# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes - bb 0x2a/imm32 # copy 42 to EBX -+translate: packing instruction 'bb 0x2a/imm32' -+translate: instruction after packing: 'bb 2a 00 00 00' -+run: copy imm32 0x0000002a to EBX - -:(scenarios transform) -:(scenario pack_silently_ignores_non_hex) -== 0x1 -# instruction effective address operand displacement immediate -# op subop mod rm32 base index scale r32 -# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes - bb foo/imm32 # copy foo to EBX -+translate: packing instruction 'bb foo/imm32' -# no change (we're just not printing metadata to the trace) -+translate: instruction after packing: 'bb foo' -$error: 0 -:(scenarios run) diff --git a/subx/024pack_operands.cc b/subx/024pack_operands.cc new file mode 100644 index 00000000..aa4fec7d --- /dev/null +++ b/subx/024pack_operands.cc @@ -0,0 +1,215 @@ +//: Operands can refer to bitfields smaller than a byte. This layer packs +//: operands into their containing bytes in the right order. + +:(scenario pack_immediate_constants) +== 0x1 +# instruction effective address operand displacement immediate +# op subop mod rm32 base index scale r32 +# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes + bb 0x2a/imm32 # copy 42 to EBX ++transform: packing instruction 'bb 0x2a/imm32' ++transform: instruction after packing: 'bb 2a 00 00 00' ++run: copy imm32 0x0000002a to EBX + +:(scenario pack_disp8) +== 0x1 +74 2/disp8 # jump 2 bytes away if ZF is set ++transform: packing instruction '74 2/disp8' ++transform: instruction after packing: '74 02' + +:(scenarios transform) +:(scenario pack_disp8_negative) +== 0x1 +# running this will cause an infinite loop +74 -1/disp8 # jump 1 byte before if ZF is set ++transform: packing instruction '74 -1/disp8' ++transform: instruction after packing: '74 ff' +:(scenarios run) + +:(scenario pack_modrm_imm32) +== 0x1 +# instruction effective address operand displacement immediate +# op subop mod rm32 base index scale r32 +# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes + 81 0/add/subop 3/mod/direct 3/ebx/rm32 1/imm32 # add 1 to EBX ++transform: packing instruction '81 0/add/subop 3/mod/direct 3/ebx/rm32 1/imm32' ++transform: instruction after packing: '81 c3 01 00 00 00' + +:(scenario pack_imm32_large) +== 0x1 +b9 0x080490a7/imm32 # copy to ECX ++transform: packing instruction 'b9 0x080490a7/imm32' ++transform: instruction after packing: 'b9 a7 90 04 08' + +:(before "End One-time Setup") +Transform.push_back(pack_operands); + +:(code) +void pack_operands(program& p) { + trace(99, "transform") << "-- pack operands" << end(); + if (p.segments.empty()) return; + segment& code = p.segments.at(0); + for (int i = 0; i < SIZE(code.lines); ++i) { + line& inst = code.lines.at(i); + if (all_hex_bytes(inst)) continue; + trace(99, "transform") << "packing instruction '" << to_string(/*with metadata*/inst) << "'" << end(); + pack_operands(inst); + trace(99, "transform") << "instruction after packing: '" << to_string(/*without metadata*/inst.words) << "'" << end(); + } +} + +void pack_operands(line& inst) { + line new_inst; + add_opcodes(inst, new_inst); + add_modrm_byte(inst, new_inst); + add_sib_byte(inst, new_inst); + add_disp_bytes(inst, new_inst); + add_imm_bytes(inst, new_inst); + inst.words.swap(new_inst.words); +} + +void add_opcodes(const line& in, line& out) { + out.words.push_back(in.words.at(0)); + if (in.words.at(0).data == "0f" || in.words.at(0).data == "f3") + out.words.push_back(in.words.at(1)); + if (in.words.at(0).data == "f3" && in.words.at(1).data == "0f") + out.words.push_back(in.words.at(2)); +} + +void add_modrm_byte(const line& in, line& out) { + uint8_t mod=0, reg_subop=0, rm32=0; + bool emit = false; + for (int i = 0; i < SIZE(in.words); ++i) { + const word& curr = in.words.at(i); + if (has_metadata(curr, "mod")) { + mod = hex_byte(curr.data); + emit = true; + } + else if (has_metadata(curr, "rm32")) { + rm32 = hex_byte(curr.data); + emit = true; + } + else if (has_metadata(curr, "r32")) { + reg_subop = hex_byte(curr.data); + emit = true; + } + else if (has_metadata(curr, "subop")) { + reg_subop = hex_byte(curr.data); + emit = true; + } + } + if (emit) + out.words.push_back(hex_byte_text((mod << 6) | (reg_subop << 3) | rm32)); +} + +void add_sib_byte(const line& in, line& out) { + uint8_t scale=0, index=0, base=0; + bool emit = false; + for (int i = 0; i < SIZE(in.words); ++i) { + const word& curr = in.words.at(i); + if (has_metadata(curr, "scale")) { + scale = hex_byte(curr.data); + emit = true; + } + else if (has_metadata(curr, "index")) { + index = hex_byte(curr.data); + emit = true; + } + else if (has_metadata(curr, "base")) { + base = hex_byte(curr.data); + emit = true; + } + } + if (emit) + out.words.push_back(hex_byte_text((scale << 6) | (index << 3) | base)); +} + +void add_disp_bytes(const line& in, line& out) { + for (int i = 0; i < SIZE(in.words); ++i) { + const word& curr = in.words.at(i); + if (has_metadata(curr, "disp8")) + emit_hex_bytes(out, curr, 1); + else if (has_metadata(curr, "disp32")) + emit_hex_bytes(out, curr, 4); + } +} + +void add_imm_bytes(const line& in, line& out) { + for (int i = 0; i < SIZE(in.words); ++i) { + const word& curr = in.words.at(i); + if (has_metadata(curr, "imm8")) + emit_hex_bytes(out, curr, 1); + else if (has_metadata(curr, "imm32")) + emit_hex_bytes(out, curr, 4); + } +} + +void emit_hex_bytes(line& out, const word& w, int num) { + assert(num <= 4); + if (!is_hex_int(w.data)) { + out.words.push_back(w); + return; + } + uint32_t val = static_cast(parse_int(w.data)); + for (int i = 0; i < num; ++i) { + out.words.push_back(hex_byte_text(val & 0xff)); + val = val >> 8; + } +} + +bool is_hex_int(const string& s) { + if (s.empty()) return false; + size_t pos = 0; + if (s.at(0) == '-' || s.at(0) == '+') pos++; + if (s.substr(pos, pos+2) == "0x") pos += 2; + return s.find_first_not_of("0123456789abcdefABCDEF", pos) == string::npos; +} + +word hex_byte_text(uint8_t val) { + ostringstream out; + out << HEXBYTE << NUM(val); + word result; + result.data = out.str(); + return result; +} + +string to_string(const vector& in) { + ostringstream out; + for (int i = 0; i < SIZE(in); ++i) { + if (i > 0) out << ' '; + out << in.at(i).data; + } + return out.str(); +} + +// helper +void transform(const string& text_bytes) { + program p; + istringstream in(text_bytes); + parse(in, p); + if (trace_contains_errors()) return; + transform(p); +} + +:(scenario pack_immediate_constants_hex) +== 0x1 +# instruction effective address operand displacement immediate +# op subop mod rm32 base index scale r32 +# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes + bb 0x2a/imm32 # copy 42 to EBX ++transform: packing instruction 'bb 0x2a/imm32' ++transform: instruction after packing: 'bb 2a 00 00 00' ++run: copy imm32 0x0000002a to EBX + +:(scenarios transform) +:(scenario pack_silently_ignores_non_hex) +== 0x1 +# instruction effective address operand displacement immediate +# op subop mod rm32 base index scale r32 +# 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes + bb foo/imm32 # copy foo to EBX ++transform: packing instruction 'bb foo/imm32' +# no change (we're just not printing metadata to the trace) ++transform: instruction after packing: 'bb foo' +$error: 0 +:(scenarios run) diff --git a/subx/025non_code_segment.cc b/subx/025non_code_segment.cc index ba713cca..5006e9a1 100644 --- a/subx/025non_code_segment.cc +++ b/subx/025non_code_segment.cc @@ -9,9 +9,10 @@ cd 12/imm8 +error: 12/imm8: metadata imm8 is only allowed in the (first) code segment :(before "End One-time Setup") -Transform.push_back(check_operands_in_non_code_segments); +Transform.push_back(ensure_operands_only_in_code_segments); :(code) -void check_operands_in_non_code_segments(/*const*/ program& p) { +void ensure_operands_only_in_code_segments(/*const*/ program& p) { + trace(99, "transform") << "-- ensure operands only in code segments" << end(); if (p.segments.empty()) return; for (int i = /*skip code segment*/1; i < SIZE(p.segments); ++i) { const segment& seg = p.segments.at(i); diff --git a/subx/026labels.cc b/subx/026labels.cc index fc52fe74..cc11eb0b 100644 --- a/subx/026labels.cc +++ b/subx/026labels.cc @@ -9,13 +9,14 @@ # 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes loop: 05 0x0d0c0b0a/imm32 # add to EAX -+translate: label 'loop' is at address 1 ++transform: label 'loop' is at address 1 :(before "End One-time Setup") -Transform.push_back(replace_labels); +Transform.push_back(rewrite_labels); :(code) -void replace_labels(program& p) { +void rewrite_labels(program& p) { + trace(99, "transform") << "-- rewrite labels" << end(); if (p.segments.empty()) return; segment& code = p.segments.at(0); map address; @@ -53,7 +54,7 @@ void compute_addresses_for_labels(const segment& code, map add raise << "'" << to_string(inst) << "': labels can only be the first word in a line.\n" << end(); string label = curr.data.substr(0, SIZE(curr.data)-1); put(address, label, current_byte); - trace(99, "translate") << "label '" << label << "' is at address " << (current_byte+code.start) << end(); + trace(99, "transform") << "label '" << label << "' is at address " << (current_byte+code.start) << end(); // no modifying current_byte; label definitions won't be in the final binary } } @@ -90,6 +91,6 @@ loop2: 05 0x0d0c0b0a/imm32 # add to EAX loop3: f -+translate: label 'loop' is at address 1 -+translate: label 'loop2' is at address 1 -+translate: label 'loop3' is at address 6 ++transform: label 'loop' is at address 1 ++transform: label 'loop2' is at address 1 ++transform: label 'loop3' is at address 6 -- cgit 1.4.1-2-gfad0