1
0
mirror of https://github.com/cc65/cc65.git synced 2026-04-21 09:17:52 +00:00

Load INITBSS segment from disk.

Conceptually the INITBSS segment is not initialized in any way. Therefore it makes sense to not load it from disk. However the INIT segment has to be loaded from disk and therefore moved to its run location above the INITBSS segment. The necessary move routine increases runtime RAM usage :-(

Therefore we now "unnecessarily" load the INITBSS segment from disk too meaning that the INIT segment is loaded at its run location. Therefore there's no need for the move routine anymore.

After all we trade disk space for (runtime) RAM space - an easy decision ;-)

Notes:

- The code allowing to re-run a program without re-load present so far could not have worked as far as I can see as it only avoided to re-run the move routine but still tried to re-run the code in the INIT segment that was clobbered by zeroing the BSS. Therefore I removed the code in question altogether. I'm personally not into this "dirty re-run" but if someone wants to add an actually working solution I won't block that.

- INITBSS is intentionally not just merged with the DATA segment as ROM-based targets can't reuse the INIT segment for the BSS and therefore have no reason to place the INIT segment above INITBSS.

- Because ROM-based targets don't copy INITBSS from the ROM (like it is done with the DATA segment) all users of INITBSS _MUST_NOT_ presume INITBSS to be initialized with zeros!
This commit is contained in:
Oliver Schmidt
2016-02-28 19:29:37 +01:00
parent 25f4482641
commit 3d08abcfa8
4 changed files with 51 additions and 119 deletions
-45
View File
@@ -1,45 +0,0 @@
;
; 2015-10-07, Greg King
;
.export moveinit
.import __INIT_LOAD__, __INIT_RUN__, __INIT_SIZE__ ; Linker-generated
.macpack cpu
.macpack generic
; Put this in the DATA segment because it is self-modifying code.
.data
; Move the INIT segment from where it was loaded (over the bss segments)
; into where it must be run (over the BSS segment). The two areas might overlap;
; and, the segment is moved upwards. Therefore, this code starts at the highest
; address, and decrements to the lowest address. The low bytes of the starting
; pointers are not sums. The high bytes are sums; but, they do not include the
; carry. Both the low-byte sums and the carries will be done when the pointers
; are indexed by the .Y register.
moveinit:
; First, move the last, partial page.
; Then, move all of the full pages.
ldy #<__INIT_SIZE__ ; size of partial page
ldx #>__INIT_SIZE__ + (<__INIT_SIZE__ <> 0) ; number of pages, including partial
L1: dey
init_load:
lda __INIT_LOAD__ + (__INIT_SIZE__ & $FF00) - $0100 * (<__INIT_SIZE__ = 0),y
init_run:
sta __INIT_RUN__ + (__INIT_SIZE__ & $FF00) - $0100 * (<__INIT_SIZE__ = 0),y
tya
bnz L1 ; page not finished
dec init_load+2
dec init_run+2
dex
bnz L1 ; move next page
rts