[wip] make it compile

This commit is contained in:
Berkus Decker 2021-01-12 17:35:23 +02:00
parent b594552f23
commit 94789e7979
6 changed files with 38 additions and 14 deletions

View File

@ -16,6 +16,10 @@ use {
crate::arch::memory::{PhysAddr, VirtAddr},
crate::objects::thread::ThreadState,
crate::caps::{ReplyCapability, NullCapability},
core::result::Result, // temp: use own result type here
crate::platform::rpi3::gic::get_active_irq, // temp: derive based on current platform
crate::objects::thread::TCB,
crate::caps::captable::CapPath,
};
// Syscalls (kernel API)
@ -100,6 +104,20 @@ fn handle_syscall(syscall: SysCall) -> Result<()> {
Ok(())
}
fn handle_interrupt(int: u16) -> Result<()> {
Ok(())
}
// some kernel globals
static KernelCurrentThread: &TCB = Default::default(); // @todo Scheduler.CurrentThread
static KernelCurrentFault: Fault = Fault::NoFault;
static KernelSchedulerAction: SchedulerAction = SchedulerAction::None;
static KernelDomainTime: usize = 100; // @todo Scheduler.DomainTime
const msgInfoRegister: usize = 1; // @todo wip number
const capRegister: usize = 2;
const n_MsgRegisters: usize = 2;
// end kernel globals
fn handle_invocation(is_call: bool, is_blocking: bool) -> Result<()> {
let thread: &TCB = KernelCurrentThread;
@ -107,7 +125,7 @@ fn handle_invocation(is_call: bool, is_blocking: bool) -> Result<()> {
let info: MessageInfo = messageInfoFromWord(infoRegister);
let cap_ptr: CapPath = thread.get_register(capRegister);
result = thread.lookup_cap_and_slot(cap_ptr);
let result = thread.lookup_cap_and_slot(cap_ptr);
if result.is_err() {
println!(
@ -234,8 +252,8 @@ fn handle_yield() {
#[derive(Debug, Snafu)]
enum Fault {
#[snafu(display("null fault"))]
Null,
#[snafu(display("no fault"))]
NoFault,
#[snafu(display("capability fault in {} phase at address {:x}", if in_receive_phase { "receive" } else { "send" }, address))]
Capability {
in_receive_phase: bool,

View File

@ -151,13 +151,16 @@ struct CapSpace {
type CapPath = u64;
#[derive(Debug, Snafu)]
enum LookupFault {
pub(crate) enum LookupFault {
InvalidRoot,
GuardMismatch,
DepthMismatch { expected: usize, actual: usize },
NoResolvedBits,
}
type Slot = u64; // @temp
type BitsRemaining = usize; // @temp
// seL4: resolveAddressBits(nodeCap, capptr, n_bits)
pub(crate) fn resolve_address_bits(
node_cap: &dyn Capability,
@ -180,7 +183,7 @@ pub(crate) fn resolve_address_bits(
let cap_guard = node_cap.guard();
// @todo common code to extract guard_bits from an int?
let guard = (capptr >> core::min(n_bits - guard_bits, 63)) & ((1 << guard_bits) - 1);
let guard = (capptr >> core::cmp::min(n_bits - guard_bits, 63)) & ((1 << guard_bits) - 1);
if guard_bits > n_bits || guard != cap_guard {
return Err(LookupFault::GuardMismatch);

View File

@ -27,15 +27,15 @@
use {crate::memory::PhysAddr, core::convert::TryFrom, snafu::Snafu};
mod capnode_cap;
mod captable;
pub(crate) mod captable;
mod derivation_tree;
mod domain_cap;
mod endpoint_cap;
mod irq_control_cap;
mod irq_handler_cap;
mod notification_cap;
pub mod null_cap;
pub mod reply_cap;
pub(crate) mod null_cap;
pub(crate) mod reply_cap;
mod resume_cap;
mod thread_cap;
mod untyped_cap;
@ -74,7 +74,8 @@ macro_rules! capdef {
#[doc = "Wrapper representing `" $name "Capability`."]
pub struct [<$name Capability>](LocalRegisterCopy<u128, [<$name Cap>]::Register>);
impl [<$name Capability>] {
type Type = [<$name Cap>]::Register;
//@todo must be part of trait impl then? See rust-lang/rust#8995
// type Type = [<$name Cap>]::Register;
}
impl Capability for [<$name Capability>] {
#[inline]

View File

@ -3,7 +3,7 @@
* Copyright (c) Berkus Decker <berkus+vesper@metta.systems>
*/
use crate::{arch, arch::memory::VirtAddr};
use crate::{api::Fault, arch, arch::memory::VirtAddr, caps::captable::LookupFault};
// trait Thread {
// // Configuration
@ -50,15 +50,15 @@ use crate::{arch, arch::memory::VirtAddr};
// }
// impl super::KernelObject for Thread {}
impl super::KernelObject for TCB {
impl super::NucleusObject for TCB {
const SIZE_BITS: usize = 12;
}
// -- from actual code parts in api.rs
/* TCB: size 64 bytes + sizeof(arch_tcb_t) (aligned to nearest power of 2) */
struct TCB {
arch_specific: arch::objects::TCB,
pub(crate) struct TCB<'a> {
arch_specific: arch::objects::thread::TCB,
state: ThreadState, // 12 bytes?
/* Notification that this TCB is bound to. If this is set, when this TCB waits on
* any sync endpoint, it may receive a signal from a Notification object.
@ -85,7 +85,7 @@ struct TCB {
ep_next: *mut TCB,
ep_prev: *mut TCB,
/* Use any remaining space for a thread name */
name: &str,
name: &'a str,
// name_storage: [u8],// add SIZE_BITS calculations for length of storage in here somewhere
}

View File

@ -0,0 +1 @@
pub fn get_active_irq() -> core::Result<u16> {}

View File

@ -7,6 +7,7 @@
pub mod display;
pub mod fb;
pub mod gic;
pub mod gpio;
pub mod mailbox;
pub mod mini_uart;