riscv64: switch process (#678)

* riscv64: switch process

* fixname
This commit is contained in:
LoGin
2024-03-31 22:53:01 +08:00
committed by GitHub
parent 7d580ef99d
commit 9b96c5b547
5 changed files with 415 additions and 47 deletions

View File

@ -53,7 +53,7 @@ pub(super) fn local_context() -> &'static PerCpuVar<LocalContext> {
///
/// - 从用户态进入内核态时会从sscratch寄存器加载这个结构体的地址到tp寄存器并把sscratch寄存器清零
/// - 从内核态进入用户态时会将tp寄存器的值保存到sscratch寄存器
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub(super) struct LocalContext {
/// 当前cpu的id
pub current_cpu: ProcessorId,
@ -64,7 +64,7 @@ pub(super) struct LocalContext {
}
impl LocalContext {
fn new(cpu: ProcessorId) -> Self {
pub fn new(cpu: ProcessorId) -> Self {
Self {
current_cpu: cpu,
kernel_sp: 0,
@ -102,6 +102,13 @@ impl LocalContext {
// 写入tp寄存器
riscv::register::tp::write(ptr);
}
pub fn restore(&mut self, from: &LocalContext) {
// 不恢复cpu id
self.kernel_sp = from.kernel_sp;
self.user_sp = from.user_sp;
}
}
/// 初始化本地上下文