WASM Execution Pipeline, File Dispatch & Supporting Infrastructure #52

Merged
admin merged 6 commits from feature/wasm into develop 2026-03-07 22:29:31 +00:00
Owner

feature/wasmdevelop

WASM Execution Pipeline, File Dispatch & Supporting Infrastructure

Adds end-to-end WebAssembly program execution to Asuro, from build-chain integration through to runtime I/O and cleanup, along with several supporting subsystems.

New: Wasuro WASM Runtime Integration

  • compile_wasuro.sh - Build script that compiles the Wasuro WASM interpreter (C → .o) and links it into the kernel.
  • wasmrunner.pas (283 lines) - Loads .wasm files from VFS, instantiates modules via Wasuro, and launches them as kernel processes with dedicated stdout/stderr buffers.
  • wasmshim.pas (44 lines) - Pascal-side declarations for the Wasuro C API (wasm_decode, wasm_instantiate, wasm_call, etc.).
  • wasmio.pas (246 lines) - Host-imported I/O functions exposed to WASM guests (fd_write, fd_read, proc_exit, args_sizes_get, environ_sizes_get, etc.).
  • wasmcleanup.pas (290 lines) - Post-execution teardown: frees WASM module memory, linear memory, function tables, and all associated allocations.

New: File Dispatch System

  • filedispatch.pas (178 lines) - Magic-byte-based file type dispatcher. Opens a file, reads header bytes, matches against registered handlers (e.g. \0asm → WASM runner), and launches the appropriate program. Registered as the terminal's fallback command handler.

New: RAM Drive

  • ramdrive.pas (286 lines) - In-memory VFS volume mounted at /disk/ram. Files stored as (name, pointer, size) tuples. Implements TFilesystem hooks (readCallback, readDirCallback, readOffsetCallback, identifyCallback). Includes storeFile/storeFileCopy/removeFile API and auto-loads WASM builtins from FAT32 at boot.

Modified: VFS (vfs.pas)

  • File handle table - new FD-based OpenFile/ReadFile/CloseFile that works with volume-backed paths (removed old Lock parameter).
  • PathValid fix - otDRIVE nodes now correctly identify individual files by splitting the path into parent + leaf, listing the parent via readDirCallback, and checking each entry's type. Previously could only return pvDirectory or pvInvalid.

Modified: Desktop (desktop.pas)

  • Program registry converted from static array[0..MAX_PROGRAMS-1] to dynamic PLinkedListBase with lazy init.
  • Removed prog_count := 0 from init - programs registered before desktop.init (notepad, diskutil, etc.) are no longer wiped.

Modified: System Unit (system.pas)

  • Added memcpy, memset, memmove and various integer/pointer conversion helpers required by the Wasuro C runtime when linked into the Pascal kernel.

Modified: Virtual Terminal (vterminal.pas)

  • WASM stdout/stderr integration - terminal now renders output from WASM process buffers.
  • File dispatch hook - unrecognized commands fall through to filedispatch.dispatchFile.

Other

  • progmanager.pas - Cleaned up duplicate uses clauses; removed invalid kernel.bsod registration; registers WASM builtins and file dispatch.
  • kernel.pas - Added ramdrive.init and filedispatch.init to boot sequence.
  • contextswitcher.pas - Minor preemptive scheduling progress.
  • .gitignore - Added wasuro build artifacts.
  • Removed sha1.pas (moved to separate branch).

17 files changed, +1798 / −281

**`feature/wasm` → `develop`** ## WASM Execution Pipeline, File Dispatch & Supporting Infrastructure Adds end-to-end WebAssembly program execution to Asuro, from build-chain integration through to runtime I/O and cleanup, along with several supporting subsystems. ### New: Wasuro WASM Runtime Integration - **compile_wasuro.sh** - Build script that compiles the Wasuro WASM interpreter (C → `.o`) and links it into the kernel. - **`wasmrunner.pas`** (283 lines) - Loads `.wasm` files from VFS, instantiates modules via Wasuro, and launches them as kernel processes with dedicated stdout/stderr buffers. - **`wasmshim.pas`** (44 lines) - Pascal-side declarations for the Wasuro C API (`wasm_decode`, `wasm_instantiate`, `wasm_call`, etc.). - **`wasmio.pas`** (246 lines) - Host-imported I/O functions exposed to WASM guests (`fd_write`, `fd_read`, `proc_exit`, `args_sizes_get`, `environ_sizes_get`, etc.). - **`wasmcleanup.pas`** (290 lines) - Post-execution teardown: frees WASM module memory, linear memory, function tables, and all associated allocations. ### New: File Dispatch System - **`filedispatch.pas`** (178 lines) - Magic-byte-based file type dispatcher. Opens a file, reads header bytes, matches against registered handlers (e.g. `\0asm` → WASM runner), and launches the appropriate program. Registered as the terminal's fallback command handler. ### New: RAM Drive - **`ramdrive.pas`** (286 lines) - In-memory VFS volume mounted at `/disk/ram`. Files stored as (name, pointer, size) tuples. Implements `TFilesystem` hooks (`readCallback`, `readDirCallback`, `readOffsetCallback`, `identifyCallback`). Includes `storeFile`/`storeFileCopy`/`removeFile` API and auto-loads WASM builtins from FAT32 at boot. ### Modified: VFS (`vfs.pas`) - **File handle table** - new FD-based `OpenFile`/`ReadFile`/`CloseFile` that works with volume-backed paths (removed old `Lock` parameter). - **`PathValid` fix** - `otDRIVE` nodes now correctly identify individual files by splitting the path into parent + leaf, listing the parent via `readDirCallback`, and checking each entry's type. Previously could only return `pvDirectory` or `pvInvalid`. ### Modified: Desktop (desktop.pas) - Program registry converted from static `array[0..MAX_PROGRAMS-1]` to dynamic `PLinkedListBase` with lazy init. - Removed `prog_count := 0` from `init` - programs registered before `desktop.init` (notepad, diskutil, etc.) are no longer wiped. ### Modified: System Unit (`system.pas`) - Added `memcpy`, `memset`, `memmove` and various integer/pointer conversion helpers required by the Wasuro C runtime when linked into the Pascal kernel. ### Modified: Virtual Terminal (`vterminal.pas`) - WASM stdout/stderr integration - terminal now renders output from WASM process buffers. - File dispatch hook - unrecognized commands fall through to `filedispatch.dispatchFile`. ### Other - **`progmanager.pas`** - Cleaned up duplicate uses clauses; removed invalid `kernel.bsod` registration; registers WASM builtins and file dispatch. - **`kernel.pas`** - Added `ramdrive.init` and `filedispatch.init` to boot sequence. - **`contextswitcher.pas`** - Minor preemptive scheduling progress. - **.gitignore** - Added wasuro build artifacts. - Removed `sha1.pas` (moved to separate branch). **17 files changed, +1798 / −281**
admin added 6 commits 2026-03-07 22:17:16 +00:00
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)
- Add compile_wasuro.sh to sparse-clone Wasuro src/wasm from gitea
  (develop branch) with caching to skip redundant pulls
