Skip to content

Commit

Permalink
pvh: Move note definition/declaration to Rust
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
josephlr committed Apr 9, 2020
1 parent 7bfc362 commit 317cf22
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/asm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
global_asm!(include_str!("note.s"));
global_asm!(include_str!("ram32.s"));
global_asm!(include_str!("ram64.s"));
global_asm!(include_str!("gdt64.s"));
20 changes: 0 additions & 20 deletions src/asm/note.s

This file was deleted.

34 changes: 34 additions & 0 deletions src/pvh.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::mem::size_of;

use crate::{
boot::{E820Entry, Info},
common,
Expand Down Expand Up @@ -53,3 +55,35 @@ impl Info for StartInfo {
}
}
}

// The PVH Boot Protocol starts at the 32-bit entrypoint to our firmware.
extern "C" {
fn ram32_start();
}

// The kind/name/desc of the PHV ELF Note are from xen/include/public/elfnote.h.
// This is the "Physical entry point into the kernel".
const XEN_ELFNOTE_PHYS32_ENTRY: u32 = 18;
type Name = [u8; 4];
type Desc = unsafe extern "C" fn();

#[repr(C, packed(4))]
struct Note {
name_size: u32,
desc_size: u32,
kind: u32,
name: Name,
desc: Desc,
}

// This is: ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .quad ram32_start)
#[cfg(not(test))]
#[link_section = ".note"]
#[used]
static PVH_NOTE: Note = Note {
name_size: size_of::<Name>() as u32,
desc_size: size_of::<Desc>() as u32,
kind: XEN_ELFNOTE_PHYS32_ENTRY,
name: *b"Xen\0",
desc: ram32_start,
};

0 comments on commit 317cf22

Please sign in to comment.