]> Projects (at) Tadryanom (dot) Me - AdrOS.git/log
AdrOS.git
7 weeks agorefactor: migrate all filesystems to struct file_operations
Tulio A M Mendes [Fri, 13 Feb 2026 21:23:05 +0000 (18:23 -0300)]
refactor: migrate all filesystems to struct file_operations

Every filesystem and device driver now defines static const
file_operations tables and assigns f_ops on every node:
- tmpfs: tmpfs_file_ops, tmpfs_dir_ops
- devfs: devfs_dir_ops, dev_null_ops, dev_zero_ops, dev_random_ops
- ext2: ext2_file_fops, ext2_dir_fops
- fat: fat_file_fops, fat_dir_fops
- diskfs: diskfs_file_fops, diskfs_dir_fops
- overlayfs: overlay_file_ops, overlay_dir_ops
- tty: tty_fops (console + tty)
- pipe: pipe_read_fops, pipe_write_fops
- socket: sock_fops
- vbe: fb0_fops
- keyboard: kbd_fops

VFS dispatch (fs.c + syscall.c) checks f_ops first, falls back to
legacy per-node pointers. Legacy pointers are still set (dual
assignment) for callers that access them directly (e.g. overlayfs
layer delegation). Phase B3 will remove legacy pointers after all
direct accesses are eliminated.

20/20 smoke tests pass, cppcheck clean.

7 weeks agorefactor: VFS file_operations dispatch layer
Tulio A M Mendes [Fri, 13 Feb 2026 21:05:14 +0000 (18:05 -0300)]
refactor: VFS file_operations dispatch layer

Add struct file_operations to fs.h with all VFS callback signatures.
Add const struct file_operations* f_ops to fs_node_t.

Update all VFS dispatch points (fs.c wrappers + syscall.c direct
dispatch for poll, readdir, ioctl, mmap) to check f_ops first,
then fall back to legacy per-node function pointers.

This enables incremental migration: filesystems can adopt f_ops
one at a time while legacy pointers continue to work.

20/20 smoke tests pass.

7 weeks agofeat: O(1) sorted sleep queue for process_wake_check
Tulio A M Mendes [Fri, 13 Feb 2026 21:00:07 +0000 (18:00 -0300)]
feat: O(1) sorted sleep queue for process_wake_check

Replace O(N) scan of all processes with a sorted doubly-linked sleep
queue. process_wake_check now pops expired entries from the queue head
in O(1) time. The O(N) scan is retained only for alarm delivery.

Key design decisions:
- sleep_prev/sleep_next/in_sleep_queue fields added to struct process
- process_sleep() inserts into sorted queue under sched_lock
- schedule() handles deferred insertion for ksem_wait_timeout/futex
  (SLEEPING set under external lock, inserted under sched_lock in
  schedule — no preemption window)
- All wake paths (signal, kill, reap, sched_enqueue_ready) call
  sleep_queue_remove to prevent double-insert corruption
- Defensive sleep_queue_remove before insert in process_sleep

20/20 smoke tests pass, cppcheck clean.

7 weeks agocleanup: fix stale x86 'eax' reference in syscall.c comment
Tulio A M Mendes [Fri, 13 Feb 2026 20:05:07 +0000 (17:05 -0300)]
cleanup: fix stale x86 'eax' reference in syscall.c comment

7 weeks agofeat: migrate PCI and E1000 to HAL driver registry
Tulio A M Mendes [Fri, 13 Feb 2026 20:01:37 +0000 (17:01 -0300)]
feat: migrate PCI and E1000 to HAL driver registry

- PCI: hal_driver 'x86-pci' (BUS, priority 10) — self-registers via pci_driver_register()
- E1000: hal_driver 'e1000' (NET, priority 20) — probe checks PCI for Intel 82540EM
- init.c: replace explicit pci_init()/e1000_init() with driver registration + hal_drivers_init_all()
- Drivers init in priority order: PCI bus first, then E1000 probes and inits
- Pattern ready for additional drivers to self-register

20/20 smoke, cppcheck clean

7 weeks agofeat: HAL Device Driver API — driver registry with probe/init/shutdown lifecycle
Tulio A M Mendes [Fri, 13 Feb 2026 19:54:47 +0000 (16:54 -0300)]
feat: HAL Device Driver API — driver registry with probe/init/shutdown lifecycle

- Add include/hal/driver.h: struct hal_driver with type, priority, ops (probe/init/shutdown)
- Add src/kernel/driver.c: driver registry with hal_driver_register(), hal_drivers_init_all(),
  hal_drivers_shutdown_all(), hal_driver_find(), hal_driver_count()
- Drivers init in priority order (insertion sort), shutdown in reverse
- HAL_MAX_DRIVERS=32, 6 driver types: PLATFORM, CHAR, BLOCK, NET, DISPLAY, BUS
- Framework ready for existing drivers to self-register (incremental migration)

20/20 smoke, cppcheck clean

7 weeks agorefactor: move syscall_init arch dispatch to arch/x86/sysenter_init.c
Tulio A M Mendes [Fri, 13 Feb 2026 19:48:51 +0000 (16:48 -0300)]
refactor: move syscall_init arch dispatch to arch/x86/sysenter_init.c

- Add arch_syscall_init() that registers INT 0x80 handler and calls x86_sysenter_init()
- syscall_init() now just calls arch_syscall_init() — zero #ifdef in syscall.c
- x86_sysenter_init() made static (internal to sysenter_init.c)
- syscall.c contains ZERO architecture-specific code or #ifdefs

20/20 smoke, cppcheck clean

7 weeks agorefactor: decouple struct process from arch-specific struct registers
Tulio A M Mendes [Fri, 13 Feb 2026 19:42:45 +0000 (16:42 -0300)]
refactor: decouple struct process from arch-specific struct registers

- Replace embedded 'struct registers user_regs' with opaque uint8_t user_regs[ARCH_REGS_SIZE]
- Add include/arch_types.h dispatcher and include/arch/x86/arch_types.h (ARCH_REGS_SIZE=64)
- Change arch_regs_set_retval, arch_regs_set_ustack, hal_usermode_enter_regs, arch_sigreturn
  to accept void* instead of struct registers* — arch implementations cast internally
- process_fork_create and process_clone_create now take const void* child_regs
- Remove #include interrupts.h from process.h, arch_process.h, hal/usermode.h, arch_signal.h
- process.h is now fully architecture-agnostic (no x86 register names visible)

20/20 smoke, cppcheck clean

7 weeks agofix: rx_thread uses ksem_wait_timeout on e1000_rx_sem instead of blind process_sleep...
Tulio A M Mendes [Fri, 13 Feb 2026 19:29:19 +0000 (16:29 -0300)]
fix: rx_thread uses ksem_wait_timeout on e1000_rx_sem instead of blind process_sleep polling

7 weeks agocleanup: remove stale comments from process_sleep and process_wake_check
Tulio A M Mendes [Fri, 13 Feb 2026 19:24:05 +0000 (16:24 -0300)]
cleanup: remove stale comments from process_sleep and process_wake_check

7 weeks agorefactor: replace socket magic 0x534F434B with proper VFS FS_SOCKET nodes
Tulio A M Mendes [Fri, 13 Feb 2026 18:45:18 +0000 (15:45 -0300)]
refactor: replace socket magic 0x534F434B with proper VFS FS_SOCKET nodes

- Add FS_SOCKET type to fs.h
- Create sock_node_create/close/read/write: proper fs_node_t for sockets
  with read→ksocket_recv, write→ksocket_send, close→ksocket_close
- Socket ID stored in node->inode (previously in file->offset)
- sock_fd_get_sid helper validates socket FDs via FS_SOCKET type check
- socket()/accept() now create VFS nodes instead of magic-flagged files
- fd_close no longer needs special socket magic check
- read()/write() on socket FDs now work via standard VFS dispatch
- All 0x534F434BU magic references eliminated from codebase

7 weeks agorefactor: add VFS poll callback to fs_node_t, eliminate abstraction leaks from syscall.c
Tulio A M Mendes [Fri, 13 Feb 2026 18:37:02 +0000 (15:37 -0300)]
refactor: add VFS poll callback to fs_node_t, eliminate abstraction leaks from syscall.c

- Add int (*poll)(struct fs_node*, int events) to fs_node_t in fs.h
- Define VFS_POLL_IN/OUT/ERR/HUP constants in fs.h (shared)
- Implement poll callbacks: pipe_poll, tty_devfs_poll, pty_master/slave_poll_fn,
  dev_null_poll, dev_always_ready_poll, kbd_dev_poll
- Wire poll into all device nodes: /dev/null, /dev/zero, /dev/random, /dev/urandom,
  /dev/tty, /dev/console, /dev/ptmx, /dev/pts/N, /dev/kbd, pipe nodes
- Refactor poll_wait_kfds: dispatch through node->poll instead of hardcoded
  pipe name prefix, tty inode==3, pty_is_master/slave_ino checks
- Refactor non-blocking read/write: use node->poll instead of pipe name
  checks and tty/pty inode checks
- syscall.c no longer references tty_can_read/write, pty_*_can_read/write_idx,
  pty_is_master_ino, pty_ino_to_idx for poll/nonblock purposes

7 weeks agofix: replace x86-specific child_regs.eax=0 with arch_regs_set_retval in fork_impl
Tulio A M Mendes [Fri, 13 Feb 2026 18:25:45 +0000 (15:25 -0300)]
fix: replace x86-specific child_regs.eax=0 with arch_regs_set_retval in fork_impl

7 weeks agodocs: update README, BUILD_GUIDE, POSIX_ROADMAP, TESTING_PLAN for current state
Tulio A M Mendes [Fri, 13 Feb 2026 11:14:26 +0000 (08:14 -0300)]
docs: update README, BUILD_GUIDE, POSIX_ROADMAP, TESTING_PLAN for current state

- README: buddy allocator heap, ICMP ping, IOAPIC level-triggered,
  multi-drive ATA, kernel cmdline, kconsole, NO_SYS=0, 20 smoke tests,
  16-check test battery, ~103K LOC across 255 commits, ~95% POSIX coverage
- BUILD_GUIDE: networking, multi-disk QEMU, root= cmdline param,
  test-battery target, 20 smoke checks
- POSIX_ROADMAP: FAT12/16/32 full RW (was FAT16 RO), ext2 full RW (was
  not implemented), NO_SYS=0 threaded mode, ICMP ping, multi-drive ATA,
  kconsole, buddy allocator, 48 total features (31+17), updated remaining
  work tiers
