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