setos

拙OS
Log | Files | Refs | LICENSE

commit 82bbf229d8b6d057d4f05975d2e91e721377ce6c
parent 632937475fcc4fa80c4d5d364d87ab3c59756243
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Thu, 21 Mar 2024 07:57:38 +0900

open root directory

Diffstat:
Mloader.c | 19+++++++++++++++++--
Muefi.h | 33++++++++++++++++++++++++++++++---
2 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/loader.c b/loader.c @@ -3,6 +3,8 @@ #define NULL 0L +EFI_STATUS open_root(EFI_HANDLE, EFI_FILE_PROTOCOL **); + EFI_SYSTEM_TABLE *SystemTable; EFI_STATUS @@ -40,6 +42,10 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) mmap->PhysicalStart, mmap->NumberOfPages, mmap->Attribute); } + EFI_FILE_PROTOCOL *root; + stat = open_root(ImageHandle, &root); + efi_printf("open_root: %d\n", stat); + // Echo back user input. EFI_INPUT_KEY Key; CHAR16 str[2] = {' ', '\0'}; @@ -56,11 +62,20 @@ EFI_STATUS open_root(EFI_HANDLE ImageHandle, EFI_FILE_PROTOCOL **root) { EFI_STATUS stat; + EFI_LOADED_IMAGE_PROTOCOL *li; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; stat = SystemTable->BootServices->OpenProtocol( - ImageHandle, &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, - NULL, ImageHandle, ImageHandle, 0 + ImageHandle, &EFI_LOADED_IMAGE_PROTOCOL_GUID, + (VOID **) &li, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (stat != EFI_SUCCESS) { + return stat; + } + + stat = SystemTable->BootServices->OpenProtocol( + li->DeviceHandle, &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, + (VOID **) &fs, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL ); return stat; diff --git a/uefi.h b/uefi.h @@ -22,14 +22,20 @@ typedef struct EFI_GUID { UINT8 Data4[8]; } EFI_GUID; +#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ + ((EFI_GUID) {0x5b1b31a1, 0x9562, 0x11d2, \ + {0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - ((EFI_GUID) {0x964e5b22, 0x6459, 0x11d2, {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) + ((EFI_GUID) {0x964e5b22, 0x6459, 0x11d2, \ + {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) // EFI_STATUS enum { EFI_SUCCESS = 0, }; +typedef struct _EFI_SYSTEM_TABLE EFI_SYSTEM_TABLE; + typedef struct { UINT16 ScanCode; CHAR16 UnicodeChar; @@ -141,6 +147,25 @@ struct _EFI_FILE_PROTOCOL { void *dummy[9]; }; +typedef struct _EFI_LOADED_IMAGE_PROTOCOL EFI_LOADED_IMAGE_PROTOCOL; + +struct _EFI_LOADED_IMAGE_PROTOCOL{ + UINT32 Revision; + EFI_HANDLE ParentHandle; + EFI_SYSTEM_TABLE *SystemTable; + + EFI_HANDLE DeviceHandle; + void *dummy[2]; + + UINT32 LoadOptionSize; + VOID *LoadOptions; + + VOID *ImageBase; + UINT64 ImageSize; + char dummy1[4 + 4]; + void *dummy2; +}; + typedef struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL; typedef @@ -177,6 +202,8 @@ EFI_STATUS (EFIAPI *EFI_OPEN_PROTOCOL)( IN UINT32 Attributes ); +#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x1 + typedef struct { } EFI_RUNTIME_SERVICES; @@ -212,7 +239,7 @@ typedef struct { void *miscellaneus_services1[3]; } EFI_BOOT_SERVICES; -typedef struct { +struct _EFI_SYSTEM_TABLE { EFI_TABLE_HEADER Hdr; CHAR16 *FirmwareVendor; char dummy1[4]; @@ -225,4 +252,4 @@ typedef struct { EFI_RUNTIME_SERVICES *RuntimeServices; EFI_BOOT_SERVICES *BootServices; char dummy2[16]; -} EFI_SYSTEM_TABLE; +};