about summary refs log tree commit diff stats
path: root/313index-bounds-check.subx
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-03 22:09:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-03 22:21:03 -0800
commit71e4f3812982dba2efb471283d310224e8db363e (patch)
treeea111a1acb8b8845dbda39c0e1b4bac1d198143b /313index-bounds-check.subx
parentc6b928be29ac8cdb4e4d6e1eaa20420ff03e5a4c (diff)
downloadmu-71e4f3812982dba2efb471283d310224e8db363e.tar.gz
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.

So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.

A couple of things have gotten dropped in this process:
  - I had old ways to run on just a Linux kernel, or with a Soso kernel.
    No more.
  - I had some old tooling for running a single test at the cursor. I haven't
    used that lately. Maybe I'll bring it back one day.

The reorg isn't done yet. Still to do:
  - redo documentation everywhere. All the README files, all other markdown,
    particularly vocabulary.md.
  - clean up how-to-run comments at the start of programs everywhere
  - rethink what to do with the html/ directory. Do we even want to keep
    supporting it?

In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
Diffstat (limited to '313index-bounds-check.subx')
-rw-r--r--313index-bounds-check.subx64
1 files changed, 19 insertions, 45 deletions
diff --git a/313index-bounds-check.subx b/313index-bounds-check.subx
index 615935b3..c9d01ee2 100644
--- a/313index-bounds-check.subx
+++ b/313index-bounds-check.subx
@@ -26,17 +26,16 @@ __check-mu-array-bounds:  # index: int, elem-size: int, arr-size: int, function-
     39/compare %eax 1/r32/ecx
     0f 82/jump-if-unsigned< $__check-mu-array-bounds:end/disp32  # negative index should always abort
     # abort if necessary
-    (write-buffered Stderr "fn ")
-    (write-buffered Stderr *(ebp+0x14))
-    (write-buffered Stderr ": offset ")
-    (write-int32-hex-buffered Stderr %eax)
-    (write-buffered Stderr " is too large for array '")
-    (write-buffered Stderr *(ebp+0x18))
-    (write-buffered Stderr "'\n")
-    (flush Stderr)
-    # exit(1)
-    bb/copy-to-ebx 1/imm32
-    e8/call syscall_exit/disp32
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "fn " 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x14) 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 ": offset " 3 0)  # 3=cyan
+    (draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen 0 %eax 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 " is too large for array '" 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x18) 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "'" 3 0)  # 3=cyan
+    {
+      eb/jump loop/disp8
+    }
     # never gets here
 $__check-mu-array-bounds:end:
     # . restore registers
@@ -49,38 +48,13 @@ $__check-mu-array-bounds:end:
     c3/return
 
 __check-mu-array-bounds:overflow:
-    # "fn " function-name ": offset to array '" array-name "' overflowed 32 bits\n"
-    (write-buffered Stderr "fn ")
-    (write-buffered Stderr *(ebp+0x14))
-    (write-buffered Stderr ": offset to array '")
-    (write-buffered Stderr *(ebp+0x18))
-    (write-buffered Stderr "' overflowed 32 bits\n")
-    (flush Stderr)
-    # exit(1)
-    bb/copy-to-ebx 1/imm32
-    e8/call syscall_exit/disp32
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "fn " 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x14) 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 ": offset to array '" 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "offset to array overflowed 32 bits" 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x18) 3 0)  # 3=cyan
+    (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "' overflowed 32 bits" 3 0)  # 3=cyan
+    {
+      eb/jump loop/disp8
+    }
     # never gets here
-
-# potential alternative
-
-#? __bounds-check:  # msg: (addr array byte)
-#?   (write-buffered Stderr "abort: array bounds exceeded in fn ")
-#?   8b/-> *(esp+4) 0/r32/eax  # we're going to abort, so just clobber away
-#?   (write-buffered Stderr %eax)
-#?   (write-buffered Stderr Newline)
-#?   # exit(1)
-#?   bb/copy-to-ebx 1/imm32
-#?   e8/call syscall_exit/disp32
-
-# to be called as follows:
-#   var/reg <- index arr/rega: (addr array T), idx/regi: int
-#     | if size-of(T) is 1, 2, 4 or 8
-#         => # temporarily save array size to reg to check bounds
-#            "8b/-> *" rega " " reg "/r32"
-#            "c1/shift 5/subop/right %" reg " " log2(size-of(T)) "/imm32"
-#            "3b/compare " reg "/r32 *" rega
-#            "68/push \"" function "\"/imm32"  # pass function name to error message
-#            "0f 8d/jump-if->= __bounds_check/disp32"
-#            "81 0/subop/add %esp 4/imm32"  # drop function name
-#            # actually save the index addr in reg
-#            "8d/copy-address *(" rega "+" regi "<<" log2(size-of(T)) "+4) " reg "/r32"