Skip to main content

Crate tg_sbi

Crate tg_sbi 

Source
Expand description

§tg-sbi

为 rCore 教学操作系统提供的 SBI (Supervisor Binary Interface) 调用封装。

§Features

  • nobios: 启用内置的 M-Mode SBI 实现,用于 -bios none 启动模式。 启用此 feature 后,crate 将提供自己的 M-Mode 陷阱处理程序和基本 SBI 服务。

§支持的 SBI 扩展

  • Legacy 控制台 I/O (EID 0x01, 0x02)
  • Timer 扩展 (EID 0x54494D45)
  • System Reset 扩展 (EID 0x53525354)

§Example

use tg_sbi::{console_putchar, set_timer, shutdown};

// 输出字符
console_putchar(b'H');

// 设置定时器中断
set_timer(1000000);

// 关闭系统
shutdown(false);

§调用链(学习者重点)

对于章节内核调用 tg_sbi 接口时,整体链路如下:

  1. chX 内核代码调用 set_timer/console_putchar/shutdown
  2. 本文件的 sbi_call()ecall 发起 SBI 请求
  3. 若未开启 nobios:请求进入外部 SBI 固件(例如 RustSBI)
  4. 若开启 nobios:请求进入本 crate 的 m_entry.asm + msbi.rs
  5. M-mode 处理完成后,返回到 S-mode 内核继续执行

这使得上层章节代码不需要关心“外部固件”还是“内置最小 SBI”, 只需面向统一 API 编程即可。

Functions§

console_getchar
从调试控制台读取一个字符。
console_putchar
向调试控制台输出一个字符。
set_timer
设置下一次定时器中断的时间。
shutdown
关闭系统。