flat assembler
Message board for the users of flat assembler.

Index > OS Construction > [solved] EFI_INVALID_PARAMETER on calling OpenProtocol()

Author
Thread Post new topic Reply to topic
robstat7



Joined: 03 Apr 2024
Posts: 9
robstat7 28 Oct 2026, 11:11
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.

Code:
; 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
    
Post 28 Oct 2026, 11:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21191
Location: In your JS exploiting you and your system
revolution 28 Oct 2026, 17:44
The EFI call convention is to push parameters to the stack in reverse order.

Parameters 5 and 6 are pushed first in order 6 then 5. After that the shadow space is allocated.
Post 28 Oct 2026, 17:44
View user's profile Send private message Visit poster's website Reply with quote
robstat7



Joined: 03 Apr 2024
Posts: 9
robstat7 29 Oct 2026, 05:12
Thank you so much. It worked! Sorry I read the Microsoft's x64 calling convention document wrongly!
Post 29 Oct 2026, 05:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.