diff options
Diffstat (limited to 'uefi.h')
| -rw-r--r-- | uefi.h | 230 |
1 files changed, 230 insertions, 0 deletions
| @@ -0,0 +1,230 @@ | |||
| 1 | /* ============================================================================= | ||
| 2 | * uefi.h — minimal UEFI types and protocols for the RNG bootloader | ||
| 3 | * | ||
| 4 | * Standalone, freestanding, no external headers. | ||
| 5 | * ============================================================================= */ | ||
| 6 | |||
| 7 | #ifndef UEFI_H | ||
| 8 | #define UEFI_H | ||
| 9 | |||
| 10 | /* ---- basic types ---- */ | ||
| 11 | typedef unsigned char u8; | ||
| 12 | typedef unsigned short u16; | ||
| 13 | typedef unsigned int u32; | ||
| 14 | typedef unsigned long long u64; | ||
| 15 | /* UEFI CHAR16 — wchar_t must be 16-bit (use -fshort-wchar). | ||
| 16 | * GCC by default makes wchar_t = int (32-bit). -fshort-wchar makes | ||
| 17 | * it unsigned short (16-bit) to match UEFI's CHAR16. | ||
| 18 | * We don't include <stddef.h> (freestanding), so define our own. */ | ||
| 19 | typedef __CHAR16_TYPE__ char16; | ||
| 20 | typedef signed short int16; | ||
| 21 | typedef long long int64; | ||
| 22 | typedef void *handle; | ||
| 23 | |||
| 24 | /* ---- EFI status codes ---- */ | ||
| 25 | #define EFI_SUCCESS 0 | ||
| 26 | #define EFI_LOAD_ERROR ((u64)1) | ||
| 27 | #define EFI_INVALID_PARAMETER ((u64)2) | ||
| 28 | #define EFI_UNSUPPORTED ((u64)3) | ||
| 29 | #define EFI_NOT_FOUND ((u64)14) | ||
| 30 | #define EFI_ALREADY_STARTED ((u64)25) | ||
| 31 | #define EFI_OUT_OF_RESOURCES ((u64)9) | ||
| 32 | |||
| 33 | /* ---- GUIDs (128-bit) ---- */ | ||
| 34 | typedef struct { u32 a; u16 b; u16 c; u8 d[8]; } efi_guid; | ||
| 35 | |||
| 36 | /* ---- EFI time (unused, part of file info struct) ---- */ | ||
| 37 | typedef struct { | ||
| 38 | u16 year; u8 month; u8 day; | ||
| 39 | u8 hour; u8 minute; u8 second; u8 pad1; | ||
| 40 | u32 ns; int16 tz; u8 daylight; | ||
| 41 | } efi_time; | ||
| 42 | |||
| 43 | /* ---- table headers ---- */ | ||
| 44 | typedef struct { | ||
| 45 | u64 signature; | ||
| 46 | u32 revision; | ||
| 47 | u32 header_size; | ||
| 48 | u32 crc32; | ||
| 49 | u32 reserved; | ||
| 50 | } efi_table_header; | ||
| 51 | |||
| 52 | /* ---- system table ---- */ | ||
| 53 | typedef struct efi_config_table efi_config_table; | ||
| 54 | typedef struct efi_simple_text_output efi_simple_text_output; | ||
| 55 | typedef struct efi_simple_text_input efi_simple_text_input; | ||
| 56 | typedef struct efi_boot_services efi_boot_services; | ||
| 57 | typedef struct efi_runtime_services efi_runtime_services; | ||
| 58 | |||
| 59 | typedef struct { | ||
| 60 | efi_table_header hdr; | ||
| 61 | char16 *firmware_vendor; | ||
| 62 | u32 firmware_revision; | ||
| 63 | handle console_in_handle; | ||
| 64 | efi_simple_text_input *con_in; | ||
| 65 | handle console_out_handle; | ||
| 66 | efi_simple_text_output *con_out; | ||
| 67 | handle stderr_handle; | ||
| 68 | efi_simple_text_output *std_err; | ||
| 69 | efi_runtime_services *runtime_services; | ||
| 70 | efi_boot_services *boot_services; | ||
| 71 | u64 number_of_table_entries; | ||
| 72 | efi_config_table *configuration_table; | ||
| 73 | } efi_system_table; | ||
| 74 | |||
| 75 | /* ---- EFI input key ---- */ | ||
| 76 | typedef struct { | ||
| 77 | u16 scan_code; | ||
| 78 | char16 unicode_char; | ||
| 79 | } efi_input_key; | ||
| 80 | |||
| 81 | /* ---- simple text output (console) ---- */ | ||
| 82 | typedef u64 (*efi_text_reset)(efi_simple_text_output *, u8); | ||
| 83 | typedef u64 (*efi_text_output)(efi_simple_text_output *, const char16 *); | ||
| 84 | |||
| 85 | struct efi_simple_text_output { | ||
| 86 | void *unused; // Index 0: Reset | ||
| 87 | efi_text_output output_string; // Index 1: OutputString | ||
| 88 | void *unused2[8]; // Index 2-9: TestString..Mode | ||
| 89 | }; | ||
| 90 | |||
| 91 | /* ---- simple text input (keyboard) ---- */ | ||
| 92 | typedef u64 (*efi_input_reset)(efi_simple_text_input *, u8); | ||
| 93 | typedef u64 (*efi_input_read_key)(efi_simple_text_input *, efi_input_key *); | ||
| 94 | |||
| 95 | struct efi_simple_text_input { | ||
| 96 | efi_input_reset reset; /* Index 0: Reset */ | ||
| 97 | efi_input_read_key read_key_stroke; /* Index 1: ReadKeyStroke */ | ||
| 98 | handle wait_for_key; /* Index 2: WaitForKey event */ | ||
| 99 | }; | ||
| 100 | |||
| 101 | /* ---- boot services ---- */ | ||
| 102 | typedef u64 (*efi_exit_boot_services)(handle, u64); | ||
| 103 | typedef u64 (*efi_get_memory_map)(void*, void*, void*, void*, void*); | ||
| 104 | typedef u64 (*efi_locate_protocol)(const efi_guid *, void *, void **); | ||
| 105 | typedef u64 (*efi_load_image)(u8, handle, void *, void *, u64, handle *); | ||
| 106 | typedef u64 (*efi_start_image)(handle, void *, u64 *); | ||
| 107 | typedef u64 (*efi_handle_protocol)(handle, const efi_guid *, void **); | ||
| 108 | typedef u64 (*efi_open_volume)(void *, void **); | ||
| 109 | typedef u64 (*efi_open_file)(void *, void **, char16 *, u64, u64); | ||
| 110 | typedef u64 (*efi_read_file)(void *, u64 *, void *); | ||
| 111 | typedef u64 (*efi_allocate_pool)(u8, u64, void **); | ||
| 112 | |||
| 113 | /* Boot Services table matching UEFI spec v2.10 function order. | ||
| 114 | Each entry is one function pointer (8 bytes on x64). */ | ||
| 115 | struct efi_boot_services { | ||
| 116 | efi_table_header hdr; /* 0 */ | ||
| 117 | void *raise_tpl; /* 24 index 0 */ | ||
| 118 | void *restore_tpl; /* 32 index 1 */ | ||
| 119 | void *allocate_pages; /* 40 index 2 */ | ||
| 120 | void *free_pages; /* 48 index 3 */ | ||
| 121 | efi_get_memory_map get_memory_map; /* 56 index 4 */ | ||
| 122 | efi_allocate_pool allocate_pool; /* 64 index 5 */ | ||
| 123 | void *free_pool; /* 72 index 6 */ | ||
| 124 | void *create_event; /* 80 index 7 */ | ||
| 125 | void *set_timer; /* 88 index 8 */ | ||
| 126 | void *wait_for_event; /* 96 index 9 */ | ||
| 127 | void *signal_event; /*104 index 10 */ | ||
| 128 | void *close_event; /*112 index 11 */ | ||
| 129 | void *check_event; /*120 index 12 */ | ||
| 130 | void *install_protocol_interface; /*128 index 13 */ | ||
| 131 | void *reinstall_protocol_interface;/*136 index 14 */ | ||
| 132 | void *uninstall_protocol_interface;/*144 index 15 */ | ||
| 133 | efi_handle_protocol handle_protocol; /*152 index 16 */ | ||
| 134 | void *reserved; /*160 index 17 */ | ||
| 135 | void *register_protocol_notify; /*168 index 18 */ | ||
| 136 | void *locate_handle; /*176 index 19 */ | ||
| 137 | void *locate_device_path; /*184 index 20 */ | ||
| 138 | void *install_config_table; /*192 index 21 */ | ||
| 139 | efi_load_image load_image; /*200 index 22 */ | ||
| 140 | efi_start_image start_image; /*208 index 23 */ | ||
| 141 | void *exit; /*216 index 24 */ | ||
| 142 | void *unload_image; /*224 index 25 */ | ||
| 143 | efi_exit_boot_services exit_boot_services; /*232 index 26 */ | ||
| 144 | void *get_next_monotonic_count; /*240 index 27 */ | ||
| 145 | void *stall; /*248 index 28 */ | ||
| 146 | void *set_watchdog_timer; /*256 index 29 */ | ||
| 147 | void *connect_controller; /*264 index 30 */ | ||
| 148 | void *disconnect_controller; /*272 index 31 */ | ||
| 149 | void *open_protocol; /*280 index 32 */ | ||
| 150 | void *close_protocol; /*288 index 33 */ | ||
| 151 | void *open_protocol_information; /*296 index 34 */ | ||
| 152 | void *protocols_per_handle; /*304 index 35 */ | ||
| 153 | void *locate_handle_buffer; /*312 index 36 */ | ||
| 154 | efi_locate_protocol locate_protocol; /*320 index 37 */ | ||
| 155 | void *install_multiple_protocols; /*328 index 38 */ | ||
| 156 | void *uninstall_multiple_protocols;/*336 index 39 */ | ||
| 157 | void *calculate_crc32; /*344 index 40 */ | ||
| 158 | void *copy_mem; /*352 index 41 */ | ||
| 159 | void *set_mem; /*360 index 42 */ | ||
| 160 | void *create_event_ex; /*368 index 43 */ | ||
| 161 | }; | ||
| 162 | |||
| 163 | /* ---- GUID for Simple File System Protocol ---- */ | ||
| 164 | #define EFI_SIMPLE_FILE_SYSTEM_GUID \ | ||
| 165 | {0x0964e5b22, 0x6459, 0x11d2, {0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b}} | ||
| 166 | |||
| 167 | /* ---- file protocol ---- */ | ||
| 168 | typedef struct { | ||
| 169 | u64 revision; | ||
| 170 | efi_open_volume open_volume; | ||
| 171 | } efi_simple_file_system; | ||
| 172 | |||
| 173 | typedef struct efi_file_protocol efi_file_protocol; | ||
| 174 | |||
| 175 | typedef u64 (*efi_file_open)(efi_file_protocol *, efi_file_protocol **, char16 *, u64, u64); | ||
| 176 | typedef u64 (*efi_file_read)(efi_file_protocol *, u64 *, void *); | ||
| 177 | typedef u64 (*efi_file_close)(efi_file_protocol *); | ||
| 178 | |||
| 179 | #define EFI_FILE_MODE_READ 1 | ||
| 180 | |||
| 181 | struct efi_file_protocol { | ||
| 182 | u64 revision; | ||
| 183 | efi_file_open open; | ||
| 184 | efi_file_close close; | ||
| 185 | void *unused; | ||
| 186 | efi_file_read read; | ||
| 187 | void *unused2[5]; | ||
| 188 | }; | ||
| 189 | |||
| 190 | /* ---- file info (for getting file size) ---- */ | ||
| 191 | typedef struct { | ||
| 192 | u64 size; | ||
| 193 | u64 file_size; | ||
| 194 | u64 physical_size; | ||
| 195 | efi_time create_time; | ||
| 196 | efi_time last_access; | ||
| 197 | efi_time modification_time; | ||
| 198 | u64 attribute; | ||
| 199 | char16 file_name[1]; | ||
| 200 | } efi_file_info; | ||
| 201 | |||
| 202 | /* ---- loaded image protocol ---- */ | ||
| 203 | typedef struct { | ||
| 204 | u32 revision; | ||
| 205 | handle parent_handle; | ||
| 206 | handle system_table; | ||
| 207 | handle device_handle; | ||
| 208 | void *file_path; | ||
| 209 | void *reserved; | ||
| 210 | u32 load_options_size; | ||
| 211 | void *load_options; | ||
| 212 | void *image_base; | ||
| 213 | u64 image_size; | ||
| 214 | u64 image_code_type; | ||
| 215 | u64 image_data_type; | ||
| 216 | void *unused; | ||
| 217 | } efi_loaded_image; | ||
| 218 | |||
| 219 | /* ---- loaded image protocol GUID ---- */ | ||
| 220 | #define EFI_LOADED_IMAGE_GUID \ | ||
| 221 | {0x5b1b31a1, 0x9562, 0x11d2, {0x8e,0x3f,0x00,0xa0,0xc9,0x69,0x72,0x3b}} | ||
| 222 | |||
| 223 | /* ---- device path protocol ---- */ | ||
| 224 | typedef struct { | ||
| 225 | u8 type; | ||
| 226 | u8 sub_type; | ||
| 227 | u16 length; | ||
| 228 | } efi_device_path; | ||
| 229 | |||
| 230 | #endif /* UEFI_H */ | ||
