diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-07-13 12:27:54 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-07-13 12:27:54 -0700 |
commit | a2593892deac85b3cd082f2a0110f241a49dd0c3 (patch) | |
tree | 87554984fe68b5656bb5972d3cc82ad06ebca4b7 /subx | |
parent | f518bd972e7830cbc99481ce9a31631a282a3f8d (diff) | |
download | mu-a2593892deac85b3cd082f2a0110f241a49dd0c3.tar.gz |
fixed second bug, hit third
Diffstat (limited to 'subx')
-rw-r--r-- | subx/039debug.cc | 7 | ||||
-rw-r--r-- | subx/apps/subx-common.subx | 1 | ||||
-rw-r--r-- | subx/apps/survey.subx | 291 |
3 files changed, 293 insertions, 6 deletions
diff --git a/subx/039debug.cc b/subx/039debug.cc index 49c0b8b6..b308a7d4 100644 --- a/subx/039debug.cc +++ b/subx/039debug.cc @@ -95,11 +95,10 @@ if (!Watch_this_effective_address.empty()) { //: Not a general mechanism; by the time you get here you're willing to hack //: on the emulator. :(after "Run One Instruction") -if (contains_key(Symbol_name, EIP) && get(Symbol_name, EIP) == "$dump-stream-at-ESI") - dump_stream_at_ESI(); +if (contains_key(Symbol_name, EIP) && get(Symbol_name, EIP) == "$dump-stream-at-EAX") + dump_stream_at(Reg[EAX].u); :(code) -void dump_stream_at_ESI() { - uint32_t stream_start = Reg[ESI].i; +void dump_stream_at(uint32_t stream_start) { int32_t stream_length = read_mem_i32(stream_start + 8); dbg << "stream length: " << std::dec << stream_length << end(); for (int i = 0; i < stream_length + 12; ++i) diff --git a/subx/apps/subx-common.subx b/subx/apps/subx-common.subx index 2ebf9807..60bb6cc2 100644 --- a/subx/apps/subx-common.subx +++ b/subx/apps/subx-common.subx @@ -53,6 +53,7 @@ get: # table : (address stream {string, _}), key : (address string), row-size : # curr/ECX = table->data 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 0xc/disp8 . # copy ESI+12 to ECX # max/EDX = table->data + table->write + # HERE: table->write is too large 8b/copy 0/mod/indirect 6/rm32/ESI . . . 2/r32/EDX . . # copy *ESI to EDX 8d/copy-address 0/mod/indirect 4/rm32/sib 1/base/ECX 2/index/EDX . 2/r32/EDX . . # copy ECX+EDX to EDX $get:search-loop: diff --git a/subx/apps/survey.subx b/subx/apps/survey.subx index 659184da..7f44be4c 100644 --- a/subx/apps/survey.subx +++ b/subx/apps/survey.subx @@ -135,6 +135,52 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 2/rm32/EDX . . . 4/r32/ESP . . # copy ESP to EDX + # dump labels->write {{{ + # . write(2/stderr, "labels->write initially: ") + # . . push args + 68/push "labels->write initially: "/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . clear-stream(Stderr+4) + # . . save EAX + 50/push-EAX + # . . push args + b8/copy-to-EAX Stderr/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . . restore EAX + 58/pop-to-EAX + # . print-int32-buffered(Stderr, labels) + # . . push args + ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . . # push *EDX + 68/push Stderr/imm32 + # . . call + e8/call print-int32-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . flush(Stderr) + # . . push args + 68/push Stderr/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . write(2/stderr, "\n") + # . . push args + 68/push "\n"/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # }}} # compute-offsets(in, segments, labels) # . . push args 52/push-EDX @@ -144,6 +190,52 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void e8/call compute-offsets/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP + # dump labels->write {{{ + # . write(2/stderr, "labels->write after compute-offsets: ") + # . . push args + 68/push "labels->write after compute-offsets: "/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . clear-stream(Stderr+4) + # . . save EAX + 50/push-EAX + # . . push args + b8/copy-to-EAX Stderr/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . . restore EAX + 58/pop-to-EAX + # . print-int32-buffered(Stderr, labels) + # . . push args + ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . . # push *EDX + 68/push Stderr/imm32 + # . . call + e8/call print-int32-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . flush(Stderr) + # . . push args + 68/push Stderr/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . write(2/stderr, "\n") + # . . push args + 68/push "\n"/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # }}} # compute-addresses(segments, labels) # . . push args 52/push-EDX @@ -151,7 +243,53 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void # . . call e8/call compute-addresses/disp32 # . . discard args - 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x10/imm32 # add to ESP + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0x8/imm32 # add to ESP + # dump labels->write {{{ + # . write(2/stderr, "labels->write after compute-addresses: ") + # . . push args + 68/push "labels->write after compute-addresses: "/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . clear-stream(Stderr+4) + # . . save EAX + 50/push-EAX + # . . push args + b8/copy-to-EAX Stderr/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . . restore EAX + 58/pop-to-EAX + # . print-int32-buffered(Stderr, labels) + # . . push args + ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . . # push *EDX + 68/push Stderr/imm32 + # . . call + e8/call print-int32-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . flush(Stderr) + # . . push args + 68/push Stderr/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . write(2/stderr, "\n") + # . . push args + 68/push "\n"/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # }}} # rewind-stream(in) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) @@ -159,6 +297,78 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> <void e8/call rewind-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP +#? # dump *Trace-stream {{{ +#? # . write(2/stderr, "^") +#? # . . push args +#? 68/push "^"/imm32 +#? 68/push 2/imm32/stderr +#? # . . call +#? e8/call write/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +#? # . write-stream(2/stderr, *Trace-stream) +#? # . . push args +#? ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Trace-stream/disp32 # push *Trace-stream +#? 68/push 2/imm32/stderr +#? # . . call +#? e8/call write-stream/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +#? # . write(2/stderr, "$\n") +#? # . . push args +#? 68/push "$\n"/imm32 +#? 68/push 2/imm32/stderr +#? # . . call +#? e8/call write/disp32 +#? # . . discard args +#? 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +#? # }}} + # dump labels->write {{{ + # . write(2/stderr, "labels->write after rewinding input: ") + # . . push args + 68/push "labels->write after rewinding input: "/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . clear-stream(Stderr+4) + # . . save EAX + 50/push-EAX + # . . push args + b8/copy-to-EAX Stderr/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . . restore EAX + 58/pop-to-EAX + # . print-int32-buffered(Stderr, labels) + # . . push args + ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . . # push *EDX + 68/push Stderr/imm32 + # . . call + e8/call print-int32-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . flush(Stderr) + # . . push args + 68/push Stderr/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . write(2/stderr, "\n") + # . . push args + 68/push "\n"/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # }}} # emit-output(in, out, segments, labels) # . . push args 52/push-EDX @@ -183,6 +393,7 @@ $convert:end: test-convert-computes-addresses: # input: # == code 0x1 + # Entry: # ab x/imm32 # == data 0x1000 # x: @@ -239,6 +450,14 @@ test-convert-computes-addresses: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . write(_test-input-stream, "Entry:\n") + # . . push args + 68/push "Entry:\n"/imm32 + 68/push _test-input-stream/imm32 + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # . write(_test-input-stream, "ab x/imm32\n") # . . push args 68/push "ab x/imm32\n"/imm32 @@ -1089,6 +1308,15 @@ test-compute-offsets: e8/call check-trace-contains/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . check-ints-equal(labels->write, 0x10, msg) + # . . push args + 68/push "F - test-compute-offsets-maintains-labels-write-index"/imm32 + 68/push 0x10/imm32/1-entry + ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . . # push *EDX + # . . call + e8/call check-ints-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # . epilog 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP 5d/pop-to-EBP @@ -1475,6 +1703,15 @@ test-compute-addresses: e8/call check-trace-contains/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . check-ints-equal(labels->write, 0x20, msg) + # . . push args + 68/push "F - test-compute-addresses-maintains-labels-write-index"/imm32 + 68/push 0x20/imm32/2-entries + ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . . # push *EDX + # . . call + e8/call check-ints-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP # . epilog 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP 5d/pop-to-EBP @@ -1497,6 +1734,55 @@ emit-output: # in : (address buffered-file), out : (address buffered-file), seg e8/call emit-headers/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP + # dump labels->write {{{ + # . write(2/stderr, "labels->write after emit-headers: ") + # . . push args + 68/push "labels->write after emit-headers: "/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # . clear-stream(Stderr+4) + # . . save EAX + 50/push-EAX + # . . push args + b8/copy-to-EAX Stderr/imm32 + 05/add-to-EAX 4/imm32 + 50/push-EAX + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . . restore EAX + 58/pop-to-EAX + # . print-int32-buffered(Stderr, labels) + # . . push args + 52/push-EDX + 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 8/disp8 . # copy *(EBP+8) to EDX + ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . . # push *EDX + 68/push Stderr/imm32 + # . . call + e8/call print-int32-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + 5a/pop-to-EDX + # . flush(Stderr) + # . . push args + 68/push Stderr/imm32 + # . . call + e8/call flush/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + # . write(2/stderr, "\n") + # . . push args + 68/push "\n"/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP + # }}} # emit-segments(in, out, segments, labels) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0x14/disp8 . # push *(EBP+20) @@ -2342,11 +2628,12 @@ emit-elf-header: # out : (address buffered-file), segments : (address stream {s # *Elf_e_entry = get(labels, "Entry")->address # . EAX = labels 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 0x10/disp8 . # copy *(EBP+16) to EAX +#? $dump-stream-at-EAX: # . label-info/EAX = get(labels, "Entry", row-size=16) # . . push args 68/push 0x10/imm32/row-size 68/push "Entry"/imm32 - ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0x10/disp8 . # push *(EBP+16) + 50/push-EAX # . . call e8/call get/disp32 # . . discard args |