feature: preemptive process management & TCP/IP barebones #41

Merged
t3hn3rd merged 4 commits from feature/process-management into develop 2026-03-04 20:04:27 +00:00
Owner

Process Management:

  • Add processmanager.pas: process table (DList), create/find/send/terminate/kill
    APIs, round-robin scheduler with priority-based quantum (priority * 8 ticks)
  • Add proctypes.pas: TProcessContext, TProcessState (Created/Running/Ready/
    Suspended/Awaiting/Finished), TProcessSysMsg, TResourceBinding for per-process
    resource cleanup
  • Add contextswitcher.pas: naked IRQ0 ISR that saves full register context
    (PUSHAD + segment regs), calls scheduler, switches ESP, IRETD into next process
  • Per-process 8KB kernel stacks with fake interrupt frame for first context switch
  • Process self-management: proc_yield, proc_sleep_ms, proc_await, proc_suspend,
    proc_exit
  • Resource binding system with automatic cleanup on process death
  • Idle process (PID 0) as scheduler fallback
  • PS, KILL, TERMINATE terminal commands
  • Reaper for finished processes

TCP (RFC 793) - Started Implementation (merged in from feature/tcp):

  • Full TCP implementation (1881 lines): connect/listen/accept/send/close/abort
  • 3-way handshake, FIN/RST teardown, TIME_WAIT (60s)
  • Retransmission with configurable RTO (1-60s), SYN retransmit (3s)
  • Delayed ACK (~200ms), keepalive probes (30s idle, 10s interval, 5 probes)
  • Zero-window probing (exponential backoff 1-60s)
  • Congestion control: initial CWND (3 segments), MSS negotiation
  • Out-of-order segment buffering (4 slots)
  • TCP pseudo-header checksum per RFC 793
  • TCPCONNECT, TCPLISTEN, TCPHTTP terminal commands

VTerminal Rewrite:

  • Multi-instance: each terminal is a heap-allocated TVTermState process with
    it's own LVGL widgets, scrollback buffer (4KB), input line (1KB) &
    command history (10 entries)
  • Commands execute as preemptive processes via processmanager.runCommand
  • Per-instance LVGL drain timer polls foreground process stdout/stderr
  • Background job support: launch with &, JOBS command, auto-reap on completion
  • Ctrl+C support: LV_KEY_CTRLC injected from LVGL keyboard handler, terminates
    foreground process
  • Per-terminal working directory with filesystem builtins: CD, LS, PUSHD, POPD
  • Directory commands moved from global VFS registration to per-terminal builtins

Supporting Changes:

  • vfs.pas: add makeAbsolutePathFrom, resolvePathFrom, GetDirectoryListingFrom,
    changeDirectoryFrom for per-terminal CWD support; remove global LS/CD commands
  • lvgl.pas: add LV_KEY_CTRLC (128), Ctrl+C keyboard intercept
  • isrmanager.pas: dispatchHooks exposed for context switcher
  • testprocs.pas: test process entry points for scheduler validation
  • ping.pas, testcmd.pas: new terminal programs
  • progmanager.pas: register new programs (ping, testcmd, tcp commands)
  • Minor fixes: nettypes.pas expanded, net/eth2/arp/ipv4/udp/icmp/dhcp adjusted
    for TCP integration, storagemanagement/drivermanagement/cpu minor updates
Process Management: - Add processmanager.pas: process table (DList), create/find/send/terminate/kill APIs, round-robin scheduler with priority-based quantum (priority * 8 ticks) - Add proctypes.pas: TProcessContext, TProcessState (Created/Running/Ready/ Suspended/Awaiting/Finished), TProcessSysMsg, TResourceBinding for per-process resource cleanup - Add contextswitcher.pas: naked IRQ0 ISR that saves full register context (PUSHAD + segment regs), calls scheduler, switches ESP, IRETD into next process - Per-process 8KB kernel stacks with fake interrupt frame for first context switch - Process self-management: proc_yield, proc_sleep_ms, proc_await, proc_suspend, proc_exit - Resource binding system with automatic cleanup on process death - Idle process (PID 0) as scheduler fallback - PS, KILL, TERMINATE terminal commands - Reaper for finished processes TCP (RFC 793) - Started Implementation (merged in from feature/tcp): - Full TCP implementation (1881 lines): connect/listen/accept/send/close/abort - 3-way handshake, FIN/RST teardown, TIME_WAIT (60s) - Retransmission with configurable RTO (1-60s), SYN retransmit (3s) - Delayed ACK (~200ms), keepalive probes (30s idle, 10s interval, 5 probes) - Zero-window probing (exponential backoff 1-60s) - Congestion control: initial CWND (3 segments), MSS negotiation - Out-of-order segment buffering (4 slots) - TCP pseudo-header checksum per RFC 793 - TCPCONNECT, TCPLISTEN, TCPHTTP terminal commands VTerminal Rewrite: - Multi-instance: each terminal is a heap-allocated TVTermState process with it's own LVGL widgets, scrollback buffer (4KB), input line (1KB) & command history (10 entries) - Commands execute as preemptive processes via processmanager.runCommand - Per-instance LVGL drain timer polls foreground process stdout/stderr - Background job support: launch with &, JOBS command, auto-reap on completion - Ctrl+C support: LV_KEY_CTRLC injected from LVGL keyboard handler, terminates foreground process - Per-terminal working directory with filesystem builtins: CD, LS, PUSHD, POPD - Directory commands moved from global VFS registration to per-terminal builtins Supporting Changes: - vfs.pas: add makeAbsolutePathFrom, resolvePathFrom, GetDirectoryListingFrom, changeDirectoryFrom for per-terminal CWD support; remove global LS/CD commands - lvgl.pas: add LV_KEY_CTRLC (128), Ctrl+C keyboard intercept - isrmanager.pas: dispatchHooks exposed for context switcher - testprocs.pas: test process entry points for scheduler validation - ping.pas, testcmd.pas: new terminal programs - progmanager.pas: register new programs (ping, testcmd, tcp commands) - Minor fixes: nettypes.pas expanded, net/eth2/arp/ipv4/udp/icmp/dhcp adjusted for TCP integration, storagemanagement/drivermanagement/cpu minor updates
t3hn3rd added this to the 2.0.0 milestone 2026-03-04 19:56:59 +00:00
t3hn3rd added the ImprovementFeature
Component
Userspace
labels 2026-03-04 19:56:59 +00:00
t3hn3rd self-assigned this 2026-03-04 19:56:59 +00:00
t3hn3rd added 4 commits 2026-03-04 19:57:00 +00:00
Add full TCP/IP stack implementation at L4 alongside UDP and ICMP.

