Hi in my UEFI bootloader using FASM Assembly, I am trying to get my loaded image protocol interface structure using BS->OpenProtocol() function call. I am getting `EFI_INVALID_PARAMETER` as the result. As per my checks, the handle, the protocol and the interface are not NULL and I am passing the 5th and 6th arguments in stack from right-to-left and they are 8-byte aligned too. What am I missing? Any idea? Thank you.
; UEFI Bootloader using FASM Assembly
format pe64 efi
entry start
; EFI Constants
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL = 0x00000001
EFIERR = 0x8000000000000000
EFI_INVALID_PARAMETER = EFIERR or 0x2
section '.text' code executable readable
start:
push rbp
mov [image_handle], rcx
mov [system_table], rdx
...
; Get our loaded image protocol interface structure.
; Invoke ST->BootServices->OpenProtocol() function.
mov rax, [system_table]
mov rcx, [rax + 96]
mov r10, [rcx + 280]
mov rcx, [image_handle]
lea rdx, [EFI_LOADED_IMAGE_PROTOCOL_GUID]
lea r8, [boot_img]
mov r9, rcx
sub rsp, 32
mov eax, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
push rax
xor eax, eax
push rax
call r10
pop rcx
pop rcx
add rsp, 32
mov rcx, EFI_INVALID_PARAMETER
cmp rax, rcx
je .hang
...
.hang:
jmp $
...
section '.data' data readable writable
image_handle dq 0
system_table dq 0
; Image that we booted from.
boot_img dq 0
EFI_LOADED_IMAGE_PROTOCOL_GUID:
dd 0x5b1b31a1
dw 0x9562
dw 0x11d2
db 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b