commit 5b7bd0f5c338ca4b909167a69cf1401bc675b450
parent bb8e448454814a866eee68ba5ec664291d2baff4
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 19 Mar 2024 11:46:43 +0900
rename hello.c to loader.c and add kernel.c
Diffstat:
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/kernel.c b/kernel.c
diff --git a/loader.c b/loader.c
@@ -0,0 +1,51 @@
+#include "uefi.h"
+#include "utils.h"
+
+EFI_SYSTEM_TABLE *SystemTable;
+
+EFI_STATUS
+EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab)
+{
+ // init global variable.
+ SystemTable = systab;
+
+ EFI_STATUS stat;
+ char s8[32];
+
+ // Output firmware bender.
+ SystemTable->ConOut->ClearScreen(SystemTable->ConOut);
+ efi_printf("vendor: %s\n", wstr2str(SystemTable->FirmwareVendor, s8));
+
+ // Output memory map information.
+ UINTN mmsize = 8196;
+ char mmbuf[8196];
+ EFI_MEMORY_DESCRIPTOR *mmap;
+ UINTN mkey;
+ UINTN dsize;
+ UINT32 dver;
+ mmap = (EFI_MEMORY_DESCRIPTOR *) mmbuf;
+ stat = SystemTable->BootServices->GetMemoryMap(&mmsize, mmap, &mkey, &dsize, &dver);
+ if (stat != EFI_SUCCESS) {
+ return stat;
+ }
+
+ for (; mmap < (EFI_MEMORY_DESCRIPTOR *)(mmbuf + mmsize);
+ mmap = (EFI_MEMORY_DESCRIPTOR *) (((char *)mmap) + dsize)) {
+ if (mmap->Type != EfiConventionalMemory) {
+ continue;
+ }
+ efi_printf("%d\t%x\t%x\t%x\t%x\n", mmap->Type, mmap->VirtualStart,
+ mmap->PhysicalStart, mmap->NumberOfPages, mmap->Attribute);
+ }
+
+ // Echo back user input.
+ EFI_INPUT_KEY Key;
+ CHAR16 str[2] = {' ', '\0'};
+ while(1) {
+ SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &Key);
+ str[0] = Key.UnicodeChar;
+ SystemTable->ConOut->OutputString(SystemTable->ConOut, str);
+ }
+
+ return EFI_SUCCESS;
+}