diff options
Diffstat (limited to 'subx/apps/survey.subx')
-rw-r--r-- | subx/apps/survey.subx | 291 |
1 files changed, 289 insertions, 2 deletions
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 |