|
|
@@ -141,8 +141,9 @@ make clean
|
|
|
{wait}`, and `{click:X,Y}` for a left click at canvas coordinates). It needs the multilib `lib32-sdl3`,
|
|
|
`lib32-wayland` and `lib32-libxkbcommon`; host sockets replace the NebOS TCP
|
|
|
stack and the kernel/WM paths are not exercised.
|
|
|
-- QEMU guests default to 1 GB (`QEMU_MEM`, e.g. `make run QEMU_MEM=512M`),
|
|
|
- matching `MM_MAX_PHYS` in `phys.h`; all run and UEFI targets pass `-m`.
|
|
|
+- QEMU guests default to 1 GB (`QEMU_MEM`), the lowmem size (`MM_MAX_PHYS`
|
|
|
+ in `phys.h`); `make run QEMU_MEM=3G` exercises highmem. All run and UEFI
|
|
|
+ targets pass `-m`.
|
|
|
- The command pack is the system rootfs: `cmds.pack` (NBPAK1), gzip-compressed
|
|
|
to `cmds_pack_gz.bin`, wrapped by `mkrootfs` with a one-sector `NBROOT1`
|
|
|
header into `cmds.img` (the 8 MB USB partition image) and `BOOTX64.EFI`.
|
|
|
@@ -249,7 +250,8 @@ and `make net-dev`/`kernel-net-dev` reload over the network. `bootlog save
|
|
|
4. `mbr.S` — MBR (USB/HDD boot); loads the active partition's boot sector
|
|
|
(partition 1 at LBA 63).
|
|
|
5. **UEFI (`boot/efi/`)** — an x86-64 PE32+ `BOOTX64.EFI` loads from the ESP. It
|
|
|
- picks a GOP mode, converts `GetMemoryMap` into the E820 map at `0x1000`,
|
|
|
+ picks a GOP mode, converts `GetMemoryMap` into the E820 map at `0x1000`
|
|
|
+ (all RAM below 4 GB, at most 32 runs),
|
|
|
stages `kernel.bin` below 4 GB, allocates a loader-data buffer below the
|
|
|
1 GB identity window (above the low 1 MB) for the embedded gz rootfs
|
|
|
and copies it there, fills
|
|
|
@@ -353,19 +355,36 @@ it to `0x7E00`. The kernel region itself only has one wall (`_end` below
|
|
|
trampoline at `0x6000`), and `spinlock.h` (the IRQ-safe spinlocks).
|
|
|
`cpu_enable_sse()` runs on every AP: an AP starts with firmware CR4, and the
|
|
|
SSE2 drawing fast paths #UD until OSFXSR/OSXMMEXCPT are set.
|
|
|
-- **Memory**: `phys.h` — the shared 1 GB physical ceiling (`MM_MAX_PHYS`),
|
|
|
- also used by the UEFI loader; it ends where ring-3 space starts
|
|
|
- (`USER_BASE` = `0x40000000`), and `paging.c` statically asserts that the
|
|
|
- identity map never reaches a user window. RAM above 1 GB is ignored (no
|
|
|
- highmem zone or PAE yet). `mm.c/h` — INT 15h E820 detection (real-mode in
|
|
|
- `vesa_stage.S`, map at `0x1000`) + a bitmap page-frame allocator (4 KB
|
|
|
- pages). Reserves low 1 MB and an 8 MB VGA-shadow region. The bitmap is
|
|
|
- sized to the highest E820 RAM address (32 KB at 1 GB) and is not in BSS:
|
|
|
- `mm_init` places it in the first RAM run at or above `0x900000` that
|
|
|
- avoids the boot pack and the LFB and marks its own pages used (a 512-byte
|
|
|
- static array covers the 16 MB no-E820 fallback). Allocation is lowest
|
|
|
- address first: a `first_free` word hint skips the full low words,
|
|
|
- `mm_alloc_page()` finds the bit with `bsf`, and `mm_alloc_pages()` steps
|
|
|
+- **Memory**: `phys.h` — `MM_MAX_PHYS` (1 GB, the lowmem/identity-map
|
|
|
+ ceiling, also used by the UEFI loader for the pack buffer), `MM_KMAP_VA`
|
|
|
+ (`0x4FC00000`) and `MM_HIGH_LIMIT` (4 GB). Lowmem ends where ring-3 space
|
|
|
+ starts (`USER_BASE` = `0x40000000`), and `paging.c` statically asserts that
|
|
|
+ the identity map never reaches a user window. `mm.c/h` — INT 15h E820
|
|
|
+ detection (real-mode in `vesa_stage.S`, map at `0x1000`) + a bitmap
|
|
|
+ page-frame allocator (4 KB pages) over all RAM below 4 GB, in two zones:
|
|
|
+ **lowmem** `[0, 1 GB)` is identity-mapped and serves every kernel
|
|
|
+ allocation (`mm_alloc_page`, `mm_alloc_pages`, `kmalloc`: page tables,
|
|
|
+ DMA buffers, canvases, kernel stacks); **highmem** `[1 GB, 4 GB)` is never
|
|
|
+ identity-mapped and is handed out only by `mm_alloc_user_page()` (highmem
|
|
|
+ first, lowmem fallback) for ring-3 program, stack and heap frames
|
|
|
+ (`elf.c`, `process.c`, `sys_mem.c`). The kernel touches such a frame only
|
|
|
+ through the owning process's mapping or `kmap(phys)`/`kunmap()`
|
|
|
+ (`paging.c`): the 4 MB slot at `MM_KMAP_VA` (in the gap below
|
|
|
+ `USER_WIN_BASE`) has one supervisor page table shared by every process
|
|
|
+ directory, with 4 nesting (LIFO) slots per CPU; a highmem `kmap` disables
|
|
|
+ preemption until `kunmap` and flushes only its local TLB entry, lowmem
|
|
|
+ returns the identity address. Nothing may sleep between them.
|
|
|
+ `paging_map_ram`, `paging_map_mmio_cr3` and the LFB mapping refuse to
|
|
|
+ overwrite the kmap slot. (It is not the last lowmem slot, where firmware
|
|
|
+ puts the ACPI tables, nor the top PDE, where a VBE LFB may sit.) The
|
|
|
+ kernel reserves low 1 MB and an 8 MB VGA-shadow region. The bitmap is
|
|
|
+ sized to the highest E820 RAM address (32 KB at 1 GB, 96 KB at 3 GB) and
|
|
|
+ is not in BSS: `mm_init` places it in the first lowmem RAM run at or above
|
|
|
+ `0x900000` that avoids the boot pack and the LFB and marks its own pages
|
|
|
+ used (a 512-byte static array covers the 16 MB no-E820 fallback); COM1
|
|
|
+ logs `mm: bitmap ... highmem free N MB`. Allocation is lowest address
|
|
|
+ first within a zone: a per-zone first-free word hint skips the full low
|
|
|
+ words, single pages are found with `bsf`, and `mm_alloc_pages()` steps
|
|
|
over full and empty words 32 pages at a time. `kmalloc.c/h` — a power-of-two heap
|
|
|
allocator on top of the frame allocator (used for PCBs and command context).
|
|
|
Process stacks (≥ `0x900000`) come from the frame allocator, with an 8-stack
|
|
|
@@ -1341,7 +1360,10 @@ it to `0x7E00`. The kernel region itself only has one wall (`_end` below
|
|
|
WM top bar and the `powerinfo`/`sensors` commands work on both.
|
|
|
- **Ring-3 address space**: the ELF image and 128 KB (32-page) stack live in
|
|
|
the 4 MB `USER_BASE` (`0x40000000`)..`USER_STACK_TOP` (`0x40400000`)
|
|
|
- window, which is too small for a full-frame image. `SYS_MEM_ALLOC`/`SYS_MEM_GROW`/`SYS_MEM_FREE`
|
|
|
+ window, which is too small for a full-frame image. Their frames, and the
|
|
|
+ heap's, come from highmem when the machine has RAM above 1 GB. The 4 MB
|
|
|
+ slot at `0x4FC00000`, just below `USER_WIN_BASE`, is the kernel's kmap
|
|
|
+ window (supervisor-only). `SYS_MEM_ALLOC`/`SYS_MEM_GROW`/`SYS_MEM_FREE`
|
|
|
(`sys_mem.c/h`) map/grow/delete a single anonymous arena at
|
|
|
`USER_HEAP_BASE` (`0x60000000`), capped at 64 MB (`USER_HEAP_MAX`; the
|
|
|
browser's DOM arenas plus the QuickJS heap need ~30 MB before images); the initial allocation is
|
|
|
@@ -2517,7 +2539,9 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
|
|
|
the in-tree `libc.a` when they need allocation or standard string/stdlib
|
|
|
functions; the `SYS_MEM_*` syscalls are internal to the libc backend.
|
|
|
- **Paging is on but flat** — identity-mapped 4 MB pages (`paging.c`), so
|
|
|
- physical == virtual everywhere. Still no per-process address spaces or process
|
|
|
+ physical == virtual for lowmem (below 1 GB). A frame from
|
|
|
+ `mm_alloc_user_page()` may be highmem: never dereference it by its
|
|
|
+ physical address, use `kmap()`/`kunmap()`. Still no per-process address spaces or process
|
|
|
isolation: everything runs ring-0 and shares the address space.
|
|
|
- **Fresh memory is not zeroed** — `mm_alloc_page`/`kmalloc` hand out whatever
|
|
|
RAM contained; QEMU starts guest RAM cleared, real hardware does not, so a
|
|
|
@@ -2563,11 +2587,16 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
|
|
|
3. No per-process address spaces or process isolation (paging is identity-mapped).
|
|
|
4. FAT32: FSInfo free-count not updated, no directory-chain growth.
|
|
|
5. `disk.c` `fdc_reset()` and `fdc_init_once()` overlap/duplicate logic.
|
|
|
-6. Physical RAM above 1 GB is unused: the identity map stops at `USER_BASE`
|
|
|
- (`0x40000000`). Using it needs a highmem zone (user-only frames plus a
|
|
|
- per-CPU temporary kernel mapping for zeroing/ELF loads) and, for RAM above
|
|
|
- 4 GB, PAE. MMIO is still mapped at its physical address, which also
|
|
|
- blocks growing ring-3 space above the PCI hole.
|
|
|
+6. Highmem limits: RAM above 4 GB is ignored (it would need PAE), and on a
|
|
|
+ 4 GB board the PCI hole leaves ~3-3.5 GB usable. Highmem only backs
|
|
|
+ ring-3 pages, so the 1 GB lowmem zone (kernel structures, canvases,
|
|
|
+ contiguous buffers) can still run out first. One process is still capped
|
|
|
+ by `USER_HEAP_MAX` (64 MB) and the 4 MB image/stack window; raising that
|
|
|
+ needs demand paging and moving MMIO out of the identity layout, which
|
|
|
+ currently maps BARs at their physical address and so blocks ring-3 space
|
|
|
+ near the PCI hole. A BIOS that puts ACPI tables, MMIO or the LFB in the
|
|
|
+ 4 MB kmap slot at `0x4FC00000` cannot have that range identity-mapped
|
|
|
+ (the mappers log `refusing to map over the kmap window`).
|
|
|
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 kernel, plus the privileged ones (`peek`, `poke`, `dbg`, `serial`,
|
|
|
@@ -2650,7 +2679,7 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
|
|
|
`websrv` cannot start while any TCP socket is open. Kill the other
|
|
|
command first.
|
|
|
20. `/share` is RAM only: a reboot/kexec starts empty, and the 16 MB cap is
|
|
|
- charged against the 1 GB identity-mapped window.
|
|
|
+ charged against the 1 GB lowmem zone.
|
|
|
|
|
|
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
|