UEFI Stack Order

Programming, for all ages and all languages.
Post Reply
d2alphame
Member
Member
Posts: 35
Joined: Fri May 04, 2012 8:04 am

UEFI Stack Order

Post by d2alphame »

I am learning UEFI (in assembly language). I have been able to clear the screen, print some stuff and exit successfully. However, I have issues with calling LocateHandle. I suspect the problem is with the way I am handling the stack and so I want to use this opportunity to understand how the stack should be.

What order should things be in when calling UEFI functions? Should I have the 5th, 6th, and 7th parameters on the stack before the shadow space or vice versa? For example should I have this

Code: Select all

; UEFI parameters go on the stack in reverse order

push PARAM_7         ; Push parameter 7
push PARAM_6         ; Push parameter 6
push PARAM_5         ; Push parameter 5
sub rsp, 32              ; Required shadow space
call UEFI_function    ; Call the function
Or should I have this

Code: Select all

sub rsp, 32              ; Make shadow space

; Remaining parameters go on the stack in reverse order
push PARAM_7        ; Push parameter 7
push PARAM_6        ; Push parameter 6
push PARAM_5        ; Push parameter 5
call UEFI_function    ; Call the function
If neither of these is correct, then what is the correct way to do it?
User avatar
zaval
Member
Member
Posts: 656
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: UEFI Stack Order

Post by zaval »

writing this from the phone, so hardly will be helpful. but, first, the calling convention is specified in the spec the latter is described on the Microsoft site, see the link and second, personally, I believe they go before shadow space, since the shadow space is for the first parameters, (I was wrong, they go after the shadow space) third, why you just don't check, crashing UEFI in VM is not that scary, I did that a hundred of times. :lol: fourth, read the article below, it describes it fully. in conclusion, your second variant is correct.

here read, there are answers there.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
Post Reply