diff --git a/317abort.subx b/317abort.subx index 8c6b3b48..3a2aad43 100644 --- a/317abort.subx +++ b/317abort.subx @@ -15,13 +15,24 @@ abort: # e: (addr array byte) eb/jump loop/disp8 } +# destroys the heap dump-call-stack: # . prologue 55/push-ebp 89/<- %ebp 4/r32/esp # . save registers 50/push-eax + 51/push-ecx + 52/push-edx 53/push-ebx + # var labels/edx: (stream {label-name, address} 0x1000) + 81 5/subop/subtract %esp 0xc000/imm32 + 68/push 0xc000/imm32 + 68/push 0/imm32/read + 68/push 0/imm32/write + 89/<- %edx 4/r32/esp + # + (load-debug-symbols %edx) # destroys the heap # traverse the linked list of ebp pointers: https://wiki.osdev.org/Stack_Trace 8b/-> *ebp 3/r32/ebx { @@ -37,8 +48,55 @@ dump-call-stack: e9/jump loop/disp32 } $dump-call-stack:end: + # . reclaim locals + 81 0/subop/add %esp 0x100c/imm32 # . restore registers 5b/pop-to-ebx + 5a/pop-to-edx + 59/pop-to-ecx + 58/pop-to-eax + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +load-debug-symbols: # labels/edx: (stream {label-name, address}) + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # . save registers + 50/push-eax + 51/push-ecx + 52/push-edx + 53/push-ebx + # create space for a stream on the heap, clobbering any existing data + # var ecx: (addr stream byte) + b9/copy-to-ecx 0x03000000/imm32 + c7 0/subop/copy *ecx 0/imm32 # write index + c7 0/subop/copy *(ecx+4) 0/imm32 # read index + c7 0/subop/copy *(ecx+8) 0x01000000/imm32 # stream capacity = 16MB + # load 0x100 sectors starting from sector 10080 = 0x2760 + (load-sectors Primary-bus-primary-drive 0x2760 0x100 %ecx) + b8/copy-to-eax 0x0300000c/imm32 + b9/copy-to-ecx 0/imm32 + { + 3d/compare-eax-and 0x030000ff/imm32 + 74/jump-if-= break/disp8 + # + 8a/byte-> *eax 1/r32/CL + (draw-grapheme-at-cursor 0 %ecx 7 0) + (move-cursor-rightward-and-downward 0) + # + 40/increment-eax + eb/jump loop/disp8 + } +$load-debug-symbols:end: + # . reclaim locals + 81 0/subop/add %esp 0x100c/imm32 + # . restore registers + 5b/pop-to-ebx + 5a/pop-to-edx + 59/pop-to-ecx 58/pop-to-eax # . epilogue 89/<- %esp 5/r32/ebp diff --git a/boot.subx b/boot.subx index 7ded7309..afe826ca 100644 --- a/boot.subx +++ b/boot.subx @@ -889,12 +889,33 @@ Font: == data -# We'll be gaining access just to the secondary drive on the primary bus for -# now. It will have the designated 'data' disk so we don't mess with the code -# disk. -# -# The type definition for this variable is in safe Mu (rather than unsafe -# SubX) code. +# code disk +# All ports are 8-bit except data-port, which is 16-bit. +Primary-bus-primary-drive: + # command-port: int (write) + 0x1f7/imm32 + # status-port: int (read) + 0x1f7/imm32 + # alternative-status-port: int (read) + 0x3f6/imm32 + # error-port: int (read) + 0x1f1/imm32 + # drive-and-head-port: int + 0x1f6/imm32 + # sector-count-port: int + 0x1f2/imm32 + # lba-low-port: int + 0x1f3/imm32 + # lba-mid-port: int + 0x1f4/imm32 + # lba-high-port: int + 0x1f5/imm32 + # data-port: int + 0x1f0/imm32 + # drive-code: byte # only drive-specific field + 0xe0/imm32 # LBA mode also enabled + +# data disk # All ports are 8-bit except data-port, which is 16-bit. Primary-bus-secondary-drive: # command-port: int (write) @@ -944,6 +965,7 @@ load-sectors: # disk: (addr disk), lba: int, n: int, out: (addr stream byte) { # poll for results #? (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "waiting for sector.." 7 0) +#? (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "." 7 0) (while-ata-busy *(ebp+8)) (until-ata-data-available *(ebp+8)) #? (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "reading\n" 7 0) diff --git a/ex2.mu b/ex2.mu index cd170aa7..148b424e 100644 --- a/ex2.mu +++ b/ex2.mu @@ -25,4 +25,13 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) y <- increment loop } + foo +} + +fn foo { + bar +} + +fn bar { + abort "aaa" } diff --git a/translate_subx b/translate_subx index 66df2a91..8d97b197 100755 --- a/translate_subx +++ b/translate_subx @@ -42,9 +42,15 @@ then fi # Latter half of disk is for debug info. -dd if=labels of=code.img seek=10080 conv=notrunc +dd if=labels of=code.img seek=10080 conv=notrunc # keep this sync'd with abort.subx if [ `stat --printf="%s" labels` -ge 131072 ] # 256 sectors * 512 bytes per sector, the most an ATA drive can read in a single command then echo "labels won't all be loaded on abort" exit 1 fi + +if [ `wc -l < labels` -gt 4096 ] # 0x1000 stream capacity in abort.subx +then + echo "abort will go into infinite regress" + exit 1 +fi diff --git a/translate_subx_emulated b/translate_subx_emulated index aef29801..439befcd 100755 --- a/translate_subx_emulated +++ b/translate_subx_emulated @@ -46,9 +46,15 @@ then fi # Latter half of disk is for debug info. -dd if=labels of=code.img seek=10080 conv=notrunc +dd if=labels of=code.img seek=10080 conv=notrunc # keep this sync'd with abort.subx if [ `stat --printf="%s" labels` -ge 131072 ] # 256 sectors * 512 bytes per sector, the most an ATA drive can read in a single command then echo "labels won't all be loaded on abort" exit 1 fi + +if [ `wc -l < labels` -gt 4096 ] # 0x1000 stream capacity in abort.subx +then + echo "abort will go into infinite regress" + exit 1 +fi