blob: e2662c2945e4a6e9f16fee6171644806604e6417 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Rudolph1af89232018-11-11 12:50:51 +01002
Patrick Rudolph1af89232018-11-11 12:50:51 +01003#include <cpu/x86/post_code.h>
Arthur Heymans3edf8402021-07-05 21:18:50 +02004#include <cpu/x86/64bit/entry64.inc>
Patrick Rudolph1af89232018-11-11 12:50:51 +01005
Patrick Rudolph82e111c2021-01-07 14:12:38 +01006#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älkki7522a8f2020-11-20 16:47:38 +020012.section .init, "ax", @progbits
Patrick Rudolph82e111c2021-01-07 14:12:38 +010013.code32
Kyösti Mälkki7522a8f2020-11-20 16:47:38 +020014
Patrick Rudolph1af89232018-11-11 12:50:51 +010015.global bootblock_pre_c_entry
16bootblock_pre_c_entry:
17
18cache_as_ram:
lilacious40cb3fe2023-06-21 23:24:14 +020019 post_code(POSTCODE_BOOTBLOCK_CAR)
Patrick Rudolph1af89232018-11-11 12:50:51 +010020 /*
21 * Nothing to do here on qemu, RAM works just fine without any
22 * initialization.
23 */
24
Patrick Rudolph1af89232018-11-11 12:50:51 +010025 /* Clear the cache memory region. This will also clear CAR GLOBAL */
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030026 movl $_car_region_start, %edi
Patrick Rudolph1af89232018-11-11 12:50:51 +010027 movl $_car_region_end, %ecx
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030028 sub %edi, %ecx
Patrick Rudolph1af89232018-11-11 12:50:51 +010029 shr $2, %ecx
30 xorl %eax, %eax
31 rep stosl
32
Patrick Rudolph82e111c2021-01-07 14:12:38 +010033#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
471:
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
66loop:
67 movl (%esi), %eax
68 movl %eax, (%edi)
69 addl $4, %esi
70 addl $4, %edi
71 decl %ecx
72 jnz loop
73pages_done:
74#endif
75
Arthur Heymansdf9cdcf2019-11-09 06:50:20 +010076 movl $_ecar_stack, %esp
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030077
78 /* Align the stack and keep aligned for call to bootblock_c_entry() */
79 and $0xfffffff0, %esp
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030080
Arthur Heymanscdea5082024-02-06 15:27:21 +010081#if ENV_X86_64
Patrick Rudolph82e111c2021-01-07 14:12:38 +010082 /* entry64.inc preserves ebx. */
Arthur Heymans3edf8402021-07-05 21:18:50 +020083 setup_longmode $(CONFIG_ARCH_X86_64_PGTBL_LOC)
Patrick Rudolphdc2f0e32019-11-15 12:31:18 +010084
Patrick Rudolph1af89232018-11-11 12:50:51 +010085 /* Restore the BIST result and timestamps. */
Patrick Rudolph98c987a2020-07-02 08:08:37 +020086 movd %mm2, %rdi
Patrick Rudolph7a042222020-09-29 13:32:06 +020087 shlq $32, %rdi
Patrick Rudolphb1ef7252019-09-28 17:44:01 +020088 movd %mm1, %rsi
89 or %rsi, %rdi
Patrick Rudolph98c987a2020-07-02 08:08:37 +020090
91 movd %mm0, %rsi
Patrick Rudolphb1ef7252019-09-28 17:44:01 +020092#else
93 sub $4, %esp
94
Patrick Rudolph1af89232018-11-11 12:50:51 +010095 movd %mm0, %ebx
96 movd %mm1, %eax
97 movd %mm2, %edx
98
99 pushl %ebx
100 pushl %edx
101 pushl %eax
Patrick Rudolphb1ef7252019-09-28 17:44:01 +0200102#endif
Patrick Rudolph1af89232018-11-11 12:50:51 +0100103
Jeremy Compostellab7832de2023-08-30 15:42:09 -0700104 /* Copy .data section content to Cache-As-Ram */
105#include <cpu/x86/copy_data_section.inc>
106
Patrick Rudolph1af89232018-11-11 12:50:51 +0100107before_c_entry:
Patrick Rudolph1af89232018-11-11 12:50:51 +0100108 call bootblock_c_entry_bist
109 /* Never returns */
110.Lhlt:
lilacious40cb3fe2023-06-21 23:24:14 +0200111 post_code(POSTCODE_DEAD_CODE)
Patrick Rudolph1af89232018-11-11 12:50:51 +0100112 hlt
113 jmp .Lhlt
Patrick Rudolph82e111c2021-01-07 14:12:38 +0100114
115pagetables_name:
116 .string "pagetables"