From: Michael D. Lowis Date: Fri, 17 Sep 2021 18:17:55 +0000 (-0400) Subject: refactored uefi stuff X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4aa46d05e6df6bd9a46cc972c23c95f23d8e732d;p=proto%2Fuefi.git refactored uefi stuff --- diff --git a/uefi/crt_x86_64.c b/uefi/crt_x86_64.c index 54a82b5..253fd93 100644 --- a/uefi/crt_x86_64.c +++ b/uefi/crt_x86_64.c @@ -2,39 +2,14 @@ #include /* this is implemented by the application */ -extern int main(int argc, char_t **argv); - -/* definitions for elf relocations */ -typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; -typedef uint64_t Elf64_Addr; -typedef struct -{ - Elf64_Sxword d_tag; /* Dynamic entry type */ - union - { - Elf64_Xword d_val; /* Integer value */ - Elf64_Addr d_ptr; /* Address value */ - } d_un; -} Elf64_Dyn; -#define DT_NULL 0 /* Marks end of dynamic section */ -#define DT_RELA 7 /* Address of Rela relocs */ -#define DT_RELASZ 8 /* Total size of Rela relocs */ -#define DT_RELAENT 9 /* Size of one Rela reloc */ -typedef struct -{ - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ -} Elf64_Rel; -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#define R_X86_64_RELATIVE 8 /* Adjust by program base */ +extern int main(void); /* globals to store system table pointers */ -efi_handle_t IM = NULL; -efi_system_table_t *ST = NULL; -efi_boot_services_t *BS = NULL; -efi_runtime_services_t *RT = NULL; -efi_loaded_image_protocol_t *LIP = NULL; +static efi_handle_t IM = NULL; +static efi_system_table_t *ST = NULL; +static efi_boot_services_t *BS = NULL; +static efi_runtime_services_t *RT = NULL; +static efi_loaded_image_protocol_t *LIP = NULL; /* platform specific globals */ VideoConfig Video = {0}; @@ -105,14 +80,34 @@ static void video_init(void) * */ +/* definitions for elf relocations */ +typedef uint64_t Elf64_Xword; +typedef int64_t Elf64_Sxword; +typedef uint64_t Elf64_Addr; +typedef struct +{ + Elf64_Sxword d_tag; /* Dynamic entry type */ + union + { + Elf64_Xword d_val; /* Integer value */ + Elf64_Addr d_ptr; /* Address value */ + } d_un; +} Elf64_Dyn; +#define DT_NULL 0 /* Marks end of dynamic section */ +#define DT_RELA 7 /* Address of Rela relocs */ +#define DT_RELASZ 8 /* Total size of Rela relocs */ +#define DT_RELAENT 9 /* Size of one Rela reloc */ +typedef struct +{ + Elf64_Addr r_offset; /* Address */ + Elf64_Xword r_info; /* Relocation type and symbol index */ +} Elf64_Rel; +#define ELF64_R_TYPE(i) ((i) & 0xffffffff) +#define R_X86_64_RELATIVE 8 /* Adjust by program base */ + int uefi_init(uintptr_t ldbase, Elf64_Dyn *dyn, efi_system_table_t *systab, efi_handle_t image) { - efi_guid_t shpGuid = EFI_SHELL_PARAMETERS_PROTOCOL_GUID; - efi_shell_parameters_protocol_t *shp = NULL; - efi_guid_t shiGuid = SHELL_INTERFACE_PROTOCOL_GUID; - efi_shell_interface_protocol_t *shi = NULL; efi_guid_t lipGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID; - efi_guid_t gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; efi_status_t status; long relsz = 0, relent = 0; @@ -156,7 +151,8 @@ int uefi_init(uintptr_t ldbase, Elf64_Dyn *dyn, efi_system_table_t *systab, efi_ /* perform some initialization for the kernel */ video_init(); - return main(0, 0); + /* now jump to kernel main() */ + return main(); } /* we only need one .o file, so use inline Assembly here */ diff --git a/uefi/platform.h b/uefi/platform.h index 32cd983..538b276 100644 --- a/uefi/platform.h +++ b/uefi/platform.h @@ -16,7 +16,10 @@ extern char check_u32[sizeof(uint32_t) == 4 ? 1 : -1]; extern char check_u64[sizeof(uint64_t) == 8 ? 1 : -1]; extern char check_uptr[sizeof(uintptr_t) == 8 ? 1 : -1]; -#define NULL ((void*)0) +#define NULL ((void*)0) +#define abs(x) ((x)<0?-(x):(x)) +#define min(x,y) ((x)<(y)?(x):(y)) +#define max(x,y) ((x)>(y)?(x):(y)) /* video memory configuration info */ typedef struct { diff --git a/uefi/uefi.h b/uefi/uefi.h index 7454fa5..82d3bd9 100644 --- a/uefi/uefi.h +++ b/uefi/uefi.h @@ -654,8 +654,6 @@ typedef struct { efi_query_capsule_capabilities_t QueryCapsuleCapabilities; efi_query_variable_info_t QueryVariableInfo; } efi_runtime_services_t; -extern efi_runtime_services_t *RT; -#define gRT RT /** Boot Services ***/ typedef struct { @@ -770,8 +768,6 @@ typedef struct { efi_calculate_crc32_t CalculateCrc32; } efi_boot_services_t; -extern efi_boot_services_t *BS; -#define gBS BS /*** Loaded Image Protocol ***/ #ifndef EFI_LOADED_IMAGE_PROTOCOL_GUID @@ -796,8 +792,6 @@ typedef struct { efi_memory_type_t ImageCodeType; efi_memory_type_t ImageDataType; } efi_loaded_image_protocol_t; -extern efi_loaded_image_protocol_t *LIP; -extern efi_handle_t IM; /*** System Table ***/ typedef struct { @@ -826,8 +820,6 @@ typedef struct { uintn_t NumberOfTableEntries; efi_configuration_table_t *ConfigurationTable; } efi_system_table_t; -extern efi_system_table_t *ST; -#define gST ST /*** Simple File System Protocol ***/ #ifndef EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID @@ -1123,8 +1115,6 @@ typedef struct { efi_gop_mode_t *Mode; } efi_gop_t; -extern efi_gop_t *GOP; - /*** Simple Pointer Protocol (not used, but could be useful to have) ***/ #ifndef EFI_SIMPLE_POINTER_PROTOCOL_GUID #define EFI_SIMPLE_POINTER_PROTOCOL_GUID { 0x31878c87, 0xb75, 0x11d5, { 0x9a, 0x4f, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }