1 #*****************************************************************************
3 #* Copyright (c) 2008 - 2010, 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 #*****************************************************************************
27 .globl ASM_PFX(mCode16Size)
30 mCode16Size: .long _Code16End - _Code16Addr
39 .byte 0x8f #16-bit segment
46 .byte 0x8f #16-bit segment
50 .word _16Gdtr - NullSegSel - 1
99 movzwq 0x36(%rsi),%r10 #movzx r10, (IA32_REGS ptr [rsi])._SS
101 mov 0xc(%rsi),%edi #mov edi, (IA32_REGS ptr [rsi])._ESP
102 add $0xffffffffffffffb0,%rdi #add rdi, - sizeof (IA32_REGS) - sizeof (_STK16)
106 pushq $0xe #push sizeof (IA32_REGS) / 4
108 rep movsl %ds:(%rsi),%es:(%rdi)
109 #; copy eflags to stack frame
112 pop %rbx #rbx <- 16-bit stack offset
113 lea Label,%eax #42 <_Thunk16+0x42>
115 movl %cs,%eax #return segment
117 mov %edx,%eax #THUNK Flags
119 sgdt 0x58(%rsp) #save GDTR
122 mov %cr0,%rax #save CR0
123 mov %eax,%esi #esi <- CR0 to set
125 mov %cr4,%rax #save CR4
127 sidt 0x58(%rsp) #save IDTR
128 and $0x7ffffffe,%esi #clear PE & PG bits
129 mov %r10,%rdi #rdi <- 16-bit stack segment
131 push %r8 #far jmp address
135 lgdt _16Gdtr #bugbug: may not match.
139 movl $0xc0000080,%ecx
140 mov %rsi,%cr0 #disable PE & PG
145 and $0xcf,%al #clear PAE & PSE
177 mov %bx,%sp #set up 16-bit stack
182 .word _16Idtr - _Code16Addr #lidt _16Idtr
190 .byte 0x66, 0x9d #popfd
191 add $0x4,%esp #skip high part of RFLAGS
192 .byte 0x67 #; test (_STK16 ptr [esp + STACK_PARAM_SIZE + sizeof(IA32_REGS)]).ThunkFlags, 1
200 pushfq #pushf, actually, when it's INT#
204 .word FarCallRet - _Code16Addr
214 push $0x00 #push a dword of zero
216 pushf #pushfd, actually
224 .byte 0x66 #sizeof (IA32_REGS) = 13 * 4 = 52
225 lgdt 64(%esp) #lgdt (_STK16 ptr [esp + sizeof (IA32_REGS)]).SavedGdtr
230 mov $0xc0000080, %ecx
236 mov %rax, %cr0 #restore CR0
241 .word 0x3ff #FWORD (1 SHL 10) - 1