7524 - bring back some abort messages
Our infrastructure for displaying errors is far more rudimentary in baremetal. Many ways things can go wrong. But making the attempt seems better than not. I'm also making some effort to keep it easy to see what has been copied over from the top-level, by not modifying copied code to use syntax sugar and so on. It may not be an important enough reason to mix notations in a single file.
This commit is contained in:
parent
49424b1933
commit
0d246473c5
|
@ -23,7 +23,7 @@ read-byte: # s: (addr stream byte) -> result/eax: byte
|
|||
8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 . # copy *(esi+4) to ecx
|
||||
# if (f->read >= f->write) abort
|
||||
3b/compare 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . . # compare ecx with *esi
|
||||
0f 8d/jump-if->= $read-byte:end/disp32 # TODO: abort
|
||||
0f 8d/jump-if->= $read-byte:abort/disp32
|
||||
# result = f->data[f->read]
|
||||
31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax
|
||||
8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0xc/disp8 . # copy byte at *(esi+ecx+12) to AL
|
||||
|
@ -38,4 +38,11 @@ $read-byte:end:
|
|||
5d/pop-to-ebp
|
||||
c3/return
|
||||
|
||||
$read-byte:abort:
|
||||
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "read-byte: empty stream" 3) # 3=cyan
|
||||
{
|
||||
eb/jump loop/disp8
|
||||
}
|
||||
# never gets here
|
||||
|
||||
# . . vim:nowrap:textwidth=0
|
||||
|
|
|
@ -22,7 +22,7 @@ append-byte: # f: (addr stream byte), n: int
|
|||
8b/copy 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . . # copy *edi to ecx
|
||||
# if (f->write >= f->size) abort
|
||||
3b/compare 1/mod/*+disp8 7/rm32/edi . . . 1/r32/ecx 8/disp8 . # compare ecx with *(edi+8)
|
||||
7d/jump-if->= $append-byte:end/disp8 # TODO: abort
|
||||
7d/jump-if->= $append-byte:abort/disp8
|
||||
$append-byte:to-stream:
|
||||
# write to stream
|
||||
# f->data[f->write] = LSB(n)
|
||||
|
@ -40,6 +40,13 @@ $append-byte:end:
|
|||
5d/pop-to-ebp
|
||||
c3/return
|
||||
|
||||
$append-byte:abort:
|
||||
(draw-text-wrapping-down-then-right-from-cursor-over-full-screen 0 "append-byte: out of space\n" 3) # 3=cyan
|
||||
{
|
||||
eb/jump loop/disp8
|
||||
}
|
||||
# never gets here
|
||||
|
||||
test-append-byte-single:
|
||||
# - check that append-byte writes to first byte of 'file'
|
||||
# setup
|
||||
|
|
|
@ -65,11 +65,11 @@ write-to-stream: # s: (addr stream _), in: (addr byte), n: int
|
|||
8b/-> *(ebp+8) 7/r32/edi
|
||||
# var swrite/edx: int = s->write
|
||||
8b/-> *edi 2/r32/edx
|
||||
# if (swrite + n > s->size) return
|
||||
# if (swrite + n > s->size) abort
|
||||
8b/-> *(ebp+0x10) 1/r32/ecx
|
||||
01/add-to %ecx 2/r32/edx
|
||||
3b/compare 1/r32/ecx *(edi+8)
|
||||
0f 8f/jump-if-> $write-to-stream:end/disp32 # TODO: abort
|
||||
0f 8f/jump-if-> $write-to-stream:abort/disp32
|
||||
# var out/edx: (addr byte) = s->data + s->write
|
||||
8d/copy-address *(edi+edx+0xc) 2/r32/edx
|
||||
# var outend/ebx: (addr byte) = out + n
|
||||
|
@ -97,6 +97,13 @@ $write-to-stream:end:
|
|||
5d/pop-to-ebp
|
||||
c3/return
|
||||
|
||||
$write-to-stream:abort:
|
||||
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "write-to-stream: stream full" 3) # 3=cyan
|
||||
{
|
||||
eb/jump loop/disp8
|
||||
}
|
||||
# never gets here
|
||||
|
||||
read-from-stream: # s: (addr stream _), out: (addr byte), n: int
|
||||
# . prologue
|
||||
55/push-ebp
|
||||
|
@ -111,11 +118,11 @@ read-from-stream: # s: (addr stream _), out: (addr byte), n: int
|
|||
8b/-> *(ebp+8) 6/r32/esi
|
||||
# var sread/edx: int = s->read
|
||||
8b/-> *(esi+4) 2/r32/edx
|
||||
# if (sread + n > s->write) return
|
||||
# if (sread + n > s->write) abort
|
||||
8b/-> *(ebp+0x10) 1/r32/ecx
|
||||
01/add-to %ecx 2/r32/edx
|
||||
3b/compare 1/r32/ecx *esi
|
||||
0f 8f/jump-if-> $read-from-stream:end/disp32 # TODO: abort
|
||||
0f 8f/jump-if-> $read-from-stream:abort/disp32
|
||||
# var in/edx: (addr byte) = s->data + s->read
|
||||
8d/copy-address *(esi+edx+0xc) 2/r32/edx
|
||||
# var inend/ebx: (addr byte) = in + n
|
||||
|
@ -143,6 +150,12 @@ $read-from-stream:end:
|
|||
5d/pop-to-ebp
|
||||
c3/return
|
||||
|
||||
$read-from-stream:abort:
|
||||
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "read-from-stream: stream empty" 3) # 3=cyan
|
||||
{
|
||||
eb/jump loop/disp8
|
||||
}
|
||||
|
||||
stream-first: # s: (addr stream byte) -> result/eax: byte
|
||||
# . prologue
|
||||
55/push-ebp
|
||||
|
|
Loading…
Reference in New Issue