#include <linux/linkage.h>
#include <asm/desc_defs.h>
#include <asm/msr.h>
#include <asm/page_types.h>
#include <asm/pgtable_types.h>
#include <asm/processor-flags.h>
#include <asm/segment.h>
.text
.code32
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
SYM_FUNC_START(efi32_stub_entry)
call 1f
1: popl %ecx
xorl %eax, %eax
leal (_bss - 1b)(%ecx), %edi
leal (_ebss - 1b)(%ecx), %ecx
subl %edi, %ecx
shrl $2, %ecx
cld
rep stosl
add $0x4, %esp
movl 8(%esp), %ebx
jmp efi32_startup
SYM_FUNC_END(efi32_stub_entry)
#endif
SYM_FUNC_START_LOCAL(efi_enter32)
pushl 32(%ebp)
pushl 24(%ebp)
pushl 16(%ebp)
pushl %ebx
pushl %eax
pushl %ecx
pushl %edx
pushl %esi
movl %cr0, %eax
btrl $X86_CR0_PG_BIT, %eax
movl %eax, %cr0
movl $MSR_EFER, %ecx
rdmsr
btrl $_EFER_LME, %eax
wrmsr
call *%edi
movl %eax, %edi
call efi32_enable_long_mode
addl $32, %esp
movl %edi, %eax
lret
SYM_FUNC_END(efi_enter32)
.code64
SYM_FUNC_START(__efi64_thunk)
push %rbp
movl %esp, %ebp
push %rbx
movl %r8d, %eax
movl %r9d, %ebx
lcalll *efi32_call(%rip)
pop %rbx
pop %rbp
RET
SYM_FUNC_END(__efi64_thunk)
.code32
SYM_FUNC_START_LOCAL(efi32_enable_long_mode)
movl %cr4, %eax
btsl $(X86_CR4_PAE_BIT), %eax
movl %eax, %cr4
movl $MSR_EFER, %ecx
rdmsr
btsl $_EFER_LME, %eax
wrmsr
cli
movl %cr0, %eax
btsl $X86_CR0_PG_BIT, %eax
movl %eax, %cr0
ret
SYM_FUNC_END(efi32_enable_long_mode)
SYM_FUNC_START_LOCAL(efi32_startup)
movl %esp, %ebp
subl $8, %esp
sgdtl (%esp)
movl 2(%esp), %esi
movzwl (%esp), %ecx
inc %ecx
andl $~7, %ecx
subl %ecx, %esp
andl $~15, %esp
movl %esp, %edi
leal 7(%ecx), %eax
pushw %cx
pushl %edi
pushw %ax
movl $GDT_ENTRY(DESC_CODE64, 0, 0xfffff) & 0xffffffff, (%edi,%ecx)
movl $GDT_ENTRY(DESC_CODE64, 0, 0xfffff) >> 32, 4(%edi,%ecx)
shrl $2, %ecx
cld
rep movsl
lgdtl (%esp)
call 1f
1: pop %edi
movb $0x0, (efi_is64 - 1b)(%edi)
leal (efi32_call - 1b)(%edi), %eax
addl %eax, (%eax)
movw %cs, 4(%eax)
movl %cr0, %eax
btrl $X86_CR0_PG_BIT, %eax
movl %eax, %cr0
leal (pte - 1b)(%edi), %eax
movl $_PAGE_PRESENT | _PAGE_RW | _PAGE_PSE, %ecx
leal (_PAGE_PRESENT | _PAGE_RW)(%eax), %edx
2: movl %ecx, (%eax)
addl $8, %eax
addl $PMD_SIZE, %ecx
jnc 2b
movl $PAGE_SIZE, %ecx
.irpc l, 0123
movl %edx, \l * 8(%eax)
addl %ecx, %edx
.endr
addl %ecx, %eax
movl %edx, (%eax)
movl %eax, %cr3
call efi32_enable_long_mode
leal (efi_stub_entry - 1b)(%edi), %eax
movl %eax, 2(%esp)
movl 0(%ebp), %edi
movl 4(%ebp), %esi
movl %ebx, %edx
ljmpl *2(%esp)
SYM_FUNC_END(efi32_startup)
SYM_FUNC_START(efi32_pe_entry)
pushl %ebx
movl $0x80000001, %eax
cpuid
btl $29, %edx
jnc 1f
leal 8(%esp), %esp
xor %ebx, %ebx
jmp efi32_startup
1: movl $0x80000003, %eax
popl %ebx
RET
SYM_FUNC_END(efi32_pe_entry)
#ifdef CONFIG_EFI_HANDOVER_PROTOCOL
.org efi32_stub_entry + 0x200
.code64
SYM_FUNC_START_NOALIGN(efi64_stub_entry)
jmp efi_handover_entry
SYM_FUNC_END(efi64_stub_entry)
#endif
.data
.balign 8
SYM_DATA_START_LOCAL(efi32_call)
.long efi_enter32 - .
.word 0x0
SYM_DATA_END(efi32_call)
SYM_DATA(efi_is64, .byte 1)
.bss
.balign PAGE_SIZE
SYM_DATA_LOCAL(pte, .fill 6 * PAGE_SIZE, 1, 0