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