Explorar el Código

Remove the legacy ring-0 program loader

run <file> already refused everything except "serial", and its FAT loader
had no caller; prog/space bypassed it entirely through an embedded blob at
0x80000.  The two demos ran as kernel command threads, so they held the BKL
and busy-spun while drawing into the WM shadow, freezing the desktop; they
were the last ring-0 user code.

Delete run.c, run_api.h, prog.c, space.c, user.ld, serial_recv.c,
bin_recv.c/h and the 9600-baud bootstrap with send_serial.c, together with
the run/space/prog commands, serial recv, the embedded blobs and the
PROG.BIN/SPACE.BIN copies on root.img.  serial test stays.

The 0x7FF00 program API and 0x80000 load area go away with them.  kernel.ld
now keeps _end below 0x90000 instead of 0x7F000 (the loaded image must
still end below the 0x60000 pack staging gap), which leaves about 190 KB of
BSS/stack headroom.  Drop the fbtext string helpers that only run.c used.

Update AGENTS.md and the docs site in the same change, and renumber the
known-issues list.

Verified with make all, a headless BIOS QEMU boot (ramfs pack, ring-3 WM
attached and started) and make uefi + make test-uefi.
Johannes Zellner hace 1 semana
padre
commit
0a4d0c6e15
Se han modificado 29 ficheros con 67 adiciones y 1190 borrados
  1. 0 1
      .gitignore
  2. 38 78
      AGENTS.md
  3. 5 68
      Makefile
  4. 0 75
      bin_recv.c
  5. 0 7
      bin_recv.h
  6. 0 169
      bootstrap.c
  7. 0 17
      bootstrap.ld
  8. 1 1
      docs/boot.html
  9. 1 7
      docs/development.html
  10. 2 2
      docs/drivers.html
  11. 2 4
      docs/index.html
  12. 1 3
      docs/memory.html
  13. 1 27
      docs/userland.html
  14. 3 2
      efi/main.c
  15. 0 46
      fbtext.c
  16. 0 10
      fbtext.h
  17. 4 3
      io.c
  18. 4 2
      kernel.ld
  19. 1 1
      kexec_send.c
  20. 0 32
      prog.c
  21. 0 161
      run.c
  22. 0 42
      run_api.h
  23. 0 127
      send_serial.c
  24. 0 2
      serial.h
  25. 0 30
      serial_recv.c
  26. 0 232
      space.c
  27. 2 27
      terminal.c
  28. 2 2
      tty.c
  29. 0 12
      user.ld

+ 0 - 1
.gitignore

@@ -5,7 +5,6 @@
 *.pack
 *.pack
 BOOTX64.EFI
 BOOTX64.EFI
 efi/efi_entry.h
 efi/efi_entry.h
-send_serial
 kexec_send
 kexec_send
 netkexec_send
 netkexec_send
 netmonitor
 netmonitor

+ 38 - 78
AGENTS.md

@@ -84,11 +84,9 @@ make clean
   partition image).  The kernel itself no longer carries the pack; the boot
   partition image).  The kernel itself no longer carries the pack; the boot
   path loads it into RAM and `ramfs_init` takes a private copy (`bin/<name>`
   path loads it into RAM and `ramfs_init` takes a private copy (`bin/<name>`
   mounted at `/ramfs`).
   mounted at `/ramfs`).
-- `root.img` is a second FAT12 floppy holding user binaries (`PROG.BIN`, `SPACE.BIN`),
-  the disk fallback copies of the browser/gallery (`BROWSER`, `GALLERY`) and
-  its `DEMO.HTM`/`PIC.BMP` test page, plus a few test files; it requires
-  `mtools` to build.
-- `make send PROGRAM=prog` transfers a binary to a real machine over serial.
+- `root.img` is a second FAT12 floppy holding the disk fallback copies of the
+  browser/gallery (`BROWSER`, `GALLERY`) and its `DEMO.HTM`/`PIC.BMP` test
+  page, plus a few test files; it requires `mtools` to build.
 - UEFI needs `x86_64-w64-mingw32-gcc` (the 64-bit loader) and, for the QEMU
 - UEFI needs `x86_64-w64-mingw32-gcc` (the 64-bit loader) and, for the QEMU
   targets, an OVMF firmware (`OVMF=/path/to/OVMF.4m.fd` overrides the default).
   targets, an OVMF firmware (`OVMF=/path/to/OVMF.4m.fd` overrides the default).
   `make all` does not build the UEFI image, so a machine without mingw still
   `make all` does not build the UEFI image, so a machine without mingw still
@@ -168,10 +166,8 @@ a Pentium 1 (and a Pentium II board without ACPI) on the UP path.
 | `0x6C00`  | AP trampoline real-mode stack top (grows down) |
 | `0x6C00`  | AP trampoline real-mode stack top (grows down) |
 | `0x6F00`  | AP startup info block (CR3, stack top, C entry, CPU index) |
 | `0x6F00`  | AP startup info block (CR3, stack top, C entry, CPU index) |
 | `0x60000` | Legacy rootfs pack staging (`vesa_stage.S`; compressed gzip data, up to `PACK_LOW_MAX` 0x3FBFF, ending below the EBDA at `0x9FC00`).  Temporary: copied to `0x900000` in protected mode before the kernel starts, so the kernel BSS/boot stack may extend past this address |
 | `0x60000` | Legacy rootfs pack staging (`vesa_stage.S`; compressed gzip data, up to `PACK_LOW_MAX` 0x3FBFF, ending below the EBDA at `0x9FC00`).  Temporary: copied to `0x900000` in protected mode before the kernel starts, so the kernel BSS/boot stack may extend past this address |
-| `_end`    | Kernel end (linker symbol; `kernel.ld` ASSERTs `__bss_start <= 0x60000` so the loaded image stays below the legacy staging gap, and `_end <= 0x7F000` so it does not reach the run area).  BSS and the boot stack may extend past `0x60000` |
+| `_end`    | Kernel end (linker symbol; `kernel.ld` ASSERTs `__bss_start <= 0x60000` so the loaded image stays below the legacy staging gap, and `_end <= 0x90000` so the top of the staging gap and the EBDA stay untouched).  BSS and the boot stack may extend past `0x60000` |
 | (in-image) | Bootstrap/protected-mode stack: 8 KB `.stack` NOLOAD section, `__boot_stack_top`/`__boot_stack_bottom` (travels with the kernel) |
 | (in-image) | Bootstrap/protected-mode stack: 8 KB `.stack` NOLOAD section, `__boot_stack_top`/`__boot_stack_bottom` (travels with the kernel) |
-| `0x7FF00` | Program API struct (`PROGRAM_API_ADDR`, `run_api.h`) |
-| `0x80000` | Legacy ring-0 program load area (`run.c`, `serial_recv.c`, `user.ld`; max 0x6000, inside the reserved low 1 MB) |
 | `0x900000`| Legacy boot-time rootfs pack after `vesa_stage.S` relocates it (reserved by `mm_init` until `ramfs_init` takes its copy, then freed; process stacks and kexec staging also start here) |
 | `0x900000`| Legacy boot-time rootfs pack after `vesa_stage.S` relocates it (reserved by `mm_init` until `ramfs_init` takes its copy, then freed; process stacks and kexec staging also start here) |
 | `0x100000`| VGA shadow buffer (`VGA_SHADOW_BASE`, `vga.h`) |
 | `0x100000`| VGA shadow buffer (`VGA_SHADOW_BASE`, `vga.h`) |
 
 
@@ -194,8 +190,8 @@ Everything else is dynamic: process stacks and the kexec staging buffer come
 from the frame allocator (≥ `0x900000`), and the fallback stack pool is a
 from the frame allocator (≥ `0x900000`), and the fallback stack pool is a
 static BSS array.  The UEFI loader's kernel staging buffer comes from
 static BSS array.  The UEFI loader's kernel staging buffer comes from
 `AllocatePages` below 4 GB and only lives until the `0x800` trampoline copies
 `AllocatePages` below 4 GB and only lives until the `0x800` trampoline copies
-it to `0x7E00`.  The kernel region itself only has one wall (`_end` below the
-run area), so adding code no longer moves any address.
+it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
+`0x90000`), so adding code no longer moves any address.
 
 
 ## Key files
 ## Key files
 
 
@@ -423,8 +419,8 @@ run area), so adding code no longer moves any address.
   as `sata0`..`sataN` (named by AHCI port index) and mount like IDE disks
   as `sata0`..`sataN` (named by AHCI port index) and mount like IDE disks
   (`sata0p1` for an MBR partition). >2 TB disks are clamped to 32-bit LBA;
   (`sata0p1` for an MBR partition). >2 TB disks are clamped to 32-bit LBA;
   a disk added after boot needs a rescan (no COMRESET hotplug).
   a disk added after boot needs a rescan (no COMRESET hotplug).
