| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
|
| 3 |
#include <cpu/x86/post_code.h> |
| 4 |
#include <cpu/x86/64bit/entry64.inc> |
| 5 |
|
| 6 |
#define CBFS_FILE_MAGIC 0 |
| 7 |
#define CBFS_FILE_LEN (CBFS_FILE_MAGIC + 8) |
| 8 |
#define CBFS_FILE_TYPE (CBFS_FILE_LEN + 4) |
| 9 |
#define CBFS_FILE_CHECKSUM (CBFS_FILE_TYPE + 4) |
| 10 |
#define CBFS_FILE_OFFSET (CBFS_FILE_CHECKSUM + 4) |
| 11 |
|
| 12 |
.section .init, "ax", @progbits |
| 13 |
.code32 |
| 14 |
|
| 15 |
.global bootblock_pre_c_entry |
| 16 |
bootblock_pre_c_entry: |
| 17 |
|
| 18 |
cache_as_ram: |
| 19 |
post_code(POSTCODE_BOOTBLOCK_CAR) |
| 20 |
/* |
| 21 |
* Nothing to do here on qemu, RAM works just fine without any |
| 22 |
* initialization. |
| 23 |
*/ |
| 24 |
|
| 25 |
/* Clear the cache memory region. This will also clear CAR GLOBAL */ |
| 26 |
movl $_car_region_start, %edi |
| 27 |
movl $_car_region_end, %ecx |
| 28 |
sub %edi, %ecx |
| 29 |
shr $2, %ecx |
| 30 |
xorl %eax, %eax |
| 31 |
rep stosl |
| 32 |
|
| 33 |
#if defined(__x86_64__) |
| 34 |
/* |
| 35 |
* Copy page tables to final location in DRAM. This prevents some strange |
| 36 |
* bugs when running KVM enabled: |
| 37 |
* Accessing MMX instructions in long mode causes an abort |
| 38 |
* Some physical addresses aren't properly translated |
| 39 |
* Emulation fault on every instruction fetched due to page tables in ROM |
| 40 |
* Enabling or disabling paging causes a fault |
| 41 |
* |
| 42 |
* First, find page tables in CBFS: |
| 43 |
*/ |
| 44 |
lea pagetables_name, %esi |
| 45 |
mov $1f, %esp |
| 46 |
jmp walkcbfs_asm |
| 47 |
1: |
| 48 |
cmpl $0, %eax |
| 49 |
je .Lhlt |
| 50 |
|
| 51 |
/* Test if page tables are memory-mapped and skip relocation */ |
| 52 |
cmpl $(CONFIG_ARCH_X86_64_PGTBL_LOC), %eax |
| 53 |
je pages_done |
| 54 |
|
| 55 |
movl CBFS_FILE_OFFSET(%eax), %ebx |
| 56 |
bswap %ebx |
| 57 |
addl %eax, %ebx |
| 58 |
movl %ebx, %esi |
| 59 |
|
| 60 |
movl CBFS_FILE_LEN(%eax), %ecx |
| 61 |
bswap %ecx |
| 62 |
shr $2, %ecx |
| 63 |
|
| 64 |
movl $(CONFIG_ARCH_X86_64_PGTBL_LOC), %edi |
| 65 |
|
| 66 |
loop: |
| 67 |
movl (%esi), %eax |
| 68 |
movl %eax, (%edi) |
| 69 |
addl $4, %esi |
| 70 |
addl $4, %edi |
| 71 |
decl %ecx |
| 72 |
jnz loop |
| 73 |
pages_done: |
| 74 |
#endif |
| 75 |
|
| 76 |
movl $_ecar_stack, %esp |
| 77 |
|
| 78 |
/* Align the stack and keep aligned for call to bootblock_c_entry() */ |
| 79 |
and $0xfffffff0, %esp |
| 80 |
|
| 81 |
#if ENV_X86_64 |
| 82 |
/* entry64.inc preserves ebx. */ |
| 83 |
setup_longmode $(CONFIG_ARCH_X86_64_PGTBL_LOC) |
| 84 |
|
| 85 |
/* Restore the BIST result and timestamps. */ |
| 86 |
movd %mm2, %rdi |
| 87 |
shlq $32, %rdi |
| 88 |
movd %mm1, %rsi |
| 89 |
or %rsi, %rdi |
| 90 |
|
| 91 |
movd %mm0, %rsi |
| 92 |
#else |
| 93 |
sub $4, %esp |
| 94 |
|
| 95 |
movd %mm0, %ebx |
| 96 |
movd %mm1, %eax |
| 97 |
movd %mm2, %edx |
| 98 |
|
| 99 |
pushl %ebx |
| 100 |
pushl %edx |
| 101 |
pushl %eax |
| 102 |
#endif |
| 103 |
|
| 104 |
/* Copy .data section content to Cache-As-Ram */ |
| 105 |
#include <cpu/x86/copy_data_section.inc> |
| 106 |
|
| 107 |
before_c_entry: |
| 108 |
call bootblock_c_entry_bist |
| 109 |
/* Never returns */ |
| 110 |
.Lhlt: |
| 111 |
post_code(POSTCODE_DEAD_CODE) |
| 112 |
hlt |
| 113 |
jmp .Lhlt |
| 114 |
|
| 115 |
pagetables_name: |
| 116 |
.string "pagetables" |