setos

拙OS
Log | Files | Refs | LICENSE

commit 09dcf5409ce00122ecb34954ff60b45b6d1a957a
parent ac9795006358408d2b8048c5a10884d56758e5dd
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue, 26 Mar 2024 12:43:57 +0900

load kernel to the memory. page fault

Diffstat:
Mloader.c | 16+++++++++++++++-
Muefi.h | 30++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/loader.c b/loader.c @@ -57,12 +57,26 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) } EFI_PHYSICAL_ADDRESS kernel_base = 0x100000; - stat = kernel->Read(kernel, 10, (VOID *)kernel_base); + UINTN fib_size = 1024; + char fibuf[1024]; + EFI_FILE_INFO *fileInfo = (EFI_FILE_INFO *) fibuf; + stat = kernel->GetInfo(kernel, &EFI_FILE_INFO_ID, &fib_size, (VOID *)fibuf); + if (stat != EFI_SUCCESS) { + efi_printf("get info of \"kernel.elf\": %d\n", stat); + return stat; + } + efi_printf("file size: %d\n", fileInfo->FileSize); + + UINTN kernel_size = 1024; + stat = kernel->Read(kernel, &kernel_size, (VOID *)kernel_base); if (stat != EFI_SUCCESS) { efi_printf("read file \"kernel.elf\": %d\n", stat); return stat; } + typedef void (* Kernel) (void); + ((Kernel) kernel_base)(); + stat = kernel->Close(kernel); if (stat != EFI_SUCCESS) { efi_printf("close file: %d\n", stat); diff --git a/uefi.h b/uefi.h @@ -7,6 +7,7 @@ typedef unsigned short CHAR16; typedef unsigned long long UINTN; typedef unsigned char UINT8; +typedef short INT16; typedef unsigned short UINT16; typedef unsigned UINT32; typedef unsigned long long UINT64; @@ -28,6 +29,10 @@ typedef struct EFI_GUID { #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ ((EFI_GUID) {0x964e5b22, 0x6459, 0x11d2, \ {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) +#define EFI_FILE_INFO_ID \ + ((EFI_GUID) {0x9576e92, 0x6d3f, 0x11d2, \ + {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) + // EFI_STATUS enum { @@ -161,6 +166,31 @@ struct _EFI_FILE_PROTOCOL { void *dummy1[6]; }; +typedef struct { + UINT16 Year; + UINT8 Month; + UINT8 Day; + UINT8 Hour; + UINT8 Minute; + UINT8 Second; + UINT8 Pad1; + UINT32 NanoSecond; + INT16 TimeZone; + UINT8 Daylight; + UINT8 Pad2; +} EFI_TIME; + +typedef struct { + UINT64 Size; + UINT64 FileSize; + UINT64 PhysicalSize; + EFI_TIME CreateTime; + EFI_TIME LastAccessTime; + EFI_TIME ModificationTime; + UINT64 Attribute; + CHAR16 FileName[]; +} EFI_FILE_INFO; + typedef struct _EFI_LOADED_IMAGE_PROTOCOL EFI_LOADED_IMAGE_PROTOCOL; struct _EFI_LOADED_IMAGE_PROTOCOL{