mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 20:18:04 +11:00
z80: implement stack overflow error condition
Also, remove underflow checks from next: it's taxing and useless because underflow check already takes place in each relevant native word.
This commit is contained in:
parent
78d4d15fcf
commit
d1de99d8c9
17
blk/076
17
blk/076
@ -1,6 +1,11 @@
|
|||||||
STACK OVERFLOW PROTECTION: To avoid having to check for stack
|
Stack underflow and overflow: In each native word involving
|
||||||
underflow after each pop operation (which can end up being
|
PSP popping, we check whether the stack is big enough. If it's
|
||||||
prohibitive in terms of costs), PS_ADDR should be set to
|
not we go in "uflw" (underflow) error condition, then abort.
|
||||||
at least 6 bytes before its actual limit. 6 bytes because we
|
|
||||||
seldom have words requiring more than 3 items from the stack.
|
We don't check RSP for underflow because the cost of the check
|
||||||
Then, at each "exit" call we check for stack underflow.
|
is significant and its usefulness is dubious: if RSP isn't
|
||||||
|
tightly in control, we're screwed anyways, and that, well
|
||||||
|
before we reach underflow.
|
||||||
|
|
||||||
|
Overflow condition happen when RSP and PSP meet somewhere in
|
||||||
|
the middle. That check is made at each "next" call.
|
||||||
|
1
blk/284
1
blk/284
@ -1,5 +1,4 @@
|
|||||||
PC ORG @ 1 + ! ( main )
|
PC ORG @ 1 + ! ( main )
|
||||||
( STACK OVERFLOW PROTECTION: See B76 )
|
|
||||||
SP PS_ADDR LDdn, IX RS_ADDR LDdn,
|
SP PS_ADDR LDdn, IX RS_ADDR LDdn,
|
||||||
( LATEST is a label to the latest entry of the dict. It is
|
( LATEST is a label to the latest entry of the dict. It is
|
||||||
written at offset 0x08 by the process or person building
|
written at offset 0x08 by the process or person building
|
||||||
|
16
blk/286
16
blk/286
@ -2,14 +2,14 @@ lblnext BSET PC ORG @ 0x1b + ! ( next )
|
|||||||
( This routine is jumped to at the end of every word. In it,
|
( This routine is jumped to at the end of every word. In it,
|
||||||
we jump to current IP, but we also take care of increasing
|
we jump to current IP, but we also take care of increasing
|
||||||
it by 2 before jumping. )
|
it by 2 before jumping. )
|
||||||
( Before we continue: are stacks within bounds? )
|
( Before we continue: are we overflowing? )
|
||||||
( PS ) HL PS_ADDR LDdn,
|
IX PUSH, EX(SP)HL, ( do EX to count the IX push in SP )
|
||||||
SP SUBHLd,
|
SP SUBHLd, HL POP,
|
||||||
JRC, lblofl BWR ( abortUnderflow-B285 )
|
IFNC, ( SP <= IX? overflow )
|
||||||
( RS ) IX PUSH, HL POP,
|
SP PS_ADDR LDdn, IX RS_ADDR LDdn,
|
||||||
DE RS_ADDR LDdn,
|
DE BIN( @ 0x13 ( oflw ) + LDdd(n),
|
||||||
DE SUBHLd,
|
JR, L3 FWR ( execute, B287 )
|
||||||
JRC, lblofl BWR ( IX < RS_ADDR? abortUnderflow-B285 )
|
THEN,
|
||||||
LDA(BC), E A LDrr, BC INCd,
|
LDA(BC), E A LDrr, BC INCd,
|
||||||
LDA(BC), D A LDrr, BC INCd,
|
LDA(BC), D A LDrr, BC INCd,
|
||||||
( continue to execute )
|
( continue to execute )
|
||||||
|
2
blk/287
2
blk/287
@ -1,4 +1,4 @@
|
|||||||
lblexec BSET L1 FSET ( B284 ) L2 FSET ( B285 )
|
lblexec BSET L1 FSET ( B284 ) L2 FSET ( B285 ) L3 FSET ( B286 )
|
||||||
( DE -> wordref )
|
( DE -> wordref )
|
||||||
( When we have a BIN( offset, we need to adjust stable
|
( When we have a BIN( offset, we need to adjust stable
|
||||||
ABI offsets. )
|
ABI offsets. )
|
||||||
|
Loading…
Reference in New Issue
Block a user