From 7bb1d31f68881c561cbed4275a0294e7ba34e2c8 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, 24 insertions(+), 1 deletion(-) create mode 100644 src/asm/note.s diff --git a/layout.ld b/layout.ld index 108a5dbc..5aff83e1 100644 --- a/layout.ld +++ b/layout.ld @@ -3,6 +3,7 @@ ENTRY(linux64_start) PHDRS { ram PT_LOAD FILEHDR PHDRS ; + note PT_NOTE ; } /* Loaders like to put stuff in low memory (< 1M), so we don't use it. */ @@ -13,9 +14,10 @@ stack_size = 64K; SECTIONS { - /* Mapping the program headers into RAM makes the file smaller. */ + /* Mapping the program headers and note into RAM makes the file smaller. */ . = ram_min; . += SIZEOF_HEADERS; + .note : { *(.note) } :note :ram /* These sections are mapped into RAM from the file. Omitting :ram from later sections avoids emitting empty sections in the final binary. */ diff --git a/src/asm/mod.rs b/src/asm/mod.rs index 8183e317..95dd9360 100644 --- a/src/asm/mod.rs +++ b/src/asm/mod.rs @@ -1,3 +1,4 @@ +global_asm!(include_str!("note.s")); global_asm!(include_str!("ram32.s")); global_asm!(include_str!("ram64.s")); global_asm!(include_str!("gdt64.s")); diff --git a/src/asm/note.s b/src/asm/note.s new file mode 100644 index 00000000..674cf70e --- /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 ram32_start +desc_end: +.align 4