| .. | .. |
|---|
| 22 | 22 | #include <linux/linkage.h> |
|---|
| 23 | 23 | #include <asm/page_types.h> |
|---|
| 24 | 24 | #include <asm/segment.h> |
|---|
| 25 | +#include <asm/nospec-branch.h> |
|---|
| 25 | 26 | |
|---|
| 26 | 27 | .text |
|---|
| 27 | 28 | .code64 |
|---|
| 28 | | -ENTRY(efi64_thunk) |
|---|
| 29 | +SYM_CODE_START(__efi64_thunk) |
|---|
| 29 | 30 | push %rbp |
|---|
| 30 | 31 | push %rbx |
|---|
| 31 | 32 | |
|---|
| 32 | 33 | /* |
|---|
| 33 | 34 | * Switch to 1:1 mapped 32-bit stack pointer. |
|---|
| 34 | 35 | */ |
|---|
| 35 | | - movq %rsp, efi_saved_sp(%rip) |
|---|
| 36 | + movq %rsp, %rax |
|---|
| 36 | 37 | movq efi_scratch(%rip), %rsp |
|---|
| 38 | + push %rax |
|---|
| 37 | 39 | |
|---|
| 38 | 40 | /* |
|---|
| 39 | 41 | * Calculate the physical address of the kernel text. |
|---|
| .. | .. |
|---|
| 41 | 43 | movq $__START_KERNEL_map, %rax |
|---|
| 42 | 44 | subq phys_base(%rip), %rax |
|---|
| 43 | 45 | |
|---|
| 44 | | - /* |
|---|
| 45 | | - * Push some physical addresses onto the stack. This is easier |
|---|
| 46 | | - * to do now in a code64 section while the assembler can address |
|---|
| 47 | | - * 64-bit values. Note that all the addresses on the stack are |
|---|
| 48 | | - * 32-bit. |
|---|
| 49 | | - */ |
|---|
| 50 | | - subq $16, %rsp |
|---|
| 51 | | - leaq efi_exit32(%rip), %rbx |
|---|
| 46 | + leaq 1f(%rip), %rbp |
|---|
| 47 | + leaq 2f(%rip), %rbx |
|---|
| 48 | + subq %rax, %rbp |
|---|
| 52 | 49 | subq %rax, %rbx |
|---|
| 53 | | - movl %ebx, 8(%rsp) |
|---|
| 54 | 50 | |
|---|
| 55 | | - leaq __efi64_thunk(%rip), %rbx |
|---|
| 56 | | - subq %rax, %rbx |
|---|
| 57 | | - call *%rbx |
|---|
| 58 | | - |
|---|
| 59 | | - movq efi_saved_sp(%rip), %rsp |
|---|
| 60 | | - pop %rbx |
|---|
| 61 | | - pop %rbp |
|---|
| 62 | | - retq |
|---|
| 63 | | -ENDPROC(efi64_thunk) |
|---|
| 64 | | - |
|---|
| 65 | | -/* |
|---|
| 66 | | - * We run this function from the 1:1 mapping. |
|---|
| 67 | | - * |
|---|
| 68 | | - * This function must be invoked with a 1:1 mapped stack. |
|---|
| 69 | | - */ |
|---|
| 70 | | -ENTRY(__efi64_thunk) |
|---|
| 71 | | - movl %ds, %eax |
|---|
| 72 | | - push %rax |
|---|
| 73 | | - movl %es, %eax |
|---|
| 74 | | - push %rax |
|---|
| 75 | | - movl %ss, %eax |
|---|
| 76 | | - push %rax |
|---|
| 77 | | - |
|---|
| 78 | | - subq $32, %rsp |
|---|
| 79 | | - movl %esi, 0x0(%rsp) |
|---|
| 80 | | - movl %edx, 0x4(%rsp) |
|---|
| 81 | | - movl %ecx, 0x8(%rsp) |
|---|
| 82 | | - movq %r8, %rsi |
|---|
| 83 | | - movl %esi, 0xc(%rsp) |
|---|
| 84 | | - movq %r9, %rsi |
|---|
| 85 | | - movl %esi, 0x10(%rsp) |
|---|
| 86 | | - |
|---|
| 87 | | - leaq 1f(%rip), %rbx |
|---|
| 88 | | - movq %rbx, func_rt_ptr(%rip) |
|---|
| 51 | + subq $28, %rsp |
|---|
| 52 | + movl %ebx, 0x0(%rsp) /* return address */ |
|---|
| 53 | + movl %esi, 0x4(%rsp) |
|---|
| 54 | + movl %edx, 0x8(%rsp) |
|---|
| 55 | + movl %ecx, 0xc(%rsp) |
|---|
| 56 | + movl %r8d, 0x10(%rsp) |
|---|
| 57 | + movl %r9d, 0x14(%rsp) |
|---|
| 89 | 58 | |
|---|
| 90 | 59 | /* Switch to 32-bit descriptor */ |
|---|
| 91 | 60 | pushq $__KERNEL32_CS |
|---|
| 92 | | - leaq efi_enter32(%rip), %rax |
|---|
| 93 | | - pushq %rax |
|---|
| 61 | + pushq %rdi /* EFI runtime service address */ |
|---|
| 94 | 62 | lretq |
|---|
| 95 | 63 | |
|---|
| 96 | | -1: addq $32, %rsp |
|---|
| 97 | | - |
|---|
| 64 | +1: movq 24(%rsp), %rsp |
|---|
| 98 | 65 | pop %rbx |
|---|
| 99 | | - movl %ebx, %ss |
|---|
| 100 | | - pop %rbx |
|---|
| 101 | | - movl %ebx, %es |
|---|
| 102 | | - pop %rbx |
|---|
| 103 | | - movl %ebx, %ds |
|---|
| 104 | | - |
|---|
| 105 | | - /* |
|---|
| 106 | | - * Convert 32-bit status code into 64-bit. |
|---|
| 107 | | - */ |
|---|
| 108 | | - test %rax, %rax |
|---|
| 109 | | - jz 1f |
|---|
| 110 | | - movl %eax, %ecx |
|---|
| 111 | | - andl $0x0fffffff, %ecx |
|---|
| 112 | | - andl $0xf0000000, %eax |
|---|
| 113 | | - shl $32, %rax |
|---|
| 114 | | - or %rcx, %rax |
|---|
| 115 | | -1: |
|---|
| 66 | + pop %rbp |
|---|
| 67 | + ANNOTATE_UNRET_SAFE |
|---|
| 116 | 68 | ret |
|---|
| 117 | | -ENDPROC(__efi64_thunk) |
|---|
| 118 | | - |
|---|
| 119 | | -ENTRY(efi_exit32) |
|---|
| 120 | | - movq func_rt_ptr(%rip), %rax |
|---|
| 121 | | - push %rax |
|---|
| 122 | | - mov %rdi, %rax |
|---|
| 123 | | - ret |
|---|
| 124 | | -ENDPROC(efi_exit32) |
|---|
| 69 | + int3 |
|---|
| 125 | 70 | |
|---|
| 126 | 71 | .code32 |
|---|
| 127 | | -/* |
|---|
| 128 | | - * EFI service pointer must be in %edi. |
|---|
| 129 | | - * |
|---|
| 130 | | - * The stack should represent the 32-bit calling convention. |
|---|
| 131 | | - */ |
|---|
| 132 | | -ENTRY(efi_enter32) |
|---|
| 133 | | - movl $__KERNEL_DS, %eax |
|---|
| 134 | | - movl %eax, %ds |
|---|
| 135 | | - movl %eax, %es |
|---|
| 136 | | - movl %eax, %ss |
|---|
| 137 | | - |
|---|
| 138 | | - call *%edi |
|---|
| 139 | | - |
|---|
| 140 | | - /* We must preserve return value */ |
|---|
| 141 | | - movl %eax, %edi |
|---|
| 142 | | - |
|---|
| 143 | | - movl 72(%esp), %eax |
|---|
| 144 | | - pushl $__KERNEL_CS |
|---|
| 145 | | - pushl %eax |
|---|
| 146 | | - |
|---|
| 72 | +2: pushl $__KERNEL_CS |
|---|
| 73 | + pushl %ebp |
|---|
| 147 | 74 | lret |
|---|
| 148 | | -ENDPROC(efi_enter32) |
|---|
| 149 | | - |
|---|
| 150 | | - .data |
|---|
| 151 | | - .balign 8 |
|---|
| 152 | | -func_rt_ptr: .quad 0 |
|---|
| 153 | | -efi_saved_sp: .quad 0 |
|---|
| 75 | +SYM_CODE_END(__efi64_thunk) |
|---|