Changed run location of INIT segment.

So far the INIT segment was run from the later heap+stack. Now the INIT segment is run from the later BSS. The background is that so far the INIT segment was pretty small (from $80 to $180 bytes). But upcoming changes will increase the INIT segment in certain scenarios up to ~ $1000 bytes. So programs with very limited heap+stack might just not been able to move the INIT segment to its run location. But moving the INIT segment to the later BSS allows it to occupy the later BSS+heap+stack.

In order to allow that the constructors are _NOT_ allowed anymore to access the BSS. Rather they must use the DATA segment or the new INITBSS segment. The latter isn't cleared at any point so the constructors may use it to expose values to the main program. However they must make sure to always write the values as they are not pre-initialized.
This commit is contained in:
Oliver Schmidt
2015-10-14 22:52:09 +02:00
parent 023b461bb8
commit 0ee9b2e446
35 changed files with 234 additions and 260 deletions

View File

@@ -8,7 +8,7 @@
.import initlib, donelib
.import moveinit, zerobss, callmain
.import BSOUT
.import __RAM_START__, __RAM_SIZE__ ; Linker generated
.import __MAIN_START__, __MAIN_SIZE__ ; Linker generated
.import __STACKSIZE__ ; from configure file
.importzp ST
@@ -45,16 +45,24 @@ Start:
ldx move_init
beq L0
; Move the INIT segment from where it was loaded (over ZPSAVE and BSS)
; into where it must be run (in the heap).
; Move the INIT segment from where it was loaded (over the bss segments)
; into where it must be run (over the BSS segment).
jsr moveinit
dec move_init ; set to false
dec move_init ; Set to false
; Save space by putting the rest of the start-up code in the INIT segment,
; which can be re-used by the heap and the C stack.
; Save space by putting some of the start-up code in the INIT segment,
; which can be re-used by the BSS segment, the heap and the C stack.
L0: jsr initstart
L0: jsr runinit
; Clear the BSS data.
jsr zerobss
; Push the command-line arguments; and, call main().
jsr callmain
; Back from main() [this is also the exit() entry]. Run the module destructors.
@@ -90,7 +98,7 @@ L2: lda zpsave,x
.segment "INIT"
initstart:
runinit:
; Save the zero-page locations that we need.
@@ -100,24 +108,16 @@ L1: lda sp,x
dex
bpl L1
; Clear the BSS data.
jsr zerobss
; Set up the stack.
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
ldx #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
sta sp
stx sp+1 ; Set argument stack ptr
; Call the module constructors.
jsr initlib
; Push the command-line arguments; and, call main().
jmp callmain
jmp initlib
; ------------------------------------------------------------------------
@@ -134,6 +134,6 @@ spsave: .res 1
move_init:
.byte 1
.segment "ZPSAVE"
.segment "INITBSS"
zpsave: .res zpspace