setos

拙OS
Log | Files | Refs | LICENSE

commit 261bb7c373f6c1b38130f6d30211654470bca313
parent d29cbf94bdd950b87d2605ba1433047e4a40b8e4
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 29 Mar 2024 15:34:56 +0900

add graphics output protocol

Diffstat:
Mloader.c | 8++++++++
Muefi.h | 46+++++++++++++++++++++++++++++++++++++++++++++-
Mutils.c | 24++++++++++++++++++++++++
Mutils.h | 3+++
4 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/loader.c b/loader.c @@ -39,6 +39,14 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab) mmap->PhysicalStart, mmap->NumberOfPages, mmap->Attribute); } + EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; + stat = open_gop(ImageHandle, &gop); + if (stat != EFI_SUCCESS) { + efi_printf("open_gop: %d\n", stat); + return stat; + } + efi_printf("gop open\n"); + EFI_FILE_PROTOCOL *root, *kernel; stat = open_root(ImageHandle, &root); if (stat != EFI_SUCCESS) { diff --git a/uefi.h b/uefi.h @@ -26,6 +26,9 @@ typedef struct EFI_GUID { #define EFI_LOADED_IMAGE_PROTOCOL_GUID \ ((EFI_GUID) {0x5b1b31a1, 0x9562, 0x11d2, \ {0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) +#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ + ((EFI_GUID) {0x9042a9de, 0x23dc, 0x4a38, \ + {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a}}) #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ ((EFI_GUID) {0x964e5b22, 0x6459, 0x11d2, \ {0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}) @@ -109,6 +112,30 @@ typedef struct { UINT64 Attribute; } EFI_MEMORY_DESCRIPTOR; +typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL; + +typedef struct { +} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE; + +typedef +EFI_STATUS (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE) ( + ); + +typedef +EFI_STATUS (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE) ( + ); + +typedef +EFI_STATUS (EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT) ( + ); + +struct _EFI_GRAPHICS_OUTPUT_PROTOCOL { + EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode; + EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode; + EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt; + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; +}; + typedef struct _EFI_FILE_PROTOCOL EFI_FILE_PROTOCOL; typedef @@ -278,6 +305,21 @@ EFI_STATUS (EFIAPI *EFI_OPEN_PROTOCOL)( IN UINT32 Attributes ); +typedef enum { + AllHandles, + ByRegisterNotify, + ByProtocol +} EFI_LOCATE_SEARCH_TYPE; + +typedef +EFI_STATUS (EFIAPI *EFI_LOCATE_HANDLE_BUFFER)( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + OUT UINTN *NoHandles, + OUT EFI_HANDLE **Buffer + ); + #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x1 typedef struct { @@ -311,7 +353,9 @@ typedef struct { void *driversupport_services[2]; EFI_OPEN_PROTOCOL OpenProtocol; void *open_and_close_protocol_services[2]; - void *library_servies[5]; + void *library_servies0[1]; + EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer; + void *library_servies1[3]; void *crc_services[1]; void *miscellaneus_services1[3]; } EFI_BOOT_SERVICES; diff --git a/utils.c b/utils.c @@ -151,6 +151,30 @@ open_root(EFI_HANDLE ImageHandle, EFI_FILE_PROTOCOL **root) return stat; } +EFI_STATUS +open_gop(EFI_HANDLE ImageHandle, EFI_GRAPHICS_OUTPUT_PROTOCOL **gop) +{ + EFI_STATUS stat; + UINTN n = 0; + EFI_HANDLE *_gop; + stat = SystemTable->BootServices->LocateHandleBuffer( + ByProtocol, &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, NULL, + &n, &_gop + ); + if (stat != EFI_SUCCESS) { + efi_printf("locate handle buffer: %d\n", stat); + return stat; + } + stat = SystemTable->BootServices->OpenProtocol( + _gop[0], &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, + (VOID **) gop, ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL + ); + if (stat != EFI_SUCCESS) { + efi_printf("open protocol: %d\n", stat); + return stat; + } + return EFI_SUCCESS; +} EFI_STATUS read_ehdr(EFI_FILE_PROTOCOL *elf, ElfHdr *ehdr) diff --git a/utils.h b/utils.h @@ -20,6 +20,9 @@ char *wstr2str(CHAR16 *s16, char *s8); // It returns number of CHAR16s written excluding the final NULL. int efi_printf(char *fmt, ...); +// Open_gop opens the graphics output protocol. +EFI_STATUS open_gop(EFI_HANDLE, EFI_GRAPHICS_OUTPUT_PROTOCOL **); + // Open_root opens the root directory of the efi image. EFI_STATUS open_root(EFI_HANDLE, EFI_FILE_PROTOCOL **);