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