From 9f38cec485132ed76e67994d5505b977fa195f13 Mon Sep 17 00:00:00 2001 From: Oliver Anderson Date: Fri, 20 Mar 2026 16:21:02 +0100 Subject: [PATCH] arch: Serializable CPUID parameters We introduce a type representing CPUID parameters that will be utilized by the CPU profiles. We place this new type in a module that will be further populated with types related to adjusting CPUID entries based on the CPU profile in a follow up commit. Signed-off-by: Oliver Anderson On-behalf-of: SAP oliver.anderson@sap.com --- .../x86_64/cpu_profile/cpuid_adjustments.rs | 66 +++++++++++++++++++ arch/src/x86_64/cpu_profile/mod.rs | 6 ++ arch/src/x86_64/mod.rs | 1 + 3 files changed, 73 insertions(+) create mode 100644 arch/src/x86_64/cpu_profile/cpuid_adjustments.rs create mode 100644 arch/src/x86_64/cpu_profile/mod.rs diff --git a/arch/src/x86_64/cpu_profile/cpuid_adjustments.rs b/arch/src/x86_64/cpu_profile/cpuid_adjustments.rs new file mode 100644 index 000000000..10ae1bb61 --- /dev/null +++ b/arch/src/x86_64/cpu_profile/cpuid_adjustments.rs @@ -0,0 +1,66 @@ +// Copyright © 2026 Cyberus Technology GmbH +// +// SPDX-License-Identifier: Apache-2.0 +// + +//! This module contains types associated with adjusting CPUID entries according +//! to a selected CPU profile. + +use std::ops::RangeInclusive; + +use serde::{Deserialize, Serialize}; + +use crate::x86_64::{CpuidReg, deserialize_u32_hex, serialize_u32_hex}; + +/// Parameters for inspecting CPUID definitions. +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +pub struct CpuidParameters { + /// The leaf (EAX) parameter used with the CPUID instruction + #[serde( + serialize_with = "serialize_u32_hex", + deserialize_with = "deserialize_u32_hex" + )] + pub leaf: u32, + /// The sub-leaf (ECX) parameter used with the CPUID instruction + #[serde( + serialize_with = "serialize_range_hex", + deserialize_with = "deserialize_range_hex" + )] + pub sub_leaf: RangeInclusive, + /// The register we are interested in inspecting which gets filled by the CPUID instruction + pub register: CpuidReg, +} + +// Only used for (de-)serialization +#[derive(Debug, Serialize, Deserialize)] +struct ProvisionalRangeInclusive { + #[serde( + serialize_with = "serialize_u32_hex", + deserialize_with = "deserialize_u32_hex" + )] + start: u32, + #[serde( + serialize_with = "serialize_u32_hex", + deserialize_with = "deserialize_u32_hex" + )] + end: u32, +} + +fn serialize_range_hex( + input: &RangeInclusive, + serializer: S, +) -> Result { + let provisional = ProvisionalRangeInclusive { + start: *input.start(), + end: *input.end(), + }; + provisional.serialize(serializer) +} + +fn deserialize_range_hex<'de, D: serde::Deserializer<'de>>( + deserializer: D, +) -> Result, D::Error> { + let ProvisionalRangeInclusive { start, end } = + ProvisionalRangeInclusive::deserialize(deserializer)?; + Ok(start..=end) +} diff --git a/arch/src/x86_64/cpu_profile/mod.rs b/arch/src/x86_64/cpu_profile/mod.rs new file mode 100644 index 000000000..a2780443c --- /dev/null +++ b/arch/src/x86_64/cpu_profile/mod.rs @@ -0,0 +1,6 @@ +// Copyright © 2026 Cyberus Technology GmbH +// +// SPDX-License-Identifier: Apache-2.0 +// + +pub mod cpuid_adjustments; diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index b60b430cf..cb51471c4 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -7,6 +7,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-BSD-3-Clause file. +pub mod cpu_profile; pub mod interrupts; pub mod layout; pub mod regs;