diff --git a/src/arch/aarch64/consts.rs b/src/arch/aarch64/consts.rs index 997cc93..1656c8c 100644 --- a/src/arch/aarch64/consts.rs +++ b/src/arch/aarch64/consts.rs @@ -1,16 +1,12 @@ // Because the memory map is so important to not be aliased, it is defined here, in one place // The lower 256 PML4 entries are reserved for userspace // Each PML4 entry references up to 512 GB of memory -// The top (511) PML4 is reserved for recursive mapping // The second from the top (510) PML4 is reserved for the kernel /// The size of a single PML4 pub const PML4_SIZE: usize = 0x0000_0080_0000_0000; pub const PML4_MASK: usize = 0x0000_ff80_0000_0000; - /// Size of a page and frame - pub const PAGE_SIZE: usize = 4096; - - /// Offset of recursive paging + /// Offset of recursive paging (deprecated, but still reserved) pub const RECURSIVE_PAGE_OFFSET: usize = (-(PML4_SIZE as isize)) as usize; pub const RECURSIVE_PAGE_PML4: usize = (RECURSIVE_PAGE_OFFSET & PML4_MASK)/PML4_SIZE; @@ -18,28 +14,21 @@ pub const KERNEL_OFFSET: usize = RECURSIVE_PAGE_OFFSET - PML4_SIZE; pub const KERNEL_PML4: usize = (KERNEL_OFFSET & PML4_MASK)/PML4_SIZE; - /// Kernel stack size - must be kept in sync with early_init.S. Used by memory::init - pub const KERNEL_STACK_SIZE: usize = PAGE_SIZE; - /// Offset to kernel heap pub const KERNEL_HEAP_OFFSET: usize = KERNEL_OFFSET - PML4_SIZE; pub const KERNEL_HEAP_PML4: usize = (KERNEL_HEAP_OFFSET & PML4_MASK)/PML4_SIZE; - /// Size of kernel heap pub const KERNEL_HEAP_SIZE: usize = 1 * 1024 * 1024; // 1 MB - /// Offset of environment region - pub const KERNEL_ENV_OFFSET: usize = KERNEL_HEAP_OFFSET - PML4_SIZE; - /// Offset of temporary mapping for misc kernel bring-up actions - pub const KERNEL_TMP_MISC_OFFSET: usize = KERNEL_ENV_OFFSET - PML4_SIZE; + pub const KERNEL_TMP_MISC_OFFSET: usize = KERNEL_HEAP_OFFSET - PML4_SIZE; /// Offset to kernel percpu variables pub const KERNEL_PERCPU_OFFSET: usize = KERNEL_TMP_MISC_OFFSET - PML4_SIZE; - pub const KERNEL_PERCPU_PML4: usize = (KERNEL_PERCPU_OFFSET & PML4_MASK) / PML4_SIZE; - + pub const KERNEL_PERCPU_PML4: usize = (KERNEL_PERCPU_OFFSET & PML4_MASK)/PML4_SIZE; /// Size of kernel percpu variables - pub const KERNEL_PERCPU_SIZE: usize = 64 * 1024; // 64 KB + pub const KERNEL_PERCPU_SHIFT: u8 = 16; // 2^16 = 64 KiB + pub const KERNEL_PERCPU_SIZE: usize = 1_usize << KERNEL_PERCPU_SHIFT; /// Offset of physmap // This needs to match RMM's PHYS_OFFSET @@ -48,67 +37,6 @@ /// Offset to user image pub const USER_OFFSET: usize = 0; - pub const USER_PML4: usize = (USER_OFFSET & PML4_MASK)/PML4_SIZE; /// End offset of the user image, i.e. kernel start pub const USER_END_OFFSET: usize = 256 * PML4_SIZE; - - /// Offset to user TCB - pub const USER_TCB_OFFSET: usize = 0xB000_0000; - - /// Offset to user arguments - pub const USER_ARG_OFFSET: usize = USER_OFFSET + PML4_SIZE/2; - - /// Offset to user heap - pub const USER_HEAP_OFFSET: usize = USER_OFFSET + PML4_SIZE; - pub const USER_HEAP_PML4: usize = (USER_HEAP_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset to user grants - pub const USER_GRANT_OFFSET: usize = USER_HEAP_OFFSET + PML4_SIZE; - pub const USER_GRANT_PML4: usize = (USER_GRANT_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset to user stack - pub const USER_STACK_OFFSET: usize = USER_GRANT_OFFSET + PML4_SIZE; - pub const USER_STACK_PML4: usize = (USER_STACK_OFFSET & PML4_MASK)/PML4_SIZE; - /// Size of user stack - pub const USER_STACK_SIZE: usize = 1024 * 1024; // 1 MB - - /// Offset to user sigstack - pub const USER_SIGSTACK_OFFSET: usize = USER_STACK_OFFSET + PML4_SIZE; - pub const USER_SIGSTACK_PML4: usize = (USER_SIGSTACK_OFFSET & PML4_MASK)/PML4_SIZE; - /// Size of user sigstack - pub const USER_SIGSTACK_SIZE: usize = 256 * 1024; // 256 KB - - /// Offset to user TLS - pub const USER_TLS_OFFSET: usize = USER_SIGSTACK_OFFSET + PML4_SIZE; - pub const USER_TLS_PML4: usize = (USER_TLS_OFFSET & PML4_MASK)/PML4_SIZE; - // Maximum TLS allocated to each PID, should be approximately 8 MB - pub const USER_TLS_SIZE: usize = PML4_SIZE / 65536; - - /// Offset to user temporary image (used when cloning) - pub const USER_TMP_OFFSET: usize = USER_TLS_OFFSET + PML4_SIZE; - pub const USER_TMP_PML4: usize = (USER_TMP_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset to user temporary heap (used when cloning) - pub const USER_TMP_HEAP_OFFSET: usize = USER_TMP_OFFSET + PML4_SIZE; - pub const USER_TMP_HEAP_PML4: usize = (USER_TMP_HEAP_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset to user temporary page for grants - pub const USER_TMP_GRANT_OFFSET: usize = USER_TMP_HEAP_OFFSET + PML4_SIZE; - pub const USER_TMP_GRANT_PML4: usize = (USER_TMP_GRANT_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset to user temporary stack (used when cloning) - pub const USER_TMP_STACK_OFFSET: usize = USER_TMP_GRANT_OFFSET + PML4_SIZE; - pub const USER_TMP_STACK_PML4: usize = (USER_TMP_STACK_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset to user temporary sigstack (used when cloning) - pub const USER_TMP_SIGSTACK_OFFSET: usize = USER_TMP_STACK_OFFSET + PML4_SIZE; - pub const USER_TMP_SIGSTACK_PML4: usize = (USER_TMP_SIGSTACK_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset to user temporary tls (used when cloning) - pub const USER_TMP_TLS_OFFSET: usize = USER_TMP_SIGSTACK_OFFSET + PML4_SIZE; - pub const USER_TMP_TLS_PML4: usize = (USER_TMP_TLS_OFFSET & PML4_MASK)/PML4_SIZE; - - /// Offset for usage in other temporary pages - pub const USER_TMP_MISC_OFFSET: usize = USER_TMP_TLS_OFFSET + PML4_SIZE; - pub const USER_TMP_MISC_PML4: usize = (USER_TMP_MISC_OFFSET & PML4_MASK)/PML4_SIZE; diff --git a/src/arch/aarch64/debug.rs b/src/arch/aarch64/debug.rs index 24ff375..a1d0260 100644 --- a/src/arch/aarch64/debug.rs +++ b/src/arch/aarch64/debug.rs @@ -3,6 +3,8 @@ use spin::MutexGuard; use crate::log::{LOG, Log}; +#[cfg(feature = "graphical_debug")] +use crate::devices::graphical_debug::{DEBUG_DISPLAY, DebugDisplay}; #[cfg(feature = "serial_debug")] use super::device::{ serial::COM1, @@ -11,6 +13,8 @@ use super::device::{ pub struct Writer<'a> { log: MutexGuard<'a, Option>, + #[cfg(feature = "graphical_debug")] + display: MutexGuard<'a, Option>, #[cfg(feature = "serial_debug")] serial: MutexGuard<'a, Option>, } @@ -19,6 +23,8 @@ impl<'a> Writer<'a> { pub fn new() -> Writer<'a> { Writer { log: LOG.lock(), + #[cfg(feature = "graphical_debug")] + display: DEBUG_DISPLAY.lock(), #[cfg(feature = "serial_debug")] serial: COM1.lock(), } @@ -31,6 +37,13 @@ impl<'a> Writer<'a> { } } + #[cfg(feature = "graphical_debug")] + { + if let Some(ref mut display) = *self.display { + let _ = display.write(buf); + } + } + #[cfg(feature = "serial_debug")] { if let Some(ref mut serial) = *self.serial { diff --git a/src/arch/aarch64/start.rs b/src/arch/aarch64/start.rs index 102cf98..ed94fcb 100644 --- a/src/arch/aarch64/start.rs +++ b/src/arch/aarch64/start.rs @@ -62,23 +62,14 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { let bootstrap = { let args = &*args_ptr; - let kernel_base = args.kernel_base as usize; - let kernel_size = args.kernel_size as usize; - let stack_base = args.stack_base as usize; - let stack_size = args.stack_size as usize; - let env_base = args.env_base as usize; - let env_size = args.env_size as usize; - let dtb_base = args.dtb_base as usize; - let dtb_size = args.dtb_size as usize; - // BSS should already be zero { assert_eq!(BSS_TEST_ZERO, 0); assert_eq!(DATA_TEST_NONZERO, 0xFFFF_FFFF_FFFF_FFFF); } - KERNEL_BASE.store(kernel_base, Ordering::SeqCst); - KERNEL_SIZE.store(kernel_size, Ordering::SeqCst); + KERNEL_BASE.store(args.kernel_base, Ordering::SeqCst); + KERNEL_SIZE.store(args.kernel_size, Ordering::SeqCst); //TODO: Remove hard-coded UART for QEMU virt machine { @@ -91,7 +82,7 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { } // Try to find serial port prior to logging - device::serial::init_early(crate::PHYS_OFFSET + dtb_base, dtb_size); + device::serial::init_early(crate::PHYS_OFFSET + args.dtb_base, args.dtb_size); // Convert env to slice let env = slice::from_raw_parts((args.env_base + crate::PHYS_OFFSET) as *const u8, args.env_size); @@ -170,6 +161,10 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { // Setup kernel heap allocator::init(); + // Set up double buffer for grpahical debug now that heap is available + #[cfg(feature = "graphical_debug")] + graphical_debug::init_heap(); + // Activate memory logging log::init(); @@ -179,6 +174,10 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! { // Initialize all of the non-core devices not otherwise needed to complete initialization device::init_noncore(); + // Stop graphical debug + #[cfg(feature = "graphical_debug")] + graphical_debug::fini(); + BSP_READY.store(true, Ordering::SeqCst); crate::Bootstrap {