]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/Thunk16/Ia32/Thunk16.S
Sync all bug fixes between EDK1.04 and EDK1.06 into EdkCompatibilityPkg.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Thunk16 / Ia32 / Thunk16.S
CommitLineData
b341712e 1#*****************************************************************************\r
2#*\r
3e99020d 3#* Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
4ea9375a 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.asm\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 .686p: \r
24\r
25.globl ASM_PFX(mCode16Size)\r
26\r
27.data\r
28mCode16Size: .long _TEXT16SIZE\r
29\r
30.data\r
31\r
32NullSegSel: .quad 0\r
33_16BitCsSel: \r
34 .word -1\r
35 .word 0\r
36 .byte 0\r
37 .byte 0x9b\r
38 .byte 0x8f # 16-bit segment\r
39 .byte 0\r
40_16BitSsSel:\r
41 .word -1\r
42 .word 0\r
43 .byte 0\r
44 .byte 0x93\r
45 .byte 0x8f # 16-bit segment\r
46 .byte 0\r
47\r
48_16Gdtr:\r
49 .word _16Gdtr - NullSegSel - 1\r
50 .long NullSegSel\r
51\r
52\r
53.text\r
b341712e 54\r
55\r
56ASM_PFX(Thunk16):\r
57 push %ebp\r
58 push %ebx\r
59 push %esi\r
60 push %edi\r
61 push %ds\r
62 push %es\r
63 push %fs\r
64 push %gs\r
65 mov 0x24(%esp),%esi\r
66 movzwl 0x32(%esi),%edx\r
67 mov 0xc(%esi),%edi\r
68 add $0xffffffb0,%edi\r
69 push %edi #; save stack offset\r
70 imul $0x10,%edx,%eax #; eax <- edx*16\r
71 add %eax,%edi #; edi <- linear address of 16-bit stack\r
72 push $0xd\r
73 pop %ecx\r
74 rep movsl %ds:(%esi),%es:(%edi) #; copy context to 16-bit stack\r
3e99020d
LG
75 #; copy eflags to stack frame\r
76 mov -12(%esi), %eax\r
77 mov %eax, -72(%edi) \r
b341712e 78 pop %ebx #; ebx <- 16-bit stack offset\r
e8de4680 79 mov $L_Lable1,%eax\r
b341712e 80 stos %eax,%es:(%edi)\r
81 movl %cs,%eax\r
82 stos %ax,%es:(%edi)\r
83 mov 0x28(%esp),%eax\r
84 stos %ax,%es:(%edi)\r
85 mov %esp,%eax\r
86 stos %eax,%es:(%edi)\r
87 movl %ss,%eax\r
88 stos %ax,%es:(%edi)\r
89 sgdtl (%edi)\r
90 sidtl 0x24(%esp)\r
91 mov %cr0,%esi\r
92 mov %esi,0x6(%edi) #; save CR0\r
93 and $0x7ffffffe,%esi #; esi <- CR0 to set\r
94 mov %cr4,%eax\r
95 mov %eax,0xa(%edi) #; save CR4\r
96 and $0xcf,%al #; clear PAE & PSE\r
97 mov %edx,%edi #; edi <- 16-bit stack segment\r
98 mov 0x2c(%esp),%edx\r
99 shl $0x10,%edx\r
100 push %edx\r
101 pop %edx\r
102 mov $(_16BitSsSel - NullSegSel),%dx\r
103 lgdtl _16Gdtr #bugbug mismatch.\r
104 .byte 0xea\r
105 .long L_16Bit #bugbug mismatch.\r
106 .word _16BitCsSel - NullSegSel\r
107L_16Bit: \r
108 .byte 0x66 \r
109 movw %dx,%ss\r
110 mov %esi,%cr0\r
111 mov %eax,%cr4\r
112 .byte 0x67\r
113 .byte 0xff\r
114 .byte 0x6c\r
115 .byte 0x24\r
116 .byte 0xfc\r
117 \r
118L_Lable1:\r
119 movl %ss,%eax\r
120 shl $0x4,%eax\r
121 add %esp,%eax\r
122 lss 0x3c(%esp),%esp\r
123 lidtl 0x24(%esp)\r
124 pop %gs\r
125 pop %fs\r
126 pop %es\r
127 pop %ds\r
128 pop %edi\r
129 pop %esi\r
130 pop %ebx\r
131 pop %ebp\r
132 ret \r
133\r
134.code16\r
135_Code16Addr:\r
136ASM_PFX(RealMode):\r
137 movw %di, %ss # set up stack\r
138 movl %ebx, %esp\r
139 lidt %cs:_16Idtr - _Code16Addr #lidt fword ptr cs:[_16Idtr - _Code16Addr]\r
140 .byte 0x66\r
141 popaw\r
142 popw %ds\r
143 popw %es\r
144 popw %fs\r
145 popw %gs\r
3e99020d
LG
146 sub 60, %esp\r
147 popfw\r
148 testw $1, 74(%esp) #(_STK16 ptr [esp + STACK_PARAM_SIZE + sizeof(IA32_REGS)]).ThunkFlags, 1\r
149\r
b341712e 150 jz 1f\r
3e99020d 151 pushf # push Flags when it's INT#\r
b341712e 1521: \r
153 pushw %cs\r
154# push @FarCallRet - _Code16Addr\r
155 .byte 0x68 # push /iw\r
156 .word FarCallRet - _Code16Addr\r
157 jz 2f\r
3e99020d 158 ljmp *66(%esp) #[esp + 6 + STACK_PARAM_SIZE + sizeof(IA32_REGS) - 8]\r
b341712e 1592: \r
3e99020d 160 ljmp *64(%esp) #[esp + 4 + STACK_PARAM_SIZE + sizeof(IA32_REGS) - 8]\r
b341712e 161FarCallRet: \r
3e99020d 162 add 60, %esp\r
b341712e 163 pushfl\r
164 pushw %gs\r
165 pushw %fs\r
166 pushw %es\r
167 pushw %ds\r
168 pushal\r
169 cli\r
170 .byte 0x66 # sizeof (IA32_REGS) = 13 * 4 = 52\r
171 lgdt 66(%esp) #lgdt (_STK16 ptr [esp + sizeof (IA32_REGS)]).SavedGdtr\r
172 mov 76(%esp), %eax\r
173 movl %eax, %cr4\r
174 mov 72(%esp), %eax\r
175 movl %eax, %cr0 # restore CR0\r
176 ljmpl *52(%esp) \r
177#RealMode ENDP\r
178\r
179.text\r
180_16Idtr:\r
181 .word 0x3ff #_16Idtr FWORD (1 SHL 10) - 1\r
182 .byte 0x00\r
183\r
184_TEXT16END: \r
185\r
186_TEXT16SIZE = _TEXT16END - _Code16Addr\r
187\r
188\r