1 #------------------------------------------------------------------------------
3 # Copyright (c) 2006 - 2008, 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#
59 .byte 0x67, 0x66, 0x8d, 0x6c, 0x24, 0x34, 0x66
60 mov %ebp, 0xffffffd8(%esi)
61 mov 0xfffffff8(%esi), %ebx
62 shlw $4, %ax # shl eax, 4
63 addw %ax, %bp # add ebp, eax
64 .byte 0x66, 0xb8 # mov eax, imm32
67 lgdtw %cs:0xfffffff2(%edi)
68 .byte 0x66, 0xb8 # mov eax, imm32
71 .byte 0xb8 # mov ax, imm16
74 .byte 0x66, 0xbc # mov esp, imm32
77 lret # return to protected mode
79 _EntryPoint: .long ASM_PFX(ToUserCode) - ASM_PFX(m16Start)
83 _16Gdtr: .word GdtEnd - _NullSegDesc - 1
84 _16GdtrBase: .long _NullSegDesc
88 movl %ecx, %ss # set new segment selectors
94 movl %ebp, %cr4 # real mode starts at next instruction
95 movl %esi, %ss # set up 16-bit stack segment
96 xchgw %bx, %sp # set up 16-bit stack pointer
98 call L_Base # push eip
100 popw %bp # ebp <- offset L_Base
101 .byte 0x67; # address size override
108 mov %edx, %cs:0xffffffc5(%esi)
109 mov %bx, %cs:0xffffffcb(%esi)
110 lidtw %cs:0xffffffd7(%esi)
111 popaw # popad actually
117 lretw # transfer control to user code
119 _NullSegDesc: .quad 0
125 .byte 0x8f # 16-bit segment, 4GB limit
132 .byte 0x8f # 16-bit segment, 4GB limit
137 # @param RegSet The pointer to a IA32_DWORD_REGS structure
138 # @param Transition The pointer to the transition code
139 # @return The address of the 16-bit stack after returning from user code
141 ASM_PFX(InternalAsmThunk16):
150 movl 36(%esp), %esi # esi <- RegSet
151 movzwl 0x32(%esi), %edx
153 add $0xffffffc8, %edi
154 movl %edi, %ebx # ebx <- stack offset
155 imul $0x10, %edx, %eax
157 addl %eax, %edi # edi <- linear address of 16-bit stack
161 movl 40(%esp), %eax # eax <- address of transition code
162 movl %edx, %esi # esi <- 16-bit stack segment
169 stosl # [edi] <- return address of user code
170 sgdtl 0xffffffa2(%edx)
173 movl %eax, (%edx) # save CR0 in SavedCr0
174 andl $0x7ffffffe, %eax # clear PE, PG bits
176 mov %ebp, 0xfffffff1(%edx)
177 andl $0x300, %ebp # clear all but PCE and OSFXSR bits
179 pop %ecx # ecx <- selector for data segments
185 lea 0xffffffcc(%ebp), %eax
198 ASM_PFX(m16Size): .word ASM_PFX(InternalAsmThunk16) - ASM_PFX(m16Start)
199 ASM_PFX(mThunk16Attr): .word ASM_PFX(ThunkAttr) - ASM_PFX(m16Start)
200 ASM_PFX(m16Gdt): .word _NullSegDesc - ASM_PFX(m16Start)
201 ASM_PFX(m16GdtrBase): .word _16GdtrBase - ASM_PFX(m16Start)
202 ASM_PFX(mTransition): .word _EntryPoint - ASM_PFX(m16Start)