aboutsummaryrefslogtreecommitdiffstats
path: root/src/programs.asm (follow)
Commit message (Collapse)AuthorAgeFilesLines
* kill + ps: implement SYS_KILL (pid 1 immortal) and a ps tooluser6 days1-0/+16
| | | | | | | | | | | - PCB gains PROC_PROG (running program id), set by exec, inherited on fork. - sys_kill(pid): reject pid 1 (immortal) and unknown/dead pids; mark the target zombie, reparent its children to init, wake its parent if blocked in wait; schedule away if a process kills itself. Reuses FindPcbByPid/ReparentToInit. - sys_ps(slot,buf)->{pid,state,prog}; sys_progname(id) via NameTable reverse lookup. NameTable gains sh/ps/kill. - libc: kill/psget/progname; tools ps (pid state cmd) and kill <pid>. - verified: ps lists sh(B)+ps(R); kill 1 refused; kill 42 fails.
* shell: I/O redirection (>/<) and pipes (|); rewrite shell in Cuser6 days1-140/+41
| | | | | | | | | | | | | - kernel I/O routing: PCB gains PROC_STDIN/PROC_STDOUT (default console $FF), inherited across fork. KGetc/KPutc route read/write/putc to the console or a file fd. New syscalls: putc(16), setin(17), setout(18), lookup(19). read/write now go through the routing; putc/puts/nl use SYS_PUTC. - sys_lookup + NameTable move command-name resolution into the kernel. - shell rewritten in C (c/sh.c): tokenizes a line, parses > / < / |, and drives fork+setin/setout+exec+wait. Pipes run as 'a > __pipe ; b < __pipe' (temp file). asm shell + cmdtab removed; StrEqual/SkipName kept for sys_lookup. - libc: fork/exec/wait/setin/setout/lookup wrappers. - verified: echo>file, cat file, wc<file, cat readme|wc -l, echo ...|wc.
* filesystem: a RAM FS (WRAMX) + ls/cat/save/rm; wc/head read filesuser6 days1-0/+21
| | | | | | | | | | | - fs.asm: 8-slot RAM filesystem in WRAMX ($D000-$DFFF), name[8]+len[2]+data[502]; syscalls open/close/getb/putb/list/remove, seeded with a 'readme' at boot. - libc: open/close/fgetc/fputc/flist/fremove wrappers + O_READ/O_WRITE/NOFD. - tools: ls, save (stdin->file, one line), rm; cat/wc/head now take a file arg. - fix: syscall dispatch clobbers A, so putb takes its byte in E (was reading the handler's low address byte, 0xDC); ls NUL-terminates 8-char names. - verified: save/cat/ls/rm cycle; wc readme -> '2 7 38'; head -n 1 readme. - README: document the filesystem + the A-clobber ABI note.
* tools: wc, head, and an argc/argv demo (args) + libc.c helpersuser6 days1-0/+21
| | | | | | | | | | - c/libc.c: shared C helpers linked into every program - putu (print decimal), atou (parse decimal), argv_parse (tokenize getargs() into argc/argv). - wc: count lines/words/chars of stdin. head [n]: first n lines (drains rest to EOF). args: argc/argv demo. - pid now uses libc putu; build.sh links libc.c; Makefile CBLOBS + libc dep. - README: document the new tools + argv_parse. - verified: 'args one two three' -> argc=3/argv[..]; wc '2 3 16'; head 2.
* libc + CLI tools: a small C userlanduser6 days1-3/+68
| | | | | | | | | | | - libc: add putc, puts, strlen, getargs (args string), EOF (=4) for readc. - args: shell splits the command line at the first space ("cmd\0args\0" at $A000, inherited by the child via fork); getargs() returns the arg string. - shell: exit on Ctrl-D/EOF; $ prompt over a clean read loop. - tools (c/): echo (argv), cat (stdin->stdout to EOF), uname, pid (decimal print), true, false. Each built to a ROM-bank blob and registered. - Makefile: CBLOBS list builds all C programs. - README: document libc + the tool set.
* C toolchain: run SDCC-compiled C programs as gbos processesuser6 days1-0/+13
| | | | | | | | | | | | | - 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'.
* shell working: fix syscall ABI (trap clobbers HL) + documentuser6 days1-1/+5
| | | | | | | | | | | - root cause of the read/echo corruption: SyscallTrap uses HL to index the dispatch table, so HL is clobbered across a syscall; the shell then wrote its buffer pointer's garbage into the $0000-$7FFF MBC register region, corrupting the mapper. fix: userland saves HL around sys_read (push/pop). - shell now runs commands end to end: $ hello -> hello world!, $ worker -> worker!, $ foo -> ? - README: document that syscalls clobber BC/DE/HL (return in A, B for wait); add read + shell to the syscall table.
* wip: sys_read + serial console shell (read-store bug under investigation)user6 days1-13/+153
| | | | | | | | | | | | - sys_read (SYS_READ): blocking console input via external-clock serial poll; yields while waiting. Verified working (direct-echo cat: 'hi' -> 'hi'). - shell (PROG_SH): prompt/read/parse/fork+exec+wait; worker+hello programs; StrEqual/SkipName helpers; command table. - init now execs the shell. - KNOWN BUG: storing the typed char to the line buffer at $A000 (cart RAM of an exec'd program) corrupts the following sys_read; sys_write reading $A000 also returns $3E. Kernel syscalls themselves are correct; isolating the cart-RAM / exec RAM-bank interaction next.
* kernel: complete the process lifecycle (exit/wait/reap + bank free list)user6 days1-35/+19
| | | | | | | | | | | | | | - exit(): zombie + status, reparent orphans to init, wake blocked parent, schedule away forever (resources reclaimed by the reaper) - wait(): scan for a zombie child; reap (free cart-RAM bank + PCB slot) and return pid/code; block PS_BLOCKED + yield if children still live; $FF if none - cart-RAM banks are now a free list (wBankUsed bitmap): AllocRamBank/FreeRamBank - scheduler: FindNextReady returns carry when nothing runnable; yield idles instead of blindly picking slot 0 - helpers: FindPcbByPid, ReparentToInit - demo: init forks 3 workers -> exec -> exit(pid) -> wait/reap => wwwR2R3R4! verified bank recycling with 6 workers over 3 banks (w2w3w4w5w6w7) - README: document the lifecycle + syscall status
* kernel: implement exec()user6 days1-0/+52
- sys_exec(B=program id): look up ProgramTable, point PROC_ROMB at the program's ROM text bank, map it into $4000-$7FFF, reset stack, jp to entry (no return) - programs.asm: two demo programs (ping/pong) ORG'd at the SAME $4000 in banks 2 and 3 - proves execution is driven purely by PROC_ROMB - demo: init forks; parent execs PROG_PING (bank2, '1'), child execs PROG_PONG (bank3, '2') -> '1212...', 2000/2000 balanced, zero garbage - README: document exec + text-in-ROM model