diff options
| author | user <user@clank> | 2026-07-17 13:43:10 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-17 13:43:10 +0200 |
| commit | b52f37602968768901d2dd83ccf966d953a532f0 (patch) | |
| tree | d497c52bf672291d1cd9cf0579b6191155cb56d4 /c/libc.c | |
| parent | net: keep network packets out of the console (fixes shell garbage on netboot) (diff) | |
| download | gbos-b52f37602968768901d2dd83ccf966d953a532f0.tar.gz gbos-b52f37602968768901d2dd83ccf966d953a532f0.tar.xz gbos-b52f37602968768901d2dd83ccf966d953a532f0.zip | |
kernel: sys_sleep - a cooperative delay off the DIV timer (+ ping pacing)
There was no time source at all (IRQ vectors just reti; scheduler is purely
cooperative). The DIV register (FF04) free-runs at 16384 Hz regardless of
interrupts, so sys_sleep accumulates DIV deltas across SchedYields (other procs
keep running) until the requested number of 1/64-second units elapse.
- SYS_SLEEP(34): B = 1/64s units; libc gsleep(units) / msleep(ms) wrappers.
- ping now msleep(800) between echoes, so it paces like real ping instead of
blasting all four at once.
Verified real-time (capped emulator): replies land ~0.85s apart. In --uncapped
runs the delay is GB-time (fast wall-clock), as expected.
Diffstat (limited to 'c/libc.c')
| -rw-r--r-- | c/libc.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -1,6 +1,15 @@ /* gbos libc C helpers (compiled once, linked into every program). */ #include "gbos.h" +/* sleep for approximately 'ms' milliseconds (cooperative; other procs run). + The kernel counts in 1/64-second units (~15.6 ms), so we round ms to that. */ +void msleep(unsigned int ms) { + unsigned int u = ms >> 4; /* ~ms/15.6, close enough for a delay */ + if (u > 255) u = 255; + if (u == 0 && ms) u = 1; + gsleep((unsigned char)u); +} + /* print an unsigned int in decimal */ void putu(unsigned int n) { char buf[5]; |
