SDCC crt0.s for floppy bload

Pagina 2/2
1 |

Van zPasi

Champion (471)

afbeelding van zPasi

26-09-2019, 07:23

There is no ROM crt0 in Fusion-C (yet). There are crt0s for MSX-DOS and BASIC (BLOAD), based on Konamiman code. link

Building ROMs with Fusion-C is currently based on Dsk2Rom tools. You build MSX-DOS com and disk like normal, then convert that to a Megarom.

I think I'm going to make a ROM crt0 for Fusion-C, at least if no-one else will...

Van akumajo

Rookie (27)

afbeelding van akumajo

26-09-2019, 07:53

zPasi wrote:

There is no ROM crt0 in Fusion-C (yet). There are crt0s for MSX-DOS and BASIC (BLOAD), based on Konamiman code. link

Building ROMs with Fusion-C is currently based on Dsk2Rom tools. You build MSX-DOS com and disk like normal, then convert that to a Megarom.

I think I'm going to make a ROM crt0 for Fusion-C, at least if no-one else will...

Hi Pasi!
I use Fusion-C too, and I've found many crt0 for DOS, BIN (BASIC BLOAD) and ROM, they work, but as I said earlier, I would like to understand where I am wrong in global variables initialization procedure.
I would like to know how to make GSINIT function (in crt0) go in CODE section and not in the DATA section.

Van zPasi

Champion (471)

afbeelding van zPasi

26-09-2019, 09:00

akumajo][quote=zPasi wrote:

I would like to understand where I am wrong in global variables initialization procedure.
I would like to know how to make GSINIT function (in crt0) go in CODE section and not in the DATA section.

Me too Wink

Currently I don't have the answer but I'll find out.

Edit: You could check this out SDCC_startup_MSX816kROM4000

Van akumajo

Rookie (27)

afbeelding van akumajo

26-09-2019, 17:21

Got it!

The problem comes from sdcc command ; SDCC uses sdasz80 to assemble .asm code, then creates .lk file and finaly calls sdldz80 to link .rel files with instructions in .lk file.
You can put the .c file at the beginning or at the end of the sdcc command, it's the same .lk output :

ASlink >> -p
ASlink >> -f test.lk
ASlink >> -mjwx
ASlink >> -i test.ihx
ASlink >> -b _CODE = 0x401d
ASlink >> -b _DATA = 0x8000
ASlink >> -k D:\SDCC\bin\..\lib\z80
ASlink >> -l z80
ASlink >> test.rel
ASlink >> crt0.rel
ASlink >>

The first .rel file is always that of the .c file !
But the linker needs crt0.rel first to set areas at expected address location.

The solution I found is to :
1) compile the .c file apart
sdasz80 -plosgffw prog.rel prog.asm

2) use SDCC with only .rel files, beginning with crt0.rel file. You have to specify the name of the output file with -o option, otherwise the name of .ihx file will be crt0.ihx

sdcc -mz80 -o prog.ihx --no-std-crt0 --code-loc $ADDR_CODE --out-fmt-ihx --opt-code-size crt0.rel prog.rel

Now GSINIT, GSFINAL and INITIALIZER are at the rigth place :

      Value  Global                          
      -----  --------------------------------
     00000000  .__.ABS.                      
     00000000  l__BSEG                       
     00000000  l__BSS                        
     00000000  l__CABS                       
     00000000  l__DABS                       
     00000000  l__DATA                       
     00000000  l__HEADER                     
     00000000  l__HEAP                       
     00000000  l__HOME                       
     00000000  s__CABS                       
     00000000  s__DABS                       
     00000000  s__HEADER                     
     00000000  s__HEADER0                    
     00000001  l__GSFINAL                    
     0000000F  l__GSINIT                     
     0000001D  l__HEADER0                    
     00000025  l__INITIALIZED                
     00000025  l__INITIALIZER                
     00000026  l__CODE                       
     0000401D  s__CODE                       
     00004043  s__HOME                       
     00004043  s__INITIALIZER                
     00004068  s__GSINIT                     
     00004077  s__GSFINAL                    
     00008000  s__DATA                       
     00008000  s__INITIALIZED                
     00008025  s__BSEG                       
     00008025  s__BSS                        
     00008025  s__HEAP            

Van ericb59

Paladin (859)

afbeelding van ericb59

26-09-2019, 19:05

Hi !

Is this method must be done with other crt0 ?

Van reidrac

Resident (48)

afbeelding van reidrac

26-09-2019, 21:00

The crt0.rel must be linked first, always.

Van akumajo

Rookie (27)

afbeelding van akumajo

26-09-2019, 21:21

ericb59 wrote:

Hi !

Is this method must be done with other crt0 ?

Yes, as reidrac said, crt0.rel must be linked first, but sdcc does not.
When you do :

sdcc -mz80 --no-std-crt0 --code-loc ADDR_CODE --data-loc ADDR_DATA crt0.rel prog.c

or

sdcc -mz80 --no-std-crt0 --code-loc ADDR_CODE --data-loc ADDR_DATA prog.c crt0.rel

then, prog.rel is linked before... and here's the catch oO

Van akumajo

Rookie (27)

afbeelding van akumajo

26-09-2019, 21:31

Little trick if you want to calculate automatically ADDR_CODE from your crt0.rel :

on linux system :

CRT_SIZE=0x`grep 'A _HEADER0' crt0.rel | cut -d' ' -f4`
CRT_STRT=0x`grep 'A _HEADER0' crt0.rel | cut -d' ' -f8`
export ADDR_CODE=$(( $CRT_STRT + $CRT_SIZE ))

on windows :

for /F "tokens=4 delims= " %%i in ('"findstr /C:"A _HEADER0" crt0.rel') do set /a VAR1=0x%%i
for /F "tokens=8 delims= " %%i in ('"findstr /C:"A _HEADER0" crt0.rel') do set /a VAR2=0x%%i
set /a ADDR_CODE=%VAR1%+%VAR2%

Wink

Van akumajo

Rookie (27)

afbeelding van akumajo

27-09-2019, 12:12

Sorry, I made a mistake in my post :

The solution I found is to :
1) compile the .c file apart

sdcc -c -mz80 program.c

2) use SDCC with only .rel files, beginning with crt0.rel file. Specify the name of the output file with -o option, otherwise the name of .ihx file will be crt0.ihx

sdcc -mz80 -o program.ihx --no-std-crt0 --code-loc (ADDR_CODE) --out-fmt-ihx --opt-code-size crt0.rel program.rel

then

hex2bin -e bin -l (ROMSIZE) program.ihx
Pagina 2/2
1 |