Skip to content

Commit

Permalink
Clean ffi 1 (#8)
Browse files Browse the repository at this point in the history
* clean the tcb debug

* add the map_kernel_devices of aarch64,but need fix the riscv64

* clean warnings and fmt

* add the riscv64 map_kernel_devices
  • Loading branch information
ZhiyuanSue committed Aug 28, 2024
1 parent 4abdc8b commit c4c30a6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 64 deletions.
42 changes: 21 additions & 21 deletions src/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod utils;

use core::mem::size_of;

use crate::ffi::tcbDebugAppend;
// use crate::ffi::tcbDebugAppend;
use crate::{BIT, ROUND_UP};
use log::debug;
use sel4_common::arch::config::PADDR_TOP;
Expand Down Expand Up @@ -142,26 +142,26 @@ pub fn bi_finalise(dtb_size: usize, dtb_phys_addr: usize, extra_bi_size: usize)
}

pub fn init_core_state(scheduler_action: *mut tcb_t) {
unsafe {
#[cfg(feature = "ENABLE_SMP")]
if scheduler_action as usize != 0 && scheduler_action as usize != 1 {
tcbDebugAppend(scheduler_action);
}
let idle_thread = {
#[cfg(not(feature = "ENABLE_SMP"))]
{
ksIdleThread as *mut tcb_t
}
#[cfg(feature = "ENABLE_SMP")]
{
ksSMP[cpu_id()].ksIdleThread as *mut tcb_t
}
};

tcbDebugAppend(idle_thread);
set_current_scheduler_action(scheduler_action as usize);
set_current_thread(get_idle_thread());
}
// unsafe {
// #[cfg(feature = "ENABLE_SMP")]
// if scheduler_action as usize != 0 && scheduler_action as usize != 1 {
// tcbDebugAppend(scheduler_action);
// }
// let idle_thread = {
// #[cfg(not(feature = "ENABLE_SMP"))]
// {
// ksIdleThread as *mut tcb_t
// }
// #[cfg(feature = "ENABLE_SMP")]
// {
// ksSMP[cpu_id()].ksIdleThread as *mut tcb_t
// }
// };
// tcbDebugAppend(idle_thread);
// }

set_current_scheduler_action(scheduler_action as usize);
set_current_thread(get_idle_thread());
}

#[cfg(feature = "ENABLE_SMP")]
Expand Down
4 changes: 0 additions & 4 deletions src/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use sel4_task::tcb_t;

extern "C" {
// #[cfg(target_arch = "aarch64")]
// pub fn kernel_stack_alloc();
#[cfg(target_arch = "riscv64")]
pub fn init_plat();
pub fn tcbDebugAppend(action: *mut tcb_t);
pub fn tcbDebugRemove(tcb: *mut tcb_t);
}

