Skip to content

Commit

Permalink
merge with mi_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiQiu-ovO committed Jul 15, 2024
1 parent fa2215b commit ac96413
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 49 deletions.
14 changes: 7 additions & 7 deletions src/arch/aarch64/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sel4_common::arch::MessageLabel;
use sel4_common::structures::exception_t;
use sel4_common::structures::seL4_IPCBuffer;
use sel4_cspace::interface::{cap_t, cte_t};
use sel4_vspace::{pte_t, vptr_t};
use sel4_vspace::{PTE, vptr_t};

#[repr(C)]
struct lookupPGDSlot_ret_t {
Expand All @@ -24,22 +24,22 @@ struct lookupPUDSlot_ret_t {
}

#[no_mangle]
extern "C" fn lookupPGDSlot(vspace: *mut pte_t, vptr: vptr_t) -> lookupPGDSlot_ret_t {
// which is realized under sel4_vspace/src/arch/aarch64/pte.rs as a member function of pte_t in this commit
extern "C" fn lookupPGDSlot(vspace: *mut PTE, vptr: vptr_t) -> lookupPGDSlot_ret_t {
// which is realized under sel4_vspace/src/arch/aarch64/pte.rs as a member function of PTE in this commit
// ZhiyuanSue
todo!("lookupPGDSlot")
}

#[no_mangle]
extern "C" fn lookupPDSlot(vspace: *mut pte_t, vptr: vptr_t) -> lookupPDSlot_ret_t {
// which is realized under sel4_vspace/src/arch/aarch64/pte.rs as a member function of pte_t in this commit
extern "C" fn lookupPDSlot(vspace: *mut PTE, vptr: vptr_t) -> lookupPDSlot_ret_t {
// which is realized under sel4_vspace/src/arch/aarch64/pte.rs as a member function of PTE in this commit
// ZhiyuanSue
todo!("lookupPDSlot")
}

#[no_mangle]
extern "C" fn lookupPUDSlot(vspace: *mut pte_t, vptr: vptr_t) -> lookupPUDSlot_ret_t {
// which is realized under sel4_vspace/src/arch/aarch64/pte.rs as a member function of pte_t in this commit
extern "C" fn lookupPUDSlot(vspace: *mut PTE, vptr: vptr_t) -> lookupPUDSlot_ret_t {
// which is realized under sel4_vspace/src/arch/aarch64/pte.rs as a member function of PTE in this commit
// ZhiyuanSue
todo!("lookupPUDSlot")
}
Expand Down
5 changes: 1 addition & 4 deletions src/boot/root_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ fn rust_create_frames_of_region(
true,
);
} else {
frame_cap = rust_create_unmapped_it_frame_cap(f, false);
frame_cap = create_unmapped_it_frame_cap(f, false);
}

if !provide_cap(root_cnode_cap, frame_cap) {
Expand Down Expand Up @@ -575,9 +575,6 @@ unsafe fn create_bi_frame_cap(root_cnode_cap: &cap_t, pd_cap: &cap_t, vptr: usiz
write_slot(ptr.add(seL4_CapBootInfoFrame), cap);
}

fn rust_create_unmapped_it_frame_cap(pptr: pptr_t, _use_large: bool) -> cap_t {
cap_t::new_frame_cap(0, pptr, 0, 0, 0, 0)
}

unsafe fn rust_populate_bi_frame(
node_id: usize,
Expand Down
8 changes: 4 additions & 4 deletions src/compatibility.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use sel4_common::structures::seL4_IPCBuffer;
use sel4_cspace::interface::{cap_t, cte_t};
use sel4_task::{set_thread_state, tcb_t, ThreadState};
use sel4_vspace::{pte_t, vptr_t};
use sel4_vspace::{PTE, vptr_t};

#[inline]
#[no_mangle]
Expand Down Expand Up @@ -41,16 +41,16 @@ pub fn lookupIPCBuffer(isReceiver: bool, thread: *mut tcb_t) -> usize {
}

#[no_mangle]
pub fn pte_next(_phys_addr: usize, _is_leaf: bool) -> pte_t {
pub fn pte_next(_phys_addr: usize, _is_leaf: bool) -> PTE {
panic!("should not be invoked!")
}

#[no_mangle]
pub fn isPTEPageTable(_pte: *mut pte_t) -> bool {
pub fn isPTEPageTable(_pte: *mut PTE) -> bool {
panic!("should not be invoked!")
}

#[no_mangle]
pub extern "C" fn lookupPTSlot(_lvl1pt: *mut pte_t, _vptr: vptr_t) {
pub extern "C" fn lookupPTSlot(_lvl1pt: *mut PTE, _vptr: vptr_t) {
panic!("should not be invoked!")
}
8 changes: 4 additions & 4 deletions src/interfaces_impl/cspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sel4_cspace::interface::{cap_t, finaliseCap_ret, CapTag};
use sel4_ipc::{endpoint_t, notification_t, Transfer};
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, pte_t, unmapPage,
asid_pool_t, asid_t, delete_asid, delete_asid_pool, find_vspace_for_asid, PTE, unmapPage,
};

#[cfg(target_arch = "riscv64")]
Expand Down Expand Up @@ -41,9 +41,9 @@ pub fn Arch_finaliseCap(cap: &cap_t, final_: bool) -> finaliseCap_ret {
if find_ret.status == exception_t::EXCEPTION_NONE
&& find_ret.vspace_root.unwrap() as usize == pte
{
deleteASID(asid, pte as *mut pte_t);
deleteASID(asid, pte as *mut PTE);
} else {
convert_to_mut_type_ref::<pte_t>(pte)
convert_to_mut_type_ref::<PTE>(pte)
.unmap_page_table(asid, cap.get_pt_mapped_address());
}
if let Some(lookup_fault) = find_ret.lookup_fault {
Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn preemptionPoint() -> exception_t {
}

#[no_mangle]
pub fn deleteASID(asid: asid_t, vspace: *mut pte_t) {
pub fn deleteASID(asid: asid_t, vspace: *mut PTE) {
unsafe {
if let Err(lookup_fault) = delete_asid(
asid,
Expand Down
10 changes: 5 additions & 5 deletions src/kernel/fastpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn endpoint_ptr_mset_epQueue_tail_state(ptr: *mut endpoint_t, tail: usize, s

#[inline]
#[no_mangle]
pub fn switchToThread_fp(thread: *mut tcb_t, vroot: *mut pte_t, stored_hw_asid: pte_t) {
pub fn switchToThread_fp(thread: *mut tcb_t, vroot: *mut PTE, stored_hw_asid: PTE) {
let asid = stored_hw_asid.0;
unsafe {
#[cfg(target_arch = "riscv64")]
Expand Down Expand Up @@ -199,8 +199,8 @@ pub fn fastpath_call(cptr: usize, msgInfo: usize) {
);
fastpath_copy_mrs(length, current, dest);
dest.tcbState.words[0] = ThreadState::ThreadStateRunning as usize;
let cap_pd = new_vtable.get_pt_base_ptr() as *mut pte_t;
let stored_hw_asid: pte_t = pte_t(new_vtable.get_pt_mapped_asid());
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(dest as *mut tcb_t, cap_pd, stored_hw_asid);
info.set_caps_unwrapped(0);
let msgInfo1 = info.to_word();
Expand Down Expand Up @@ -296,8 +296,8 @@ pub fn fastpath_reply_recv(cptr: usize, msgInfo: usize) {
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_t;
let stored_hw_asid: pte_t = pte_t(new_vtable.get_pt_mapped_asid());
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();
Expand Down
14 changes: 7 additions & 7 deletions src/syscall/invocation/decode/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sel4_common::{
MASK,
};
use sel4_cspace::interface::{cap_t, cte_t, CapTag};
use sel4_vspace::{checkVPAlignment, find_vspace_for_asid, pptr_to_paddr, pte_t, vm_attributes_t};
use sel4_vspace::{checkVPAlignment, find_vspace_for_asid, pptr_to_paddr, vm_attributes_t, PTE};

use crate::syscall::invocation::invoke_mmu_op::{
invoke_asid_control, invoke_asid_pool, invoke_huge_page_map, invoke_large_page_map,
Expand Down Expand Up @@ -196,7 +196,7 @@ fn decode_frame_map(
return exception_t::EXCEPTION_SYSCALL_ERROR;
}
set_thread_state(get_currenct_thread(), ThreadState::ThreadStateRestart);
let ptSlot = convert_to_mut_type_ref::<pte_t>(lu_ret.ptSlot as usize);
let ptSlot = convert_to_mut_type_ref::<PTE>(lu_ret.ptSlot as usize);
invoke_small_page_map(asid, frame_slot, ptSlot)
} else if frame_size == ARM_Large_Page {
let lu_ret = lvl1pt.lookup_pd_slot(vaddr);
Expand All @@ -208,7 +208,7 @@ fn decode_frame_map(
return exception_t::EXCEPTION_SYSCALL_ERROR;
}
set_thread_state(get_currenct_thread(), ThreadState::ThreadStateRestart);
let pdSlot = convert_to_mut_type_ref::<pte_t>(lu_ret.pdSlot as usize);
let pdSlot = convert_to_mut_type_ref::<PTE>(lu_ret.pdSlot as usize);
invoke_large_page_map(asid, frame_slot, pdSlot)
} else if frame_size == ARM_Huge_Page {
let lu_ret = lvl1pt.lookup_pud_slot(vaddr);
Expand All @@ -220,7 +220,7 @@ fn decode_frame_map(
return exception_t::EXCEPTION_SYSCALL_ERROR;
}
set_thread_state(get_currenct_thread(), ThreadState::ThreadStateRestart);
let pudSlot = convert_to_mut_type_ref::<pte_t>(lu_ret.pudSlot as usize);
let pudSlot = convert_to_mut_type_ref::<PTE>(lu_ret.pudSlot as usize);
invoke_large_page_map(asid, frame_slot, pudSlot)
} else {
return exception_t::EXCEPTION_SYSCALL_ERROR;
Expand Down Expand Up @@ -294,15 +294,15 @@ fn decode_page_table_map(
}
return exception_t::EXCEPTION_SYSCALL_ERROR;
}
let pdSlot = convert_to_mut_type_ref::<pte_t>(pd_ret.pdSlot as usize);
let pdSlot = convert_to_mut_type_ref::<PTE>(pd_ret.pdSlot as usize);
set_thread_state(get_currenct_thread(), ThreadState::ThreadStateRestart);
return invoke_page_table_map(cap, pdSlot, asid, vaddr & !MASK!(PD_INDEX_OFFSET));
} else {
return exception_t::EXCEPTION_SYSCALL_ERROR;
}
}

fn get_vspace(lvl1pt_cap: &cap_t) -> Option<(&mut pte_t, usize)> {
fn get_vspace(lvl1pt_cap: &cap_t) -> Option<(&mut PTE, usize)> {
if lvl1pt_cap.get_cap_type() != CapTag::CapPageGlobalDirectoryCap
|| lvl1pt_cap.get_pt_is_mapped() == asidInvalid
{
Expand All @@ -314,7 +314,7 @@ fn get_vspace(lvl1pt_cap: &cap_t) -> Option<(&mut pte_t, usize)> {
return None;
}

let lvl1pt = convert_to_mut_type_ref::<pte_t>(lvl1pt_cap.get_pt_base_ptr());
let lvl1pt = convert_to_mut_type_ref::<PTE>(lvl1pt_cap.get_pt_base_ptr());
let asid = lvl1pt_cap.get_pt_mapped_asid();

let find_ret = find_vspace_for_asid(asid);
Expand Down
14 changes: 7 additions & 7 deletions src/syscall/invocation/decode/arch/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sel4_common::{BIT, MASK};
use sel4_cspace::interface::{cap_t, cte_t, CapTag};
use sel4_task::{get_currenct_thread, set_thread_state, ThreadState};
use sel4_vspace::{
checkVPAlignment, find_vspace_for_asid, get_asid_pool_by_index, pte_t, vm_attributes_t,
checkVPAlignment, find_vspace_for_asid, get_asid_pool_by_index, PTE, vm_attributes_t,
};

use crate::{
Expand Down Expand Up @@ -294,7 +294,7 @@ fn decode_frame_map(
return exception_t::EXCEPTION_SYSCALL_ERROR;
}

let pt_slot = convert_to_mut_type_ref::<pte_t>(lu_ret.ptSlot as usize);
let pt_slot = convert_to_mut_type_ref::<PTE>(lu_ret.ptSlot as usize);
let frame_asid = frame_slot.cap.get_frame_mapped_asid();
if frame_asid != asidInvalid {
if frame_asid != asid {
Expand All @@ -315,7 +315,7 @@ fn decode_frame_map(
return exception_t::EXCEPTION_SYSCALL_ERROR;
}

if pt_slot.is_pte_table() {
if pt_slot.is_PTEable() {
debug!("RISCVPageMap: no mapping to remap.");
unsafe {
current_syscall_error._type = seL4_DeleteFirst;
Expand Down Expand Up @@ -357,7 +357,7 @@ fn decode_page_table_unmap(pt_cte: &mut cte_t) -> exception_t {
if cap.get_pt_is_mapped() != 0 {
let asid = cap.get_pt_mapped_asid();
let find_ret = find_vspace_for_asid(asid);
let pte_ptr = cap.get_pt_base_ptr() as *mut pte_t;
let pte_ptr = cap.get_pt_base_ptr() as *mut PTE;
if find_ret.status == exception_t::EXCEPTION_NONE
&& find_ret.vspace_root.unwrap() == pte_ptr
{
Expand Down Expand Up @@ -411,7 +411,7 @@ fn decode_page_table_map(

if let Some((lvl1pt, asid)) = get_vspace(&lvl1pt_cap) {
let lu_ret = lvl1pt.lookup_pt_slot(vaddr);
let lu_slot = convert_to_mut_type_ref::<pte_t>(lu_ret.ptSlot as usize);
let lu_slot = convert_to_mut_type_ref::<PTE>(lu_ret.ptSlot as usize);
#[cfg(target_arch = "riscv64")]
if lu_ret.ptBitsLeft == seL4_PageBits || lu_slot.get_valid() != 0 {
debug!("RISCVPageTableMap: All objects mapped at this address");
Expand All @@ -427,7 +427,7 @@ fn decode_page_table_map(
}
}

fn get_vspace(lvl1pt_cap: &cap_t) -> Option<(&mut pte_t, usize)> {
fn get_vspace(lvl1pt_cap: &cap_t) -> Option<(&mut PTE, usize)> {
if lvl1pt_cap.get_cap_type() != CapTag::CapPageTableCap
|| lvl1pt_cap.get_pt_is_mapped() == asidInvalid
{
Expand All @@ -439,7 +439,7 @@ fn get_vspace(lvl1pt_cap: &cap_t) -> Option<(&mut pte_t, usize)> {
return None;
}

let lvl1pt = convert_to_mut_type_ref::<pte_t>(lvl1pt_cap.get_pt_base_ptr());
let lvl1pt = convert_to_mut_type_ref::<PTE>(lvl1pt_cap.get_pt_base_ptr());
let asid = lvl1pt_cap.get_pt_mapped_asid();

let find_ret = find_vspace_for_asid(asid);
Expand Down
22 changes: 11 additions & 11 deletions src/syscall/invocation/invoke_mmu_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sel4_common::{
use sel4_cspace::interface::{cap_t, cte_insert, cte_t};
use sel4_task::{get_currenct_thread, set_thread_state, ThreadState};
use sel4_vspace::{
asid_pool_t, pptr_t, pptr_to_paddr, pte_t, set_asid_pool_by_index, unmapPage, vm_attributes_t,
asid_pool_t, pptr_t, pptr_to_paddr, PTE, set_asid_pool_by_index, unmapPage, vm_attributes_t,
PTEFlags,
};
#[cfg(target_arch = "riscv64")]
Expand All @@ -23,7 +23,7 @@ use crate::{kernel::boot::current_lookup_fault, utils::clear_memory};

pub fn invoke_page_table_unmap(cap: &mut cap_t) -> exception_t {
if cap.get_pt_is_mapped() != 0 {
let pt = convert_to_mut_type_ref::<pte_t>(cap.get_pt_base_ptr());
let pt = convert_to_mut_type_ref::<PTE>(cap.get_pt_base_ptr());
pt.unmap_page_table(cap.get_pt_mapped_asid(), cap.get_pt_mapped_address());
clear_memory(pt.get_ptr() as *mut u8, seL4_PageTableBits)
}
Expand All @@ -33,19 +33,19 @@ pub fn invoke_page_table_unmap(cap: &mut cap_t) -> exception_t {

pub fn invoke_page_table_map(
pt_cap: &mut cap_t,
pt_slot: &mut pte_t,
pt_slot: &mut PTE,
asid: usize,
vaddr: usize,
) -> exception_t {
let paddr = pptr_to_paddr(pt_cap.get_pt_base_ptr());
#[cfg(target_arch = "riscv64")]
{
let pte = pte_t::new(paddr >> seL4_PageBits, PTEFlags::V);
let pte = PTE::new(paddr >> seL4_PageBits, PTEFlags::V);
*pt_slot = pte;
}
#[cfg(target_arch = "aarch64")]
{
let pde = pte_t::new(paddr >> seL4_PageBits, PTEFlags::VALID);
let pde = PTE::new(paddr >> seL4_PageBits, PTEFlags::VALID);
*pt_slot = pde;
}
pt_cap.set_pt_is_mapped(1);
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn invoke_page_map(
vaddr: usize,
asid: usize,
attr: vm_attributes_t,
pt_slot: &mut pte_t,
pt_slot: &mut PTE,
frame_slot: &mut cte_t,
) -> exception_t {
let frame_vm_rights = unsafe { core::mem::transmute(frame_slot.cap.get_frame_vm_rights()) };
Expand All @@ -113,9 +113,9 @@ pub fn invoke_page_map(
#[cfg(target_arch = "riscv64")]
let executable = attr.get_execute_never() == 0;
#[cfg(target_arch = "riscv64")]
let pte = pte_t::make_user_pte(frame_addr, executable, vm_rights);
let pte = PTE::make_user_pte(frame_addr, executable, vm_rights);
#[cfg(target_arch = "aarch64")]
let pte = pte_t::make_user_pte(frame_addr, vm_rights, attr, frame_slot.cap.get_frame_size());
let pte = PTE::make_user_pte(frame_addr, vm_rights, attr, frame_slot.cap.get_frame_size());
set_thread_state(get_currenct_thread(), ThreadState::ThreadStateRestart);
pt_slot.update(pte);
exception_t::EXCEPTION_NONE
Expand All @@ -124,7 +124,7 @@ pub fn invoke_page_map(
pub fn invoke_huge_page_map(
asid: usize,
frame_slot: &mut cte_t,
pudSlot: &mut pte_t,
pudSlot: &mut PTE,
) -> exception_t {
exception_t::EXCEPTION_NONE
}
Expand All @@ -133,7 +133,7 @@ pub fn invoke_huge_page_map(
pub fn invoke_large_page_map(
asid: usize,
frame_slot: &mut cte_t,
pdSlot: &mut pte_t,
pdSlot: &mut PTE,
) -> exception_t {
exception_t::EXCEPTION_NONE
}
Expand All @@ -142,7 +142,7 @@ pub fn invoke_large_page_map(
pub fn invoke_small_page_map(
asid: usize,
frame_slot: &mut cte_t,
pdSlot: &mut pte_t,
pdSlot: &mut PTE,
) -> exception_t {
exception_t::EXCEPTION_NONE
}
Expand Down

0 comments on commit ac96413

Please sign in to comment.