1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2006, Intel Corporation
4 ; All rights reserved. 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 ;------------------------------------------------------------------------------
28 _16BitCsSel LABEL QWORD
33 DB 8fh ; 16-bit segment
35 _16BitDsSel LABEL QWORD
40 DB 8fh ; 16-bit segment
47 DW offset GdtEnd - offset NullSegSel - 1
50 _16Idtr FWORD (1 SHL 10) - 1
73 InternalAsmThunk16 PROC USES ebp ebx esi edi ds es fs gs
74 mov esi, [esp + 36] ; esi <- RegSet
75 push sizeof (IA32_REGS)
77 movzx edx, (IA32_REGS ptr [esi])._SS
78 mov edi, (IA32_REGS ptr [esi])._ESP
79 sub edi, ecx ; reserve space on realmode stack
80 push edi ; save stack offset
81 imul eax, edx, 16 ; eax <- edx * 16
82 add edi, eax ; edi <- linear address of 16-bit stack
83 rep movsb ; copy RegSet
84 mov esi, edx ; esi <- 16-bit stack segment
85 pop ebx ; ebx <- 16-bit stack offset
86 mov edi, [esp + 40] ; edi <- realmode patch
87 push cs ; save CS segment selector
88 push offset @BackToThunk ; offset to back from real mode
89 mov eax, offset @16Return
92 stosw ; set CS base to 0
98 mov ecx, eax ; ecx <- CR0
99 and ecx, 7ffffffeh ; clear PE, PG bits
103 and ebp, 300h ; clear all but PCE and OSFXSR bits
105 sidt fword ptr [esp + 44] ; use parameter space to save IDTR
114 @16Start: ; 16-bit starts here
115 mov ss, eax ; set SS to be a 16-bit segment
118 mov ss, esi ; set up 16-bit stack
119 mov sp, bx ; mov esp, ebx actually
120 popaw ; popad actually
125 add sp, 4 ; skip _EFLAGS
127 retf ; transfer control to 16-bit code
129 pushf ; pushfd actually
134 pushaw ; pushad actually
136 lds esi, fword ptr (IA32_REGS ptr [esp])._EIP
139 mov cr4, eax ; restore CR4
141 lgdt fword ptr [esi + 16]
144 mov cr0, eax ; restore CR0
145 xor ax, ax ; xor eax, eax actually
148 mov dword ptr (IA32_REGS ptr [esp])._SS, eax
149 shl ax, 4 ; shl eax, 4 actually
150 add ax, sp ; add eax, esp actually
151 add sp, sizeof (IA32_REGS) ; add esp, sizeof (IA32_REGS)
153 mov dword ptr (IA32_REGS ptr [esp - sizeof (IA32_REGS)])._ESP, esp
155 lss esp, fword ptr [esi] ; restore protected mode stack
157 retf ; go back to protected mode
159 lidt fword ptr [esp + 36] ; restore protected mode IDTR
161 InternalAsmThunk16 ENDP