-- **Serial**: `serial.c`, `serial_ring_buf.c/h`, `bin_recv.c/h`, `serial_recv.c`,
-  `serial_loop.c`, `send_serial.c` — 16550 UART, IRQ-driven ring buffer, XMODEM.
+- **Serial**: `serial.c`, `serial_ring_buf.c/h`, `serial_loop.c` — 16550 UART
+  with an IRQ-driven ring buffer and the `serial test` loopback check.
 - **Network**: `netdev.c/h` — NIC driver registry (`struct netdev`, first probe
 - **Network**: `netdev.c/h` — NIC driver registry (`struct netdev`, first probe
   wins; drivers: `e1000e.c` Intel e1000/PCH LAN (82540EM emulated,
   wins; drivers: `e1000e.c` Intel e1000/PCH LAN (82540EM emulated,
   82577LM/82578/82579; polled, PCI INTx disabled before MMIO, PCH D0 and
   82577LM/82578/82579; polled, PCI INTx disabled before MMIO, PCH D0 and
@@ -463,7 +459,7 @@ run area), so adding code no longer moves any address.
   lives in the command pack, so `make net-cmds` updates it without a
   lives in the command pack, so `make net-cmds` updates it without a
   kernel reload.  Static IP default `192.168.178.240`, mask/gateway learned
   kernel reload.  Static IP default `192.168.178.240`, mask/gateway learned
   from DHCP (off-subnet traffic goes via the router).
   from DHCP (off-subnet traffic goes via the router).
-- **Hot-reload (kexec)**: `kexec.c/h`, `kexec_tramp.S`, `entry.S`, `bootstrap.c`, and the
+- **Hot-reload (kexec)**: `kexec.c/h`, `kexec_tramp.S`, `entry.S`, and the
   host-side `kexec_send.c` — reload the kernel over serial without rebooting
   host-side `kexec_send.c` — reload the kernel over serial without rebooting
   (C-light: reuses the current framebuffer, re-runs `kernel_main`).
   (C-light: reuses the current framebuffer, re-runs `kernel_main`).
   The transfer entry is `kernel_entry` (`entry.S`), which re-points ESP before
   The transfer entry is `kernel_entry` (`entry.S`), which re-points ESP before
@@ -555,16 +551,6 @@ run area), so adding code no longer moves any address.
   drained before every command, and every wait is bounded; nothing is
   drained before every command, and every wait is bounded; nothing is
   written to the EC.  `sensors` labels the EC registers and decodes the fan
   written to the EC.  `sensors` labels the EC registers and decodes the fan
   mode (auto / full speed / level).
   mode (auto / full speed / level).
-- **User programs**: `run.c`, `run_api.h`, `prog.c`, `space.c` — raw binaries at
-  `0x80000`, API function-pointer struct at `0x7FF00`.  `prog`/`space` are
-  **embedded in the kernel image** (`prog_embed.o`/`space_embed.o`), so
-  `make dev`/`make net-dev` update them too and a board with no readable
-  filesystem can still run them: `run <name>` and the `prog`/
-  `space` commands use the embedded copy, `run /<device>/<file>` still loads
-  from FAT.  Rebuilds are wired (`space.c` -> `space.bin` -> `space_embed.o` ->
-  `kernel.elf`).  Note: `run`/`prog`/`space` still draw over the WM (which keeps
-  repainting its desktop); the windowed path for such programs is the ring-3
-  canvas service (see the window graphics bullet, used by `clock`/`colors`).
 - **Ring-3 address space**: the ELF image and 8 KB stack live in the 2 MB
 - **Ring-3 address space**: the ELF image and 8 KB stack live in the 2 MB
   `USER_BASE` (`0x40000000`)..`USER_STACK_TOP` (`0x40200000`) window, which is
   `USER_BASE` (`0x40000000`)..`USER_STACK_TOP` (`0x40200000`) window, which is
   too small for a full-frame image.  `SYS_MEM_ALLOC`/`SYS_MEM_GROW`/`SYS_MEM_FREE`
   too small for a full-frame image.  `SYS_MEM_ALLOC`/`SYS_MEM_GROW`/`SYS_MEM_FREE`
@@ -726,10 +712,9 @@ run area), so adding code no longer moves any address.
 ## Shell commands
 ## Shell commands
 
 
 `cd [path]`, `ls [path]`, `cat <path>`, `save <path> <text>`, `rm <path>`,
 `cd [path]`, `ls [path]`, `cat <path>`, `save <path> <text>`, `rm <path>`,
-`mkdir <path>`, `rmdir <path>`, `hello`, `reboot`, `poweroff`, `run <name>|<file>`, `space`,
-`prog`,
+`mkdir <path>`, `rmdir <path>`, `hello`, `reboot`, `poweroff`,
 `display`, `cpuinfo`, `mouseinfo`, `gfxbench`, `lsusb`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `meminfo`, `top`, `sched`, `format <device> [size]` (binary units, e.g. `format ide0 100mb` or `1gb`; no size formats the whole disk),
 `display`, `cpuinfo`, `mouseinfo`, `gfxbench`, `lsusb`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `meminfo`, `top`, `sched`, `format <device> [size]` (binary units, e.g. `format ide0 100mb` or `1gb`; no size formats the whole disk),
-`ps`, `renice <pid> <weight>`, `kill <pid>`, `idle [auto|hlt|c1e|c3|c6]`, `power`, `cpufreq [auto|min|max|off|<ratio>]`, `spin [ms]`, `help`, `clear`, `serial test|recv`, `kexec`, `dbg`, `view <file>` (image viewer; PNG, baseline/progressive JPEG, animated GIF, BMP, TGA, PNM, ICO, PAM), and `browser [url|file]` (disk app launcher).
+`ps`, `renice <pid> <weight>`, `kill <pid>`, `idle [auto|hlt|c1e|c3|c6]`, `power`, `cpufreq [auto|min|max|off|<ratio>]`, `spin [ms]`, `help`, `clear`, `serial test`, `kexec`, `dbg`, `view <file>` (image viewer; PNG, baseline/progressive JPEG, animated GIF, BMP, TGA, PNM, ICO, PAM), and `browser [url|file]` (disk app launcher).
 
 
 Network: `netinfo`, `netrecv`, `netsend`, `netip [a.b.c.d]`, `dhcp` (re-run the
 Network: `netinfo`, `netrecv`, `netsend`, `netip [a.b.c.d]`, `dhcp` (re-run the
 DHCP client), `netdev [name]` (kernel command: show the active NIC driver or
 DHCP client), `netdev [name]` (kernel command: show the active NIC driver or
@@ -769,18 +754,10 @@ commands spawned as processes, or builtins (`cd`, `path`, `help`, `clear`).
 ## Serial hot-reload (kexec) workflow
 ## Serial hot-reload (kexec) workflow
 
 
 Develop without reflashing the floppy. The serial link (COM1 ↔ `/dev/ttyUSB0`)
 Develop without reflashing the floppy. The serial link (COM1 ↔ `/dev/ttyUSB0`)
-runs at **115200 baud**. Two paths exist:
-
-- **Auto-detect** (the normal loop) — the WM loop watches the serial
-  ring buffer for the `"KXE2"` magic and auto-spawns the reload, so `make dev`
-  alone boots a fresh kernel + rootfs. The manual `kexec` command is kept as a
-  fallback that waits for the same image.
-- **`bootstrap`** (one-time, zero-reflash) — a ring-0 program loaded through the
-  existing `serial recv` + `run serial` path that switches the UART to 115200,
-  receives a new kernel, and jumps into it. Used only to install the first new
-  kernel onto a machine still running an old (9600 baud) build; `bootstrap.bin`
-  is linked by `bootstrap.ld` at the *old* program address (`0x4A000`) because
-  that is where the old build's `serial recv` writes it.
+runs at **115200 baud**. The WM loop watches the serial ring buffer for the
+`"KXE2"` magic and auto-spawns the reload, so `make dev` alone boots a fresh
+kernel + rootfs. The manual `kexec` command is kept as a fallback that waits
+for the same image.
 
 
 Wire protocol (host → target, sent immediately; no handshake):
 Wire protocol (host → target, sent immediately; no handshake):
 `[magic "KXE2"][entry u32 LE][kernel_size u32 LE][pack_size u32 LE]`
 `[magic "KXE2"][entry u32 LE][kernel_size u32 LE][pack_size u32 LE]`
@@ -810,20 +787,6 @@ make monitor       # tail the serial line (picocom; Ctrl-A Ctrl-X to exit)
 Run it in a second terminal, then `make dev` in the first — each reload prints
 Run it in a second terminal, then `make dev` in the first — each reload prints
 the `... booted` line.
 the `... booted` line.
 
 
-**One-time install onto a 9600-baud machine (no floppy):**
-```sh
-make bootstrap                                   # builds bootstrap.bin
-# 1) start the host sender first (it waits for 'R'):
-./send_serial /dev/ttyUSB0 9600 bootstrap.bin
-# 2) on the PC: `serial recv` (sends 'R'), then `run serial`
-# 3) the bootstrap switches the link to 115200 and waits; send the kernel:
-make dev                                         # 115200
-```
-After the first kexec the machine is at 115200, and `make dev` is all you need
-from then on.  `make bootstrap` is built from the new tree and speaks `KXE2`;
-it stages only the kernel and discards the rootfs bytes, so run `make dev`
-again (or `make cmds-dev`) to install a pack afterwards.
-
 Notes: the kexec path rebuilds a flat GDT at `0x900` before jumping (the old GDT
 Notes: the kexec path rebuilds a flat GDT at `0x900` before jumping (the old GDT
 lives inside the overwritten kernel region), so it's safe to edit any file,
 lives inside the overwritten kernel region), so it's safe to edit any file,
 including `vesa_stage.S`/`boot.S` layout — but the video *mode* itself is only
 including `vesa_stage.S`/`boot.S` layout — but the video *mode* itself is only
@@ -890,7 +853,7 @@ couple of seconds on a wired LAN.  While a net command owns the receiver
 
 
 The old `KXNU`/`KXEC` magics are deliberately not understood by this kernel
 The old `KXNU`/`KXEC` magics are deliberately not understood by this kernel
 (and it uses `KXN2`/`KXE2`), so a board still running a pre-rootfs build must
 (and it uses `KXN2`/`KXE2`), so a board still running a pre-rootfs build must
-be flashed (or bootstrapped) once; the new `make net-dev` is then atomic.
+be flashed once; the new `make net-dev` is then atomic.
 
 
 The board's address comes from DHCP when a server is present (the DHCP client
 The board's address comes from DHCP when a server is present (the DHCP client
 runs at boot; `netinfo` shows ip/mask/gateway and the lease), so use
 runs at boot; `netinfo` shows ip/mask/gateway and the lease), so use
@@ -1178,17 +1141,14 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
 3. No per-process address spaces or process isolation (paging is identity-mapped).
 3. No per-process address spaces or process isolation (paging is identity-mapped).
 4. FAT32: FSInfo free-count not updated, no directory-chain growth.
 4. FAT32: FSInfo free-count not updated, no directory-chain growth.
 5. `disk.c` `fdc_reset()` and `fdc_init_once()` overlap/duplicate logic.
 5. `disk.c` `fdc_reset()` and `fdc_init_once()` overlap/duplicate logic.
-6. The ring-0 `run` area (`0x80000`) and the program API at `0x7FF00` are the
-   last fixed low-memory addresses; moving `prog`/`space` to ring-3 would let
-   the whole block go (see the roadmap).
-7. Killing/reaping a ring-3 process frees its kernel stack and page directory
+6. Killing/reaping a ring-3 process frees its kernel stack and page directory
    but not the user pages mapped into it (a few pages leak per command run;
    but not the user pages mapped into it (a few pages leak per command run;
    needs a page-table walk/unmap on reap).
    needs a page-table walk/unmap on reap).
-8. `display` (needs a GPU snapshot) and `lsusb` (a 45-byte wrapper around
+7. `display` (needs a GPU snapshot) and `lsusb` (a 45-byte wrapper around
    the USB tree printer) are the last non-privileged commands still living in
    the USB tree printer) are the last non-privileged commands still living in
    the kernel, plus the privileged ones (`peek`, `poke`, `dbg`, `serial`,
    the kernel, plus the privileged ones (`peek`, `poke`, `dbg`, `serial`,
-   `kexec`, `reboot`, `poweroff`, `format`, `run`/`prog`/`space`, `ps`/`kill`).
-9. The rootfs pack is inflated into one contiguous page-allocated run at
+   `kexec`, `reboot`, `poweroff`, `format`, `ps`/`kill`).
+8. The rootfs pack is inflated into one contiguous page-allocated run at
    boot, capped by `RAMFS_MAX_DECOMPRESSED` (8 MB); a larger pack fails to
    boot, capped by `RAMFS_MAX_DECOMPRESSED` (8 MB); a larger pack fails to
    load (the USB rootfs partition is 8 MB, so this only bites if the cap is
    load (the USB rootfs partition is 8 MB, so this only bites if the cap is
    raised without a bigger partition).  The legacy stage still stages the
    raised without a bigger partition).  The legacy stage still stages the
@@ -1200,61 +1160,61 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
    is ~245 KB, leaving ~16 KB under the cap.  Command growth still needs
    is ~245 KB, leaving ~16 KB under the cap.  Command growth still needs
    care because `libdeflate-gzip -12` is already required (plain `gzip -9`
    care because `libdeflate-gzip -12` is already required (plain `gzip -9`
    is over the cap).
    is over the cap).
-10. SMP is **ACPI/MADT only**: no Intel MP-table fallback, so a Pentium II SMP
+9. SMP is **ACPI/MADT only**: no Intel MP-table fallback, so a Pentium II SMP
     board that exposes only MP tables stays UP (deliberate; there is no test
     board that exposes only MP tables stays UP (deliberate; there is no test
     hardware).
     hardware).
-11. There is no IOAPIC driver.  The BSP keeps the 8259 PIC in LAPIC ExtINT mode;
+10. There is no IOAPIC driver.  The BSP keeps the 8259 PIC in LAPIC ExtINT mode;
     APs mask LINT0/LINT1 and only use their LAPIC timer/IPIs.  Device IRQs never
     APs mask LINT0/LINT1 and only use their LAPIC timer/IPIs.  Device IRQs never
     reach an AP, and `pit_irq_stub` should be treated as BSP-only.
     reach an AP, and `pit_irq_stub` should be treated as BSP-only.
-12. The BKL serializes all kernel execution: a long FAT/disk operation, a
+11. The BKL serializes all kernel execution: a long FAT/disk operation, a
     non-network driver wait or a big shadow-buffer operation can stall syscalls
     non-network driver wait or a big shadow-buffer operation can stall syscalls
     on the other CPUs for its duration.  `bkl_pause()`/`bkl_resume()` is used
     on the other CPUs for its duration.  `bkl_pause()`/`bkl_resume()` is used
     for serial/network waits, not yet for disk I/O.
     for serial/network waits, not yet for disk I/O.
-13. Kernel threads (kworker, kexec/payload, kernel commands) are pinned to
+12. Kernel threads (kworker, kexec/payload, kernel commands) are pinned to
     the BSP.  Only ring-3 processes use the APs, so a single CPU-bound kernel
     the BSP.  Only ring-3 processes use the APs, so a single CPU-bound kernel
     driver still limits throughput.
     driver still limits throughput.
-14. Page-table updates for another CPU's running process (e.g. an MMIO mapping)
+13. Page-table updates for another CPU's running process (e.g. an MMIO mapping)
     rely on not-present TLB entries not being cached; there is no cross-CPU
     rely on not-present TLB entries not being cached; there is no cross-CPU
     TLB shootdown.  No process shares an address space with another, so normal
     TLB shootdown.  No process shares an address space with another, so normal
     process teardown is unaffected.
     process teardown is unaffected.
-15. Image library limits: arithmetic JPEG and CMYK are rejected; EXIF
+14. Image library limits: arithmetic JPEG and CMYK are rejected; EXIF
     orientation is applied but ICC/gamma is ignored; animated GIF frames are
     orientation is applied but ICC/gamma is ignored; animated GIF frames are
     composited (the viewer plays them), but APNG/WebP remain unsupported.  The
     composited (the viewer plays them), but APNG/WebP remain unsupported.  The
     whole file is read into memory (4 MB cap in the viewer) and very large
     whole file is read into memory (4 MB cap in the viewer) and very large
     photos still need DCT-scaled/streamed decode before they fit the 32 MB
     photos still need DCT-scaled/streamed decode before they fit the 32 MB
     arena.
     arena.
-16. `img_draw()`'s box-filter downscale runs on the CPU.  It is fine for the
+15. `img_draw()`'s box-filter downscale runs on the CPU.  It is fine for the
     viewer's static frames, but a browser showing many large inline images
     viewer's static frames, but a browser showing many large inline images
     should cache a scaled bitmap (or use decode-at-display-scale) instead of
     should cache a scaled bitmap (or use decode-at-display-scale) instead of
     rescaling on every repaint.
     rescaling on every repaint.
-17. `files` recognises images by file extension only (`.png .jpg .jpeg .gif
+16. `files` recognises images by file extension only (`.png .jpg .jpeg .gif
     .bmp .tga .ppm .pgm .pbm .ico .cur .pam`); a magic-based fallback would
     .bmp .tga .ppm .pgm .pbm .ico .cur .pam`); a magic-based fallback would
     also open extensionless files in the viewer.  Automatic decode-at-scale
     also open extensionless files in the viewer.  Automatic decode-at-scale
     for oversized images is still missing.
     for oversized images is still missing.
 
 
-18. WebDAV limits: one request at a time (one active connection plus 3
+17. WebDAV limits: one request at a time (one active connection plus 3
     backlog/closing slots; the queue holds each connection's first 1 KB with a zero window),
     backlog/closing slots; the queue holds each connection's first 1 KB with a zero window),
     files are buffered whole (4 MB cap; a larger PUT gets 413), directory
     files are buffered whole (4 MB cap; a larger PUT gets 413), directory
     `MOVE` is 501, `PROPPATCH` is answered 200 without persisting, and there
     `MOVE` is 501, `PROPPATCH` is answered 200 without persisting, and there
     is no authentication.  Sends use a four-segment window, and keep-alive is
     is no authentication.  Sends use a four-segment window, and keep-alive is
     off, so parallel gvfs clients serialize but do not wedge.
     off, so parallel gvfs clients serialize but do not wedge.
-19. FAT mounts are writable over WebDAV only for names that
+18. FAT mounts are writable over WebDAV only for names that
     `fat_name_to_8_3()` can represent exactly; anything longer is refused
     `fat_name_to_8_3()` can represent exactly; anything longer is refused
     with 409 instead of silently truncating (two long names could otherwise
     with 409 instead of silently truncating (two long names could otherwise
     collide and overwrite each other).  Use `/share` for long names.
     collide and overwrite each other).  Use `/share` for long names.
-20. The WebDAV server and the packet-level net commands are mutually
+19. The WebDAV server and the packet-level net commands are mutually
     exclusive: both need the single NIC receiver (`netdev_acquire`).  Starting
     exclusive: both need the single NIC receiver (`netdev_acquire`).  Starting
     `websrv` while `ping`/`curl`/`netrecv` owns the NIC fails; kill the other
     `websrv` while `ping`/`curl`/`netrecv` owns the NIC fails; kill the other
     command first.
     command first.
-21. `/share` is RAM only: a reboot/kexec starts empty, and the 16 MB cap is
+20. `/share` is RAM only: a reboot/kexec starts empty, and the 16 MB cap is
     charged against the 128 MB identity-mapped window.
     charged against the 128 MB identity-mapped window.
 
 
-22. The TCP backlog's early-request buffers cost 8 KB of kernel BSS
+21. The TCP backlog's early-request buffers cost 8 KB of kernel BSS
     (8 slots x 1 KB), and the FAT listing cache another 5 KB.  The command
     (8 slots x 1 KB), and the FAT listing cache another 5 KB.  The command
-    pack is out of the kernel now, so `_end` keeps ~130 KB of headroom below
-    the `0x7F000` wall; the remaining limit is kernel code/buffers only.
+    pack is out of the kernel now, so `_end` keeps ~190 KB of headroom below
+    the `0x90000` wall; the remaining limit is kernel code/buffers only.
 
 
-23. Browser limits: no JavaScript, forms, pseudo-classes/elements,
+22. Browser limits: no JavaScript, forms, pseudo-classes/elements,
     border-radius clipping of descendant content, gradients/box-shadow/
     border-radius clipping of descendant content, gradients/box-shadow/
     transitions (a gradient background falls back to its last solid colour),
     transitions (a gradient background falls back to its last solid colour),
     or CSS `color-mix`.  CSS custom properties (`var()`), flex rows with
     or CSS `color-mix`.  CSS custom properties (`var()`), flex rows with
@@ -1299,7 +1259,7 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     seconds; the 8 KB user stack means the layout state is deliberately
     seconds; the 8 KB user stack means the layout state is deliberately
     static.
     static.
 
 
-24. UEFI boot is x86-64 firmware only (no `BOOTIA32.EFI` yet) and the loader
+23. UEFI boot is x86-64 firmware only (no `BOOTIA32.EFI` yet) and the loader
     is unsigned, so Secure Boot must be off.  The loader needs a GOP mode with
     is unsigned, so Secure Boot must be off.  The loader needs a GOP mode with
     BGRX or RGBX 32bpp, width ≤ 1280, `pitch * height` ≤ 8 MB and the
     BGRX or RGBX 32bpp, width ≤ 1280, `pitch * height` ≤ 8 MB and the
     framebuffer below 4 GB; otherwise the kernel starts headless (serial only).
     framebuffer below 4 GB; otherwise the kernel starts headless (serial only).
@@ -1313,7 +1273,7 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     `reboot`/`poweroff` still use the legacy ports.  The image is 17 MB: the
     `reboot`/`poweroff` still use the legacy ports.  The image is 17 MB: the
     9 MB kernel + rootfs disk and the 8 MB ESP.
     9 MB kernel + rootfs disk and the 8 MB ESP.
 
 
-25. ThinkPad EC sensor access (`tpec.c`) runs in legacy/SMM mode because
+24. ThinkPad EC sensor access (`tpec.c`) runs in legacy/SMM mode because
     there is no ACPI interpreter: an SMI that touches the EC between our port
     there is no ACPI interpreter: an SMI that touches the EC between our port
     accesses can produce an occasional bad sample, and EC hotkey events are
     accesses can produce an occasional bad sample, and EC hotkey events are
     drained/discarded instead of handled.  The PCH thermal sensor
     drained/discarded instead of handled.  The PCH thermal sensor

+ 5 - 68
Makefile

@@ -34,7 +34,7 @@ EFI_LDFLAGS = -nostdlib -Wl,--subsystem,10 -Wl,-e,efi_main \
               -Wl,--image-base,0x0 -Wl,--dynamicbase \
               -Wl,--image-base,0x0 -Wl,--dynamicbase \
               -Wl,--enable-reloc-section -Wl,--no-insert-timestamp
               -Wl,--enable-reloc-section -Wl,--no-insert-timestamp
 
 
-.PHONY: all clean run run-smp run-floppy run-usb run-uhci run-ehci run-ehci-asix run-xhci run-xhci-asix run-net run-e1000 run-ahci test-usb run-serial floppy usb uefi run-uefi test-uefi flash space prog bootstrap dev net-dev cmds-dev net-cmds browser-dev gallery-dev netmon monitor test-crypto test-images test-images-asan kernel-dev kernel-net-dev rootfs
+.PHONY: all clean run run-smp run-floppy run-usb run-uhci run-ehci run-ehci-asix run-xhci run-xhci-asix run-net run-e1000 run-ahci test-usb run-serial floppy usb uefi run-uefi test-uefi flash dev net-dev cmds-dev net-cmds browser-dev gallery-dev netmon monitor test-crypto test-images test-images-asan kernel-dev kernel-net-dev rootfs
 
 
 all: floppy.img usb.img final.bin root.img
 all: floppy.img usb.img final.bin root.img
 
 
@@ -86,9 +86,6 @@ disk.o: disk.c disk.h io.h timer.h
 fat.o: fat.c fat.h blkdev.h io.h
 fat.o: fat.c fat.h blkdev.h io.h
 	$(CC) $(CFLAGS) -Os -o $@ $<
 	$(CC) $(CFLAGS) -Os -o $@ $<
 
 
-run.o: run.c fat.h io.h fbtext.h run_api.h timer.h vga.h vfs.h
-	$(CC) $(CFLAGS) -o $@ $<
-
 rtc.o: rtc.c rtc.h
 rtc.o: rtc.c rtc.h
 	$(CC) $(CFLAGS) -o $@ $<
 	$(CC) $(CFLAGS) -o $@ $<
 
 
@@ -101,12 +98,6 @@ serial_ring_buf.o: serial_ring_buf.c serial_ring_buf.h
 serial_loop.o: serial_loop.c serial.h io.h timer.h
 serial_loop.o: serial_loop.c serial.h io.h timer.h
 	$(CC) $(CFLAGS) -o $@ $<
 	$(CC) $(CFLAGS) -o $@ $<
 
 
-bin_recv.o: bin_recv.c bin_recv.h serial.h io.h timer.h
-	$(CC) $(CFLAGS) -o $@ $<
-
-serial_recv.o: serial_recv.c serial.h bin_recv.h io.h
-	$(CC) $(CFLAGS) -o $@ $<
-
 vga.o: vga.c vga.h bootinfo.h blit.h pci.h gpu.h ati.h process.h
 vga.o: vga.c vga.h bootinfo.h blit.h pci.h gpu.h ati.h process.h
 	$(CC) $(CFLAGS) -o $@ $<
 	$(CC) $(CFLAGS) -o $@ $<
 
 
@@ -344,7 +335,7 @@ sys_net.o: sys_net.c sys_net.h syscall.h dhcp.h dns.h net.h netdev.h netlog.h pr
 syscall_stub.o: syscall_stub.S irqret.inc
 syscall_stub.o: syscall_stub.S irqret.inc
 	$(AS) $(ASFLAGS) -o $@ $<
 	$(AS) $(ASFLAGS) -o $@ $<
 
 
-kernel.elf: kernel.ld vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o reboot.o poweroff.o disk.o fat.o run.o serial.o serial_ring_buf.o serial_loop.o serial_recv.o bin_recv.o vga.o blit.o cpu.o thermal.o it87.o tpec.o power.o vga_copy.o gfxbench.o gpu.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o fbtext.o gfx.o display.o mouse.o uhci.o ohci.o ehci.o xhci.o asix.o usb.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o ata.o ahci.o fatdetect.o fatformat.o format.o vfs.o sys_fs.o sys_info.o sys_mem.o sys_net.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netkexec.o netlog.o dhcp.o dns.o tcp.o acpi.o lapic.o smp.o ap_tramp_embed.o prog_embed.o space_embed.o inflate.o ramfs.o share.o payload.o
+kernel.elf: kernel.ld vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o reboot.o poweroff.o disk.o fat.o serial.o serial_ring_buf.o serial_loop.o vga.o blit.o cpu.o thermal.o it87.o tpec.o power.o vga_copy.o gfxbench.o gpu.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o fbtext.o gfx.o display.o mouse.o uhci.o ohci.o ehci.o xhci.o asix.o usb.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o ata.o ahci.o fatdetect.o fatformat.o format.o vfs.o sys_fs.o sys_info.o sys_mem.o sys_net.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netkexec.o netlog.o dhcp.o dns.o tcp.o acpi.o lapic.o smp.o ap_tramp_embed.o inflate.o ramfs.o share.o payload.o
 	$(LD) $(KERNEL_LDFLAGS) -o $@ $(filter-out kernel.ld,$^)
 	$(LD) $(KERNEL_LDFLAGS) -o $@ $(filter-out kernel.ld,$^)
 
 
 MBR_LDFLAGS = -T mbr.ld -nostdlib -m elf_i386
 MBR_LDFLAGS = -T mbr.ld -nostdlib -m elf_i386
@@ -527,19 +518,6 @@ test-uefi: usb-efi.img
 		echo "UEFI boot: OK (/tmp/opencode/nebos-uefi-serial.log)" || \
 		echo "UEFI boot: OK (/tmp/opencode/nebos-uefi-serial.log)" || \
 		{ echo "UEFI boot: FAILED"; tail -c 4000 /tmp/opencode/nebos-uefi-serial.log; exit 1; }
 		{ echo "UEFI boot: FAILED"; tail -c 4000 /tmp/opencode/nebos-uefi-serial.log; exit 1; }
 
 
-prog.o: prog.c run_api.h
-	$(CC) $(CFLAGS) -o $@ $<
-
-prog.elf: prog.o
-	$(LD) -T user.ld -nostdlib -m elf_i386 -o $@ $<
-
-prog.bin: prog.elf
-	$(OBJCOPY) -O binary $< $@
-
-space: space.bin
-
-prog: prog.bin
-
 # Ring-3 commands: freestanding ELFs at USER_BASE, packed into cmds.pack and
 # Ring-3 commands: freestanding ELFs at USER_BASE, packed into cmds.pack and
 # mounted at /ramfs/bin (the shell's PATH default).  New command: add
 # mounted at /ramfs/bin (the shell's PATH default).  New command: add
 # ucmd_<name>.c to UCMDS; the pack is rebuilt automatically.
 # ucmd_<name>.c to UCMDS; the pack is rebuilt automatically.
@@ -770,46 +748,15 @@ payload.o: payload.c payload.h io.h mm.h ramfs.h serial.h vfs.h
 ramfs.o: ramfs.c ramfs.h serial.h inflate.h mm.h
 ramfs.o: ramfs.c ramfs.h serial.h inflate.h mm.h
 	$(CC) $(CFLAGS) -o $@ $<
 	$(CC) $(CFLAGS) -o $@ $<
 
 
-space.o: space.c run_api.h
-	$(CC) $(CFLAGS) -o $@ $<
-
-space.elf: space.o
-	$(LD) -T user.ld -nostdlib -m elf_i386 -o $@ $<
-
-space.bin: space.elf
-	$(OBJCOPY) -O binary $< $@
-
 hello.elf: hello.o
 hello.elf: hello.o
 	$(LD) -T hello.ld -nostdlib -m elf_i386 -o $@ $<
 	$(LD) -T hello.ld -nostdlib -m elf_i386 -o $@ $<
 	$(OBJCOPY) --strip-all $@ $@
 	$(OBJCOPY) --strip-all $@ $@
 
 
-hello_embed.o: hello.elf
-	$(LD) -m elf_i386 -r -b binary -o hello_embed.o hello.elf
-
-# User programs ship inside the kernel image so `make dev`/`make net-dev`
-# update them too (boards without a readable filesystem can still run them).
-prog_embed.o: prog.bin
-	$(LD) -m elf_i386 -r -b binary -o prog_embed.o prog.bin
-
-space_embed.o: space.bin
-	$(LD) -m elf_i386 -r -b binary -o space_embed.o space.bin
-
-bootstrap.o: bootstrap.c
-	$(CC) $(CFLAGS) -o $@ $<
-
-bootstrap.elf: bootstrap.o bootstrap.ld
-	$(LD) -T bootstrap.ld -nostdlib -m elf_i386 -o $@ $<
-
-bootstrap.bin: bootstrap.elf
-	$(OBJCOPY) -O binary $< $@
-
-root.img: prog.bin space.bin browser.elf gallery.elf testdata/browser/demo.html testdata/images/rgb.bmp
+root.img: browser.elf gallery.elf testdata/browser/demo.html testdata/images/rgb.bmp
 	dd if=/dev/zero of=$@ bs=512 count=2880 2>/dev/null
 	dd if=/dev/zero of=$@ bs=512 count=2880 2>/dev/null
 	mkfs.fat -F 12 -n "ROOTDISK" $@
 	mkfs.fat -F 12 -n "ROOTDISK" $@
 	echo "Hello from the second floppy!" | mcopy -i $@ - ::HELLO.TXT
 	echo "Hello from the second floppy!" | mcopy -i $@ - ::HELLO.TXT
 	echo "This is a test file on drive 1." | mcopy -i $@ - ::TEST.TXT
 	echo "This is a test file on drive 1." | mcopy -i $@ - ::TEST.TXT
-	mcopy -i $@ prog.bin ::PROG.BIN
-	mcopy -i $@ space.bin ::SPACE.BIN
 	mcopy -i $@ browser.elf ::BROWSER
 	mcopy -i $@ browser.elf ::BROWSER
 	mcopy -i $@ gallery.elf ::GALLERY
 	mcopy -i $@ gallery.elf ::GALLERY
 	mcopy -i $@ testdata/browser/demo.html ::DEMO.HTM
 	mcopy -i $@ testdata/browser/demo.html ::DEMO.HTM
@@ -948,11 +895,10 @@ scp-root: root.img
 
 
 SERIAL_DEV ?= /dev/ttyUSB0
 SERIAL_DEV ?= /dev/ttyUSB0
 SERIAL_BAUD ?= 115200
 SERIAL_BAUD ?= 115200
-SZ ?= /usr/bin/lrzsz-sz
 
 
 run-serial:
 run-serial:
 	@echo "Starting serial monitor on $(SERIAL_DEV) at $(SERIAL_BAUD) baud..."
 	@echo "Starting serial monitor on $(SERIAL_DEV) at $(SERIAL_BAUD) baud..."
-	@echo "Type 'serial test' or 'serial recv' in the nebos terminal."
+	@echo "Type 'serial test' in the nebos terminal."
 	@echo "Press Ctrl-A Ctrl-X to exit picocom."
 	@echo "Press Ctrl-A Ctrl-X to exit picocom."
 	picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
 	picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
 
 
@@ -961,13 +907,6 @@ monitor:
 	@echo "Each 'make dev' reload prints: NebOS v<version> booted"
 	@echo "Each 'make dev' reload prints: NebOS v<version> booted"
 	picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
 	picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
 
 
-send: $(PROGRAM).bin send_serial
-	@echo "Sending $(PROGRAM).bin via serial..."
-	./send_serial $(SERIAL_DEV) $(SERIAL_BAUD) $(PROGRAM).bin
-
-send_serial: send_serial.c
-	gcc -O2 -o $@ $<
-
 kexec_send: kexec_send.c
 kexec_send: kexec_send.c
 	gcc -O2 -o $@ $<
 	gcc -O2 -o $@ $<
 
 
@@ -977,8 +916,6 @@ netkexec_send: netkexec_send.c
 netmonitor: netmonitor.c
 netmonitor: netmonitor.c
 	gcc -O2 -o $@ $<
 	gcc -O2 -o $@ $<
 
 
-bootstrap: bootstrap.bin
-
 dev: kernel.bin cmds_pack_gz.bin kexec_send
 dev: kernel.bin cmds_pack_gz.bin kexec_send
 	@entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
 	@entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
 	if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
 	if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
@@ -1042,4 +979,4 @@ kernel-net-dev: kernel.bin netkexec_send
 	./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin
 	./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin
 
 
 clean:
 clean:
-	rm -f boot.o vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o hello.o reboot.o poweroff.o fat.o run.o disk.o serial.o serial_ring_buf.o serial_loop.o serial_recv.o bin_recv.o vga.o blit.o cpu.o thermal.o it87.o tpec.o power.o vga_copy.o gfxbench.o gpu.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o font_8x16.o fbtext.o gfx.o display.o mouse.o uhci.o ohci.o ehci.o xhci.o asix.o usb.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o ata.o ahci.o fatdetect.o fatformat.o format.o vfs.o sys_fs.o sys_info.o sys_mem.o inflate.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netkexec.o netlog.o dhcp.o dns.o tcp.o acpi.o lapic.o smp.o ap_tramp.o ap_tramp.elf ap_tramp.bin ap_tramp_embed.o mbr.o boot.elf kernel.elf mbr.elf boot.bin mbr.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin floppy.img usb.img final.bin root.img prog.o prog.elf prog.bin space.o space.elf space.bin hello.elf hello_embed.o prog_embed.o space_embed.o cmds.pack cmds_pack_gz.bin cmds_pack.o rootfs.bin cmds.img mkrootfs ramfs.o share.o payload.o mkpack uwm_lib.o ngui.o img.o img_mem.o img_blit.o img_png.o img_bmp.o img_gif.o img_jpeg.o img_tga.o img_pnm.o img_ico.o img_pam.o img_gif_anim.o img_file.o browser.o browser_html.o uhttp.o browser.elf img_test img_test_asan *.boot.tmp $(addsuffix .o,$(UCMDS)) $(addsuffix .elf,$(UCMDS)) gallery.o gallery.elf $(TLSLIB_OBJS) tls_test bootstrap.o bootstrap.elf bootstrap.bin send_serial kexec_send netkexec_send netmonitor BOOTX64.EFI esp.img usb-efi.img efi/main.o efi/payload.o efi/tramp.o efi/tramp.elf efi/tramp.bin efi/efi_entry.h
+	rm -f boot.o vesa_stage.o entry.o kernel.o timer.o switch.o sched.o process.o mm.o kmalloc.o paging.o elf.o tss.o syscall.o sys_wm.o syscall_stub.o screen.o io.o tty.o rtc.o terminal.o wm.o hello.o reboot.o poweroff.o fat.o disk.o serial.o serial_ring_buf.o serial_loop.o vga.o blit.o cpu.o thermal.o it87.o tpec.o power.o vga_copy.o gfxbench.o gpu.o ati.o cirrus.o intel.o nvidia.o nv50.o radeon.o mtrr.o font_8x8.o font_8x16.o fbtext.o gfx.o display.o mouse.o uhci.o ohci.o ehci.o xhci.o asix.o usb.o usbhid.o lsusb.o panic.o bootcon.o blkdev.o ata.o ahci.o fatdetect.o fatformat.o format.o vfs.o sys_fs.o sys_info.o sys_mem.o inflate.o idle.o kexec.o kexec_tramp.o dbg.o lspci.o peek.o ne2000.o r8168.o e1000e.o netdev.o net.o netkexec.o netlog.o dhcp.o dns.o tcp.o acpi.o lapic.o smp.o ap_tramp.o ap_tramp.elf ap_tramp.bin ap_tramp_embed.o mbr.o boot.elf kernel.elf mbr.elf boot.bin mbr.bin kernel.bin boot.bin.tmp boot.bin.patched image.bin floppy.img usb.img final.bin root.img hello.elf cmds.pack cmds_pack_gz.bin cmds_pack.o rootfs.bin cmds.img mkrootfs ramfs.o share.o payload.o mkpack uwm_lib.o ngui.o img.o img_mem.o img_blit.o img_png.o img_bmp.o img_gif.o img_jpeg.o img_tga.o img_pnm.o img_ico.o img_pam.o img_gif_anim.o img_file.o browser.o browser_html.o uhttp.o browser.elf img_test img_test_asan *.boot.tmp $(addsuffix .o,$(UCMDS)) $(addsuffix .elf,$(UCMDS)) gallery.o gallery.elf $(TLSLIB_OBJS) tls_test kexec_send netkexec_send netmonitor BOOTX64.EFI esp.img usb-efi.img efi/main.o efi/payload.o efi/tramp.o efi/tramp.elf efi/tramp.bin efi/efi_entry.h

+ 0 - 75
bin_recv.c

@@ -1,75 +0,0 @@
-/* Simple binary receiver: size (4 bytes BE) + data + checksum (1 byte).
-   Returns bytes received, or -1 on error/timeout.
-   Prints '.' via io_putchar for each 512-byte chunk received. */
-
-#include "bin_recv.h"
-#include "serial.h"
-#include "io.h"
-#include "timer.h"
-#include "idle.h"
-
-#define TIMEOUT_MS 5000
-
-static int wait_byte(unsigned int port, unsigned char *out, unsigned int timeout_ms)
-{
-	(void)port;
-	return serial_ring_wait(timeout_ms, out);
-}
-
-int bin_recv(unsigned int port, void *buf, unsigned int max_size)
-{
-	unsigned char *p = (unsigned char *)buf;
-	unsigned int total = 0;
-	unsigned char c;
-	unsigned int i;
-	unsigned int size = 0;
-	unsigned char checksum = 0;
-	unsigned char recv_sum = 0;
-
-	/* Send 'R' to signal ready, wait for sender to start. */
-	serial_putc(port, 'R');
-
-	/* Read 4-byte size (big-endian). */
-	for (i = 0; i < 4; i++) {
-		if (!wait_byte(port, &c, TIMEOUT_MS)) {
-			io_putstr("timeout reading size\n");
-			return -1;
-		}
-		size = (size << 8) | c;
-	}
-
-	if (size == 0 || size > max_size) {
-		io_putstr("bad size\n");
-		return -1;
-	}
-
-	/* Read data bytes. */
-	for (i = 0; i < size; i++) {
-		if (!wait_byte(port, &c, TIMEOUT_MS)) {
-			io_putstr("timeout at byte ");
-			serial_putdec(port, i);
-			io_putstr("\n");
-			return -1;
-		}
-		p[i] = c;
-		checksum += c;
-		total++;
-		if ((i + 1) % 512 == 0)
-			io_putchar('.');
-	}
-	io_putchar('.');
-
-	/* Read checksum byte. */
-	if (!wait_byte(port, &recv_sum, TIMEOUT_MS)) {
-		io_putstr("timeout reading checksum\n");
-		return -1;
-	}
-
-	if (checksum != recv_sum) {
-		io_putstr("checksum mismatch\n");
-		return -1;
-	}
-
-	io_putchar('\n');
-	return (int)total;
-}

+ 0 - 7
bin_recv.h

@@ -1,7 +0,0 @@
-/* Simple binary receiver for serial transfer. */
-#ifndef BIN_RECV_H
-#define BIN_RECV_H
-
-int bin_recv(unsigned int port, void *buf, unsigned int max_size);
-
-#endif

+ 0 - 169
bootstrap.c

@@ -1,169 +0,0 @@
-/* One-time kexec bootstrap (loaded via the existing `serial recv` + `run serial`
- * path at 9600 baud). Because nebos runs everything in ring-0, this program has
- * full hardware access: it switches COM1 to 115200, receives a new kernel image,
- * copies it over 0x7E00, and jumps to its kernel_main.
- *
- * Self-contained: no kernel symbols, no run_api dependency. We live at 0x4A000
- * (outside the 0x7E00..0x49000 kernel region), so we can overwrite the kernel
- * directly from our own code without a relocated trampoline.
- *
- * Wire protocol (host -> us), after we emit 'R':
- *   4 bytes: magic "KXE2" (LE)
- *   4 bytes: entry address (LE)
- *   4 bytes: kernel_size (LE)
- *   4 bytes: pack_size (LE)      -- consumed but not stored (see below)
- *   N bytes: kernel.bin data
- *   M bytes: rootfs pack data
- *   1 byte:  checksum (sum of both payloads mod 256)
- *
- * The bootstrap only installs the kernel; the rootfs pack arrives with the
- * next normal `make dev`/`make net-dev` (or `make cmds-dev`).
- */
-
-#define UART_BASE        0x3F8
-#define STAGE_ADDR       0x58000
-#define KERNEL_LOAD_ADDR 0x7E00
-#define BOOT_STACK       0x49800
-#define MAGIC            0x3245584B /* "KXE2" little-endian */
-#define MAX_SIZE         0x3C200
-
-static inline void outb(unsigned short port, unsigned char v)
-{
-	__asm__ volatile ("outb %0, %1" : : "a"(v), "Nd"(port));
-}
-
-static inline unsigned char inb(unsigned short port)
-{
-	unsigned char v;
-	__asm__ volatile ("inb %1, %0" : "=a"(v) : "Nd"(port));
-	return v;
-}
-
-static void uart_115200(void)
-{
-	outb(UART_BASE + 1, 0x00); /* IER off */
-	outb(UART_BASE + 3, 0x80); /* DLAB */
-	outb(UART_BASE + 0, 0x01); /* divisor low = 1 (115200) */
-	outb(UART_BASE + 1, 0x00); /* divisor high = 0 */
-	outb(UART_BASE + 3, 0x03); /* 8N1 */
-	outb(UART_BASE + 2, 0xC7); /* FIFO on, clear */
-	outb(UART_BASE + 4, 0x03); /* DTR|RTS */
-}
-
-static unsigned char read_byte(void)
-{
-	while (!(inb(UART_BASE + 5) & 0x01))
-		;
-	return inb(UART_BASE + 0);
-}
-
-static unsigned int read32le(void)
-{
-	unsigned int v = 0;
-	unsigned int i;
-	for (i = 0; i < 4; i++)
-		v |= (unsigned int)read_byte() << (8 * i);
-	return v;
-}
-
-static void delay(void)
-{
-	volatile unsigned int i;
-	for (i = 0; i < 50000; i++)
-		;
-}
-
-static void halt(void)
-{
-	for (;;)
-		__asm__ volatile ("hlt");
-}
-
-/* Flat GDT (base 0 / 4 GB) + GDTR, written to 0x900 (below the kernel) so
- * the new kernel's segment reloads don't read the old GDT we overwrite.
- * Layout: 24-byte GDT at 0x900, 6-byte GDTR at 0x918 (limit 23, base 0x900). */
-static const unsigned char flat_gdt_blob[30] = {
-	0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* null */
-	0xFF,0xFF,0x00,0x00, 0x00,0x9A,0xCF,0x00, /* code */
-	0xFF,0xFF,0x00,0x00, 0x00,0x92,0xCF,0x00, /* data */
-	0x17,0x00,              /* gdtr limit = 23 */
-	0x00,0x09,0x00,0x00     /* gdtr base = 0x900 */
-};
-
-static void copy_to(unsigned int dst, const void *src, unsigned int n)
-{
-	__asm__ volatile (
-		"cld\n\t"
-		"rep movsb"
-		: "+S"(src), "+D"(dst), "+c"(n)
-		:
-		: "memory");
-}
-
-static void setup_flat_gdt(void)
-{
-	copy_to(0x900, flat_gdt_blob, sizeof(flat_gdt_blob));
-	__asm__ volatile ("lgdt (%0)" : : "r"(0x918));
-}
-
-void _start(void)
-{
-	unsigned char c, sum = 0, chk;
-	unsigned int magic, entry, size, pack_size, i;
-
-	/* Stop the PIT (and all IRQs) so the kernel's serial_poll stops
-	 * competing with us for UART bytes. */
-	__asm__ volatile ("cli");
-	outb(0x21, 0xFF);
-	outb(0xA1, 0xFF);
-
-	uart_115200();
-
-	/* Drain stale bytes. */
-	while (inb(UART_BASE + 5) & 0x01)
-		(void)inb(UART_BASE + 0);
-
-	/* Emit 'R' until the host starts sending the header. */
-	for (;;) {
-		outb(UART_BASE + 0, 'R');
-		delay();
-		if (inb(UART_BASE + 5) & 0x01)
-			break;
-	}
-
-	magic = read32le();
-	entry = read32le();
-	size  = read32le();
-	pack_size = read32le();
-
-	if (magic != MAGIC || size == 0 || size > MAX_SIZE ||
-	    pack_size > 0x400000) {
-		outb(UART_BASE + 0, 'E');
-		halt();
-	}
-
-	for (i = 0; i < size; i++) {
-		c = read_byte();
-		((volatile unsigned char *)STAGE_ADDR)[i] = c;
-		sum += c;
-	}
-
-	/* Consume the rootfs bytes; the kernel gets them on the next reload. */
-	for (i = 0; i < pack_size; i++)
-		sum += read_byte();
-
-	chk = read_byte();
-	if (chk != sum) {
-		outb(UART_BASE + 0, 'E');
-		halt();
-	}
-
-	/* Copy staged kernel over 0x7E00, then jump to its kernel_main.
-	 * We live at 0x4A000, outside the overwritten region, so this is safe. */
-	setup_flat_gdt();
-	for (i = 0; i < size; i++)
-		((volatile unsigned char *)KERNEL_LOAD_ADDR)[i] =
-			((volatile unsigned char *)STAGE_ADDR)[i];
-
-	__asm__ volatile ("movl %0, %%esp; jmp *%1" : : "i"(BOOT_STACK), "r"(entry));
-}

+ 0 - 17
bootstrap.ld

@@ -1,17 +0,0 @@
-/* Bootstrap installer: pinned at the OLD build's PROGRAM_LOAD_ADDR (0x4A000).
- *
- * bootstrap.bin is received by a still-running *old* kernel whose `serial recv`
- * writes to its own fixed program address (0x4A000, pre-Stage-A builds), so it
- * must be linked there to run.  New builds never need it: the serial/net kexec
- * auto-detect reloads them.  See bootstrap.c and the AGENTS.md bootstrap flow. */
-ENTRY(_start)
-
-SECTIONS
-{
-	. = 0x4A000;
-	.text : { *(.text .text.*) }
-	.rodata : { *(.rodata .rodata.*) }
-	.data : { *(.data .data.*) }
-	.bss : { *(.bss .bss.*) *(COMMON) }
-	_end = .;
-}

+ 1 - 1
docs/boot.html

@@ -340,7 +340,7 @@
 					<tr><td><code>usb.img</code></td><td>9 MB</td><td>Legacy BIOS USB/IDE disk; MBR, boot partition at LBA 63, rootfs at LBA 1088.</td></tr>
 					<tr><td><code>usb.img</code></td><td>9 MB</td><td>Legacy BIOS USB/IDE disk; MBR, boot partition at LBA 63, rootfs at LBA 1088.</td></tr>
 					<tr><td><code>usb-efi.img</code></td><td>17 MB</td><td>Dual boot; adds an 8 MB FAT16 ESP at LBA 18432 with <code>BOOTX64.EFI</code>.</td></tr>
 					<tr><td><code>usb-efi.img</code></td><td>17 MB</td><td>Dual boot; adds an 8 MB FAT16 ESP at LBA 18432 with <code>BOOTX64.EFI</code>.</td></tr>
 					<tr><td><code>final.bin</code></td><td>Varies</td><td>Raw boot sector + kernel + rootfs, written directly to a device.</td></tr>
 					<tr><td><code>final.bin</code></td><td>Varies</td><td>Raw boot sector + kernel + rootfs, written directly to a device.</td></tr>
-					<tr><td><code>root.img</code></td><td>1.44 MB</td><td>FAT12 second floppy with test programs and fallback browser/gallery.</td></tr>
+					<tr><td><code>root.img</code></td><td>1.44 MB</td><td>FAT12 second floppy with the browser/gallery disk fallbacks and its test page/images.</td></tr>
 				</tbody>
 				</tbody>
 			</table>
 			</table>
 		</div>
 		</div>

+ 1 - 7
docs/development.html

@@ -202,12 +202,6 @@
 			The serial receive drops the BKL while it waits for bytes, so the WM
 			The serial receive drops the BKL while it waits for bytes, so the WM
 			and the other CPU's syscalls stay responsive during a reload.
 			and the other CPU's syscalls stay responsive during a reload.
 		</p>
 		</p>
-		<div class="note">
-			<p><strong>One-time install on a 9600-baud machine.</strong> Use the
-			<code>bootstrap</code> program loaded through <code>serial recv</code>
-			+ <code>run serial</code>. It switches the link to 115200 and waits
-			for a normal <code>KXE2</code> transfer.</p>
-		</div>
 	</section>
 	</section>
 
 
 	<section id="network">
 	<section id="network">
@@ -284,7 +278,7 @@ make net-cmds                   # replace /ramfs only</code></pre>
 			<li><strong>Ring-3 data segments.</strong> An IRET to ring 3 nulls DS/ES/FS/GS whose DPL is below CPL 3. Kernel stubs must restore selector <code>0x23</code> with <code>IRQ_RETURN_DS</code>. QEMU does not model this; only real hardware fails.</li>
 			<li><strong>Ring-3 data segments.</strong> An IRET to ring 3 nulls DS/ES/FS/GS whose DPL is below CPL 3. Kernel stubs must restore selector <code>0x23</code> with <code>IRQ_RETURN_DS</code>. QEMU does not model this; only real hardware fails.</li>
 			<li><strong>Paging is flat.</strong> Physical equals virtual everywhere; there is no process isolation.</li>
 			<li><strong>Paging is flat.</strong> Physical equals virtual everywhere; there is no process isolation.</li>
 			<li><strong>The BKL is not preemptible.</strong> A BKL holder can be in the middle of kernel structures; block points drop it, and <code>bkl_pause()</code> is for long waits.</li>
 			<li><strong>The BKL is not preemptible.</strong> A BKL holder can be in the middle of kernel structures; block points drop it, and <code>bkl_pause()</code> is for long waits.</li>
-			<li><strong>Kernel size wall.</strong> <code>_end</code> must stay below <code>0x7F000</code>; the legacy staging gap also constrains BSS and the compressed pack.</li>
+			<li><strong>Kernel size wall.</strong> <code>_end</code> must stay below <code>0x90000</code>; the legacy staging gap also constrains the loaded image and the compressed pack.</li>
 		</ul>
 		</ul>
 	</section>
 	</section>
 
 

+ 2 - 2
docs/drivers.html

@@ -300,8 +300,8 @@
 		<p>
 		<p>
 			<span class="file">serial.c</span> drives the 16550 at COM1, 115200
 			<span class="file">serial.c</span> drives the 16550 at COM1, 115200
 			8N1, with an IRQ-driven receive ring buffer. It is used for the boot
 			8N1, with an IRQ-driven receive ring buffer. It is used for the boot
-			trace, the netlog mirror source, XMODEM transfers, the <code>dbg</code>
-			monitor and the <code>KXE2</code> kexec receiver.
+			trace, the netlog mirror source, the <code>dbg</code> monitor and the
+			<code>KXE2</code> kexec receiver.
 		</p>
 		</p>
 		<p>
 		<p>
 			The transmitter is polled, so a machine without a serial port still
 			The transmitter is polled, so a machine without a serial port still

+ 2 - 4
docs/index.html

@@ -118,9 +118,7 @@
 			<figcaption>
 			<figcaption>
 				<strong>The layering is real, not just conceptual.</strong>
 				<strong>The layering is real, not just conceptual.</strong>
 				Ring-3 commands enter the kernel only through <code>int 0x80</code>;
 				Ring-3 commands enter the kernel only through <code>int 0x80</code>;
-				the kernel owns the devices and exposes narrow services. The one
-				deliberate exception is the legacy ring-0 <code>run</code> area used
-				by <code>prog</code> and <code>space</code>.
+				the kernel owns the devices and exposes narrow services.
 			</figcaption>
 			</figcaption>
 		</figure>
 		</figure>
 	</section>
 	</section>
@@ -152,7 +150,7 @@
 		<p>
 		<p>
 			The unusual parts of the architecture follow from a few hard rules.
 			The unusual parts of the architecture follow from a few hard rules.
 			They explain why the code uses fixed low-memory blocks, why the kernel
 			They explain why the code uses fixed low-memory blocks, why the kernel
-			is linked below <code>0x7F000</code>, and why so much care goes into
+			is linked below <code>0x90000</code>, and why so much care goes into
 			keeping the kernel image small.
 			keeping the kernel image small.
 		</p>
 		</p>
 		<ul>
 		<ul>

+ 1 - 3
docs/memory.html

@@ -131,9 +131,7 @@
 					<tr><td><code>0x6C00</code></td><td>AP trampoline real-mode stack top</td><td>Grows down</td></tr>
 					<tr><td><code>0x6C00</code></td><td>AP trampoline real-mode stack top</td><td>Grows down</td></tr>
 					<tr><td><code>0x6F00</code></td><td>AP startup info block</td><td>CR3, stack top, C entry, CPU index</td></tr>
 					<tr><td><code>0x6F00</code></td><td>AP startup info block</td><td>CR3, stack top, C entry, CPU index</td></tr>
 					<tr><td><code>0x60000</code></td><td>Legacy rootfs staging</td><td><code>0x60000..0x9FBFF</code>, compressed pack only</td></tr>
 					<tr><td><code>0x60000</code></td><td>Legacy rootfs staging</td><td><code>0x60000..0x9FBFF</code>, compressed pack only</td></tr>
-					<tr><td><code>_end</code></td><td>Kernel end</td><td><code>kernel.ld</code> asserts <code>_end ≤ 0x7F000</code></td></tr>
-					<tr><td><code>0x7FF00</code></td><td>Program API struct</td><td><code>PROGRAM_API_ADDR</code>, <code>run_api.h</code></td></tr>
-					<tr><td><code>0x80000</code></td><td>Legacy ring-0 program load area</td><td><code>run.c</code>, <code>serial_recv.c</code>, <code>user.ld</code>; max <code>0x6000</code></td></tr>
+					<tr><td><code>_end</code></td><td>Kernel end</td><td><code>kernel.ld</code> asserts <code>_end ≤ 0x90000</code></td></tr>
 					<tr><td><code>0x900000</code></td><td>Boot pack after relocation; dynamic stacks and kexec staging</td><td>Freed after <code>ramfs_init</code> takes its copy</td></tr>
 					<tr><td><code>0x900000</code></td><td>Boot pack after relocation; dynamic stacks and kexec staging</td><td>Freed after <code>ramfs_init</code> takes its copy</td></tr>
 					<tr><td><code>0x100000</code></td><td>VGA shadow buffer base</td><td><code>VGA_SHADOW_BASE</code>; 8 MB reserved</td></tr>
 					<tr><td><code>0x100000</code></td><td>VGA shadow buffer base</td><td><code>VGA_SHADOW_BASE</code>; 8 MB reserved</td></tr>
 					<tr><td><code>0x40000000</code></td><td>Ring-3 ELF link/load address</td><td><code>USER_BASE</code>, 2 MB window up to <code>0x40200000</code></td></tr>
 					<tr><td><code>0x40000000</code></td><td>Ring-3 ELF link/load address</td><td><code>USER_BASE</code>, 2 MB window up to <code>0x40200000</code></td></tr>

+ 1 - 27
docs/userland.html

@@ -59,7 +59,6 @@
 			<li><a href="#pack">Command pack</a></li>
 			<li><a href="#pack">Command pack</a></li>
 			<li><a href="#apps">GUI applications</a></li>
 			<li><a href="#apps">GUI applications</a></li>
 			<li><a href="#browser">Browser</a></li>
 			<li><a href="#browser">Browser</a></li>
-			<li><a href="#legacy">Legacy ring-0 programs</a></li>
 			<li><a href="#sources">Source map</a></li>
 			<li><a href="#sources">Source map</a></li>
 		</ul>
 		</ul>
 	</nav>
 	</nav>
@@ -210,16 +209,10 @@
 					<tr><td>Process / scheduler</td><td><code>ps</code> <code>sched</code> <code>renice</code> <code>kill</code> <code>idle</code> <code>cpufreq</code> <code>power</code></td></tr>
 					<tr><td>Process / scheduler</td><td><code>ps</code> <code>sched</code> <code>renice</code> <code>kill</code> <code>idle</code> <code>cpufreq</code> <code>power</code></td></tr>
 					<tr><td>Hardware / debug</td><td><code>display</code> <code>gfxbench</code> <code>lsusb</code> <code>lspci</code> <code>peek</code> <code>poke</code> <code>format</code> <code>dbg</code> <code>serial</code></td></tr>
 					<tr><td>Hardware / debug</td><td><code>display</code> <code>gfxbench</code> <code>lsusb</code> <code>lspci</code> <code>peek</code> <code>poke</code> <code>format</code> <code>dbg</code> <code>serial</code></td></tr>
 					<tr><td>Network control</td><td><code>netdev</code></td></tr>
 					<tr><td>Network control</td><td><code>netdev</code></td></tr>
-					<tr><td>Boot / power</td><td><code>reboot</code> <code>poweroff</code> <code>kexec</code> <code>run</code> <code>space</code> <code>prog</code></td></tr>
+					<tr><td>Boot / power</td><td><code>reboot</code> <code>poweroff</code> <code>kexec</code></td></tr>
 				</tbody>
 				</tbody>
 			</table>
 			</table>
 		</div>
 		</div>
-		<p>
-			<code>run</code> and the embedded <code>prog</code>/<code>space</code>
-			programs are the remaining ring-0 user-code path: binaries load at
-			<code>0x80000</code> and call the program API at <code>0x7FF00</code>.
-			Everything else user-facing is a ring-3 ELF.
-		</p>
 	</section>
 	</section>
 
 
 	<section id="pack">
 	<section id="pack">
@@ -298,24 +291,6 @@
 		</p>
 		</p>
 	</section>
 	</section>
 
 
-	<section id="legacy">
-		<h2>Legacy ring-0 programs</h2>
-		<p>
-			<code>run &lt;name&gt;</code>, <code>prog</code> and <code>space</code>
-			are the last programs that execute in ring 0. They load as raw
-			binaries at <code>0x80000</code> and use the function-pointer API at
-			<code>0x7FF00</code>. <code>prog</code>/<code>space</code> are also
-			embedded in the kernel image, so a board with no readable filesystem
-			can still run them.
-		</p>
-		<p>
-			These programs draw directly over the WM, which keeps repainting its
-			desktop, so they are demos rather than windowed applications. Moving
-			them to ring 3 would let the fixed low-memory block
-			(<code>0x7FF00</code>/<code>0x80000</code>) go away.
-		</p>
-	</section>
-
 	<section id="sources">
 	<section id="sources">
 		<h2>Source map</h2>
 		<h2>Source map</h2>
 		<ul class="filelist">
 		<ul class="filelist">
@@ -329,7 +304,6 @@
 			<li><code>Makefile</code> — <code>UCMDS</code> and pack rules</li>
 			<li><code>Makefile</code> — <code>UCMDS</code> and pack rules</li>
 			<li><code>ucmd_*.c</code> — commands</li>
 			<li><code>ucmd_*.c</code> — commands</li>
 			<li><code>browser.c</code>, <code>browser_html.c</code>, <code>gallery.c</code></li>
 			<li><code>browser.c</code>, <code>browser_html.c</code>, <code>gallery.c</code></li>
-			<li><code>run.c</code>, <code>run_api.h</code>, <code>prog.c</code>, <code>space.c</code></li>
 		</ul>
 		</ul>
 	</section>
 	</section>
 </main>
 </main>

+ 3 - 2
efi/main.c

@@ -21,8 +21,9 @@
 #define MAX_PAGES   (MAX_PHYS / PAGE_SIZE_)
 #define MAX_PAGES   (MAX_PHYS / PAGE_SIZE_)
 #define E820_ADDR   0x1000u
 #define E820_ADDR   0x1000u
 
 
-/* The kernel image is linked to live at 0x7E00 and must stay below the run
- * area at 0x80000 (kernel.ld asserts _end <= 0x7F000). */
+/* The kernel image is linked to live at 0x7E00.  Its file image must stay
+ * below the legacy pack staging gap at 0x60000 (kernel.ld asserts
+ * __bss_start <= 0x60000); KERNEL_MAX is a generous sanity bound. */
 #define KERNEL_DEST 0x7E00u
 #define KERNEL_DEST 0x7E00u
 #define KERNEL_MAX  0x70000u
 #define KERNEL_MAX  0x70000u
 
 

+ 0 - 46
fbtext.c

@@ -346,52 +346,6 @@ static void hue_to_rgb(unsigned int hue, unsigned int *r, unsigned int *g, unsig
 	*b = (b1 * (RAINBOW_SEG - f) + b2 * f) / RAINBOW_SEG;
 	*b = (b1 * (RAINBOW_SEG - f) + b2 * f) / RAINBOW_SEG;
 }
 }
 
 
-/* Draw string at pixel (x0, y0) with fg RGB. transparent_bg 1 = only fg pixels (for overlays). */
-void fbtext_draw_string_xy(unsigned int x0, unsigned int y0, const char *str,
-		unsigned int r_fg, unsigned int g_fg, unsigned int b_fg, int transparent_bg)
-{
-	unsigned int i = 0;
-	while (str[i]) {
-		draw_glyph_at(x0 + i * 8, y0, (unsigned char)str[i], r_fg, g_fg, b_fg, 0, 0, 0, FONT_8X8_ROWS, transparent_bg);
-		i++;
-	}
-	vga_target_damage(x0, y0, i * 8, FONT_8X8_ROWS);
-}
-
-/* Like fbtext_draw_string_xy, but per-pixel clipped to (cx, cy, cw, ch): only
- * foreground pixels inside the clip rect are written. */
-void fbtext_draw_string_xy_clip(unsigned int x0, unsigned int y0, const char *str,
-		unsigned int r_fg, unsigned int g_fg, unsigned int b_fg,
-		unsigned int cx, unsigned int cy, unsigned int cw, unsigned int ch)
-{
-	unsigned int i;
-
-	for (i = 0; str[i]; i++) {
-		unsigned int gx = x0 + i * 8;
-		const unsigned char *glyph;
-		unsigned int x, y;
-
-		if (gx + 8 <= cx || gx >= cx + cw ||
-		    y0 + FONT_8X8_ROWS <= cy || y0 >= cy + ch)
-			continue;
-		glyph = &font_8x8[(unsigned int)str[i] * FONT_8X8_ROWS];
-		for (y = 0; y < FONT_8X8_ROWS; y++) {
-			unsigned char bits = glyph[y];
-			unsigned int py = y0 + y;
-			unsigned int xa, xb;
-
-			if (!bits || py < cy || py >= cy + ch)
-				continue;
-			xa = (gx > cx) ? gx : cx;
-			xb = (gx + 8 < cx + cw) ? gx + 8 : cx + cw;
-			for (x = xa; x < xb; x++)
-				if (bits & (0x80u >> (x - gx)))
-					vga_put_pixel_rgb(x, py, r_fg, g_fg, b_fg);
-		}
-	}
-	vga_target_damage(cx, cy, cw, ch);
-}
-
 #define RAINBOW_LINE_HEIGHT  2   /* 2-pixel tall line for visibility */
 #define RAINBOW_LINE_HEIGHT  2   /* 2-pixel tall line for visibility */
 
 
 void fbtext_draw_rainbow_separator(void)
 void fbtext_draw_rainbow_separator(void)

+ 0 - 10
fbtext.h

@@ -27,16 +27,6 @@ void fbtext_show_cursor(void);
 /* Hide cursor and redraw cell with (c, attr) so the character is restored. */
 /* Hide cursor and redraw cell with (c, attr) so the character is restored. */
 void fbtext_hide_cursor(unsigned char c, unsigned char attr);
 void fbtext_hide_cursor(unsigned char c, unsigned char attr);
 
 
-/* Draw string at pixel (x0, y0) with fg RGB. transparent_bg 1 = only fg pixels (overlays). */
-void fbtext_draw_string_xy(unsigned int x0, unsigned int y0, const char *str,
-		unsigned int r_fg, unsigned int g_fg, unsigned int b_fg, int transparent_bg);
-
-/* Same, but per-pixel clipped to (cx, cy, cw, ch): pixels outside the clip
- * are never written (used by the window manager's damage-rect repaints). */
-void fbtext_draw_string_xy_clip(unsigned int x0, unsigned int y0, const char *str,
-		unsigned int r_fg, unsigned int g_fg, unsigned int b_fg,
-		unsigned int cx, unsigned int cy, unsigned int cw, unsigned int ch);
-
 /* Draw a rainbow gradient line just below the header row (between header and content). No-op if not LFB. */
 /* Draw a rainbow gradient line just below the header row (between header and content). No-op if not LFB. */
 void fbtext_draw_rainbow_separator(void);
 void fbtext_draw_rainbow_separator(void);
 
 

+ 4 - 3
io.c

@@ -367,9 +367,10 @@ int io_poll_key(void)
 }
 }
 
 
 /* Like io_poll_key but also reads from port 0x60 when buffer is empty.
 /* Like io_poll_key but also reads from port 0x60 when buffer is empty.
-   For use by full-screen programs (e.g. space.bin) where IRQ may be missed on
-   real HW.  Only reads when a keyboard byte is actually pending (OBF set, AUX
-   clear); the status+data pair is read atomically wrt IRQ1. */
+   For use by callers that poll the keyboard without an IRQ path (the WM's
+   boot-console fallback and format's confirmation prompt) where an IRQ may be
+   missed on real HW.  Only reads when a keyboard byte is actually pending
+   (OBF set, AUX clear); the status+data pair is read atomically wrt IRQ1. */
 int io_poll_key_with_hw(void)
 int io_poll_key_with_hw(void)
 {
 {
 	unsigned char sc = 0;
 	unsigned char sc = 0;

+ 4 - 2
kernel.ld

@@ -28,9 +28,11 @@ SECTIONS
 	}
 	}
 	_end = .;
 	_end = .;
 }
 }
