Skip to content

Commit 5fb4d60

Browse files
authored
Merge pull request #362 from 00xc/stage2
stage2: refactor stage2
2 parents 75b83b3 + 3b611e0 commit 5fb4d60

File tree

5 files changed

+263
-181
lines changed

5 files changed

+263
-181
lines changed

bootlib/src/platform.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ pub enum SvsmPlatformType {
1212
Snp = 1,
1313
}
1414

15-
impl SvsmPlatformType {
16-
pub fn as_u32(&self) -> u32 {
17-
match self {
18-
Self::Native => 0,
19-
Self::Snp => 1,
20-
}
21-
}
22-
23-
pub fn from_u32(value: u32) -> Self {
15+
impl From<u32> for SvsmPlatformType {
16+
fn from(value: u32) -> Self {
2417
match value {
2518
1 => Self::Snp,
2619
_ => Self::Native,
2720
}
2821
}
2922
}
23+
24+
impl From<SvsmPlatformType> for u32 {
25+
fn from(p: SvsmPlatformType) -> u32 {
26+
p as u32
27+
}
28+
}

igvmbuilder/src/stage2_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Stage2Stack {
4747
};
4848

4949
let mut stage2_stack = self.stage2_stack;
50-
stage2_stack.platform_type = platform.as_u32();
50+
stage2_stack.platform_type = u32::from(platform);
5151

5252
// The native platform does not record VTOM because there is no
5353
// encryption in native platforms.

kernel/src/error.rs

+9
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ use crate::sev::ghcb::GhcbError;
2626
use crate::sev::msr_protocol::GhcbMsrError;
2727
use crate::sev::SevSnpError;
2828
use crate::task::TaskError;
29+
use elf::ElfError;
2930

3031
/// A generic error during SVSM operation.
3132
#[derive(Clone, Copy, Debug)]
3233
pub enum SvsmError {
34+
/// Errors during ELF parsing and loading.
35+
Elf(ElfError),
3336
/// Errors related to GHCB
3437
Ghcb(GhcbError),
3538
/// Errors related to MSR protocol
@@ -65,3 +68,9 @@ pub enum SvsmError {
6568
/// Errors from #VC handler
6669
Vc(VcError),
6770
}
71+
72+
impl From<ElfError> for SvsmError {
73+
fn from(err: ElfError) -> Self {
74+
Self::Elf(err)
75+
}
76+
}

0 commit comments

Comments
 (0)