diff options
| author | user <user@clank> | 2026-07-16 08:25:35 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-16 08:25:35 +0200 |
| commit | 6c64d97e70984c77be3cd8d4e03e9adf717e02fb (patch) | |
| tree | fd55f0ef943fef12a833ab526ebfe6bc5740f728 /c/libc.s | |
| parent | filesystem: a RAM FS (WRAMX) + ls/cat/save/rm; wc/head read files (diff) | |
| download | gbos-6c64d97e70984c77be3cd8d4e03e9adf717e02fb.tar.gz gbos-6c64d97e70984c77be3cd8d4e03e9adf717e02fb.tar.xz gbos-6c64d97e70984c77be3cd8d4e03e9adf717e02fb.zip | |
shell: I/O redirection (>/<) and pipes (|); rewrite shell in C
- 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.
Diffstat (limited to '')
| -rw-r--r-- | c/libc.s | 67 |
1 files changed, 51 insertions, 16 deletions
@@ -25,11 +25,11 @@ _getargs: ld c, l ret - ;; void putc(char c /*A*/) + ;; void putc(char c /*A*/) -> stdout via SYS_PUTC _putc: - ld (0xff01), a - ld a, #0x81 - ld (0xff02), a + ld e, a + ld c, #16 ; SYS_PUTC + rst #0x30 ret ;; void puts(const char *s /*DE*/) - write until NUL (no newline) @@ -37,22 +37,22 @@ _puts: 1$: ld a, (de) or a ret z - ld (0xff01), a - ld a, #0x81 - ld (0xff02), a + push de + ld e, a + ld c, #16 ; SYS_PUTC + rst #0x30 + pop de inc de jr 1$ - ;; void nl(void) - CRLF + ;; void nl(void) - CRLF via stdout _nl: - ld a, #0x0d - ld (0xff01), a - ld a, #0x81 - ld (0xff02), a - ld a, #0x0a - ld (0xff01), a - ld a, #0x81 - ld (0xff02), a + ld e, #0x0d + ld c, #16 ; SYS_PUTC + rst #0x30 + ld e, #0x0a + ld c, #16 + rst #0x30 ret ;; unsigned char strlen(const char *s /*DE*/) -> A @@ -132,3 +132,38 @@ _fremove: ld c, #15 ; SYS_REMOVE rst #0x30 ret + + .globl _fork, _exec, _wait, _setin, _setout, _lookup + ;; unsigned char fork(void) -> A (child pid in parent, 0 in child) +_fork: + ld c, #1 ; SYS_FORK + rst #0x30 + ret + ;; void exec(unsigned char id /*A*/) - never returns +_exec: + ld b, a + ld c, #6 ; SYS_EXEC + rst #0x30 + ret + ;; unsigned char wait(void) -> A (reaped pid) +_wait: + ld c, #7 ; SYS_WAIT + rst #0x30 + ret + ;; void setin(unsigned char fd /*A*/) +_setin: + ld b, a + ld c, #17 ; SYS_SETIN + rst #0x30 + ret + ;; void setout(unsigned char fd /*A*/) +_setout: + ld b, a + ld c, #18 ; SYS_SETOUT + rst #0x30 + ret + ;; unsigned char lookup(const char *name /*DE*/) -> A (prog id or $FF) +_lookup: + ld c, #19 ; SYS_LOOKUP + rst #0x30 + ret |
