Debian Codegraph @

src/cpu/via/car/cache_as_ram.S

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <cpu/x86/mtrr.h>
4 #include <cpu/x86/cache.h>
5 #include <cpu/x86/post_code.h>
6
7 .section .init
8 .global bootblock_pre_c_entry
9
10 .code32
11 _cache_as_ram_setup:
12
13 bootblock_pre_c_entry:
14
15 cache_as_ram:
16 post_code(POSTCODE_BOOTBLOCK_CAR)
17
18 /* Disable cache. */
19 movl %cr0, %eax
20 orl $CR0_CacheDisable, %eax
21 movl %eax, %cr0
22 invd
23
24 /* Set the default memory type and enable fixed and variable MTRRs. */
25 movl $MTRR_DEF_TYPE_MSR, %ecx
26 xorl %edx, %edx
27 movl $(MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN), %eax
28 wrmsr
29
30 /* Clear all MTRRs. */
31 xorl %edx, %edx
32 movl $all_mtrr_msrs, %esi
33
34 clear_fixed_var_mtrr:
35 lodsl (%esi), %eax
36 testl %eax, %eax
37 jz clear_fixed_var_mtrr_out
38
39 movl %eax, %ecx
40 xorl %eax, %eax
41 wrmsr
42
43 jmp clear_fixed_var_mtrr
44
45 all_mtrr_msrs:
46 /* fixed MTRR MSRs */
47 .long MTRR_FIX_64K_00000
48 .long MTRR_FIX_16K_80000
49 .long MTRR_FIX_16K_A0000
50 .long MTRR_FIX_4K_C0000
51 .long MTRR_FIX_4K_C8000
52 .long MTRR_FIX_4K_D0000
53 .long MTRR_FIX_4K_D8000
54 .long MTRR_FIX_4K_E0000
55 .long MTRR_FIX_4K_E8000
56 .long MTRR_FIX_4K_F0000
57 .long MTRR_FIX_4K_F8000
58
59 /* var MTRR MSRs */
60 .long MTRR_PHYS_BASE(0)
61 .long MTRR_PHYS_MASK(0)
62 .long MTRR_PHYS_BASE(1)
63 .long MTRR_PHYS_MASK(1)
64 .long MTRR_PHYS_BASE(2)
65 .long MTRR_PHYS_MASK(2)
66 .long MTRR_PHYS_BASE(3)
67 .long MTRR_PHYS_MASK(3)
68 .long MTRR_PHYS_BASE(4)
69 .long MTRR_PHYS_MASK(4)
70 .long MTRR_PHYS_BASE(5)
71 .long MTRR_PHYS_MASK(5)
72 .long MTRR_PHYS_BASE(6)
73 .long MTRR_PHYS_MASK(6)
74 .long MTRR_PHYS_BASE(7)
75 .long MTRR_PHYS_MASK(7)
76
77 .long 0x000 /* NULL, end of table */
78
79 clear_fixed_var_mtrr_out:
80 movl $MTRR_PHYS_BASE(0), %ecx
81 xorl %edx, %edx
82 movl $_car_mtrr_start, %eax
83 orl $MTRR_TYPE_WRBACK, %eax
84 wrmsr
85
86 movl $MTRR_PHYS_MASK(0), %ecx
87 /* This assumes we never access addresses above 2^36 in CAR. */
88 movl $0x0000000f, %edx
89 movl $_car_mtrr_mask, %eax
90 orl $MTRR_PHYS_MASK_VALID, %eax
91 wrmsr
92
93 /*
94 * Enable write base caching so we can do execute in place (XIP)
95 * on the flash ROM.
96 */
97 movl $MTRR_PHYS_BASE(1), %ecx
98 xorl %edx, %edx
99 movl $_program, %eax
100 andl $_xip_mtrr_mask, %eax
101 orl $MTRR_TYPE_WRBACK, %eax
102 wrmsr
103
104 movl $MTRR_PHYS_MASK(1), %ecx
105 movl $0x0000000f, %edx
106 movl $_xip_mtrr_mask, %eax
107 orl $MTRR_PHYS_MASK_VALID, %eax
108 wrmsr
109
110 /* Set the default memory type and enable variable MTRRs. */
111 movl $MTRR_DEF_TYPE_MSR, %ecx
112 xorl %edx, %edx
113 movl $(MTRR_DEF_TYPE_EN), %eax
114 wrmsr
115
116 /* Enable cache. */
117 movl %cr0, %eax
118 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
119 movl %eax, %cr0
120
121 /* Read the range with lodsl. */
122 cld
123 movl $_car_mtrr_start, %esi
124 movl %esi, %edi
125 movl $_car_mtrr_size, %ecx
126 shr $2, %ecx
127 movl %ecx, %ebx
128 rep lodsl
129
130 /* Zero out the cache-as-ram area. */
131 movl %ebx, %ecx
132 xorl %eax, %eax
133 rep stosl
134
135 /*
136 * The key point of this CAR code is C7 cache does not turn into
137 * "no fill" mode, which is not compatible with general CAR code.
138 */
139
140 /* Setup the stack. */
141 mov $_ecar_stack, %esp
142
143 /* Need to align stack to 16 bytes at call instruction. Account for
144 the pushes below. */
145 andl $0xfffffff0, %esp
146 subl $4, %esp
147
148 /* push TSC and BIST to stack */
149 movd %mm0, %eax
150 pushl %eax /* BIST */
151 movd %mm2, %eax
152 pushl %eax /* tsc[63:32] */
153 movd %mm1, %eax
154 pushl %eax /* tsc[31:0] */
155
156 /* Copy .data section content to Cache-As-Ram */
157 #include <cpu/x86/copy_data_section.inc>
158
159 before_c_entry:
160 call bootblock_c_entry_bist
161
162 /* Should never see this postcode */
163 post_code(POSTCODE_DEAD_CODE)
164
165 .Lhlt:
166 hlt
167 jmp .Lhlt