1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cpu/intel/post_codes.h>
4 #include <cpu/x86/mtrr.h>
5 #include <cpu/x86/cache.h>
6 #include <cpu/x86/post_code.h>
9 .global bootblock_pre_c_entry
14 bootblock_pre_c_entry:
17 post_code(POSTCODE_BOOTBLOCK_CAR)
19 /* Clear/disable fixed MTRRs */
20 mov $fixed_mtrr_list_size, %ebx
26 movzwl fixed_mtrr_list(%ebx), %ecx
30 /* Figure out how many MTRRs we have, and clear them out */
31 mov $MTRR_CAP_MSR, %ecx
33 movzb %al, %ebx /* Number of variable MTRRs */
34 mov $MTRR_PHYS_BASE(0), %ecx
45 post_code(POSTCODE_SOC_SET_DEF_MTRR_TYPE)
47 /* Configure the default memory type to uncacheable. */
48 movl $MTRR_DEF_TYPE_MSR, %ecx
50 andl $(~0x00000cff), %eax
53 post_code(POSTCODE_SOC_DETERMINE_CPU_ADDR_BITS)
55 /* Determine CPU_ADDR_BITS and load PHYSMASK high word to %edx. */
58 andl $(1 << 6 | 1 << 17), %edx /* PAE or PSE36 */
62 /* Preload high word of address mask (in %edx) for Variable
66 movl $MTRR_PHYS_MASK(0), %ecx
68 movl $MTRR_PHYS_MASK(1), %ecx
71 post_code(POSTCODE_SOC_SET_CAR_BASE)
73 /* Set Cache-as-RAM base address. */
74 movl $(MTRR_PHYS_BASE(0)), %ecx
75 movl $_car_mtrr_start, %eax
76 orl $MTRR_TYPE_WRBACK, %eax
80 /* Set Cache-as-RAM mask. */
81 movl $(MTRR_PHYS_MASK(0)), %ecx
83 movl $_car_mtrr_mask, %eax
84 orl $MTRR_PHYS_MASK_VALID, %eax
87 post_code(POSTCODE_SOC_ENABLE_MTRRS)
90 movl $MTRR_DEF_TYPE_MSR, %ecx
92 orl $MTRR_DEF_TYPE_EN, %eax
95 post_code(POSTCODE_SOC_ENABLE_CACHE)
97 /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
99 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
103 /* Read then clear the CAR region. This will also fill up the cache.
104 * IMPORTANT: The read is mandatory.
107 movl $_car_mtrr_start, %edi
108 movl $_car_mtrr_size, %ecx
117 post_code(POSTCODE_SOC_DISABLE_CACHE)
118 /* Enable Cache-as-RAM mode by disabling cache. */
120 orl $CR0_CacheDisable, %eax
123 /* Enable cache for our code in Flash because we do XIP here */
124 movl $MTRR_PHYS_BASE(1), %ecx
127 andl $_xip_mtrr_mask, %eax
128 orl $MTRR_TYPE_WRPROT, %eax
130 movl $MTRR_PHYS_MASK(1), %ecx
132 movl $_xip_mtrr_mask, %eax
133 orl $MTRR_PHYS_MASK_VALID, %eax
136 post_code(POSTCODE_SOC_FILL_CACHE)
139 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
142 /* Setup the stack. */
143 mov $_ecar_stack, %esp
145 /* Need to align stack to 16 bytes at call instruction. Account for
147 andl $0xfffffff0, %esp
150 /* push TSC and BIST to stack */
152 pushl %eax /* BIST */
154 pushl %eax /* tsc[63:32] */
156 pushl %eax /* tsc[31:0] */
158 /* Copy .data section content to Cache-As-Ram */
159 #include <cpu/x86/copy_data_section.inc>
162 post_code(POSTCODE_BOOTBLOCK_BEFORE_C_ENTRY)
163 call bootblock_c_entry_bist
165 /* Should never see this postcode */
166 post_code(POSTCODE_DEAD_CODE)
173 .word MTRR_FIX_64K_00000
174 .word MTRR_FIX_16K_80000
175 .word MTRR_FIX_16K_A0000
176 .word MTRR_FIX_4K_C0000
177 .word MTRR_FIX_4K_C8000
178 .word MTRR_FIX_4K_D0000
179 .word MTRR_FIX_4K_D8000
180 .word MTRR_FIX_4K_E0000
181 .word MTRR_FIX_4K_E8000
182 .word MTRR_FIX_4K_F0000
183 .word MTRR_FIX_4K_F8000
184 fixed_mtrr_list_size = . - fixed_mtrr_list
186 _cache_as_ram_setup_end: