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