ahrightos-kernel 0.1.0

RISC-V 64 Rust teaching kernel for AhRightOS.
Documentation
#![no_std]
#![no_main]

use core::arch::global_asm;
use core::panic::PanicInfo;
use os::{exit_qemu, hlt_loop, println, QemuExitCode};

// RISC-V 汇编入口点
global_asm!(
    ".section .text.entry",
    ".globl _start",
    "_start:",
    "   la sp, stack_end",
    "   la t0, bss_start",
    "   la t1, bss_end",
    "1:",
    "   bgeu t0, t1, 2f",
    "   sd zero, (t0)",
    "   addi t0, t0, 8",
    "   j 1b",
    "2:",
    "   call test_kernel_main",
    "3:",
    "   wfi",
    "   j 3b",
);

#[no_mangle]
pub extern "C" fn test_kernel_main() -> ! {
    test_main();
    loop {
        hlt_loop();
    }
}

fn test_main() {
    test_runner(&[&test_println]);
}

// 实现测试运行器:执行所有测试用例
fn test_runner(tests: &[&dyn Fn()]) {
    println!("Running {} tests", tests.len());
    for test in tests {
        test();
    }
    exit_qemu(QemuExitCode::Success);
}

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    os::test_panic_handler(info)
}

// 测试用例:验证 println 功能
fn test_println() {
    println!("test_println output");
}