SDCC crt0.s for floppy bload

Страница 2/3
1 | | 3

By zPasi

Champion (499)

Аватар пользователя 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...

By akumajo

Resident (43)

Аватар пользователя 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.

By zPasi

Champion (499)

Аватар пользователя 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

By akumajo

Resident (43)

Аватар пользователя 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            

By ericb59

Paragon (1046)

Аватар пользователя ericb59

26-09-2019, 19:05

Hi !

Is this method must be done with other crt0 ?

By reidrac

Expert (98)

Аватар пользователя reidrac

26-09-2019, 21:00

The crt0.rel must be linked first, always.

By akumajo

Resident (43)

Аватар пользователя 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

By akumajo

Resident (43)

Аватар пользователя 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

By akumajo

Resident (43)

Аватар пользователя 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

By ocitygate

Expert (67)

Аватар пользователя ocitygate

06-02-2021, 18:12

I want to code C for my first generation MSX (Toshiba HX-10), but since I do not have any disk controllers and therefore no MSX DOS, I need to load my programs through the cassette interface with the BLOAD command in MSX BASIC.
After a lot of trial and error, I found Konamiman's crt0 for MSX BASIC which works like a charm.
Just save the following code to crt0.s and change .org 0xA000 to the first memory address where you want to load the binary in BASIC. Still unsure about BASIC's memory management, but some research pointed to 0xC000 and higher addresses. Now compile crt0.s, by running "sdasz80 -o crt0.rel crt0.s". Next step is to compile your program, by running:
"sdcc --code-loc 0xC020 --data-loc 0x00 -mz80 --no-std-crt0 crt0.rel yourprog.c"
Important that --code-loc 0xC020 is exactly 0x20 higher that the first address.

    ;--- crt0.asm for MSX-BASIC - by Konamiman, 1/2018
    ;
    ;    Change the .org directive as appropriate for your program
    ;
    ;    To assemble it:
    ;    sdasz80 -o crt0_msxbasic.rel crt0_msxbasic.s
    ;
    ;    Compile programs with --code-loc  --data-loc X
    ;    X=0  -> global vars will be placed immediately after code
    ;    X!=0 -> global vars will be placed at address X
    
    .module crt0
    .globl  _main

    .globl  l__INITIALIZER
    .globl  s__INITIALIZED
    .globl  s__INITIALIZER

    .area _HEADER (ABS)

    .org    0xA000
    .db     0xFE
    .dw     init
    .dw     end
    .dw     init

    ;--- Initialize globals and jump to "main"

init:
    ld  bc, #l__INITIALIZER
    ld  a, b
    or  a, c
    jp  z,_main
    ld  de, #s__INITIALIZED
    ld  hl, #s__INITIALIZER
    ldir

    jp    _main

    ;; Ordering of segments for the linker.
    .area   _HOME
    .area   _CODE
    .area   _INITIALIZER
    .area   _GSINIT
    .area   _GSFINAL
    .area   _DATA
    .area   _INITIALIZED
    .area   _BSEG
    .area   _BSS
    .area   _HEAP

end:
Страница 2/3
1 | | 3