Skip to content

Commit e07fb90

Browse files
josephlrrbradford
authored andcommitted
main: Reorganize main function
We now have the protocol name as part of the Info interface. Signed-off-by: Joe Richey <[email protected]>
1 parent 8a5b0da commit e07fb90

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/boot.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::{
88

99
// Common data needed for all boot paths
1010
pub trait Info {
11+
// Name of for this boot protocol
12+
fn name(&self) -> &str;
1113
// Starting address of the Root System Descriptor Pointer
1214
fn rsdp_addr(&self) -> u64;
1315
// The kernel command line (not including null terminator)
@@ -86,6 +88,9 @@ impl Params {
8688
}
8789

8890
impl Info for Params {
91+
fn name(&self) -> &str {
92+
"Linux Boot Protocol"
93+
}
8994
fn rsdp_addr(&self) -> u64 {
9095
self.acpi_rsdp_addr
9196
}

src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,14 @@ fn boot_from_device(device: &mut block::VirtioBlockDevice, info: &dyn boot::Info
139139
}
140140

141141
#[no_mangle]
142-
pub extern "C" fn rust64_start(rdi: Option<&pvh::StartInfo>) -> ! {
143-
serial::PORT.borrow_mut().init();
144-
145-
if let Some(start_info) = rdi {
146-
log!("\nBooting via PVH Boot Protocol");
147-
run(start_info)
148-
}
149-
panic!("Unable to determine boot protocol")
142+
pub extern "C" fn rust64_start(rdi: &pvh::StartInfo) -> ! {
143+
main(rdi)
150144
}
151145

152-
fn run(info: &dyn boot::Info) -> ! {
146+
fn main(info: &dyn boot::Info) -> ! {
147+
serial::PORT.borrow_mut().init();
148+
log!("\nBooting with {}", info.name());
149+
153150
enable_sse();
154151
paging::setup();
155152

src/pvh.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ struct MemMapEntry {
3131
}
3232

3333
impl Info for StartInfo {
34+
fn name(&self) -> &str {
35+
"PVH Boot Protocol"
36+
}
3437
fn rsdp_addr(&self) -> u64 {
3538
self.rsdp_paddr
3639
}

0 commit comments

Comments
 (0)