Move initialization code into the init segment
git-svn-id: svn://svn.cc65.org/cc65/trunk@3404 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -20,17 +20,17 @@
|
||||
|
||||
.macpack cpu
|
||||
|
||||
.code
|
||||
|
||||
; --------------------------------------------------------------------------
|
||||
; Initialize library modules
|
||||
|
||||
.segment "INIT"
|
||||
|
||||
.proc initlib
|
||||
|
||||
ldy #<(__CONSTRUCTOR_COUNT__*2)
|
||||
ldy #<(__CONSTRUCTOR_COUNT__*2)
|
||||
beq exit
|
||||
lda #<__CONSTRUCTOR_TABLE__
|
||||
ldx #>__CONSTRUCTOR_TABLE__
|
||||
lda #<__CONSTRUCTOR_TABLE__
|
||||
ldx #>__CONSTRUCTOR_TABLE__
|
||||
jmp condes
|
||||
exit: rts
|
||||
|
||||
@@ -40,13 +40,16 @@ exit: rts
|
||||
; --------------------------------------------------------------------------
|
||||
; Cleanup library modules
|
||||
|
||||
.code
|
||||
|
||||
.proc donelib
|
||||
|
||||
ldy #<(__DESTRUCTOR_COUNT__*2)
|
||||
beq initlib::exit
|
||||
beq exit
|
||||
lda #<__DESTRUCTOR_TABLE__
|
||||
ldx #>__DESTRUCTOR_TABLE__
|
||||
jmp condes
|
||||
exit: rts
|
||||
|
||||
.endproc
|
||||
|
||||
|
||||
@@ -22,24 +22,25 @@
|
||||
; Use macros for better readability
|
||||
.macpack generic
|
||||
|
||||
.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__
|
||||
add #1 ; Add 256 bytes safety area
|
||||
sta lowwater+1
|
||||
rts
|
||||
|
||||
.endproc
|
||||
|
||||
@@ -47,14 +48,18 @@
|
||||
; 6502 stack checking routine. Does not need to save any registers.
|
||||
; Safety zone for the hardware stack is 12 bytes.
|
||||
|
||||
.code
|
||||
|
||||
stkchk: tsx
|
||||
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
|
||||
@@ -101,4 +106,4 @@ initialsp: .word 0
|
||||
lowwater: .word 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user