]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFspPkg/Library/SecFspSecPlatformLibNull/Ia32/Flat32.s
IntelFspPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFspPkg / Library / SecFspSecPlatformLibNull / Ia32 / Flat32.s
1 #------------------------------------------------------------------------------
2 #
3 # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
4 # SPDX-License-Identifier: BSD-2-Clause-Patent
5 #
6 # Abstract:
7 #
8 # This is the code that goes from real-mode to protected mode.
9 # It consumes the reset vector, configures the stack.
10 #
11 #------------------------------------------------------------------------------
12
13
14 #
15 # Contrary to the name, this file contains 16 bit code as well.
16 #
17 .text
18 #----------------------------------------------------------------------------
19 #
20 # Procedure: _ModuleEntryPoint
21 #
22 # Input: None
23 #
24 # Output: None
25 #
26 # Destroys: Assume all registers
27 #
28 # Description:
29 #
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.
34 #
35 # After enabling protected mode, a far jump is executed to
36 # transfer to PEI using the newly loaded GDT.
37 #
38 # Return: None
39 #
40 #----------------------------------------------------------------------------
41 ASM_GLOBAL ASM_PFX(_ModuleEntryPoint)
42 ASM_PFX(_ModuleEntryPoint):
43
44 #
45 # Load the GDT table in GdtDesc
46 #
47 .byte 0x66,0xbe #movl $GdtDesc, %esi
48 .long GdtDesc
49
50 .byte 0x66,0x2e,0x0f,0x01,0x14 #lgdt %cs:(%si)
51
52 #
53 # Transition to 16 bit protected mode
54 #
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
58
59 #
60 # Now we're in 16 bit protected mode
61 # Set up the selectors for 32 bit protected mode entry
62 #
63 .byte 0xb8 #movw SYS_DATA_SEL, %ax
64 .word SYS_DATA_SEL
65
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
71
72 #
73 # Transition to Flat 32 bit protected mode
74 # The jump to a far pointer causes the transition to 32 bit mode
75 #
76 .byte 0x66,0xbe #movl ProtectedModeEntryLinearAddress, %esi
77 .long ProtectedModeEntryLinearAddress
78 .byte 0x66,0x2e,0xff,0x2c #jmp %cs:(%esi)
79
80 #
81 # Protected mode portion initializes stack, configures cache, and calls C entry point
82 #
83
84 #----------------------------------------------------------------------------
85 #
86 # Procedure: ProtectedModeEntryPoint
87 #
88 # Input: Executing in 32 Bit Protected (flat) mode
89 # cs: 0-4GB
90 # ds: 0-4GB
91 # es: 0-4GB
92 # fs: 0-4GB
93 # gs: 0-4GB
94 # ss: 0-4GB
95 #
96 # Output: This function never returns
97 #
98 # Destroys:
99 # ecx
100 # edi
101 # esi
102 # esp
103 #
104 # Description:
105 # Perform any essential early platform initilaisation
106 # Setup a stack
107 #
108 #----------------------------------------------------------------------------
109 ProtectedModeEntryPoint:
110 #
111 # Dummy function. Consume 2 API to make sure they can be linked.
112 #
113 movl ASM_PFX(TempRamInitApi), %eax
114 movl ASM_PFX(FspInitApi), %eax
115 #
116 # Should never return
117 #
118 jmp . #'$'
119
120 #
121 # ROM-based Global-Descriptor Table for the PEI Phase
122 #
123 .align 16
124 #
125 # GDT[0]: 000h: Null entry, never used.
126 #
127 .equ NULL_SEL, . - GDT_BASE # Selector [0]
128 GDT_BASE:
129 BootGdtTable:
130 .long 0
131 .long 0
132 #
133 # Linear code segment descriptor
134 #
135 .equ LINEAR_CODE_SEL, . - GDT_BASE # Selector [08h]
136 .word 0xFFFF # limit 0FFFFh
137 .word 0 # base 0
138 .byte 0
139 .byte 0x9B # present, ring 0, data, expand-up, not-writable
140 .byte 0xCF # page-granular, 32-bit
141 .byte 0
142 #
143 # System data segment descriptor
144 #
145 .equ SYS_DATA_SEL, . - GDT_BASE # Selector [010h]
146 .word 0xFFFF # limit 0FFFFh
147 .word 0 # base 0
148 .byte 0
149 .byte 0x93 # present, ring 0, data, expand-up, not-writable
150 .byte 0xCF # page-granular, 32-bit
151 .byte 0
152
153 .equ GDT_SIZE, . - BootGdtTable # Size, in bytes
154
155 #
156 # GDT Descriptor
157 #
158 GdtDesc: # GDT descriptor
159 .word GDT_SIZE - 1
160 .long BootGdtTable
161
162 ProtectedModeEntryLinearAddress:
163 ProtectedModeEntryLinearOffset:
164 .long ProtectedModeEntryPoint
165 .word LINEAR_CODE_SEL