Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean ffi 2 #9

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 83 additions & 2 deletions kernel/src/arch/aarch64/exception.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,98 @@
use crate::arch::aarch64::consts::ARMDataAbort;
use crate::arch::aarch64::consts::ARMPrefetchAbort;
use crate::compatibility::lookupIPCBuffer;
use crate::halt;
use crate::kernel::boot::current_fault;
use crate::object::lookupCapAndSlot;
use crate::strnlen;
use crate::syscall::handle_fault;
use crate::syscall::{
SysDebugCapIdentify, SysDebugDumpScheduler, SysDebugHalt, SysDebugNameThread, SysDebugPutChar,
SysDebugSnapshot, SysGetClock,
};

use aarch64_cpu::registers::Readable;
use aarch64_cpu::registers::TTBR0_EL1;
use sel4_common::arch::ArchReg;
use log::debug;
use sel4_common::arch::ArchReg::*;
use sel4_common::print;
use sel4_common::fault::seL4_Fault_t;
use sel4_common::sel4_config::seL4_MsgMaxLength;
use sel4_common::structures::exception_t;
use sel4_common::utils::global_read;
use sel4_cspace::arch::CapTag;
use sel4_task::{activateThread, get_currenct_thread, get_current_domain, schedule};

use super::instruction::*;

#[no_mangle]
pub fn handleUnknownSyscall(w: isize) -> exception_t {
let thread = get_currenct_thread();
if w == SysDebugPutChar {
print!("{}",thread.tcbArch.get_register(Cap) as u8 as char);
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugDumpScheduler {
// unimplement debug
// println!("debug dump scheduler");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugHalt {
// unimplement debug
// println!("debug halt");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugSnapshot {
// unimplement debug
// println!("debug snapshot");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugCapIdentify {
// println!("debug cap identify");
let cptr = thread.tcbArch.get_register(Cap);
let lu_ret = lookupCapAndSlot(thread, cptr);
let cap_type = lu_ret.cap.get_cap_type();
thread.tcbArch.set_register(Cap, cap_type as usize);
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugNameThread {
// println!("debug name thread");
let cptr = thread.tcbArch.get_register(Cap);
let lu_ret = lookupCapAndSlot(thread, cptr);
let cap_type = lu_ret.cap.get_cap_type();

if cap_type != CapTag::CapThreadCap {
debug!("SysDebugNameThread: cap is not a TCB, halting");
halt();
}
let name = lookupIPCBuffer(true, thread) + 1;
if name == 0 {
debug!("SysDebugNameThread: Failed to lookup IPC buffer, halting");
halt();
}

let len = strnlen(name as *const u8, seL4_MsgMaxLength * 8);
if len == seL4_MsgMaxLength * 8 {
debug!("SysDebugNameThread: Name too long, halting");
halt();
}

// setThreadName(TCB_PTR(cap_thread_cap_get_capTCBPtr(lu_ret.cap)), name);
return exception_t::EXCEPTION_NONE;
}
if w == SysGetClock {
/*no implementation of aarch64 get clock*/
return exception_t::EXCEPTION_NONE;
}
unsafe {
current_fault = seL4_Fault_t::new_unknown_syscall_fault(w as usize);
handle_fault(get_currenct_thread());
}
schedule();
activateThread();
exception_t::EXCEPTION_NONE
}

#[no_mangle]
pub fn handleUserLevelFault(w_a: usize, w_b: usize) -> exception_t {
unsafe {
Expand Down Expand Up @@ -84,7 +165,7 @@ pub fn handle_vm_fault(type_: usize) -> exception_t {
exception_t::EXCEPTION_FAULT
}
ARMPrefetchAbort => {
let pc = get_currenct_thread().tcbArch.get_register(ArchReg::FaultIP);
let pc = get_currenct_thread().tcbArch.get_register(FaultIP);
let fault = get_esr();
unsafe {
current_fault = seL4_Fault_t::new_vm_fault(pc, fault, 1);
Expand Down
1 change: 1 addition & 0 deletions kernel/src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod arm_gic;
use aarch64_cpu::registers::{Writeable, CNTV_CTL_EL0, CNTV_TVAL_EL0};
pub use boot::try_init_kernel;
pub use c_traps::restore_user_context;
pub use exception::handleUnknownSyscall;
pub(crate) use pg::set_vm_root_for_flush;
pub use platform::init_freemem;

Expand Down
82 changes: 81 additions & 1 deletion kernel/src/arch/riscv/exception.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,91 @@
use super::read_stval;
use super::{read_stval, read_time};
use crate::compatibility::lookupIPCBuffer;
use crate::config::*;
use crate::halt;
use crate::kernel::boot::current_fault;
use crate::object::lookupCapAndSlot;
use crate::strnlen;
use crate::syscall::handle_fault;
use crate::syscall::{
SysDebugCapIdentify, SysDebugDumpScheduler, SysDebugHalt, SysDebugNameThread, SysDebugPutChar,
SysDebugSnapshot, SysGetClock,
};
use log::debug;
use sel4_common::arch::ArchReg::*;
use sel4_common::fault::seL4_Fault_t;
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();
if w == SysDebugPutChar {
print!("{}",thread.tcbArch.get_register(Cap) as u8 as char);
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugDumpScheduler {
// unimplement debug
// println!("debug dump scheduler");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugHalt {
// unimplement debug
// println!("debug halt");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugSnapshot {
// unimplement debug
// println!("debug snap shot");
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugCapIdentify {
let cptr = thread.tcbArch.get_register(Cap);
let lu_ret = lookupCapAndSlot(thread, cptr);
let cap_type = lu_ret.cap.get_cap_type();
thread.tcbArch.set_register(Cap, cap_type as usize);
return exception_t::EXCEPTION_NONE;
}
if w == SysDebugNameThread {
let cptr = thread.tcbArch.get_register(Cap);
let lu_ret = lookupCapAndSlot(thread, cptr);
let cap_type = lu_ret.cap.get_cap_type();

if cap_type != CapTag::CapThreadCap {
debug!("SysDebugNameThread: cap is not a TCB, halting");
halt();
}
let name = lookupIPCBuffer(true, thread) + 1;
if name == 0 {
debug!("SysDebugNameThread: Failed to lookup IPC buffer, halting");
halt();
}

let len = strnlen(name as *const u8, seL4_MsgMaxLength * 8);
if len == seL4_MsgMaxLength * 8 {
debug!("SysDebugNameThread: Name too long, halting");
halt();
}

// setThreadName(TCB_PTR(cap_thread_cap_get_capTCBPtr(lu_ret.cap)), name);
return exception_t::EXCEPTION_NONE;
}
if w == SysGetClock {
let current = read_time();
thread.tcbArch.set_register(Cap, current);
return exception_t::EXCEPTION_NONE;
}
unsafe {
current_fault = seL4_Fault_t::new_unknown_syscall_fault(w as usize);
handle_fault(get_currenct_thread());
}
schedule();
activateThread();
exception_t::EXCEPTION_NONE
}

#[no_mangle]
pub fn handleUserLevelFault(w_a: usize, w_b: usize) -> exception_t {
unsafe {
Expand Down
1 change: 1 addition & 0 deletions kernel/src/arch/riscv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use core::arch::asm;
pub use platform::{init_cpu, init_freemem};

use crate::config::RESET_CYCLES;
pub use exception::handleUnknownSyscall;
use sel4_common::arch::set_timer;

core::arch::global_asm!(include_str!("restore_fp.S"));
Expand Down
14 changes: 12 additions & 2 deletions kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ pub mod invocation;
pub mod syscall_reply;
pub mod utils;

use super::arch::handleUnknownSyscall;
use core::intrinsics::unlikely;
use sel4_common::arch::ArchReg;
use sel4_common::fault::{lookup_fault_t, seL4_Fault_t, FaultType};
use sel4_common::ffi_call;
// use sel4_common::ffi_call;
use sel4_common::sel4_config::tcbCaller;

pub const SysCall: isize = -1;
Expand All @@ -16,6 +17,14 @@ pub const SysRecv: isize = -5;
pub const SysReply: isize = -6;
pub const SysYield: isize = -7;
pub const SysNBRecv: isize = -8;

pub const SysDebugPutChar: isize = -9;
pub const SysDebugDumpScheduler: isize = -10;
pub const SysDebugHalt: isize = -11;
pub const SysDebugCapIdentify: isize = -12;
pub const SysDebugSnapshot: isize = -13;
pub const SysDebugNameThread: isize = -14;
pub const SysGetClock: isize = -30;
use sel4_common::structures::exception_t;
use sel4_common::utils::{convert_to_mut_type_ref, ptr_to_mut};
use sel4_cspace::interface::CapTag;
Expand All @@ -37,7 +46,8 @@ use self::invocation::handleInvocation;
pub fn slowpath(syscall: usize) {
if (syscall as isize) < -8 || (syscall as isize) > -1 {
// using ffi_call! macro to call c function
ffi_call!(handleUnknownSyscall(id: usize => syscall));
handleUnknownSyscall(syscall as isize);
// ffi_call!(handleUnknownSyscall(id: usize => syscall));
} else {
handleSyscall(syscall);
}
Expand Down
2 changes: 1 addition & 1 deletion sel4_common/src/arch/aarch64/registers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::arch::ArchReg;

// X0 = 0, /* 0x00 */
pub(super) const capRegister: usize = 0;
pub const capRegister: usize = 0;
pub(super) const badgeRegister: usize = 0;
// X1 = 1, /* 0x08 */
pub(super) const msgInfoRegister: usize = 1;
Expand Down
2 changes: 2 additions & 0 deletions sel4_task/src/tcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ impl tcb_t {
self.tcbState.set_ts_type(state as usize);
schedule_tcb(self);
}
pub fn DebugAppend(&mut self) {}
pub fn DebugRemove(&mut self) {}
}

#[inline]
Expand Down
Loading