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