Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv64: switch process #678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ x86_64 = "=0.14.10"

# target为riscv64时,使用下面的依赖
[target.'cfg(target_arch = "riscv64")'.dependencies]
riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", revision = "79d27d0f3a", features = [ "s-mode" ] }
riscv = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/riscv.git", revision = "01fc40d", features = [ "s-mode" ] }
sbi-rt = { version = "=0.0.3", features = ["legacy"] }


Expand Down
11 changes: 9 additions & 2 deletions kernel/src/arch/riscv64/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
}

/// 初始化本地上下文
Expand Down
72 changes: 36 additions & 36 deletions kernel/src/arch/riscv64/interrupt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,44 @@ impl InterruptArch for RiscV64InterruptArch {
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct TrapFrame {
epc: usize,
ra: usize,
sp: usize,
gp: usize,
tp: usize,
t0: usize,
t1: usize,
t2: usize,
s0: usize,
s1: usize,
a0: usize,
a1: usize,
a2: usize,
a3: usize,
a4: usize,
a5: usize,
a6: usize,
a7: usize,
s2: usize,
s3: usize,
s4: usize,
s5: usize,
s6: usize,
s7: usize,
s8: usize,
s9: usize,
s10: usize,
s11: usize,
t3: usize,
t4: usize,
t5: usize,
t6: usize,
pub epc: usize,
pub ra: usize,
pub sp: usize,
pub gp: usize,
pub tp: usize,
pub t0: usize,
pub t1: usize,
pub t2: usize,
pub s0: usize,
pub s1: usize,
pub a0: usize,
pub a1: usize,
pub a2: usize,
pub a3: usize,
pub a4: usize,
pub a5: usize,
pub a6: usize,
pub a7: usize,
pub s2: usize,
pub s3: usize,
pub s4: usize,
pub s5: usize,
pub s6: usize,
pub s7: usize,
pub s8: usize,
pub s9: usize,
pub s10: usize,
pub s11: usize,
pub t3: usize,
pub t4: usize,
pub t5: usize,
pub t6: usize,
// 以下是中断发生时自动保存的寄存器
status: Sstatus,
badaddr: usize,
cause: Scause,
pub status: Sstatus,
pub badaddr: usize,
pub cause: Scause,
/// a0 value before the syscall
origin_a0: usize,
pub origin_a0: usize,
}

impl TrapFrame {
Expand Down
Loading
Loading