`test-convert-computes-addresses` bugfix six
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*
This commit is contained in:
parent
62bb910301
commit
c6f91e15a4
BIN
subx/apps/survey
BIN
subx/apps/survey
Binary file not shown.
|
@ -135,6 +135,15 @@ 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
|
||||
# write(2/stderr, "compute-offsets\n") {{{
|
||||
# . . push args
|
||||
68/push "compute-offsets\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 +153,15 @@ 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
|
||||
# write(2/stderr, "compute-addresses\n") {{{
|
||||
# . . push args
|
||||
68/push "compute-addresses\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
|
||||
|
@ -159,6 +177,15 @@ 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
|
||||
# write(2/stderr, "emit-output\n") {{{
|
||||
# . . push args
|
||||
68/push "emit-output\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 *Trace-stream {{{
|
||||
#? # . write(2/stderr, "^")
|
||||
#? # . . push args
|
||||
|
@ -1586,6 +1613,15 @@ emit-output: # in : (address buffered-file), out : (address buffered-file), seg
|
|||
# . prolog
|
||||
55/push-EBP
|
||||
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
|
||||
# write(2/stderr, "emit-headers\n") {{{
|
||||
# . . push args
|
||||
68/push "emit-headers\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-headers(out, segments, labels)
|
||||
# . . push args
|
||||
ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0x14/disp8 . # push *(EBP+20)
|
||||
|
@ -1595,6 +1631,15 @@ 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
|
||||
# write(2/stderr, "emit-segments\n") {{{
|
||||
# . . push args
|
||||
68/push "emit-segments\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)
|
||||
|
@ -2376,7 +2421,7 @@ emit-headers: # out : (address buffered-file), segments : (address stream {stri
|
|||
# while true
|
||||
# if (curr-segment >= 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
|
||||
|
|
Loading…
Reference in New Issue