- TESTING_PLAN: 20 smoke checks, test-battery description, updated
  Makefile targets

7 weeks agofeat: ICMP ping test, IOAPIC level-triggered PCI IRQ, multi-disk test battery
Tulio A M Mendes [Fri, 13 Feb 2026 11:06:06 +0000 (08:06 -0300)]
feat: ICMP ping test, IOAPIC level-triggered PCI IRQ, multi-disk test battery

- net_ping.c: kernel ICMP ping test using lwIP raw API with inline
  e1000_recv polling (3 pings to 10.0.2.2 QEMU gateway)
- ioapic: add ioapic_route_irq_level() for PCI interrupts
  (level-triggered, active-low per PCI spec)
- arch_platform: route E1000 NIC IRQ 11 via ioapic_route_irq_level
- e1000_netif: rx_thread uses process_sleep(1) polling fallback
- smoke_test.exp: add PING network pattern (20/20 tests)
- test_battery.exp: 16 tests covering multi-disk ATA detection
  (hda+hdb+hdd), VFS InitRD+diskfs mount, ping, and diskfs ops
- Makefile: add test-battery target and -nic user,model=e1000

7 weeks agofeat: interrupt-driven E1000 RX, non-blocking TX, root= cmdline param
Tulio A M Mendes [Fri, 13 Feb 2026 10:01:48 +0000 (07:01 -0300)]
feat: interrupt-driven E1000 RX, non-blocking TX, root= cmdline param

E1000 networking overhaul — replace polling with proper interrupt-driven I/O:

1. RX interrupt-driven:
   - IRQ handler (e1000_irq_handler) now signals e1000_rx_sem on
     RXT0/RXDMT0/RXO events instead of being a no-op.
   - Dedicated kernel thread (e1000_rx_thread) blocks on the
     semaphore, drains all available packets via e1000_recv(),
     and delivers them to lwIP via tcpip_input().
   - Latency: immediate wake on packet arrival (was 20ms polling).

2. TX non-blocking:
   - e1000_send() checks the DD bit immediately and returns -1 if
     the descriptor is not ready (was: busy-wait up to 100K iters).
   - lwIP's linkoutput callback returns ERR_IF on ring-full.

3. Idle loop cleanup:
   - net_poll() removed from kernel_main's idle loop.
   - net_poll() is now a no-op (kept for backward compat).
   - PID 0 idle loop is pure hlt — no wasted CPU cycles.

4. root= kernel command line parameter:
   - Syntax: root=/dev/hdX (e.g. root=/dev/hda)
   - Auto-detects filesystem (tries diskfs, fat, ext2 in order)
   - Mounts at /disk on success
   - Processed after ATA init, before /etc/fstab parsing
   - Example GRUB entry:
     multiboot2 /boot/adros-x86.bin root=/dev/hda quiet

Files changed:
- src/drivers/e1000.c: add sync.h, ksem_init/signal, non-blocking TX
- include/e1000.h: export e1000_rx_sem
- src/net/e1000_netif.c: rewrite with rx_thread, remove polling
- src/kernel/main.c: remove net_poll() from idle loop
- src/kernel/init.c: add root= auto-mount logic

Build: clean, cppcheck: clean, smoke: 19/19 pass
Stress: 10/10 boots without ring3 — zero panics

7 weeks agofix: hold sched_lock through context_switch to prevent timer race
Tulio A M Mendes [Fri, 13 Feb 2026 09:43:51 +0000 (06:43 -0300)]
fix: hold sched_lock through context_switch to prevent timer race

Root cause of rare kernel panics with EIP on the kernel stack:

When schedule() was called from process context (waitpid, sleep),
irq_flags had IF=1. spin_unlock_irqrestore() re-enabled interrupts
BEFORE context_switch(). If a timer fired in this window:

1. current_process was already set to 'next' (line 835)
2. But we were still executing on prev's stack
3. Nested schedule() treated 'next' as prev, saved prev's ESP
   into next->sp — CORRUPTING next->sp
4. Future context_switch to 'next' loaded the wrong stack offset,
   popping garbage registers and a garbage return address
5. EIP ended up pointing into the kernel stack → PAGE FAULT

Fix (three parts):
1. schedule(): move context_switch BEFORE spin_unlock_irqrestore.
   After context_switch we are on the new process's stack, and its
   saved irq_flags correctly releases the lock.
2. arch_kstack_init: set initial EFLAGS to 0x002 (IF=0) instead of
   0x202 so popf in context_switch doesn't enable interrupts while
   the lock is held.
3. thread_wrapper: release sched_lock and enable interrupts, since
   new processes arrive here via context_switch's ret (bypassing
   the spin_unlock_irqrestore after context_switch).

Also: remove get_next_ready_process() which incorrectly returned
fallback processes not in rq_active, causing rq_dequeue to corrupt
the runqueue bitmap. Inlined the logic correctly in schedule().

Verified: 20/20 boots without 'ring3' — zero panics.
Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofeat: Linux-like kernel command line parser with /proc/cmdline
Tulio A M Mendes [Fri, 13 Feb 2026 09:15:09 +0000 (06:15 -0300)]
feat: Linux-like kernel command line parser with /proc/cmdline

Implement a proper kernel command line parsing system modeled after
Linux's cmdline triaging:

1. Kernel params: recognized 'key=value' tokens (init=, root=,
   console=, loglevel=) are consumed by the kernel.
2. Kernel flags: recognized plain tokens (quiet, ring3, nokaslr,
   single, noapic, nosmp) are consumed by the kernel.
3. Init envp: unrecognized 'key=value' tokens become environment
   variables for the init process.
4. Init argv: unrecognized plain tokens (no '=' or '.') become
   command-line arguments for the init process.
5. '--' separator: everything after it goes to init untouched.
6. First token (kernel path) is always skipped.

New files:
- include/kernel/cmdline.h: API (cmdline_parse, cmdline_get,
  cmdline_has, cmdline_init_path, cmdline_init_argv/envp, cmdline_raw)
- src/kernel/cmdline.c: implementation with static storage

Changes:
- init.c: calls cmdline_parse() early, uses cmdline_has('ring3')
  instead of the old cmdline_has_token() (removed)
- arch_platform.c: uses cmdline_init_path() for init binary path
  (supports 'init=/path/to/init' from GRUB cmdline)
- procfs.c: added /proc/cmdline file (readable by userspace)

The 'ring3' parameter is no longer required for stable boot (the
scheduler bug causing panics without it was fixed in the previous
commit). It now only controls the inline ring3 test.

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofix: remove killed READY processes from runqueue before marking ZOMBIE
Tulio A M Mendes [Fri, 13 Feb 2026 09:00:13 +0000 (06:00 -0300)]
fix: remove killed READY processes from runqueue before marking ZOMBIE

Root cause of intermittent kernel panic (PAGE FAULT at 0x0, ESP=0):

When process_kill(SIGKILL) killed a READY process (sitting in
rq_active or rq_expired), it set state=ZOMBIE but did NOT remove
the process from the runqueue. Later, the parent reaped the ZOMBIE
via waitpid → process_reap_locked → kfree(p), freeing the struct.
But the freed pointer remained in the runqueue. rq_pick_next()
returned the dangling pointer, schedule() read sp=0 from freed
heap memory, and context_switch loaded ESP=0 → PAGE FAULT.

The 'ring3' cmdline flag masked this bug by changing scheduler
timing: with ring3, the BSP entered usermode immediately via iret,
altering the sequence of context switches such that the ZOMBIE was
typically dequeued before being reaped.

Fix:
- Add rq_remove_if_queued() helper: safely searches both rq_active
  and rq_expired for a process at its priority level before calling
  rq_dequeue()
- process_kill(SIGKILL): dequeue READY victims before setting ZOMBIE
- process_reap_locked(): dequeue as safety net before freeing

Verified: 10/10 boots without 'ring3' — zero panics (was ~50% fail).
Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofix: add IOAPIC route for IRQ 15 (secondary ATA channel)
Tulio A M Mendes [Fri, 13 Feb 2026 08:22:35 +0000 (05:22 -0300)]
fix: add IOAPIC route for IRQ 15 (secondary ATA channel)

The secondary ATA channel (IRQ 15, vector 47) was not routed through
the IOAPIC. After the multi-drive ATA refactor, ata_pio_init() probes
the secondary channel, which can generate IRQ 15 (e.g. IDENTIFY to
QEMU's ATAPI CD-ROM). Without a proper IOAPIC route:

1. The interrupt was lost (PIC disabled, IOAPIC not routing it)
2. The IOAPIC pin 15 remained in an undefined state
3. Depending on timing, this could cause spurious behavior

This was the likely root cause of intermittent kernel panics/reboots
when booting without the 'ring3' cmdline flag — the timing difference
meant the secondary ATA probe's unhandled IRQ could manifest as an
unrecoverable interrupt state.

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofeat: multi-drive ATA support (4 drives) + fstab/mount command
Tulio A M Mendes [Fri, 13 Feb 2026 08:07:10 +0000 (05:07 -0300)]
feat: multi-drive ATA support (4 drives) + fstab/mount command

Major ATA driver refactoring:

1. ATA PIO driver (ata_pio.h, hal/x86/ata_pio.c):
   - Support all 4 ATA drives: primary/master (hda), primary/slave (hdb),
     secondary/master (hdc), secondary/slave (hdd)
   - New API: ata_pio_init() probes both channels, ata_pio_read28/write28
     take a drive ID parameter, ata_pio_drive_present() query
   - ata_name_to_drive/ata_drive_to_name helpers for device name mapping
   - Per-channel I/O ports (0x1F0/0x3F6 primary, 0x170/0x376 secondary)
   - Master/slave selection (0xE0/0xF0 LBA mode bits)
   - Floating bus detection (0xFF = no controller)
   - ATAPI rejection (non-zero LBA1/LBA2 after IDENTIFY)

2. ATA DMA driver (ata_dma.h, hal/x86/ata_dma.c):
   - Per-channel DMA state: separate PRDT, bounce buffer, spinlock, IRQ
     handler for primary (BAR4+0) and secondary (BAR4+8)
   - KVA map extended: 4 pages (PRDT+buf x 2 channels) at 0xC0320000-3
   - PCI Bus Master probe factored out and cached (single PCI lookup)
   - DMA-aware IRQ handlers for both IRQ 14 and IRQ 15

3. Filesystem drivers updated to accept drive parameter:
   - fat_mount(int drive, uint32_t lba) — stores drive in g_fat struct
   - ext2_mount(int drive, uint32_t lba) — stores drive in g_ext2 struct
   - diskfs_create_root(int drive) — static g_diskfs_drive for all I/O
   - persistfs_create_root(int drive) — delegates to diskfs on same drive

4. Mount system redesigned — no more auto-mount of disk FS:
   - init.c: calls ata_pio_init() once, then parses /etc/fstab
   - Fstab format: /dev/hdX  /mountpoint  fstype  options
   - init_mount_fs() helper reusable by both fstab and kconsole
   - rootfs/etc/fstab created with default diskfs+persistfs on hda

5. kconsole mount command:
   - 'mount -t <type> /dev/<hd> <mountpoint>' for manual mounting
   - 'lsblk' lists all 4 ATA drives and their detection status
   - Help text updated with new commands

6. Weak stubs updated for new API signatures (src/drivers/ata_pio.c)
7. Mount table increased from 8 to 16 slots (previous commit)

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofix: consolidate kconsole banner + safe disk FS probe order
Tulio A M Mendes [Fri, 13 Feb 2026 07:39:05 +0000 (04:39 -0300)]
fix: consolidate kconsole banner + safe disk FS probe order

1. Consolidate redundant PANIC + kconsole banners into a single
   message shown by kconsole_enter(). Previously both main.c and
   kconsole.c printed separate banners.

2. Fix critical VFS mount ordering bug: diskfs, FAT, and ext2 all
   share the same ATA primary master disk at LBA 0. Previously
   diskfs_create_root() was called first, and its auto-format
   (diskfs_super_load) would overwrite LBA 2-3 if DISKFS_MAGIC
   was not found -- destroying any ext2 superblock at the same
   location. Now the probe order is:
     a) ext2 (checks magic 0xEF53 at byte 1080)
     b) FAT (validates BPB fields at LBA 0)
     c) diskfs (fallback, may auto-format blank disks)
   Only one FS is mounted per device -- they are mutually exclusive.

