]> git.mdlowis.com Git - proto/uefi.git/commitdiff
refactored uefi stuff
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 17 Sep 2021 18:17:55 +0000 (14:17 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 17 Sep 2021 18:17:55 +0000 (14:17 -0400)
uefi/crt_x86_64.c
uefi/platform.h
uefi/uefi.h

index 54a82b523e3b3b10c6fc16c1204c2a5cf11830fe..253fd93c5fce1a5c23a75e5c8784e72a85960ab7 100644 (file)
@@ -2,39 +2,14 @@
 #include <uefi.h>
 
 /* 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 */
index 32cd983d88b0987b980fe992f9a992d7116fea87..538b27627cea75de307cc6c69dd05d3a082fb999 100644 (file)
@@ -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 {
index 7454fa5204a9accc77f9cf482a91dcaa050243d3..82d3bd9ffb08518021da2fd57348d688f7053021 100644 (file)
@@ -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 } }