My kernel loads programs off of a compact flash card and has a built-in command line. A picture is worth a thousand words so here is a video of me showcasing mouse functionality on my system just so you guys can gauge sort of what kind of system this is and understand my needs a little better.
My kernel runs in assembly and has a compact flash card with a filesystem on it. I can load programs from the filesystem into ram and run them from ram. My system loads the programs into ram starting at address 3000h and does a call to that address. When the program runs its last ret instruction, it goes back to running the command line. Programs are able to use however much ram they want up to like 9000h iirc. In reality, non of my programs are ever larger than 4kb but they can be up to I think 16kb before running into problems.
My kernel has a lot of useful system subroutines starting at location b000h, each 4 bytes apart. A program can easily use these subroutines by doing a call instruction to that address. There's all kinds of subroutines but most importantly there's driver and math stuff. I would like to set up z88dk in such a way that I can access these from a c program.
Now that I have explained my system architecture in a way that my needs can hopefully be better understood, let's talk about actually getting z88dk to do stuff.
I'm pretty stumped here. If I could just set up the simplest thing that works, I could probably take it from there but I have been unsuccessful even doing that. For starters, these are the steps I've taken:
- I copied the file "z88dk/lib/config/z80.cfg" and named it "custom_z80.cfg"
- I replaced the line
Code: Select all
CRT0 DESTDIR/lib/target/z80/classic/crt0.asm
Code: Select all
CRT0 DESTDIR/lib/target/custom_z80/classic/crt0.asm
Code: Select all
MODULE customz80_crt0
.globl _main
.globl _exit
.globl l__DATA
.globl s__DATA
.globl l__BSS
.globl s__BSS
.globl l__INITIALIZER
.globl s__INITIALIZER
.globl s__INITIALIZED
.area _HEADER
defc crt0 = 1
;INCLUDE "zcc_opt.def"
EXTERN _main ; main() is always external to crt0 code
defc CRT_ORG_CODE = 0x3000
defc CRT_ORG_BSS = 0x37FF
CRT_MODEL = 0 (RAM), 1 = (ROM, code copied), 2 = (ROM, code compressed)
;defc CONSOLE_ROWS = 24
;defc CONSOLE_COLUMNS = 40
defc CRT_KEY_DEL = 12
defc __CPU_CLOCK = 4000000
org CRT_ORG_CODE
jp start
start:
;call crt0_init_bss
call _main ; Call user program
cleanup:
;push hl ; return code
;call crt0_exit
;INCLUDE "crt/classic/crt_runtime_selection.asm"
;INCLUDE "crt/classic/crt_section.asm"
_init_end:
; The following section contains the data to copy to the _INITIALIZED section.
.area _INITIALIZER
; =========== START OF CODE =========== ;
.area _HOME
; SYSTEM section contains the system library code that acts as a glue between C and OS assembly.
.area _SYSTEM
; TEXT section contains the actual user's code. We MUST use this section to store the code
; intead of the default _CODE one because the SDCC assembler/linker will always put _CODE
; as the first section. We don't want this behavior, we cannot override it, so let's work
; around it.
.area _TEXT
; ============ END OF CODE ============ ;
; =========== START OF DATA =========== ;
; The following sections contain data, group them.
.area _INITIALIZED
.area _BSEG
.area _BSS
.area _DATA
.area _HEAP
; ============ END OF DATA ============ ;
When I compile a test program such as for example this:
Code: Select all
int main()
{
int i = 4;
int y = 5;
char ree = '1';
if (y < 7)
{
//ree = '9';
}
ree = '5';
return i;
}
void test()
{
int i = 7;
}
- a test.bin file 0 bytes in size
- a test_BSS.bin file 134 bytes in size
- a test_CODE.bin file 371 bytes in size
- a test_DATA.bin file 9 bytes in size
The sizes of these files don't change regardless of what I put in "test.c".
How can I get started? I want the simplest thing I can get to work without having to rewrite my entire kernel in some weird different way. If that means no standard libraries, fine. I bet I could figure it out myself if I could get it working well enough to run a hello world on the target system but for now, I'm completely stumped.
What can I do to get something as simple as the above source code to compile both a) at all and b) run on my system?