]> Projects (at) Tadryanom (dot) Me - AdrOS.git/log
AdrOS.git
7 weeks agofeat: add ulibc — minimal userspace C library
Tulio A M Mendes [Tue, 10 Feb 2026 07:19:46 +0000 (04:19 -0300)]
feat: add ulibc — minimal userspace C library

Create user/ulibc/ with headers and implementations for:
- crt0.S: _start entry point that calls main() then exit()
- syscall.h: raw INT 0x80 wrappers (_syscall0..5)
- unistd.c/h: POSIX wrappers (read, write, open, close, fork,
  execve, pipe, dup2, brk, getpid, chdir, mkdir, etc)
- string.c/h: memcpy, memset, memmove, strlen, strcmp, strcpy,
  strchr, strcat, etc
- stdlib.c/h: malloc/free (bump allocator via brk), calloc,
  realloc, atoi, exit
- stdio.c/h: printf, puts, putchar, snprintf, vsnprintf with
  format specifiers: %d %i %u %x %X %s %c %p %%
- errno.c/h: errno variable + error codes + __syscall_ret helper

Build system: user/ulibc/Makefile produces libulibc.a static lib.
Main Makefile updated with ULIBC_LIB target.

Future user programs can link against libulibc.a instead of
duplicating syscall wrappers inline.

Passes: make (kernel), ulibc builds clean, QEMU smoke test OK.

7 weeks agofeat: implement SYSENTER/SYSEXIT fast syscall entry for x86-32
Tulio A M Mendes [Tue, 10 Feb 2026 07:07:14 +0000 (04:07 -0300)]
feat: implement SYSENTER/SYSEXIT fast syscall entry for x86-32

Add fast syscall support via SYSENTER/SYSEXIT (SEP), ~10x faster
than INT 0x80 (~30 cycles vs ~300 cycles overhead).

Components:
- src/arch/x86/sysenter.S: assembly entry point that builds a
  struct registers frame compatible with existing syscall_handler()
- src/arch/x86/sysenter_init.c: MSR setup (0x174=CS, 0x175=ESP,
  0x176=EIP), CPUID check for SEP support
- syscall_handler() made non-static so assembly can call it
- tss_set_kernel_stack() now also updates SYSENTER ESP MSR so
  context switches keep the fast path working

Userspace convention:
  push ecx; push edx; push $return; mov esp,ecx; sysenter
  EAX=syscall_no, EBX=arg1, ECX=arg2, EDX=arg3, ESI=arg4, EDI=arg5

INT 0x80 remains as fallback for CPUs without SEP.
QEMU confirms: [SYSENTER] Fast syscall enabled.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofeat: improve spinlock with per-arch cpu_relax() and memory barriers
Tulio A M Mendes [Tue, 10 Feb 2026 06:57:43 +0000 (03:57 -0300)]
feat: improve spinlock with per-arch cpu_relax() and memory barriers

Spinlock improvements for SMP readiness:
- Add cpu_relax() with per-arch spin-wait hints:
  x86: PAUSE, ARM/AArch64: YIELD, RISC-V: FENCE, MIPS: PAUSE
- Add __sync_synchronize() barrier before lock release in spin_unlock
- Add spin_is_locked() debug helper
- Add spin_trylock() for non-blocking lock attempts
- TTAS (test-and-test-and-set) pattern with cpu_relax() in inner loop
- __sync_lock_test_and_set maps to XCHG (x86), LDREX/STREX (ARM),
  AMOSWAP.W.AQ (RISC-V), LL/SC (MIPS)

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofeat: implement CPUID feature detection + HAL wrapper
Tulio A M Mendes [Tue, 10 Feb 2026 06:53:50 +0000 (03:53 -0300)]
feat: implement CPUID feature detection + HAL wrapper

Add x86 CPUID detection (src/arch/x86/cpuid.c) that queries:
- Leaf 0: vendor string, max leaf
- Leaf 1: feature flags (PAE, NX, APIC, SEP, SSE, SSE2, HTT, etc)
- Leaf 1 EBX: topology (APIC ID, logical CPUs)
- Extended leaves: NX, Long Mode, SYSCALL, brand string

HAL wrapper (include/hal/cpu_features.h):
- hal_cpu_detect_features() / hal_cpu_get_features() / hal_cpu_print_features()
- x86 impl in src/hal/x86/cpu_features.c
- Weak default stub in src/kernel/cpu_features.c

Called from kernel_main() right after console_init().
QEMU output: GenuineIntel, PAE APIC SEP SSE SSE2 FXSR HYPERVISOR.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: remove dead shell.c, integrate commands into kconsole
Tulio A M Mendes [Tue, 10 Feb 2026 06:27:16 +0000 (03:27 -0300)]
refactor: remove dead shell.c, integrate commands into kconsole

shell.c became dead code after kconsole_enter() replaced shell_init()
as the fallback when init_start() fails. Nobody called shell_init().

- Integrate useful shell commands into kconsole: ls, cat, clear,
  mem, sleep, ring3 (via arch_platform_usermode_test_start)
- Remove src/kernel/shell.c and include/shell.h
- Remove shell.h include from main.c
- kconsole is now the single kernel-mode interactive console

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: move x86 uaccess page table walking to src/arch/x86/uaccess.c
Tulio A M Mendes [Tue, 10 Feb 2026 06:19:36 +0000 (03:19 -0300)]
refactor: move x86 uaccess page table walking to src/arch/x86/uaccess.c

