Page 1 of 1

UEFI Stack Order

Posted: Sun Jan 01, 2023 4:45 pm
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?

Re: UEFI Stack Order

Posted: Sun Jan 01, 2023 5:48 pm
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.