Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layout: Added multi sub-leaf fields #17

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean for there to be 3 of each register?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a list of maps. each map is a struct that has fields eax,ebx,ecx,edx that are also lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, it means there could be 3 sub-leaves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is probably worth looking at the BitField structure that those end up becoming.

- {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
Loading