From: Michael D. Lowis Date: Wed, 24 Nov 2021 01:47:33 +0000 (-0500) Subject: Successfully exiting boot services now. X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4c327fb22dbb2c52e11c3a363f8c19838500c300;p=proto%2Fuefi.git Successfully exiting boot services now. --- diff --git a/Makefile b/Makefile index 0c2734e..e2ae2fa 100644 --- 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 diff --git a/core/main.c b/core/main.c index 8fd3a76..935e029 100644 --- a/core/main.c +++ b/core/main.c @@ -1,26 +1,12 @@ #include +#include #include 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; } diff --git a/core/term.c b/core/term.c index 92cf194..ef90847 100644 --- a/core/term.c +++ b/core/term.c @@ -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'); } - diff --git a/uefi/crt_x86_64.c b/uefi/crt_x86_64.c index b5481f6..7826efc 100644 --- a/uefi/crt_x86_64.c +++ b/uefi/crt_x86_64.c @@ -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(); diff --git a/uefi/platform.h b/uefi/platform.h index 1ec72bd..b4b599b 100644 --- a/uefi/platform.h +++ b/uefi/platform.h @@ -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);