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
27 ; ----------------------------------------------------------------------------
28 ; Initialization code. This is a constructor, so it is called on startup if
29 ; the linker has detected references to this module.
42 .if (.cpu .bitand ::CPU_ISET_65SC02)
43 ina ; Add 256 bytes safety area
45 add #1 ; Add 256 bytes safety area
52 ; ----------------------------------------------------------------------------
53 ; 6502 stack checking routine. Does not need to save any registers.
54 ; Safety zone for the hardware stack is 12 bytes.
60 bcc Fail ; Jump on stack overflow
63 ; ----------------------------------------------------------------------------
64 ; C stack checking routine. Does not need to save any registers.
70 ; Check the high byte of the software stack
79 @L1: bne CStackOverflow
85 ; We have a C stack overflow. Set the stack pointer to the initial value, so
86 ; we can continue without worrying about stack issues.
94 ; Generic abort entry. We should output a diagnostic here, but this is
95 ; difficult, since we're operating at a lower level here.
101 ; ----------------------------------------------------------------------------
106 ; Initial stack pointer value. Stack is reset to this in case of overflows to
107 ; allow program exit processing.
110 ; Stack low water mark.