-ASSERT(_end <= 0x7F000, "Kernel too large: would reach the run area at 0x80000");
 /* The legacy stage stages the compressed rootfs at 0x60000 before copying it
 /* The legacy stage stages the compressed rootfs at 0x60000 before copying it
  * to PACK_HIGH_ADDR; the loaded image (text/rodata/data) must not reach that
  * to PACK_HIGH_ADDR; the loaded image (text/rodata/data) must not reach that
  * staging area.  BSS and the boot stack may extend past it: the stage copy
  * staging area.  BSS and the boot stack may extend past it: the stage copy
- * happens before the kernel clears BSS and starts using its stack. */
+ * happens before the kernel clears BSS and starts using its stack.  Keep the
+ * kernel end below 0x90000 so the top of the staging gap and the EBDA stay
+ * untouched. */
 ASSERT(__bss_start <= 0x60000, "Kernel image too large: legacy pack staging would overwrite it");
 ASSERT(__bss_start <= 0x60000, "Kernel image too large: legacy pack staging would overwrite it");
+ASSERT(_end <= 0x90000, "Kernel too large: would reach the top of the low-memory staging gap");

+ 1 - 1
kexec_send.c

@@ -1,4 +1,4 @@
-/* Host-side sender for nebos `kexec` / `bootstrap` / `cmds-dev`.
+/* Host-side sender for nebos `kexec` / `cmds-dev`.
  *
  *
  * Kernel + rootfs protocol (serial, no handshake; the kernel auto-detects it):
  * Kernel + rootfs protocol (serial, no handshake; the kernel auto-detects it):
  *   4 bytes: magic "KXE2" (LE)
  *   4 bytes: magic "KXE2" (LE)

+ 0 - 32
prog.c

@@ -1,32 +0,0 @@
-/* Example user program: draws "omg!" centered, runs until ESC. Uses kernel API at PROGRAM_API_ADDR. */
-
-#include "run_api.h"
-
-/* Character cell size used by fbtext (8px wide, 10px row height). */
-#define CHAR_WIDTH  8
-#define ROW_HEIGHT  10
-
-static const struct prog_api *const api = (const struct prog_api *)PROGRAM_API_ADDR;
-
-/* Pad binary past 1KB so it uses cluster 8+ (reproduces LBA 0x27 read failure on real HW). */
-static const char prog_padding[3072] __attribute__((used)) = { 0 };
-
-void _start(void)
-{
-	(void)prog_padding;  /* keep in binary */
-	unsigned int cols, rows, cx, cy;
-	const char *msg = "omg!";
-
-	cols = api->get_cols();
-	rows = api->get_rows();
-	/* Center "omg!" (4 chars): x = (cols*8)/2 - (4*8)/2, y = (rows*10)/2 - 5 */
-	cx = (cols * CHAR_WIDTH) / 2 - (4 * CHAR_WIDTH) / 2;
-	cy = (rows * ROW_HEIGHT) / 2 - ROW_HEIGHT / 2;
-
-	api->draw_string_xy(cx, cy, msg, 255, 255, 255, 0);
-
-	while (api->poll_key() != IO_KEY_ESC)
-		;
-
-	return;
-}

