Skip to content

Commit c106bdb

Browse files
committed
pvh: Add Structures for PVH Boot Protocol
These are simply translated from the C structs in: xen/include/public/arch-x86/hvm/start_info.h Note that unlike the Linux Boot Protocol structures, these structures don't need to be `#[repr(packed)]` as they are garunteed to have the proper alignment. Signed-off-by: Joe Richey <joerichey@google.com>
1 parent 50bec24 commit c106bdb

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mod paging;
4444
mod part;
4545
mod pci;
4646
mod pe;
47+
mod pvh;
4748
mod virtio;
4849

4950
#[cfg(all(not(test), feature = "log-panic"))]

src/pvh.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use crate::{
2+
boot::{E820Entry, Info},
3+
common,
4+
};
5+
6+
// Structures from xen/include/public/arch-x86/hvm/start_info.h
7+
#[derive(Debug)]
8+
#[repr(C)]
9+
pub struct StartInfo {
10+
magic: [u8; 4],
11+
version: u32,
12+
flags: u32,
13+
nr_modules: u32,
14+
modlist_paddr: u64,
15+
cmdline_paddr: u64,
16+
rsdp_paddr: u64,
17+
memmap_paddr: u64,
18+
memmap_entries: u32,
19+
_pad: u32,
20+
}
21+
22+
#[derive(Clone, Copy, Debug)]
23+
#[repr(C)]
24+
struct MemMapEntry {
25+
addr: u64,
26+
size: u64,
27+
entry_type: u32,
28+
_pad: u32,
29+
}
30+
31+
impl Info for StartInfo {
32+
fn rsdp_addr(&self) -> u64 {
33+
self.rsdp_paddr
34+
}
35+
fn cmdline(&self) -> &[u8] {
36+
unsafe { common::from_cstring(self.cmdline_paddr) }
37+
}
38+
fn num_entries(&self) -> u8 {
39+
// memmap_paddr and memmap_entries only exist in version 1 or later
40+
if self.version < 1 || self.memmap_paddr == 0 {
41+
return 0;
42+
}
43+
self.memmap_entries as u8
44+
}
45+
fn entry(&self, idx: u8) -> E820Entry {
46+
assert!(idx < self.num_entries());
47+
let ptr = self.memmap_paddr as *const MemMapEntry;
48+
let entry = unsafe { *ptr.offset(idx as isize) };
49+
E820Entry {
50+
addr: entry.addr,
51+
size: entry.size,
52+
entry_type: entry.entry_type,
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)