Skip to content

Commit

Permalink
layout: Added multi sub-leaf fields (#17)
Browse files Browse the repository at this point in the history
The Structured Extended Flags are the first ones added for this.
  • Loading branch information
andrewjj20 authored Jun 12, 2024
1 parent 3790417 commit 6d31f61
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@ cpuids:
name: vme
bit: 0

0x00000007:
name: "Structured Extened Flags"
data_type:
type: SubLeafBitField
leaves:
- eax:
- {type: Int, name: "Sub-Leaf Count", bounds: {start: 0, end: 31}}
ebx:
- {type: Flag, name: HLE, bit: 4}
- {type: Flag, name: RTM, bit: 11}
- {type: Flag, name: MPX, bit: 14}
ecx: []
edx:
- {type: Flag, name: "AVX512 VP2Intersect", bit: 8}
- {type: Flag, name: "RTM Always Abort", bit: 11}
- {type: Flag, name: "RTM Force Abort", bit: 13}
- eax:
- {type: Flag, name: "AVX VNNI", bit: 14}
ebx: []
ecx: []
edx: []
- eax: []
ebx: []
ecx: []
edx:
- {type: Flag, name: PSFD, bit: 0}

0x40000000:
name: "Hypervisor ID"
data_type:
Expand Down
49 changes: 49 additions & 0 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,54 @@ impl DisplayLeaf for BitFieldLeaf {
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BitFieldMultiLeaf {
leaves: Vec<BitFieldLeaf>,
}

impl DisplayLeaf for BitFieldMultiLeaf {
fn scan_sub_leaves<CPUIDFunc: CpuidDB>(
&self,
leaf: u32,
cpuid: &CPUIDFunc,
) -> Vec<CpuidResult> {
match cpuid.get_cpuid(leaf, 0) {
Some(cpuid_start_leaf) => {
let count = cpuid_start_leaf.eax;
let mut ret = vec![cpuid_start_leaf];
for leaf_id in 1..=count {
match cpuid.get_cpuid(leaf, leaf_id) {
Some(cpuid_value) => ret.push(cpuid_value),
None => break,
}
}
ret
}
None => vec![],
}
}
fn display_leaf(
&self,
leaves: &[CpuidResult],
f: &mut fmt::Formatter<'_>,
) -> Result<(), fmt::Error> {
for (field, leaf) in self.leaves.iter().zip(leaves) {
field.display_leaf(&[*leaf], f)?;
}
Ok(())
}
fn get_facts<T: From<String> + From<u32> + From<bool>>(
&self,
leaves: &[CpuidResult],
) -> Vec<GenericFact<T>> {
self.leaves
.iter()
.zip(leaves)
.flat_map(|(field, leaf)| field.get_facts(&[*leaf]).into_iter())
.collect()
}
}

/// Enum to aid in serializing and deserializing leaf information
#[enum_dispatch(DisplayLeaf)]
#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -223,6 +271,7 @@ pub enum LeafType {
Start(StartLeaf),
String(StringLeaf),
BitField(BitFieldLeaf),
SubLeafBitField(BitFieldMultiLeaf),
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down

0 comments on commit 6d31f61

Please sign in to comment.