1 #------------------------------------------------------------------------------
3 #* Copyright (c) 2006, Intel Corporation
4 #* All rights reserved. This program and the accompanying materials
5 #* are licensed and made available under the terms and conditions of the BSD License
6 #* which accompanies this distribution. The full text of the license may be found at
7 #* http://opensource.org/licenses/bsd-license.php
9 #* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 #* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #* Transition from 32-bit protected mode EFI environment into x64
17 #* 64-bit bit long mode.
19 #* This file is not fully ported or operational.
21 #------------------------------------------------------------------------------
27 # Create the exception handler code in IA32 C code
45 # Reload the selectors
47 # Make the Selectors 64-bit ready
49 movl gdtr, %edi # Load GDT register
50 movw %cs, %ax # Get the selector data from our code image
52 # FIXME MISMATCH: " lgdt FWORD PTR es:[edi] "
55 .byte 0xea # Far Jump Offset:Selector to reload CS
56 # FIXME MISMATCH: " dd OFFSET DataSelectorRld"
57 # FIXME MISMATCH: " dw LINEAR_CODE_SEL "
59 movw SYS_DATA_SEL, %ax # Update the Base for the new selectors, too
74 # IN EFI_PHYSICAL_ADDRESS PageTables,
75 # IN EFI_PHYSICAL_ADDRESS HobStart,
76 # IN EFI_PHYSICAL_ADDRESS Stack,
77 # IN EFI_PHYSICAL_ADDRESS PpisNeededByDxeIplEntryPoint,
78 # IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint
81 # Input: [ebp][0h] = Original ebp
82 # [ebp][4h] = Return address
83 # [ebp][8h] = PageTables
84 # [ebp][10h] = HobStart
86 # [ebp][20h] = CodeEntryPoint1 <--- Call this first (for each call, pass HOB pointer)
87 # [ebp][28h] = CodeEntryPoint2 <--- Call this second
90 .global _ActivateLongMode;
96 # Use CPUID to determine if the processor supports long mode.
98 movl $0x80000000, %eax # Extended-function code 8000000h.
99 cpuid # Is largest extended function
100 cmpl $0x80000000, %eax # any function > 80000000h?
101 jbe no_long_mode # If not, no long mode.
102 movl $0x80000001, %eax # Extended-function code 8000001h.
103 cpuid # Now EDX = extended-features flags.
104 btl $29, %edx # Test if long mode is supported.
105 jnc no_long_mode # Exit if not supported.
108 # Enable the 64-bit page-translation-table entries by
109 # setting CR4.PAE=1 (this is _required_ before activating
110 # long mode). Paging is not enabled until after long mode
118 # Get the long-mode page tables, and initialize the
119 # 64-bit CR3 (page-table base address) to point to the base
120 # of the PML4 page table. The PML4 page table must be located
121 # below 4 Gbytes because only 32 bits of CR3 are loaded when
122 # the processor is not in 64-bit mode.
124 movl 0x8(%ebp), %eax # Get Page Tables
125 movl %eax, %cr3 # Initialize CR3 with PML4 base.
128 # Enable long mode (set EFER.LME=1).
130 movl $0xc0000080, %ecx # EFER MSR number.
132 btsl $8, %eax # Set LME=1.
136 # Enable paging to activate long mode (set CR0.PG=1)
140 movl %cr0, %eax # Read CR0.
141 btsl $31, %eax # Set PG=1.
142 movl %eax, %cr0 # Write CR0.
147 # This is the next instruction after enabling paging. Jump to long mode
150 .byte 0xea # Far Jump Offset:Selector to reload CS
151 #FIXME MISMATCH: " dd OFFSET in_long_mode"
152 #FIXME MISMATCH: " dw SYS_CODE64_SEL "
154 movw SYS_DATA64_SEL, %ax
162 # We're in long mode, so marshall the arguments to call the
163 # passed in function pointers
165 # [ebp][10h] = HobStart
167 # [ebp][20h] = PpisNeededByDxeIplEntryPoint <--- Call this first (for each call, pass HOB pointer)
168 # [ebp][28h] = DxeCoreEntryPoint <--- Call this second
171 movl 0x18(%ebp), %ebx # Setup the stack
173 movl %ebx, %esp # On a new stack now
176 ## 00000905 FF D0 call rax
179 movl 0x10(%ebp), %ecx # Pass Hob Start in RCX
181 movl 0x28(%ebp), %eax # Get the function pointer for
182 # DxeCoreEntryPoint into EAX
184 ## 00000905 FF D0 call rax
189 # WE SHOULD NEVER GET HERE!!!!!!!!!!!!!
193 #_ActivateLongMode ENDP
197 gdtr: #FIXME MISMATCH: "gdtr dw _GDT_END - _GDT_BASE - 1 "
198 #FIXME MISMATCH: " dd OFFSET _GDT_BASE "
200 #-----------------------------------------------------------------------------;
201 # global descriptor table (GDT)
202 #-----------------------------------------------------------------------------;
209 .equ NULL_SEL, .-_GDT_BASE # Selector [0]
214 .byte 0 # limit 19:16, flags
217 # linear data segment descriptor
218 .equ LINEAR_SEL, .-_GDT_BASE # Selector [0x8]
219 .word 0xFFFF # limit 0xFFFFF
222 .byte 0x92 # present, ring 0, data, expand-up, writable
223 .byte 0xCF # page-granular, 32-bit
226 # linear code segment descriptor
227 .equ LINEAR_CODE_SEL, .-_GDT_BASE # Selector [0x10]
228 .word 0xFFFF # limit 0xFFFFF
231 .byte 0x9F # present, ring 0, data, expand-up, writable
232 .byte 0xCF # page-granular, 32-bit
235 # system data segment descriptor
236 .equ SYS_DATA_SEL, .-_GDT_BASE # Selector [0x18]
237 .word 0xFFFF # limit 0xFFFFF
240 .byte 0x93 # present, ring 0, data, expand-up, writable
241 .byte 0xCF # page-granular, 32-bit
244 # system code segment descriptor
245 .equ SYS_CODE_SEL, .-_GDT_BASE # Selector [0x20]
246 .word 0xFFFF # limit 0xFFFFF
249 .byte 0x9A # present, ring 0, data, expand-up, writable
250 .byte 0xCF # page-granular, 32-bit
253 # spare segment descriptor
254 .equ SPARE3_SEL, .-_GDT_BASE # Selector [0x28]
255 .word 0 # limit 0xFFFFF
258 .byte 0 # present, ring 0, data, expand-up, writable
259 .byte 0 # page-granular, 32-bit
263 # system data segment descriptor
265 .equ SYS_DATA64_SEL, .-_GDT_BASE # Selector [0x30]
266 .word 0xFFFF # limit 0xFFFFF
269 .byte 0x92 # P | DPL [1..2] | 1 | 1 | C | R | A
270 .byte 0xCF # G | D | L | AVL | Segment [19..16]
274 # system code segment descriptor
276 .equ SYS_CODE64_SEL, .-_GDT_BASE # Selector [0x38]
277 .word 0xFFFF # limit 0xFFFFF
280 .byte 0x9A # P | DPL [1..2] | 1 | 1 | C | R | A
281 .byte 0xAF # G | D | L | AVL | Segment [19..16]
284 # spare segment descriptor
285 .equ SPARE4_SEL, .-_GDT_BASE # Selector [0x40]
286 .word 0 # limit 0xFFFFF
289 .byte 0 # present, ring 0, data, expand-up, writable
290 .byte 0 # page-granular, 32-bit