about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-07-12 23:41:23 -0700
committerKartik Agaram <vc@akkartik.com>2019-07-12 23:41:23 -0700
commitfb935eaa7e044b2e55490972e95233f3321e6d87 (patch)
tree1742a052ab81126141ba238368eae072e9f4eb85 /subx
parent8ba17d839eeca97bbf3947ce1995350b0858f233 (diff)
downloadmu-fb935eaa7e044b2e55490972e95233f3321e6d87.tar.gz
fixed one bug, hit another
I carefully logged the segment a label is declared in but forgot to
actually save it in the table. This has been a theoretic concern for
some time, but I've never seen it actually happen until now. SubX is
just too low level.

Now I get past the first two phases but code generation fails to find
the 'Entry' label.
Diffstat (limited to 'subx')
-rwxr-xr-xsubx/apps/surveybin39892 -> 39901 bytes
-rw-r--r--subx/apps/survey.subx145
2 files changed, 87 insertions, 58 deletions
diff --git a/subx/apps/survey b/subx/apps/survey
index aeb2290b..2e90499c 100755
--- a/subx/apps/survey
+++ b/subx/apps/survey
Binary files differdiff --git a/subx/apps/survey.subx b/subx/apps/survey.subx
index deedebef..bda3f856 100644
--- a/subx/apps/survey.subx
+++ b/subx/apps/survey.subx
@@ -378,8 +378,9 @@ compute-offsets:  # in : (address buffered-file), segments : (address stream {st
     #       else if is-label?(word-slice)
     #         strip trailing ':' from word-slice
     #         x : (address label-info) = get-or-insert(labels, name)
-    #         x->segment-offset = segment-offset
+    #         x->segment-name = curr-segment-name
     #         trace("label '", word-slice, "' is in segment '", curr-segment-name, "'.")
+    #         x->segment-offset = segment-offset
     #         trace("label '", word-slice, "' is at segment offset ", segment-offset, ".")
     #         # labels occupy no space, so no need to increment offsets
     #       else
@@ -732,11 +733,8 @@ $compute-offsets:case-label:
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
 $compute-offsets:save-label-offset:
-    # x->segment-offset = segment-offset
-    # . EBX = segment-offset
-    8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   compute-offsets:segment-offset/disp32  # copy *segment-offset to EBX
-    # . x->segment-offset = EBX
-    89/copy                         1/mod/*+disp8   0/rm32/EAX    .           .             .           3/r32/EBX   4/disp8         .                 # copy EBX to *(EAX+4)
+    # x->segment-name = curr-segment-name
+    89/copy                         0/mod/indirect  0/rm32/EAX    .           .             .           6/r32/ESI   .               .                 # copy ESI to *EAX
     # trace-slsss("label '" word-slice/EDX "' is in segment '" current-segment-name "'.")
     # . . push args
     68/push  "'."/imm32
@@ -748,6 +746,11 @@ $compute-offsets:save-label-offset:
     e8/call  trace-slsss/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0x14/imm32        # add to ESP
+    # x->segment-offset = segment-offset
+    # . EBX = segment-offset
+    8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   compute-offsets:segment-offset/disp32  # copy *segment-offset to EBX
+    # . x->segment-offset = EBX
+    89/copy                         1/mod/*+disp8   0/rm32/EAX    .           .             .           3/r32/EBX   4/disp8         .                 # copy EBX to *(EAX+4)
     # trace-slsns("label '" word-slice/EDX "' is at segment offset " *segment-offset/EAX ".")
     # . . EAX = file-offset
     b8/copy-to-EAX compute-offsets:segment-offset/imm32
@@ -1172,6 +1175,32 @@ $compute-addresses:segment-loop:
     05/add-to-EAX  0x10/imm32
     eb/jump  $compute-addresses:segment-loop/disp8
 $compute-addresses:segment-break:
+#?     # 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
+#?     # }}}
     # ESI = labels
     8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           6/r32/ESI   0xc/disp8       .                 # copy *(EBP+12) to ESI
 #? $dump-stream-at-ESI:
@@ -1184,60 +1213,60 @@ $compute-addresses:label-loop:
     # if (lrow >= 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  $compute-addresses:end/disp32
-    # dump lrow->key {{{
-    # . write(2/stderr, "label: ")
-    # . . push args
-    68/push  "label: "/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, lrow->key)
-    # . . push args
-    ff          6/subop/push        0/mod/indirect  0/rm32/EAX    .           .             .           .           .               .                 # push *EAX
-    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, "$\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 lrow->key {{{
+#?     # . write(2/stderr, "label: ")
+#?     # . . push args
+#?     68/push  "label: "/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, lrow->key)
+#?     # . . push args
+#?     ff          6/subop/push        0/mod/indirect  0/rm32/EAX    .           .             .           .           .               .                 # push *EAX
+#?     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, "$\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
+#?     # }}}
     # seg-name/EDX = lrow->segment-name
     8b/copy                         1/mod/*+disp8   0/rm32/EAX    .           .             .           2/r32/EDX   4/disp8         .                 # copy *EAX to EDX
-    # dump seg-name {{{
-    # . write(2/stderr, "compute-addresses: seg-name: ")
-    # . . push args
-    68/push  "seg-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
-    # . write(2/stderr, seg-name)
-    # . . push args
-    52/push-EDX
-    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, "$\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 seg-name {{{
+#?     # . write(2/stderr, "compute-addresses: seg-name: ")
+#?     # . . push args
+#?     68/push  "seg-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
+#?     # . write(2/stderr, seg-name)
+#?     # . . push args
+#?     52/push-EDX
+#?     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, "$\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
+#?     # }}}
     # label-seg/EDX : (address segment-info) = get(segments, seg-name, row-size=16)
     # . save EAX
     50/push-EAX