+ 0 - 161
run.c

@@ -1,161 +0,0 @@
-/* run command: load raw binary from a FAT filesystem to 0x80000 and execute.
- * Usage: run /<device>/<file>. */
-
-#include "fbtext.h"
-#include "io.h"
-#include "run_api.h"
-#include "serial.h"
-#include "timer.h"
-#include "vga.h"
-#include "vfs.h"
-
-#define PROGRAM_LOAD_ADDR 0x80000
-#define PROGRAM_LOAD_MAX  0x6000   /* up to 0x86000, below the VGA window */
-
-/* User programs embedded in the kernel image: they travel with
- * `make dev`/`make net-dev`, so a board with no readable filesystem can
- * still run them.  Rebuilt from prog.c/space.c by the Makefile. */
-extern unsigned char _binary_prog_bin_start[], _binary_prog_bin_end[];
-extern unsigned char _binary_space_bin_start[], _binary_space_bin_end[];
-
-struct embedded_prog {
-	const char *name;
-	const unsigned char *start;
-	const unsigned char *end;
-};
-
-static const struct embedded_prog embedded_progs[] = {
-	{ "prog",  _binary_prog_bin_start,  _binary_prog_bin_end },
-	{ "space", _binary_space_bin_start, _binary_space_bin_end },
-};
-
-static int name_eq(const char *a, const char *b)
-{
-	unsigned int i = 0;
-
-	while (a[i] && b[i] && a[i] == b[i])
-		i++;
-	return a[i] == '\0' && b[i] == '\0';
-}
-
-/* Install the program API and hand control to the image at PROGRAM_LOAD_ADDR. */
-static void jump_to_program(void)
-{
-	struct prog_api api = {
-		.draw_string_xy = fbtext_draw_string_xy,
-		.get_cols       = fbtext_get_cols,
-		.get_rows       = fbtext_get_rows,
-		.poll_key       = io_poll_key,
-		.poll_key_with_hw = io_poll_key_with_hw,
-		.get_fb_width   = vga_fb_width,
-		.get_fb_height  = vga_fb_height,
-		.clear_rgb      = vga_clear_rgb,
-		.put_pixel_rgb  = vga_put_pixel_rgb,
-		.get_ticks_ms   = get_ticks_ms,
-	};
-
-	io_drain_keyboard();
-	*(struct prog_api *)PROGRAM_API_ADDR = api;
-	((void (*)(void))PROGRAM_LOAD_ADDR)();
-}
-
-/* Load the named embedded program and run it (0 = name not found). */
-static int run_embedded(const char *name)
-{
-	unsigned int i;
-
-	for (i = 0; i < sizeof(embedded_progs) / sizeof(embedded_progs[0]); i++) {
-		const struct embedded_prog *p = &embedded_progs[i];
-		unsigned int size;
-		unsigned char *dst = (unsigned char *)PROGRAM_LOAD_ADDR;
-		const unsigned char *src;
-
-		if (!name_eq(name, p->name))
-			continue;
-		size = (unsigned int)(p->end - p->start);
-		if (size == 0 || size > PROGRAM_LOAD_MAX) {
-			io_putstr("run: embedded image size out of range\n");
-			return 1;
-		}
-		for (src = p->start; src < p->end; )
-			*dst++ = *src++;
-		jump_to_program();
-		return 1;
-	}
-	return 0;
-}
-
-void program_run_main(const char *filename)
-{
-	struct vfs_file f;
-	struct vfs_mount *m = 0;
-	unsigned int i;
-	int r;
-
-	if (!filename || !filename[0]) {
-		io_putstr("run: usage run <name>|/<device>/<file>\n");
-		return;
-	}
-
-	/* Names of embedded programs first: `run prog`, `run space`. */
-	if (run_embedded(filename))
-		return;
-
-	/* Anything else comes from a mounted filesystem (FAT or the ramfs). */
-	r = vfs_load_file(filename, &f, &m);
-	if (r == VFS_ENOENT) {
-		io_putstr("run: file not found\n");
-		return;
-	}
-	if (r != 0) {
-		io_putstr("run: disk read error (see above)\n");
-		return;
-	}
-	if (f.size == 0 || f.size > PROGRAM_LOAD_MAX) {
-		io_putstr("run: file too large\n");
-		vfs_release_file(m, &f);
-		return;
-	}
-	for (i = 0; i < f.size; i++)
-		((unsigned char *)PROGRAM_LOAD_ADDR)[i] =
-			((const unsigned char *)f.data)[i];
-	vfs_release_file(m, &f);
-
-	io_drain_keyboard();
-	{
-		struct prog_api api = {
-			.draw_string_xy = fbtext_draw_string_xy,
-			.get_cols       = fbtext_get_cols,
-			.get_rows       = fbtext_get_rows,
-			.poll_key       = io_poll_key,
-			.poll_key_with_hw = io_poll_key_with_hw,
-			.get_fb_width   = vga_fb_width,
-			.get_fb_height  = vga_fb_height,
-			.clear_rgb      = vga_clear_rgb,
-			.put_pixel_rgb  = vga_put_pixel_rgb,
-			.get_ticks_ms   = get_ticks_ms,
-		};
-		*(struct prog_api *)PROGRAM_API_ADDR = api;
-	}
-	((void (*)(void))PROGRAM_LOAD_ADDR)();
-}
-
-/* run serial: execute the binary already loaded at 0x80000 via serial_recv. */
-
-void program_run_serial_main(const char *arg)
-{
-	(void)arg;
-
-	if (serial_recv_size == 0) {
-		io_putstr("run serial: no binary received (use 'serial recv' first)\n");
-		return;
-	}
-	jump_to_program();
-}
-
-/* Command entry for the embedded programs (`prog`, `space`). */
-void program_run_embedded_main(const char *name)
-{
-	if (!run_embedded(name))
-		io_putstr("run: no such embedded program\n");
-}

