- Added paging_clone_directory_from(): deep-copies user-space pages so
parent and child have independent memory. Kernel pages are shared.
- Fixed process_fork() to accept registers_t* for accurate child state,
and to clone from the parent's page directory (not the kernel's).
- Refactored process_exit() to properly context-switch to next process
using new process_switch_to_user assembly stub (loads full registers_t
and performs iret), instead of halting unconditionally.
- Fixed sys_waitpid() to use proper blocking: marks process BLOCKED,
invokes scheduler, and resumes with exit code when child dies.
- Added SYSCALL_SWITCHED mechanism to prevent syscall_handler from
clobbering the next process's EAX after a context switch.
- Created fork-test user app that validates fork + waitpid.
- Added docs/fork.md with architecture documentation.
Tested: fork-test creates child, both print messages, parent waits for
child exit (code 7), parent reaps and exits (code 0). hello-world also
verified to still work correctly after the process_exit refactor.
Add complete user-mode process support:
- TSS (tss.c/h): Task State Segment for Ring 3->0 transitions, installed
as GDT entry 5 (selector 0x28). ESP0 updated per-process for kernel
stack switching.
- Process management (process.c/h): Process table with up to 64 processes.
process_create() clones kernel page directory, maps user code at
0x08048000 and user stack at 0xBFFFF000, copies flat binary code.
Round-robin scheduler via schedule_tick() modifies the interrupt frame
in-place for zero-copy context switching.
- System calls (syscall.c/h): INT 0x80 dispatcher with 8 syscalls:
SYS_EXIT, SYS_WRITE (to debug port + VGA), SYS_READ, SYS_FORK,
SYS_GETPID, SYS_YIELD, SYS_WAITPID, SYS_EXEC. IDT gate at 0x80
uses DPL=3 (flags 0xEE) so user code can invoke it.
- Assembly stubs (interrupts.S): isr128 for INT 0x80, tss_flush for
loading the Task Register, enter_usermode for initial iret to Ring 3.
- Paging extensions (paging.c/h): paging_clone_directory() to create
per-process page directories, paging_map_page_in() for mapping into
non-active directories, paging_switch_directory() for CR3 switching.
- GDT expanded from 5 to 6 entries to accommodate TSS descriptor.
gdt_set_gate() exposed in header for TSS initialization.
- ISR handler routes timer IRQ (32) to scheduler and INT 0x80 to
syscall dispatcher. Exception handler now prints EIP/CS/ERR for
debugging.
- Kernel boots a test user program that writes 'Hello from Ring 3!'
via SYS_WRITE and exits with code 42 via SYS_EXIT. Verified working
in QEMU.
Context switching approach: Timer/syscall interrupts save all registers
via the ISR stub. schedule_tick() copies saved_regs between PCBs and
overwrites the interrupt frame, so the existing iret restores the next
process's state without separate switch assembly.
- Created two-level x86 paging (page directory + page tables) with 4 KiB pages.
- Identity maps all detected physical memory in two phases:
1) Static: first 16 MiB using 4 BSS-allocated page tables (avoids
chicken-and-egg with PMM bitmap in BSS).
2) Dynamic: memory above 16 MiB using PMM-allocated page tables,
created before paging is enabled so physical addresses still work.
- Provides kernel heap at 0xD0000000–0xF0000000 for virtual page allocation.
- API: paging_map_page, paging_unmap_page, paging_alloc_page, paging_free_page,
paging_get_physical.
- Added pmm_get_memory_size() to expose detected RAM for paging init.
- Kernel tests paging by allocating a virtual page, writing 0xDEADBEEF, and
reading it back, then freeing it.
- Added documentation in docs/paging.md.
Tested: boots and passes paging test with both 4 MiB and 128 MiB RAM in QEMU.