From a530a34a09c04afb4a70b253a120d2eedf98d3fb Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Mon, 6 Nov 2023 18:30:41 +0200 Subject: [PATCH] refactor: fix warnings/fix incorrect EarlyMapping::map --- src/arch/x86_64/acpi.rs | 14 +++++++++----- src/arch/x86_64/boot/mod.rs | 9 +++------ src/arch/x86_64/mem/mod.rs | 5 ++--- src/arch/x86_64/registers/mod.rs | 10 ++-------- src/main.rs | 6 +++++- src/util/mod.rs | 21 ++++++++------------- 6 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/arch/x86_64/acpi.rs b/src/arch/x86_64/acpi.rs index 80ce12d6..9380f8f7 100644 --- a/src/arch/x86_64/acpi.rs +++ b/src/arch/x86_64/acpi.rs @@ -28,7 +28,6 @@ use crate::{ PhysicalAddress, }, sync::IrqSafeSpinlock, - util, }; use super::intrinsics; @@ -180,8 +179,10 @@ impl acpi_system::Handler for AcpiHandlerImpl { Ok(()) } - fn stall(duration: Duration) { - util::polling_sleep(duration).ok(); + fn stall(_duration: Duration) { + // TODO polling_sleep is not yet implemented properly + todo!() + // util::polling_sleep(duration).ok(); } } @@ -307,8 +308,9 @@ impl aml::Handler for AcpiHandlerImpl { fn write_ec_u8(&self, _address: u64, _value: u8) {} - fn sleep(&self, duration: Duration) { - util::polling_sleep(duration).unwrap(); + fn sleep(&self, _duration: Duration) { + todo!() + // util::polling_sleep(duration).unwrap(); } } @@ -335,7 +337,9 @@ impl AcpiHandler for AcpiHandlerImpl { } /// Initializes ACPI management +#[allow(unused)] pub fn init_acpi(tables: &'static AcpiTables) -> Result<(), Error> { + // TODO currently broken for real HW let mut system = AcpiSystem::new(tables, Box::new(AcpiHandlerImpl)).unwrap(); system.initialize(AcpiInterruptMethod::Apic).unwrap(); diff --git a/src/arch/x86_64/boot/mod.rs b/src/arch/x86_64/boot/mod.rs index 7b23deea..679dafdc 100644 --- a/src/arch/x86_64/boot/mod.rs +++ b/src/arch/x86_64/boot/mod.rs @@ -1,24 +1,21 @@ //! x86-64 boot and entry functions use core::{arch::global_asm, sync::atomic::Ordering}; -use tock_registers::interfaces::{ReadWriteable, Writeable}; +use tock_registers::interfaces::Writeable; use yboot_proto::{ v1::{FramebufferOption, MemoryMap}, LoadProtocolHeader, LoadProtocolV1, KERNEL_MAGIC, LOADER_MAGIC, PROTOCOL_VERSION_1, }; use crate::{ - arch::x86_64::{ - registers::{CR0, MSR_IA32_KERNEL_GS_BASE}, - smp::CPU_COUNT, - }, + arch::x86_64::{registers::MSR_IA32_KERNEL_GS_BASE, smp::CPU_COUNT}, fs::devfs, kernel_main, kernel_secondary_main, mem::KERNEL_VIRT_OFFSET, task::runtime, }; -use super::{cpuid::init_cpuid, exception, registers::CR4, ARCHITECTURE}; +use super::{cpuid::init_cpuid, exception, ARCHITECTURE}; pub enum BootData { YBoot(&'static LoadProtocolV1), diff --git a/src/arch/x86_64/mem/mod.rs b/src/arch/x86_64/mem/mod.rs index a5168bfc..ebdc8f97 100644 --- a/src/arch/x86_64/mem/mod.rs +++ b/src/arch/x86_64/mem/mod.rs @@ -5,7 +5,7 @@ use core::{ use abi::error::Error; use kernel_util::util::OneTimeInit; -use memtables::{FixedTables, KERNEL_L3_COUNT}; +use memtables::FixedTables; use static_assertions::{const_assert_eq, const_assert_ne}; pub mod process; @@ -13,7 +13,6 @@ pub mod table; use crate::{ arch::x86_64::{intrinsics, mem::table::PageAttributes, registers::CR3}, - device::display::font::PcScreenFont, mem::{ address::{FromRaw, IntoRaw, KernelImageObject}, device::RawDeviceMemoryMapping, @@ -249,7 +248,7 @@ impl<'a, T: Sized> EarlyMapping<'a, T> { let offset = physical.page_offset::(); let page_count = (offset + layout.size() + L3::SIZE - 1) / L3::SIZE; - let virt = map_early_pages(physical, page_count)?; + let virt = map_early_pages(aligned, page_count)?; let value = &mut *((virt + offset) as *mut T); Ok(EarlyMapping { value, page_count }) diff --git a/src/arch/x86_64/registers/mod.rs b/src/arch/x86_64/registers/mod.rs index 03e9e70e..0d05e99a 100644 --- a/src/arch/x86_64/registers/mod.rs +++ b/src/arch/x86_64/registers/mod.rs @@ -1,4 +1,5 @@ //! Helper types for interfacing with x86-64 registers +#![allow(unused)] macro_rules! impl_read { ($t:ident, $register:ty, $body:expr) => { @@ -259,10 +260,7 @@ mod cr0 { } mod cr3 { - use tock_registers::{ - interfaces::{ReadWriteable, Readable}, - register_bitfields, - }; + use tock_registers::{interfaces::ReadWriteable, register_bitfields}; register_bitfields! { u64, @@ -282,10 +280,6 @@ mod cr3 { assert_eq!(address & 0xFFF, 0); self.modify(CR3::ADDR.val((address as u64) >> 12)) } - - pub fn address(&self) -> usize { - (self.read(CR3::ADDR) as usize) << 12 - } } /// x86-64 control register 3 diff --git a/src/main.rs b/src/main.rs index bdb659c3..f82b4acb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,11 @@ trait_alias, strict_provenance )] -#![allow(clippy::new_without_default, clippy::fn_to_numeric_cast)] +#![allow( + clippy::new_without_default, + clippy::fn_to_numeric_cast, + async_fn_in_trait +)] // #![warn(missing_docs)] #![allow(missing_docs)] #![no_std] diff --git a/src/util/mod.rs b/src/util/mod.rs index 20124369..fa3e2598 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,9 +1,4 @@ //! Various kernel utility functions -use core::time::Duration; - -use yggdrasil_abi::error::Error; - -// use crate::arch::{Architecture, ARCHITECTURE}; pub mod queue; pub mod ring; @@ -24,11 +19,11 @@ impl>> ResultIterator for I { } } -/// Performs a busy-loop sleep until the specified duration has passed -pub fn polling_sleep(duration: Duration) -> Result<(), Error> { - // TODO no non-IRQ mode timestamp provider - for i in 0..1000000 { - core::hint::spin_loop(); - } - Ok(()) -} +// /// Performs a busy-loop sleep until the specified duration has passed +// pub fn polling_sleep(duration: Duration) -> Result<(), Error> { +// // TODO no non-IRQ mode timestamp provider +// for i in 0..1000000 { +// core::hint::spin_loop(); +// } +// Ok(()) +// }