1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-18 00:07:21 +00:00
cc65/libsrc/runtime/condes.s
Oliver Schmidt 419eb700b5 Renamed INITBSS to INIT and INIT to ONCE.
The way we want to use the INITBSS segment - and especially the fact that it won't have the type bss on all ROM based targets - means that the name INITBSS is misleading. After all INIT is the best name from my perspective as it serves several purposes and therefore needs a rather generic name.

Unfortunately this means that the current INIT segment needs to be renamed too. Looking for a short (ideally 4 letter) name I came up with ONCE as it contains all code (and data) accessed only once during initialization.
2016-03-06 21:27:19 +01:00

85 lines
2.1 KiB
ArmAsm

;
; Ullrich von Bassewitz, 20.11.2000
;
; CC65 runtime: Support for calling module constructors/destructors
;
; The condes routine must be called with the table address in a/x and the
; size of the table (which must not be zero!) in y. The current implementation
; limits the table size to 254 bytes (127 vectors) but this shouldn't be
; problem for now and may be changed later.
;
; libinit and libdone call condes with the predefined module constructor and
; destructor tables, they must be called from the platform specific startup
; code.
.export initlib, donelib, condes
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
.macpack cpu
; --------------------------------------------------------------------------
; Initialize library modules
.segment "ONCE"
.proc initlib
ldy #<(__CONSTRUCTOR_COUNT__*2)
beq exit
lda #<__CONSTRUCTOR_TABLE__
ldx #>__CONSTRUCTOR_TABLE__
jmp condes
exit: rts
.endproc
; --------------------------------------------------------------------------
; Cleanup library modules
.code
.proc donelib
ldy #<(__DESTRUCTOR_COUNT__*2)
beq exit
lda #<__DESTRUCTOR_TABLE__
ldx #>__DESTRUCTOR_TABLE__
jmp condes
exit: rts
.endproc
; --------------------------------------------------------------------------
; Generic table call handler. The code uses self modifying code and goes
; into the data segment for this reason.
; NOTE: The routine must not be called if the table is empty!
.data
.proc condes
sta fetch1+1
stx fetch1+2
sta fetch2+1
stx fetch2+2
loop: dey
fetch1: lda $FFFF,y ; Patched at runtime
sta jmpvec+2
dey
fetch2: lda $FFFF,y ; Patched at runtime
sta jmpvec+1
sty index+1
jmpvec: jsr $FFFF ; Patched at runtime
index: ldy #$FF ; Patched at runtime
bne loop
rts
.endproc