]> git.mdlowis.com Git - proto/uefi.git/commitdiff
Successfully exiting boot services now.
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 24 Nov 2021 01:47:33 +0000 (20:47 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 24 Nov 2021 01:47:33 +0000 (20:47 -0500)
Makefile
core/main.c
core/term.c
uefi/crt_x86_64.c
uefi/platform.h

index 0c2734e8f77ab4786cbe81e28f3c3db9a7e4a68f..e2ae2fa5cecd9f08b543e5e5299162191b193b7f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ all: $(TARGET)
 
 clean:
        find -name '*.o' -delete
-       rm -f kernel.efi uefi/libuefi.a boot.img
+       rm -f kernel.efi uefi/libuefi.a boot.img BOOTX64.EFI
 
 run: boot.img
        qemu-system-$(ARCH) -bios $(OVMF) -cpu qemu64 boot.img
index 8fd3a767866cc80b3aa40575dd7c2f365d2290ea..935e029150676e0963c75c9f8fe56839e4a0a028 100644 (file)
@@ -1,26 +1,12 @@
 #include <platform.h>
+#include <uefi.h>
 #include <kernel.h>
 
 int main (int argc, char** argv)
 {
     Term_Init();
-
-    /* loop forever */
-    for (;;)
-    {
-        Term_PutString("foo\n");
-        Term_PutString("bar\n");
-        Term_PutString("baz\n");
-        Term_Print("%% %d %u %c %s %p %x\n",
-            -1234,
-            4321,
-            'F',
-            "hi!",
-            (void*)0x12345678,
-            0x12345678lu
-        );
-
-    }
+    Term_Print("Done\n");
+    sleep(60000);
 
     return 0;
 }
index 92cf1943cc341019da14d2776a2d20daa5292c9d..ef90847920fd5e0c0cb7b798a57a3d4aee9b9bab 100644 (file)
@@ -78,9 +78,6 @@ void Term_PutChar(int c)
             {
                 PutCell(' ');
             }
-
-//            Term.cursor = (Term.cursor / Term.cols) * Term.cols;
-//            Term.cursor += Term.cols;
             break;
         }
 
@@ -155,10 +152,6 @@ void Term_Print(char* fmt, ...)
                 case '%':
                     Term_PutChar('%');
                     break;
-//
-//                default:
-//                    Term_PutChar(*fmt);
-//                    break;
             }
         }
         else
@@ -169,7 +162,6 @@ void Term_Print(char* fmt, ...)
     va_end (arg);
 }
 
-
 void Term_PutString(char* s)
 {
     for (; *s; s++)
@@ -269,4 +261,3 @@ void Term_PutNewline(void)
 {
     Term_PutChar('\n');
 }
-
index b5481f664941ce54daf6288756276940535bdbf1..7826efc9224c108fb401c496448f8d855c87341c 100644 (file)
@@ -57,6 +57,42 @@ static void video_init(void)
     Video.height = gop->Mode->Information->VerticalResolution;
 }
 
+extern void Term_Init(void);
+extern void Term_Print(char* s, ...);
+extern void Term_PutHex32(uint32_t);
+extern void Term_PutHex64(uint64_t);
+extern void Term_PutChar(uint8_t);
+
+MemoryMap Map;
+
+static void memory_init(void)
+{
+    efi_status_t status = 0;
+
+    /* get the map size */
+    status = BS->GetMemoryMap(
+        &Map.size, (efi_memory_descriptor_t*)Map.data, &Map.key, &Map.desc_size, &Map.desc_ver);
+    /* get the map for real now */
+    (void)BS->AllocatePool(
+        EfiBootServicesData, Map.size + 2 * Map.desc_size, (void**)&Map.data);
+    status = BS->GetMemoryMap(
+        &Map.size, (efi_memory_descriptor_t*)Map.data, &Map.key, &Map.desc_size, &Map.desc_ver);
+
+//    efi_memory_descriptor_t* entry = (efi_memory_descriptor_t*)Map.data;
+//    Term_Init();
+//    do {
+//        Term_Print("%x %x %x %x %x %d\n",
+//            (uint64_t)entry->Type + 1u,
+//            (uint64_t)entry->Pad,
+//            (uint64_t)entry->Attribute,
+//            (uint64_t)entry->PhysicalStart,
+//            (uint64_t)entry->VirtualStart,
+//            (uint64_t)entry->NumberOfPages
+//        );
+//        entry = (efi_memory_descriptor_t*)((uint8_t*)entry + Map.desc_size);
+//    } while((uint8_t*)entry < ((uint8_t*)Map.data + Map.size));
+}
+
 /*
  * crt_x86_64.c : bootstrap() and uefi_init()
  *
@@ -157,6 +193,13 @@ int uefi_init(uintptr_t ldbase, Elf64_Dyn *dyn, efi_system_table_t *systab, efi_
 
     /* perform some initialization for the kernel */
     video_init();
+    memory_init();
+
+    /* exit boot services now */
+    status = BS->ExitBootServices(IM, Map.key);
+
+    /* setup global descriptor table */
+    /* setup interrupt descriptor table */
 
     /* now jump to kernel main() */
     return main();
index 1ec72bddc09791748423f4bb08695c2d9532e21e..b4b599bbeda52afab4abe02496720158d911b6aa 100644 (file)
@@ -34,6 +34,24 @@ typedef struct {
     uint32_t height;
 } VideoConfig;
 
+typedef struct {
+    uint32_t type;
+    uint32_t pad;
+    uint64_t phys_start;
+    uint64_t virt_start;
+    uint64_t npages;
+    uint64_t attr;
+} MemoryDescriptor;
+
+typedef struct {
+    MemoryDescriptor* data;
+    uint64_t size;
+    uint64_t key;
+    uint64_t desc_size;
+    uint32_t desc_ver;
+} MemoryMap;
+
+extern MemoryMap Map;
 extern VideoConfig Video;
 
 void sleep(int ms);