+ 0 - 42
run_api.h

@@ -1,42 +0,0 @@
-/* API passed to loaded program at PROGRAM_API_ADDR. Used by run command and by programs run via run (e.g. prog, space). */
-
-#ifndef RUN_API_H
-#define RUN_API_H
-
-/* Sits just below the program load area, inside the low 1 MB the frame
- * allocator reserves; keep in sync with run.c and user.ld. */
-#define PROGRAM_API_ADDR 0x7FF00
-#define IO_KEY_ESC       0x1B
-#define IO_KEY_SPACE     0x20
-#define IO_KEY_LEFT      0x100
-#define IO_KEY_RIGHT     0x101
-
-/* Function pointer types for the program API. */
-typedef void (*prog_draw_string_xy_t)(unsigned int x0, unsigned int y0,
-	const char *str, unsigned int r_fg, unsigned int g_fg, unsigned int b_fg,
-	int transparent_bg);
-typedef unsigned int (*prog_get_cols_t)(void);
-typedef unsigned int (*prog_get_rows_t)(void);
-typedef int (*prog_poll_key_t)(void);
-typedef int (*prog_poll_key_with_hw_t)(void);
-typedef unsigned int (*prog_get_fb_width_t)(void);
-typedef unsigned int (*prog_get_fb_height_t)(void);
-typedef void (*prog_clear_rgb_t)(unsigned int r, unsigned int g, unsigned int b);
-typedef void (*prog_put_pixel_rgb_t)(unsigned int x, unsigned int y,
-	unsigned int r, unsigned int g, unsigned int b);
-typedef unsigned int (*prog_get_ticks_ms_t)(void);
-
-struct prog_api {
-	prog_draw_string_xy_t draw_string_xy;
-	prog_get_cols_t       get_cols;
-	prog_get_rows_t       get_rows;
-	prog_poll_key_t       poll_key;
-	prog_poll_key_with_hw_t poll_key_with_hw;
-	prog_get_fb_width_t   get_fb_width;
-	prog_get_fb_height_t  get_fb_height;
-	prog_clear_rgb_t      clear_rgb;
-	prog_put_pixel_rgb_t  put_pixel_rgb;
-	prog_get_ticks_ms_t   get_ticks_ms;
-};
-
-#endif