#[cfg(feature = "ENABLE_SMP")]
Expand Down
9 changes: 5 additions & 4 deletions src/interfaces_impl/cspace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::CONFIG_MAX_NUM_WORK_UNITS_PER_PREEMPTION;
use crate::ffi::tcbDebugRemove;
// use crate::ffi::tcbDebugRemove;
use crate::interrupt::{deletingIRQHandler, isIRQPending, setIRQState, IRQState};
use crate::kernel::boot::current_lookup_fault;
use crate::syscall::safe_unbind_notification;
Expand Down Expand Up @@ -199,9 +199,10 @@ pub fn finaliseCap(cap: &cap_t, _final: bool, _exposed: bool) -> finaliseCap_ret
safe_unbind_notification(tcb);
tcb.cancel_ipc();
tcb.suspend();
unsafe {
tcbDebugRemove(tcb as *mut tcb_t);
}
// #[cfg(feature="DEBUG_BUILD")]
// unsafe {
// tcbDebugRemove(tcb as *mut tcb_t);
// }
fc_ret.remainder =
Zombie_new(tcbCNodeEntries, ZombieType_ZombieTCB, cte_ptr.get_ptr());
fc_ret.cleanupInfo = cap_t::new_null_cap();
Expand Down
44 changes: 22 additions & 22 deletions src/kernel/fastpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn fastpath_copy_mrs(length: usize, src: &mut tcb_t, dest: &mut tcb_t) {
#[no_mangle]
#[cfg(target_arch = "aarch64")]
pub fn fastpath_restore(_badge: usize, _msgInfo: usize, cur_thread: *mut tcb_t) {
use core::arch::asm;
use core::arch::asm;
unsafe {
(*cur_thread).tcbArch.load_thread_local();
asm!(
Expand Down Expand Up @@ -180,13 +180,13 @@ pub fn fastpath_restore(_badge: usize, _msgInfo: usize, cur_thread: *mut tcb_t)
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")
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]
Expand Down Expand Up @@ -262,7 +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();
fastpath_restore(badge, msgInfo1, get_currenct_thread());
fastpath_restore(badge, msgInfo1, get_currenct_thread());
}

#[inline]
Expand Down Expand Up @@ -344,18 +344,18 @@ pub fn fastpath_reply_recv(cptr: usize, msgInfo: usize) {
);

// 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();
caller_slot.cteMDBNode = mdb_node_t::new(0, 0, 0, 0);
fastpath_copy_mrs(length, current, caller);

caller.tcbState.words[0] = ThreadState::ThreadStateRunning as usize;
let cap_pd = new_vtable.get_pt_base_ptr() as *mut PTE;
let stored_hw_asid: PTE = PTE(new_vtable.get_pt_mapped_asid());
switchToThread_fp(caller, cap_pd, stored_hw_asid);
info.set_caps_unwrapped(0);
let msg_info1 = info.to_word();
fastpath_restore(0, msg_info1, get_currenct_thread() as *mut tcb_t);
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();
caller_slot.cteMDBNode = mdb_node_t::new(0, 0, 0, 0);
fastpath_copy_mrs(length, current, caller);

caller.tcbState.words[0] = ThreadState::ThreadStateRunning as usize;
let cap_pd = new_vtable.get_pt_base_ptr() as *mut PTE;
let stored_hw_asid: PTE = PTE(new_vtable.get_pt_mapped_asid());
switchToThread_fp(caller, cap_pd, stored_hw_asid);
info.set_caps_unwrapped(0);
let msg_info1 = info.to_word();
fastpath_restore(0, msg_info1, get_currenct_thread() as *mut tcb_t);
// }
}
4 changes: 2 additions & 2 deletions src/kernel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod boot;
pub mod fastpath;
pub mod fault;
#[cfg(target_arch="riscv64")]
core::arch::global_asm!(include_str!("fastpath_restore.S"));
#[cfg(target_arch = "riscv64")]
core::arch::global_asm!(include_str!("fastpath_restore.S"));
16 changes: 9 additions & 7 deletions src/syscall/invocation/invoke_untyped.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ffi::tcbDebugAppend;
// use crate::ffi::tcbDebugAppend;
use crate::syscall::{
FREE_INDEX_TO_OFFSET, GET_FREE_INDEX, GET_OFFSET_FREE_PTR, OFFSET_TO_FREE_IDNEX,
};
Expand Down Expand Up @@ -48,9 +48,10 @@ fn create_object(
tcb.init();
tcb.tcbTimeSlice = CONFIG_TIME_SLICE;
tcb.domain = get_current_domain();
unsafe {
tcbDebugAppend(tcb as *mut tcb_t);
}
// #[cfg(feature="DEBUG_BUILD")]
// unsafe {
// tcbDebugAppend(tcb as *mut tcb_t);
// }
return cap_t::new_thread_cap(tcb.get_ptr());
}

Expand Down Expand Up @@ -89,9 +90,10 @@ fn create_object(
tcb.init();
tcb.tcbTimeSlice = CONFIG_TIME_SLICE;
tcb.domain = get_current_domain();
unsafe {
tcbDebugAppend(tcb as *mut tcb_t);
}
// #[cfg(feature="DEBUG_BUILD")]
// unsafe {
// tcbDebugAppend(tcb as *mut tcb_t);
// }
return cap_t::new_thread_cap(tcb.get_ptr());
}

Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(target_arch="aarch64")]
#[cfg(target_arch = "aarch64")]
use sel4_common::{
sel4_config::{ID_AA64PFR0_EL1_ASIMD, ID_AA64PFR0_EL1_FP},
MASK,
};
#[cfg(target_arch="aarch64")]
#[cfg(target_arch = "aarch64")]
use sel4_vspace::{dsb, isb};

use crate::BIT;
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn clear_memory_pt(ptr: *mut u8, bits: usize) {
}

#[inline]
#[cfg(target_arch="aarch64")]
#[cfg(target_arch = "aarch64")]
pub fn setVTable(addr: usize) {
dsb();
unsafe {
Expand All @@ -72,7 +72,7 @@ pub fn setVTable(addr: usize) {
}

#[inline]
#[cfg(target_arch="aarch64")]
#[cfg(target_arch = "aarch64")]
pub fn fpsimd_HWCapTest() -> bool {
let mut id_aa64pfr0: usize;

Expand Down

0 comments on commit c4c30a6

Please sign in to comment.