1 #------------------------------------------------------------------------------
3 # Copyright (c) 2015, 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.
14 # This is the code that goes from real-mode to protected mode.
15 # It consumes the reset vector, configures the stack.
17 #------------------------------------------------------------------------------
21 # Contrary to the name, this file contains 16 bit code as well.
24 #----------------------------------------------------------------------------
26 # Procedure: _ModuleEntryPoint
32 # Destroys: Assume all registers
36 # Transition to non-paged flat-model protected mode from a
37 # hard-coded GDT that provides exactly two descriptors.
38 # This is a bare bones transition to protected mode only
39 # used for a while in PEI and possibly DXE.
41 # After enabling protected mode, a far jump is executed to
42 # transfer to PEI using the newly loaded GDT.
46 #----------------------------------------------------------------------------
47 ASM_GLOBAL ASM_PFX(_ModuleEntryPoint)
48 ASM_PFX(_ModuleEntryPoint):
51 # Load the GDT table in GdtDesc
53 .byte 0x66,0xbe #movl $GdtDesc, %esi
56 .byte 0x66,0x2e,0x0f,0x01,0x14 #lgdt %cs:(%si)
59 # Transition to 16 bit protected mode
61 .byte 0x0f,0x20,0xc0 #movl %cr0, %eax # Get control register 0
62 .byte 0x66,0x83,0xc8,0x03 #orl $0x0000003, %eax # Set PE bit (bit #0) & MP bit (bit #1)
63 .byte 0x0f,0x22,0xc0 #movl %eax, %cr0 # Activate protected mode
66 # Now we're in 16 bit protected mode
67 # Set up the selectors for 32 bit protected mode entry
69 .byte 0xb8 #movw SYS_DATA_SEL, %ax
72 .byte 0x8e,0xd8 #movw %ax, %ds
73 .byte 0x8e,0xc0 #movw %ax, %es
74 .byte 0x8e,0xe0 #movw %ax, %fs
75 .byte 0x8e,0xe8 #movw %ax, %gs
76 .byte 0x8e,0xd0 #movw %ax, %ss
79 # Transition to Flat 32 bit protected mode
80 # The jump to a far pointer causes the transition to 32 bit mode
82 .byte 0x66,0xbe #movl ProtectedModeEntryLinearAddress, %esi
83 .long ProtectedModeEntryLinearAddress
84 .byte 0x66,0x2e,0xff,0x2c #jmp %cs:(%esi)
87 # Protected mode portion initializes stack, configures cache, and calls C entry point
90 #----------------------------------------------------------------------------
92 # Procedure: ProtectedModeEntryPoint
94 # Input: Executing in 32 Bit Protected (flat) mode
102 # Output: This function never returns
111 # Perform any essential early platform initilaisation
114 #----------------------------------------------------------------------------
115 ProtectedModeEntryPoint:
117 # Dummy function. Consume 2 API to make sure they can be linked.
119 movl ASM_PFX(TempRamInitApi), %eax
120 movl ASM_PFX(FspInitApi), %eax
122 # Should never return
127 # ROM-based Global-Descriptor Table for the PEI Phase
131 # GDT[0]: 000h: Null entry, never used.
133 .equ NULL_SEL, . - GDT_BASE # Selector [0]
139 # Linear code segment descriptor
141 .equ LINEAR_CODE_SEL, . - GDT_BASE # Selector [08h]
142 .word 0xFFFF # limit 0FFFFh
145 .byte 0x9B # present, ring 0, data, expand-up, not-writable
146 .byte 0xCF # page-granular, 32-bit
149 # System data segment descriptor
151 .equ SYS_DATA_SEL, . - GDT_BASE # Selector [010h]
152 .word 0xFFFF # limit 0FFFFh
155 .byte 0x93 # present, ring 0, data, expand-up, not-writable
156 .byte 0xCF # page-granular, 32-bit
159 .equ GDT_SIZE, . - BootGdtTable # Size, in bytes
164 GdtDesc: # GDT descriptor
168 ProtectedModeEntryLinearAddress:
169 ProtectedModeEntryLinearOffset:
170 .long ProtectedModeEntryPoint
171 .word LINEAR_CODE_SEL