Core Protocol Engine:
- TCP types in nettypes.pas (header, TCB, state enum, error codes,
  callbacks, OOO entry, socket structures)
- 3-way handshake (active & passive OPEN)
- Reliable data transfer with ACK and sequence number tracking
- Graceful close (FIN_WAIT, CLOSE_WAIT, LAST_ACK, TIME_WAIT)
- RST send/receive handling
- Retransmission with exponential backoff (max 5 attempts)
- Pseudo-header based checksum (RFC 793)

Server Support:
- LISTEN → SYN_RECEIVED → ESTABLISHED passive open path
- Listen backlog enforcement (configurable per-socket)
- accept() to retrieve established child connections

Robustness & Hardening:
- Delayed ACK timer (~200ms)
- Nagle's algorithm (buffer small sends while unACKed data pending)
- Jacobson/Karels RTT estimation with adaptive RTO
- Congestion control (slow start / congestion avoidance)
- Zero-window probing with exponential backoff
- MSS option negotiation in SYN/SYN-ACK (Kind=2, Len=4)
- Keep-alive (30s idle, 10s interval, 5 probes)
- Out-of-order segment reassembly (4-slot buffer)

Terminal & Testing:
- tcpconnect: active open + send "Hello, World!"
- tcplisten: passive open with syslog output
- tcphttp: HTTP/1.0 GET client

Also add push_trace() instrumentation to net, eth2, arp, ipv4,
icmp, udp, and dhcp entry points for call tracing, and register
tcp in net.init.
Implement a preemptive multitasking system for the Asuro kernel.

Context Switching & Scheduling:
- Custom IRQ0 ISR (contextswitcher.pas) with PUSHAD/POPAD ESP-swap
- Round-robin scheduler with priority-based quantum
- Process table using DList of PProcessContext pointers
- Idle process (PID 0) replaces kernel HLT loop

Process Lifecycle:
- create/kill/terminate/sendMessage API (processmanager.pas)
- Process states: Created, Running, Ready, Suspended, Awaiting,
  Finished, Error
- Parent-child tracking (ParentID, smChildExited notification on reap)
- proc_yield, proc_sleep_ms, proc_await, proc_suspend, proc_exit

Resource Binding & Cleanup:
- Per-process resource list
  (bindResource/unbindResource/unbindAllResources)
- TCP sockets auto-bound to owning process (OwnerPID on TTCPSocket)
- socket_cleanup + auto-unbind in DestroySocket

VTerminal Refactor:
- Multi-instance design (heap-allocated TVTermState per terminal)
- Foreground process with incremental stdout/stderr drain via LVGL timer
- Ctrl+C kills foreground process (killForeground)
- Per-terminal CWD, dir stack, FS builtins (CD/LS/PUSHD/POPD)
- Background job support (& suffix, JOBS/FG commands)
- Command history (Up/Down arrow)

Command Consolidation:
- 14 commands extracted from 9 units into centralized progmanager.pas
- Command procedures exported in host unit interfaces
- E1000/TRACER/stdio builtins kept in-place (conditional/circular)

New Units:
- src/include/proctypes.pas — process type definitions
- src/processmanager.pas — core process manager
- src/prog/ping.pas — standalone ICMP ping process
- src/prog/testcmd.pas — test command (proc_sleep_ms demo)
- src/testprocs.pas — process subsystem smoke tests

Misc:
- ICMP callbacks gain userData parameter for concurrency-safe ping
- CLI/STI guards on kalloc/kfree (lmemorymanager.pas)
- LV_KEY_CTRLC constant + Ctrl+C interception in LVGL keyboard hook
- Window owner PID tracking (windows.pas)
- ISR_32 gate override support (isrmanager.pas)
rebase fix: stdio.registerCommand('BSOS') removed from progmanager.pas
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
d01b534a3d
- This can sit in kernel for now, given that's where the handler is.
- TODO: Move everything to sit under prog/
t3hn3rd requested review from Aaron 2026-03-04 19:57:00 +00:00
Aaron approved these changes 2026-03-04 20:04:01 +00:00
t3hn3rd merged commit 9fa1c859ac into develop 2026-03-04 20:04:27 +00:00
Sign in to join this conversation.