1 #------------------------------------------------------------------------------
3 # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
8 # This is the code that goes from real-mode to protected mode.
9 # It consumes the reset vector, configures the stack.
11 #------------------------------------------------------------------------------
15 # Contrary to the name, this file contains 16 bit code as well.
18 #----------------------------------------------------------------------------
20 # Procedure: _ModuleEntryPoint
26 # Destroys: Assume all registers
30 # Transition to non-paged flat-model protected mode from a
31 # hard-coded GDT that provides exactly two descriptors.
32 # This is a bare bones transition to protected mode only
33 # used for a while in PEI and possibly DXE.
35 # After enabling protected mode, a far jump is executed to
36 # transfer to PEI using the newly loaded GDT.
40 #----------------------------------------------------------------------------
41 ASM_GLOBAL ASM_PFX(_ModuleEntryPoint)
42 ASM_PFX(_ModuleEntryPoint):
45 # Load the GDT table in GdtDesc
47 .byte 0x66,0xbe #movl $GdtDesc, %esi
50 .byte 0x66,0x2e,0x0f,0x01,0x14 #lgdt %cs:(%si)
53 # Transition to 16 bit protected mode
55 .byte 0x0f,0x20,0xc0 #movl %cr0, %eax # Get control register 0
56 .byte 0x66,0x83,0xc8,0x03 #orl $0x0000003, %eax # Set PE bit (bit #0) & MP bit (bit #1)
57 .byte 0x0f,0x22,0xc0 #movl %eax, %cr0 # Activate protected mode
60 # Now we're in 16 bit protected mode
61 # Set up the selectors for 32 bit protected mode entry
63 .byte 0xb8 #movw SYS_DATA_SEL, %ax
66 .byte 0x8e,0xd8 #movw %ax, %ds
67 .byte 0x8e,0xc0 #movw %ax, %es
68 .byte 0x8e,0xe0 #movw %ax, %fs
69 .byte 0x8e,0xe8 #movw %ax, %gs
70 .byte 0x8e,0xd0 #movw %ax, %ss
73 # Transition to Flat 32 bit protected mode
74 # The jump to a far pointer causes the transition to 32 bit mode
76 .byte 0x66,0xbe #movl ProtectedModeEntryLinearAddress, %esi
77 .long ProtectedModeEntryLinearAddress
78 .byte 0x66,0x2e,0xff,0x2c #jmp %cs:(%esi)
81 # Protected mode portion initializes stack, configures cache, and calls C entry point
84 #----------------------------------------------------------------------------
86 # Procedure: ProtectedModeEntryPoint
88 # Input: Executing in 32 Bit Protected (flat) mode
96 # Output: This function never returns
105 # Perform any essential early platform initilaisation
108 #----------------------------------------------------------------------------
109 ProtectedModeEntryPoint:
111 # Dummy function. Consume 2 API to make sure they can be linked.
113 movl ASM_PFX(TempRamInitApi), %eax
114 movl ASM_PFX(FspInitApi), %eax
116 # Should never return
121 # ROM-based Global-Descriptor Table for the PEI Phase
125 # GDT[0]: 000h: Null entry, never used.
127 .equ NULL_SEL, . - GDT_BASE # Selector [0]
133 # Linear code segment descriptor
135 .equ LINEAR_CODE_SEL, . - GDT_BASE # Selector [08h]
136 .word 0xFFFF # limit 0FFFFh
139 .byte 0x9B # present, ring 0, data, expand-up, not-writable
140 .byte 0xCF # page-granular, 32-bit
143 # System data segment descriptor
145 .equ SYS_DATA_SEL, . - GDT_BASE # Selector [010h]
146 .word 0xFFFF # limit 0FFFFh
149 .byte 0x93 # present, ring 0, data, expand-up, not-writable
150 .byte 0xCF # page-granular, 32-bit
153 .equ GDT_SIZE, . - BootGdtTable # Size, in bytes
158 GdtDesc: # GDT descriptor
162 ProtectedModeEntryLinearAddress:
163 ProtectedModeEntryLinearOffset:
164 .long ProtectedModeEntryPoint
165 .word LINEAR_CODE_SEL