feat: 批处理操作系统 (#1)

Reviewed-on: #1
This commit is contained in:
2024-07-19 13:52:36 +08:00
parent 8eba5a3d9b
commit 265e7adedf
26 changed files with 559 additions and 37 deletions

28
os/src/trap/context.rs Normal file
View File

@@ -0,0 +1,28 @@
use riscv::register::sstatus::{self, Sstatus, SPP};
#[repr(C)]
pub struct TrapContext {
pub x: [usize; 32],
pub s_status: Sstatus,
pub sepc: usize,
}
impl TrapContext {
pub unsafe fn init_application_context(entry: usize, sp: usize) -> Self {
let sstatus = sstatus::read();
sstatus::set_spp(SPP::User);
let mut context = Self {
x: [0; 32],
s_status: sstatus,
sepc: entry,
};
context.set_sp(sp);
context
}
pub fn set_sp(&mut self, sp: usize) {
// x2 is stack pointer register
self.x[2] = sp;
}
}