efi: Directly use EFI functions instead of using GNU-EFI's call wrapper

This commit is contained in:
mintsuki 2021-08-25 22:03:00 +02:00
parent 23a93a85dc
commit 31f52c2b30
12 changed files with 69 additions and 102 deletions

View File

@ -61,7 +61,6 @@ INTERNAL_CFLAGS := \
-fno-stack-protector \ -fno-stack-protector \
-fno-omit-frame-pointer \ -fno-omit-frame-pointer \
-fno-lto \ -fno-lto \
-fno-pic \
-Wno-address-of-packed-member \ -Wno-address-of-packed-member \
-Wshadow \ -Wshadow \
-mno-80387 \ -mno-80387 \
@ -85,6 +84,7 @@ ifeq ($(TARGET), bios)
-m32 \ -m32 \
-march=i386 \ -march=i386 \
-mabi=sysv \ -mabi=sysv \
-fno-pic \
-fno-pie -fno-pie
endif endif
@ -96,6 +96,7 @@ ifeq ($(TARGET), uefi)
-m32 \ -m32 \
-march=i386 \ -march=i386 \
-mabi=sysv \ -mabi=sysv \
-DGNU_EFI_USE_MS_ABI \
-fpie -fpie
INTERNAL_CFLAGS += \ INTERNAL_CFLAGS += \
@ -104,6 +105,7 @@ ifeq ($(TARGET), uefi)
-m64 \ -m64 \
-march=x86-64 \ -march=x86-64 \
-mabi=sysv \ -mabi=sysv \
-DGNU_EFI_USE_MS_ABI \
-I../gnu-efi/inc \ -I../gnu-efi/inc \
-I../gnu-efi/inc/x86_64 \ -I../gnu-efi/inc/x86_64 \
-fpie \ -fpie \
@ -117,6 +119,7 @@ ifeq ($(TARGET), uefi32)
-m32 \ -m32 \
-march=i386 \ -march=i386 \
-mabi=sysv \ -mabi=sysv \
-DGNU_EFI_USE_MS_ABI \
-I../gnu-efi/inc \ -I../gnu-efi/inc \
-I../gnu-efi/inc/ia32 \ -I../gnu-efi/inc/ia32 \
-fpie -fpie
@ -254,15 +257,12 @@ $(BUILDDIR)/BOOTX64.EFI: $(BUILDDIR)/limine_efi.elf
$(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-x86_64.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a: $(BUILDDIR)/gnu-efi $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-x86_64.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a: $(BUILDDIR)/gnu-efi
$(MAKE) -C $(BUILDDIR)/gnu-efi/gnuefi CC="$(TOOLCHAIN_CC) -m64 -march=x86-64" AR="$(TOOLCHAIN_AR)" ARCH=x86_64 $(MAKE) -C $(BUILDDIR)/gnu-efi/gnuefi CC="$(TOOLCHAIN_CC) -m64 -march=x86-64" AR="$(TOOLCHAIN_AR)" ARCH=x86_64
$(BUILDDIR)/gnu-efi/lib/x86_64/efi_stub.o: $(BUILDDIR)/gnu-efi $(BUILDDIR)/limine_efi_nomap.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-x86_64.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
$(MAKE) -C $(BUILDDIR)/gnu-efi/lib CC="$(TOOLCHAIN_CC) -m64 -march=x86-64" ARCH=x86_64 x86_64/efi_stub.o
$(BUILDDIR)/limine_efi_nomap.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-x86_64.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(BUILDDIR)/gnu-efi/lib/x86_64/efi_stub.o $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
$(TOOLCHAIN_LD) \ $(TOOLCHAIN_LD) \
-Tlinker_uefi_nomap.ld \ -Tlinker_uefi_nomap.ld \
$^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@ $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@
$(BUILDDIR)/limine_efi.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-x86_64.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(BUILDDIR)/gnu-efi/lib/x86_64/efi_stub.o $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/full.map.o $(BUILDDIR)/limine_efi.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-x86_64.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/full.map.o
$(TOOLCHAIN_LD) \ $(TOOLCHAIN_LD) \
-Tlinker_uefi.ld \ -Tlinker_uefi.ld \
$^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@ $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@
@ -282,15 +282,12 @@ $(BUILDDIR)/BOOTIA32.EFI: $(BUILDDIR)/limine_efi.elf
$(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-ia32.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a: $(BUILDDIR)/gnu-efi $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-ia32.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a: $(BUILDDIR)/gnu-efi
$(MAKE) -C $(BUILDDIR)/gnu-efi/gnuefi CC="$(TOOLCHAIN_CC) -m32 -march=i386" AR="$(TOOLCHAIN_AR)" ARCH=ia32 $(MAKE) -C $(BUILDDIR)/gnu-efi/gnuefi CC="$(TOOLCHAIN_CC) -m32 -march=i386" AR="$(TOOLCHAIN_AR)" ARCH=ia32
$(BUILDDIR)/gnu-efi/lib/ia32/efi_stub.o: $(BUILDDIR)/gnu-efi $(BUILDDIR)/limine_efi_nomap.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-ia32.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
$(MAKE) -C $(BUILDDIR)/gnu-efi/lib CC="$(TOOLCHAIN_CC) -m32 -march=i386" ARCH=ia32 ia32/efi_stub.o
$(BUILDDIR)/limine_efi_nomap.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-ia32.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(BUILDDIR)/gnu-efi/lib/ia32/efi_stub.o $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
$(TOOLCHAIN_LD) \ $(TOOLCHAIN_LD) \
-Tlinker_uefi32_nomap.ld \ -Tlinker_uefi32_nomap.ld \
$^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@ $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@
$(BUILDDIR)/limine_efi.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-ia32.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(BUILDDIR)/gnu-efi/lib/ia32/efi_stub.o $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/full.map.o $(BUILDDIR)/limine_efi.elf: $(BUILDDIR)/gnu-efi/gnuefi/crt0-efi-ia32.o $(BUILDDIR)/gnu-efi/gnuefi/libgnuefi.a $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/full.map.o
$(TOOLCHAIN_LD) \ $(TOOLCHAIN_LD) \
-Tlinker_uefi32.ld \ -Tlinker_uefi32.ld \
$^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@ $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@

View File

@ -214,23 +214,19 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE *efi_handle) {
EFI_DISK_IO *disk_io = NULL; EFI_DISK_IO *disk_io = NULL;
EFI_BLOCK_IO *block_io = NULL; EFI_BLOCK_IO *block_io = NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, efi_handle, &disk_io_guid, status = gBS->HandleProtocol(efi_handle, &disk_io_guid, (void **)&disk_io);
(void **)&disk_io);
if (status) if (status)
return NULL; return NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, efi_handle, &block_io_guid, status = gBS->HandleProtocol(efi_handle, &block_io_guid, (void **)&block_io);
(void **)&block_io);
if (status) if (status)
return NULL; return NULL;
uint64_t signature = BUILD_ID; uint64_t signature = BUILD_ID;
uint64_t orig; uint64_t orig;
uefi_call_wrapper(disk_io->ReadDisk, 5, disk_io, block_io->Media->MediaId, 0, disk_io->ReadDisk(disk_io, block_io->Media->MediaId, 0, sizeof(uint64_t), &orig);
sizeof(uint64_t), &orig);
status = uefi_call_wrapper(disk_io->WriteDisk, 5, status = disk_io->WriteDisk(disk_io, block_io->Media->MediaId, 0, sizeof(uint64_t), &signature);
disk_io, block_io->Media->MediaId, 0, sizeof(uint64_t), &signature);
if (status) { if (status) {
// Really hacky support for CDs because they are read-only // Really hacky support for CDs because they are read-only
@ -248,12 +244,12 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE *efi_handle) {
EFI_DISK_IO *cur_disk_io = NULL; EFI_DISK_IO *cur_disk_io = NULL;
EFI_BLOCK_IO *cur_block_io = NULL; EFI_BLOCK_IO *cur_block_io = NULL;
uefi_call_wrapper(gBS->HandleProtocol, 3, volume_index[i]->efi_handle, gBS->HandleProtocol(volume_index[i]->efi_handle,
&disk_io_guid, (void **)&cur_disk_io); &disk_io_guid, (void **)&cur_disk_io);
uefi_call_wrapper(gBS->HandleProtocol, 3, volume_index[i]->efi_handle, gBS->HandleProtocol(volume_index[i]->efi_handle,
&block_io_guid, (void **)&cur_block_io); &block_io_guid, (void **)&cur_block_io);
uefi_call_wrapper(cur_disk_io->ReadDisk, 5, cur_disk_io, cur_disk_io->ReadDisk(cur_disk_io,
cur_block_io->Media->MediaId, cur_block_io->Media->MediaId,
0 + 0 +
volume_index[i]->first_sect * volume_index[i]->sector_size, volume_index[i]->first_sect * volume_index[i]->sector_size,
@ -265,8 +261,7 @@ struct volume *disk_volume_from_efi_handle(EFI_HANDLE *efi_handle) {
} }
} }
uefi_call_wrapper(disk_io->WriteDisk, 5, disk_io, block_io->Media->MediaId, 0, disk_io->WriteDisk(disk_io, block_io->Media->MediaId, 0, sizeof(uint64_t), &orig);
sizeof(uint64_t), &orig);
return ret; return ret;
} }
@ -277,10 +272,10 @@ bool disk_read_sectors(struct volume *volume, void *buf, uint64_t block, size_t
EFI_GUID block_io_guid = BLOCK_IO_PROTOCOL; EFI_GUID block_io_guid = BLOCK_IO_PROTOCOL;
EFI_BLOCK_IO *block_io = NULL; EFI_BLOCK_IO *block_io = NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, volume->efi_handle, status = gBS->HandleProtocol(volume->efi_handle,
&block_io_guid, (void **)&block_io); &block_io_guid, (void **)&block_io);
status = uefi_call_wrapper(block_io->ReadBlocks, 5, block_io, status = block_io->ReadBlocks(block_io,
block_io->Media->MediaId, block_io->Media->MediaId,
block, count * volume->sector_size, buf); block, count * volume->sector_size, buf);
@ -298,13 +293,11 @@ void disk_create_index(void) {
EFI_HANDLE *handles = NULL; EFI_HANDLE *handles = NULL;
UINTN handles_size = 0; UINTN handles_size = 0;
uefi_call_wrapper(gBS->LocateHandle, 5, ByProtocol, &block_io_guid, gBS->LocateHandle(ByProtocol, &block_io_guid, NULL, &handles_size, handles);
NULL, &handles_size, handles);
handles = ext_mem_alloc(handles_size); handles = ext_mem_alloc(handles_size);
uefi_call_wrapper(gBS->LocateHandle, 5, ByProtocol, &block_io_guid, gBS->LocateHandle(ByProtocol, &block_io_guid, NULL, &handles_size, handles);
NULL, &handles_size, handles);
volume_index = ext_mem_alloc(sizeof(struct volume) * MAX_VOLUMES); volume_index = ext_mem_alloc(sizeof(struct volume) * MAX_VOLUMES);
@ -319,13 +312,11 @@ void disk_create_index(void) {
EFI_GUID disk_io_guid = DISK_IO_PROTOCOL; EFI_GUID disk_io_guid = DISK_IO_PROTOCOL;
EFI_DISK_IO *disk_io = NULL; EFI_DISK_IO *disk_io = NULL;
uefi_call_wrapper(gBS->HandleProtocol, 3, handles[i], &disk_io_guid, gBS->HandleProtocol(handles[i], &disk_io_guid, (void **)&disk_io);
(void **)&disk_io);
EFI_BLOCK_IO *drive = NULL; EFI_BLOCK_IO *drive = NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, handles[i], status = gBS->HandleProtocol(handles[i], &block_io_guid, (void **)&drive);
&block_io_guid, (void **)&drive);
if (status != 0 || drive == NULL || drive->Media->LastBlock == 0) if (status != 0 || drive == NULL || drive->Media->LastBlock == 0)
continue; continue;
@ -334,10 +325,8 @@ void disk_create_index(void) {
continue; continue;
uint64_t orig; uint64_t orig;
uefi_call_wrapper(disk_io->ReadDisk, 5, disk_io->ReadDisk(disk_io, drive->Media->MediaId, 0, sizeof(uint64_t), &orig);
disk_io, drive->Media->MediaId, 0, sizeof(uint64_t), &orig); status = disk_io->WriteDisk(disk_io, drive->Media->MediaId, 0, sizeof(uint64_t), &orig);
status = uefi_call_wrapper(disk_io->WriteDisk, 5,
disk_io, drive->Media->MediaId, 0, sizeof(uint64_t), &orig);
struct volume *block = ext_mem_alloc(sizeof(struct volume)); struct volume *block = ext_mem_alloc(sizeof(struct volume));

View File

@ -58,16 +58,14 @@ struct edid_info_struct *get_edid_info(void) {
UINTN handles_size = 0; UINTN handles_size = 0;
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
status = uefi_call_wrapper(gBS->LocateHandle, 5, status = gBS->LocateHandle(ByProtocol, &gop_guid, NULL, &handles_size, handles);
ByProtocol, &gop_guid, NULL, &handles_size, handles);
if (status && status != EFI_BUFFER_TOO_SMALL) if (status && status != EFI_BUFFER_TOO_SMALL)
goto fail; goto fail;
handles = ext_mem_alloc(handles_size); handles = ext_mem_alloc(handles_size);
status = uefi_call_wrapper(gBS->LocateHandle, 5, status = gBS->LocateHandle(ByProtocol, &gop_guid, NULL, &handles_size, handles);
ByProtocol, &gop_guid, NULL, &handles_size, handles);
if (status) if (status)
goto fail; goto fail;
@ -75,8 +73,7 @@ struct edid_info_struct *get_edid_info(void) {
EFI_EDID_ACTIVE_PROTOCOL *edid = NULL; EFI_EDID_ACTIVE_PROTOCOL *edid = NULL;
EFI_GUID edid_guid = EFI_EDID_ACTIVE_PROTOCOL_GUID; EFI_GUID edid_guid = EFI_EDID_ACTIVE_PROTOCOL_GUID;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, status = gBS->HandleProtocol(handles[0], &edid_guid, (void **)&edid);
handles[0], &edid_guid, (void **)&edid);
if (status) if (status)
goto fail; goto fail;

View File

@ -40,13 +40,12 @@ static bool try_mode(struct fb_info *ret, size_t mode, int width, int height, in
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
uefi_call_wrapper(gBS->LocateProtocol, 3, &gop_guid, NULL, (void **)&gop); gBS->LocateProtocol(&gop_guid, NULL, (void **)&gop);
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
UINTN mode_info_size; UINTN mode_info_size;
status = uefi_call_wrapper(gop->QueryMode, 4, status = gop->QueryMode(gop, mode, &mode_info_size, &mode_info);
gop, mode, &mode_info_size, &mode_info);
if (status) if (status)
return false; return false;
@ -102,7 +101,7 @@ static bool try_mode(struct fb_info *ret, size_t mode, int width, int height, in
if ((int)mode == current_video_mode) { if ((int)mode == current_video_mode) {
printv("gop: Mode was already set, perfect!\n"); printv("gop: Mode was already set, perfect!\n");
} else { } else {
status = uefi_call_wrapper(gop->SetMode, 2, gop, mode); status = gop->SetMode(gop, mode);
if (status) { if (status) {
current_video_mode = -2; current_video_mode = -2;
@ -137,17 +136,16 @@ bool init_gop(struct fb_info *ret,
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
uefi_call_wrapper(gBS->LocateProtocol, 3, &gop_guid, NULL, (void **)&gop); gBS->LocateProtocol(&gop_guid, NULL, (void **)&gop);
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
UINTN mode_info_size; UINTN mode_info_size;
status = uefi_call_wrapper(gop->QueryMode, 4, gop, status = gop->QueryMode(gop, gop->Mode == NULL ? 0 : gop->Mode->Mode,
gop->Mode == NULL ? 0 : gop->Mode->Mode, &mode_info_size, &mode_info);
&mode_info_size, &mode_info);
if (status == EFI_NOT_STARTED) { if (status == EFI_NOT_STARTED) {
status = uefi_call_wrapper(gop->SetMode, 2, gop, 0); status = gop->SetMode(gop, 0);
} }
if (status) { if (status) {

View File

@ -67,9 +67,8 @@ void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
EFI_GUID loaded_img_prot_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; EFI_GUID loaded_img_prot_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
EFI_LOADED_IMAGE_PROTOCOL *loaded_image = NULL; EFI_LOADED_IMAGE_PROTOCOL *loaded_image = NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, status = gBS->HandleProtocol(current_handle, &loaded_img_prot_guid,
current_handle, &loaded_img_prot_guid, (void **)&loaded_image);
(void **)&loaded_image);
if (status) { if (status) {
panic("HandleProtocol failure (%x)", status); panic("HandleProtocol failure (%x)", status);

View File

@ -15,7 +15,8 @@ EFI_BOOT_SERVICES *gBS;
EFI_RUNTIME_SERVICES *gRT; EFI_RUNTIME_SERVICES *gRT;
EFI_HANDLE efi_image_handle; EFI_HANDLE efi_image_handle;
EFI_MEMORY_DESCRIPTOR *efi_mmap = NULL; EFI_MEMORY_DESCRIPTOR *efi_mmap = NULL;
UINTN efi_mmap_size = 0, efi_desc_size = 0, efi_desc_ver = 0; UINTN efi_mmap_size = 0, efi_desc_size = 0;
UINT32 efi_desc_ver = 0;
#endif #endif
bool verbose = false; bool verbose = false;
@ -93,27 +94,24 @@ bool efi_exit_boot_services(void) {
efi_mmap_size = sizeof(tmp_mmap); efi_mmap_size = sizeof(tmp_mmap);
UINTN mmap_key = 0; UINTN mmap_key = 0;
uefi_call_wrapper(gBS->GetMemoryMap, 5, gBS->GetMemoryMap(&efi_mmap_size, tmp_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
&efi_mmap_size, tmp_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
efi_mmap_size += 4096; efi_mmap_size += 4096;
status = uefi_call_wrapper(gBS->FreePool, 1, efi_mmap); status = gBS->FreePool(efi_mmap);
if (status) if (status)
goto fail; goto fail;
status = uefi_call_wrapper(gBS->AllocatePool, 3, status = gBS->AllocatePool(EfiLoaderData, efi_mmap_size, (void **)&efi_mmap);
EfiLoaderData, efi_mmap_size, (void **)&efi_mmap);
if (status) if (status)
goto fail; goto fail;
status = uefi_call_wrapper(gBS->GetMemoryMap, 5, status = gBS->GetMemoryMap(&efi_mmap_size, efi_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
&efi_mmap_size, efi_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
if (status) if (status)
goto fail; goto fail;
// Be gone, UEFI! // Be gone, UEFI!
status = uefi_call_wrapper(gBS->ExitBootServices, 2, efi_image_handle, mmap_key); status = gBS->ExitBootServices(efi_image_handle, mmap_key);
asm volatile ("cli" ::: "memory"); asm volatile ("cli" ::: "memory");

View File

@ -17,7 +17,8 @@ extern EFI_BOOT_SERVICES *gBS;
extern EFI_RUNTIME_SERVICES *gRT; extern EFI_RUNTIME_SERVICES *gRT;
extern EFI_HANDLE efi_image_handle; extern EFI_HANDLE efi_image_handle;
extern EFI_MEMORY_DESCRIPTOR *efi_mmap; extern EFI_MEMORY_DESCRIPTOR *efi_mmap;
extern UINTN efi_mmap_size, efi_desc_size, efi_desc_ver; extern UINTN efi_mmap_size, efi_desc_size;
extern UINT32 efi_desc_ver;
extern bool efi_boot_services_exited; extern bool efi_boot_services_exited;
bool efi_exit_boot_services(void); bool efi_exit_boot_services(void);

View File

@ -33,7 +33,7 @@ __attribute__((noreturn)) void panic(const char *fmt, ...) {
// release all uefi memory and return to firmware // release all uefi memory and return to firmware
pmm_release_uefi_mem(); pmm_release_uefi_mem();
uefi_call_wrapper(gBS->Exit, 4, efi_image_handle, EFI_ABORTED, 0, NULL); gBS->Exit(efi_image_handle, EFI_ABORTED, 0, NULL);
__builtin_unreachable(); __builtin_unreachable();
} else { } else {
print("System halted."); print("System halted.");

View File

@ -98,10 +98,9 @@ again:;
UINTN which; UINTN which;
uefi_call_wrapper( gBS->WaitForEvent(1, (EFI_EVENT[]){ gST->ConIn->WaitForKey }, &which);
gBS->WaitForEvent, 3, 1, (EFI_EVENT[]){ gST->ConIn->WaitForKey }, &which);
uefi_call_wrapper(gST->ConIn->ReadKeyStroke, 2, gST->ConIn, &key); gST->ConIn->ReadKeyStroke(gST->ConIn, &key);
int ret = getchar_internal(key.ScanCode, key.UnicodeChar); int ret = getchar_internal(key.ScanCode, key.UnicodeChar);
@ -120,20 +119,18 @@ int pit_sleep_and_quit_on_keypress(int seconds) {
events[0] = gST->ConIn->WaitForKey; events[0] = gST->ConIn->WaitForKey;
uefi_call_wrapper( gBS->CreateEvent(EVT_TIMER, TPL_CALLBACK, NULL, NULL, &events[1]);
gBS->CreateEvent, 5, EVT_TIMER, TPL_CALLBACK, NULL, NULL, &events[1]);
uefi_call_wrapper( gBS->SetTimer(events[1], TimerRelative, 10000000 * seconds);
gBS->SetTimer, 3, events[1], TimerRelative, 10000000 * seconds);
again: again:
uefi_call_wrapper(gBS->WaitForEvent, 3, 2, events, &which); gBS->WaitForEvent(2, events, &which);
if (which == 1) { if (which == 1) {
return 0; return 0;
} }
uefi_call_wrapper(gST->ConIn->ReadKeyStroke, 2, gST->ConIn, &key); gST->ConIn->ReadKeyStroke(gST->ConIn, &key);
int ret = getchar_internal(key.ScanCode, key.UnicodeChar); int ret = getchar_internal(key.ScanCode, key.UnicodeChar);

View File

@ -52,7 +52,7 @@ uint64_t time(void) {
#if uefi == 1 #if uefi == 1
uint64_t time(void) { uint64_t time(void) {
EFI_TIME time; EFI_TIME time;
uefi_call_wrapper(gRT->GetTime, 2, &time, NULL); gRT->GetTime(&time, NULL);
return get_unix_epoch(time.Second, time.Minute, time.Hour, return get_unix_epoch(time.Second, time.Minute, time.Hour,
time.Day, time.Month, time.Year); time.Day, time.Month, time.Year);

View File

@ -261,16 +261,13 @@ void init_memmap(void) {
efi_mmap_size = sizeof(tmp_mmap); efi_mmap_size = sizeof(tmp_mmap);
UINTN mmap_key = 0; UINTN mmap_key = 0;
status = uefi_call_wrapper(gBS->GetMemoryMap, 5, status = gBS->GetMemoryMap(&efi_mmap_size, tmp_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
&efi_mmap_size, tmp_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
efi_mmap_size += 4096; efi_mmap_size += 4096;
status = uefi_call_wrapper(gBS->AllocatePool, 3, status = gBS->AllocatePool(EfiLoaderData, efi_mmap_size, (void **)&efi_mmap);
EfiLoaderData, efi_mmap_size, (void **)&efi_mmap);
status = uefi_call_wrapper(gBS->GetMemoryMap, 5, status = gBS->GetMemoryMap(&efi_mmap_size, efi_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
&efi_mmap_size, efi_mmap, &mmap_key, &efi_desc_size, &efi_desc_ver);
size_t entry_count = efi_mmap_size / efi_desc_size; size_t entry_count = efi_mmap_size / efi_desc_size;
@ -334,8 +331,8 @@ void init_memmap(void) {
EFI_PHYSICAL_ADDRESS base = memmap[i].base; EFI_PHYSICAL_ADDRESS base = memmap[i].base;
status = uefi_call_wrapper(gBS->AllocatePages, 4, status = gBS->AllocatePages(AllocateAddress, EfiLoaderData,
AllocateAddress, EfiLoaderData, memmap[i].length / 4096, &base); memmap[i].length / 4096, &base);
if (status) if (status)
panic("pmm: AllocatePages failure (%x)", status); panic("pmm: AllocatePages failure (%x)", status);
@ -447,8 +444,7 @@ void pmm_release_uefi_mem(void) {
continue; continue;
} }
status = uefi_call_wrapper(gBS->FreePages, 2, status = gBS->FreePages(memmap[i].base, memmap[i].length / 4096);
memmap[i].base, memmap[i].length / 4096);
if (status) if (status)
panic("pmm: FreePages failure (%x)", status); panic("pmm: FreePages failure (%x)", status);

View File

@ -123,8 +123,7 @@ void chainload(char *config) {
void *_ptr = freadall(image, MEMMAP_RESERVED); void *_ptr = freadall(image, MEMMAP_RESERVED);
size_t image_size = image->size; size_t image_size = image->size;
void *ptr; void *ptr;
status = uefi_call_wrapper(gBS->AllocatePool, 3, status = gBS->AllocatePool(EfiLoaderData, image_size, &ptr);
EfiLoaderData, image_size, &ptr);
if (status) if (status)
panic("chainload: Allocation failure"); panic("chainload: Allocation failure");
memcpy(ptr, _ptr, image_size); memcpy(ptr, _ptr, image_size);
@ -161,9 +160,9 @@ void chainload(char *config) {
EFI_HANDLE new_handle = 0; EFI_HANDLE new_handle = 0;
status = uefi_call_wrapper(gBS->LoadImage, 6, 0, efi_image_handle, status = gBS->LoadImage(0, efi_image_handle,
(EFI_DEVICE_PATH *)memdev_path, (EFI_DEVICE_PATH *)memdev_path,
ptr, image_size, &new_handle); ptr, image_size, &new_handle);
if (status) { if (status) {
panic("chainload: LoadImage failure (%x)", status); panic("chainload: LoadImage failure (%x)", status);
} }
@ -173,17 +172,15 @@ void chainload(char *config) {
EFI_GUID loaded_img_prot_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID; EFI_GUID loaded_img_prot_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
EFI_LOADED_IMAGE_PROTOCOL *loader_loaded_image = NULL; EFI_LOADED_IMAGE_PROTOCOL *loader_loaded_image = NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, status = gBS->HandleProtocol(efi_image_handle, &loaded_img_prot_guid,
efi_image_handle, &loaded_img_prot_guid, (void **)&loader_loaded_image);
(void **)&loader_loaded_image);
if (status) { if (status) {
panic("chainload: HandleProtocol failure (%x)", status); panic("chainload: HandleProtocol failure (%x)", status);
} }
EFI_LOADED_IMAGE_PROTOCOL *new_handle_loaded_image = NULL; EFI_LOADED_IMAGE_PROTOCOL *new_handle_loaded_image = NULL;
status = uefi_call_wrapper(gBS->HandleProtocol, 3, status = gBS->HandleProtocol(new_handle, &loaded_img_prot_guid,
new_handle, &loaded_img_prot_guid, (void **)&new_handle_loaded_image);
(void **)&new_handle_loaded_image);
if (status) { if (status) {
panic("chainload: HandleProtocol failure (%x)", status); panic("chainload: HandleProtocol failure (%x)", status);
} }
@ -192,11 +189,9 @@ void chainload(char *config) {
UINTN exit_data_size = 0; UINTN exit_data_size = 0;
CHAR16 *exit_data = NULL; CHAR16 *exit_data = NULL;
EFI_STATUS exit_status = uefi_call_wrapper(gBS->StartImage, 3, EFI_STATUS exit_status = gBS->StartImage(new_handle, &exit_data_size, &exit_data);
new_handle, &exit_data_size, &exit_data);
status = uefi_call_wrapper(gBS->Exit, 4, status = gBS->Exit(efi_image_handle, exit_status, exit_data_size, exit_data);
efi_image_handle, exit_status, exit_data_size, exit_data);
if (status) { if (status) {
panic("chainload: Exit failure (%x)", status); panic("chainload: Exit failure (%x)", status);
} }