]> git.sur5r.net Git - cc65/blobdiff - libsrc/runtime/stkchk.s
syschdir by Stefan Haubenthal
[cc65] / libsrc / runtime / stkchk.s
index 712da3094564b14e4b87623ffef178fdf335342d..ee0b7144c80fc7316fc5d611f970bb562394454d 100644 (file)
 
        ; Use macros for better readability
        .macpack        generic
+        .macpack        cpu
 
-.code
 
 ; ----------------------------------------------------------------------------
 ; Initialization code. This is a constructor, so it is called on startup if
 ; the linker has detected references to this module.
 
+.segment        "INIT"
+
 .proc  initstkchk
 
-       lda     sp
-       sta     initialsp
-       sub     #<__STACKSIZE__
-       sta     lowwater
-       lda     sp+1
-       sta     initialsp+1
-       sbc     #>__STACKSIZE__
-       add     #1                      ; Add 256 bytes safety area
-       sta     lowwater+1
-       rts
+       lda     sp
+       sta     initialsp
+       sub     #<__STACKSIZE__
+       sta     lowwater
+       lda     sp+1
+       sta     initialsp+1
+       sbc     #>__STACKSIZE__
+.if (.cpu .bitand ::CPU_ISET_65SC02)
+               ina                     ; Add 256 bytes safety area
+.else
+               add     #1              ; Add 256 bytes safety area
+.endif
+       sta     lowwater+1
+       rts
 
 .endproc
 
 ; ----------------------------------------------------------------------------
 ; 6502 stack checking routine. Does not need to save any registers.
-; Safety zone for the hardware stack is 10 bytes.
+; Safety zone for the hardware stack is 12 bytes.
+
+.code
 
 stkchk:        tsx
-               cpx     #10
+               cpx     #12
                bcc     Fail            ; Jump on stack overflow
-       rts                     ; Return if ok
+       rts                     ; Return if ok
 
 ; ----------------------------------------------------------------------------
 ; C stack checking routine. Does not need to save any registers.
 
+.code
+
 cstkchk:
 
 ; Check the high byte of the software stack
@@ -85,7 +95,7 @@ CStackOverflow:
 ; difficult, since we're operating at a lower level here.
 
 Fail:  lda     #4
-       jsr     pusha0
+        ldx     #0
        jmp     _exit
 
 ; ----------------------------------------------------------------------------
@@ -101,3 +111,4 @@ initialsp:  .word   0
 lowwater:      .word   0
 
 
+