2 ; This is the code that goes from real-mode to protected mode.
3 ; It consumes the reset vector, configures the stack.
5 ; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
6 ; This program and the accompanying materials
7 ; are licensed and made available under the terms and conditions of the BSD License
8 ; which accompanies this distribution. The full text of the license may be found at
9 ; http://opensource.org/licenses/bsd-license.php.
11 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 ; Define assembler characteristics
22 EXTRN TempRamInitApi:NEAR
26 ; Contrary to the name, this file contains 16 bit code as well.
28 _TEXT_REALMODE SEGMENT PARA PUBLIC USE16 'CODE'
29 ASSUME CS:_TEXT_REALMODE, DS:_TEXT_REALMODE
31 ;----------------------------------------------------------------------------
33 ; Procedure: _ModuleEntryPoint
39 ; Destroys: Assume all registers
43 ; Transition to non-paged flat-model protected mode from a
44 ; hard-coded GDT that provides exactly two descriptors.
45 ; This is a bare bones transition to protected mode only
46 ; used for a while in PEI and possibly DXE.
48 ; After enabling protected mode, a far jump is executed to
49 ; transfer to PEI using the newly loaded GDT.
53 ;----------------------------------------------------------------------------
55 _ModuleEntryPoint PROC C PUBLIC
57 ; Load the GDT table in GdtDesc
59 mov esi, OFFSET GdtDesc
61 lgdt fword ptr cs:[si]
64 ; Transition to 16 bit protected mode
66 mov eax, cr0 ; Get control register 0
67 or eax, 00000003h ; Set PE bit (bit #0) & MP bit (bit #1)
68 mov cr0, eax ; Activate protected mode
71 ; Now we're in 16 bit protected mode
72 ; Set up the selectors for 32 bit protected mode entry
82 ; Transition to Flat 32 bit protected mode
83 ; The jump to a far pointer causes the transition to 32 bit mode
85 mov esi, offset ProtectedModeEntryLinearAddress
88 _ModuleEntryPoint ENDP
94 ; Protected mode portion initializes stack, configures cache, and calls C entry point
97 ;----------------------------------------------------------------------------
99 ; Procedure: ProtectedModeEntryPoint
101 ; Input: Executing in 32 Bit Protected (flat) mode
109 ; Output: This function never returns
118 ; Perform any essential early platform initilaisation
121 ;----------------------------------------------------------------------------
123 ProtectedModeEntryPoint PROC NEAR C PUBLIC
125 ; Dummy function. Consume 2 API to make sure they can be linked.
127 mov eax, TempRamInitApi
130 ; Should never return
133 ProtectedModeEntryPoint ENDP
136 ; ROM-based Global-Descriptor Table for the PEI Phase
142 ; GDT[0]: 0x00: Null entry, never used.
144 NULL_SEL equ $ - GDT_BASE ; Selector [0]
149 ; Linear code segment descriptor
151 LINEAR_CODE_SEL equ $ - GDT_BASE ; Selector [0x8]
152 DW 0FFFFh ; limit 0xFFFF
155 DB 09Bh ; present, ring 0, data, expand-up, not-writable
156 DB 0CFh ; page-granular, 32-bit
159 ; System data segment descriptor
161 SYS_DATA_SEL equ $ - GDT_BASE ; Selector [0x10]
162 DW 0FFFFh ; limit 0xFFFF
165 DB 093h ; present, ring 0, data, expand-up, not-writable
166 DB 0CFh ; page-granular, 32-bit
169 GDT_SIZE EQU $ - BootGDTtable ; Size, in bytes
174 GdtDesc: ; GDT descriptor
175 DW GDT_SIZE - 1 ; GDT limit
176 DD OFFSET BootGdtTable ; GDT base address
178 ProtectedModeEntryLinearAddress LABEL FWORD
179 ProtectedModeEntryLinearOffset LABEL DWORD
180 DD OFFSET ProtectedModeEntryPoint ; Offset of our 32 bit code