1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include <linux/linkage.h>
23 #include <asm/page_types.h>
24 #include <asm/segment.h>
25
26 .text
27 .code64
28 ENTRY(efi64_thunk)
29 push %rbp
30 push %rbx
31
32
33
34
35 movq %rsp, efi_saved_sp(%rip)
36 movq efi_scratch(%rip), %rsp
37
38
39
40
41 movq $__START_KERNEL_map, %rax
42 subq phys_base(%rip), %rax
43
44
45
46
47
48
49
50 subq $16, %rsp
51 leaq efi_exit32(%rip), %rbx
52 subq %rax, %rbx
53 movl %ebx, 8(%rsp)
54
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
67
68
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)
89
90
91 pushq $__KERNEL32_CS
92 leaq efi_enter32(%rip), %rax
93 pushq %rax
94 lretq
95
96 1: addq $32, %rsp
97
98 pop %rbx
99 movl %ebx, %ss
100 pop %rbx
101 movl %ebx, %es
102 pop %rbx
103 movl %ebx, %ds
104
105
106
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:
116 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)
125
126 .code32
127
128
129
130
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
141 movl %eax, %edi
142
143 movl 72(%esp), %eax
144 pushl $__KERNEL_CS
145 pushl %eax
146
147 lret
148 ENDPROC(efi_enter32)
149
150 .data
151 .balign 8
152 func_rt_ptr: .quad 0
153 efi_saved_sp: .quad 0