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