3. Make ata_pio_init_primary_master() idempotent with a static
   guard flag so it can be called from both init.c and
   diskfs_create_root() without double-initializing.

4. Increase VFS mount table from 8 to 16 slots to prevent
   -ENOSPC when adding future mount points.

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofeat: kconsole overhaul -- bugs fixed + readline + scrollback + extended keyboard
Tulio A M Mendes [Fri, 13 Feb 2026 07:22:15 +0000 (04:22 -0300)]
feat: kconsole overhaul -- bugs fixed + readline + scrollback + extended keyboard

Bug fixes:
1. dmesg pollution from mem/ls/cat: added klog_set_suppress() flag
   in console.c. kconsole wraps command execution with suppression
   so interactive output doesn't contaminate the kernel log buffer.

2. UTF-8 em dash rendering as garbage on VGA: replaced all UTF-8
   em dashes in output strings (main.c, init.c) with ASCII '--'.
   VGA text mode only supports CP437, not UTF-8.

3. PANIC message appearing in dmesg: changed from kprintf() to
   console_write() so the emergency banner goes to screen/serial
   but NOT to the kernel log ring buffer.

Features:
1. VGA scrollback buffer (200 lines): lines that scroll off the
   top of the screen are saved in a circular buffer. Shift+PgUp
   scrolls back half-page, Shift+PgDn scrolls forward. Any new
   output auto-returns to live view (like Linux).

2. Command history (16 entries): Up/Down arrow keys navigate
   through previous commands. Duplicate suppression. Current
   line is saved/restored when navigating.

3. Full line editing: Left/Right arrows move cursor, Home/End
   jump to start/end, Delete key, insert-at-cursor mode.
   Emacs keybindings: Ctrl-A (home), Ctrl-E (end), Ctrl-U
   (kill line), Ctrl-K (kill to end).

4. Extended keyboard driver: HAL x86 keyboard now tracks shift
   state, handles 0xE0 extended scancodes, emits VT100 escape
   sequences for arrow keys/Home/End/PgUp/PgDn/Delete. Shift
   scancode map added for uppercase letters and symbols.
   Shift+PgUp/PgDn calls vga_scroll_back/fwd directly.

5. Serial input works with readline: VT100 sequences from
   terminal emulators are parsed by the same escape state
   machine, so -serial stdio now supports full line editing.

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofix: kconsole overhaul — 8 bugs fixed (echo, VGA, serial, dmesg)
Tulio A M Mendes [Fri, 13 Feb 2026 06:51:01 +0000 (03:51 -0300)]
fix: kconsole overhaul — 8 bugs fixed (echo, VGA, serial, dmesg)

Issues reported and fixed:

1. Double echo: TTY keyboard callback was echoing characters via
   tty_output_char() AND kconsole was echoing via console_write().
   Fix: keyboard_set_callback(0) detaches TTY on kconsole entry.

2. Backspace printing garbage: VGA vga_put_char() only handled \n,
   treating \b as a visible glyph. Fix: full control char support
   in vga_put_char — \b moves cursor back, \r resets column, \t
   advances to next tab stop, non-printable chars filtered.

3. Enter printing garbage: same root cause as #2 — \r was not
   handled by VGA. Now handled properly.

4. Cursor not tracking: VGA had no hardware cursor update. Added
   hal_video_set_cursor() HAL function using CRTC registers
   0x3D4/0x3D5 on x86, called after every character output.

