From 7eb58d24fc3900f72e88049c11872985c84c3307 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Sat, 28 Mar 2020 20:42:51 -0700 Subject: [PATCH] pvh: Add PVH ELFNOTE This adds information to the ELF binary so that a loader will know where to start the executable. This now allows the firmware to be booted via the PVH Boot Protocol. Signed-off-by: Joe Richey --- layout.ld | 4 ++++ src/asm/mod.rs | 1 + src/asm/note.s | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/asm/note.s diff --git a/layout.ld b/layout.ld index 3a547ed5..bfcd6639 100644 --- a/layout.ld +++ b/layout.ld @@ -3,6 +3,7 @@ ENTRY(linux64_start) PHDRS { program PT_LOAD FILEHDR PHDRS ; + note PT_NOTE ; } /* Loaders like to put stuff in low memory (< 1M), so we don't use it. */ @@ -26,6 +27,9 @@ SECTIONS ASSERT((. <= ram_max - stack_size), "firmware size too big for RAM region") + /* These sections are not mapped into RAM */ + .note : { *(.note) } :note + /* Match edk2's GccBase.lds DISCARD section */ /DISCARD/ : { *(.note.GNU-stack) diff --git a/src/asm/mod.rs b/src/asm/mod.rs index ab08edf0..e4711c2f 100644 --- a/src/asm/mod.rs +++ b/src/asm/mod.rs @@ -1,2 +1,3 @@ +global_asm!(include_str!("note.s")); global_asm!(include_str!("ram32.s")); global_asm!(include_str!("ram64.s")); diff --git a/src/asm/note.s b/src/asm/note.s new file mode 100644 index 00000000..0f7021ce --- /dev/null +++ b/src/asm/note.s @@ -0,0 +1,20 @@ +.section .note, "a" + +# From xen/include/public/elfnote.h, "Physical entry point into the kernel." +XEN_ELFNOTE_PHYS32_ENTRY = 18 + +# We don't bother defining an ELFNOTE macro, as we only have one note. +# This is equialent to the kernel's: +# ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long pvh_start) +.align 4 + .long name_end - name_start # namesz + .long desc_end - desc_start # descsz + .long XEN_ELFNOTE_PHYS32_ENTRY # type +name_start: + .asciz "Xen" +name_end: +.align 4 +desc_start: + .long pvh32_start +desc_end: +.align 4