]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/Thunk16/X64/Thunk16.S
EHCI Controllers with a CapLen of 0 are ignored.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Thunk16 / X64 / Thunk16.S
CommitLineData
b341712e 1#*****************************************************************************\r
2#*\r
4ea9375a
HT
3#* Copyright (c) 2008 - 2009, Intel Corporation. All rights reserved.<BR>\r
4#* This program and the accompanying materials \r
b341712e 5#* are licensed and made available under the terms and conditions of the BSD License \r
6#* which accompanies this distribution. The full text of the license may be found at \r
7#* http://opensource.org/licenses/bsd-license.php \r
8#* \r
9#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11#* \r
12#* Module Name:\r
13#*\r
14#* Thunk.S\r
15#* \r
16#* Abstract:\r
17#* \r
18#* Real mode thunk\r
19#* \r
20#*****************************************************************************\r
21#include <EfiBind.h>\r
22\r
23\r
24\r
25 .data\r
26\r
27.globl ASM_PFX(mCode16Size)\r
28\r
29.data\r
30mCode16Size: .long _Code16End - _Code16Addr\r
31\r
32\r
33NullSegSel: .quad 0\r
34_16CsSegSel: \r
35 .word -1\r
36 .word 0\r
37 .byte 0\r
38 .byte 0x9b\r
39 .byte 0x8f #16-bit segment\r
40 .byte 0\r
41_16DsSegSel:\r
42 .word -1\r
43 .word 0\r
44 .byte 0\r
45 .byte 0x93\r
46 .byte 0x8f #16-bit segment\r
47 .byte 0\r
48\r
49_16Gdtr:\r
50 .word _16Gdtr - NullSegSel - 1\r
51 .long NullSegSel\r
52 .code: \r
53\r
21a54a4d 54#IA32_REGS STRUC 4t\r
55#_EDI DD ?\r
56#_ESI DD ?\r
57#_EBP DD ?\r
58#_ESP DD ?\r
59#_EBX DD ?\r
60#_EDX DD ?\r
61#_ECX DD ?\r
62#_EAX DD ?\r
63#_DS DW ?\r
64#_ES DW ?\r
65#_FS DW ?\r
66#_GS DW ?\r
67#_RFLAGS DQ ?\r
68#_EIP DD ?\r
69#_CS DW ?\r
70#_SS DW ?\r
71#IA32_REGS ENDS\r
72\r
73#_STK16 STRUC 1t\r
74#RetEip DD ?\r
75#RetCs DW ?\r
76#ThunkFlags DW ?\r
77#SavedGdtr FWORD ?\r
78#Resvd1 DW ?\r
79#SavedCr0 DD ?\r
80#SavedCr4 DD ?\r
81#_STK16 ENDS\r
b341712e 82\r
83ASM_PFX(Thunk16):\r
84 push %rbp\r
85 push %rbx\r
86 push %rsi\r
87 push %rdi\r
88 push %r12\r
89 push %r13\r
90 push %r14\r
91 push %r15\r
92 pushq %fs\r
93 pushq %gs\r
94 movl %ds,%r12d\r
95 movl %es,%r13d\r
96 movl %ss,%r14d\r
97 mov %rsp,%r15\r
98 mov %rcx,%rsi\r
99 movzwq 0x36(%rsi),%r10 #movzx r10, (IA32_REGS ptr [rsi])._SS\r
100 xor %rdi,%rdi\r
101 mov 0xc(%rsi),%edi #mov edi, (IA32_REGS ptr [rsi])._ESP\r
102 add $0xffffffffffffffb0,%rdi #add rdi, - sizeof (IA32_REGS) - sizeof (_STK16)\r
103 push %rdi\r
104 imul $0x10,%r10,%rax\r
105 add %rax,%rdi\r
106 pushq $0xe #push sizeof (IA32_REGS) / 4\r
107 pop %rcx\r
108 rep movsl %ds:(%rsi),%es:(%rdi)\r
109 pop %rbx #rbx <- 16-bit stack offset\r
110 lea Label,%eax #42 <_Thunk16+0x42>\r
111 stos %eax,%es:(%rdi)\r
112 movl %cs,%eax #return segment\r
113 stos %ax,%es:(%rdi)\r
114 mov %edx,%eax #THUNK Flags\r
115 stos %ax,%es:(%rdi)\r
116 sgdt 0x58(%rsp) #save GDTR\r
117 mov 0x58(%rsp),%rax\r
118 stos %rax,%es:(%rdi)\r
119 mov %cr0,%rax #save CR0\r
120 mov %eax,%esi #esi <- CR0 to set\r
121 stos %eax,%es:(%rdi)\r
122 mov %cr4,%rax #save CR4\r
123 stos %eax,%es:(%rdi)\r
124 sidt 0x58(%rsp) #save IDTR\r
125 and $0x7ffffffe,%esi #clear PE & PG bits\r
126 mov %r10,%rdi #rdi <- 16-bit stack segment\r
127 shl $0x10,%r8\r
128 push %r8 #far jmp address\r
129 lea Label_16Bit,%eax \r
130 push %rax\r
131 movw $0x8,0x4(%rsp)\r
132 lgdt _16Gdtr #bugbug: may not match.\r
133 lret \r
134Label_16Bit:\r
135 .byte 0x66\r
136 movl $0xc0000080,%ecx\r
137 mov %rsi,%cr0 #disable PE & PG \r
138 rdmsr \r
139 and $0xfe,%ah\r
140 wrmsr #clear LME bit\r
141 mov %cr4,%rax\r
142 and $0xcf,%al #clear PAE & PSE\r
143 mov %rax,%cr4\r
144 lret \r
145\r
146Label:\r
147 xor %rax,%rax\r
148 movl %ss,%eax\r
149 shl $0x4,%eax\r
150 add %esp,%eax\r
151 mov %r15,%rsp\r
152 lidt 0x58(%rsp)\r
153 movl %r12d,%ds\r
154 movl %r13d,%es\r
155 movl %r14d,%ss\r
156 popq %gs\r
157 popq %fs\r
158 pop %r15\r
159 pop %r14\r
160 pop %r13\r
161 pop %r12\r
162 pop %rdi\r
163 pop %rsi\r
164 pop %rbx\r
165 pop %rbp\r
166 retq \r
167\r
168\r
f315cfa5 169 .p2align 4\r
b341712e 170\r
171_Code16Addr:\r
172ASM_PFX(RealMode):\r
173 movl %edi,%ss\r
174 mov %bx,%sp #set up 16-bit stack\r
175 .byte 0x2e \r
176 .byte 0x0f \r
177 .byte 0x01\r
21a54a4d 178 .byte 0x1e\r
179 .word _16Idtr - _Code16Addr #lidt _16Idtr\r
b341712e 180 .byte 0x66\r
21a54a4d 181 .byte 0x61 #popad\r
182 .byte 0x1f #pop ds\r
b341712e 183 .byte 0x07 #pop es\r
21a54a4d 184 popq %fs\r
185 popq %gs\r
186 add $0x8,%esp #skip RFLAGS\r
b341712e 187 .byte 0x67 #test [esp + 0eh], 1\r
188 .byte 0xf7 \r
189 .byte 0x44\r
190 .byte 0x24\r
191 .byte 0x0e\r
192 .byte 0x01\r
193 .byte 0x00\r
194 jz 1f\r
195 pushfq #pushf, actually\r
1961:\r
197 .byte 0x0e #push cs\r
198 .byte 0x68 #push /iw\r
199 .word FarCallRet - _Code16Addr\r
200 jz 2f\r
201 .byte 0x66\r
202 ljmp *6(%esp)\r
2032: \r
204 .byte 0x66\r
205 ljmp *4(%esp)\r
206FarCallRet: \r
207 .byte 0x66\r
208 push $0x00 #push a dword of zero\r
209 .byte 0x66\r
210 pushf #pushfd, actually\r
211 pushq %gs\r
212 pushq %fs\r
213 .byte 0x06 #push %es\r
214 .byte 0x1e #push %ds\r
215 .byte 0x66\r
216 .byte 0x60\r
217 cli\r
218 .byte 0x66 #sizeof (IA32_REGS) = 13 * 4 = 52\r
219 lgdt 64(%esp) #lgdt (_STK16 ptr [esp + sizeof (IA32_REGS)]).SavedGdtr\r
220 .byte 0x66\r
221 mov 76(%esp), %eax\r
222 mov %rax, %cr4\r
223 .byte 0x66\r
224 mov $0xc0000080, %ecx\r
225 rdmsr\r
226 orb $1, %ah\r
227 wrmsr\r
228 .byte 0x66\r
229 mov 72(%esp), %eax\r
230 mov %rax, %cr0 #restore CR0\r
231 .byte 0x66\r
232 ljmpl *52(%esp) \r
233\r
234_16Idtr:\r
235 .word 0x3ff #FWORD (1 SHL 10) - 1\r
236 .byte 0x00\r