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 <oliver.anderson@cyberus-technology.de>
On-behalf-of: SAP oliver.anderson@sap.com
This commit is contained in:
Oliver Anderson
2026-03-20 16:21:02 +01:00
committed by Rob Bradford
parent 7700f4b585
commit 9f38cec485
3 changed files with 73 additions and 0 deletions

View File

@@ -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<u32>,
/// 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<S: serde::Serializer>(
input: &RangeInclusive<u32>,
serializer: S,
) -> Result<S::Ok, S::Error> {
let provisional = ProvisionalRangeInclusive {
start: *input.start(),
end: *input.end(),
};
provisional.serialize(serializer)
}
fn deserialize_range_hex<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<RangeInclusive<u32>, D::Error> {
let ProvisionalRangeInclusive { start, end } =
ProvisionalRangeInclusive::deserialize(deserializer)?;
Ok(start..=end)
}

View File

@@ -0,0 +1,6 @@
// Copyright © 2026 Cyberus Technology GmbH
//
// SPDX-License-Identifier: Apache-2.0
//
pub mod cpuid_adjustments;

View File

@@ -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;