1 #------------------------------------------------------------------------------
3 # Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4 # 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.
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.
20 #------------------------------------------------------------------------------
22 #include <Library/BaseLib.h>
24 ASM_GLOBAL ASM_PFX(m16Start), ASM_PFX(m16Size), ASM_PFX(mThunk16Attr), ASM_PFX(m16Gdt), ASM_PFX(m16GdtrBase), ASM_PFX(mTransition)
25 ASM_GLOBAL ASM_PFX(InternalAsmThunk16)
31 ASM_PFX(BackFromUserCode):
35 call L_Base1 # push eip
37 pushfw # pushfd actually
38 cli # disable interrupts
43 pushaw # pushad actually
44 .byte 0x66, 0xba # mov edx, imm32
45 ASM_PFX(ThunkAttr): .space 4
46 testb $THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15, %dl
48 movl $0x15cd2401, %eax # mov ax, 2401h & int 15h
49 cli # disable interrupts
52 testb $THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL, %dl
56 outb %al, $0x92 # deactivate A20M#
58 xorw %ax, %ax # xor eax, eax
59 movl %ss, %eax # mov ax, ss
60 .byte 0x67, 0x66, 0x8d, 0x6c, 0x24, 0x34, 0x66
61 mov %ebp, 0xffffffd8(%esi)
62 mov 0xfffffff8(%esi), %ebx
63 shlw $4, %ax # shl eax, 4
64 addw %ax, %bp # add ebp, eax
65 .byte 0x66, 0xb8 # mov eax, imm32
68 lgdtw %cs:0xfffffff2(%edi)
69 .byte 0x66, 0xb8 # mov eax, imm32
72 .byte 0xb8 # mov ax, imm16
75 .byte 0x66, 0xbc # mov esp, imm32
78 lret # return to protected mode
80 _EntryPoint: .long ASM_PFX(ToUserCode) - ASM_PFX(m16Start)
84 _16Gdtr: .word GdtEnd - _NullSegDesc - 1
85 _16GdtrBase: .long _NullSegDesc
89 movl %ecx, %ss # set new segment selectors
95 movl %ebp, %cr4 # real mode starts at next instruction
96 movl %esi, %ss # set up 16-bit stack segment
97 xchgw %bx, %sp # set up 16-bit stack pointer
99 call L_Base # push eip
101 popw %bp # ebp <- offset L_Base
102 .byte 0x67; # address size override
109 mov %edx, %cs:0xffffffc5(%esi)
110 mov %bx, %cs:0xffffffcb(%esi)
111 lidtw %cs:0xffffffd7(%esi)
112 popaw # popad actually
118 lretw # transfer control to user code
120 _NullSegDesc: .quad 0
126 .byte 0x8f # 16-bit segment, 4GB limit
133 .byte 0x8f # 16-bit segment, 4GB limit
138 # @param RegSet The pointer to a IA32_DWORD_REGS structure
139 # @param Transition The pointer to the transition code
140 # @return The address of the 16-bit stack after returning from user code
142 ASM_PFX(InternalAsmThunk16):
151 movl 36(%esp), %esi # esi <- RegSet
152 movzwl 0x32(%esi), %edx
154 add $0xffffffc8, %edi
155 movl %edi, %ebx # ebx <- stack offset
156 imul $0x10, %edx, %eax
158 addl %eax, %edi # edi <- linear address of 16-bit stack
162 movl 40(%esp), %eax # eax <- address of transition code
163 movl %edx, %esi # esi <- 16-bit stack segment
170 stosl # [edi] <- return address of user code
171 sgdtl 0xffffff9f(%edx)
174 movl %eax, (%edx) # save CR0 in SavedCr0
175 andl $0x7ffffffe, %eax # clear PE, PG bits
177 mov %ebp, 0xfffffff1(%edx)
178 andl $0x300, %ebp # clear all but PCE and OSFXSR bits
180 pop %ecx # ecx <- selector for data segments
186 lea 0xffffffcc(%ebp), %eax
199 ASM_PFX(m16Size): .word ASM_PFX(InternalAsmThunk16) - ASM_PFX(m16Start)
200 ASM_PFX(mThunk16Attr): .word ASM_PFX(ThunkAttr) - ASM_PFX(m16Start)
201 ASM_PFX(m16Gdt): .word _NullSegDesc - ASM_PFX(m16Start)
202 ASM_PFX(m16GdtrBase): .word _16GdtrBase - ASM_PFX(m16Start)
203 ASM_PFX(mTransition): .word _EntryPoint - ASM_PFX(m16Start)