From 94789e79797d9c55fdcb17f5124ba54bb8d2828f Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Tue, 12 Jan 2021 17:35:23 +0200 Subject: [PATCH] [wip] make it compile --- nucleus/src/api.rs | 24 +++++++++++++++++++++--- nucleus/src/caps/captable.rs | 7 +++++-- nucleus/src/caps/mod.rs | 9 +++++---- nucleus/src/objects/thread.rs | 10 +++++----- nucleus/src/platform/rpi3/gic.rs | 1 + nucleus/src/platform/rpi3/mod.rs | 1 + 6 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 nucleus/src/platform/rpi3/gic.rs diff --git a/nucleus/src/api.rs b/nucleus/src/api.rs index 9f92844..5d6bf9c 100644 --- a/nucleus/src/api.rs +++ b/nucleus/src/api.rs @@ -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, diff --git a/nucleus/src/caps/captable.rs b/nucleus/src/caps/captable.rs index a0dcfca..f99add7 100644 --- a/nucleus/src/caps/captable.rs +++ b/nucleus/src/caps/captable.rs @@ -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); diff --git a/nucleus/src/caps/mod.rs b/nucleus/src/caps/mod.rs index 08093f3..10c586b 100644 --- a/nucleus/src/caps/mod.rs +++ b/nucleus/src/caps/mod.rs @@ -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]::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] diff --git a/nucleus/src/objects/thread.rs b/nucleus/src/objects/thread.rs index 65d621e..1663b49 100644 --- a/nucleus/src/objects/thread.rs +++ b/nucleus/src/objects/thread.rs @@ -3,7 +3,7 @@ * Copyright (c) Berkus Decker */ -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 } diff --git a/nucleus/src/platform/rpi3/gic.rs b/nucleus/src/platform/rpi3/gic.rs new file mode 100644 index 0000000..cc15c0e --- /dev/null +++ b/nucleus/src/platform/rpi3/gic.rs @@ -0,0 +1 @@ +pub fn get_active_irq() -> core::Result {} diff --git a/nucleus/src/platform/rpi3/mod.rs b/nucleus/src/platform/rpi3/mod.rs index 38fab56..bad3660 100644 --- a/nucleus/src/platform/rpi3/mod.rs +++ b/nucleus/src/platform/rpi3/mod.rs @@ -7,6 +7,7 @@ pub mod display; pub mod fb; +pub mod gic; pub mod gpio; pub mod mailbox; pub mod mini_uart;