ahrightos-kernel 0.1.0

RISC-V 64 Rust teaching kernel for AhRightOS.
Documentation
//! Context switch assembly — bootstrap only.
//!
//! Runtime context switches are handled through TrapFrame in
//! `process::scheduler_tick`; the old `__switch_context` is no
//! longer needed.
//!
//! ProcessContext layout (repr(C)):
//!   offset   0..248: x[31] — GPRs x1-x31 (skipping x0)
//!   offset 248:       sepc: usize
//!   offset 256:       sstatus: usize
//!   offset 264:       satp: usize

use core::arch::global_asm;

global_asm!(
    ".section .text.switch, \"ax\"",

    // ── __start_first_task ───────────────────────────────────────
    // a0 = *const ProcessContext
    // Bootstraps the very first task — no save needed.
    // sscratch must be set by the caller to point to the top of the
    // kernel stack (see process::start_first_task).
    ".globl __start_first_task",
    "__start_first_task:",

    "   mv t6, a0",

    // Restore CSRs
    "   ld t0, {satp_offset}(t6)",
    "   csrw satp, t0",
    "   sfence.vma",

    "   ld t0, {sstatus_offset}(t6)",
    "   csrw sstatus, t0",

    "   ld t0, {sepc_offset}(t6)",
    "   csrw sepc, t0",

    // Restore GPRs
    "   ld x1, 0(t6)",
    "   ld x2, 8(t6)",
    "   ld x3, 16(t6)",
    "   ld x4, 24(t6)",
    "   ld x5, 32(t6)",
    "   ld x6, 40(t6)",
    "   ld x7, 48(t6)",
    "   ld x8, 56(t6)",
    "   ld x9, 64(t6)",
    "   ld x10, 72(t6)",
    "   ld x11, 80(t6)",
    "   ld x12, 88(t6)",
    "   ld x13, 96(t6)",
    "   ld x14, 104(t6)",
    "   ld x15, 112(t6)",
    "   ld x16, 120(t6)",
    "   ld x17, 128(t6)",
    "   ld x18, 136(t6)",
    "   ld x19, 144(t6)",
    "   ld x20, 152(t6)",
    "   ld x21, 160(t6)",
    "   ld x22, 168(t6)",
    "   ld x23, 176(t6)",
    "   ld x24, 184(t6)",
    "   ld x25, 192(t6)",
    "   ld x26, 200(t6)",
    "   ld x27, 208(t6)",
    "   ld x28, 216(t6)",
    "   ld x29, 224(t6)",
    "   ld x30, 232(t6)",
    "   ld x31, 240(t6)",

    "   sret",
    satp_offset = const super::PROCESS_CONTEXT_SATP_OFFSET,
    sstatus_offset = const super::PROCESS_CONTEXT_SSTATUS_OFFSET,
    sepc_offset = const super::PROCESS_CONTEXT_SEPC_OFFSET,
);

extern "C" {
    pub fn __start_first_task(ctx: *const super::ProcessContext);
}