Skip to content

Add interrupt-driven console I/O and Rust std userland support#27

Merged
codingskynet merged 1 commit into
mainfrom
feat/interrupt-refactoring
Jul 22, 2026
Merged

Add interrupt-driven console I/O and Rust std userland support#27
codingskynet merged 1 commit into
mainfrom
feat/interrupt-refactoring

Conversation

@codingskynet

Copy link
Copy Markdown
Owner

Summary

This PR adds interrupt-driven console input, thread parking and wake-up support, timer-based sleep, PLIC integration, and a Rust standard library port for userland applications.

Highlights

  • Add SMP-safe thread parking and wake-up handling
  • Prevent lost wake-ups during the running-to-parked transition
  • Add monotonic timer waits and a userland sleep syscall
  • Add PLIC discovery and supervisor external interrupt handling
  • Convert console input from polling to interrupt-driven reads
  • Add RX/TX buffering for the kernel console
  • Discover console and PLIC MMIO regions from the device tree
  • Support stdout-path aliases and console option suffixes
  • Match supported drivers against the complete compatible string list
  • Add an SMP-safe LazyLock for boot-time global initialization
  • Port Rust std to the userland syscall ABI
  • Add a Rust std demo covering allocation, collections, file I/O, output, and sleep
  • Add selective port submodule initialization
  • Verify existing port checkouts before updating their submodules
  • Extend CI and QEMU smoke coverage for the new functionality

Concurrency and interrupt behavior

The scheduler now maintains separate ready and parked thread collections. Each thread owns a waker that records notifications before attempting to move the thread back to the ready queue.

This covers wake-ups occurring:

  • Before a thread begins parking
  • During the parking ownership handoff
  • Immediately before or after insertion into the parked-thread map
  • While the thread is already parked

Console reads register their waker while holding the console lock, preventing a race between checking for available input and subscribing to the receive event.

Timer and external interrupt handlers wake parked threads and allow the scheduler to run newly ready work.

Device tree support

  • Parse console MMIO and interrupt configuration from /chosen/stdout-path
  • Resolve aliases such as serial0:115200n8 through /aliases
  • Parse complete compatible string lists
  • Discover PLIC MMIO, interrupt sources, and per-hart supervisor contexts
  • Map console and PLIC MMIO regions during boot

Rust standard library port

The Rust port reuses the pinned host compiler and builds the target standard library for the custom userland ABI.

Currently supported functionality includes:

  • Heap allocation through dlmalloc
  • Standard output and error
  • Standard input
  • Read-only init archive files
  • Collections and other alloc functionality
  • std::thread::sleep
  • Process exit and abort

OS thread creation and writable files remain unsupported.

Validation

  • Host unit tests: 36 passed
  • RV64 cargo check: passed
  • RV64 Clippy with -D warnings: passed
  • Typo checks: passed
  • Port patch reproduction: passed
  • Four-hart QEMU smoke tests: passed
  • Kernel thread scheduling and floating-point context switching: passed
  • Rust std userland demo: passed
  • Timer sleep syscall: passed
  • Interrupt-driven MicroPython console input: passed
  • No kernel panic observed during smoke testing

Assisted-by: openai/gpt-5.6-sol
@codingskynet
codingskynet merged commit fbe95a5 into main Jul 22, 2026
2 checks passed
@codingskynet
codingskynet deleted the feat/interrupt-refactoring branch July 22, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant