blob: f828d6f31ab0e3bf271c77de137ff88ee21827a3 [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:
18 post_code(0x20)
19 /*
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
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030032 post_code(0x21)
33
Patrick Rudolph82e111c2021-01-07 14:12:38 +010034#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
481:
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
67loop:
68 movl (%esi), %eax
69 movl %eax, (%edi)
70 addl $4, %esi
71 addl $4, %edi
72 decl %ecx
73 jnz loop
74pages_done:
75#endif
76
Arthur Heymansdf9cdcf2019-11-09 06:50:20 +010077 movl $_ecar_stack, %esp
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030078
79 /* Align the stack and keep aligned for call to bootblock_c_entry() */
80 and $0xfffffff0, %esp
Kyösti Mälkkia7cac0a2019-08-18 08:30:30 +030081
Patrick Rudolph82e111c2021-01-07 14:12:38 +010082 /* entry64.inc preserves ebx. */
Patrick Rudolphdc2f0e32019-11-15 12:31:18 +010083#include <cpu/x86/64bit/entry64.inc>
84
Patrick Rudolph1af89232018-11-11 12:50:51 +010085 /* Restore the BIST result and timestamps. */
Patrick Rudolphadcf7822020-08-27 20:50:18 +020086#if ENV_X86_64
Patrick Rudolph98c987a2020-07-02 08:08:37 +020087 movd %mm2, %rdi
Patrick Rudolph7a042222020-09-29 13:32:06 +020088 shlq $32, %rdi
Patrick Rudolphb1ef7252019-09-28 17:44:01 +020089 movd %mm1, %rsi
90 or %rsi, %rdi
Patrick Rudolph98c987a2020-07-02 08:08:37 +020091
92 movd %mm0, %rsi
Patrick Rudolphb1ef7252019-09-28 17:44:01 +020093#else
94 sub $4, %esp
95
Patrick Rudolph1af89232018-11-11 12:50:51 +010096 movd %mm0, %ebx
97 movd %mm1, %eax
98 movd %mm2, %edx
99
100 pushl %ebx
101 pushl %edx
102 pushl %eax
Patrick Rudolphb1ef7252019-09-28 17:44:01 +0200103#endif
Patrick Rudolph1af89232018-11-11 12:50:51 +0100104
105before_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 Rudolph82e111c2021-01-07 14:12:38 +0100113
114pagetables_name:
115 .string "pagetables"