The uaccess implementation used x86-specific recursive page table
mapping (0xFFFFF000/0xFFC00000) for user_range_ok, copy_from_user,
copy_to_user, and uaccess_try_recover. This is 100% arch-dependent.

- Move full x86 implementation to src/arch/x86/uaccess.c (no guards)
- Replace src/kernel/uaccess.c with weak stubs (simple memcpy-based)
- The linker picks the arch-specific version when available

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: make pmm.c fully architecture-independent
Tulio A M Mendes [Tue, 10 Feb 2026 06:13:16 +0000 (03:13 -0300)]
refactor: make pmm.c fully architecture-independent

Extract all Multiboot2 x86-specific code from src/mm/pmm.c into
src/arch/x86/pmm_boot.c as pmm_arch_init().

Design:
- pmm.h now exposes pmm_mark_region(), pmm_set_limits(), pmm_arch_init()
- pmm_init() calls pmm_arch_init() (arch-specific) which discovers
  memory and calls pmm_set_limits() + pmm_mark_region()
- pmm.c provides a weak default pmm_arch_init() for archs without one
- Kernel protection uses hal_mm_virt_to_phys() (no #if MIPS/x86)
- x86 pmm_boot.c handles Multiboot2 parsing, module protection,
  and boot info protection
- Zero #if guards remain in pmm.c

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofeat: implement kconsole — kernel emergency console (like HelenOS kconsole)
Tulio A M Mendes [Tue, 10 Feb 2026 06:01:02 +0000 (03:01 -0300)]
feat: implement kconsole — kernel emergency console (like HelenOS kconsole)

When VFS mount or init fails, AdrOS now enters a minimal kernel-mode
emergency console instead of the full shell. This is similar to
HelenOS's kconsole — it runs entirely in kernel mode and provides
basic diagnostic commands.

Design:
- kconsole_enter() runs a blocking read loop using kgetc()/kprintf()
- Commands: help, dmesg, reboot, halt
- Activated from kernel_main() when init_start() returns < 0
- Fully architecture-independent (uses only generic console API)

The normal shell remains available for userspace-initiated sessions.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofeat: add kgetc() to console subsystem for kernel input
Tulio A M Mendes [Tue, 10 Feb 2026 05:56:54 +0000 (02:56 -0300)]
feat: add kgetc() to console subsystem for kernel input

kgetc() reads a single character via keyboard_read_blocking(),
providing a symmetric API alongside kprintf() for output.
This enables the kernel console (and future kconsole) to have
a generic input mechanism independent of architecture.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: remove #if x86 guard from scheduler fork_child_trampoline
Tulio A M Mendes [Tue, 10 Feb 2026 05:53:40 +0000 (02:53 -0300)]
refactor: remove #if x86 guard from scheduler fork_child_trampoline

Add hal_usermode_enter_regs() to the HAL usermode interface so
fork_child_trampoline() can call it generically without #if x86.

- Add declaration to include/hal/usermode.h
- Implement in src/hal/x86/usermode.c (calls x86_enter_usermode_regs)
- Add stubs in ARM, RISC-V, MIPS HAL usermode.c
- scheduler.c now uses hal_usermode_enter_regs() with no guards

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: remove all #if x86 guards from shell.c, migrate to kprintf + HAL
Tulio A M Mendes [Tue, 10 Feb 2026 05:47:20 +0000 (02:47 -0300)]
refactor: remove all #if x86 guards from shell.c, migrate to kprintf + HAL

shell.c is generic kernel code and should not contain any
architecture-specific guards or inline assembly.

Changes:
- Replace all uart_print() calls with kprintf() so output goes
  through the console subsystem and into the kernel log buffer
- Replace x86 'cli; ud2' panic asm with hal_cpu_disable_interrupts()
  + hal_cpu_idle() loop
- Replace #if x86 ring3 guard with arch_platform_usermode_test_start()
  which is already a generic wrapper with per-arch implementations
- Use console_write() for echo/backspace (no log buffer pollution)
- Remove unnecessary uart_console.h and vga_console.h includes

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: move x86 ATA PIO driver from src/drivers/ata_pio.c to src/hal/x86/ata_pio.c
Tulio A M Mendes [Tue, 10 Feb 2026 05:42:24 +0000 (02:42 -0300)]
refactor: move x86 ATA PIO driver from src/drivers/ata_pio.c to src/hal/x86/ata_pio.c

ATA PIO uses x86 I/O port instructions (inb/outb/inw/outw) for
disk access. The full implementation now lives in src/hal/x86/ata_pio.c
(no #if guards). src/drivers/ata_pio.c contains only weak stubs
returning -ENOSYS, overridden at link time for x86.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: move x86 PCI driver from src/drivers/pci.c to src/hal/x86/pci.c
Tulio A M Mendes [Tue, 10 Feb 2026 05:37:31 +0000 (02:37 -0300)]
refactor: move x86 PCI driver from src/drivers/pci.c to src/hal/x86/pci.c

PCI config space access via I/O ports 0xCF8/0xCFC is x86-specific.
The full PCI enumeration implementation now lives in src/hal/x86/pci.c
(no #if guards). src/drivers/pci.c contains only weak stubs that are
overridden by the arch-specific version at link time.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: move x86 ELF loader from src/kernel/elf.c to src/arch/x86/elf.c
Tulio A M Mendes [Tue, 10 Feb 2026 05:32:41 +0000 (02:32 -0300)]
refactor: move x86 ELF loader from src/kernel/elf.c to src/arch/x86/elf.c

The ELF loader uses x86-specific page table manipulation (recursive
mapping at 0xFFFFF000/0xFFC00000), EM_386 validation, and low-16MB
allocation. It is 100% architecture-dependent and should not live
in the generic kernel directory.

- Move full implementation to src/arch/x86/elf.c (no #if guards)
- Replace src/kernel/elf.c with a weak stub returning -1
- The linker picks the arch-specific version when available

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: remove include/multiboot2.h wrapper, use arch/x86/multiboot2.h directly
Tulio A M Mendes [Tue, 10 Feb 2026 05:26:38 +0000 (02:26 -0300)]
refactor: remove include/multiboot2.h wrapper, use arch/x86/multiboot2.h directly

The generic wrapper include/multiboot2.h only forwarded to
arch/x86/multiboot2.h under #if x86. Since Multiboot2 is purely
x86/GRUB-specific, the wrapper should not exist in the generic
include/ directory. pmm.c now includes arch/x86/multiboot2.h
directly (already inside its own #if x86 guard).

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: replace hardcoded 0xC0000000 in elf.c and uaccess.c with hal_mm_kernel_virt...
Tulio A M Mendes [Tue, 10 Feb 2026 05:01:18 +0000 (02:01 -0300)]
refactor: replace hardcoded 0xC0000000 in elf.c and uaccess.c with hal_mm_kernel_virt_base()

Both elf.c and uaccess.c had X86_KERNEL_VIRT_BASE defined as
0xC0000000U inside #if x86 blocks. While technically correct
(only compiled on x86), this is inconsistent with the rest of the
codebase which now uses hal_mm_kernel_virt_base() everywhere.

Replace with the HAL abstraction for consistency and to ensure
the kernel virtual base is defined in exactly one place per arch.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: replace x86 'cli; hlt' asm in syscall.c with HAL calls
Tulio A M Mendes [Tue, 10 Feb 2026 04:58:10 +0000 (01:58 -0300)]
fix: replace x86 'cli; hlt' asm in syscall.c with HAL calls

syscall.c used raw x86 inline assembly ('cli; hlt') in the exit
syscall idle loop. This would not compile on ARM/RISC-V/MIPS.

Add hal_cpu_disable_interrupts() to the HAL CPU interface with
implementations for x86 (cli) and stubs for other architectures.
Replace the raw asm with hal_cpu_disable_interrupts() + hal_cpu_idle().

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofeat: add dmesg command to kernel shell
Tulio A M Mendes [Tue, 10 Feb 2026 04:55:15 +0000 (01:55 -0300)]
feat: add dmesg command to kernel shell

Reads the kernel log ring buffer via klog_read() and prints it
to the UART console, allowing users to review boot messages and
earlier kprintf output — just like Linux's dmesg command.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofeat: add kernel log ring buffer to kprintf (printk-style dmesg support)
Tulio A M Mendes [Tue, 10 Feb 2026 04:53:00 +0000 (01:53 -0300)]
feat: add kernel log ring buffer to kprintf (printk-style dmesg support)

Like Linux's printk, kprintf() now writes every formatted message
into a 16KB circular ring buffer (klog_buf) before dispatching to
console drivers (UART, VGA). This allows old messages to be
retrieved later via klog_read(), enabling dmesg functionality.

Design:
- 16KB static ring buffer (KLOG_BUF_SIZE)
- klog_head tracks next write position, klog_count tracks fill
- klog_append() writes into ring, capping at buffer size
- klog_read(out, size) copies oldest-to-newest into caller buffer
- Protected by dedicated klog_lock spinlock

Flow: kprintf() -> kvsnprintf() -> klog_append() -> console_write()

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: replace x86 bsf asm in scheduler with portable __builtin_ctz
Tulio A M Mendes [Tue, 10 Feb 2026 04:50:27 +0000 (01:50 -0300)]
fix: replace x86 bsf asm in scheduler with portable __builtin_ctz

bsf32() used x86-only 'bsf' inline assembly to find the lowest
set bit in the O(1) scheduler bitmap. This would not compile on
ARM/RISC-V/MIPS. Replace with __builtin_ctz() which GCC supports
on all target architectures.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: x86 code uses arch-specific headers directly
Tulio A M Mendes [Tue, 10 Feb 2026 04:33:15 +0000 (01:33 -0300)]
refactor: x86 code uses arch-specific headers directly

arch_early_setup.c now includes arch/x86/multiboot2.h directly
instead of the generic wrapper, consistent with the pattern of
x86-only code using arch-specific headers.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: guard multiboot2.h include in pmm.c with #if x86
Tulio A M Mendes [Tue, 10 Feb 2026 04:30:39 +0000 (01:30 -0300)]
refactor: guard multiboot2.h include in pmm.c with #if x86

multiboot2.h is an x86/GRUB boot protocol header. pmm.c (generic
mm/ code) included it unconditionally even though all Multiboot2
usage is already inside #if x86 blocks. Guard the include so it
is not pulled in on ARM/RISC-V/MIPS builds.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agorefactor: move gdt.h/idt.h out of generic include/ into arch-specific paths
Tulio A M Mendes [Tue, 10 Feb 2026 04:27:48 +0000 (01:27 -0300)]
refactor: move gdt.h/idt.h out of generic include/ into arch-specific paths

gdt.h and idt.h are x86-only concepts (Global Descriptor Table,
Interrupt Descriptor Table) that do not exist on ARM/RISC-V/MIPS.
They should not live in the generic include/ directory.

Changes:
- Delete include/gdt.h wrapper; all 3 consumers (arch/x86/ and
  hal/x86/) now include arch/x86/gdt.h directly.
- Delete include/idt.h wrapper; create include/interrupts.h as
  the generic abstraction (provides struct registers + isr_handler_t
  with arch-specific dispatch).
- Generic kernel code (syscall.c, uaccess.c, process.h) now
  includes interrupts.h instead of idt.h.
- x86-only code (idt.c, timer HAL, keyboard HAL, usermode, etc.)
  now includes arch/x86/idt.h directly.
- Remove unused idt.h and io.h includes from kernel/main.c.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: implement VGA text-mode scrolling instead of wrap-to-row-0
Tulio A M Mendes [Tue, 10 Feb 2026 04:14:19 +0000 (01:14 -0300)]
fix: implement VGA text-mode scrolling instead of wrap-to-row-0

When the cursor reached the bottom of the 25-row VGA text buffer,
term_row was reset to 0, overwriting the top of the screen. This
made boot output unreadable once it exceeded 25 lines.

Add vga_scroll() that shifts all rows up by one and clears the
last row. Called from both vga_put_char and vga_print.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: implement real irq_save/irq_restore for ARM, RISC-V, MIPS
Tulio A M Mendes [Tue, 10 Feb 2026 04:12:07 +0000 (01:12 -0300)]
fix: implement real irq_save/irq_restore for ARM, RISC-V, MIPS

spinlock.h had no-op irq_save/irq_restore for non-x86 architectures,
meaning spin_lock_irqsave would not actually disable interrupts on
ARM, RISC-V, or MIPS — breaking all critical sections.

Add proper implementations:
- ARM: mrs/msr CPSR with cpsid i
- RISC-V: csrrci/csrsi mstatus MIE bit
- MIPS: mfc0/di/ei on CP0 Status IE bit

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: replace hardcoded 0xC0000000 in pmm.c with hal_mm_kernel_virt_base()
Tulio A M Mendes [Tue, 10 Feb 2026 04:09:56 +0000 (01:09 -0300)]
fix: replace hardcoded 0xC0000000 in pmm.c with hal_mm_kernel_virt_base()

pmm.c used raw 0xC0000000 to detect higher-half kernel and adjust
physical addresses. Replace with hal_mm_kernel_virt_base() so the
PMM works correctly on architectures with different kernel virtual
base addresses.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: replace hardcoded 0xC0000000 in syscall.c with hal_mm_kernel_virt_base()
Tulio A M Mendes [Tue, 10 Feb 2026 04:08:02 +0000 (01:08 -0300)]
fix: replace hardcoded 0xC0000000 in syscall.c with hal_mm_kernel_virt_base()

sys_brk and mmap used hardcoded 0xC0000000U (x86 kernel virtual
base) for bounds checking. Replace with hal_mm_kernel_virt_base()
so the code is architecture-independent.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: wrap pci.c in #if x86 guard with stubs for other architectures
Tulio A M Mendes [Tue, 10 Feb 2026 04:05:52 +0000 (01:05 -0300)]
fix: wrap pci.c in #if x86 guard with stubs for other architectures

PCI config space I/O port access (0xCF8/0xCFC) using outl/inl is
x86-only. The driver had no architecture guard, so it would fail
to compile on ARM, RISC-V, and MIPS.

Wrap the full implementation in #if defined(__i386__) and provide
no-op stubs for non-x86 targets.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: replace hardcoded 0xC0000000 in slab.c with hal_mm_phys_to_virt()
Tulio A M Mendes [Tue, 10 Feb 2026 04:04:05 +0000 (01:04 -0300)]
fix: replace hardcoded 0xC0000000 in slab.c with hal_mm_phys_to_virt()

slab.c used 'base + 0xC0000000U' to convert physical to virtual
addresses, which is x86 higher-half specific. This breaks on ARM,
RISC-V, and MIPS where the kernel virtual base differs.

Add hal_mm_phys_to_virt(), hal_mm_virt_to_phys(), and
hal_mm_kernel_virt_base() to the HAL mm interface with proper
implementations for x86 (0xC0000000 offset) and identity-mapped
stubs for ARM, RISC-V, MIPS.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: move VBE framebuffer VA from 0xD0000000 to 0xE0000000
Tulio A M Mendes [Tue, 10 Feb 2026 04:01:02 +0000 (01:01 -0300)]
fix: move VBE framebuffer VA from 0xD0000000 to 0xE0000000

The kernel heap starts at KHEAP_START=0xD0000000 and spans 10MB.
The VBE framebuffer was also mapped at 0xD0000000, causing a
virtual address collision that would corrupt the heap when a
framebuffer is present.

Move VBE mapping to 0xE0000000 which is safely above the heap.

Passes: make, cppcheck, QEMU smoke test.

7 weeks agofix: add rq_enqueue on wake in keyboard, tty, pty drivers
Tulio A M Mendes [Tue, 10 Feb 2026 03:59:11 +0000 (00:59 -0300)]
fix: add rq_enqueue on wake in keyboard, tty, pty drivers

keyboard.c, tty.c, pty.c all transition processes from BLOCKED to
READY without enqueuing them into the O(1) scheduler runqueue.
This causes woken processes to be invisible to rq_pick_next(),
leading to starvation until the active/expired swap rescues them.

Add sched_enqueue_ready() public API in scheduler.c and call it
from all three wake sites.

Passes: make, cppcheck, QEMU smoke test (10s, all init tests OK).

7 weeks agoPOSIX Tiers 1-3: signals, brk/sbrk, nanosleep, raw TTY, O_CLOEXEC, PMM refcount,...
Tulio A M Mendes [Tue, 10 Feb 2026 03:42:56 +0000 (00:42 -0300)]
POSIX Tiers 1-3: signals, brk/sbrk, nanosleep, raw TTY, O_CLOEXEC, PMM refcount, CoW fork, mmap/munmap, procfs, slab allocator, O(1) scheduler, PCI enumeration, VBE framebuffer

Tier 1:
- Signal characters (Ctrl+C/Z/\ -> SIGINT/SIGTSTP/SIGQUIT) in TTY/PTY
- brk/sbrk syscall with ELF loader heap break support
- nanosleep/clock_gettime syscalls (tick-based)
- Raw TTY mode (non-canonical) + ISIG flag + TIOCGWINSZ/TIOCSWINSZ

Tier 2:
- O_CLOEXEC/FD_CLOEXEC: per-FD flags, fcntl F_GETFD/F_SETFD, close on execve
- PMM ref-counting (uint16_t per-frame, atomic ops)
- Copy-on-Write fork: PTE bit 9 COW marker, page fault handler, vmm_as_clone_user_cow
- mmap/munmap: anonymous MAP_PRIVATE, per-process VMA tracker (32 slots)
- /proc filesystem: /proc/self/status, /proc/uptime, /proc/meminfo

Tier 3:
- Slab allocator: free-list-in-place, per-cache spinlock, auto-grow
- O(1) scheduler: 32-priority bitmap + active/expired runqueue swap
- PCI enumeration: bus/slot/func scan, vendor/device/class/BAR/IRQ
- VBE framebuffer: multiboot2 tag parsing, kernel VA mapping, pixel ops

All changes pass: make clean && make, cppcheck --enable=warning,performance,portability, and QEMU smoke test (10s stable boot, all init tests pass).

7 weeks agofix: heap coalesce early-return, process_create_kernel leak, pipe double-free, path...
Tulio A M Mendes [Tue, 10 Feb 2026 02:35:38 +0000 (23:35 -0300)]
fix: heap coalesce early-return, process_create_kernel leak, pipe double-free, path '..' resolution

7 weeks agodocs: update README, BUILD_GUIDE, and POSIX_ROADMAP to reflect current state
Tulio A M Mendes [Tue, 10 Feb 2026 02:16:07 +0000 (23:16 -0300)]
docs: update README, BUILD_GUIDE, and POSIX_ROADMAP to reflect current state

7 weeks agoposix: generic readdir/getdents across all VFS (tmpfs, devfs, overlayfs, diskfs)
Tulio A M Mendes [Tue, 10 Feb 2026 02:04:53 +0000 (23:04 -0300)]
posix: generic readdir/getdents across all VFS (tmpfs, devfs, overlayfs, diskfs)

7 weeks agoposix: add rename and rmdir syscalls (diskfs)
Tulio A M Mendes [Tue, 10 Feb 2026 01:56:35 +0000 (22:56 -0300)]
posix: add rename and rmdir syscalls (diskfs)

7 weeks agoposix: add openat, fstatat, unlinkat syscalls (AT_FDCWD)
Tulio A M Mendes [Tue, 10 Feb 2026 01:50:22 +0000 (22:50 -0300)]
posix: add openat, fstatat, unlinkat syscalls (AT_FDCWD)

7 weeks agoposix: add pipe2 and dup3 syscalls
Tulio A M Mendes [Tue, 10 Feb 2026 01:37:59 +0000 (22:37 -0300)]
posix: add pipe2 and dup3 syscalls

7 weeks agoposix: add chdir/getcwd and relative path resolution
Tulio A M Mendes [Tue, 10 Feb 2026 01:21:12 +0000 (22:21 -0300)]
posix: add chdir/getcwd and relative path resolution

7 weeks agoposix: add fcntl(F_SETFL) O_NONBLOCK for pipes and tty/pty
Tulio A M Mendes [Tue, 10 Feb 2026 01:12:20 +0000 (22:12 -0300)]
posix: add fcntl(F_SETFL) O_NONBLOCK for pipes and tty/pty

7 weeks agouser: add isatty smoke test via TCGETS
Tulio A M Mendes [Tue, 10 Feb 2026 01:01:09 +0000 (22:01 -0300)]
user: add isatty smoke test via TCGETS

7 weeks agovfs: add getdents syscall for diskfs directories
Tulio A M Mendes [Tue, 10 Feb 2026 00:54:17 +0000 (21:54 -0300)]
vfs: add getdents syscall for diskfs directories

7 weeks agodiskfs: add mkdir/unlink syscalls
Tulio A M Mendes [Tue, 10 Feb 2026 00:41:56 +0000 (21:41 -0300)]
diskfs: add mkdir/unlink syscalls

7 weeks agodiskfs: add hierarchical directories and migrate v2 layout
Tulio A M Mendes [Tue, 10 Feb 2026 00:32:53 +0000 (21:32 -0300)]
diskfs: add hierarchical directories and migrate v2 layout

7 weeks agopersistfs: back /persist/counter by diskfs
Tulio A M Mendes [Tue, 10 Feb 2026 00:23:15 +0000 (21:23 -0300)]
persistfs: back /persist/counter by diskfs

7 weeks agodiskfs: add minimal on-disk filesystem mounted at /disk
Tulio A M Mendes [Tue, 10 Feb 2026 00:11:50 +0000 (21:11 -0300)]
diskfs: add minimal on-disk filesystem mounted at /disk

7 weeks agouaccess: recover from kernel page faults during copy_*_user
Tulio A M Mendes [Tue, 10 Feb 2026 00:02:00 +0000 (21:02 -0300)]
uaccess: recover from kernel page faults during copy_*_user

7 weeks agopty: add minimal /dev/ptmx and /dev/pts/0
Tulio A M Mendes [Mon, 9 Feb 2026 23:41:42 +0000 (20:41 -0300)]
pty: add minimal /dev/ptmx and /dev/pts/0

7 weeks agosignal: add SA_SIGINFO and sigaction ABI
Tulio A M Mendes [Mon, 9 Feb 2026 23:25:14 +0000 (20:25 -0300)]
signal: add SA_SIGINFO and sigaction ABI

7 weeks agox86: deliver SIGSEGV on user page faults
Tulio A M Mendes [Mon, 9 Feb 2026 22:57:17 +0000 (19:57 -0300)]
x86: deliver SIGSEGV on user page faults

7 weeks agouser: add errno-based syscall wrappers
Tulio A M Mendes [Mon, 9 Feb 2026 22:46:39 +0000 (19:46 -0300)]
user: add errno-based syscall wrappers

7 weeks agotools: avoid host macro collisions in user init (cppcheck)
Tulio A M Mendes [Mon, 9 Feb 2026 22:40:42 +0000 (19:40 -0300)]
tools: avoid host macro collisions in user init (cppcheck)

7 weeks agodocs: update POSIX roadmap with sigreturn
Tulio A M Mendes [Mon, 9 Feb 2026 22:31:03 +0000 (19:31 -0300)]
docs: update POSIX roadmap with sigreturn

7 weeks agox86: add sigreturn trampoline and fix execve stack usage
Tulio A M Mendes [Mon, 9 Feb 2026 20:59:27 +0000 (17:59 -0300)]
x86: add sigreturn trampoline and fix execve stack usage

Implement SYSCALL_SIGRETURN and userland signal trampoline/sigframe so handlers can return safely.
Fix x86 signal delivery stack layout to avoid clobbering sigframe/trampoline.
Fix execve heap corruption by avoiding large on-stack argv/envp buffers and adding cleanup.
Add init.elf smoke test for sigreturn.

8 weeks agodocs: update POSIX roadmap and persistence notes
Tulio A M Mendes [Sun, 8 Feb 2026 11:08:52 +0000 (08:08 -0300)]
docs: update POSIX roadmap and persistence notes

8 weeks agostorage: add ATA PIO + persistfs mounted at /persist
Tulio A M Mendes [Sun, 8 Feb 2026 10:51:54 +0000 (07:51 -0300)]
storage: add ATA PIO + persistfs mounted at /persist

8 weeks agotty: add basic job control (fg pgrp) + SIGTTIN/SIGTTOU
Tulio A M Mendes [Sun, 8 Feb 2026 10:49:56 +0000 (07:49 -0300)]
tty: add basic job control (fg pgrp) + SIGTTIN/SIGTTOU

8 weeks agox86/vmm+elf: fix user ELF mapping and PT access
Tulio A M Mendes [Sun, 8 Feb 2026 10:29:50 +0000 (07:29 -0300)]
x86/vmm+elf: fix user ELF mapping and PT access

8 weeks agocppcheck: const cleanups (full vfs api)
Tulio A M Mendes [Sun, 8 Feb 2026 07:24:04 +0000 (04:24 -0300)]
cppcheck: const cleanups (full vfs api)

8 weeks agocppcheck: const cleanups (partial)
Tulio A M Mendes [Sun, 8 Feb 2026 07:14:56 +0000 (04:14 -0300)]
cppcheck: const cleanups (partial)

8 weeks agox86: fix fork addr_space clone; add tty ioctl + session/pgrp syscalls
Tulio A M Mendes [Sun, 8 Feb 2026 07:01:01 +0000 (04:01 -0300)]
x86: fix fork addr_space clone; add tty ioctl + session/pgrp syscalls

- fork clones from active CR3 and returns correct pid
- vmm_as_clone_user copies user pages via per-AS tmp mapping
- tty: implement ioctl (termios + pgrp) and ICANON/ECHO handling
- add setsid/setpgid/getpgrp syscalls + init.elf smoke tests
- overlayfs: fix cppcheck knownConditionTrueFalse

8 weeks agoposix: add select() syscall (minimal)
Tulio A M Mendes [Sun, 8 Feb 2026 04:07:46 +0000 (01:07 -0300)]
posix: add select() syscall (minimal)

Add a minimal select() syscall implemented as a wrapper over poll(). Uses uint64_t read/write fd masks (nfds<=64), timeout semantics aligned with poll, and a userland smoke test with a pipe.

8 weeks agox86: treat user page fault as SIGSEGV
Tulio A M Mendes [Sun, 8 Feb 2026 03:56:13 +0000 (00:56 -0300)]
x86: treat user page fault as SIGSEGV

Handle ISR14 page faults from ring3 by terminating the current process with a SIGSEGV-like status (128+11) instead of kernel panic. Add userland smoke test that triggers a NULL write and validates waitpid status.

8 weeks agoposix: add kill(SIGKILL) syscall
Tulio A M Mendes [Sun, 8 Feb 2026 03:53:48 +0000 (00:53 -0300)]
posix: add kill(SIGKILL) syscall

Introduce a minimal kill(pid,sig) syscall with SIGKILL support. Implement process_kill() to mark target as zombie, close its FDs with refcounting, and wake a waiting parent. Add ESRCH and a userland init.elf smoke test.

8 weeks agoposix: poll syscall (pipes + devfs tty/null)
Tulio A M Mendes [Sun, 8 Feb 2026 03:31:57 +0000 (00:31 -0300)]
posix: poll syscall (pipes + devfs tty/null)

Add a minimal poll() syscall (POLLIN/POLLOUT) with timeout semantics (0 non-blocking, <0 blocking). Support pipe endpoints and devfs char devices (/dev/null,/dev/tty) and add userland smoke tests.

8 weeks agodocs: update POSIX/Unix status (errno, devfs, getppid, WNOHANG)
Tulio A M Mendes [Sun, 8 Feb 2026 03:15:54 +0000 (00:15 -0300)]
docs: update POSIX/Unix status (errno, devfs, getppid, WNOHANG)

Document recently implemented Unix/POSIX features: getppid, waitpid(WNOHANG), devfs (/dev/null,/dev/tty), kernel -errno convention, and uaccess hardening.

8 weeks agoposix: standardize -errno in VFS/tmpfs/initrd
Tulio A M Mendes [Sun, 8 Feb 2026 03:12:50 +0000 (00:12 -0300)]
posix: standardize -errno in VFS/tmpfs/initrd

Replace remaining -1 style returns in core helpers used by syscalls and early init with negative errno codes (vfs_mount, tmpfs_add_file/mkdir_p, initrd alloc/path helpers). Add missing errno constants (EEXIST/ENOTDIR/ENOSPC).

8 weeks agoposix: remove -1 returns from ELF loader
Tulio A M Mendes [Sun, 8 Feb 2026 03:08:41 +0000 (00:08 -0300)]
posix: remove -1 returns from ELF loader

Convert elf32 loader helpers to return -errno codes (EINVAL/ENOMEM/ENOENT/EIO/EFAULT) instead of -1, aligning with kernel-wide -errno syscall convention.

8 weeks agoposix: tighten uaccess + errno helpers
Tulio A M Mendes [Sun, 8 Feb 2026 03:01:39 +0000 (00:01 -0300)]
posix: tighten uaccess + errno helpers

Return proper -errno from remaining syscall helpers (pipe/fd allocation) and harden copy_to_user to require writable user mappings on x86. copy_{to,from}_user now return -EFAULT on invalid ranges.

8 weeks agoposix: devfs with /dev/null and /dev/tty
Tulio A M Mendes [Sun, 8 Feb 2026 02:55:41 +0000 (23:55 -0300)]
posix: devfs with /dev/null and /dev/tty

Add a minimal devfs mounted at /dev providing /dev/null and /dev/tty char devices. Implement tty_read_kbuf/tty_write_kbuf to support VFS-backed tty IO and allow open/read/write through FS_CHARDEVICE nodes. Add userland smoke tests.

8 weeks agoposix: standardize -errno returns
Tulio A M Mendes [Sun, 8 Feb 2026 02:46:46 +0000 (23:46 -0300)]
posix: standardize -errno returns

Adopt negative errno return convention across waitpid/open/fd_close and TTY read/write, add missing errno constants, and return ENOSYS for unknown syscalls.

8 weeks agoposix: getppid syscall
Tulio A M Mendes [Sun, 8 Feb 2026 02:37:16 +0000 (23:37 -0300)]
posix: getppid syscall

Add SYSCALL_GETPPID and userland wrappers. Include a simple fork-based smoke test validating getppid() in init.elf.

8 weeks agofix: prevent fork clone stack overflow
Tulio A M Mendes [Sun, 8 Feb 2026 02:37:06 +0000 (23:37 -0300)]
fix: prevent fork clone stack overflow

Fix vmm_as_clone_user to use a heap-allocated 4KB temp buffer instead of a 4KB stack array (kernel stacks are 4KB). Harden heap free/coalesce logic and diagnostics to better catch corruption/double-free.

8 weeks agoposix: waitpid WNOHANG
Tulio A M Mendes [Sun, 8 Feb 2026 02:15:15 +0000 (23:15 -0300)]
posix: waitpid WNOHANG

Add WNOHANG option support to waitpid in kernel scheduler and syscall path, and include a userland smoke test.

8 weeks agodocs: update POSIX/Unix feature status
Tulio A M Mendes [Sun, 8 Feb 2026 02:02:09 +0000 (23:02 -0300)]
docs: update POSIX/Unix feature status

Refresh README, build guide, and POSIX roadmap to reflect implemented syscalls (dup/dup2/pipe/fork/execve), mounts/tmpfs/overlayfs, analysis targets, and remaining gaps.

8 weeks agoD3: execve argv/envp userland test
Tulio A M Mendes [Sun, 8 Feb 2026 01:56:55 +0000 (22:56 -0300)]
D3: execve argv/envp userland test

Pass argv/envp from init.elf into execve() and extend echo.elf to parse argc/argv/envp from the initial user stack for validation.

8 weeks agoD3: execve argv/envp stack + errno
Tulio A M Mendes [Sun, 8 Feb 2026 01:51:33 +0000 (22:51 -0300)]
D3: execve argv/envp stack + errno

Copy argv/envp from user memory and build a minimal initial user stack in the new address space during execve(). Improve errno reporting (EFAULT/ENOENT/ENOMEM/EINVAL).

8 weeks agoD3: fork syscall + remove spawn
Tulio A M Mendes [Sun, 8 Feb 2026 01:47:06 +0000 (22:47 -0300)]
D3: fork syscall + remove spawn

Implement fork() by cloning user address space and resuming child in ring3 from a saved register frame. Duplicate FD table via refcounting. Remove temporary spawn syscall and update init.elf waitpid test to use fork().

8 weeks agoD3: dup/pipe/execve syscalls
Tulio A M Mendes [Sun, 8 Feb 2026 01:16:45 +0000 (22:16 -0300)]
D3: dup/pipe/execve syscalls

Add refcounted dup/dup2, pipe() ring buffer, and execve() to replace the current process image. Include userland wrappers, smoke tests, and a second user binary (echo.elf) packaged into initrd.

8 weeks agobuild: add scan-build and mkinitrd-asan targets
Tulio A M Mendes [Sun, 8 Feb 2026 00:23:05 +0000 (21:23 -0300)]
build: add scan-build and mkinitrd-asan targets

8 weeks agotests: fix ring3 write buffers and add sys_exit
Tulio A M Mendes [Sun, 8 Feb 2026 00:21:26 +0000 (21:21 -0300)]
tests: fix ring3 write buffers and add sys_exit

8 weeks agokernel: add overlayfs root (initrd+tmpfs) for writable /
Tulio A M Mendes [Sat, 7 Feb 2026 23:56:43 +0000 (20:56 -0300)]
kernel: add overlayfs root (initrd+tmpfs) for writable /

8 weeks agokernel: add console subsystem and kprintf (uart+vga)
Tulio A M Mendes [Sat, 7 Feb 2026 23:13:26 +0000 (20:13 -0300)]
kernel: add console subsystem and kprintf (uart+vga)

8 weeks agosyscall: support write() to files (tmpfs test)
Tulio A M Mendes [Sat, 7 Feb 2026 22:32:02 +0000 (19:32 -0300)]
syscall: support write() to files (tmpfs test)

8 weeks agofs: add mounts and basic tmpfs
Tulio A M Mendes [Sat, 7 Feb 2026 22:31:58 +0000 (19:31 -0300)]
fs: add mounts and basic tmpfs

8 weeks agofs: add lseek/stat/fstat and minimal errno
Tulio A M Mendes [Sat, 7 Feb 2026 22:13:42 +0000 (19:13 -0300)]
fs: add lseek/stat/fstat and minimal errno

8 weeks agomm: add per-process address spaces (x86)
Tulio A M Mendes [Sat, 7 Feb 2026 21:50:10 +0000 (18:50 -0300)]
mm: add per-process address spaces (x86)

8 weeks agoproc: reap zombie children on waitpid
Tulio A M Mendes [Sat, 7 Feb 2026 21:21:21 +0000 (18:21 -0300)]
proc: reap zombie children on waitpid

8 weeks agouser/init: stress test waitpid with 100 children
Tulio A M Mendes [Sat, 7 Feb 2026 21:19:51 +0000 (18:19 -0300)]
user/init: stress test waitpid with 100 children

8 weeks agoproc: add waitpid + exit status; add temporary spawn() test helper
Tulio A M Mendes [Sat, 7 Feb 2026 20:46:02 +0000 (17:46 -0300)]
proc: add waitpid + exit status; add temporary spawn() test helper

8 weeks agodocs: update POSIX roadmap and current kernel features
Tulio A M Mendes [Sat, 7 Feb 2026 20:39:46 +0000 (17:39 -0300)]
docs: update POSIX roadmap and current kernel features

8 weeks agotty: add canonical line discipline and wire fd 0/1/2
Tulio A M Mendes [Sat, 7 Feb 2026 19:34:05 +0000 (16:34 -0300)]
tty: add canonical line discipline and wire fd 0/1/2

8 weeks agotty: make stdin (fd 0) blocking via keyboard waiter
Tulio A M Mendes [Sat, 7 Feb 2026 19:22:30 +0000 (16:22 -0300)]
tty: make stdin (fd 0) blocking via keyboard waiter

8 weeks agotty: add nonblocking stdin (fd 0) via ring buffer
Tulio A M Mendes [Sat, 7 Feb 2026 18:54:15 +0000 (15:54 -0300)]
tty: add nonblocking stdin (fd 0) via ring buffer

8 weeks agoinitrd: switch to TAR USTAR with directory support
Tulio A M Mendes [Sat, 7 Feb 2026 18:45:01 +0000 (15:45 -0300)]
initrd: switch to TAR USTAR with directory support

8 weeks agosyscall: add open/read/close and per-process fd table
Tulio A M Mendes [Sat, 7 Feb 2026 18:16:03 +0000 (15:16 -0300)]
syscall: add open/read/close and per-process fd table

8 weeks agovfs: add basic path lookup (vfs_lookup)
Tulio A M Mendes [Sat, 7 Feb 2026 17:35:49 +0000 (14:35 -0300)]
vfs: add basic path lookup (vfs_lookup)

8 weeks agokernel: introduce init_start to manage initrd and userspace bring-up
Tulio A M Mendes [Sat, 7 Feb 2026 16:27:02 +0000 (13:27 -0300)]
kernel: introduce init_start to manage initrd and userspace bring-up

8 weeks agokernel: move arch-specific init into arch_platform hooks
Tulio A M Mendes [Sat, 7 Feb 2026 16:21:47 +0000 (13:21 -0300)]
kernel: move arch-specific init into arch_platform hooks

8 weeks agokernel: move initrd mapping and usermode entry behind HAL
Tulio A M Mendes [Sat, 7 Feb 2026 16:08:30 +0000 (13:08 -0300)]
kernel: move initrd mapping and usermode entry behind HAL