Skip to content

Commit 7a06c3a

Browse files
committed
refactor: use PVH StartInfoReader
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
1 parent 5a8298b commit 7a06c3a

4 files changed

Lines changed: 16 additions & 35 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fdt = "0.1.5"
3939
chrono = { version = "0.4", default-features = false }
4040

4141
[target.'cfg(target_arch = "x86_64")'.dependencies]
42-
pvh = { version = "0.1", default-features = false, features = ["elfnote"] }
42+
pvh = "0.1"
4343
uart_16550 = "0.4.0"
4444
x86_64 = { version = "0.15.4", default-features = false, features = [
4545
"instructions",

src/common.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,6 @@ macro_rules! container_of_mut {
1515
}};
1616
}
1717

18-
// SAFETY: Requires that addr point to a static, null-terminated C-string.
19-
// The returned slice does not include the null-terminator.
20-
#[cfg(all(target_arch = "x86_64", not(feature = "coreboot")))]
21-
pub unsafe fn from_cstring(addr: u64) -> &'static [u8] {
22-
if addr == 0 {
23-
return &[];
24-
}
25-
let start = addr as *const u8;
26-
let mut size: usize = 0;
27-
while start.add(size).read() != 0 {
28-
size += 1;
29-
}
30-
core::slice::from_raw_parts(start, size)
31-
}
32-
3318
pub fn ascii_strip(s: &[u8]) -> &str {
3419
core::str::from_utf8(s).unwrap().trim_matches(char::from(0))
3520
}

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,22 @@ fn boot_from_device(
179179

180180
#[cfg(target_arch = "x86_64")]
181181
#[no_mangle]
182-
pub extern "C" fn rust64_start(
183-
#[cfg(not(feature = "coreboot"))] pvh_info: &::pvh::start_info::StartInfo,
184-
) -> ! {
182+
pub extern "C" fn rust64_start(#[cfg(not(feature = "coreboot"))] start_info_paddr: u32) -> ! {
185183
serial::PORT.borrow_mut().init();
186184
logger::init();
187185

188186
arch::x86_64::sse::enable_sse();
189187
arch::x86_64::paging::setup();
190188

191189
#[cfg(feature = "coreboot")]
192-
let info = &coreboot::StartInfo::default();
190+
let info = coreboot::StartInfo::default();
193191

194192
#[cfg(not(feature = "coreboot"))]
195-
let info = pvh_info;
193+
let info = unsafe {
194+
::pvh::start_info::reader::StartInfoReader::from_paddr_identity(start_info_paddr).unwrap()
195+
};
196196

197-
main(info)
197+
main(&info)
198198
}
199199

200200
#[cfg(target_arch = "aarch64")]

src/pvh.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright 2020 Google LLC
33

4-
use pvh::start_info::{MemmapTableEntry, StartInfo};
4+
use pvh::start_info::{
5+
reader::{MemMap, StartInfoReader},
6+
MemmapTableEntry,
7+
};
58

69
use crate::{
710
bootinfo::{EntryType, Info, MemoryEntry},
8-
common,
911
layout::MemoryDescriptor,
1012
};
1113

@@ -19,27 +21,21 @@ impl From<MemmapTableEntry> for MemoryEntry {
1921
}
2022
}
2123

22-
impl Info for StartInfo {
24+
impl<M: MemMap> Info for StartInfoReader<'_, M> {
2325
fn name(&self) -> &str {
2426
"PVH Boot Protocol"
2527
}
2628
fn rsdp_addr(&self) -> Option<u64> {
27-
Some(self.rsdp_paddr)
29+
Some(self.raw().rsdp_paddr)
2830
}
2931
fn cmdline(&self) -> &[u8] {
30-
unsafe { common::from_cstring(self.cmdline_paddr) }
32+
self.cmdline().unwrap_or_default().to_bytes()
3133
}
3234
fn num_entries(&self) -> usize {
33-
// memmap_paddr and memmap_entries only exist in version 1 or later
34-
if self.version < 1 || self.memmap_paddr == 0 {
35-
return 0;
36-
}
37-
self.memmap_entries as usize
35+
self.memmap().len()
3836
}
3937
fn entry(&self, idx: usize) -> MemoryEntry {
40-
assert!(idx < self.num_entries());
41-
let ptr = self.memmap_paddr as *const MemmapTableEntry;
42-
let entry = unsafe { *ptr.add(idx) };
38+
let entry = self.memmap()[idx];
4339
MemoryEntry::from(entry)
4440
}
4541
fn kernel_load_addr(&self) -> u64 {

0 commit comments

Comments
 (0)