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