Porting Hubris OS to RISC-V would be trivial compared to porting most operating systems because Hubris was explicitly designed with architecture portability in mind. The documentation already includes RISC-V specifications, and the architecture-specific code is minimal and well-isolated.
Hubris follows a microkernel philosophy where the kernel does as little as possible:
All architecture-specific code is isolated in a single module:
// sys/kern/src/arch.rs - Current structure cfg_if::cfg_if! { if #[cfg(target_arch = "arm")] { pub mod arm_m; pub use arm_m::*; } else { compile_error!("support for this architecture not implemented"); } }
Adding RISC-V support requires only:
// Proposed addition } else if #[cfg(target_arch = "riscv32")] { pub mod riscv; pub use riscv::*; } else {
The Hubris documentation already includes RISC-V specifications:
=== RISC-V Syscalls are invoked using the `ECALL` instruction. The rest is TBD.
silicon vendors -- the `SysTick` on ARM, the `mtimer` on RISC-V. Hubris provides a multiplexer for this timer, so that each task appears to have its own.
Hubris port, but these ideas are intended to translate to RISC-V systems using controllers like the PLIC.
The documentation specifies what any architecture port needs:
ECALL equivalent to ARM's SVCmtimer equivalent to ARM SysTickBased on the existing ARM implementation (sys/kern/src/arch/arm_m.rs - 1901 lines):
| Component | Estimated Lines | Complexity | ARM Equivalent |
|---|---|---|---|
| Context switching | ~300 | Medium | Save/restore x1-x31 vs r0-r15 |
| Syscall entry | ~200 | Low | ECALL handler vs SVC handler |
| Timer integration | ~100 | Low | mtimer vs SysTick |
| Memory protection | ~200 | Medium | PMP setup vs MPU setup |
| Interrupt routing | ~200 | Low | PLIC vs NVIC |
| Task state management | ~500 | Medium | TCB save/restore |
| Boot sequence | ~100 | Low | Reset handler |
| Utilities/macros | ~300 | Low | Architecture helpers |
| Total | ~1900 | Low-Medium | Direct translation |
Current ARM Syscall Convention:
r4 through r10 (7 args)r11r4 through r11 (8 returns)Proposed RISC-V Convention:
x10-x16 (a0-a6) (7 args)x17 (a7)x10-x17 (a0-a7) (8 returns)// Required architecture interface (based on ARM module) pub fn apply_memory_protection(task: &Task) -> Result<(), FaultInfo>; pub fn start_task(task: &Task) -> !; pub fn save_task_state(task: &mut Task); pub fn restore_task_state(task: &Task); pub fn current_task_ptr() -> *const Task; pub fn set_current_task_ptr(task: *const Task); pub fn usermode_entry_point() -> u32; pub fn get_task_dump_area() -> &'static mut [u8];