- Update compile.sh to include wasuro build step in pipeline
- Update compile_sources.sh to dynamically discover -Fu paths via
  find across src/ and wasuro/ directories
- Extend system.pas with FPC 3.2.2 compilerprocs required by Wasuro:
  - 64-bit signed/unsigned div and mod (fpc_div_int64, fpc_mod_int64,
    fpc_div_qword, fpc_mod_qword) with correct i386 parameter mapping
  - 64-bit multiply (fpc_mul_int64) via three 32-bit MUL instructions
  - Float-to-integer intrinsics (Trunc, Round) using x87 FPU
  - Memory allocation compilerprocs (fpc_getmem, fpc_freemem)
    delegating to kernel kalloc/kfree
  - Exception handling stubs (reraise, raiseexception, catches, doneexception)
  - setjmp/longjmp for exception address stack
  - Fix sInt64 type alias (was longint/32-bit, now int64/64-bit)
  - Add serial debug helpers (COM1 $3F8) for bare-metal tracing
- Wire up Wasuro in kernel.pas: init WASM VM, set I/O callback to
  syslog, and run all 1103 Wasuro tests (0 failures)
- Update .gitignore to exclude wasuro/ cache directory
- compile_wasuro.sh was copying files to the /code directory which
  is not where drone builds from, fixed to use $(pwd) and relative
  directories based on the root.
- Add file-type dispatch registry (filedispatch.pas) matching files by
  magic header bytes and routing to registered handlers
- Add WASM integration layer: wasmshim, wasmio, wasmrunner, wasmcleanup
  providing full WASI Preview1 bridging (fd_write/read, proc_exit,
  clock, random, args passthrough, environ stubs)
- Add RAM drive (ramdrive.pas) providing in-memory VFS at /disk/ram
  with a built-in hello world WASM binary
- (Placeholder) Implement VFS handle table for proper
  open/read/write/close/filesize routing through registered drives
  and devices
- Integrate file dispatch into vterminal for unknown commands, supporting
  both foreground and background execution of dispatched files
- Expand progmanager init with PS, KILL, TERMINATE, DEV, DISK, MEMRAW,
  BSOD, IFCONFIG, ARP, and TCP commands; wire up ramdrive, filedispatch,
  and wasmrunner initialization
- Replace serial.sendString with syslog.logln in desktop launcher
fix: adapt subsystems to new VFS volume API and fix desktop program registry
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
1ae867d929
- ramdrive: rewrite from registerDrive callbacks to TFilesystem/TStorage_Volume
  hooks (rd_Read, rd_ReadDir, rd_ReadOffset, rd_Identify) and mount via
  vfs.mountVolume('/disk/ram', ...). Remove open-slot tracking; VFS now
  manages file handles through the FD table.

- vfs: fix PathValid for otDRIVE nodes — split relative path into parent
  directory + leaf name, list the parent via readDirCallback, and check
  each entry's type so individual files are correctly identified as pvFile
  instead of always returning pvDirectory or pvInvalid.

- desktop: replace static array[0..MAX_PROGRAMS-1] program registry with
  a dynamic PLinkedListBase. Lazy-init on first registerProgram call.
  Remove prog_count := 0 from init so programs registered before
  desktop.init (e.g. notepad, diskutil) are no longer wiped.

- filedispatch, wasmrunner: add storagetypes to uses, remove stale Lock
  parameter from vfs.OpenFile calls.

- progmanager: clean up duplicate uses clauses and remove invalid
  kernel.bsod registration.
Aaron approved these changes 2026-03-07 22:29:15 +00:00
admin merged commit e922f086c2 into develop 2026-03-07 22:29:31 +00:00
Sign in to join this conversation.