Skip to content

Commit 5a8298b

Browse files
committed
refactor: migrate to pvh crate
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
1 parent 24bba9a commit 5a8298b

5 files changed

Lines changed: 44 additions & 61 deletions

File tree

Cargo.lock

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +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"] }
4243
uart_16550 = "0.4.0"
4344
x86_64 = { version = "0.15.4", default-features = false, features = [
4445
"instructions",

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ fn boot_from_device(
179179

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

src/pvh.rs

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

4-
use core::mem::size_of;
4+
use pvh::start_info::{MemmapTableEntry, StartInfo};
55

66
use crate::{
77
bootinfo::{EntryType, Info, MemoryEntry},
88
common,
99
layout::MemoryDescriptor,
1010
};
1111

12-
// Structures from xen/include/public/arch-x86/hvm/start_info.h
13-
#[derive(Debug)]
14-
#[repr(C)]
15-
pub struct StartInfo {
16-
magic: [u8; 4],
17-
version: u32,
18-
flags: u32,
19-
nr_modules: u32,
20-
modlist_paddr: u64,
21-
cmdline_paddr: u64,
22-
rsdp_paddr: u64,
23-
memmap_paddr: u64,
24-
memmap_entries: u32,
25-
_pad: u32,
26-
}
27-
28-
#[derive(Clone, Copy, Debug)]
29-
#[repr(C)]
30-
struct MemMapEntry {
31-
addr: u64,
32-
size: u64,
33-
entry_type: u32,
34-
_pad: u32,
35-
}
36-
37-
impl From<MemMapEntry> for MemoryEntry {
38-
fn from(value: MemMapEntry) -> Self {
12+
impl From<MemmapTableEntry> for MemoryEntry {
13+
fn from(value: MemmapTableEntry) -> Self {
3914
Self {
4015
addr: value.addr,
4116
size: value.size,
42-
entry_type: EntryType::from(value.entry_type),
17+
entry_type: EntryType::from(value.ty),
4318
}
4419
}
4520
}
@@ -63,7 +38,7 @@ impl Info for StartInfo {
6338
}
6439
fn entry(&self, idx: usize) -> MemoryEntry {
6540
assert!(idx < self.num_entries());
66-
let ptr = self.memmap_paddr as *const MemMapEntry;
41+
let ptr = self.memmap_paddr as *const MemmapTableEntry;
6742
let entry = unsafe { *ptr.add(idx) };
6843
MemoryEntry::from(entry)
6944
}
@@ -77,34 +52,7 @@ impl Info for StartInfo {
7752

7853
// The PVH Boot Protocol starts at the 32-bit entrypoint to our firmware.
7954
extern "C" {
80-
fn ram32_start();
55+
fn ram32_start() -> !;
8156
}
8257

83-
// The kind/name/desc of the PHV ELF Note are from xen/include/public/elfnote.h.
84-
// This is the "Physical entry point into the kernel".
85-
const XEN_ELFNOTE_PHYS32_ENTRY: u32 = 18;
86-
type Name = [u8; 4];
87-
type Desc = unsafe extern "C" fn();
88-
89-
// We make sure our ELF Note has an alignment of 4 for maximum compatibility.
90-
// Some software (QEMU) calculates padding incorectly if alignment != 4.
91-
#[repr(C, packed(4))]
92-
struct Note {
93-
name_size: u32,
94-
desc_size: u32,
95-
kind: u32,
96-
name: Name,
97-
desc: Desc,
98-
}
99-
100-
// This is: ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .quad ram32_start)
101-
#[cfg(not(test))]
102-
#[link_section = ".note"]
103-
#[used]
104-
static PVH_NOTE: Note = Note {
105-
name_size: size_of::<Name>() as u32,
106-
desc_size: size_of::<Desc>() as u32,
107-
kind: XEN_ELFNOTE_PHYS32_ENTRY,
108-
name: *b"Xen\0",
109-
desc: ram32_start,
110-
};
58+
pvh::xen_elfnote_phys32_entry!(ram32_start);

x86_64-unknown-none.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SECTIONS
1414
/* Mapping the program headers and note into RAM makes the file smaller. */
1515
. = ram_min;
1616
. += SIZEOF_HEADERS;
17-
.note : { *(.note) } :note :ram
17+
.note : { *(.note .note.*) } :note :ram
1818

1919
/* These sections are mapped into RAM from the file. Omitting :ram from
2020
later sections avoids emitting empty sections in the final binary. */

0 commit comments

Comments
 (0)