tg-kernel-context 0.1.0-preview.1

Kernel context management for rCore tutorial OS, including task context switching.
Documentation
  • Coverage
  • 100%
    18 out of 18 items documented0 out of 15 items with examples
  • Size
  • Source code size: 24.96 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 182.56 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • chyyuu DeathWish5 Ivans-11

tg-kernel-context

Kernel context management for the rCore tutorial operating system.

Overview

This crate provides context switching primitives for RISC-V based kernel development. It handles the low-level details of saving and restoring CPU state during context switches between kernel and user space.

Features

  • LocalContext: Thread context structure containing all general-purpose registers, program counter, and control flags
  • Context switching: Assembly-based efficient context switch implementation
  • Foreign address space support: Optional support for context switching across different address spaces (via foreign feature)
  • no_std compatible: Designed for bare-metal kernel environments

Usage

use tg_kernel_context::LocalContext;

// Create a user-mode context with entry point
let ctx = LocalContext::user(entry_point);

// Create a kernel thread context
let ctx = LocalContext::thread(entry_point, true);

// Execute the context (unsafe - modifies CPU state)
unsafe {
    let sstatus = ctx.execute();
}

Features

  • foreign - Enable support for context switching across different address spaces

Safety

The execute method is unsafe as it directly manipulates critical CSRs (sscratch, sepc, sstatus, stvec) and performs a privilege level switch.

License

Licensed under either of MIT license or Apache License, Version 2.0 at your option.