Skip to content

Commit

Permalink
add some funcitons
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiyuanSue committed Sep 10, 2024
1 parent ac4d106 commit 293b7c2
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 95 deletions.
12 changes: 6 additions & 6 deletions kernel/src/arch/aarch64/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use aarch64_cpu::registers::Readable;
use aarch64_cpu::registers::TTBR0_EL1;
use log::debug;
use sel4_common::arch::ArchReg::*;
use sel4_common::print;
use sel4_common::fault::seL4_Fault_t;
use sel4_common::print;
use sel4_common::sel4_config::seL4_MsgMaxLength;
use sel4_common::structures::exception_t;
use sel4_common::utils::global_read;
Expand All @@ -27,23 +27,23 @@ use super::instruction::*;

#[no_mangle]
pub fn handleUnknownSyscall(w: isize) -> exception_t {
let thread = get_currenct_thread();
let thread = get_currenct_thread();
if w == SysDebugPutChar {
print!("{}",thread.tcbArch.get_register(Cap) as u8 as char);
print!("{}", thread.tcbArch.get_register(Cap) as u8 as char);
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugDumpScheduler {
// unimplement debug
// unimplement debug
// println!("debug dump scheduler");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugHalt {
// unimplement debug
// unimplement debug
// println!("debug halt");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugSnapshot {
// unimplement debug
// unimplement debug
// println!("debug snapshot");
return exception_t::EXCEPTION_NONE;
}
Expand Down
14 changes: 7 additions & 7 deletions kernel/src/arch/riscv/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ use crate::syscall::{
use log::debug;
use sel4_common::arch::ArchReg::*;
use sel4_common::fault::seL4_Fault_t;
use sel4_common::print;
use sel4_common::sel4_config::seL4_MsgMaxLength;
use sel4_common::structures::exception_t;
use sel4_cspace::arch::CapTag;
use sel4_common::print;
use sel4_task::{activateThread, get_currenct_thread, schedule};

#[no_mangle]
pub fn handleUnknownSyscall(w: isize) -> exception_t {
let thread = get_currenct_thread();
let thread = get_currenct_thread();
if w == SysDebugPutChar {
print!("{}",thread.tcbArch.get_register(Cap) as u8 as char);
print!("{}", thread.tcbArch.get_register(Cap) as u8 as char);
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugDumpScheduler {
// unimplement debug
// unimplement debug
// println!("debug dump scheduler");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugHalt {
// unimplement debug
// unimplement debug
// println!("debug halt");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugSnapshot {
// unimplement debug
// unimplement debug
// println!("debug snap shot");
return exception_t::EXCEPTION_NONE;
}
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn handleUnknownSyscall(w: isize) -> exception_t {
debug!("SysDebugNameThread: Name too long, halting");
halt();
}

// setThreadName(TCB_PTR(cap_thread_cap_get_capTCBPtr(lu_ret.cap)), name);
return exception_t::EXCEPTION_NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/boot/root_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ unsafe fn rust_create_it_address_space(root_cnode_cap: &cap_t, it_v_reg: v_regio
#[cfg(target_arch = "aarch64")]
unsafe fn rust_create_it_address_space(root_cnode_cap: &cap_t, it_v_reg: v_region_t) -> cap_t {
// create the PGD
let vspace_cap = cap_t::new_page_global_directory_cap(IT_ASID, rootserver.vspace, 1);
let vspace_cap = cap_t::new_vspace_cap(IT_ASID, rootserver.vspace, 1);
let ptr = root_cnode_cap.get_cap_ptr() as *mut cte_t;
let slot_pos_before = ndks_boot.slot_pos_cur;
write_slot(ptr.add(seL4_CapInitThreadVspace), vspace_cap.clone());
Expand Down
2 changes: 0 additions & 2 deletions kernel/src/interfaces_impl/cspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ pub fn preemptionPoint() -> exception_t {
}
}


#[no_mangle]
#[cfg(target_arch = "riscv64")]
pub fn deleteASID(asid: asid_t, vspace: *mut PTE) {
Expand Down Expand Up @@ -288,7 +287,6 @@ pub fn deleteASID(asid: asid_t, vspace: *mut PGDE) {
}
}


#[no_mangle]
pub fn deleteASIDPool(asid_base: asid_t, pool: *mut asid_pool_t) {
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/interrupt/handler.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::arch::resetTimer;
use crate::config::{irqInvalid,maxIRQ};
use crate::config::{irqInvalid, maxIRQ};
use crate::interrupt::*;
use core::intrinsics::unlikely;
use log::debug;
use sel4_common::structures::exception_t;
use sel4_cspace::interface::CapTag;
use sel4_ipc::notification_t;
use sel4_task::{activateThread, schedule,timerTick};
use sel4_task::{activateThread, schedule, timerTick};

#[no_mangle]
pub fn handleInterruptEntry() -> exception_t {
Expand Down
5 changes: 4 additions & 1 deletion kernel/src/syscall/invocation/arch/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sel4_common::{arch::{vm_rights_t, ObjectType}, sel4_config::{asidInvalid, ARM_Large_Page, ARM_Small_Page}};
use sel4_common::{
arch::{vm_rights_t, ObjectType},
sel4_config::{asidInvalid, ARM_Large_Page, ARM_Small_Page},
};
use sel4_cspace::arch::cap_t;
use sel4_vspace::pptr_t;

Expand Down
6 changes: 4 additions & 2 deletions kernel/src/syscall/invocation/arch/riscv64.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use sel4_common::{arch::{vm_rights_t, ObjectType}, sel4_config::asidInvalid};
use sel4_common::{
arch::{vm_rights_t, ObjectType},
sel4_config::asidInvalid,
};
use sel4_cspace::arch::cap_t;
use sel4_vspace::pptr_t;


pub fn arch_create_object(
obj_type: ObjectType,
region_base: pptr_t,
Expand Down
12 changes: 2 additions & 10 deletions kernel/src/syscall/invocation/decode/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,7 @@ fn decode_frame_invocation(
}
}

fn decode_asid_control(
label: MessageLabel,
length: usize,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_asid_control(label: MessageLabel, length: usize, buffer: &seL4_IPCBuffer) -> exception_t {
if unlikely(label != MessageLabel::ARMASIDControlMakePool) {
global_ops!(current_syscall_error._type = seL4_IllegalOperation);
return exception_t::EXCEPTION_SYSCALL_ERROR;
Expand Down Expand Up @@ -436,11 +432,7 @@ fn decode_asid_pool(label: MessageLabel, cte: &mut cte_t) -> exception_t {
exception_t::EXCEPTION_NONE
}

fn decode_frame_map(
length: usize,
frame_slot: &mut cte_t,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_frame_map(length: usize, frame_slot: &mut cte_t, buffer: &seL4_IPCBuffer) -> exception_t {
if length < 3 || get_extra_cap_by_index(0).is_none() {
debug!("ARMPageMap: Truncated message.");
global_ops!(current_syscall_error._type = seL4_TruncatedMessage);
Expand Down
12 changes: 2 additions & 10 deletions kernel/src/syscall/invocation/decode/arch/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ fn decode_frame_invocation(
}
}

fn decode_asid_control(
label: MessageLabel,
length: usize,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_asid_control(label: MessageLabel, length: usize, buffer: &seL4_IPCBuffer) -> exception_t {
if label != MessageLabel::RISCVASIDControlMakePool {
unsafe {
current_syscall_error._type = seL4_IllegalOperation;
Expand Down Expand Up @@ -249,11 +245,7 @@ fn decode_asid_pool(label: MessageLabel, cte: &mut cte_t) -> exception_t {
}
}

fn decode_frame_map(
length: usize,
frame_slot: &mut cte_t,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_frame_map(length: usize, frame_slot: &mut cte_t, buffer: &seL4_IPCBuffer) -> exception_t {
if length < 3 || get_extra_cap_by_index(0).is_none() {
debug!("RISCVPageMap: Truncated message.");
unsafe {
Expand Down
24 changes: 4 additions & 20 deletions kernel/src/syscall/invocation/decode/decode_tcb_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ fn decode_read_registers(
invoke_tcb_read_registers(thread, flags & BIT!(ReadRegisters_suspend), n, 0, call)
}

fn decode_write_registers(
cap: &cap_t,
length: usize,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_write_registers(cap: &cap_t, length: usize, buffer: &seL4_IPCBuffer) -> exception_t {
if length < 2 {
unsafe {
debug!("TCB CopyRegisters: Truncated message.");
Expand Down Expand Up @@ -196,11 +192,7 @@ fn decode_write_registers(
invoke_tcb_write_registers(thread, flags & BIT!(0), w, 0, buffer)
}

fn decode_copy_registers(
cap: &cap_t,
_length: usize,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_copy_registers(cap: &cap_t, _length: usize, buffer: &seL4_IPCBuffer) -> exception_t {
let flags = get_syscall_arg(0, buffer);

let source_cap = get_extra_cap_by_index(0).unwrap().cap;
Expand Down Expand Up @@ -369,11 +361,7 @@ fn decode_set_priority(cap: &cap_t, length: usize, buffer: &seL4_IPCBuffer) -> e
)
}

fn decode_set_mc_priority(
cap: &cap_t,
length: usize,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_set_mc_priority(cap: &cap_t, length: usize, buffer: &seL4_IPCBuffer) -> exception_t {
if length < 1 || get_extra_cap_by_index(0).is_none() {
debug!("TCB SetMCPPriority: Truncated message.");
unsafe {
Expand Down Expand Up @@ -405,11 +393,7 @@ fn decode_set_mc_priority(
invoke_tcb_set_mcp(convert_to_mut_type_ref::<tcb_t>(cap.get_tcb_ptr()), new_mcp)
}

fn decode_set_sched_params(
cap: &cap_t,
length: usize,
buffer: &seL4_IPCBuffer,
) -> exception_t {
fn decode_set_sched_params(cap: &cap_t, length: usize, buffer: &seL4_IPCBuffer) -> exception_t {
if length < 2 || get_extra_cap_by_index(0).is_some() {
debug!("TCB SetSchedParams: Truncated message.");
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/syscall/invocation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub(crate) mod arch;
pub mod decode;
mod invoke_cnode;
pub mod invoke_irq;
mod invoke_mmu_op;
mod invoke_tcb;
mod invoke_untyped;
pub(crate) mod arch;

use core::intrinsics::unlikely;

Expand Down
40 changes: 20 additions & 20 deletions sel4_cspace/src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ plus_define_bitfield! {
// capPGDBasePtr, get_pgd_base_ptr, set_pgd_base_ptr, 1, 0, 48, 0, true,
// capPGDIsMapped, get_pgd_is_mapped, set_pgd_is_mapped, 0, 58, 1, 0, false
// },
new_vspace_cap, CapTag::CapVspaceCap as usize => {
capVSMappedASID, get_vs_mapped_asid, set_vs_mapped_asid, 0, 48, 16, 0, false,
capVSBasePtr, get_vs_base_ptr, set_vs_base_ptr, 1, 0, 48, 0, true,
capVSIsMapped, get_vs_is_mapped, set_vs_is_mapped, 0, 58, 1, 0, false
},
new_vspace_cap, CapTag::CapVspaceCap as usize => {
capVSMappedASID, get_vs_mapped_asid, set_vs_mapped_asid, 0, 48, 16, 0, false,
capVSBasePtr, get_vs_base_ptr, set_vs_base_ptr, 1, 0, 48, 0, true,
capVSIsMapped, get_vs_is_mapped, set_vs_is_mapped, 0, 58, 1, 0, false
},
new_asid_control_cap, CapTag::CapASIDControlCap as usize => {},
new_asid_pool_cap, CapTag::CapASIDPoolCap as usize => {
capASIDBase, get_asid_base, set_asid_base, 0, 43, 16, 0, false,
Expand All @@ -129,7 +129,7 @@ impl cap_t {
CapTag::CapZombieCap => self.get_zombie_ptr(),
CapTag::CapFrameCap => self.get_frame_base_ptr(),
CapTag::CapPageTableCap => self.get_pt_base_ptr(),
CapTag::CapVspaceCap => self.get_vs_base_ptr(),
CapTag::CapVspaceCap => self.get_vs_base_ptr(),
// CapTag::CapPageDirectoryCap => self.get_pd_base_ptr(),
// CapTag::CapPageUpperDirectoryCap => self.get_pud_base_ptr(),
// CapTag::CapPageGlobalDirectoryCap => self.get_pgd_base_ptr(),
Expand Down Expand Up @@ -189,15 +189,15 @@ impl cte_t {
// ret.status = exception_t::EXCEPTION_SYSCALL_ERROR;
// }
// }
CapTag::CapVspaceCap => {
if cap.get_vs_is_mapped() !=0 {
ret.cap = cap.clone();
ret.status = exception_t::EXCEPTION_NONE;
} else {
ret.cap = cap_t::new_null_cap();
ret.status = exception_t::EXCEPTION_SYSCALL_ERROR;
}
}
CapTag::CapVspaceCap => {
if cap.get_vs_is_mapped() != 0 {
ret.cap = cap.clone();
ret.status = exception_t::EXCEPTION_NONE;
} else {
ret.cap = cap_t::new_null_cap();
ret.status = exception_t::EXCEPTION_SYSCALL_ERROR;
}
}
CapTag::CapPageTableCap => {
if cap.get_pt_is_mapped() != 0 {
ret.cap = cap.clone();
Expand Down Expand Up @@ -251,11 +251,11 @@ pub fn arch_same_region_as(cap1: &cap_t, cap2: &cap_t) -> bool {
return cap1.get_pt_base_ptr() == cap2.get_pt_base_ptr();
}
}
CapTag::CapVspaceCap => {
if cap2.get_cap_type() == CapTag::CapVspaceCap {
return cap1.get_vs_base_ptr() == cap2.get_vs_base_ptr()
}
}
CapTag::CapVspaceCap => {
if cap2.get_cap_type() == CapTag::CapVspaceCap {
return cap1.get_vs_base_ptr() == cap2.get_vs_base_ptr();
}
}
CapTag::CapASIDControlCap => {
return cap2.get_cap_type() == CapTag::CapASIDControlCap;
}
Expand Down
2 changes: 1 addition & 1 deletion sel4_vspace/src/arch/aarch64/asid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn delete_asid_pool(
#[inline]
pub fn write_it_asid_pool(it_ap_cap: &cap_t, it_vspace_cap: &cap_t) {
let ap = asid_pool_from_addr(it_ap_cap.get_cap_ptr());
let asid_map = asid_map_t::new_vspace(it_vspace_cap.get_pgd_base_ptr());
let asid_map = asid_map_t::new_vspace(it_vspace_cap.get_vs_base_ptr());
ap[IT_ASID] = asid_map;
set_asid_pool_by_index(IT_ASID >> asidLowBits, ap as *const _ as usize);
}
5 changes: 3 additions & 2 deletions sel4_vspace/src/arch/aarch64/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::{
get_kernel_page_upper_directory_base, kpptr_to_paddr, mair_types, pptr_t, pptr_to_paddr,
set_kernel_page_directory_by_index, set_kernel_page_global_directory_by_index,
set_kernel_page_table_by_index, set_kernel_page_upper_directory_by_index, vm_attributes_t,
vptr_t, GET_KPT_INDEX, GET_PD_INDEX, GET_PT_INDEX, GET_PUD_INDEX, PDE, PGDE, PTE, PUDE,
vptr_t, GET_KPT_INDEX, GET_PD_INDEX, GET_PT_INDEX, GET_PUD_INDEX, GET_UPT_INDEX, PDE, PGDE,
PTE, PUDE,
};

use super::{map_kernel_devices, page_slice};
Expand Down Expand Up @@ -232,7 +233,7 @@ fn find_pt(vspace_root: usize, vptr: VAddr, ftype: find_type) -> usize {
#[no_mangle]
#[link_section = ".boot.text"]
pub fn create_it_pd_cap(vspace_cap: &cap_t, pptr: usize, vptr: usize, asid: usize) -> cap_t {
let cap = cap_t::new_page_directory_cap(asid, pptr, 1, vptr);
let cap = cap_t::new_page_table_cap(asid, pptr, 1, vptr);
map_it_pd_cap(vspace_cap, &cap);
return cap;
}
Expand Down
8 changes: 4 additions & 4 deletions sel4_vspace/src/arch/aarch64/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn set_kernel_page_table_by_index(idx: usize, pte: PTE) {
///
/// Use page table in vspace_root to set the satp register.
pub fn set_vm_root(vspace_root: &cap_t) -> Result<(), lookup_fault_t> {
setCurrentUserVSpaceRoot(pptr_to_paddr(vspace_root.get_pgd_base_ptr()));
setCurrentUserVSpaceRoot(pptr_to_paddr(vspace_root.get_vs_base_ptr()));
Ok(())
}

Expand Down Expand Up @@ -195,9 +195,9 @@ pub fn set_vm_root_for_flush_with_thread_root(
asid: asid_t,
thread_root: &cap_t,
) -> bool {
if thread_root.get_cap_type() == CapTag::CapPageGlobalDirectoryCap
&& thread_root.get_pgd_is_mapped() != 0
&& thread_root.get_pgd_base_ptr() == vspace as usize
if thread_root.get_cap_type() == CapTag::CapVspaceCap
&& thread_root.get_vs_is_mapped() != 0
&& thread_root.get_vs_base_ptr() == vspace as usize
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion sel4_vspace/src/arch/aarch64/pagetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl PageTable {
#[no_mangle]
#[link_section = ".boot.text"]
pub fn create_it_pud_cap(vspace_cap: &cap_t, pptr: pptr_t, vptr: vptr_t, asid: usize) -> cap_t {
let cap = cap_t::new_page_upper_directory_cap(asid, pptr, 1, vptr);
let cap = cap_t::new_page_table_cap(asid, pptr, 1, vptr);
map_it_pud_cap(vspace_cap, &cap);
return cap;
}
Loading

0 comments on commit 293b7c2

Please sign in to comment.