2 ; Ullrich von Bassewitz, 19.03.2001
4 ; Stack checking code. These are actually two routines, one to check the C
5 ; stack, and the other one to check the 6502 hardware stack.
6 ; For performance reasons (to avoid having to pass a parameter), the compiler
7 ; calls the cstkchk routine *after* allocating space on the stack. So the
8 ; stackpointer may already be invalid if this routine is called. In addition
9 ; to that, pushs and pops that are needed for expression evaluation are not
10 ; checked (this would be way too much overhead). As a consequence we will
11 ; operate using a safety area at the stack bottom. Once the stack reaches this
12 ; safety area, we consider it an overflow, even if the stack is still inside
16 .export stkchk, cstkchk
17 .constructor initstkchk, 25
18 .import __STACKSIZE__ ; Linker defined
22 ; Use macros for better readability
26 ; ----------------------------------------------------------------------------
27 ; Initialization code. This is a constructor, so it is called on startup if
28 ; the linker has detected references to this module.
41 add #1 ; Add 256 bytes safety area
47 ; ----------------------------------------------------------------------------
48 ; 6502 stack checking routine. Does not need to save any registers.
49 ; Safety zone for the hardware stack is 12 bytes.
55 bcc Fail ; Jump on stack overflow
58 ; ----------------------------------------------------------------------------
59 ; C stack checking routine. Does not need to save any registers.
65 ; Check the high byte of the software stack
74 @L1: bne CStackOverflow
80 ; We have a C stack overflow. Set the stack pointer to the initial value, so
81 ; we can continue without worrying about stack issues.
89 ; Generic abort entry. We should output a diagnostic here, but this is
90 ; difficult, since we're operating at a lower level here.
96 ; ----------------------------------------------------------------------------
101 ; Initial stack pointer value. Stack is reset to this in case of overflows to
102 ; allow program exit processing.
105 ; Stack low water mark.