diff --git a/src/arch/x86/ipi.rs b/src/arch/x86/ipi.rs deleted file mode 100644 index 28d21cd40b..0000000000 --- a/src/arch/x86/ipi.rs +++ /dev/null @@ -1,29 +0,0 @@ -#[derive(Clone, Copy, Debug)] -#[repr(u8)] -pub enum IpiKind { - Wakeup = 0x40, - Tlb = 0x41, - Switch = 0x42, - Pit = 0x43, -} - -#[derive(Clone, Copy, Debug)] -#[repr(u8)] -pub enum IpiTarget { - Current = 1, - All = 2, - Other = 3, -} - -#[cfg(not(feature = "multi_core"))] -#[inline(always)] -pub fn ipi(_kind: IpiKind, _target: IpiTarget) {} - -#[cfg(feature = "multi_core")] -#[inline(always)] -pub fn ipi(kind: IpiKind, target: IpiTarget) { - use crate::device::local_apic::LOCAL_APIC; - - let icr = (target as u64) << 18 | 1 << 14 | (kind as u64); - unsafe { LOCAL_APIC.set_icr(icr) }; -} diff --git a/src/arch/x86/mod.rs b/src/arch/x86/mod.rs index f6b23047cc..9703c62db0 100644 --- a/src/arch/x86/mod.rs +++ b/src/arch/x86/mod.rs @@ -9,9 +9,6 @@ pub mod consts; /// CPUID wrapper pub mod cpuid; -/// Debugging support -pub mod debug; - /// Global descriptor table pub mod gdt; @@ -22,15 +19,9 @@ pub mod interrupt; /// Interrupt descriptor table pub mod idt; -/// Inter-processor interrupts -pub mod ipi; - /// Paging pub mod paging; -/// Page table isolation -pub mod pti; - pub mod rmm; /// Initialization and start function diff --git a/src/arch/x86_64/debug.rs b/src/arch/x86_64/debug.rs deleted file mode 100644 index 4013e94f0c..0000000000 --- a/src/arch/x86_64/debug.rs +++ /dev/null @@ -1,106 +0,0 @@ -use core::fmt; -#[cfg(feature = "qemu_debug")] -use spin::Mutex; -use spin::MutexGuard; - -#[cfg(any(feature = "lpss_debug", feature = "serial_debug"))] -use crate::devices::uart_16550::SerialPort; -use crate::log::{Log, LOG}; -#[cfg(feature = "lpss_debug")] -use crate::syscall::io::Mmio; -#[cfg(any(feature = "qemu_debug", feature = "serial_debug"))] -use crate::syscall::io::Pio; -#[cfg(feature = "qemu_debug")] -use syscall::io::Io; - -#[cfg(feature = "serial_debug")] -use super::device::serial::COM1; -#[cfg(feature = "lpss_debug")] -use super::device::serial::LPSS; -#[cfg(feature = "system76_ec_debug")] -use super::device::system76_ec::{System76Ec, SYSTEM76_EC}; -#[cfg(feature = "graphical_debug")] -use crate::devices::graphical_debug::{DebugDisplay, DEBUG_DISPLAY}; - -#[cfg(feature = "qemu_debug")] -pub static QEMU: Mutex> = Mutex::new(Pio::::new(0x402)); - -pub struct Writer<'a> { - log: MutexGuard<'a, Option>, - #[cfg(feature = "graphical_debug")] - display: MutexGuard<'a, Option>, - #[cfg(feature = "lpss_debug")] - lpss: MutexGuard<'a, Option<&'static mut SerialPort>>>, - #[cfg(feature = "qemu_debug")] - qemu: MutexGuard<'a, Pio>, - #[cfg(feature = "serial_debug")] - serial: MutexGuard<'a, SerialPort>>, - #[cfg(feature = "system76_ec_debug")] - system76_ec: MutexGuard<'a, Option>, -} - -impl<'a> Writer<'a> { - pub fn new() -> Writer<'a> { - Writer { - log: LOG.lock(), - #[cfg(feature = "graphical_debug")] - display: DEBUG_DISPLAY.lock(), - #[cfg(feature = "lpss_debug")] - lpss: LPSS.lock(), - #[cfg(feature = "qemu_debug")] - qemu: QEMU.lock(), - #[cfg(feature = "serial_debug")] - serial: COM1.lock(), - #[cfg(feature = "system76_ec_debug")] - system76_ec: SYSTEM76_EC.lock(), - } - } - - pub fn write(&mut self, buf: &[u8]) { - { - if let Some(ref mut log) = *self.log { - log.write(buf); - } - } - - #[cfg(feature = "graphical_debug")] - { - if let Some(ref mut display) = *self.display { - let _ = display.write(buf); - } - } - - #[cfg(feature = "lpss_debug")] - { - if let Some(ref mut lpss) = *self.lpss { - lpss.write(buf); - } - } - - #[cfg(feature = "qemu_debug")] - { - for &b in buf { - self.qemu.write(b); - } - } - - #[cfg(feature = "serial_debug")] - { - self.serial.write(buf); - } - - #[cfg(feature = "system76_ec_debug")] - { - if let Some(ref mut system76_ec) = *self.system76_ec { - system76_ec.print_slice(buf); - } - } - } -} - -impl<'a> fmt::Write for Writer<'a> { - fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { - self.write(s.as_bytes()); - Ok(()) - } -} diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index 46bd5390cb..bbb67dc73b 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -15,9 +15,6 @@ pub mod consts; /// CPUID wrapper pub mod cpuid; -/// Debugging support -pub mod debug; - /// Global descriptor table pub mod gdt; @@ -28,18 +25,12 @@ pub mod interrupt; /// Interrupt descriptor table pub mod idt; -/// Inter-processor interrupts -pub mod ipi; - /// Miscellaneous processor features pub mod misc; /// Paging pub mod paging; -/// Page table isolation -pub mod pti; - pub mod rmm; /// Initialization and start function diff --git a/src/arch/x86_64/pti.rs b/src/arch/x86_64/pti.rs deleted file mode 100644 index c1e9422c84..0000000000 --- a/src/arch/x86_64/pti.rs +++ /dev/null @@ -1,88 +0,0 @@ -#[cfg(feature = "pti")] -use core::ptr; - -#[cfg(feature = "pti")] -use crate::memory::Frame; -#[cfg(feature = "pti")] -use crate::paging::entry::EntryFlags; -#[cfg(feature = "pti")] -use crate::paging::ActivePageTable; - -#[cfg(feature = "pti")] -#[thread_local] -pub static mut PTI_CPU_STACK: [u8; 256] = [0; 256]; - -#[cfg(feature = "pti")] -#[thread_local] -pub static mut PTI_CONTEXT_STACK: usize = 0; - -#[cfg(feature = "pti")] -#[inline(always)] -unsafe fn switch_stack(old: usize, new: usize) { - let old_rsp: usize; - asm!("", out("rsp") old_rsp); - - let offset_rsp = old - old_rsp; - - let new_rsp = new - offset_rsp; - - ptr::copy_nonoverlapping(old_rsp as *const u8, new_rsp as *mut u8, offset_rsp); - - asm!("", out("rsp") new_rsp); -} - -#[cfg(feature = "pti")] -#[inline(always)] -pub unsafe fn map() { - // { - // let mut active_table = unsafe { ActivePageTable::new() }; - // - // // Map kernel heap - // let address = active_table.p4()[::KERNEL_HEAP_PML4].address(); - // let frame = Frame::containing_address(address); - // let mut flags = active_table.p4()[::KERNEL_HEAP_PML4].flags(); - // flags.remove(EntryFlags::PRESENT); - // active_table.p4_mut()[::KERNEL_HEAP_PML4].set(frame, flags); - // - // // Reload page tables - // active_table.flush_all(); - // } - - // Switch to per-context stack - switch_stack( - PTI_CPU_STACK.as_ptr() as usize + PTI_CPU_STACK.len(), - PTI_CONTEXT_STACK, - ); -} - -#[cfg(feature = "pti")] -#[inline(always)] -pub unsafe extern "C" fn unmap() { - // Switch to per-CPU stack - switch_stack( - PTI_CONTEXT_STACK, - PTI_CPU_STACK.as_ptr() as usize + PTI_CPU_STACK.len(), - ); - - // { - // let mut active_table = unsafe { ActivePageTable::new() }; - // - // // Unmap kernel heap - // let address = active_table.p4()[::KERNEL_HEAP_PML4].address(); - // let frame = Frame::containing_address(address); - // let mut flags = active_table.p4()[::KERNEL_HEAP_PML4].flags(); - // flags.insert(EntryFlags::PRESENT); - // active_table.p4_mut()[::KERNEL_HEAP_PML4].set(frame, flags); - // - // // Reload page tables - // active_table.flush_all(); - // } -} - -#[cfg(not(feature = "pti"))] -#[inline(always)] -pub unsafe fn map() {} - -#[cfg(not(feature = "pti"))] -#[inline(always)] -pub unsafe extern "C" fn unmap() {} diff --git a/src/arch/x86/debug.rs b/src/arch/x86_shared/debug.rs similarity index 100% rename from src/arch/x86/debug.rs rename to src/arch/x86_shared/debug.rs diff --git a/src/arch/x86_64/ipi.rs b/src/arch/x86_shared/ipi.rs similarity index 100% rename from src/arch/x86_64/ipi.rs rename to src/arch/x86_shared/ipi.rs diff --git a/src/arch/x86_shared/mod.rs b/src/arch/x86_shared/mod.rs index b39dc88464..6054aba52f 100644 --- a/src/arch/x86_shared/mod.rs +++ b/src/arch/x86_shared/mod.rs @@ -1,6 +1,15 @@ +/// Debugging support +pub mod debug; + /// Devices pub mod device; +/// Inter-processor interrupts +pub mod ipi; + +/// Page table isolation +pub mod pti; + /// Stop function pub mod stop; diff --git a/src/arch/x86/pti.rs b/src/arch/x86_shared/pti.rs similarity index 100% rename from src/arch/x86/pti.rs rename to src/arch/x86_shared/pti.rs