31 fprintf (file,
"0x%02hhx, ", *(c++));
35 fprintf (file,
"0x%02hhx,", *c);
37 fprintf (file,
"0x%02hhx", *c);
42#define XEN_ELFNOTE_PHYS32_ENTRY 18
53# FDF include file that defines a PVH ELF header.\r\n\
55# Copyright (c) 2022, Intel Corporation. All rights reserved.\r\n\
57# SPDX-License-Identifier: BSD-2-Clause-Patent\r\n\
70 size_t ovmf_blob_size = 0x00200000;
72 uint32_t ovmf_base_address = 0x00100000;
73 uint32_t ovmfxen_pvh_entry_point;
74 size_t offset_into_file = 0;
82 param = strtol (str, &endptr, 10);
84 ovmf_blob_size = (size_t)param;
90 file = fopen (argv[2],
"w");
91 fprintf (file, LICENSE_HDR);
95 ovmfxen_pvh_entry_point = ovmf_base_address + ovmf_blob_size - 0x30;
106 .e_version = EV_CURRENT,
107 .e_entry = ovmfxen_pvh_entry_point,
108 .e_flags = R_386_NONE,
109 .e_ehsize =
sizeof (hdr),
117 offset_into_file +=
sizeof (hdr);
120 hdr.e_ident[EI_CLASS] = ELFCLASS64;
122 hdr.e_ident[EI_CLASS] = ELFCLASS32;
124 hdr.e_ident[EI_DATA] = ELFDATA2LSB;
125 hdr.e_ident[EI_VERSION] = EV_CURRENT;
126 hdr.e_ident[EI_OSABI] = ELFOSABI_LINUX;
128 hdr.e_phoff =
sizeof (hdr);
138 .p_paddr = ovmf_base_address,
139 .p_filesz = ovmf_blob_size,
140 .p_memsz = ovmf_blob_size,
141 .p_flags = PF_X | PF_W | PF_R,
149 phdr_load.p_vaddr = phdr_load.p_paddr;
151 offset_into_file +=
sizeof (phdr_load);
156 .type = XEN_ELFNOTE_PHYS32_ENTRY,
158 .desc = ovmfxen_pvh_entry_point,
172 .p_filesz =
sizeof (xen_elf_note),
173 .p_memsz =
sizeof (xen_elf_note),
183 offset_into_file +=
sizeof (phdr_note);
184 phdr_note.p_offset = offset_into_file;
185 phdr_note.p_paddr = ovmf_base_address + phdr_note.p_offset;
186 phdr_note.p_vaddr = phdr_note.p_paddr;
193 size_t hdr_size =
sizeof (hdr);
194 size_t entry_off = offsetof (typeof(hdr), e_entry);
196 fprintf (file,
"DATA = {\r\n");
198 fprintf (file,
" # ELF file header\r\n");
199 print_hdr (file, &hdr, entry_off,
true);
200 fprintf (file,
"\r\n");
201 print_hdr (file, &hdr.e_entry, sizeof (hdr.e_entry),
true);
202 fprintf (file,
" # hdr.e_entry\r\n");
203 print_hdr (file, &hdr.e_entry + 1, hdr_size - entry_off - sizeof (hdr.e_entry),
true);
205 fprintf (file,
"\r\n\r\n # ELF Program segment headers\r\n");
206 fprintf (file,
" # - Load segment\r\n");
207 for (i = 0; i <
sizeof (phdr_load); i += 4) {
208 print_hdr (file, ((
char *)&phdr_load) + i, 4,
true);
209 fprintf (file,
"\r\n");
212 fprintf (file,
" # - ELFNOTE segment\r\n");
213 for (i = 0; i <
sizeof (phdr_note); i += 4) {
214 print_hdr (file, ((
char *)&phdr_note) + i, 4,
true);
215 fprintf (file,
"\r\n");
218 fprintf (file,
"\r\n # XEN_ELFNOTE_PHYS32_ENTRY\r\n");
219 for (i = 0; i <
sizeof (xen_elf_note); i += 4) {
220 print_hdr (file, ((
char *)&xen_elf_note) + i, 4, (
sizeof (xen_elf_note) - i) > 4);
221 fprintf (file,
"\r\n");
224 fprintf (file,
"}\r\n");
int main()
=== TEST ENGINE ================================================================================