fix something

This commit is contained in:
hustccc 2021-03-22 02:49:08 +09:00
parent 224ed9d592
commit 350220046a
2 changed files with 9 additions and 4 deletions

View File

@ -17,7 +17,6 @@ mod trap;
mod memory;
mod task;
mod hart;
mod swap_context;
#[cfg(not(test))]
global_asm!(include_str!("entry.asm"));
@ -33,9 +32,9 @@ pub extern "C" fn rust_main(hart_id: usize) -> ! {
static _sidata: u32;
// fn _swap_frame();
// fn _user2supervisor();
// fn _supervisor2user();
fn _swap_frame();
fn _user_to_supervisor();
fn _supervisor_to_user();
}
unsafe {
@ -87,6 +86,10 @@ pub extern "C" fn rust_main(hart_id: usize) -> ! {
println!("Test #{}: {:?} and {:?}", i, frame_0.start_address(), frame_1.start_address());
}
println!("_swap_frame: {:#x}", _swap_frame as usize);
println!("_user_to_supervisor: {:#x}", _user_to_supervisor as usize);
println!("_supervisor_to_user: {:#x}", _supervisor_to_user as usize);
// let executor = task::Executor::default();
// executor.spawn(async {

View File

@ -109,6 +109,7 @@ impl SwapContext {
// 但目前的页表还是用户态的页表
// 先保存 SwapContext,然后切换到内核的地址空间
#[link_section = ".swap"]
#[export_name = "_user_to_supervisor"]
pub unsafe extern "C" fn user_to_supervisor() -> ! {
asm!(
// 交换 a0 和 sscratch原先保存着交换栈的栈顶指针
@ -175,6 +176,7 @@ pub unsafe extern "C" fn user_to_supervisor() -> ! {
// a0用户态 SwapContext 的裸指针
// a1新的 satp 寄存器的值,用于切换地址空间
#[link_section = ".swap"]
#[export_name = "_supervisor_to_user"]
pub unsafe extern "C" fn supervisor_to_user(ctx: *mut SwapContext, satp: usize) -> ! {
asm!("
csrw satp, {satp}