Rev 26 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 26 | Rev 33 | ||
---|---|---|---|
Line 239... | Line 239... | ||
239 | // immediately follows the last byte of the variable-length <args>. It will be included in the advertised <size_*> and is located at <bootargs_addr>+<size>-8 |
239 | // immediately follows the last byte of the variable-length <args>. It will be included in the advertised <size_*> and is located at <bootargs_addr>+<size>-8 |
240 | uint32_t shdr_addr; |
240 | uint32_t shdr_addr; |
241 | //char *args; // variable length |
241 | //char *args; // variable length |
242 | } bootargs_entry_t; |
242 | } bootargs_entry_t; |
243 | END_OF_PACKED_STRUCT () // restore default alignment |
243 | END_OF_PACKED_STRUCT () // restore default alignment |
- | 244 | ||
- | 245 | ||
- | 246 | START_OF_PACKED_STRUCT () // we need byte-alignment for this struct |
|
- | 247 | typedef PACKED (struct) uefi64_header_s // size 512 bytes |
|
- | 248 | { |
|
- | 249 | PACKED (struct) dos_header_s // size 64 bytes |
|
- | 250 | { |
|
- | 251 | uint8_t signature[2]; // magic number, "MZ" |
|
- | 252 | uint16_t bytes_in_last_page; // number of bytes on last 512-byte page of file (144 in our case) |
|
- | 253 | uint16_t number_of_pages; // 512-byte pages in file (3 in our case, which is a minimum) |
|
- | 254 | uint16_t number_of_relocations; // relocations (zero in our case) |
|
- | 255 | uint16_t header_size_in_paragraphs; // Size of this header in 16-byte paragraphs (4, i.e. 64 / 16) |
|
- | 256 | uint16_t required_paragraphs; // minimum extra paragraphs needed (0) |
|
- | 257 | uint16_t requested_paragraphs; // maximum extra paragraphs needed (0xffff) |
|
- | 258 | uint16_t initial_relative_relocatable_segment_address_for_ss; // Initial (relative) SS value (zero) |
|
- | 259 | uint16_t initial_stack_pointer_value; // Initial SP value (0xb8 or 184 for use with our DOS stub program code) |
|
- | 260 | uint16_t unused_checksum; // checksum (zero). Normally, value to add to the sum of all other words in the file except this one to reach zero. |
|
- | 261 | uint16_t initial_instruction_pointer_value; // initial IP value (zero in our case) |
|
- | 262 | uint16_t initial_relative_relocatable_segment_address_for_cs; // initial (relative) CS value (zero) |
|
- | 263 | uint16_t absolute_offset_to_relocation_table; // file address of relocation table (typically just after this header, i.e. 0x40 or 64 decimal) |
|
- | 264 | uint16_t overlay_number; // overlay number (zero, i.e. this is the main executable) |
|
- | 265 | uint16_t reserved_words1[4]; // reserved words (zerofilled) |
|
- | 266 | uint16_t oem_identifier; // OEM identifier for e_oeminfo (zero) |
|
- | 267 | uint16_t oem_info; // OEM information, oem_identifier specific (zero) |
|
- | 268 | uint16_t reserved_words2[10]; // reserved words (zerofilled) |
|
- | 269 | uint32_t absolute_offset_to_pe_header; // file address of PE header (typically just after the DOS stub program bytes, i.e. 0x80 or 128 decimal) |
|
- | 270 | } dos_header; |
|
- | 271 | uint8_t dos_stub_bytes[64]; // DOS stub program bytes: "\x0E\x1F\xBA\x0E\x00\xB4\x09\xCD\x21\xB8\x01\x4C\xCD\x21" "This program cannot be run in DOS mode.\r\r\n" "\x24\x00\x00\x00\x00\x00\x00\x00" |
|
- | 272 | PACKED (struct) pe_header_s |
|
- | 273 | { |
|
- | 274 | uint8_t signature[4]; // magic value, "PE\0\0" |
|
- | 275 | uint16_t machine_type; // machine type (0x8664 for AMD64) |
|
- | 276 | uint16_t number_of_sections; // number of sections (1 in our case) |
|
- | 277 | uint32_t epoch_timestamp; // number of seconds since UNIX Epoch |
|
- | 278 | uint32_t offset_to_symbols_table; // offset to symbols table (zero) |
|
- | 279 | uint32_t number_of_symbols; // number of symbols in symbols table (zero) |
|
- | 280 | uint16_t size_of_optional_header; // size of optional header (typically 240) |
|
- | 281 | uint16_t characteristics_bitmap; // bitmapped PE characteristics (0x223, or 547 decimal = executable, uses large addresses, relocs stripped, debug info stripped) |
|
- | 282 | } pe_header; |
|
- | 283 | PACKED (struct) pe_image_optional_header64_s |
|
- | 284 | { |
|
- | 285 | uint8_t signature[2]; // magic value, "\x0b\x02" |
|
- | 286 | uint8_t linker_version_major; // major version of the Microsoft linker used to produce this file (zero in our case) |
|
- | 287 | uint8_t linker_version_minor; // minor version of the Microsoft linker used to produce this file (zero in our case) |
|
- | 288 | uint32_t code_size; // size of the code section, in bytes, or the sum of all such sections if there are multiple code sections (total size of IFS minus 512 bytes for the UEFI boot header, i.e. size of startup blob plus size of image) |
|
- | 289 | uint32_t size_of_initialized_data; // size of the initialized data section, in bytes, or the sum of all such sections if there are multiple initialized data sections (zero in our case) |
|
- | 290 | uint32_t size_of_uninitialized_data; // size of the uninitialized data section, in bytes, or the sum of all such sections if there are multiple uninitialized data sections (zero in our case) |
|
- | 291 | uint32_t entrypoint_address; // offset to the entry point function, relative to the image base address |
|
- | 292 | uint32_t code_base; // offset to the beginning of the code section, relative to the image base (zero in our case) |
|
- | 293 | uint64_t image_base; // preferred address of the first byte of the image when it is loaded in memory, multiple of 64K bytes (512 * 65536, i.e. 0x2000000 in our case (FIXME: UNDERSTAND) |
|
- | 294 | uint32_t section_alignment; // alignment of sections loaded in memory in bytes ; must be greater than or equal to file_alignment, defaults to system page size (4096 for AMD64) |
|
- | 295 | uint32_t file_alignment; // alignment of the raw data of sections in the image file, in bytes ; should be a power of 2 between 512 and 64K (inclusive) corresponding I suppose to to the minimal supported underlying filesystem block size (mkifs sets 512 here) |
|
- | 296 | uint16_t os_version_major; // major version number of the required operating system (zero for UEFI) |
|
- | 297 | uint16_t os_version_minor; // minor version number of the required operating system (zero for UEFI) |
|
- | 298 | uint16_t image_version_major; // major version number of this image (mkifs sets zero here) |
|
- | 299 | uint16_t image_version_minor; // minor version number of this image (mkifs sets zero here) |
|
- | 300 | uint16_t subsystem_version_major; // major version number of the required subsystem (zero for UEFI) |
|
- | 301 | uint16_t subsystem_version_minor; // minor version number of the required subsystem (zero for UEFI) |
|
- | 302 | uint32_t win32_version_value; // Microsoft says: "reserved, must be zero" -- so be it |
|
- | 303 | uint32_t image_size; // total IFS file size |
|
- | 304 | uint32_t size_of_headers; // size of the UEFI boot header, must be a multiple of file_alignment (mkifs sets 512 here) |
|
- | 305 | uint32_t unused_checksum; // zero |
|
- | 306 | uint16_t subsystem_type; // image subsystem type (0x0a or 10 decimal i.e. IMAGE_SUBSYSTEM_EFI_APPLICATION) |
|
- | 307 | uint16_t dll_characteristics_bitmap; // bitmapped DLL characteristics (0 in our case) |
|
- | 308 | uint64_t stack_reserve_size; // maximal number of bytes to reserve (i.e. allocate on demand, one page at a time) for the stack (mkifs sets one system page here, i.e. 4096 for AMD64) |
|
- | 309 | uint64_t stack_commit_size; // number of bytes to commit (i.e. allocate at startup) for the stack (mkifs sets one system page here, i.e. 4096 for AMD64) |
|
- | 310 | uint64_t heap_reserve_size; // maximal number of bytes to reserve (i.e. allocate on demand, one page at a time) for the local heap (mkifs sets zero here) |
|
- | 311 | uint64_t heap_commit_size; // number of bytes to commit (i.e. allocate at startup) for the local heap (mkifs sets zero here) |
|
- | 312 | uint32_t unused_loader_flags; // zero |
|
- | 313 | uint32_t number_of_data_directories; // number of directory entries in the remainder of the optional header, each entry made of a location and a size (mkifs sets 16 directory entries) |
|
- | 314 | PACKED (struct) pe_image_data_directory_s |
|
- | 315 | { |
|
- | 316 | uint32_t virtual_address; // relative virtual address of the table |
|
- | 317 | uint32_t size; // size of the table, in bytes |
|
- | 318 | } data_directories[16]; // 16 directory entries (zerofilled) |
|
- | 319 | } optional_header64; |
|
- | 320 | PACKED (struct) pe_image_section_header_s |
|
- | 321 | { |
|
- | 322 | uint8_t section_name[8]; // section name, here "image\0\0\0" |
|
- | 323 | uint32_t virtual_size; // total size of the section when loaded into memory, in bytes ; same as pe_image_optional_header64.code_size |
|
- | 324 | uint32_t virtual_address; // address of the first byte of the section when loaded into memory, relative to the image base (first file_alignment multiple after pe_image_optional_header64.size_of_headers, i.e. 512 in our case) |
|
- | 325 | uint32_t rawdata_size; // size of the initialized data on disk in bytes, multiple of file_alignment (same as virtual_size in our case) |
|
- | 326 | uint32_t rawdata_offset; // offset to the first page within the COFF file (same as virtual_address in our case) |
|
- | 327 | uint32_t offset_to_relocations; // offset to the beginning of the relocation entries in this section (zero in our case) |
|
- | 328 | uint32_t offset_to_linenos; // offset to the beginning of the line-number entries in this section (zero in our case) |
|
- | 329 | uint16_t relocation_count; // number of relocation entries in this section (zero in our case) |
|
- | 330 | uint16_t lineno_count; // number of line number entries in this section (zero in our case) |
|
- | 331 | uint32_t characteristics_bitmap; // bitmapped PE section characteristics (0x60, or 96 decimal, for: image contains code, image contains initialized data) |
|
- | 332 | } unique_section; |
|
- | 333 | uint8_t trailing_padding[80]; // zerofill |
|
- | 334 | } uefi64_header_t; // size 512 bytes |
|
- | 335 | END_OF_PACKED_STRUCT () // restore default alignment |
|
- | 336 | #define UEFI_DOS_STUB_PROGRAM_BYTES "\x0E\x1F\xBA\x0E\x00\xB4\x09\xCD\x21\xB8\x01\x4C\xCD\x21" "This program cannot be run in DOS mode.\r\r\n" "\x24\x00\x00\x00\x00\x00\x00\x00" // 64 bytes |
|
244 | 337 | ||
245 | 338 | ||
246 | // undefine the helpers we no longer need |
339 | // undefine the helpers we no longer need |
247 | #undef START_OF_PACKED_STRUCT |
340 | #undef START_OF_PACKED_STRUCT |
248 | #undef END_OF_PACKED_STRUCT |
341 | #undef END_OF_PACKED_STRUCT |