Skip to content

Commit eb9a243

Browse files
committed
pvh: Move note definition/declaration to Rust
The structure of the ELF note can be done with pure Rust code. We can definie the Name and Desc types and use a static struct to hold the note. Due to Rust's limitations on "pointer-to-integer cast", we have to have Desc have a function pointer type, which means that field is now 8 bytes long instead of 4. However, this doesn't seem to be an issue. The binary still works w/ PVH Boot on QEMU and CH. Signed-off-by: Joe Richey <[email protected]>
1 parent 08b2089 commit eb9a243

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

src/asm/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
global_asm!(include_str!("note.s"));
21
global_asm!(include_str!("ram32.s"));
32
global_asm!(include_str!("ram64.s"));
43
global_asm!(include_str!("gdt64.s"));

src/asm/note.s

-20
This file was deleted.

src/pvh.rs

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::mem::size_of;
2+
13
use crate::{
24
boot::{E820Entry, Info},
35
common,
@@ -53,3 +55,35 @@ impl Info for StartInfo {
5355
}
5456
}
5557
}
58+
59+
// The PVH Boot Protocol starts at the 32-bit entrypoint to our firmware.
60+
extern "C" {
61+
fn ram32_start();
62+
}
63+
64+
// The kind/name/desc of the PHV ELF Note are from xen/include/public/elfnote.h.
65+
// This is the "Physical entry point into the kernel".
66+
const XEN_ELFNOTE_PHYS32_ENTRY: u32 = 18;
67+
type Name = [u8; 4];
68+
type Desc = unsafe extern "C" fn();
69+
70+
#[repr(C, packed(4))]
71+
struct Note {
72+
name_size: u32,
73+
desc_size: u32,
74+
kind: u32,
75+
name: Name,
76+
desc: Desc,
77+
}
78+
79+
// This is: ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .quad ram32_start)
80+
#[cfg(not(test))]
81+
#[link_section = ".note"]
82+
#[used]
83+
static PVH_NOTE: Note = Note {
84+
name_size: size_of::<Name>() as u32,
85+
desc_size: size_of::<Desc>() as u32,
86+
kind: XEN_ELFNOTE_PHYS32_ENTRY,
87+
name: *b"Xen\0",
88+
desc: ram32_start,
89+
};

0 commit comments

Comments
 (0)