1/* 2 * Function calling ABI conversion from Linux to EFI for x86_64 3 * 4 * Copyright (C) 2007 Intel Corp 5 * Bibo Mao <bibo.mao@intel.com> 6 * Huang Ying <ying.huang@intel.com> 7 */ 8 9#include <linux/linkage.h> 10#include <asm/segment.h> 11#include <asm/msr.h> 12#include <asm/processor-flags.h> 13#include <asm/page_types.h> 14#include <asm/frame.h> 15 16#define SAVE_XMM \ 17 mov %rsp, %rax; \ 18 subq $0x70, %rsp; \ 19 and $~0xf, %rsp; \ 20 mov %rax, (%rsp); \ 21 mov %cr0, %rax; \ 22 clts; \ 23 mov %rax, 0x8(%rsp); \ 24 movaps %xmm0, 0x60(%rsp); \ 25 movaps %xmm1, 0x50(%rsp); \ 26 movaps %xmm2, 0x40(%rsp); \ 27 movaps %xmm3, 0x30(%rsp); \ 28 movaps %xmm4, 0x20(%rsp); \ 29 movaps %xmm5, 0x10(%rsp) 30 31#define RESTORE_XMM \ 32 movaps 0x60(%rsp), %xmm0; \ 33 movaps 0x50(%rsp), %xmm1; \ 34 movaps 0x40(%rsp), %xmm2; \ 35 movaps 0x30(%rsp), %xmm3; \ 36 movaps 0x20(%rsp), %xmm4; \ 37 movaps 0x10(%rsp), %xmm5; \ 38 mov 0x8(%rsp), %rsi; \ 39 mov %rsi, %cr0; \ 40 mov (%rsp), %rsp 41 42 /* stolen from gcc */ 43 .macro FLUSH_TLB_ALL 44 movq %r15, efi_scratch(%rip) 45 movq %r14, efi_scratch+8(%rip) 46 movq %cr4, %r15 47 movq %r15, %r14 48 andb $0x7f, %r14b 49 movq %r14, %cr4 50 movq %r15, %cr4 51 movq efi_scratch+8(%rip), %r14 52 movq efi_scratch(%rip), %r15 53 .endm 54 55 .macro SWITCH_PGT 56 cmpb $0, efi_scratch+24(%rip) 57 je 1f 58 movq %r15, efi_scratch(%rip) # r15 59 # save previous CR3 60 movq %cr3, %r15 61 movq %r15, efi_scratch+8(%rip) # prev_cr3 62 movq efi_scratch+16(%rip), %r15 # EFI pgt 63 movq %r15, %cr3 64 1: 65 .endm 66 67 .macro RESTORE_PGT 68 cmpb $0, efi_scratch+24(%rip) 69 je 2f 70 movq efi_scratch+8(%rip), %r15 71 movq %r15, %cr3 72 movq efi_scratch(%rip), %r15 73 FLUSH_TLB_ALL 74 2: 75 .endm 76 77ENTRY(efi_call) 78 FRAME_BEGIN 79 SAVE_XMM 80 mov (%rsp), %rax 81 mov 8(%rax), %rax 82 subq $48, %rsp 83 mov %r9, 32(%rsp) 84 mov %rax, 40(%rsp) 85 mov %r8, %r9 86 mov %rcx, %r8 87 mov %rsi, %rcx 88 SWITCH_PGT 89 call *%rdi 90 RESTORE_PGT 91 addq $48, %rsp 92 RESTORE_XMM 93 FRAME_END 94 ret 95ENDPROC(efi_call) 96 97 .data 98ENTRY(efi_scratch) 99 .fill 3,8,0 100 .byte 0 101 .quad 0 102