+ 0 - 127
send_serial.c

@@ -1,127 +0,0 @@
-/* Simple binary sender for nebos serial_recv.
-   Protocol: receiver sends 'R', then sender sends:
-     4 bytes: size (big-endian)
-     N bytes: data
-     1 byte: checksum (sum of data bytes mod 256)
-   Usage: send_serial <device> <baud> <file> */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <termios.h>
-#include <stdint.h>
-
-int main(int argc, char *argv[])
-{
-	int fd;
-	FILE *fp;
-	unsigned char *data;
-	long size;
-	unsigned int cksum;
-	unsigned char buf[5];
-	unsigned char r;
-	struct termios tty;
-
-	if (argc != 4) {
-		fprintf(stderr, "Usage: %s <device> <baud> <file>\n", argv[0]);
-		return 1;
-	}
-
-	fd = open(argv[1], O_RDWR | O_NOCTTY);
-	if (fd < 0) {
-		perror("open");
-		return 1;
-	}
-
-	/* Configure serial port. */
-	memset(&tty, 0, sizeof(tty));
-	if (tcgetattr(fd, &tty) != 0) {
-		perror("tcgetattr");
-		return 1;
-	}
-
-	cfsetispeed(&tty, atoi(argv[2]));
-	cfsetospeed(&tty, atoi(argv[2]));
-
-	tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
-	tty.c_cflag |= CLOCAL | CREAD;
-	tty.c_cflag &= ~(PARENB | PARODD | CRTSCTS | CSTOPB);
-	tty.c_iflag &= ~(IXON | IXOFF | IXANY | IGNBRK | BRKINT | ICRNL | INLCR);
-	tty.c_oflag &= ~OPOST;
-	tty.c_lflag = 0;
-	tty.c_cc[VMIN] = 1;
-	tty.c_cc[VTIME] = 0;
-
-	if (tcsetattr(fd, TCSANOW, &tty) != 0) {
-		perror("tcsetattr");
-		return 1;
-	}
-
-	/* Read file. */
-	fp = fopen(argv[3], "rb");
-	if (!fp) {
-		perror("fopen");
-		return 1;
-	}
-	fseek(fp, 0, SEEK_END);
-	size = ftell(fp);
-	fseek(fp, 0, SEEK_SET);
-
-	data = malloc(size);
-	if (!data) {
-		perror("malloc");
-		return 1;
-	}
-	if (fread(data, 1, size, fp) != (size_t)size) {
-		perror("fread");
-		return 1;
-	}
-	fclose(fp);
-
-	/* Compute checksum. */
-	cksum = 0;
-	for (long i = 0; i < size; i++)
-		cksum += data[i];
-	cksum &= 0xFF;
-
-	/* Wait for 'R' from receiver. */
-	fprintf(stderr, "Waiting for receiver...\n");
-	if (read(fd, &r, 1) != 1 || r != 'R') {
-		fprintf(stderr, "No 'R' received\n");
-		return 1;
-	}
-	fprintf(stderr, "Got 'R', sending %ld bytes...\n", size);
-
-	/* Send size (4 bytes big-endian). */
-	buf[0] = (size >> 24) & 0xFF;
-	buf[1] = (size >> 16) & 0xFF;
-	buf[2] = (size >> 8) & 0xFF;
-	buf[3] = size & 0xFF;
-	if (write(fd, buf, 4) != 4) {
-		perror("write size");
-		return 1;
-	}
-	tcdrain(fd);
-
-	/* Send data. */
-	if (write(fd, data, size) != size) {
-		perror("write data");
-		return 1;
-	}
-	tcdrain(fd);
-
-	/* Send checksum. */
-	buf[0] = cksum;
-	if (write(fd, buf, 1) != 1) {
-		perror("write checksum");
-		return 1;
-	}
-	tcdrain(fd);
-
-	fprintf(stderr, "Done.\n");
-	free(data);
-	close(fd);
-	return 0;
-}

