From 4891cac91f1e13efe806f2bb70687f16bbe238bb Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 14 Aug 2026 16:52:58 -0400 Subject: [PATCH 1/2] patina_internal_cpu: Delete orphaned file (cpu.rs) This file is an orphaned version of: `patina_dxe_core\src\cpu\efi_cpu\x64\cpu.rs` That was accidentally left in place during earlier refactors of the CPU code. It also follows some practices like directly referencing `r-efi` that we want to avoid in favor of using `patina::standard::efi` so it is being removed to avoid confusion. Refactor references: - Moved to patina_dxe_core in 3d598615fe0334d59e04f17b2320b8a56fc7bdb6 - Accidentally added back in ac11069630ece945a4a3368e842fff7fb59e39e3 Signed-off-by: Michael Kubacki --- core/patina_internal_cpu/src/cpu/x64/cpu.rs | 96 --------------------- 1 file changed, 96 deletions(-) delete mode 100644 core/patina_internal_cpu/src/cpu/x64/cpu.rs 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(())); - } -} From e82b6d67cd876d3b95fd4016e9aab0c081911da8 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 14 Aug 2026 14:17:42 -0400 Subject: [PATCH 2/2] deny.toml: Ban direct dependecies on r-efi outside the SDK crate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `r_efi::efi` is re-exported from `patina::standard::efi`, with the guidance that code should depend on the re-export. While r-efi is only an explicit crate dependency of the `patina` crate today, it could inadvertently be added as a direct dependency of other crates in the repo in the future. This change adds a deny rule to the `deny.toml` file to prevent direct dependencies on `r-efi` outside of the SDK crate. This also allows tracking of transitive dependencies on `r-efi`. Both `patina` and `getrandom` are allowed to depend on `r-efi` as `getrandom` does so today used as follows by `patina_internal_core`: ``` warning[unmatched-wrapper]: direct parent 'getrandom = 0.4.3' of banned crate 'r-efi = 6.0.0' was not marked as a wrapper ┌─ deny.toml:146:16 │ 146 │ { crate = "r-efi", reason = "Depend on `patina` and use `patina::standard::efi` instead of r-efi directly.", wrappers = ["patina"] } │ ━━━━━ ───────────────────────────────────────────────────────────────────────────── reason │ │ │ banned here │ ├ r-efi v6.0.0 └── getrandom v0.4.3 └── rand v0.10.2 └── (dev) patina_internal_core v23.0.2 └── patina_dxe_core v23.0.2 ├── (dev) patina_adv_logger v23.0.2 ``` A small touchup to arch.rs is made to use the re-exported path. Signed-off-by: Michael Kubacki --- deny.toml | 3 ++- sdk/patina/src/arch.rs | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) 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"))] {