]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/Thunk16/Ia32/Thunk16.S
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Thunk16 / Ia32 / Thunk16.S
CommitLineData
b341712e 1#*****************************************************************************\r
2#*\r
4ea9375a
HT
3#* Copyright (c) 2006 - 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.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
75 pop %ebx #; ebx <- 16-bit stack offset\r
e8de4680 76 mov $L_Lable1,%eax\r
b341712e 77 stos %eax,%es:(%edi)\r
78 movl %cs,%eax\r
79 stos %ax,%es:(%edi)\r
80 mov 0x28(%esp),%eax\r
81 stos %ax,%es:(%edi)\r
82 mov %esp,%eax\r
83 stos %eax,%es:(%edi)\r
84 movl %ss,%eax\r
85 stos %ax,%es:(%edi)\r
86 sgdtl (%edi)\r
87 sidtl 0x24(%esp)\r
88 mov %cr0,%esi\r
89 mov %esi,0x6(%edi) #; save CR0\r
90 and $0x7ffffffe,%esi #; esi <- CR0 to set\r
91 mov %cr4,%eax\r
92 mov %eax,0xa(%edi) #; save CR4\r
93 and $0xcf,%al #; clear PAE & PSE\r
94 mov %edx,%edi #; edi <- 16-bit stack segment\r
95 mov 0x2c(%esp),%edx\r
96 shl $0x10,%edx\r
97 push %edx\r
98 pop %edx\r
99 mov $(_16BitSsSel - NullSegSel),%dx\r
100 lgdtl _16Gdtr #bugbug mismatch.\r
101 .byte 0xea\r
102 .long L_16Bit #bugbug mismatch.\r
103 .word _16BitCsSel - NullSegSel\r
104L_16Bit: \r
105 .byte 0x66 \r
106 movw %dx,%ss\r
107 mov %esi,%cr0\r
108 mov %eax,%cr4\r
109 .byte 0x67\r
110 .byte 0xff\r
111 .byte 0x6c\r
112 .byte 0x24\r
113 .byte 0xfc\r
114 \r
115L_Lable1:\r
116 movl %ss,%eax\r
117 shl $0x4,%eax\r
118 add %esp,%eax\r
119 lss 0x3c(%esp),%esp\r
120 lidtl 0x24(%esp)\r
121 pop %gs\r
122 pop %fs\r
123 pop %es\r
124 pop %ds\r
125 pop %edi\r
126 pop %esi\r
127 pop %ebx\r
128 pop %ebp\r
129 ret \r
130\r
131.code16\r
132_Code16Addr:\r
133ASM_PFX(RealMode):\r
134 movw %di, %ss # set up stack\r
135 movl %ebx, %esp\r
136 lidt %cs:_16Idtr - _Code16Addr #lidt fword ptr cs:[_16Idtr - _Code16Addr]\r
137 .byte 0x66\r
138 popaw\r
139 popw %ds\r
140 popw %es\r
141 popw %fs\r
142 popw %gs\r
143 addw $4, %sp # skip EFlags\r
144 testw $1, 14(%esp) #(_STK16 ptr [esp + 8]).ThunkFlags, 1\r
145 jz 1f\r
146 pushf\r
1471: \r
148 pushw %cs\r
149# push @FarCallRet - _Code16Addr\r
150 .byte 0x68 # push /iw\r
151 .word FarCallRet - _Code16Addr\r
152 jz 2f\r
153 ljmp *6(%esp) #bugbug\r
1542: \r
155 ljmp *4(%esp) #bugbug\r
156FarCallRet: \r
157 pushfl\r
158 pushw %gs\r
159 pushw %fs\r
160 pushw %es\r
161 pushw %ds\r
162 pushal\r
163 cli\r
164 .byte 0x66 # sizeof (IA32_REGS) = 13 * 4 = 52\r
165 lgdt 66(%esp) #lgdt (_STK16 ptr [esp + sizeof (IA32_REGS)]).SavedGdtr\r
166 mov 76(%esp), %eax\r
167 movl %eax, %cr4\r
168 mov 72(%esp), %eax\r
169 movl %eax, %cr0 # restore CR0\r
170 ljmpl *52(%esp) \r
171#RealMode ENDP\r
172\r
173.text\r
174_16Idtr:\r
175 .word 0x3ff #_16Idtr FWORD (1 SHL 10) - 1\r
176 .byte 0x00\r
177\r
178_TEXT16END: \r
179\r
180_TEXT16SIZE = _TEXT16END - _Code16Addr\r
181\r
182\r