setos

拙OS
Log | Files | Refs | LICENSE

commit bb8e448454814a866eee68ba5ec664291d2baff4
parent 26e6ec85fbeca3e2d4dc3673f7683158f0bc07a0
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Mon, 18 Mar 2024 18:40:32 +0900

rename printf to efi_printf

Diffstat:
MMakefile | 20+++++++++++---------
Dhello.c | 51---------------------------------------------------
Mtest/utils_test.c | 2++
Mutils.c | 2+-
Mutils.h | 4++--
5 files changed, 16 insertions(+), 63 deletions(-)

diff --git a/Makefile b/Makefile @@ -3,26 +3,28 @@ CFLAGS = -nostdlib -fpic -shared -mno-red-zone -fno-stack-protector \ -fno-builtin \ -mno-stack-arg-probe -Wall -e EfiMain OBJCOPY = objcopy -SRC = hello.c utils.c -HDR = uefi.h stdarg.h +SRC = loader.c utils.c +HDR = uefi.h -all: hello.efi +all: loader.efi -hello.dll: $(SRC) $(HDR) +loader.dll: $(SRC) $(HDR) $(CC) $(CFLAGS) -o $@ $(SRC) -hello.efi: hello.dll +loader.efi: loader.dll $(OBJCOPY) --target=efi-app-x86_64 $< $@ -run: hello.efi +run: loader.efi mkdir -p image doas mount disk.img image doas mkdir -p image/EFI/BOOT - doas cp hello.efi image/EFI/BOOT/BOOTX64.EFI + doas cp loader.efi image/EFI/BOOT/BOOTX64.EFI doas umount image - qemu-system-x86_64 -bios /usr/share/edk2/x64/OVMF.fd -drive format=raw,file=disk.img + qemu-system-x86_64 \ + -bios /usr/share/edk2/x64/OVMF.fd \ + -drive format=raw,file=disk.img -test: test/* +test: test/* $(SRC) $(HDR) (cd test && make) clean: diff --git a/hello.c b/hello.c @@ -1,51 +0,0 @@ -#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); - 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; - } - 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; -} diff --git a/test/utils_test.c b/test/utils_test.c @@ -5,6 +5,8 @@ #include "../uefi.h" #include "../utils.h" +EFI_SYSTEM_TABLE *SystemTable; + int str16cmp(CHAR16 *s, CHAR16 *t) { diff --git a/utils.c b/utils.c @@ -33,7 +33,7 @@ wstr2str(CHAR16 *s16, char *s8) } int -printf(char *fmt, ...) +efi_printf(char *fmt, ...) { va_list ap; CHAR16 _buf[1024], *buf = _buf; diff --git a/utils.h b/utils.h @@ -13,7 +13,7 @@ CHAR16 *sprinth(UINT64, CHAR16[19]); // It returns s. char *wstr2str(CHAR16 *s16, char *s8); -// Printf prints formatted string to ConOut. +// Efi_rintf prints formatted string to ConOut. // Can't format a string longer than 1024 CHAR16s. // It returns number of CHAR16s written excluding the final NULL. -int printf(char *fmt, ...); +int efi_printf(char *fmt, ...);