OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 5:49 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: EFI: Having difficulties opening the loaded image protocol
PostPosted: Sun Apr 03, 2016 7:37 am 
Offline

Joined: Sun Apr 03, 2016 7:09 am
Posts: 2
Hi everyone,
I think I need a fresh eye on my issue. Using FASM I kind of fail opening the loaded image protocol at the very start of a small EFI project. I think I'm following what the specs say, I disassembled to check that the instructions are in place, I read the assembly to check that the protocol GUID is right. But whatever the case, the BootService.OpenProtocol always returns a 2 for "invalid parameter".
Can someone check that this call seems right?
Code:
format pe64 dll efi
entry main

section '.text' code executable readable
include "efi_test.inc"

main:
mov [Handle], rcx         ; ImageHandle
mov [SystemTable], rdx    ; pointer to SystemTable

; this is calling OpenProtocol on the image handle for EFI_LOADED_IMAGE_PROTOCOL_GUID
mov rcx, [Handle]                     ; param 1: image handle
lea rdx, [EFI_LOADED_IMAGE_PROTOCOL_GUID]   ; param 2: GUID
lea r8, [LoadedImageProtocol]            ; param 3: pointer where to store the protocol
mov r9, rcx                        ; param 4: image handle
mov r10, 0
push r10                           ; param 5: optional null, not a driver
mov r10, 2
push r10                           ; param 6: attributes=2=EFI_OPEN_PROTOCOL_GET_PROTOCOL
mov rax, [SystemTable]
mov rax, [rax + EFI_SYSTEM_TABLE.BootServices]
call [rax + EFI_BOOT_SERVICES_TABLE.OpenProtocol]
pop rcx
pop rcx
cmp rax, EFI_SUCCESS
je got_protocol
   ; ... display error message here


I got the 6 parameters correctly, right? Or do I need to do something before so that the call is successful? I can't figure out this one.


Top
 Profile  
 
 Post subject: Re: EFI: Having difficulties opening the loaded image protoc
PostPosted: Mon Apr 04, 2016 2:56 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
It looks like the wrong calling convention. You need to have empty stack space so that register parameters can be shoved back, and the stack needs to remain SSE-aligned.

I haven't dealt with the win64 convention in a while, so please look it up for the exact details.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: EFI: Having difficulties opening the loaded image protoc
PostPosted: Tue Apr 05, 2016 10:55 pm 
Offline

Joined: Sun Apr 03, 2016 7:09 am
Posts: 2
A small update. I managed to get the loaded image protocol but by using HandleProtocol, which is supposed to be deprecated by OpenProtocol.

Apparently, in order to successfully use OpenProtocol, I need to use a "EFI core image handle" as the agent instead of the currently running EFI image. The only issue is that I have no idea where to find it, so I'm stuck using a deprecated API.


Top
 Profile  
 
 Post subject: Re: EFI: Having difficulties opening the loaded image protoc
PostPosted: Wed Apr 06, 2016 12:03 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
For applications. just pass your application handle as the "agent". This is what the UEFI 2.5 specs says to do and it works.

That said, both Linux and FreeBSD use HandleProtocol() and not OpenProtocol(). So we know it is working and not going away soon. Up to you if you insist on using OpenProtocol() / CloseProtocol().

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group