]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Thunk16/Ia32/Thunk16.S
Fixed issues compiling for Apple gcc on IA-32
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Thunk16 / Ia32 / Thunk16.S
1 #*****************************************************************************
2 #*
3 #* Copyright (c) 2006 - 2009, Intel Corporation
4 #* All rights reserved. This program and the accompanying materials
5 #* are licensed and made available under the terms and conditions of the BSD License
6 #* which accompanies this distribution. The full text of the license may be found at
7 #* http://opensource.org/licenses/bsd-license.php
8 #*
9 #* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 #* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 #*
12 #* Module Name:
13 #*
14 #* Thunk.asm
15 #*
16 #* Abstract:
17 #*
18 #* Real mode thunk
19 #*
20 #*****************************************************************************
21 #include <EfiBind.h>
22
23 .686p:
24
25 .globl ASM_PFX(mCode16Size)
26
27 .data
28 mCode16Size: .long _TEXT16SIZE
29
30 .data
31
32 NullSegSel: .quad 0
33 _16BitCsSel:
34 .word -1
35 .word 0
36 .byte 0
37 .byte 0x9b
38 .byte 0x8f # 16-bit segment
39 .byte 0
40 _16BitSsSel:
41 .word -1
42 .word 0
43 .byte 0
44 .byte 0x93
45 .byte 0x8f # 16-bit segment
46 .byte 0
47
48 _16Gdtr:
49 .word _16Gdtr - NullSegSel - 1
50 .long NullSegSel
51
52
53 .text
54
55
56 ASM_PFX(Thunk16):
57 push %ebp
58 push %ebx
59 push %esi
60 push %edi
61 push %ds
62 push %es
63 push %fs
64 push %gs
65 mov 0x24(%esp),%esi
66 movzwl 0x32(%esi),%edx
67 mov 0xc(%esi),%edi
68 add $0xffffffb0,%edi
69 push %edi #; save stack offset
70 imul $0x10,%edx,%eax #; eax <- edx*16
71 add %eax,%edi #; edi <- linear address of 16-bit stack
72 push $0xd
73 pop %ecx
74 rep movsl %ds:(%esi),%es:(%edi) #; copy context to 16-bit stack
75 pop %ebx #; ebx <- 16-bit stack offset
76 mov $L_Lable1,%eax
77 stos %eax,%es:(%edi)
78 movl %cs,%eax
79 stos %ax,%es:(%edi)
80 mov 0x28(%esp),%eax
81 stos %ax,%es:(%edi)
82 mov %esp,%eax
83 stos %eax,%es:(%edi)
84 movl %ss,%eax
85 stos %ax,%es:(%edi)
86 sgdtl (%edi)
87 sidtl 0x24(%esp)
88 mov %cr0,%esi
89 mov %esi,0x6(%edi) #; save CR0
90 and $0x7ffffffe,%esi #; esi <- CR0 to set
91 mov %cr4,%eax
92 mov %eax,0xa(%edi) #; save CR4
93 and $0xcf,%al #; clear PAE & PSE
94 mov %edx,%edi #; edi <- 16-bit stack segment
95 mov 0x2c(%esp),%edx
96 shl $0x10,%edx
97 push %edx
98 pop %edx
99 mov $(_16BitSsSel - NullSegSel),%dx
100 lgdtl _16Gdtr #bugbug mismatch.
101 .byte 0xea
102 .long L_16Bit #bugbug mismatch.
103 .word _16BitCsSel - NullSegSel
104 L_16Bit:
105 .byte 0x66
106 movw %dx,%ss
107 mov %esi,%cr0
108 mov %eax,%cr4
109 .byte 0x67
110 .byte 0xff
111 .byte 0x6c
112 .byte 0x24
113 .byte 0xfc
114
115 L_Lable1:
116 movl %ss,%eax
117 shl $0x4,%eax
118 add %esp,%eax
119 lss 0x3c(%esp),%esp
120 lidtl 0x24(%esp)
121 pop %gs
122 pop %fs
123 pop %es
124 pop %ds
125 pop %edi
126 pop %esi
127 pop %ebx
128 pop %ebp
129 ret
130
131 .code16
132 _Code16Addr:
133 ASM_PFX(RealMode):
134 movw %di, %ss # set up stack
135 movl %ebx, %esp
136 lidt %cs:_16Idtr - _Code16Addr #lidt fword ptr cs:[_16Idtr - _Code16Addr]
137 .byte 0x66
138 popaw
139 popw %ds
140 popw %es
141 popw %fs
142 popw %gs
143 addw $4, %sp # skip EFlags
144 testw $1, 14(%esp) #(_STK16 ptr [esp + 8]).ThunkFlags, 1
145 jz 1f
146 pushf
147 1:
148 pushw %cs
149 # push @FarCallRet - _Code16Addr
150 .byte 0x68 # push /iw
151 .word FarCallRet - _Code16Addr
152 jz 2f
153 ljmp *6(%esp) #bugbug
154 2:
155 ljmp *4(%esp) #bugbug
156 FarCallRet:
157 pushfl
158 pushw %gs
159 pushw %fs
160 pushw %es
161 pushw %ds
162 pushal
163 cli
164 .byte 0x66 # sizeof (IA32_REGS) = 13 * 4 = 52
165 lgdt 66(%esp) #lgdt (_STK16 ptr [esp + sizeof (IA32_REGS)]).SavedGdtr
166 mov 76(%esp), %eax
167 movl %eax, %cr4
168 mov 72(%esp), %eax
169 movl %eax, %cr0 # restore CR0
170 ljmpl *52(%esp)
171 #RealMode ENDP
172
173 .text
174 _16Idtr:
175 .word 0x3ff #_16Idtr FWORD (1 SHL 10) - 1
176 .byte 0x00
177
178 _TEXT16END:
179
180 _TEXT16SIZE = _TEXT16END - _Code16Addr
181
182