+ 0 - 2
serial.h

@@ -17,6 +17,4 @@ int  serial_ring_getc(void);
 int  serial_ring_wait(unsigned int timeout_ms, unsigned char *out);
 int  serial_ring_wait(unsigned int timeout_ms, unsigned char *out);
 int  serial_ring_peek(unsigned int offset, unsigned char *byte);
 int  serial_ring_peek(unsigned int offset, unsigned char *byte);
 
 
-extern unsigned int serial_recv_size;
-
 #endif
 #endif

+ 0 - 30
serial_recv.c

@@ -1,30 +0,0 @@
-/* Serial receive command: receives a binary via serial into 0x80000. */
-
-#include "io.h"
-#include "serial.h"
-#include "bin_recv.h"
-
-#define PROGRAM_LOAD_ADDR 0x80000
-#define PROGRAM_LOAD_MAX  0x6000   /* up to 0x86000, below the VGA window */
-
-unsigned int serial_recv_size;
-
-void program_serial_recv_main(const char *arg)
-{
-	int n;
-
-	(void)arg;
-
-	serial_recv_size = 0;
-
-	n = bin_recv(SERIAL_COM1, (void *)PROGRAM_LOAD_ADDR, PROGRAM_LOAD_MAX);
-	if (n < 0) {
-		io_putstr("serial_recv: transfer failed\n");
-		return;
-	}
-
-	serial_recv_size = (unsigned int)n;
-	io_putstr("serial_recv: received ");
-	serial_putdec(SERIAL_COM1, serial_recv_size);
-	io_putstr(" bytes\n");
-}

+ 0 - 232
space.c

