MartinezTorres / sdcc_msx

framework for mixed msx/linux development
Other
14 stars 2 forks source link

global variables not initialized #2

Open pvmm opened 3 years ago

pvmm commented 3 years ago

I found differences between code generated with GCC and SDCC concerning global variables. Global variables in different modules are not properly initialized. Investigating it a little, I think there are some code missing in crt0msx.32k.4000.s to move code from INITIALIZER to INITIALIZED. The generic z80/crt0.s from SDCC has this piece of code after gsinit for instance that does exactly that:

zeroed_data:      
            ; Explicitly initialized global variables.
            ld  bc, #l__INITIALIZER
            ld  a, b
            or  a, c
            jr  Z, gsinit_next
            ld  de, #s__INITIALIZED
            ld  hl, #s__INITIALIZER
            ldir

but there is no equivalent in crt0msx.32k.4000.s.

MartinezTorres commented 3 years ago

This is correct. The linker implemented in sdcc_msx does not support the initialization of global variables (must be initialized manually). The next generation of linker (https://github.com/MartinezTorres/megalinker) does support them, but it's mostly incompatible with sdcc_msx, so I keep it in a different project.