Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 2 | |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 3 | #include <cpu/x86/post_code.h> |
Arthur Heymans | 3edf840 | 2021-07-05 21:18:50 +0200 | [diff] [blame] | 4 | #include <cpu/x86/64bit/entry64.inc> |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 5 | |
Patrick Rudolph | 82e111c | 2021-01-07 14:12:38 +0100 | [diff] [blame] | 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 | |
Kyösti Mälkki | 7522a8f | 2020-11-20 16:47:38 +0200 | [diff] [blame] | 12 | .section .init, "ax", @progbits |
Patrick Rudolph | 82e111c | 2021-01-07 14:12:38 +0100 | [diff] [blame] | 13 | .code32 |
Kyösti Mälkki | 7522a8f | 2020-11-20 16:47:38 +0200 | [diff] [blame] | 14 | |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 15 | .global bootblock_pre_c_entry |
| 16 | bootblock_pre_c_entry: |
| 17 | |
| 18 | cache_as_ram: |
lilacious | 40cb3fe | 2023-06-21 23:24:14 +0200 | [diff] [blame] | 19 | post_code(POSTCODE_BOOTBLOCK_CAR) |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 20 | /* |
| 21 | * Nothing to do here on qemu, RAM works just fine without any |
| 22 | * initialization. |
| 23 | */ |
| 24 | |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 25 | /* Clear the cache memory region. This will also clear CAR GLOBAL */ |
Kyösti Mälkki | a7cac0a | 2019-08-18 08:30:30 +0300 | [diff] [blame] | 26 | movl $_car_region_start, %edi |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 27 | movl $_car_region_end, %ecx |
Kyösti Mälkki | a7cac0a | 2019-08-18 08:30:30 +0300 | [diff] [blame] | 28 | sub %edi, %ecx |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 29 | shr $2, %ecx |
| 30 | xorl %eax, %eax |
| 31 | rep stosl |
| 32 | |
Patrick Rudolph | 82e111c | 2021-01-07 14:12:38 +0100 | [diff] [blame] | 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 | |
Arthur Heymans | df9cdcf | 2019-11-09 06:50:20 +0100 | [diff] [blame] | 76 | movl $_ecar_stack, %esp |
Kyösti Mälkki | a7cac0a | 2019-08-18 08:30:30 +0300 | [diff] [blame] | 77 | |
| 78 | /* Align the stack and keep aligned for call to bootblock_c_entry() */ |
| 79 | and $0xfffffff0, %esp |
Kyösti Mälkki | a7cac0a | 2019-08-18 08:30:30 +0300 | [diff] [blame] | 80 | |
Arthur Heymans | cdea508 | 2024-02-06 15:27:21 +0100 | [diff] [blame] | 81 | #if ENV_X86_64 |
Patrick Rudolph | 82e111c | 2021-01-07 14:12:38 +0100 | [diff] [blame] | 82 | /* entry64.inc preserves ebx. */ |
Arthur Heymans | 3edf840 | 2021-07-05 21:18:50 +0200 | [diff] [blame] | 83 | setup_longmode $(CONFIG_ARCH_X86_64_PGTBL_LOC) |
Patrick Rudolph | dc2f0e3 | 2019-11-15 12:31:18 +0100 | [diff] [blame] | 84 | |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 85 | /* Restore the BIST result and timestamps. */ |
Patrick Rudolph | 98c987a | 2020-07-02 08:08:37 +0200 | [diff] [blame] | 86 | movd %mm2, %rdi |
Patrick Rudolph | 7a04222 | 2020-09-29 13:32:06 +0200 | [diff] [blame] | 87 | shlq $32, %rdi |
Patrick Rudolph | b1ef725 | 2019-09-28 17:44:01 +0200 | [diff] [blame] | 88 | movd %mm1, %rsi |
| 89 | or %rsi, %rdi |
Patrick Rudolph | 98c987a | 2020-07-02 08:08:37 +0200 | [diff] [blame] | 90 | |
| 91 | movd %mm0, %rsi |
Patrick Rudolph | b1ef725 | 2019-09-28 17:44:01 +0200 | [diff] [blame] | 92 | #else |
| 93 | sub $4, %esp |
| 94 | |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 95 | movd %mm0, %ebx |
| 96 | movd %mm1, %eax |
| 97 | movd %mm2, %edx |
| 98 | |
| 99 | pushl %ebx |
| 100 | pushl %edx |
| 101 | pushl %eax |
Patrick Rudolph | b1ef725 | 2019-09-28 17:44:01 +0200 | [diff] [blame] | 102 | #endif |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 103 | |
Jeremy Compostella | b7832de | 2023-08-30 15:42:09 -0700 | [diff] [blame] | 104 | /* Copy .data section content to Cache-As-Ram */ |
| 105 | #include <cpu/x86/copy_data_section.inc> |
| 106 | |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 107 | before_c_entry: |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 108 | call bootblock_c_entry_bist |
| 109 | /* Never returns */ |
| 110 | .Lhlt: |
lilacious | 40cb3fe | 2023-06-21 23:24:14 +0200 | [diff] [blame] | 111 | post_code(POSTCODE_DEAD_CODE) |
Patrick Rudolph | 1af8923 | 2018-11-11 12:50:51 +0100 | [diff] [blame] | 112 | hlt |
| 113 | jmp .Lhlt |
Patrick Rudolph | 82e111c | 2021-01-07 14:12:38 +0100 | [diff] [blame] | 114 | |
| 115 | pagetables_name: |
| 116 | .string "pagetables" |