@@ -1,232 +0,0 @@
-/* Simple Space Invaders: pixel graphics, keyboard input. Uses kernel API at PROGRAM_API_ADDR. */
-
-#include "run_api.h"
-
-#define INV_ROWS      5
-#define INV_COLS      10
-#define INV_W         10
-#define INV_H         8
-#define SHIP_W        16
-#define SHIP_H        8
-#define BULLET_W      2
-#define BULLET_H      6
-#define MAX_BULLETS   4
-#define FRAME_MS      33
-#define INV_STEP      4
-#define BULLET_SPEED  6
-#define SHIP_SPEED    6
-
-static const struct prog_api *const api = (const struct prog_api *)PROGRAM_API_ADDR;
-
-/* Row colors: red, green, yellow, cyan, magenta */
-static const unsigned int row_r[INV_ROWS] = { 255, 0, 255, 0, 255 };
-static const unsigned int row_g[INV_ROWS] = { 0, 255, 255, 255, 0 };
-static const unsigned int row_b[INV_ROWS] = { 0, 0, 0, 255, 255 };
-
-static unsigned int fb_w, fb_h;
-static int ship_x;
-static int inv_x, inv_y;
-static int inv_dir;
-static unsigned char alive[INV_ROWS][INV_COLS];
-static int num_alive;
-
-static int bullet_x[MAX_BULLETS];
-static int bullet_y[MAX_BULLETS];
-static int bullet_active[MAX_BULLETS];
-static int num_bullets;
-
-static void put_rect(int x0, int y0, int w, int h, unsigned int r, unsigned int g, unsigned int b)
-{
-	int x, y;
-	for (y = 0; y < h; y++)
-		for (x = 0; x < w; x++)
-			api->put_pixel_rgb((unsigned int)(x0 + x), (unsigned int)(y0 + y), r, g, b);
-}
-
-static void draw_ship(void)
-{
-	int x = ship_x;
-	int y = (int)fb_h - SHIP_H - 4;
-	put_rect(x, y, SHIP_W, SHIP_H, 0, 255, 128);
-}
-
-static void draw_invader(int row, int col)
-{
-	int x = inv_x + col * (INV_W + 4);
-	int y = inv_y + row * (INV_H + 2);
-	if (!alive[row][col])
-		return;
-	put_rect(x, y, INV_W, INV_H, row_r[row], row_g[row], row_b[row]);
-}
-
-static void draw_bullets(void)
-{
-	int i;
-	for (i = 0; i < MAX_BULLETS; i++)
-		if (bullet_active[i])
-			put_rect(bullet_x[i], bullet_y[i], BULLET_W, BULLET_H, 255, 255, 255);
-}
-
-static void spawn_bullet(void)
-{
-	int i;
-	for (i = 0; i < MAX_BULLETS; i++) {
-		if (!bullet_active[i]) {
-			bullet_x[i] = ship_x + SHIP_W / 2 - BULLET_W / 2;
-			bullet_y[i] = (int)fb_h - SHIP_H - 4 - BULLET_H;
-			bullet_active[i] = 1;
-			num_bullets++;
-			break;
-		}
-	}
-}
-
-static void update_bullets(void)
-{
-	int i, r, c;
-	int bx, by, ix, iy;
-
-	for (i = 0; i < MAX_BULLETS; i++) {
-		if (!bullet_active[i])
-			continue;
-		bullet_y[i] -= BULLET_SPEED;
-		if (bullet_y[i] < 0) {
-			bullet_active[i] = 0;
-			num_bullets--;
-			continue;
-		}
-		bx = bullet_x[i];
-		by = bullet_y[i];
-		for (r = 0; r < INV_ROWS; r++) {
-			for (c = 0; c < INV_COLS; c++) {
-				if (!alive[r][c])
-					continue;
-				ix = inv_x + c * (INV_W + 4);
-				iy = inv_y + r * (INV_H + 2);
-				if (bx + BULLET_W > ix && bx < ix + INV_W &&
-				    by + BULLET_H > iy && by < iy + INV_H) {
-					alive[r][c] = 0;
-					num_alive--;
-					bullet_active[i] = 0;
-					num_bullets--;
-					goto next_bullet;
-				}
-			}
-		}
-next_bullet:;
-	}
-}
-
-static void update_invaders(void)
-{
-	int edge;
-
-	inv_x += inv_dir * INV_STEP;
-	edge = inv_x + INV_COLS * (INV_W + 4) - 4;
-	if (inv_dir > 0 && edge >= (int)fb_w) {
-		inv_dir = -1;
-		inv_y += INV_H + 4;
-		inv_x = (int)fb_w - (INV_COLS * (INV_W + 4) - 4);
-		if (inv_x < 0)
-			inv_x = 0;
-	} else if (inv_dir < 0 && inv_x <= 0) {
-		inv_dir = 1;
-		inv_y += INV_H + 4;
-		inv_x = 0;
-	}
-}
-
-static void game_init(void)
-{
-	int r, c;
-	fb_w = api->get_fb_width();
-	fb_h = api->get_fb_height();
-	if (fb_w < 100)
-		fb_w = 320;
-	if (fb_h < 100)
-		fb_h = 200;
-
-	ship_x = (int)fb_w / 2 - SHIP_W / 2;
-	if (ship_x < 0)
-		ship_x = 0;
-
-	inv_x = 20;
-	inv_y = 20;
-	inv_dir = 1;
-	num_alive = INV_ROWS * INV_COLS;
-	for (r = 0; r < INV_ROWS; r++)
-		for (c = 0; c < INV_COLS; c++)
-			alive[r][c] = 1;
-
-	num_bullets = 0;
-	for (c = 0; c < MAX_BULLETS; c++)
-		bullet_active[c] = 0;
-}
-
-void _start(void)
-{
-	unsigned int last_tick;
-	int k;
-	int r, c;
-
-	game_init();
-	last_tick = api->get_ticks_ms();
-
-	for (;;) {
-		int want_left = 0, want_right = 0, want_fire = 0;
-		while (api->get_ticks_ms() - last_tick < FRAME_MS) {
-			k = api->poll_key();
-			if (k == IO_KEY_ESC)
-				return;
-			if (k == IO_KEY_LEFT)
-				want_left = 1;
-			if (k == IO_KEY_RIGHT)
-				want_right = 1;
-			if (k == IO_KEY_SPACE)
-				want_fire = 1;
-		}
-		last_tick = api->get_ticks_ms();
-		if (want_left && ship_x > 0)
-			ship_x -= SHIP_SPEED;
-		if (want_right && ship_x + SHIP_W < (int)fb_w)
-			ship_x += SHIP_SPEED;
-		if (want_fire)
-			spawn_bullet();
-
-		update_bullets();
-		update_invaders();
-
-		api->clear_rgb(8, 8, 32);
-		while ((k = api->poll_key()) != 0) {
-			if (k == IO_KEY_ESC)
-				return;
-			if (k == IO_KEY_LEFT)
-				want_left = 1;
-			if (k == IO_KEY_RIGHT)
-				want_right = 1;
-			if (k == IO_KEY_SPACE)
-				want_fire = 1;
-		}
-		draw_ship();
-		for (r = 0; r < INV_ROWS; r++) {
-			for (c = 0; c < INV_COLS; c++)
-				draw_invader(r, c);
-			while ((k = api->poll_key()) != 0) {
-				if (k == IO_KEY_ESC)
-					return;
-				if (k == IO_KEY_LEFT)
-					want_left = 1;
-				if (k == IO_KEY_RIGHT)
-					want_right = 1;
-				if (k == IO_KEY_SPACE)
-					want_fire = 1;
-			}
-		}
-		draw_bullets();
-
-		if (num_alive <= 0)
-			return;
-		if (inv_y + INV_ROWS * (INV_H + 2) >= (int)fb_h - SHIP_H - 8)
-			return;
-	}
-}

+ 2 - 27
terminal.c

@@ -16,13 +16,9 @@
 
 
 extern void program_reboot_main(void);
 extern void program_reboot_main(void);
 extern void program_poweroff_main(void);
 extern void program_poweroff_main(void);
-extern void program_run_main(const char *filename);
 extern void program_display_main(void);
 extern void program_display_main(void);
 extern void program_gfxbench_main(void);
 extern void program_gfxbench_main(void);
 extern void program_serial_loop_main(const char *arg);
 extern void program_serial_loop_main(const char *arg);
-extern void program_serial_recv_main(const char *arg);
-extern void program_run_serial_main(const char *arg);
-extern void program_run_embedded_main(const char *name);
 extern void program_lsusb_main(void);
 extern void program_lsusb_main(void);
 extern void program_netdev_main(const char *arg);
 extern void program_netdev_main(const char *arg);
 extern void program_format_main(const char *arg);
 extern void program_format_main(const char *arg);
@@ -74,7 +70,6 @@ static int cmd_ps(struct term *t, const char *args);
 static int cmd_renice(struct term *t, const char *args);
 static int cmd_renice(struct term *t, const char *args);
 static int cmd_sched(struct term *t, const char *args);
 static int cmd_sched(struct term *t, const char *args);
 static int cmd_reboot(struct term *t, const char *args);
 static int cmd_reboot(struct term *t, const char *args);
-static int cmd_run(struct term *t, const char *args);
 static int cmd_serial(struct term *t, const char *args);
 static int cmd_serial(struct term *t, const char *args);
 
 
 /* Table order defines the `help` layout (printed as two columns).  Ring-3
 /* Table order defines the `help` layout (printed as two columns).  Ring-3
@@ -82,9 +77,6 @@ static int cmd_serial(struct term *t, const char *args);
 static const struct kcmd cmds[] = {
 static const struct kcmd cmds[] = {
 	{ "help",       "help",                          CK_CUSTOM, CMD_BUILTIN, 0, 0, 0, cmd_help },
 	{ "help",       "help",                          CK_CUSTOM, CMD_BUILTIN, 0, 0, 0, cmd_help },
 	{ "bootlog",    "bootlog",                       CK_CUSTOM, CMD_BUILTIN, 0, 0, 0, cmd_bootlog },
 	{ "bootlog",    "bootlog",                       CK_CUSTOM, CMD_BUILTIN, 0, 0, 0, cmd_bootlog },
-	{ "run",        "run <name>|<file>",             CK_CUSTOM, 0, 0, 0, 0, cmd_run },
-	{ "space",      "space",                         CK_SPAWN, 0, 0, program_run_embedded_main, "space", 0 },
-	{ "prog",       "prog",                          CK_SPAWN, 0, 0, program_run_embedded_main, "prog", 0 },
 	{ "reboot",     "reboot",                        CK_CUSTOM, 0, 0, 0, 0, cmd_reboot },
 	{ "reboot",     "reboot",                        CK_CUSTOM, 0, 0, 0, 0, cmd_reboot },
 	{ "poweroff",   "poweroff",                      CK_CUSTOM, 0, 0, 0, 0, cmd_poweroff },
 	{ "poweroff",   "poweroff",                      CK_CUSTOM, 0, 0, 0, 0, cmd_poweroff },
 	{ "display",    "display",                       CK_SPAWN, 0, program_display_main, 0, 0, 0 },
 	{ "display",    "display",                       CK_SPAWN, 0, program_display_main, 0, 0, 0 },
@@ -104,7 +96,7 @@ static const struct kcmd cmds[] = {
 	{ "kill",       "kill <pid>",                    CK_CUSTOM, 0, 0, 0, 0, cmd_kill },
 	{ "kill",       "kill <pid>",                    CK_CUSTOM, 0, 0, 0, 0, cmd_kill },
 	{ "kexec",      "kexec",                         CK_CUSTOM, 0, 0, 0, 0, cmd_kexec },
 	{ "kexec",      "kexec",                         CK_CUSTOM, 0, 0, 0, 0, cmd_kexec },
 	{ "dbg",        "dbg",                           CK_CUSTOM, 0, 0, 0, 0, cmd_dbg },
 	{ "dbg",        "dbg",                           CK_CUSTOM, 0, 0, 0, 0, cmd_dbg },
-	{ "serial",     "serial test|recv",              CK_CUSTOM, 0, 0, 0, 0, cmd_serial },
+	{ "serial",     "serial test",                   CK_CUSTOM, 0, 0, 0, 0, cmd_serial },
 };
 };
 
 
 #define NCMDS (sizeof(cmds) / sizeof(cmds[0]))
 #define NCMDS (sizeof(cmds) / sizeof(cmds[0]))
@@ -447,20 +439,6 @@ static int cmd_reboot(struct term *t, const char *args)
 	return 0;
 	return 0;
 }
 }
 
 
-static int cmd_run(struct term *t, const char *args)
-{
-	(void)t;
-	if (args[0] == 's' && args[1] == 'e' && args[2] == 'r' &&
-	    args[3] == 'i' && args[4] == 'a' && args[5] == 'l' &&
-	    args[6] == '\0') {
-		if (process_create_arg("run_serial", program_run_serial_main, "serial") < 0)
-			io_putstr("error: too many processes\n");
-	} else {
-		io_putstr("run: not available in windowed mode yet\n");
-	}
-	return 0;
-}
-
 static int cmd_serial(struct term *t, const char *args)
 static int cmd_serial(struct term *t, const char *args)
 {
 {
 	(void)t;
 	(void)t;
@@ -468,11 +446,8 @@ static int cmd_serial(struct term *t, const char *args)
 	    args[4] == '\0') {
 	    args[4] == '\0') {
 		if (process_create_arg("serial_loop", program_serial_loop_main, "test") < 0)
 		if (process_create_arg("serial_loop", program_serial_loop_main, "test") < 0)
 			io_putstr("error: too many processes\n");
 			io_putstr("error: too many processes\n");
-	} else if (args[0] == 'r' && args[1] == 'e' && args[2] == 'c' &&
-		   args[3] == 'v' && args[4] == '\0') {
-		program_serial_recv_main("recv");
 	} else {
 	} else {
-		io_putstr("serial: usage serial test|recv\n");
+		io_putstr("serial: usage serial test\n");
 	}
 	}
 	return 0;
 	return 0;
 }
 }

+ 2 - 2
tty.c

@@ -19,8 +19,8 @@ struct tty {
 _Static_assert(sizeof(struct tty) <= TTY_STRIDE,
 _Static_assert(sizeof(struct tty) <= TTY_STRIDE,
 	       "tty state no longer fits its two-page slot");
 	       "tty state no longer fits its two-page slot");
 
 
-/* The rings are 16 KB of state; keep them out of BSS so the kernel image
- * stays below the run area. */
+/* The rings are 16 KB of state; allocate them from the frame heap instead of
+ * BSS to keep the kernel's low-memory footprint small. */
 static struct tty *ttys;
 static struct tty *ttys;
 static int tty_ready;
 static int tty_ready;
 
 

+ 0 - 12
user.ld

@@ -1,12 +0,0 @@
-/* User program: load at 0x80000, same as run.c PROGRAM_LOAD_ADDR. */
-ENTRY(_start)
-
-SECTIONS
-{
-	. = 0x80000;
-	.text : { *(.text .text.*) }
-	.rodata : { *(.rodata .rodata.*) }
-	.data : { *(.data .data.*) }
-	.bss : { *(.bss .bss.*) *(COMMON) }
-	_end = .;
-}