From c6f91e15a40970f3c6cb047d257df22ae63c6e76 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 13 Jul 2019 19:25:52 -0700 Subject: `test-convert-computes-addresses` bugfix six MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit map of how far we've gotten by now (functions with '*' independently tested): ✓ compute-offsets* ✓ compute-addresses* ✓ emit-output ✓ emit-headers ✓ emit-elf-header ✓ emit-hex-array* ✓ first emit-elf-program-header-entry ✓ emit-hex-array* ? second emit-elf-program-header-entry emit-hex-array* emit-segments* --- subx/apps/survey | Bin 40163 -> 40657 bytes subx/apps/survey.subx | 207 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 135 insertions(+), 72 deletions(-) diff --git a/subx/apps/survey b/subx/apps/survey index 0a9ad45c..1cf107fe 100755 Binary files a/subx/apps/survey and b/subx/apps/survey differ diff --git a/subx/apps/survey.subx b/subx/apps/survey.subx index 102e5793..c533dbfa 100644 --- a/subx/apps/survey.subx +++ b/subx/apps/survey.subx @@ -135,6 +135,15 @@ convert: # in : (address buffered-file), out : (address buffered-file) -> = max) break # emit-elf-program-header-entry(out, curr-segment) - # curr-segment += 20 # size of a row + # curr-segment += 16 # size of a row # # . prolog 55/push-EBP @@ -2384,6 +2429,15 @@ emit-headers: # out : (address buffered-file), segments : (address stream {stri # . save registers 50/push-EAX 51/push-ECX + # write(2/stderr, "emit-elf-header\n") {{{ + # . . push args + 68/push "emit-elf-header\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-elf-header(out, segments, labels) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0x10/disp8 . # push *(EBP+16) @@ -2405,75 +2459,84 @@ $emit-headers:loop: # if (curr-segment >= max) break 39/compare 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . . # compare EAX with ECX 0f 83/jump-if-greater-or-equal-unsigned $emit-headers:end/disp32 -#? # dump curr-segment->name {{{ -#? # . write(2/stderr, "about to emit ph entry: segment->name: ") -#? # . . push args -#? 68/push "about to emit ph entry: segment->name: "/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, &curr-segment) -#? # . . push args -#? 50/push-EAX -#? 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, " -> ") -#? # . . 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 -#? # . print-int32-buffered(Stderr, curr-segment->name) -#? # . . push args -#? ff 6/subop/push 0/mod/indirect 0/rm32/EAX . . . . . . # push *EAX -#? 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 -#? # }}} + # dump curr-segment->name {{{ + # . write(2/stderr, "about to emit ph entry: segment->name: ") + # . . push args + 68/push "about to emit ph entry: segment->name: "/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, &curr-segment) + # . . push args + 50/push-EAX + 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, " -> ") + # . . 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 + # . print-int32-buffered(Stderr, curr-segment->name) + # . . push args + ff 6/subop/push 0/mod/indirect 0/rm32/EAX . . . . . . # push *EAX + 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 + # }}} + # write(2/stderr, "emit-segment-header\n") {{{ + # . . push args + 68/push "emit-segment-header\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-elf-program-header-entry(out, curr-segment) # . . push args 50/push-EAX @@ -2482,8 +2545,8 @@ $emit-headers:loop: e8/call emit-elf-program-header-entry/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # curr-segment += 20 # size of a row - 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 0x14/imm32 # add to EAX + # curr-segment += 16 # size of a row + 81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 0x10/imm32 # add to EAX e9/jump $emit-headers:loop/disp32 $emit-headers:end: # . restore registers -- cgit 1.4.1-2-gfad0