Crate kernel

source ·
Expand description

rust-kernel-riscv is an open-source project that implements an operating system kernel on RISC-V architecture with Rust programming language. The project draws inspiration from several open-source implementations, such as xv6-riscv and zCore.

  • The kernel leverages Rust’s asynchronous programming model to schedule threads in both the kernel and user space, which makes context switching more efficient and eliminates the need of allocating a separate kernel stack for each user process.

  • The kernel implements the kernel page-table isolation, which prevents the kernel space and the user space to share a same page table and mitigates potential Meltdown attacks.

Modules

  • console 🔒
    The console module contains functions that interacts with the debug console. It exports useful macros such as print! and println!.
  • constant 🔒
    The constant module defines several parameters for the kernel.
  • executor 🔒
    The executor module provides an executor that schedules and runs both the kernel threads and the user threads.
  • file 🔒
  • lang_items 🔒
    The lang_items module contains Rust lang items. Rust lang items are functionalities that isn’t hard-coded into the language, but is implemented in libraries, with a special marker to tell the compiler it exists. Since the kernel doesn’t depend on the std crate, it has to implement some lang items, such as the panic_handler.
  • logging 🔒
    The logging module implements the log::Log trait.
  • mem 🔒
  • sbi 🔒
    The sbi module contains functions that invokes the RISC-V interface. SBI is an interface between the Supervisor Execution Environment and the supervisor. It allows the supervisor to execute some privileged operations with the ecall instruction. For more details, please refer to the RISC-V SBI Specification.
  • sync 🔒
    The sync module provides synchronization primitives for concurrent programming.
  • syscall 🔒
    The syscall module provides system calls for interacting with the operating system.
  • task 🔒
    The task module provides types for representing processes and threads.
  • timer 🔒
    The timer module provides functions to configure the timer interrupt.

Macros

  • Print to the debug console.
  • Print to the debug console, with a newline.

Functions

  • bss_end 🔒
    The bss_end is a symbol declared in the src/linker.ld, which represent the end address of the .bss section.
  • bss_start 🔒
    The bss_start is a symbol declared in the src/linker.ld, which represent the start address of the .bss section.
  • clear_bss 🔒
    Initializes the .bss section with zeros.
  • Initializes the thread executor and spawns the INIT_PROCESS.