Skip to content

Commit

Permalink
try to clean the ffi kernel_stack_alloc ksIdleThreadTCB and Arch_fina…
Browse files Browse the repository at this point in the history
…liseCap
  • Loading branch information
ZhiyuanSue committed Jul 22, 2024
1 parent 318ca6f commit def5c36
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/arch/aarch64/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use aarch64_cpu::registers::Writeable;
use aarch64_cpu::registers::{TPIDR_EL1, VBAR_EL1};
use core::arch::asm;
use sel4_common::arch::config::{KERNEL_ELF_BASE, PADDR_TOP};
use sel4_common::ffi::kernel_stack_alloc;
use sel4_common::ffi_addr;
use sel4_common::sel4_config::{wordBits, CONFIG_KERNEL_STACK_BITS};
use sel4_common::utils::cpu_id;
Expand All @@ -27,7 +28,8 @@ pub fn init_cpu() -> bool {
// Wrapping_add, first argument is CURRENT_CPU_INDEX
//
let mut stack_top =
(kernel_stack_alloc as *mut u8).wrapping_add(0 + (1 << CONFIG_KERNEL_STACK_BITS)) as u64;
unsafe { &kernel_stack_alloc.data[0][0 + (1 << CONFIG_KERNEL_STACK_BITS)] as *const u8 }
as u64;
stack_top |= cpu_id() as u64; //the judge of enable smp have done in cpu_id

TPIDR_EL1.set(stack_top);
Expand Down
4 changes: 2 additions & 2 deletions src/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use sel4_task::tcb_t;

extern "C" {
#[cfg(target_arch = "aarch64")]
pub fn kernel_stack_alloc();
// #[cfg(target_arch = "aarch64")]
// pub fn kernel_stack_alloc();
pub fn init_plat();
pub fn tcbDebugAppend(action: *mut tcb_t);
pub fn tcbDebugRemove(tcb: *mut tcb_t);
Expand Down
73 changes: 71 additions & 2 deletions src/interfaces_impl/cspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ use sel4_task::{get_currenct_thread, ksWorkUnitsCompleted, tcb_t};
use sel4_vspace::{
asid_pool_t, asid_t, delete_asid, delete_asid_pool, find_vspace_for_asid, unmapPage, PTE,
};
#[cfg(target_arch = "aarch64")]
use sel4_vspace::{
unmap_page_directory, unmap_page_table, unmap_page_upper_directory, PDE, PGDE, PUDE,
};

#[cfg(target_arch = "riscv64")]
#[no_mangle]
Expand Down Expand Up @@ -67,8 +71,67 @@ pub fn Arch_finaliseCap(cap: &cap_t, final_: bool) -> finaliseCap_ret {
}

#[cfg(target_arch = "aarch64")]
extern "C" {
pub fn Arch_finaliseCap(cap: &cap_t, final_: bool) -> finaliseCap_ret;
// extern "C" {
// pub fn Arch_finaliseCap(cap: &cap_t, final_: bool) -> finaliseCap_ret;
// }
pub fn Arch_finaliseCap(cap: &cap_t, final_: bool) -> finaliseCap_ret {
let mut fc_ret = finaliseCap_ret::default();
match cap.get_cap_type() {
CapTag::CapASIDPoolCap => {
if final_ {
deleteASIDPool(cap.get_asid_base(), cap.get_asid_pool() as *mut asid_pool_t);
}
}
CapTag::CapPageGlobalDirectoryCap => {
if final_ && cap.get_pgd_is_mapped() != 0 {
deleteASID(
cap.get_pgd_mapped_asid(),
cap.get_pgd_base_ptr() as *mut sel4_vspace::PGDE,
);
}
}
CapTag::CapPageUpperDirectoryCap => {
if final_ && cap.get_pud_is_mapped() != 0 {
unmap_page_upper_directory(
cap.get_pud_mapped_asid(),
cap.get_pud_mapped_address(),
&PUDE::new_from_pte(cap.get_pud_base_ptr()),
);
}
}
CapTag::CapPageDirectoryCap => {
if final_ && cap.get_pd_is_mapped() != 0 {
unmap_page_directory(
cap.get_pd_mapped_asid(),
cap.get_pd_mapped_address(),
&PDE::new_from_pte(cap.get_pd_base_ptr()),
);
}
}
CapTag::CapPageTableCap => {
if final_ && cap.get_pt_is_mapped() != 0 {
unmap_page_table(
cap.get_pt_mapped_asid(),
cap.get_pt_mapped_address(),
&PTE::new_from_pte(cap.get_pt_base_ptr()),
);
}
}
CapTag::CapFrameCap => {
if cap.get_frame_mapped_asid() != 0 {
let _ = unmapPage(
cap.get_frame_size(),
cap.get_frame_mapped_asid(),
cap.get_frame_mapped_address(),
cap.get_frame_base_ptr(),
);
}
}
_ => panic!(),
}
fc_ret.remainder = cap_t::new_null_cap();
fc_ret.cleanupInfo = cap_t::new_null_cap();
fc_ret
}

#[no_mangle]
Expand Down Expand Up @@ -201,6 +264,7 @@ pub fn preemptionPoint() -> exception_t {
}

#[no_mangle]
#[cfg(target_arch = "riscv64")]
pub fn deleteASID(asid: asid_t, vspace: *mut PTE) {
unsafe {
if let Err(lookup_fault) = delete_asid(
Expand All @@ -212,6 +276,11 @@ pub fn deleteASID(asid: asid_t, vspace: *mut PTE) {
}
}
}
#[no_mangle]
#[cfg(target_arch = "aarch64")]
pub fn deleteASID(asid: asid_t, vspace: *mut PGDE) {
todo!()
}

#[no_mangle]
pub fn deleteASIDPool(asid_base: asid_t, pool: *mut asid_pool_t) {
Expand Down

0 comments on commit def5c36

Please sign in to comment.