blob: fe872debea16b68e842fa31cdd89381d6390c1b4 [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>
4
Patrick Rudolph82e111c2021-01-07 14:12:38 +01005#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älkki7522a8f2020-11-20 16:47:38 +020011.section .init, "ax", @progbits
Patrick Rudolph82e111c2021-01-07 14:12:38 +010012.code32
Kyösti Mälkki7522a8f2020-11-20 16:47:38 +020013
Patrick Rudolph1af89232018-11-11 12:50:51 +010014.global bootblock_pre_c_entry
15bootblock_pre_c_entry:
16
17cache_as_ram:
lilacious40cb3fe2023-06-21 23:24:14 +020018 post_code(POSTCODE_BOOTBLOCK_CAR)
Patrick Rudolph1af89232018-11-11 12:50:51 +010019 /*
20 * Nothing to do here on qemu, RAM works just fine without any
21 * initialization.
22 */
23
Patrick Rudolph1af89232018-11-11 12:50:51 +010024 /* Clear the cache memory region. This will also clear CAR GLOBAL */
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030025 movl $_car_region_start, %edi
Patrick Rudolph1af89232018-11-11 12:50:51 +010026 movl $_car_region_end, %ecx
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030027 sub %edi, %ecx
Patrick Rudolph1af89232018-11-11 12:50:51 +010028 shr $2, %ecx
29 xorl %eax, %eax
30 rep stosl
31
Patrick Rudolph82e111c2021-01-07 14:12:38 +010032#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
461:
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
65loop:
66 movl (%esi), %eax
67 movl %eax, (%edi)
68 addl $4, %esi
69 addl $4, %edi
70 decl %ecx
71 jnz loop
72pages_done:
73#endif
74
Arthur Heymansdf9cdcf2019-11-09 06:50:20 +010075 movl $_ecar_stack, %esp
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030076
77 /* Align the stack and keep aligned for call to bootblock_c_entry() */
78 and $0xfffffff0, %esp
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030079
Patrick Rudolph82e111c2021-01-07 14:12:38 +010080 /* entry64.inc preserves ebx. */
Patrick Rudolphdc2f0e32019-11-15 12:31:18 +010081#include <cpu/x86/64bit/entry64.inc>
82
Patrick Rudolph1af89232018-11-11 12:50:51 +010083 /* Restore the BIST result and timestamps. */
Patrick Rudolphadcf7822020-08-27 20:50:18 +020084#if ENV_X86_64
Patrick Rudolph98c987a2020-07-02 08:08:37 +020085 movd %mm2, %rdi
Patrick Rudolph7a042222020-09-29 13:32:06 +020086 shlq $32, %rdi
Patrick Rudolphb1ef7252019-09-28 17:44:01 +020087 movd %mm1, %rsi
88 or %rsi, %rdi
Patrick Rudolph98c987a2020-07-02 08:08:37 +020089
90 movd %mm0, %rsi
Patrick Rudolphb1ef7252019-09-28 17:44:01 +020091#else
92 sub $4, %esp
93
Patrick Rudolph1af89232018-11-11 12:50:51 +010094 movd %mm0, %ebx
95 movd %mm1, %eax
96 movd %mm2, %edx
97
98 pushl %ebx
99 pushl %edx
100 pushl %eax
Patrick Rudolphb1ef7252019-09-28 17:44:01 +0200101#endif
Patrick Rudolph1af89232018-11-11 12:50:51 +0100102
103before_c_entry:
Patrick Rudolph1af89232018-11-11 12:50:51 +0100104 call bootblock_c_entry_bist
105 /* Never returns */
106.Lhlt:
lilacious40cb3fe2023-06-21 23:24:14 +0200107 post_code(POSTCODE_DEAD_CODE)
Patrick Rudolph1af89232018-11-11 12:50:51 +0100108 hlt
109 jmp .Lhlt
Patrick Rudolph82e111c2021-01-07 14:12:38 +0100110
111pagetables_name:
112 .string "pagetables"