diff --git a/core/patina_internal_cpu/src/cpu/x64/cpu.rs b/core/patina_internal_cpu/src/cpu/x64/cpu.rs deleted file mode 100644 index 09cbcffa0..000000000 --- a/core/patina_internal_cpu/src/cpu/x64/cpu.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! X64 CPU initialization implementation -//! -//! ## License -//! -//! Copyright (c) Microsoft Corporation. -//! -//! SPDX-License-Identifier: Apache-2.0 -//! -#[cfg(not(test))] -use super::gdt; -use crate::interrupts; -#[cfg(not(test))] -use core::arch::asm; -use patina::{ - error::EfiError, - pi::protocol::cpu_arch::{CpuFlushType, CpuInitType}, -}; -use r_efi::efi; - -pub const CACHE_WRITEBACK_GRANULE: u32 = 4; // Using 4 bytes following precedence set by Tianocore - -/// Struct to implement X64 Cpu Init. -/// -/// This struct cannot be used directly. It replaces the `EfiCpu` struct when compiling for the x86_64 architecture. -#[derive(Default)] -pub struct EfiCpuX64; - -#[allow(dead_code)] -impl EfiCpuX64 { - /// This function initializes the CPU for the x86_64 architecture. - pub fn initialize(&mut self) -> Result<(), EfiError> { - // Initialize floating point units - self.initialize_fpu(); - - // disable interrupts - interrupts::disable_interrupts(); - - // Initialize GDT - self.initialize_gdt(); - - interrupts::enable_interrupts(); - - Ok(()) - } - - fn initialize_gdt(&self) { - #[cfg(not(test))] - gdt::init(); - } - - #[cfg_attr(coverage, coverage(off))] - fn initialize_fpu(&self) { - #[cfg(not(test))] - // SAFETY: This assembly writes only hard coded values to CR4 register, and MMX and FPU control words. No - // inputs are used that could violate memory safety. - unsafe { - // sdm vol. 1, x87 FPU Control Word configuration - static FPU_CONTROL_WORD: u16 = 0x037F; - - // sdm vol. 1, MMX Control Status Register configuration - static MMX_CONTROL_WORD: u32 = 0x1F80; - let fpu_cw = &raw const FPU_CONTROL_WORD; - let mmx_cw = &raw const MMX_CONTROL_WORD; - asm!( - "finit", - "fldcw [{fpu_cw}]", - - // Set OSFXSR (bit 9) in CR4 to enable SSE instructions - "mov {temp}, cr4", - "or {temp}, {BIT9}", - "mov cr4, {temp}", - - "ldmxcsr [{mmx_cw}]", - temp = out(reg) _, - fpu_cw = in(reg) fpu_cw, - mmx_cw = in(reg) mmx_cw, - BIT9 = const patina::bit!(9), - options(nostack) - ); - } - } -} - -#[cfg(test)] -#[cfg_attr(coverage, coverage(off))] -mod tests { - - use super::*; - - #[test] - fn test_initialize() { - let mut x64_cpu_init = EfiCpuX64; - - assert_eq!(x64_cpu_init.initialize(), Ok(())); - } -} diff --git a/deny.toml b/deny.toml index e13a2b5f0..d1baba0b5 100644 --- a/deny.toml +++ b/deny.toml @@ -142,7 +142,8 @@ deny = [ # is a direct dependency of the otherwise banned crate #{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, { crate = "indoc", reason = "Does not support CRLF, producing hard to read logs." }, - { crate = "tiny-keccak", reason = "Not updated in 5 years. Use alternative." } + { crate = "tiny-keccak", reason = "Not updated in 5 years. Use alternative." }, + { crate = "r-efi", reason = "Depend on `patina` and use `patina::standard::efi` instead of r-efi directly.", wrappers = ["patina", "getrandom"] } ] # List of features to allow/deny diff --git a/sdk/patina/src/arch.rs b/sdk/patina/src/arch.rs index d8ec2ea99..518b44fef 100644 --- a/sdk/patina/src/arch.rs +++ b/sdk/patina/src/arch.rs @@ -7,9 +7,8 @@ //! SPDX-License-Identifier: Apache-2.0 //! -use crate::{error::EfiError, pi::protocol::cpu_arch::CpuFlushType}; +use crate::{error::EfiError, pi::protocol::cpu_arch::CpuFlushType, standard::efi}; use core::num::NonZeroU64; -use r_efi::efi; cfg_if::cfg_if! { if #[cfg(not(target_os = "uefi"))] {