Skip to content

Implement XHCI USB Driver in pure C#5

Open
rtech-technologies wants to merge 7 commits into
sovereign-core-expansion-2313558312167675719from
xhci-c-driver-port-9158994455323184841
Open

Implement XHCI USB Driver in pure C#5
rtech-technologies wants to merge 7 commits into
sovereign-core-expansion-2313558312167675719from
xhci-c-driver-port-9158994455323184841

Conversation

@rtech-technologies

Copy link
Copy Markdown
Owner

This PR ports the XHCI USB controller driver from its original C++ implementation to pure C, specifically adapted for the OSx2 Limemade Kernel.

Key improvements and adaptations:

  • Translated all class structures and member functions to C structs and standalone functions.
  • Replaced C++ standard library/custom classes (Vector, Semaphore) with kernel-specific mechanisms.
  • Added explicit volatile qualifiers to hardware-facing structures to prevent compiler optimizations.
  • Enhanced PCI BAR discovery to support 64-bit addressing.
  • Properly integrated the driver's interrupt handler into the kernel's IDT.
  • Ensured 4KB alignment for hardware rings and buffers using pmm_alloc.
  • Validated that the kernel builds correctly with the new driver integration.

PR created automatically by Jules for task 9158994455323184841 started by @rtech-technologies

- Created `kernel/libs/storage/xhci.h` with XHCI hardware structures
- Ported driver logic to `kernel/libs/storage/usb_xhci.c`
- Implemented command and event ring management
- Added support for BIOS handover and 64-bit PCI BARs
- Integrated with kernel service model and interrupt handling
- Enforced volatile access for hardware registers
- Verified kernel compilation

Co-authored-by: rtech-technologies <254326487+rtech-technologies@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 6 commits April 19, 2026 18:55
- Defined volatile hardware structures in xhci.h
- Implemented 64-bit BAR detection and BIOS handover
- Integrated with kernel tasking via usb_sovereign_task
- Registered IRQ handler on vector 43
- Ensured proper memory alignment for hardware contexts

Co-authored-by: rtech-technologies <254326487+rtech-technologies@users.noreply.github.com>
- Ported XHCI driver from C++ to pure C.
- Implemented hardware initialization, ring management, and BIOS handover.
- Added support for 64-bit PCI BARs and ensured volatile hardware access.
- Implemented USB device enumeration and descriptor fetching.
- Created unified input buffer in console.c to support PS/2 and USB Keyboard.
- Implemented background usb_sovereign_task for asynchronous event processing.
- Verified kernel compilation and addressed code review feedback.

Co-authored-by: rtech-technologies <254326487+rtech-technologies@users.noreply.github.com>
This commit transitions the XHCI driver from C++ to pure C, ensuring
compatibility with the kernel's freestanding environment.

Key changes:
- XHCI: Implemented atomic spinlocks for controller synchronization,
  fixed ring management, and implemented the BIOS handover protocol.
- USB Mass Storage: Implemented the Bulk-Only Transport (BOT) protocol
  with CBW/Data/CSW stages and signature verification.
- NVMe: Implemented a functional NVMe driver with Admin and I/O queue
  setup and sector read support using phase-bit polling.
- UI/Safety: Enhanced vga_serial.c with framebuffer height checks and
  telemetry output stabilization.
- Core: Added a spinlock implementation in kernel/libs/core/lock.c.

All changes have been verified to compile and link correctly within
the OSx2 build system.

Co-authored-by: rtech-technologies <254326487+rtech-technologies@users.noreply.github.com>
This commit provides a comprehensive update to the OSx2 storage and
core infrastructure:

- XHCI: Ported from C++ to pure C with atomic spinlock synchronization.
  Implemented the Bulk-Only Transport (BOT) protocol for Mass Storage.
- NVMe: Added functional support including Admin/IO queue setup and
  polled reads with safety timeouts.
- AHCI/ATAPI: Resolved linker errors and added hardware auditing.
- Syscalls: Fixed a critical bug in interrupts.s where registers were
  corrupted during syscalls; all caller-saved registers are now
  preserved.
- UI/VGA: Added framebuffer bounds-checking and stabilized telemetry.
- Tasking: Reverted to a 3-task baseline for enhanced stability during
  hardware discovery.
- Panic: Hardened the panic handler to avoid nested faults.

Co-authored-by: Jules <jules@rtech.com>

Co-authored-by: rtech-technologies <254326487+rtech-technologies@users.noreply.github.com>
This commit provides a comprehensive update to the OSx2 storage and
core infrastructure on the target branch:

- XHCI: Ported from C++ to pure C with atomic spinlock synchronization.
  Implemented the Bulk-Only Transport (BOT) protocol for Mass Storage.
- NVMe: Added functional support including Admin/IO queue setup and
  polled reads with safety timeouts.
- AHCI/ATAPI: Resolved linkage issues and added hardware auditing.
- Syscalls: Fixed register corruption in interrupts.s; all caller-saved
  registers (rax, rcx, rdx, rsi, rdi, r8-r11) are now preserved.
- UI/VGA: Added framebuffer bounds-checking and stabilized telemetry.
- Stability: Hardened the panic handler and restored 3-task baseline.

All changes verified to compile and link correctly.

Co-authored-by: rtech-technologies <254326487+rtech-technologies@users.noreply.github.com>
- Architecture: Restructured kernel into a modular KSDK (Kernel Software Development Kit).
- XHCI: Ported driver to C and implemented USB Mass Storage BOT protocol.
- NVMe: Implemented functional Admin/IO queues and sector reads with safety timeouts.
- Core: Fixed syscall register corruption and hardened panic/tasking systems.
- UI: Added vertical bounds-checking to VGA rendering for system stability.

Verified build and linkage on the RTECH ahci-refactor branch.

Co-authored-by: rtech-technologies <254326487+rtech-technologies@users.noreply.github.com>
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