From ef88f0e530b898ebcb14f9e3dff1d58e83089ada Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 00:49:58 +0200 Subject: C toolchain: run SDCC-compiled C programs as gbos processes - c/{gbos.h,crt0.s,libc.s,build.sh}: SDCC sm83 -> ROM-bank blob toolchain. libc syscall wrappers save/restore BC/DE/HL around rst $30 (trap clobbers them; SDCC expects them preserved). - build via SDCC native asxxxx path (sdasgb/sdldgb), crt0 linked first so _start is the $4000 entry; blob INCBIN'd into a ROM bank. - chello.c: prints a message + getpid() -> runs as 'chello' shell command. - Makefile: auto-build c/*.bin, track as a dep of programs.o; gitignore blobs. - README: document the C toolchain + the SDCC --asm=rgbds codegen bug that forced the native-toolchain approach. - verified: '$ chello' -> 'hello from C on gbos!' / 'my pid is 2'. --- src/programs.asm | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/programs.asm') diff --git a/src/programs.asm b/src/programs.asm index d4ae89f..eabe56f 100644 --- a/src/programs.asm +++ b/src/programs.asm @@ -44,6 +44,15 @@ ProgHello: db "hello world!", $0D, $0A .msgend +; ----------------------------------------------------------------------------- +; PROG_CHELLO (bank 5) - a program written in C, compiled with SDCC to a +; self-contained ROM-bank image (crt0 + libc + code) and included verbatim. +; Rebuild with: sh c/build.sh c/chello.c c/chello.bin +; ----------------------------------------------------------------------------- +SECTION "prog_chello", ROMX[$4000], BANK[5] +ProgChello: + INCBIN "c/chello.bin" + ; ----------------------------------------------------------------------------- ; PROG_SH (bank 3) - a tiny shell. ; prompt -> read a line (with echo) -> match a command -> fork+exec+wait. @@ -138,6 +147,8 @@ ProgSh: db PROG_WORKER db "hello", 0 db PROG_HELLO + db "chello", 0 + db PROG_CHELLO db 0 ; terminator ; ----------------------------------------------------------------------------- @@ -178,3 +189,5 @@ ProgramTable:: dw ProgSh db LOW(BANK(ProgHello)), HIGH(BANK(ProgHello)) dw ProgHello + db LOW(BANK(ProgChello)), HIGH(BANK(ProgChello)) + dw ProgChello -- cgit v1.3.1-sl0p