So I got quite excited about playing with UEFI again.. So for UASM 2.50 release I've created a new custom EFI.INC with all the type/structs hand ported from the C headers.. I will be making a tutorial for it explaining in detail how to setup UEFI and get it booting on real h/w, Virtual BOX etc with a simple build and debug process for creating UEFI apps and boot files.. Just to give you an example of how the header port works in UASM (a lot nicer than NASM ;) )
OPTION WIN64:15
OPTION STACKBASE:RSP
OPTION LITERALS:ON
OPTION ARCH:AVX
OPTION CASEMAP:NONE
include efi.inc
.data
Handle dq 0
SystemTablePtr dq 0
HelloMsg dw 'Hello UEFI World!',13,10,0
pConsole PCONOUT 0
pBootServices P_BOOT_SERVICES 0
mapSize UINTN 64*SIZEOF(EFI_MEMORY_DESCRIPTOR)
descriptors EFI_MEMORY_DESCRIPTOR 64 DUP (<?>)
mapKey UINTN 0
descSize UINTN 0
descVer UINT32 0
.code
Main PROC FRAME imageHandle:EFI_HANDLE, SystemTable:PTR_EFI_SYSTEM_TABLE
mov Handle,rcx
mov SystemTablePtr,rdx
;=====================================================================================
; The normal ASM way to make a 64bit FASTCALL.
;=====================================================================================
sub rsp,20h
lea rdx,HelloMsg
mov rcx,SystemTablePtr
mov rcx,[rcx + EFI_SYSTEM_TABLE_CONOUT]
call qword ptr [rcx + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_OUTPUTSTRING]
add rsp,20h
;=====================================================================================
; The smarter UASM way...
;=====================================================================================
mov rcx,SystemTablePtr
mov rcx,[rcx].EFI_SYSTEM_TABLE.ConOut
mov pConsole,rcx
invoke [rcx].ConOut.OutputString, pConsole, L"Hello Smarter UEFI World!\r\n"
; Or if you have a list of calls to make against the same protocol/interface
ASSUME rcx:PTR ConOut
mov rcx,pConsole
invoke [rcx].OutputString, pConsole, ADDR HelloMsg
ASSUME rcx:NOTHING
;=====================================================================================
; The even smarter ways...
;=====================================================================================
pConsole->OutputString(pConsole, L"Testing\r\n")
; or
mov rax,pConsole
[rax].ConOut->OutputString(pConsole, L"Testing2\r\n")
pConsole->ClearScreen()
;=====================================================================================
; Store pointer to the BOOT SERVICES Interface
;=====================================================================================
mov rax,SystemTablePtr
mov rsi,[rax].EFI_SYSTEM_TABLE.BootServices
mov pBootServices,rsi
; Get Memory Map
[rsi].BOOT_SERVICES->GetMemoryMap(&mapSize, &descriptors, &mapKey, &descSize, &descVer)
.if(rax != EFI_SUCCESS)
pConsole->OutputString(pConsole, L"Failed to get memory map\r\n")
pBootServices->Exit(Handle, EFI_ERROR, 36, L"Memory Map Error\r\n")
.else
pConsole->OutputString(pConsole, L"Got memory map\r\n")
.endif
mov eax,EFI_SUCCESS
ret
Main ENDP
END Main