1 #*****************************************************************************
3 #* Copyright (c) 2008 - 2009, 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 pop %rbx #rbx <- 16-bit stack offset
110 lea Label,%eax #42 <_Thunk16+0x42>
112 movl %cs,%eax #return segment
114 mov %edx,%eax #THUNK Flags
116 sgdt 0x58(%rsp) #save GDTR
119 mov %cr0,%rax #save CR0
120 mov %eax,%esi #esi <- CR0 to set
122 mov %cr4,%rax #save CR4
124 sidt 0x58(%rsp) #save IDTR
125 and $0x7ffffffe,%esi #clear PE & PG bits
126 mov %r10,%rdi #rdi <- 16-bit stack segment
128 push %r8 #far jmp address
132 lgdt _16Gdtr #bugbug: may not match.
136 movl $0xc0000080,%ecx
137 mov %rsi,%cr0 #disable PE & PG
142 and $0xcf,%al #clear PAE & PSE
174 mov %bx,%sp #set up 16-bit stack
179 .word _16Idtr - _Code16Addr #lidt _16Idtr
186 add $0x8,%esp #skip RFLAGS
187 .byte 0x67 #test [esp + 0eh], 1
195 pushfq #pushf, actually
199 .word FarCallRet - _Code16Addr
208 push $0x00 #push a dword of zero
210 pushf #pushfd, actually
218 .byte 0x66 #sizeof (IA32_REGS) = 13 * 4 = 52
219 lgdt 64(%esp) #lgdt (_STK16 ptr [esp + sizeof (IA32_REGS)]).SavedGdtr
224 mov $0xc0000080, %ecx
230 mov %rax, %cr0 #restore CR0
235 .word 0x3ff #FWORD (1 SHL 10) - 1