load debug info from disk on abort

This commit is contained in:
Kartik K. Agaram 2021-05-14 21:32:06 -07:00
parent 7205c2465f
commit 56c9248109
5 changed files with 109 additions and 8 deletions

View File

@ -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

View File

@ -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)

9
ex2.mu
View File

@ -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"
}

View File

@ -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

View File

@ -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