Skip to content

Commit

Permalink
Clean fastpath restore (#7)
Browse files Browse the repository at this point in the history
* add the aarch64 clean fastpath restore

* try to add the riscv fastpath_restore,but failed

* use a way to solve the problem

* clean some warnings
  • Loading branch information
ZhiyuanSue committed Aug 26, 2024
1 parent 2d9f4d2 commit 4abdc8b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extern "C" {
pub fn init_plat();
pub fn tcbDebugAppend(action: *mut tcb_t);
pub fn tcbDebugRemove(tcb: *mut tcb_t);
pub fn fastpath_restore(badge: usize, msgInfo: usize, cur_thread: *mut tcb_t);
}

#[cfg(feature = "ENABLE_SMP")]
Expand Down
2 changes: 1 addition & 1 deletion src/interrupt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod handler;

#[cfg(target_arch="riscv64")]
#[cfg(target_arch = "riscv64")]
use crate::BIT;
#[cfg(target_arch = "riscv64")]
use core::arch::asm;
Expand Down
67 changes: 61 additions & 6 deletions src/kernel/fastpath.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::MASK;
use crate::{
config::seL4_MsgLengthBits,
ffi::fastpath_restore,
syscall::{slowpath, SysCall, SysReplyRecv},
};
use core::intrinsics::{likely, unlikely};
Expand Down Expand Up @@ -131,6 +130,64 @@ pub fn fastpath_copy_mrs(length: usize, src: &mut tcb_t, dest: &mut tcb_t) {
// __restore_fp(badge, msgInfo, cur_thread_regs);
// }
// }
#[inline]
#[no_mangle]
#[cfg(target_arch = "aarch64")]
pub fn fastpath_restore(_badge: usize, _msgInfo: usize, cur_thread: *mut tcb_t) {
use core::arch::asm;
unsafe {
(*cur_thread).tcbArch.load_thread_local();
asm!(
"mov sp, {} \n",
/* Restore thread's SPSR, LR, and SP */
"ldp x21, x22, [sp, #31 * 8] \n",
"ldr x23, [sp, #33 * 8] \n",
"msr sp_el0, x21 \n",
// #ifdef CONFIG_ARM_HYPERVISOR_SUPPORT
// "msr elr_el2, x22 \n"
// "msr spsr_el2, x23 \n"
// #else
"msr elr_el1, x22 \n",
"msr spsr_el1, x23 \n",
// #endif

/* Restore remaining registers */
"ldp x2, x3, [sp, #16 * 1] \n",
"ldp x4, x5, [sp, #16 * 2] \n",
"ldp x6, x7, [sp, #16 * 3] \n",
"ldp x8, x9, [sp, #16 * 4] \n",
"ldp x10, x11, [sp, #16 * 5] \n",
"ldp x12, x13, [sp, #16 * 6] \n",
"ldp x14, x15, [sp, #16 * 7] \n",
"ldp x16, x17, [sp, #16 * 8] \n",
"ldp x18, x19, [sp, #16 * 9] \n",
"ldp x20, x21, [sp, #16 * 10] \n",
"ldp x22, x23, [sp, #16 * 11] \n",
"ldp x24, x25, [sp, #16 * 12] \n",
"ldp x26, x27, [sp, #16 * 13] \n",
"ldp x28, x29, [sp, #16 * 14] \n",
"ldr x30, [sp, #30 * 8] \n",
"eret ",
in(reg) (*cur_thread).tcbArch.raw_ptr()
);
}
panic!("unreachable")
}

#[inline]
#[no_mangle]
#[cfg(target_arch = "riscv64")]
pub fn fastpath_restore(_badge: usize, _msgInfo: usize, cur_thread: *mut tcb_t) {
#[cfg(feature = "ENABLE_SMP")]
{}
extern "C" {
pub fn __fastpath_restore(badge: usize, msgInfo: usize, cur_thread_reg: usize);
}
unsafe {
__fastpath_restore(_badge,_msgInfo,(*cur_thread).tcbArch.raw_ptr());
}
panic!("unreachable")
}

#[inline]
#[no_mangle]
Expand Down Expand Up @@ -205,9 +262,7 @@ pub fn fastpath_call(cptr: usize, msgInfo: usize) {
info.set_caps_unwrapped(0);
let msgInfo1 = info.to_word();
let badge = ep_cap.get_ep_badge();
unsafe {
fastpath_restore(badge, msgInfo1, get_currenct_thread());
}
fastpath_restore(badge, msgInfo1, get_currenct_thread());
}

#[inline]
Expand Down Expand Up @@ -288,7 +343,7 @@ pub fn fastpath_reply_recv(cptr: usize, msgInfo: usize) {
EPState_Recv,
);

unsafe {
// unsafe {
let node = convert_to_mut_type_ref::<cte_t>(caller_slot.cteMDBNode.get_prev());
mdb_node_ptr_mset_mdbNext_mdbRevocable_mdbFirstBadged(&mut node.cteMDBNode, 0, 1, 1);
caller_slot.cap = cap_t::new_null_cap();
Expand All @@ -302,5 +357,5 @@ pub fn fastpath_reply_recv(cptr: usize, msgInfo: usize) {
info.set_caps_unwrapped(0);
let msg_info1 = info.to_word();
fastpath_restore(0, msg_info1, get_currenct_thread() as *mut tcb_t);
}
// }
}
40 changes: 40 additions & 0 deletions src/kernel/fastpath_restore.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
__fastpath_restore:
mv t0 , a2
ld ra, (0*8)(t0)
ld sp, (1*8)(t0)
ld gp, (2*8)(t0)
/* skip tp */
/* skip x5/t0 */
ld t2, (6*8)(t0)
ld s0, (7*8)(t0)
ld s1, (8*8)(t0)
ld a2, (11*8)(t0)
ld a3, (12*8)(t0)
ld a4, (13*8)(t0)
ld a5, (14*8)(t0)
ld a6, (15*8)(t0)
ld a7, (16*8)(t0)
ld s2, (17*8)(t0)
ld s3, (18*8)(t0)
ld s4, (19*8)(t0)
ld s5, (20*8)(t0)
ld s6, (21*8)(t0)
ld s7, (22*8)(t0)
ld s8, (23*8)(t0)
ld s9, (24*8)(t0)
ld s10, (25*8)(t0)
ld s11, (26*8)(t0)
ld t3, (27*8)(t0)
ld t4, (28*8)(t0)
ld t5, (29*8)(t0)
ld t6, (30*8)(t0)
ld t1, (3*8)(t0)
add tp, t1, x0
ld t1, (34*8)(t0)
csrw sepc, t1
csrw sscratch, t0
ld t1, (32*8)(t0)
csrw sstatus, t1
ld t1, (5*8)(t0)
ld t0, (4*8)(t0)
sret
2 changes: 2 additions & 0 deletions src/kernel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod boot;
pub mod fastpath;
pub mod fault;
#[cfg(target_arch="riscv64")]
core::arch::global_asm!(include_str!("fastpath_restore.S"));
1 change: 0 additions & 1 deletion src/syscall/invocation/decode/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ fn decode_upper_page_directory_unmap(ctSlot: &mut cte_t) -> exception_t {
exception_t::EXCEPTION_NONE
}


fn decode_page_directory_unmap(ctSlot: &mut cte_t) -> exception_t {
let cap = &mut ctSlot.cap;
if cap.get_pd_is_mapped() != 0 {
Expand Down

0 comments on commit 4abdc8b

Please sign in to comment.