| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
|
| 3 |
/* |
| 4 |
* For starting coreboot in long mode. |
| 5 |
* |
| 6 |
* For reference see "AMD64 ArchitectureProgrammer's Manual Volume 2", |
| 7 |
* Document 24593-Rev. 3.31-July 2019 Chapter 5.3 |
| 8 |
* |
| 9 |
* Clobbers: eax, ecx, edx |
| 10 |
*/ |
| 11 |
|
| 12 |
#if ENV_X86_64 |
| 13 |
.code32 |
| 14 |
#if CONFIG(PAGE_TABLES_IN_CBFS) |
| 15 |
#if (CONFIG_ARCH_X86_64_PGTBL_LOC & 0xfff) > 0 |
| 16 |
#error pagetables must be 4KiB aligned! |
| 17 |
#endif |
| 18 |
#endif |
| 19 |
|
| 20 |
#include <cpu/x86/gdt.h> |
| 21 |
#include <cpu/x86/msr.h> |
| 22 |
|
| 23 |
.macro setup_longmode page_table |
| 24 |
/* Get page table address */ |
| 25 |
movl \page_table, %eax |
| 26 |
|
| 27 |
/* load identity mapped page tables */ |
| 28 |
movl %eax, %cr3 |
| 29 |
|
| 30 |
/* enable PAE */ |
| 31 |
movl %cr4, %eax |
| 32 |
btsl $5, %eax |
| 33 |
movl %eax, %cr4 |
| 34 |
|
| 35 |
/* enable long mode */ |
| 36 |
movl $(IA32_EFER), %ecx |
| 37 |
rdmsr |
| 38 |
btsl $8, %eax |
| 39 |
wrmsr |
| 40 |
|
| 41 |
/* enable paging */ |
| 42 |
movl %cr0, %eax |
| 43 |
btsl $31, %eax |
| 44 |
movl %eax, %cr0 |
| 45 |
|
| 46 |
/* use long jump to switch to 64-bit code segment */ |
| 47 |
ljmp $GDT_CODE_SEG64, $jmp_addr\@ |
| 48 |
|
| 49 |
.code64 |
| 50 |
jmp_addr\@: |
| 51 |
.endm |
| 52 |
|
| 53 |
#endif |