Skip to content

Commit 3fab433

Browse files
nivedita76Ingo Molnar
authored andcommitted
efi/x86: Make efi32_pe_entry() more readable
Set up a proper frame pointer in efi32_pe_entry() so that it's easier to calculate offsets for arguments. Signed-off-by: Arvind Sankar <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 71ff44a commit 3fab433

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

arch/x86/boot/compressed/head_64.S

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -658,42 +658,65 @@ SYM_DATA(efi_is64, .byte 1)
658658
.text
659659
.code32
660660
SYM_FUNC_START(efi32_pe_entry)
661+
/*
662+
* efi_status_t efi32_pe_entry(efi_handle_t image_handle,
663+
* efi_system_table_32_t *sys_table)
664+
*/
665+
661666
pushl %ebp
667+
movl %esp, %ebp
668+
pushl %eax // dummy push to allocate loaded_image
662669

663-
pushl %ebx
670+
pushl %ebx // save callee-save registers
664671
pushl %edi
672+
665673
call verify_cpu // check for long mode support
666-
popl %edi
667-
popl %ebx
668674
testl %eax, %eax
669675
movl $0x80000003, %eax // EFI_UNSUPPORTED
670-
jnz 3f
676+
jnz 2f
671677

672678
call 1f
673-
1: pop %ebp
674-
subl $1b, %ebp
679+
1: pop %ebx
680+
subl $1b, %ebx
675681

676682
/* Get the loaded image protocol pointer from the image handle */
677-
subl $12, %esp // space for the loaded image pointer
678-
pushl %esp // pass its address
679-
leal loaded_image_proto(%ebp), %eax
683+
leal -4(%ebp), %eax
684+
pushl %eax // &loaded_image
685+
leal loaded_image_proto(%ebx), %eax
680686
pushl %eax // pass the GUID address
681-
pushl 28(%esp) // pass the image handle
687+
pushl 8(%ebp) // pass the image handle
682688

683-
movl 36(%esp), %eax // sys_table
689+
/*
690+
* Note the alignment of the stack frame.
691+
* sys_table
692+
* handle <-- 16-byte aligned on entry by ABI
693+
* return address
694+
* frame pointer
695+
* loaded_image <-- local variable
696+
* saved %ebx <-- 16-byte aligned here
697+
* saved %edi
698+
* &loaded_image
699+
* &loaded_image_proto
700+
* handle <-- 16-byte aligned for call to handle_protocol
701+
*/
702+
703+
movl 12(%ebp), %eax // sys_table
684704
movl ST32_boottime(%eax), %eax // sys_table->boottime
685705
call *BS32_handle_protocol(%eax) // sys_table->boottime->handle_protocol
686-
cmp $0, %eax
706+
addl $12, %esp // restore argument space
707+
testl %eax, %eax
687708
jnz 2f
688709

689-
movl 32(%esp), %ecx // image_handle
690-
movl 36(%esp), %edx // sys_table
691-
movl 12(%esp), %esi // loaded_image
710+
movl 8(%ebp), %ecx // image_handle
711+
movl 12(%ebp), %edx // sys_table
712+
movl -4(%ebp), %esi // loaded_image
692713
movl LI32_image_base(%esi), %esi // loaded_image->image_base
714+
movl %ebx, %ebp // startup_32 for efi32_pe_stub_entry
693715
jmp efi32_pe_stub_entry
694716

695-
2: addl $24, %esp
696-
3: popl %ebp
717+
2: popl %edi // restore callee-save registers
718+
popl %ebx
719+
leave
697720
ret
698721
SYM_FUNC_END(efi32_pe_entry)
699722

0 commit comments

Comments
 (0)