]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFspPkg/Library/SecFspSecPlatformLibNull/Ia32/Flat32.asm
DynamicTablesPkg: GTDT updates for ACPI 6.3
[mirror_edk2.git] / IntelFspPkg / Library / SecFspSecPlatformLibNull / Ia32 / Flat32.asm
1 ;; @file
2 ; This is the code that goes from real-mode to protected mode.
3 ; It consumes the reset vector, configures the stack.
4 ;
5 ; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
6 ; SPDX-License-Identifier: BSD-2-Clause-Patent
7 ;;
8
9 ;
10 ; Define assembler characteristics
11 ;
12 .586p
13 .xmm
14 .model flat, c
15
16 EXTRN TempRamInitApi:NEAR
17 EXTRN FspInitApi:NEAR
18
19 ;
20 ; Contrary to the name, this file contains 16 bit code as well.
21 ;
22 _TEXT_REALMODE SEGMENT PARA PUBLIC USE16 'CODE'
23 ASSUME CS:_TEXT_REALMODE, DS:_TEXT_REALMODE
24
25 ;----------------------------------------------------------------------------
26 ;
27 ; Procedure: _ModuleEntryPoint
28 ;
29 ; Input: None
30 ;
31 ; Output: None
32 ;
33 ; Destroys: Assume all registers
34 ;
35 ; Description:
36 ;
37 ; Transition to non-paged flat-model protected mode from a
38 ; hard-coded GDT that provides exactly two descriptors.
39 ; This is a bare bones transition to protected mode only
40 ; used for a while in PEI and possibly DXE.
41 ;
42 ; After enabling protected mode, a far jump is executed to
43 ; transfer to PEI using the newly loaded GDT.
44 ;
45 ; Return: None
46 ;
47 ;----------------------------------------------------------------------------
48 align 16
49 _ModuleEntryPoint PROC C PUBLIC
50 ;
51 ; Load the GDT table in GdtDesc
52 ;
53 mov esi, OFFSET GdtDesc
54 db 66h
55 lgdt fword ptr cs:[si]
56
57 ;
58 ; Transition to 16 bit protected mode
59 ;
60 mov eax, cr0 ; Get control register 0
61 or eax, 00000003h ; Set PE bit (bit #0) & MP bit (bit #1)
62 mov cr0, eax ; Activate protected mode
63
64 ;
65 ; Now we're in 16 bit protected mode
66 ; Set up the selectors for 32 bit protected mode entry
67 ;
68 mov ax, SYS_DATA_SEL
69 mov ds, ax
70 mov es, ax
71 mov fs, ax
72 mov gs, ax
73 mov ss, ax
74
75 ;
76 ; Transition to Flat 32 bit protected mode
77 ; The jump to a far pointer causes the transition to 32 bit mode
78 ;
79 mov esi, offset ProtectedModeEntryLinearAddress
80 jmp fword ptr cs:[si]
81
82 _ModuleEntryPoint ENDP
83
84 _TEXT_REALMODE ENDS
85
86 .code
87 ;
88 ; Protected mode portion initializes stack, configures cache, and calls C entry point
89 ;
90
91 ;----------------------------------------------------------------------------
92 ;
93 ; Procedure: ProtectedModeEntryPoint
94 ;
95 ; Input: Executing in 32 Bit Protected (flat) mode
96 ; cs: 0-4GB
97 ; ds: 0-4GB
98 ; es: 0-4GB
99 ; fs: 0-4GB
100 ; gs: 0-4GB
101 ; ss: 0-4GB
102 ;
103 ; Output: This function never returns
104 ;
105 ; Destroys:
106 ; ecx
107 ; edi
108 ; esi
109 ; esp
110 ;
111 ; Description:
112 ; Perform any essential early platform initilaisation
113 ; Setup a stack
114 ;
115 ;----------------------------------------------------------------------------
116
117 ProtectedModeEntryPoint PROC NEAR C PUBLIC
118 ;
119 ; Dummy function. Consume 2 API to make sure they can be linked.
120 ;
121 mov eax, TempRamInitApi
122 mov eax, FspInitApi
123
124 ; Should never return
125 jmp $
126
127 ProtectedModeEntryPoint ENDP
128
129 ;
130 ; ROM-based Global-Descriptor Table for the PEI Phase
131 ;
132 align 16
133 PUBLIC BootGdtTable
134
135 ;
136 ; GDT[0]: 0x00: Null entry, never used.
137 ;
138 NULL_SEL equ $ - GDT_BASE ; Selector [0]
139 GDT_BASE:
140 BootGdtTable DD 0
141 DD 0
142 ;
143 ; Linear code segment descriptor
144 ;
145 LINEAR_CODE_SEL equ $ - GDT_BASE ; Selector [0x8]
146 DW 0FFFFh ; limit 0xFFFF
147 DW 0 ; base 0
148 DB 0
149 DB 09Bh ; present, ring 0, data, expand-up, not-writable
150 DB 0CFh ; page-granular, 32-bit
151 DB 0
152 ;
153 ; System data segment descriptor
154 ;
155 SYS_DATA_SEL equ $ - GDT_BASE ; Selector [0x10]
156 DW 0FFFFh ; limit 0xFFFF
157 DW 0 ; base 0
158 DB 0
159 DB 093h ; present, ring 0, data, expand-up, not-writable
160 DB 0CFh ; page-granular, 32-bit
161 DB 0
162
163 GDT_SIZE EQU $ - BootGDTtable ; Size, in bytes
164
165 ;
166 ; GDT Descriptor
167 ;
168 GdtDesc: ; GDT descriptor
169 DW GDT_SIZE - 1 ; GDT limit
170 DD OFFSET BootGdtTable ; GDT base address
171
172 ProtectedModeEntryLinearAddress LABEL FWORD
173 ProtectedModeEntryLinearOffset LABEL DWORD
174 DD OFFSET ProtectedModeEntryPoint ; Offset of our 32 bit code
175 DW LINEAR_CODE_SEL
176
177 END