5. Clear screen broken: was using ANSI escape \033[2J which VGA
   can't parse. Added vga_clear() function, kconsole calls it
   directly.

6. dmesg contamination: kconsole prompts and help text used
   kprintf() which appends to klog ring buffer. Introduced
   kc_puts() wrapper over console_write() for interactive output
   that should NOT appear in dmesg.

7. Scroll (Shift+PageUp/Down): deferred — requires scrollback
   buffer (significant feature). Documented as known limitation.

8. Serial input not working (-serial stdio): kgetc() only read
   from PS/2 keyboard via keyboard_read_blocking(). Added
   hal_uart_try_getc() to HAL (poll UART LSR data-ready bit),
   rewrote kgetc() to poll both keyboard and UART in a loop.

9. ring3 command: removed from kconsole (useless without initrd
   in emergency mode). Replaced with proper ls command using
   readdir to list directory contents.

HAL changes (all 4 architectures):
- hal_video_set_cursor(row, col) — x86 uses VGA CRTC I/O ports
- hal_uart_try_getc() — non-blocking serial RX polling

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofix: kconsole fallback not activating when initrd is missing
Tulio A M Mendes [Fri, 13 Feb 2026 06:18:24 +0000 (03:18 -0300)]
fix: kconsole fallback not activating when initrd is missing

Root cause: init_start() always called arch_platform_start_userspace()
even when fs_root was NULL. The userspace init thread was created
asynchronously and returned 0 (success) to kernel_main(), so the
'init_ret < 0' check never triggered kconsole_enter(). The init
thread would later discover fs_root==NULL, print '[ELF] fs_root
missing' and hang — but kconsole was never entered.

Fix: init_start() now checks fs_root before attempting to start
userspace. If no root filesystem exists (e.g. missing initrd module
in GRUB), it returns -1 immediately, triggering the kconsole
emergency console fallback in kernel_main().

Also added clear panic message before kconsole entry (similar to
Linux's 'Kernel panic - not syncing: VFS: Unable to mount root fs').

Tested: boot without initrd module now shows:
  [INIT] No root filesystem — cannot start userspace.
  [PANIC] Userspace init failed — dropping to emergency console.
  *** AdrOS Kernel Console (kconsole) ***
  kconsole>

Normal boot: 19/19 smoke pass, cppcheck clean

7 weeks agofix: deep audit — VA collision, arch pollution, broken stubs
Tulio A M Mendes [Fri, 13 Feb 2026 06:07:43 +0000 (03:07 -0300)]
fix: deep audit — VA collision, arch pollution, broken stubs

Critical bug fix:
- VDSO and E1000 both mapped at VA 0xC0230000 — silent corruption!
  VDSO moved to 0xC0280000, E1000 moved to 0xC0330000-0xC0371FFF

New centralized VA map (include/kernel_va_map.h):
- All fixed kernel VA allocations documented in one header
- IOAPIC, VDSO, ACPI, ATA DMA, E1000, LAPIC all use KVA_* defines
- Prevents future VA collisions — single source of truth

Architecture pollution fixes:
- syscall.c SET_THREAD_AREA: replaced x86 gdt_set_gate_ext() with
  hal_cpu_set_tls() HAL call (was #if __i386__ inline)
- e1000_netif.c: replaced x86 'pause' asm with cpu_relax() from
  spinlock.h (arch-agnostic)
- tty.c: removed dead uart_console.h include (switched to
  console_put_char in previous commit)

Broken code fix:
- pmm_print_stats(): was declared in pmm.h but never implemented —
  now prints Total/Used/Free RAM in KB and MB
- kconsole 'mem' command: replaced [TODO] stub with pmm_print_stats()

Files using centralized KVA_* defines:
- vdso.c, e1000.c, acpi.c, ata_dma.c, ioapic.c, lapic.c

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agodocs: update README with TTY/PTY OPOST, console routing, stdio buffering improvements
Tulio A M Mendes [Fri, 13 Feb 2026 05:54:14 +0000 (02:54 -0300)]
docs: update README with TTY/PTY OPOST, console routing, stdio buffering improvements

7 weeks agofeat: PTY line discipline with OPOST/ONLCR processing
Tulio A M Mendes [Fri, 13 Feb 2026 05:53:18 +0000 (02:53 -0300)]
feat: PTY line discipline with OPOST/ONLCR processing

- Add per-PTY oflag field (default: OPOST | ONLCR)
- PTY slave write now applies ONLCR: \n → \r\n conversion
- PTY slave ioctl now supports TCGETS/TCSETS for c_oflag
- isatty() now returns 1 for PTY slaves (TCGETS succeeds)
- Matches Linux n_tty line discipline behavior on PTY output

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofeat: industry-standard TTY output pipeline (Linux/BSD parity)
Tulio A M Mendes [Fri, 13 Feb 2026 05:48:55 +0000 (02:48 -0300)]
feat: industry-standard TTY output pipeline (Linux/BSD parity)

Kernel:
- Open /dev/console as fd 0/1/2 for init process (mirrors Linux
  kernel_init: open + dup + dup pattern)
- Add console_put_char() that outputs to both UART and VGA
- TTY write path now routes through console_put_char() instead of
  uart_put_char() only — userspace output now appears on VGA too
- Implement OPOST/ONLCR output processing: \n → \r\n conversion
  (POSIX termios c_oflag, enabled by default)
- TCGETS/TCSETS ioctl now reads/writes c_oflag
- All TTY echo paths (canonical, raw, line editing) use tty_output_char()
  for consistent UART+VGA output with OPOST processing
- Increase syscall write copy buffer from 256 to 1024 bytes
- Declare vga_put_char() in vga_console.h

Userspace (ulibc):
- stdout is now line-buffered (_STDIO_LBUF): flushes on \n
- stderr is now unbuffered (_STDIO_UNBUF): writes immediately
- printf()/vprintf() now go through fwrite(stdout) instead of raw
  write(), unifying all stdio output through the FILE buffer
- putchar()/puts() also route through fwrite(stdout)
- fwrite() respects buffering modes: unbuffered bypasses buffer,
  line-buffered flushes on newline, full-buffered flushes when full
- Add setvbuf()/setbuf() with _IOFBF/_IOLBF/_IONBF modes
- Add isatty() implemented via TCGETS ioctl probe (POSIX standard)

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agodocs: update README for FAT12/16/32 RW and ext2 RW filesystems
Tulio A M Mendes [Fri, 13 Feb 2026 05:08:33 +0000 (02:08 -0300)]
docs: update README for FAT12/16/32 RW and ext2 RW filesystems

- Filesystems section: 8 types → 10 types
- FAT16 read-only → FAT12/16/32 unified RW driver
- Added ext2 RW description
- Removed ext2 from remaining work list (now implemented)
- Fixed lwIP mode description (NO_SYS=0 threaded)
- Updated directory structure listing

7 weeks agofeat: mount FAT and ext2 filesystems from init.c
Tulio A M Mendes [Fri, 13 Feb 2026 05:07:22 +0000 (02:07 -0300)]
feat: mount FAT and ext2 filesystems from init.c

- Probe IDE disk at LBA 0 for FAT and ext2 signatures during boot
- FAT mounts at /fat, ext2 mounts at /ext2
- Both fail gracefully on unformatted/zeroed disks (no panic)
- diskfs remains at /disk as primary RW filesystem

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofeat: ext2 filesystem driver with full RW support
Tulio A M Mendes [Fri, 13 Feb 2026 05:03:12 +0000 (02:03 -0300)]
feat: ext2 filesystem driver with full RW support

- New ext2.c + ext2.h: complete ext2 filesystem implementation
- Superblock parsing, block group descriptor table, inode read/write
- Block mapping: direct, singly/doubly/triply indirect blocks
- File read/write with automatic block allocation
- Directory operations: finddir, readdir, create, mkdir, unlink, rmdir,
  rename, truncate, link (hard links)
- Block and inode bitmap allocation/deallocation
- Symlink support (inline small symlinks via i_block)
- Auto-detection of inode size (128 or 256 for rev1)
- Supports 1KB, 2KB, and 4KB block sizes

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agofeat: unified FAT12/16/32 RW driver replacing read-only FAT16
Tulio A M Mendes [Fri, 13 Feb 2026 04:54:13 +0000 (01:54 -0300)]
feat: unified FAT12/16/32 RW driver replacing read-only FAT16

- New fat.c: unified FAT driver with auto-detection (FAT12/16/32) based on
  cluster count per Microsoft FAT spec
- Full RW support: file read/write, create, delete, truncate, mkdir, rmdir,
  rename, readdir, finddir — all wired to VFS callbacks
- FAT table access for all three variants (12-bit, 16-bit, 32-bit entries)
- Cluster chain management: alloc, extend, free
- Subdirectory support (cluster-based dirs + fixed root for FAT12/16)
- 8.3 filename conversion (to/from human-readable lowercase)
- fat16.h retained as backward-compat wrapper redirecting to fat.h
- Old read-only fat16.c removed

Fix: BSS collision with ACPI temp VA window
- BSS grew past 0xC0202000 with lwIP memp pools + FAT statics
- Moved ACPI temp VA: 0xC0202000 -> 0xC0300000
- Moved DMA PRDT VA: 0xC0220000 -> 0xC0320000
- Moved DMA bounce VA: 0xC0221000 -> 0xC0321000

Build: clean, cppcheck: clean, smoke: 19/19 pass

7 weeks agokprintf: migrate all uart_print() calls to kprintf() (Route A)
Tulio A M Mendes [Fri, 13 Feb 2026 04:31:04 +0000 (01:31 -0300)]
kprintf: migrate all uart_print() calls to kprintf() (Route A)

Replace 270 direct uart_print() calls across 42 files with kprintf(),
routing all kernel messages through the klog ring buffer and multi-backend
console infrastructure (UART + VGA).

Key changes:
- All kernel log/debug messages now go through kprintf() -> klog_append()
  -> console_write(), ensuring they appear in dmesg and on all enabled
  output devices.
- Consolidated multi-call patterns (uart_print+itoa_hex) into single
  kprintf() calls with format specifiers (%x, %u, %s, %d, %c).
- Removed manual itoa/itoa_hex + uart_print concatenation throughout.
- Cleaned up stale #include uart_console.h from files that no longer
  need it (main.c, socket.c, syscall.c, slab.c, timer.c).
- uart_print() now only remains in 2 places:
  * uart_console.c (the implementation)
  * console.c (the UART backend in console_write)
- uart_put_char() retained in tty.c for direct terminal I/O (not logging).
- arch_early_setup files keep uart_console.h for uart_init() call.

Build: clean, cppcheck: clean, smoke: 19/19 pass.

7 weeks agorefactor: replace doubly-linked-list heap with buddy allocator
Tulio A M Mendes [Fri, 13 Feb 2026 04:07:06 +0000 (01:07 -0300)]
refactor: replace doubly-linked-list heap with buddy allocator

Power-of-2 block sizes from 2^5 (32B) to 2^23 (8MB) with O(log N)
alloc/free and automatic buddy coalescing on free.

Design:
- block_hdr_t (8B) at the start of every block: magic, order, is_free
- Free blocks embed circular doubly-linked list pointers in their
  data area (free_node_t) for O(1) insert/remove per order
- 19 free lists (one per order, sentinel-based)
- Buddy merge: XOR offset to find buddy, check magic + is_free + order
- Spinlock-protected for SMP safety

Allocation:
- size_to_order: find smallest 2^k >= size + 8 (header)
- Search free lists from requested order upward
- Split larger blocks down, placing upper buddies on their free lists

Deallocation:
- Verify magic and double-free
- Iteratively merge with buddy while buddy is free at same order
- Insert merged block into correct free list

Trade-offs vs previous doubly-linked-list allocator:
+ O(log N) worst case vs O(N) first-fit scan
+ No external fragmentation (buddy coalescing)
+ Deterministic allocation time
- Internal fragmentation from power-of-2 rounding (~50% worst case)
- Fixed 8MB heap (was 10MB growable to 64MB)

Updated smoke test expectation for new init message.
19/19 smoke tests pass, cppcheck clean.

7 weeks agofeat: enable lwIP NO_SYS=0 threaded mode with kernel sync primitives
Tulio A M Mendes [Fri, 13 Feb 2026 03:52:10 +0000 (00:52 -0300)]
feat: enable lwIP NO_SYS=0 threaded mode with kernel sync primitives

Kernel synchronization primitives (include/sync.h + src/kernel/sync.c):
- ksem_t: counting semaphore with sleep/wake blocking (not spin-wait)
  - ksem_init, ksem_wait, ksem_wait_timeout, ksem_signal
  - Timeout support via process wake_at_tick mechanism
  - Race-safe: ksem_signal skips already-woken (timed-out) waiters
- kmutex_t: binary semaphore wrapper for mutual exclusion
- kmbox_t: fixed-size circular queue with not_empty/not_full semaphores
  - kmbox_init, kmbox_free, kmbox_post, kmbox_trypost
  - kmbox_fetch (with timeout), kmbox_tryfetch

lwIP sys_arch layer (include/net/arch/sys_arch.h + sys_arch.c):
- sys_sem_t, sys_mutex_t, sys_mbox_t backed by kernel primitives
- sys_thread_new: creates kernel threads via process_create_kernel
  with static trampoline array (up to 4 lwIP threads)
- sys_arch_protect/unprotect: IRQ save/restore for SYS_LIGHTWEIGHT_PROT
- sys_init, sys_now (50Hz tick to ms conversion)

lwIP configuration (lwipopts.h):
- NO_SYS=0, LWIP_NETCONN=1, SYS_LIGHTWEIGHT_PROT=1
- LWIP_SOCKET=0 (kernel uses netconn API; avoids POSIX type conflicts)
- Thread/mbox sizing: TCPIP_MBOX_SIZE=16, recvmbox sizes=8

Build system (Makefile):
- Added lwIP api/ sources: api_lib, api_msg, err, if_api, netbuf,
  netifapi, tcpip

Network init (e1000_netif.c):
- tcpip_init(callback, NULL) with volatile flag polling for sync
- netif input changed from ethernet_input to tcpip_input
- net_poll no longer calls sys_check_timeouts (handled by tcpip_thread)

Kernel stack enlargement (scheduler.c):
- Increased from 4KB (1 page) to 8KB (2 pages) per thread
- Required for deeper call chains in lwIP threaded mode
- Updated kstack_alloc, kstack_free, and all stack+offset references

LAPIC VA relocation (lapic.c):
- Moved from 0xC0200000 to 0xC0400000 to avoid collision with
  enlarged kernel BSS (~764KB with NO_SYS=0 memp pools)

lwIP third-party patch (patches/lwip-tcpip-volatile.patch):
- tcpip_init_done and tcpip_init_done_arg marked volatile in tcpip.c
- Fixes cross-thread visibility: compiler was caching NULL from BSS
  init, preventing tcpip_thread from seeing the callback set by
  tcpip_init in the init thread

All 19/19 smoke tests pass, cppcheck clean.

7 weeks agofix: resolve implicit declaration warnings in init.c and keyboard.c
Tulio A M Mendes [Fri, 13 Feb 2026 03:01:34 +0000 (00:01 -0300)]
fix: resolve implicit declaration warnings in init.c and keyboard.c

- src/kernel/init.c: add missing #include "keyboard.h" for
  keyboard_register_devfs()
- src/drivers/keyboard.c: add #include "utils.h" for memset/strcpy
  prototypes
- include/utils.h: remove duplicate strcpy prototype

7 weeks agorefactor: abstract x86 register accesses in syscall dispatcher via sc_* macros
Tulio A M Mendes [Fri, 13 Feb 2026 01:09:53 +0000 (22:09 -0300)]
refactor: abstract x86 register accesses in syscall dispatcher via sc_* macros

- include/arch/x86/arch_syscall.h: define sc_num/sc_arg0..4/sc_ret/
  sc_ip/sc_usp macros mapping to x86 INT 0x80 ABI registers
  (eax/ebx/ecx/edx/esi/edi/eip/useresp)
- include/arch_syscall.h: generic dispatch header with non-x86 stubs
- src/kernel/syscall.c: replace all ~200 direct regs->eax/ebx/ecx/
  edx/esi/edi/eip/useresp accesses with arch-agnostic sc_* macros
  across syscall_handler, posix_ext_syscall_dispatch, and
  socket_syscall_dispatch

syscall.c now contains zero x86-specific register names. To port to
ARM, only arch/arm/arch_syscall.h needs to map sc_* to ARM registers
(r7/r0-r4/pc/sp).

7 weeks agorefactor: route link() through VFS callback — remove last diskfs bypass from syscall.c
Tulio A M Mendes [Fri, 13 Feb 2026 00:58:05 +0000 (21:58 -0300)]
refactor: route link() through VFS callback — remove last diskfs bypass from syscall.c

- fs.h: add link callback to fs_node_t (dir, name, target_node)
- fs.c: implement vfs_link() wrapper — resolves old_path to node,
  new_path to parent+basename, calls parent->link()
- diskfs.c: implement diskfs_vfs_link() using parent ino + target ino,
  wire into diskfs_set_dir_ops()
- syscall.c: syscall_link_impl now calls vfs_link() instead of
  extern diskfs_link() with /disk/ prefix stripping

syscall.c no longer references any diskfs symbol.

7 weeks agorefactor: remove /disk/ VFS bypass from syscall.c — route through VFS mount + callbacks
Tulio A M Mendes [Fri, 13 Feb 2026 00:43:13 +0000 (21:43 -0300)]
refactor: remove /disk/ VFS bypass from syscall.c — route through VFS mount + callbacks

- fs.h: add create/mkdir/unlink/rmdir/rename/truncate callbacks to fs_node_t
- fs.h: add vfs_lookup_parent, vfs_create, vfs_mkdir, vfs_unlink, vfs_rmdir,
  vfs_rename, vfs_truncate prototypes
- fs.c: implement vfs_lookup_parent (split path into parent dir + basename)
  and all VFS mutation wrappers that resolve mount points transparently
- diskfs.c: implement VFS callback wrappers (diskfs_vfs_create, diskfs_vfs_mkdir,
  diskfs_vfs_unlink, diskfs_vfs_rmdir, diskfs_vfs_rename, diskfs_vfs_truncate)
  using parent diskfs_node ino for correct hierarchy scoping
- diskfs.c: wire callbacks into root and subdirectory nodes via diskfs_set_dir_ops
- syscall.c: open/mkdir/unlink/rmdir/rename now use generic VFS functions
  instead of hardcoded path[0]==/ && path[1]==d... checks
- syscall.c: remove #include diskfs.h (only diskfs_link extern remains)

Any filesystem mounted via vfs_mount that implements these callbacks will
now transparently support file creation, directory operations, and rename
without requiring syscall.c modifications.

7 weeks agorefactor: move sigframe/sigreturn from syscall.c to arch/x86/signal.c
Tulio A M Mendes [Fri, 13 Feb 2026 00:33:03 +0000 (21:33 -0300)]
refactor: move sigframe/sigreturn from syscall.c to arch/x86/signal.c

- New include/arch/x86/signal.h: shared struct sigframe + SIGFRAME_MAGIC
- New include/arch_signal.h: arch-agnostic arch_sigreturn() prototype
- New src/arch/x86/signal.c: x86 sigreturn implementation (eflags sanitize,
  CS/SS ring3 validation, IOPL clear)
- src/arch/x86/idt.c: use shared arch/x86/signal.h instead of local copy
- src/kernel/syscall.c: remove x86-specific sigframe struct and sigreturn_impl,
  call arch_sigreturn() via generic void* interface

No x86 signal frame knowledge remains in generic kernel code.

7 weeks agorefactor: extract x86 kernel stack setup and register accessors from scheduler to...
Tulio A M Mendes [Fri, 13 Feb 2026 00:29:02 +0000 (21:29 -0300)]
refactor: extract x86 kernel stack setup and register accessors from scheduler to arch layer

- New include/arch_process.h: arch-agnostic prototypes for arch_kstack_init(),
  arch_regs_set_retval(), arch_regs_set_ustack()
- New src/arch/x86/arch_process.c: x86 implementation (EFLAGS 0x202, cdecl
  stack frame layout matching context_switch in process.S)
- scheduler.c: process_create_kernel, process_fork_create, process_clone_create
  now use arch_kstack_init() instead of inline x86 stack manipulation
- scheduler.c: process_clone_create uses arch_regs_set_retval/arch_regs_set_ustack
  instead of direct .eax/.useresp access

No x86-specific constants or register names remain in scheduler.c.

7 weeks agodocs: update all documentation for DOOM port, euid/egid, /dev/fb0, /dev/kbd, fd-backe...
Tulio A M Mendes [Thu, 12 Feb 2026 08:47:23 +0000 (05:47 -0300)]
docs: update all documentation for DOOM port, euid/egid, /dev/fb0, /dev/kbd, fd-backed mmap

README.md:
- Added DOOM port (/bin/doom.elf), /dev/fb0, /dev/kbd to features
- Updated permissions: euid/egid + VFS enforcement on open()
- Updated mmap: now includes fd-backed mappings
- Updated guard pages: kernel stacks at 0xC8000000
- Updated ulibc: added all new headers (stdlib.h, ctype.h, sys/mman.h, etc.)
- Updated POSIX score: 90% → 93%
- Removed file-backed mmap from remaining work (now implemented)
- Added user/doom/ to directory structure

BUILD_GUIDE.md:
- Added Section 3: Building DOOM (setup, build, run instructions)
- Updated ulibc description with all new headers
- Added doom.elf to initrd listing

docs/POSIX_ROADMAP.md:
- Added geteuid/getegid/seteuid/setegid syscalls (all [x])
- Updated permissions entry: euid/egid + VFS enforcement
- Updated devfs: added /dev/fb0, /dev/kbd
- Updated mmap: fd-backed mappings
- Added /dev/kbd and /bin/doom.elf entries
- Added 8 additional features (tasks 32-39) to progress section
- Removed file-backed mmap from remaining gaps (now done)
- Updated ulibc header list

docs/AUDIT_REPORT.md:
- Updated 4.3 (guard pages): kernel stacks now fixed too
- Updated summary table: 4.3 now FIXED (user + kernel)
- Updated fix summary: 2 MODERATE fixed, 6 remaining

docs/SUPPLEMENTARY_ANALYSIS.md:
- Updated POSIX score: 90% → 93%
- Updated VMM summary: fd-backed mmap, kernel guard pages
- Updated process model: full euid/egid syscall list
- Updated memory management: fd-backed mmap, kernel guard pages
- Updated security: VFS permission enforcement
- Updated userland: all new ulibc headers + DOOM port
- Removed file-backed mmap from remaining gaps
- Updated remaining actions (file-backed mmap removed)
- Updated conclusion

docs/TESTING_PLAN.md:
- Added DOOM Smoke Test section describing integration test value

7 weeks agofeat: proper uid/gid + euid/egid implementation with permission enforcement
Tulio A M Mendes [Thu, 12 Feb 2026 08:34:46 +0000 (05:34 -0300)]
feat: proper uid/gid + euid/egid implementation with permission enforcement

Kernel:
- struct process: added euid/egid (effective uid/gid) fields
- process_fork_create: now inherits uid/gid/euid/egid from parent
  (previously left at 0 from memset)
- process_clone_create: also inherits euid/egid
- setuid/setgid: permission checks — only euid==0 can set arbitrary
  uid/gid; unprivileged processes can only set to their real uid/gid
- New syscalls: geteuid (88), getegid (89), seteuid (90), setegid (91)
- vfs_check_permission(): checks owner/group/other rwx bits against
  process euid/egid and file uid/gid/mode
- open() now calls vfs_check_permission() for R/W/RW access
- chmod: only root or file owner can change mode
- chown: only root can change ownership
- Added EACCES (13) to errno.h

ulibc:
- Added SYS_GETUID (52), SYS_GETGID (53), SYS_CHMOD (50),
  SYS_CHOWN (51), SYS_GETEUID (88), SYS_GETEGID (89),
  SYS_SETEUID (90), SYS_SETEGID (91)
- Added getuid/getgid/geteuid/getegid/seteuid/setegid wrappers

All 19/19 smoke tests pass.

7 weeks agofeat: include doom.elf in initrd when built
Tulio A M Mendes [Thu, 12 Feb 2026 08:13:01 +0000 (05:13 -0300)]
feat: include doom.elf in initrd when built

The Makefile now conditionally includes user/doom/doom.elf in the
initrd as bin/doom.elf if it exists. This allows DOOM to be
launched from the AdrOS shell via: /bin/doom.elf -iwad /path/to/doom1.wad

The DOOM build is optional — the main kernel build is unaffected
if doomgeneric has not been cloned.

7 weeks agofeat: DOOM compiles and links — adapter, build system, ulibc compat headers
Tulio A M Mendes [Thu, 12 Feb 2026 08:08:50 +0000 (05:08 -0300)]
feat: DOOM compiles and links — adapter, build system, ulibc compat headers

doom.elf (450KB) now builds successfully from doomgeneric source
with the AdrOS platform adapter.

Build system:
- user/doom/Makefile: excludes platform-specific adapters (SDL,
  allegro, emscripten, xlib, win, soso, linuxvt) and links with
  ulibc + crt0
- doomgeneric_adros.c: added main() entry point calling
  doomgeneric_Create/doomgeneric_Tick

New ulibc compatibility headers for DOOM:
- strings.h (wrapper for string.h)
- inttypes.h (PRId32/PRIu32/PRIx32 format macros)
- math.h (fabs/fabsf inline stubs)
- fcntl.h (O_RDONLY, O_WRONLY, O_CREAT, etc.)
- assert.h (assert macro with printf+exit)
- sys/types.h (ssize_t, off_t, pid_t, etc.)
- sys/stat.h (struct stat, S_ISDIR/S_ISREG)

New ulibc functions:
- stdlib: atof, system (stub), strtol
- All 19/19 kernel tests pass

7 weeks agofeat: DOOM port — doomgeneric AdrOS adapter + remaining ulibc extensions
Tulio A M Mendes [Thu, 12 Feb 2026 07:54:41 +0000 (04:54 -0300)]
feat: DOOM port — doomgeneric AdrOS adapter + remaining ulibc extensions

Added user/doom/ with the AdrOS platform adapter for doomgeneric:
- doomgeneric_adros.c: implements DG_Init (fb0 mmap + kbd open),
  DG_DrawFrame (nearest-neighbor scale to framebuffer),
  DG_GetKey (PS/2 scancode → DOOM keycode mapping),
  DG_GetTicksMs (clock_gettime), DG_SleepMs (nanosleep)
- Makefile: builds doom.elf from doomgeneric source + adapter
- README.md: setup instructions

Additional ulibc functions for DOOM engine compatibility:
- ctype.h: isdigit, isspace, isalpha, toupper, tolower, etc.
- stdlib: strtol (base 8/10/16 + auto-detect)
- string: strncat, strdup, strcasecmp, strncasecmp, strstr,
  memchr, strtok
- stdio: fseek, ftell, rewind, sprintf, sscanf, remove

To build DOOM:
  cd user/doom && git clone https://github.com/ozkl/doomgeneric.git && make

7 weeks agofeat: ulibc DOOM-ready extensions — fseek, ftell, sprintf, sscanf, strdup, etc.
Tulio A M Mendes [Thu, 12 Feb 2026 07:48:04 +0000 (04:48 -0300)]
feat: ulibc DOOM-ready extensions — fseek, ftell, sprintf, sscanf, strdup, etc.

Added missing C library functions required by the DOOM engine:

stdio: fseek, ftell, rewind, sprintf, sscanf (minimal %d/%s),
       remove, rename (stub)
stdlib: getenv (stub), abs, labs
string: strncat, strdup, strcasecmp, strncasecmp, strstr,
        memchr, strtok

7 weeks agofeat: guard pages for kernel stacks — detect overflow via page fault
Tulio A M Mendes [Thu, 12 Feb 2026 07:40:52 +0000 (04:40 -0300)]
feat: guard pages for kernel stacks — detect overflow via page fault

Replaced kmalloc(4096) kernel stack allocation with a dedicated
kstack_alloc() that uses a virtual address region (0xC8000000+)
with guard pages. Each stack slot is 2 pages:

  [guard page (unmapped)] [stack page (mapped, 4KB)]

If a kernel stack overflows, the CPU hits the unmapped guard page
and triggers a page fault instead of silently corrupting heap
metadata. This eliminates the class of heap corruption bugs caused
by deep syscall call chains or large stack frames.

All 4 kernel stack allocation sites updated:
- process_init (PID 0)
- process_fork_create
- process_clone_impl
- create_kernel_thread

kstack_free() unmaps the stack page on process exit.

7 weeks agofeat: ulibc extensions for DOOM — mmap, munmap, ioctl, nanosleep, clock_gettime
Tulio A M Mendes [Thu, 12 Feb 2026 07:36:52 +0000 (04:36 -0300)]
feat: ulibc extensions for DOOM — mmap, munmap, ioctl, nanosleep, clock_gettime

Added userspace wrappers required for the DOOM port:
- sys/mman.h + mman.c: mmap() and munmap() for framebuffer mapping
- sys/ioctl.h + ioctl.c: ioctl() for framebuffer info queries
- time.h + time.c: nanosleep() and clock_gettime() for frame timing

All wrappers use the existing INT 0x80 syscall interface.

7 weeks agofeat: /dev/kbd raw scancode device for game input (DOOM)
Tulio A M Mendes [Thu, 12 Feb 2026 07:32:51 +0000 (04:32 -0300)]
feat: /dev/kbd raw scancode device for game input (DOOM)

Added raw scancode ring buffer to the keyboard driver. The HAL
keyboard layer now fires a second callback with the unprocessed
scancode byte (both key-press and key-release events).

- hal/keyboard.h: added hal_keyboard_scan_cb_t and setter
- hal/x86/keyboard.c: fires g_scan_cb before ASCII translation
- drivers/keyboard.c: raw scancode buffer + /dev/kbd device node
  registered via devfs (non-blocking read returns raw scancodes)
- init.c: calls keyboard_register_devfs() after devfs is mounted

DOOM can now open /dev/kbd and read raw PS/2 scancodes to detect
key press/release events without TTY line buffering.

7 weeks agofeat: /dev/fb0 framebuffer device + fd-backed mmap support
Tulio A M Mendes [Thu, 12 Feb 2026 07:26:30 +0000 (04:26 -0300)]
feat: /dev/fb0 framebuffer device + fd-backed mmap support

Added /dev/fb0 device node registered via devfs by vbe.c:
- ioctl: FBIOGET_VSCREENINFO (resolution, bpp), FBIOGET_FSCREENINFO
  (phys addr, pitch, size)
- mmap: maps physical framebuffer into userspace with NOCACHE flags
- read/write: direct pixel buffer access via offset

Extended syscall_mmap_impl to support fd-backed mmap: when
MAP_ANONYMOUS is not set, the file descriptor's node->mmap callback
is invoked. This enables userspace to mmap /dev/fb0 for direct
framebuffer access (required for DOOM).

Marked syscall_mmap_impl as noinline to prevent GCC from merging it
into syscall_handler (4KB kernel stack limit).

7 weeks agorefactor: add ioctl/mmap callbacks to fs_node_t, decouple ioctl dispatch
Tulio A M Mendes [Thu, 12 Feb 2026 07:11:59 +0000 (04:11 -0300)]
refactor: add ioctl/mmap callbacks to fs_node_t, decouple ioctl dispatch

Added ioctl and mmap function pointers to fs_node_t for generic
device dispatch. Refactored syscall_ioctl_impl to call node->ioctl
instead of hardcoding TTY/PTY dispatch by inode number.

- tty.c: added tty_devfs_ioctl wrapper, set on console/tty nodes
- pty.c: added pty_slave_ioctl_fn wrapper, set on all slave nodes
- syscall.c: ioctl now dispatches generically through node callback

This prepares the VFS for /dev/fb0 and other devices that need
ioctl and mmap support.

7 weeks agorefactor: extract generic VMM wrappers from x86 implementation to src/mm/vmm.c
Tulio A M Mendes [Thu, 12 Feb 2026 07:04:21 +0000 (04:04 -0300)]
refactor: extract generic VMM wrappers from x86 implementation to src/mm/vmm.c

Moved vmm_protect_range(), vmm_as_activate(), and vmm_as_map_page()
from src/arch/x86/vmm.c to src/mm/vmm.c. These functions contain only
architecture-independent logic (looping over pages, delegating to HAL
for address space switching).

The x86-specific VMM code (PAE page table manipulation, recursive
mapping, CoW handling, address space create/destroy/clone) remains
in src/arch/x86/vmm.c where it belongs.

This ensures new architectures only need to implement the core
primitives (vmm_init, vmm_map_page, vmm_unmap_page, vmm_set_page_flags,
vmm_as_create_kernel_clone, vmm_as_destroy, vmm_as_clone_user,
vmm_as_clone_user_cow, vmm_handle_cow_fault) and get the wrapper
functions for free.

7 weeks agorefactor: decouple DevFS from TTY/PTY drivers via device registration API
Tulio A M Mendes [Thu, 12 Feb 2026 07:01:14 +0000 (04:01 -0300)]
refactor: decouple DevFS from TTY/PTY drivers via device registration API

Added devfs_register_device() API so device drivers register their own
fs_node_t with DevFS. DevFS is now a generic device registry that
dispatches through function pointers — it no longer includes tty.h or
pty.h and has zero knowledge of TTY/PTY internals.

- tty.c: registers /dev/console and /dev/tty with VFS-compatible wrappers
- pty.c: registers /dev/ptmx and /dev/pts (with finddir/readdir moved
  from devfs.c)
- devfs.c: only owns built-in devices (null, zero, random, urandom);
  all other devices come from the registry

This enables any future driver to register device nodes without
modifying devfs.c.

7 weeks agorefactor: move lwIP port headers from src/net/lwip_port/ to include/net/
Tulio A M Mendes [Thu, 12 Feb 2026 06:46:40 +0000 (03:46 -0300)]
refactor: move lwIP port headers from src/net/lwip_port/ to include/net/

Moved lwipopts.h and arch/cc.h to include/net/ where they belong
alongside other public headers. Updated Makefile include path from
-Isrc/net/lwip_port to -Iinclude/net.

Also fixed cc.h to use arch-conditional BYTE_ORDER instead of
hardcoding x86 little-endian, supporting ARM, RISC-V, and MIPS
targets.

7 weeks agorefactor: extract x86 GDT/GS TLS setup from scheduler to HAL layer
Tulio A M Mendes [Thu, 12 Feb 2026 06:42:19 +0000 (03:42 -0300)]
refactor: extract x86 GDT/GS TLS setup from scheduler to HAL layer

Added hal_cpu_set_tls(base) to the HAL CPU API with x86 implementation
(GDT entry 22 + GS segment load) and a no-op fallback for other arches.

kernel/scheduler.c no longer contains x86 inline assembly for TLS —
the #if defined(__i386__) block is replaced by a single HAL call.

7 weeks agorefactor: extract x86 rdtsc from kernel/kaslr.c to HAL layer
Tulio A M Mendes [Thu, 12 Feb 2026 06:39:37 +0000 (03:39 -0300)]
refactor: extract x86 rdtsc from kernel/kaslr.c to HAL layer

Added hal_cpu_read_timestamp() to the HAL CPU API with x86
implementation using rdtsc and a fallback stub for other arches.

kernel/kaslr.c no longer contains x86 inline assembly — it calls
the generic HAL function for timestamp-based PRNG seeding.

7 weeks agorefactor: extract x86 CMOS I/O from drivers/rtc.c to HAL layer
Tulio A M Mendes [Thu, 12 Feb 2026 06:37:06 +0000 (03:37 -0300)]
refactor: extract x86 CMOS I/O from drivers/rtc.c to HAL layer

Created include/hal/rtc.h with generic HAL RTC interface and
src/hal/x86/rtc.c with x86 CMOS port I/O implementation.

src/drivers/rtc.c is now fully architecture-agnostic: it calls
hal_rtc_read_raw() for hardware access and keeps only the generic
BCD-to-binary conversion and UNIX timestamp calculation logic.

This follows the same HAL pattern used by timer, keyboard, uart,
and video drivers.

7 weeks agofix: add timeout to UART busy-wait in hal_uart_putc()
Tulio A M Mendes [Thu, 12 Feb 2026 06:25:39 +0000 (03:25 -0300)]
fix: add timeout to UART busy-wait in hal_uart_putc()

The UART transmit loop now gives up after ~100k iterations instead
of spinning forever. This prevents the kernel from hanging with
the console spinlock held if the UART hardware is unresponsive,
which would otherwise deadlock all CPUs attempting kprintf (including
panic and debug output paths).

7 weeks agofix: allocate dedicated heap kernel stack for PID 0 (idle task)
Tulio A M Mendes [Thu, 12 Feb 2026 06:23:30 +0000 (03:23 -0300)]
fix: allocate dedicated heap kernel stack for PID 0 (idle task)

PID 0 previously used the boot stack from assembly (_stack_top),
which is not heap-managed. This caused two issues:
- TSS esp0 was not updated when switching to PID 0 (kernel_stack
  was NULL, so the guard in schedule() skipped the update)
- If PID 0 were ever reaped or its stack freed, it would corrupt
  memory since the boot stack is not a kmalloc'd block

Now process_init() allocates a 4KB kernel stack via kmalloc and
sets TSS esp0 to its top, matching the pattern used by all other
processes.

7 weeks agofix: save/restore EFLAGS in context_switch instead of forcing sti after schedule()
Tulio A M Mendes [Thu, 12 Feb 2026 06:21:08 +0000 (03:21 -0300)]
fix: save/restore EFLAGS in context_switch instead of forcing sti after schedule()

context_switch now uses pushf/popf to properly save and restore the
EFLAGS register (including the IF bit) across context switches.
This replaces the unconditional hal_cpu_enable_interrupts() call
after context_switch in schedule(), which broke the interrupt-state
semantics for callers that needed atomicity.

All process creation functions (fork, clone, kernel thread) now push
EFLAGS=0x202 (IF=1) onto the initial stack so new processes start
with interrupts enabled via popf in context_switch.

7 weeks agodocs: update all documentation to reflect 31 completed POSIX tasks
Tulio A M Mendes [Thu, 12 Feb 2026 05:19:17 +0000 (02:19 -0300)]
docs: update all documentation to reflect 31 completed POSIX tasks

- POSIX_ROADMAP.md: mark all 31 tasks complete, add remaining gaps in 3 tiers
- README.md: add ASLR, vDSO, futex, guard pages, FAT16, DNS, zero-copy DMA, RTC, MTRR, ld.so stub; update POSIX score to ~90%
- BUILD_GUIDE.md: add ld.so, expanded ulibc details, updated smoke test list
- SUPPLEMENTARY_ANALYSIS.md: fix ~20 stale table entries, update score 70%->90%, rewrite gaps/recommendations/conclusion
- AUDIT_REPORT.md: mark user stack guard pages as fixed, update fix summary
- TESTING_PLAN.md: update current state to reflect all 4 testing layers operational

7 weeks agofeat: ASLR — TSC-seeded xorshift32 PRNG randomizes user stack base by up to 1MB per...
Tulio A M Mendes [Thu, 12 Feb 2026 04:47:34 +0000 (01:47 -0300)]
feat: ASLR — TSC-seeded xorshift32 PRNG randomizes user stack base by up to 1MB per execve

7 weeks agofeat: userspace ld.so stub — minimal dynamic linker placeholder, built and packed...
Tulio A M Mendes [Thu, 12 Feb 2026 04:42:40 +0000 (01:42 -0300)]
feat: userspace ld.so stub — minimal dynamic linker placeholder, built and packed into initrd as lib/ld.so

7 weeks agofeat: zero-copy DMA I/O — ata_dma_read_direct/ata_dma_write_direct bypass bounce...
Tulio A M Mendes [Thu, 12 Feb 2026 04:36:43 +0000 (01:36 -0300)]
feat: zero-copy DMA I/O — ata_dma_read_direct/ata_dma_write_direct bypass bounce buffer with caller-provided physical address

7 weeks agofeat: FAT16 read-only filesystem driver — BPB parsing, FAT chain traversal, root...
Tulio A M Mendes [Thu, 12 Feb 2026 04:30:56 +0000 (01:30 -0300)]
feat: FAT16 read-only filesystem driver — BPB parsing, FAT chain traversal, root dir finddir, VFS read

7 weeks agofeat: DNS resolver — enable lwIP DNS, kernel dns_resolve() wrapper with async callbac...
Tulio A M Mendes [Thu, 12 Feb 2026 04:24:31 +0000 (01:24 -0300)]
feat: DNS resolver — enable lwIP DNS, kernel dns_resolve() wrapper with async callback + timeout

7 weeks agofeat: vDSO shared page — kernel-updated tick_count mapped read-only into user address...
Tulio A M Mendes [Thu, 12 Feb 2026 04:18:08 +0000 (01:18 -0300)]
feat: vDSO shared page — kernel-updated tick_count mapped read-only into user address space at 0x007FE000

7 weeks agofeat: decay-based scheduler — priority decay on time slice exhaustion, boost on sleep...
Tulio A M Mendes [Thu, 12 Feb 2026 04:13:13 +0000 (01:13 -0300)]
feat: decay-based scheduler — priority decay on time slice exhaustion, boost on sleep wake

7 weeks agofeat: MTRR write-combining support — mtrr_init/mtrr_set_range for variable-range...
Tulio A M Mendes [Thu, 12 Feb 2026 04:09:08 +0000 (01:09 -0300)]
feat: MTRR write-combining support — mtrr_init/mtrr_set_range for variable-range MTRR programming

7 weeks agofeat: flock() syscall (87) — advisory file locking no-op stub + ulibc wrapper
Tulio A M Mendes [Thu, 12 Feb 2026 04:05:00 +0000 (01:05 -0300)]
feat: flock() syscall (87) — advisory file locking no-op stub + ulibc wrapper

7 weeks agofeat: sigaltstack syscall (86) — alternate signal stack per-process (ss_sp/ss_size...
Tulio A M Mendes [Thu, 12 Feb 2026 04:00:34 +0000 (01:00 -0300)]
feat: sigaltstack syscall (86) — alternate signal stack per-process (ss_sp/ss_size/ss_flags)

7 weeks agofeat: futex syscall (85) — FUTEX_WAIT/FUTEX_WAKE with global waiter table + ulibc...
Tulio A M Mendes [Thu, 12 Feb 2026 03:53:40 +0000 (00:53 -0300)]
feat: futex syscall (85) — FUTEX_WAIT/FUTEX_WAKE with global waiter table + ulibc wrapper

7 weeks agofeat: times() syscall (84) — per-process CPU time accounting (utime/stime fields...
Tulio A M Mendes [Thu, 12 Feb 2026 03:49:04 +0000 (00:49 -0300)]
feat: times() syscall (84) — per-process CPU time accounting (utime/stime fields in struct process)

7 weeks agofeat: hard links in diskfs — diskfs_link() with shared storage, nlink tracking, updat...
Tulio A M Mendes [Thu, 12 Feb 2026 03:40:48 +0000 (00:40 -0300)]
feat: hard links in diskfs — diskfs_link() with shared storage, nlink tracking, updated syscall_link_impl

7 weeks agofeat: pmm_alloc_blocks/pmm_free_blocks — contiguous physical page allocation for...
Tulio A M Mendes [Thu, 12 Feb 2026 03:34:23 +0000 (00:34 -0300)]
feat: pmm_alloc_blocks/pmm_free_blocks — contiguous physical page allocation for DMA buffers

7 weeks agofeat: guard pages — 32KB user stack with unmapped guard page below for stack overflow...
Tulio A M Mendes [Thu, 12 Feb 2026 03:30:19 +0000 (00:30 -0300)]
feat: guard pages — 32KB user stack with unmapped guard page below for stack overflow detection

7 weeks agofeat: alarm() syscall (83) — per-process SIGALRM timer via scheduler tick check
Tulio A M Mendes [Thu, 12 Feb 2026 03:25:31 +0000 (00:25 -0300)]
feat: alarm() syscall (83) — per-process SIGALRM timer via scheduler tick check

7 weeks agofeat: RTC driver (CMOS real-time clock) + clock_gettime(CLOCK_REALTIME) uses wall...
Tulio A M Mendes [Thu, 12 Feb 2026 03:20:48 +0000 (00:20 -0300)]
feat: RTC driver (CMOS real-time clock) + clock_gettime(CLOCK_REALTIME) uses wall-clock time

7 weeks agofeat: readv/writev syscalls (81/82) + ulibc sys/uio.h wrappers
Tulio A M Mendes [Thu, 12 Feb 2026 03:14:55 +0000 (00:14 -0300)]
feat: readv/writev syscalls (81/82) + ulibc sys/uio.h wrappers

7 weeks agofeat: ulibc realpath() — resolves '.', '..', relative paths via getcwd
Tulio A M Mendes [Thu, 12 Feb 2026 03:10:44 +0000 (00:10 -0300)]
feat: ulibc realpath() — resolves '.', '..', relative paths via getcwd

7 weeks agofeat: ulibc stdio.h buffered I/O (FILE, fopen/fclose/fread/fwrite/fflush/fgetc/fgets...
Tulio A M Mendes [Thu, 12 Feb 2026 03:07:11 +0000 (00:07 -0300)]
feat: ulibc stdio.h buffered I/O (FILE, fopen/fclose/fread/fwrite/fflush/fgetc/fgets/fputc/fputs/fprintf/vfprintf/feof/ferror, stdin/stdout/stderr)

7 weeks agofeat: sigsuspend syscall (80) — temporarily replace signal mask and block until signa...
Tulio A M Mendes [Thu, 12 Feb 2026 03:02:32 +0000 (00:02 -0300)]
feat: sigsuspend syscall (80) — temporarily replace signal mask and block until signal delivery

7 weeks agofeat: truncate/ftruncate syscalls (78/79) + ulibc wrappers
Tulio A M Mendes [Thu, 12 Feb 2026 02:58:41 +0000 (23:58 -0300)]
feat: truncate/ftruncate syscalls (78/79) + ulibc wrappers

7 weeks agofeat: sigpending, pread/pwrite, access, umask, setuid/setgid syscalls + ulibc wrappers
Tulio A M Mendes [Thu, 12 Feb 2026 02:54:11 +0000 (23:54 -0300)]
feat: sigpending, pread/pwrite, access, umask, setuid/setgid syscalls + ulibc wrappers

- SYSCALL_SIGPENDING (71): returns pending & blocked signal mask
- SYSCALL_PREAD/PWRITE (72/73): positional read/write without altering file offset
- SYSCALL_ACCESS (74): checks file existence (simplified, no real perm check yet)
- SYSCALL_UMASK (75): per-process file creation mask (new umask field in struct process)
- SYSCALL_SETUID/SETGID (76/77): change process uid/gid
- Extract pread/pwrite/access into noinline posix_ext_syscall_dispatch to avoid stack bloat
- ulibc: signal.h sigpending(), unistd.h pread/pwrite/access/setuid/setgid

7 weeks agofeat: O_APPEND support in write() + fcntl F_SETFL
Tulio A M Mendes [Thu, 12 Feb 2026 02:45:09 +0000 (23:45 -0300)]
feat: O_APPEND support in write() + fcntl F_SETFL

7 weeks agofeat: fsync/fdatasync syscall stubs (no-op, POSIX compliance)
Tulio A M Mendes [Thu, 12 Feb 2026 02:40:17 +0000 (23:40 -0300)]
feat: fsync/fdatasync syscall stubs (no-op, POSIX compliance)

7 weeks agofeat: ulibc signal.h with raise(), kill(), sigprocmask() and POSIX signal constants
Tulio A M Mendes [Thu, 12 Feb 2026 02:36:01 +0000 (23:36 -0300)]
feat: ulibc signal.h with raise(), kill(), sigprocmask() and POSIX signal constants

7 weeks agodocs: comprehensive documentation update reflecting all 15 implemented features ...
Tulio A M Mendes [Thu, 12 Feb 2026 02:27:09 +0000 (23:27 -0300)]
docs: comprehensive documentation update reflecting all 15 implemented features (threads, networking, dynamic linking, shell, core utils, permissions, symlinks, PAE+NX, procfs, multi-PTY, VMIN/VTIME)

7 weeks agofeat: dynamic linking infrastructure - PT_INTERP support, ET_DYN validation, elf32_lo...
Tulio A M Mendes [Thu, 12 Feb 2026 02:19:39 +0000 (23:19 -0300)]
feat: dynamic linking infrastructure - PT_INTERP support, ET_DYN validation, elf32_load_interp, ELF dynamic section types, auxiliary vector definitions

7 weeks agofeat: threads (clone/pthread) - SYSCALL_CLONE, SYSCALL_GETTID, SET_THREAD_AREA, proce...
Tulio A M Mendes [Thu, 12 Feb 2026 02:14:24 +0000 (23:14 -0300)]
feat: threads (clone/pthread) - SYSCALL_CLONE, SYSCALL_GETTID, SET_THREAD_AREA, process_clone_create, ulibc pthread stubs

7 weeks agofeat: socket syscalls (socket/bind/listen/accept/connect/send/recv/sendto/recvfrom)
Tulio A M Mendes [Thu, 12 Feb 2026 02:01:31 +0000 (23:01 -0300)]
feat: socket syscalls (socket/bind/listen/accept/connect/send/recv/sendto/recvfrom)

Kernel socket subsystem over lwIP TCP/UDP PCBs with ring-buffer RX,
wait queues for blocking ops, and fd integration via sentinel file
structs (flags=0x534F434B).

Socket dispatch extracted to separate noinline function to prevent
syscall_handler stack overflow that caused heap corruption.

7 weeks agofeat: lwIP TCP/IP stack integration with E1000 netif
Tulio A M Mendes [Wed, 11 Feb 2026 23:43:33 +0000 (20:43 -0300)]
feat: lwIP TCP/IP stack integration with E1000 netif

- third_party/lwip/ added to .gitignore (cloned separately)
- src/net/lwip_port/lwipopts.h: NO_SYS=1 config, IPv4 only, TCP+UDP+ICMP+ARP
- src/net/lwip_port/arch/cc.h: compiler/type defines for lwIP on x86
- src/net/lwip_port/sys_arch.c: sys_now() using kernel tick counter
- src/net/e1000_netif.c: lwIP netif driver bridging E1000 hardware
  net_init() configures IP 10.0.2.15/24, gw 10.0.2.2 (QEMU user-mode)
  net_poll() feeds RX packets to lwIP + processes timeouts
- include/net.h: public API (net_init, net_poll, net_get_netif)
- include/utils.h + src/kernel/utils.c: added memmove, memcmp, strncpy,
  strtol, __memcpy_chk, __ctype_b_loc stubs needed by lwIP
- Makefile: lwIP core+ipv4+ethernet sources compiled with relaxed warnings,
  include paths for lwip_port and lwip/src/include
- src/kernel/main.c: net_poll() in idle loop
- src/kernel/init.c: net_init() after e1000_init()
- 19/19 smoke tests pass, cppcheck clean

7 weeks agofeat: E1000 NIC driver (Intel 82540EM)
Tulio A M Mendes [Wed, 11 Feb 2026 23:33:57 +0000 (20:33 -0300)]
feat: E1000 NIC driver (Intel 82540EM)

- include/e1000.h: register defines, TX/RX descriptor structs, public API
- src/drivers/e1000.c: full E1000 driver implementation
  PCI BAR0 MMIO mapping (128KB at 0xC0230000), bus mastering enabled
  EEPROM MAC address read, TX/RX descriptor ring setup (32 entries each)
  DMA buffer allocation, legacy TX descriptors, interrupt handler
  e1000_send/e1000_recv/e1000_get_mac/e1000_link_up API
- src/arch/x86/arch_platform.c: IOAPIC route IRQ 11 -> vector 43
- src/kernel/init.c: call e1000_init() after pci_init()
- Tested: MAC 52:54:00:12:34:56, IRQ=11, 19/19 smoke tests pass

7 weeks agofeat: PAE paging + NX bit support
Tulio A M Mendes [Wed, 11 Feb 2026 23:21:00 +0000 (20:21 -0300)]
feat: PAE paging + NX bit support

- src/arch/x86/boot.S: complete rewrite for PAE 3-level page tables
  PDPT (4 entries) + 4 PDs (512 entries each) + 8 PTs covering 16MB
  CR4.PAE enabled before paging, recursive mapping via PD[3][508-511]
- src/arch/x86/vmm.c: complete rewrite for 64-bit PAE entries
  New recursive mapping accessors (PD at 0xFFFFC000, PT at 0xFF800000)
  NX bit support (bit 63), VMM_FLAG_NX added
  All address space ops updated: create, clone, destroy, CoW, fault handler
- src/arch/x86/ap_trampoline.S: enable CR4.PAE before paging for APs
- src/arch/x86/elf.c: updated page table check to PAE 64-bit entries
- src/arch/x86/uaccess.c: updated page present/writable checks for PAE
- include/vmm.h: added VMM_FLAG_NX define
- cppcheck clean, 19/19 smoke tests pass

7 weeks agofeat: per-process errno + set_thread_area syscall stub for future TLS
Tulio A M Mendes [Wed, 11 Feb 2026 22:57:23 +0000 (19:57 -0300)]
feat: per-process errno + set_thread_area syscall stub for future TLS

- user/errno.c: documented per-process errno isolation via fork
- include/syscall.h: added SYSCALL_SET_THREAD_AREA(57) for future TLS
- src/kernel/syscall.c: set_thread_area dispatch stub (-ENOSYS)
- True TLS deferred until clone/threads (task #14) is implemented
- cppcheck clean, 19/19 smoke tests pass

7 weeks agofeat: symbolic links (symlink, readlink) and link stub
Tulio A M Mendes [Wed, 11 Feb 2026 22:53:00 +0000 (19:53 -0300)]
feat: symbolic links (symlink, readlink) and link stub

- include/fs.h: added FS_SYMLINK type and symlink_target[128] field to fs_node_t
- include/stat.h: added S_IFLNK define
- include/syscall.h: added SYSCALL_LINK(54), SYSCALL_SYMLINK(55), SYSCALL_READLINK(56)
- src/kernel/fs.c: vfs_lookup follows symlinks with depth limit (max 8)
- src/kernel/tmpfs.c: tmpfs_create_symlink creates FS_SYMLINK nodes
- src/kernel/syscall.c: symlink_impl, readlink_impl, link_impl (stub -ENOSYS)
  stat_from_node reports S_IFLNK for symlink nodes
- cppcheck clean, 19/19 smoke tests pass

7 weeks agofeat: permissions support (uid/gid/mode, chmod, chown, getuid, getgid)
Tulio A M Mendes [Wed, 11 Feb 2026 22:46:34 +0000 (19:46 -0300)]
feat: permissions support (uid/gid/mode, chmod, chown, getuid, getgid)

- include/fs.h: added uid, gid, mode fields to fs_node_t
- include/process.h: added uid, gid fields to struct process
- include/stat.h: added st_uid, st_gid to struct stat, permission bit defines
- include/syscall.h: added SYSCALL_CHMOD(50), SYSCALL_CHOWN(51), SYSCALL_GETUID(52), SYSCALL_GETGID(53)
- src/kernel/syscall.c: chmod_impl, chown_impl, getuid/getgid dispatch; stat_from_node now populates uid/gid/mode
- user/init.c: updated struct stat to match kernel layout
- cppcheck clean, 19/19 smoke tests pass

7 weeks agofeat: /proc per-process directories (/proc/[pid]/status, maps)
Tulio A M Mendes [Wed, 11 Feb 2026 22:39:04 +0000 (19:39 -0300)]
feat: /proc per-process directories (/proc/[pid]/status, maps)

- /proc/[pid]/status: shows Pid, PPid, Pgrp, Session, State, signals, heap
- /proc/[pid]/maps: shows heap range and mmap regions
- /proc root readdir now lists numeric PID entries alongside self/uptime/meminfo
- /proc root finddir resolves numeric names to per-PID directory nodes
- Uses small static pool of fs_node_t (8 slots) for dynamic PID nodes
- proc_find_pid helper iterates ready queue to find process by PID
- cppcheck clean, 19/19 smoke tests pass