blob: 95dd74d6cb29813454717238b08f58edb1f3ef23 [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/*
2 * Copyright (c) 2011, Advanced Micro Devices, Inc.
3 * All rights reserved.
zbaoafd141d2012-03-30 15:32:07 +08004 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +00005 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
zbaoafd141d2012-03-30 15:32:07 +080012 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
13 * its contributors may be used to endorse or promote products derived
Frank Vibrans2b4c8312011-02-14 18:30:54 +000014 * from this software without specific prior written permission.
zbaoafd141d2012-03-30 15:32:07 +080015 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
zbaoafd141d2012-03-30 15:32:07 +080026 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000027 */
zbaoafd141d2012-03-30 15:32:07 +080028
Frank Vibrans2b4c8312011-02-14 18:30:54 +000029/******************************************************************************
30* AMD Generic Encapsulated Software Architecture
31*
32* $Workfile:: GccCar.inc $Revision:: 32932 $
33*
34* Description: GccCar.inc - AGESA cache-as-RAM setup Include File for GCC complier
35*
36******************************************************************************/
37
38.altmacro
39
zbao39256222012-04-05 13:20:50 +080040BSP_STACK_BASE_ADDR = 0x30000 /* Base address for primary cores stack */
41BSP_STACK_SIZE = 0x10000 /* 64KB for BSP core */
42CORE0_STACK_BASE_ADDR = 0x80000 /* Base address for primary cores stack */
43CORE0_STACK_SIZE = 0x4000 /* 16KB for primary cores */
44CORE1_STACK_BASE_ADDR = 0x40000 /* Base address for AP cores */
Kyösti Mälkkiacd139852017-07-13 22:48:22 +030045
Stefan Reinauerf8532b12015-07-21 14:37:13 -070046#ifdef __x86_64__
47CORE1_STACK_SIZE = 0x2000 /* 8KB for each AP cores */
48#else
zbao39256222012-04-05 13:20:50 +080049CORE1_STACK_SIZE = 0x1000 /* 4KB for each AP cores */
Stefan Reinauerf8532b12015-07-21 14:37:13 -070050#endif
zbao39256222012-04-05 13:20:50 +080051
52APIC_BASE_ADDRESS = 0x0000001B
53 APIC_BSC = 8 /* Boot Strap Core */
54
55AMD_MTRR_VARIABLE_BASE0 = 0x0200
56AMD_MTRR_VARIABLE_BASE6 = 0x020C
57AMD_MTRR_FIX64k_00000 = 0x0250
58AMD_MTRR_FIX16k_80000 = 0x0258
59AMD_MTRR_FIX16k_A0000 = 0x0259
60AMD_MTRR_FIX4k_C0000 = 0x0268
61AMD_MTRR_FIX4k_C8000 = 0x0269
62AMD_MTRR_FIX4k_D0000 = 0x026A
63AMD_MTRR_FIX4k_D8000 = 0x026B
64AMD_MTRR_FIX4k_E0000 = 0x026C
65AMD_MTRR_FIX4k_E8000 = 0x026D
66AMD_MTRR_FIX4k_F0000 = 0x026E
67AMD_MTRR_FIX4k_F8000 = 0x026F
68
69/* Reproduced from AGESA.h */
70AMD_AP_MTRR_FIX64k_00000 = 0x00000250
71AMD_AP_MTRR_FIX16k_80000 = 0x00000258
72AMD_AP_MTRR_FIX16k_A0000 = 0x00000259
73AMD_AP_MTRR_FIX4k_C0000 = 0x00000268
74AMD_AP_MTRR_FIX4k_C8000 = 0x00000269
75AMD_AP_MTRR_FIX4k_D0000 = 0x0000026A
76AMD_AP_MTRR_FIX4k_D8000 = 0x0000026B
77AMD_AP_MTRR_FIX4k_E0000 = 0x0000026C
78AMD_AP_MTRR_FIX4k_E8000 = 0x0000026D
79AMD_AP_MTRR_FIX4k_F0000 = 0x0000026E
80AMD_AP_MTRR_FIX4k_F8000 = 0x0000026F
81CPU_LIST_TERMINAL = 0xFFFFFFFF
82
83AMD_MTRR_DEFTYPE = 0x02FF
84 WB_DRAM_TYPE = 0x1E /* MemType - memory type */
85 MTRR_DEF_TYPE_EN = 11 /* MtrrDefTypeEn - variable and fixed MTRRs default enabled */
86 MTRR_DEF_TYPE_FIX_EN = 10 /* MtrrDefTypeEn - fixed MTRRs default enabled */
87
88HWCR = 0x0C0010015 /* Hardware Configuration */
89 INVD_WBINVD = 0x04 /* INVD to WBINVD conversion */
90
91IORR_BASE = 0x0C0010016 /* IO Range Regusters Base/Mask, 2 pairs */
92 /* uses 16h - 19h */
93TOP_MEM = 0x0C001001A /* Top of Memory */
94TOP_MEM2 = 0x0C001001D /* Top of Memory2 */
95
96LS_CFG = 0x0C0011020 /* Load-Store Configuration */
97 DIS_SS = 28 /* Family 10h,12h,15h:Disable Streng Store functionality */
98 DIS_STREAM_ST = 28 /* Family 14h:DisStreamSt - Disable Streaming Store functionality */
99
100IC_CFG = 0x0C0011021 /* Instruction Cache Config Register */
101 IC_DIS_SPEC_TLB_RLD = 9 /* Disable speculative TLB reloads */
102 DIS_IND = 14 /* Family 10-14h:Disable Indirect Branch Predictor */
103 DIS_I_CACHE = 14 /* Family 15h:DisICache - Disable Indirect Branch Predictor */
104
105DC_CFG = 0x0C0011022 /* Data Cache Configuration */
106 DC_DIS_SPEC_TLB_RLD = 4 /* Disable speculative TLB reloads */
107 DIS_CLR_WBTOL2_SMC_HIT = 8 /* self modifying code check buffer bit */
108 DIS_HW_PF = 13 /* Hardware prefetches bit */
109
110DE_CFG = 0x0C0011029 /* Decode Configuration */
111 CL_FLUSH_SERIALIZE = 23 /* Family 12h,15h: CL Flush Serialization */
112
113BU_CFG2 = 0x0C001102A /* Family 10h: Bus Unit Configuration 2 */
114CU_CFG2 = 0x0C001102A /* Family 15h: Combined Unit Configuration 2 */
115 F10_CL_LINES_TO_NB_DIS = 15 /* ClLinesToNbDis - allows WP code to be cached in L2 */
116 IC_DIS_SPEC_TLB_WR = 35 /* IcDisSpecTlbWr - ITLB speculative writes */
117
118CU_CFG3 = 0x0C001102B /* Combined Unit Configuration 3 */
119 COMBINE_CR0_CD = 49 /* Combine CR0.CD for both cores of a compute unit */
120
121
Konstantin Aladyshevc2f2bd02013-03-06 22:13:42 +0400122CR0_PE = 0 # Protection Enable
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000123CR0_NW = 29 # Not Write-through
124CR0_CD = 30 # Cache Disable
125CR0_PG = 31 # Paging Enable
zbao39256222012-04-05 13:20:50 +0800126
127/* CPUID Functions */
128
129CPUID_MODEL = 1
130AMD_CPUID_FMF = 0x80000001 /* Family Model Features information */
131AMD_CPUID_APIC = 0x80000008 /* Long Mode and APIC info., core count */
132
133NB_CFG = 0x0C001001F /* Northbridge Configuration Register */
134 INIT_APIC_ID_CPU_ID_LO = 54 /* InitApicIdCpuIdLo - is core# in high or low half of APIC ID? */
135
136MTRR_SYS_CFG = 0x0C0010010 /* System Configuration Register */
137 CHX_TO_DIRTY_DIS = 16 /* ChxToDirtyDis Change to dirty disable */
138 SYS_UC_LOCK_EN = 17 /* SysUcLockEn System lock command enable */
139 MTRR_FIX_DRAM_EN = 18 /* MtrrFixDramEn MTRR fixed RdDram and WrDram attributes enable */
140 MTRR_FIX_DRAM_MOD_EN = 19 /* MtrrFixDramModEn MTRR fixed RdDram and WrDram modification enable */
141 MTRR_VAR_DRAM_EN = 20 /* MtrrVarDramEn MTRR variable DRAM enable */
142 MTRR_TOM2_EN = 21 /* MtrrTom2En MTRR top of memory 2 enable */
143
144PERF_CONTROL3 = 0x0C0010003 /* Performance event control three */
145 PERF_CONTROL3_RESERVE_L = 0x00200000 /* Preserve the reserved bits */
146 PERF_CONTROL3_RESERVE_H = 0x0FCF0 /* Preserve the reserved bits */
147 CONFIG_EVENT_L = 0x0F0E2 /* All cores with level detection */
148 CONFIG_EVENT_H = 4 /* Increment count by number of event */
149 /* occured in clock cycle */
150 EVENT_ENABLE = 22 /* Enable the event */
151PERF_COUNTER3 = 0x0C0010007 /* Performance event counter three */
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000152
153# Local use flags, in upper most byte if ESI
154FLAG_UNKNOWN_FAMILY = 24 # Signals that the family# of the installed processor is not recognized
155FLAG_STACK_REENTRY = 25 # Signals that the environment has made a re-entry (2nd) call to set up the stack
156FLAG_IS_PRIMARY = 26 # Signals that this core is the primary within the comoute unit
157
158CR0_MASK = ((1 << CR0_CD) | (1 << CR0_NW))
159MSR_MASK = ((1 << MTRR_DEF_TYPE_EN)+(1 << MTRR_DEF_TYPE_FIX_EN))
160
161/****************************************************************************
162 *
163 * CPU MACROS - PUBLIC
164 *
165 ****************************************************************************/
zbaoafd141d2012-03-30 15:32:07 +0800166.macro _WRMSR
167 .byte 0x0f, 0x30
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000168.endm
169
zbaoafd141d2012-03-30 15:32:07 +0800170.macro _RDMSR
171 .byte 0x0F, 0x32
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000172.endm
173
174.macro AMD_CPUID arg0
zbaoafd141d2012-03-30 15:32:07 +0800175 .ifb \arg0
176 mov $0x1, %eax
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000177 .byte 0x0F, 0x0A2 /* Execute instruction */
zbaoafd141d2012-03-30 15:32:07 +0800178 bswap %eax
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000179 xchg %ah, %al /* Ext model in al now */
180 rol $0x08, %eax /* Ext model in ah, model in al */
181 and $0x0FFCF, ax /* Keep 23:16, 7:6, 3:0 */
182 .else
zbaoafd141d2012-03-30 15:32:07 +0800183 mov \arg0, %eax
184 .byte 0x0F, 0x0A2
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000185 .endif
186.endm
zbaoafd141d2012-03-30 15:32:07 +0800187
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000188/****************************************************************************
189*
190* AMD_ENABLE_STACK_FAMILY_HOOK Macro - Stackless
191*
192* Set any family specific controls needed to enable the use of
193* cache as general storage before main memory is available.
194*
195* Inputs:
196* none
197* Outputs:
198* none
199 ****************************************************************************/
200.macro AMD_ENABLE_STACK_FAMILY_HOOK
201
zbaoafd141d2012-03-30 15:32:07 +0800202 AMD_ENABLE_STACK_FAMILY_HOOK_F10
203 AMD_ENABLE_STACK_FAMILY_HOOK_F12
204 AMD_ENABLE_STACK_FAMILY_HOOK_F14
205 AMD_ENABLE_STACK_FAMILY_HOOK_F15
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000206.endm
zbaoafd141d2012-03-30 15:32:07 +0800207
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000208/****************************************************************************
209*
210* AMD_DISABLE_STACK_FAMILY_HOOK Macro - Stackless
211*
212* Return any family specific controls to their 'standard'
213* settings for using cache with main memory.
214*
215* Inputs:
216* none
217* Outputs:
218* none
219 ****************************************************************************/
220.macro AMD_DISABLE_STACK_FAMILY_HOOK
221
222 AMD_DISABLE_STACK_FAMILY_HOOK_F10
223 AMD_DISABLE_STACK_FAMILY_HOOK_F12
224 AMD_DISABLE_STACK_FAMILY_HOOK_F14
225 AMD_DISABLE_STACK_FAMILY_HOOK_F15
226
227.endm
zbaoafd141d2012-03-30 15:32:07 +0800228
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000229/****************************************************************************
230*
231* GET_NODE_ID_CORE_ID Macro - Stackless
232*
233* Read family specific values to determine the node and core
234* numbers for the core executing this code.
235*
236* Inputs:
237* none
238* Outputs:
239* SI[7:0] = Core# (0..N, relative to node)
240* SI[15:8]= Node# (0..N)
241* SI[23:16]= reserved
242* SI[24]= flag: 1=Family Unrecognized
243* SI[25]= flag: 1=Interface re-entry call
244* SI[26]= flag: 1=Core is primary of compute unit
245* SI[31:27]= reserved, =0
246****************************************************************************/
247.macro GET_NODE_ID_CORE_ID
248 LOCAL node_core_exit
249
250 mov $-1, %si
251 GET_NODE_ID_CORE_ID_F10
252 GET_NODE_ID_CORE_ID_F12
253 GET_NODE_ID_CORE_ID_F14
254 GET_NODE_ID_CORE_ID_F15
255 /*
256 * Check for unrecognized Family
257 */
258 cmp $-1, %si # Has family (node/core) already been discovered?
259 jnz node_core_exit # Br if yes
zbaoafd141d2012-03-30 15:32:07 +0800260
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000261 mov $((1 << FLAG_UNKNOWN_FAMILY)+(1 << FLAG_IS_PRIMARY)), %esi # No, Set error code, Only let BSP continue
zbaoafd141d2012-03-30 15:32:07 +0800262
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000263 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
264 _RDMSR
265 bt $APIC_BSC, %eax # Is this the BSC?
266 jc node_core_exit # Br if yes
267 hlt # Kill APs
268node_core_exit:
269
270.endm
zbaoafd141d2012-03-30 15:32:07 +0800271
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000272/****************************************************************************
273## Family 10h MACROS
274##***************************************************************************
275#---------------------------------------------------
276#
277# AMD_ENABLE_STACK_FAMILY_HOOK_F10 Macro - Stackless
278#
279# Set any family specific controls needed to enable the use of
280# cache as general storage before main memory is available.
281#
282# Inputs:
283# ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
284# Outputs:
285# none
286#
287# Family 10h requirements (BKDG section 2.3.3):
288# * Paging disabled
289# * MSRC001_0015[INVDWBINVD]=0
290# * MSRC001_1021[DIS_IND]=1
291# * MSRC001_1021[DIS_SPEC_TLB_RLD]=1
292# * MSRC001_1022[DIS_SPEC_TLB_RLD]=1
293# * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=1
294# * MSRC001_1022[DIS_HW_PF]=1
295# * MSRC001_102A[IcDisSpecTlbWr]=1
296# * MSRC001_102A[ClLinesToNbDis]=1
297# * No INVD or WBINVD, no exceptions, page faults or interrupts
298****************************************************************************/
zbaoafd141d2012-03-30 15:32:07 +0800299.macro AMD_ENABLE_STACK_FAMILY_HOOK_F10
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000300 LOCAL fam10_enable_stack_hook_exit
301
302 AMD_CPUID $CPUID_MODEL
303 shr $20, %eax # AL = cpu extended family
304 cmp $0x01, %al # Is this family 10h?
305 jnz fam10_enable_stack_hook_exit # Br if no
306
307 mov $DC_CFG, %ecx # MSR:C001_1022
308 _RDMSR
309 bts $DC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative DTLB reloads bit
310 bts $DIS_CLR_WBTOL2_SMC_HIT, %eax # Turn on Disable the self modifying code check buffer bit
311 bts $DIS_HW_PF, %eax # Turn on Disable hardware prefetches bit
312 _WRMSR
313
314 dec %cx # MSR:C001_1021
315 _RDMSR
316 bts $IC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative TLB reloads bit
317 bts $DIS_IND, %eax # Turn on Disable indirect branch predictor
318 _WRMSR
319
320 mov $BU_CFG2, %ecx # MSR C001_102A
321 _RDMSR
322 bts $F10_CL_LINES_TO_NB_DIS, %eax # Allow BIOS ROM to be cached in the IC
323 bts $(IC_DIS_SPEC_TLB_WR-32), %edx #Disable speculative writes to the ITLB
324 _WRMSR
325
326 mov $HWCR, %ecx # MSR C001_0015
327 _RDMSR
328 bt $FLAG_STACK_REENTRY, %esi # Check if stack has already been set
329 jc fam10_skipClearingBit4
330 btr $INVD_WBINVD, %eax # disable INVD -> WBINVD conversion
331 _WRMSR
zbaoafd141d2012-03-30 15:32:07 +0800332
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000333fam10_skipClearingBit4:
334 mov %esi, %eax # load core#
335 or %al, %al # If (BSP)
336 jne fam10_enable_stack_hook_exit
337 mov $PERF_COUNTER3, %ecx # Select performance counter three
338 # to count number of CAR evictions
339 xor %eax, %eax # Initialize the lower part of the counter to zero
340 xor %edx, %edx # Initializa the upper part of the counter to zero
341 _WRMSR # Save it
342 mov $PERF_CONTROL3, %ecx # Select the event control three
343 _RDMSR # Get the current setting
344 and $PERF_CONTROL3_RESERVE_L, %eax # Preserve the reserved bits
345 or $CONFIG_EVENT_L, %eax # Set the lower part of event register to
346 # select CAR Corruption occurred by any cores
347 and $PERF_CONTROL3_RESERVE_H, %dx # Preserve the reserved bits
348 or $CONFIG_EVENT_H, %dx # Set the upper part of event register
349 _WRMSR # Save it
350 bts $EVENT_ENABLE, %eax # Enable it
351 _WRMSR # Save it
352
353fam10_enable_stack_hook_exit:
354.endm
zbaoafd141d2012-03-30 15:32:07 +0800355
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000356/****************************************************************************
357*
358* AMD_DISABLE_STACK_FAMILY_HOOK_F10 Macro - Stackless
359*
360* Return any family specific controls to their 'standard'
361* settings for using cache with main memory.
362*
363* Inputs:
364* ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
365* Outputs:
366* none
367*
368* Family 10h requirements:
369* * INVD or WBINVD
370* * MSRC001_0015[INVD_WBINVD]=1
371* * MSRC001_1021[DIS_IND]=0
372* * MSRC001_1021[DIS_SPEC_TLB_RLD]=0
373* * MSRC001_1022[DIS_SPEC_TLB_RLD]=0
374* * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=0
375* * MSRC001_1022[DIS_HW_PF]=0
376* * MSRC001_102A[IcDisSpecTlbWr]=0
377* * MSRC001_102A[ClLinesToNbDis]=0
378*****************************************************************************/
zbaoafd141d2012-03-30 15:32:07 +0800379
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000380.macro AMD_DISABLE_STACK_FAMILY_HOOK_F10
381 LOCAL fam10_disable_stack_hook_exit
382
Damien Zammit9e818872014-11-19 00:20:08 +1100383 AMD_CPUID $CPUID_MODEL
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000384 shr $20, %eax # AL = cpu extended family
385 cmp $0x01, %al # Is this family 10h?
386 jnz fam10_disable_stack_hook_exit # Br if no
387
388 mov $DC_CFG, %ecx # MSR:C001_1022
389 _RDMSR
390 btr $DC_DIS_SPEC_TLB_RLD, %eax # Enable speculative TLB reloads
391 btr $DIS_CLR_WBTOL2_SMC_HIT, %eax # Allow self modifying code check buffer
392 btr $DIS_HW_PF, %eax # Allow hardware prefetches
393 _WRMSR
394
395 dec %cx # MSR:C001_1021
396 _RDMSR
397 btr $DIS_IND, %eax # Turn on indirect branch predictor
398 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative TLB reloads
399 _WRMSR
400
401 mov $BU_CFG2, %ecx # MSR:C001_102A
402 _RDMSR
403 btr $F10_CL_LINES_TO_NB_DIS, %eax # Return L3 to normal mode
404 btr $(IC_DIS_SPEC_TLB_WR-32), %edx #Re-enable speculative writes to the ITLB
405 _WRMSR
406
407 #--------------------------------------------------------------------------
408 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
409 #--------------------------------------------------------------------------
410
411 mov $HWCR, %ecx # MSR:0000_0015
412 _RDMSR
413 mov %ax, %bx # Save INVD -> WBINVD bit
414 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion for the invd instruction.
415 _WRMSR
416 invd # Clear the cache tag RAMs
417 mov %bx, %ax # Restore INVD -> WBINVD bit
418 _WRMSR
419
420 #--------------------------------------------------------------------------
421 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
422 #--------------------------------------------------------------------------
423
424 mov $PERF_CONTROL3, %ecx # Select the event control three
425 _RDMSR # Retrieve the current value
426 btc $EVENT_ENABLE, %eax # Is event enable, complement it as well
427 jnc fam10_disable_stack_hook_exit # No
428 cmp $CONFIG_EVENT_L, %ax # Is the lower part of event set to capture the CAR Corruption
429 jne fam10_disable_stack_hook_exit # No
430 cmp $CONFIG_EVENT_H, %dl # Is the upper part of event set to capture the CAR Corruption
431 jne fam10_disable_stack_hook_exit # No
432 _WRMSR # Disable the event
433
434fam10_disable_stack_hook_exit:
zbaoafd141d2012-03-30 15:32:07 +0800435.endm
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000436
437/****************************************************************************
438*
439* GET_NODE_ID_CORE_ID_F10 Macro - Stackless
440*
441* Read family specific values to determine the node and core
442* numbers for the core executing this code.
443*
444* Inputs:
445* none
446* Outputs:
447* SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
448*****************************************************************************/
449.macro GET_NODE_ID_CORE_ID_F10
450
451 LOCAL node_core_f10_exit
452 LOCAL node_core_f10_AP
453
454 cmp $-1, %si # Has node/core already been discovered?
455 jnz node_core_f10_exit # Br if yes
456
457 AMD_CPUID $CPUID_MODEL
458 shr $20, %eax # AL = cpu extended family
459 cmp $0x01, %al # Is this family 10h?
460 jnz node_core_f10_exit # Br if no
461
462 xor %esi, %esi # Assume BSC, clear flags
463 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
464 _RDMSR
465 bt $APIC_BSC, %eax # Is this the BSC?
466 jnc node_core_f10_AP # Br if no
467
468 # This is the BSP.
469 # Enable routing tables on BSP (just in case the HT init code has not yet enabled them)
470 mov $0x8000C06C, %eax # PCI address for D18F0x6C Link Initialization Control Register
471 mov $0x0CF8, %dx
472 out %eax, %dx
473 add $4, %dx
474 in %dx, %eax
475 btr $0, %eax # Set LinkInitializationControl[RouteTblDis] = 0
476 out %eax, %dx
477 jmp 1f #
478
479node_core_f10_AP:
480 #
481 # This is an AP. Routing tables have been enabled by the HT Init process.
482 # Also, the MailBox register was set by the BSP during early init
483 # The Mailbox register content is formatted as follows:
484 # UINT32 Node:4# // The node id of Core's node.
485 # UINT32 Socket:4# // The socket of this Core's node.
486 # UINT32 Module:2# // The internal module number for Core's node.
487 # UINT32 ModuleType:2# // Single Module = 0, Multi-module = 1.
488 # UINT32 :20# // Reserved
489 #
490 mov $0x0C0000408, %ecx # Read the family 10h mailbox
491 _RDMSR # MC4_MISC1[63:32]
492 mov %dx, %si # SI = raw mailbox contents (will extract node# from this)
493 shr $24, %ebx # BL = CPUID Fn0000_0001_EBX[LocalApicId]
494 mov %bx, %di # DI = Initial APIC ID (will extract core# from this)
495
496 AMD_CPUID $AMD_CPUID_APIC #
497 shr $4, %ch # CH = ApicIdSize, #bits in APIC ID that show core#
498 inc %cl # CL = Number of enabled cores in the socket
499 mov %cx, %bx
500
501 mov $NB_CFG, %ecx # MSR:C001_001F
502 _RDMSR # EDX has InitApicIdCpuIdLo bit
503
504 mov %bh, %cl # CL = APIC ID size
505 mov $1, %al # Convert APIC ID size to an AND mask
506 shl %cl, %al # AL = 2^APIC ID size
507 dec %al # AL = mask for relative core number
508 xor %ah, %ah # AX = mask for relative core number
509 bt $(INIT_APIC_ID_CPU_ID_LO-32), %edx # InitApicIdCpuIdLo == 1?
510 #.if (!carry?) # Br if yes
511 jc 0f
512 mov $8, %ch # Calculate core number shift count
513 sub %cl, %ch # CH = core shift count
514 mov %ch, %cl
515 shr %cl, %di # Right justify core number
516 #.endif
517 0:
518 and %ax, %di # DI = socket-relative core number
519
520 mov %si, %cx # CX = raw mailbox value
521 shr $10, %cx # CL[1:0] = ModuleType or #nodes per socket (0-SCM, 1-MCM)
522 and $3, %cl # Isolate ModuleType
523 xor %bh, %bh # BX = Number of enabled cores in the socket
524 shr %cl, %bx # BX = Number of enabled cores per node
525 xor %dx, %dx # Clear upper word for div
526 mov %di, %ax # AX = socket-relative core number
527 div %bx # DX = node-relative core number
528 movzx %si, %eax # prepare return value, [23:16]=shared Core# (=0, not shared)
529 and $0x000F, %ax # AX = node number
530 shl $8, %ax # [15:8]=node#
531 mov %dl, %al # [7:0]=core# (relative to node)
532 mov %eax, %esi # ESI = return value
5331:
534 bts $FLAG_IS_PRIMARY, %esi # all Family 10h cores are primary
535node_core_f10_exit:
536.endm
537
538
539/*****************************************************************************
540** Family 12h MACROS
541*****************************************************************************/
542/*****************************************************************************
543*
544* AMD_ENABLE_STACK_FAMILY_HOOK_F12 Macro - Stackless
545*
546* Set any family specific controls needed to enable the use of
547* cache as general storage before main memory is available.
548*
549* Inputs:
550* ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
551* Outputs:
552* none
553*
554* Family 12h requirements (BKDG section 2.3.3):
555* The following requirements must be satisfied prior to using the cache as general storage:
556* * Paging must be disabled.
557* * MSRC001_0015[INVD_WBINVD]=0
558* * MSRC001_1020[DIS_SS]=1
559* * MSRC001_1021[DIS_SPEC_TLB_RLD]=1
560* * MSRC001_1022[DIS_SPEC_TLB_RLD]=1
561* * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=1
562* * MSRC001_1022[DIS_HW_PF]=1
563* * MSRC001_1029[ClflushSerialize]=1
564* * No INVD or WBINVD, no exceptions, page faults or interrupts
565*****************************************************************************/
566.macro AMD_ENABLE_STACK_FAMILY_HOOK_F12
567 LOCAL fam12_enable_stack_hook_exit
568
569 AMD_CPUID $CPUID_MODEL
570 shr $20, %eax # AL = cpu extended family
571 cmp $0x03, %al # Is this family 12h?
572 jnz fam12_enable_stack_hook_exit # Br if no
573
574 mov $DC_CFG, %ecx # MSR:C001_1022
575 _RDMSR
576 bts $DC_DIS_SPEC_TLB_RLD, %eax # Disable speculative DC-TLB reloads
577 bts $DIS_CLR_WBTOL2_SMC_HIT, %eax # Disable self modifying code check buffer
578 bts $DIS_HW_PF, %eax # Disable hardware prefetches
579 _WRMSR
580
581 dec %cx #IC_CFG # MSR:C001_1021
582 _RDMSR
583 bts $IC_DIS_SPEC_TLB_RLD, %eax # Disable speculative IC-TLB reloads
584 _WRMSR
585
586 dec %cx #LS_CFG # MSR:C001_1020
587 _RDMSR
588 bts $DIS_SS, %eax # Disabled Streaming store functionality
589 _WRMSR
590
591 mov $HWCR, %ecx # MSR C001_0015
592 _RDMSR
593 bt $FLAG_STACK_REENTRY , %esi # Check if stack has already been set
594 jc fam12_skipClearingBit4
595 btr $INVD_WBINVD, %eax # disable INVD -> WBINVD conversion
596 _WRMSR
zbaoafd141d2012-03-30 15:32:07 +0800597
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000598fam12_skipClearingBit4:
599 mov $DE_CFG, %ecx # MSR:C001_1029
600 _RDMSR
601 bts $CL_FLUSH_SERIALIZE, %eax # Serialize all CL Flush actions
602 _WRMSR
603
604fam12_enable_stack_hook_exit:
605.endm
606
607/*****************************************************************************
608*
609* AMD_DISABLE_STACK_FAMILY_HOOK_F12 Macro - Stackless
610*
611* Return any family specific controls to their 'standard'
612* settings for using cache with main memory.
613*
614* Inputs:
615* ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
616* Outputs:
617* none
618*
619* Family 12h requirements:
620* * INVD or WBINVD
621* * MSRC001_0015[INVD_WBINVD]=1
622* * MSRC001_1020[DIS_SS]=0
623* * MSRC001_1021[IC_DIS_SPEC_TLB_RLD]=0
624* * MSRC001_1022[DC_DIS_SPEC_TLB_RLD]=0
625* * MSRC001_1022[DIS_CLR_WBTOL2_SMC_HIT]=0
626* * MSRC001_1022[DIS_HW_PF]=0
627* * MSRC001_1029[ClflushSerialize]=0
628*****************************************************************************/
629.macro AMD_DISABLE_STACK_FAMILY_HOOK_F12
630 LOCAL fam12_disable_stack_hook_exit
631
632 AMD_CPUID $CPUID_MODEL
633 shr $20, %eax # AL = cpu extended family
634 cmp $0x03, %al # Is this family 12h?
635 jnz fam12_disable_stack_hook_exit # Br if no
636
637 mov $DC_CFG, %ecx # MSR:C001_1022
638 _RDMSR
639 btr $DC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative DC-TLB reloads
640 btr $DIS_CLR_WBTOL2_SMC_HIT, %eax # Enable self modifying code check buffer
641 btr $DIS_HW_PF, %eax # Enable Hardware prefetches
642 _WRMSR
643
644 dec %cx #IC_CFG # MSR:C001_1021
645 _RDMSR
646 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative IC-TLB reloads
647 _WRMSR
648
649 dec %cx #LS_CFG # MSR:C001_1020
650 _RDMSR
651 btr $DIS_SS, %eax # Turn on Streaming store functionality
652 _WRMSR
653
654 mov $DE_CFG, %ecx # MSR:C001_1029
655 _RDMSR
656 btr $CL_FLUSH_SERIALIZE, %eax
657 _WRMSR
658
659 #--------------------------------------------------------------------------
660 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
661 #--------------------------------------------------------------------------
662
663 mov $HWCR, %ecx # MSR:0000_0015h
664 _RDMSR
665 mov %ax, %bx # Save INVD -> WBINVD bit
666 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
667 _WRMSR
668 invd # Clear the cache tag RAMs
669 mov %bx, %ax # Restore INVD -> WBINVD bit
670 _WRMSR
671
672 #--------------------------------------------------------------------------
673 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
674 #--------------------------------------------------------------------------
675
676fam12_disable_stack_hook_exit:
677.endm
678
679/*****************************************************************************
680*
681* GET_NODE_ID_CORE_ID_F12 Macro - Stackless
682*
683* Read family specific values to determine the node and core
684* numbers for the core executing this code.
685*
686* Inputs:
687* none
688* Outputs:
689* SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
690*****************************************************************************/
691.macro GET_NODE_ID_CORE_ID_F12
692
693 LOCAL node_core_f12_exit
694
695 cmp $-1, %si # Has node/core already been discovered?
696 jnz node_core_f12_exit # Br if yes
697
698 AMD_CPUID $CPUID_MODEL
699 shr $20, %eax # AL = cpu extended family
700 cmp $0x03, %al # Is this family 12h?
701 jnz node_core_f12_exit # Br if no
702
703 shr $24, %ebx # CPUID_0000_0001_EBX[31:24]: initial local APIC physical ID
704 bts $FLAG_IS_PRIMARY, %ebx # all family 12h cores are primary
705 mov %ebx, %esi # ESI = Node#=0, core number
706node_core_f12_exit:
707.endm
708
709/*****************************************************************************
710** Family 14h MACROS
711*****************************************************************************/
712/*****************************************************************************
713*
714* AMD_ENABLE_STACK_FAMILY_HOOK_F14 Macro - Stackless
715*
716* Set any family specific controls needed to enable the use of
717* cache as general storage before main memory is available.
718*
719* Inputs:
720* ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
721* Outputs:
722* none
723*
724* Family 14h requirements (BKDG section 2.3.3):
725* * Paging must be disabled.
726* * MSRC001_0015[INVD_WBINVD]=0.
727* * MSRC001_1020[DisStreamSt]=1.
728* * MSRC001_1021[DIS_SPEC_TLB_RLD]=1. Disable speculative ITLB reloads.
729* * MSRC001_1022[DIS_HW_PF]=1.
730* * No INVD or WBINVD, no exceptions, page faults or interrupts
731*****************************************************************************/
732.macro AMD_ENABLE_STACK_FAMILY_HOOK_F14
733 LOCAL fam14_enable_stack_hook_exit
734
735 AMD_CPUID $CPUID_MODEL
736 shr $20, %eax # AL = cpu extended family
737 cmp $0x05, %al # Is this family 14h?
738 jnz fam14_enable_stack_hook_exit # Br if no
739
740 mov $DC_CFG, %ecx # MSR:C001_1022
741 _RDMSR
742 bts $DIS_HW_PF, %eax # Disable hardware prefetches
743 _WRMSR
744
745 dec %cx #IC_CFG # MSR:C001_1021
746 _RDMSR
747 bts $IC_DIS_SPEC_TLB_RLD, %eax # Disable speculative TLB reloads
748 _WRMSR
749
750 dec %cx #LS_CFG # MSR:C001_1020
751 _RDMSR
752 bts $DIS_STREAM_ST, %eax # Disabled Streaming store functionality
753 _WRMSR
754
755 mov $HWCR, %ecx # MSR C001_0015
756 _RDMSR
757 bt $FLAG_STACK_REENTRY, %esi # Check if stack has already been set
758 jc fam14_skipClearingBit4
759 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
760 _WRMSR
761fam14_skipClearingBit4: # Keeping this label
762
763fam14_enable_stack_hook_exit:
764.endm
765
766/*****************************************************************************
767*
768* AMD_DISABLE_STACK_FAMILY_HOOK_F14 Macro - Stackless
769*
770* Return any family specific controls to their 'standard'
771* settings for using cache with main memory.
772*
773* Inputs:
774* ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
775* Outputs:
776* none
777*
778* Family 14h requirements:
779* * INVD or WBINVD
780* * MSRC001_0015[INVD_WBINVD]=1.
781* * MSRC001_1020[DisStreamSt]=0.
782* * MSRC001_1021[DIS_SPEC_TLB_RLD]=0.
783* * MSRC001_1022[DIS_HW_PF]=0.
784*****************************************************************************/
785.macro AMD_DISABLE_STACK_FAMILY_HOOK_F14
786 LOCAL fam14_disable_stack_hook_exit
787
788 AMD_CPUID $CPUID_MODEL
789 shr $20, %eax # AL = cpu extended family
790 cmp $0x05, %al # Is this family 14h?
791 jnz fam14_disable_stack_hook_exit # Br if no
792
793 mov $LS_CFG, %ecx # MSR:C001_1020
794 _RDMSR
795 btr $DIS_STREAM_ST, %eax # Turn on Streaming store functionality
796 _WRMSR
797
798 inc %cx #IC_CFG # MSR:C001_1021
799 _RDMSR
800 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative DC-TLB reloads
801 _WRMSR
802
803 inc %cx #DC_CFG # MSR:C001_1022
804 _RDMSR
805 btr $DIS_HW_PF, %eax # Turn on hardware prefetches
806 _WRMSR
807
808 #--------------------------------------------------------------------------
809 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
810 #--------------------------------------------------------------------------
811
812 mov $HWCR, %ecx # MSR:C001_0015h
813 _RDMSR
814 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
815 _WRMSR
Kyösti Mälkki0f6c0b12017-09-07 06:46:46 +0300816 invd # Clear the cache tag RAMs
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000817 bts $INVD_WBINVD, %eax # Turn on Conversion of INVD to WBINVD
818 _WRMSR
819
820 #--------------------------------------------------------------------------
821 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
822 #--------------------------------------------------------------------------
823
824fam14_disable_stack_hook_exit:
825.endm
826
827/*****************************************************************************
828*
829* GET_NODE_ID_CORE_ID_F14 Macro - Stackless
830*
831* Read family specific values to determine the node and core
832* numbers for the core executing this code.
833*
834* Inputs:
835* none
836* Outputs:
837* SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
838*****************************************************************************/
839.macro GET_NODE_ID_CORE_ID_F14
840
841 LOCAL node_core_f14_exit
842
Edward O'Callaghan9cd96b42014-02-21 12:43:07 +1100843 cmp $-1, %si # Has node/core already been discovered?
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000844 jnz node_core_f14_exit # Br if yes
845
846 AMD_CPUID $CPUID_MODEL
847 shr $20, %eax # AL = cpu extended family
848 cmp $0x05, %al # Is this family 14h?
849 jnz node_core_f14_exit # Br if no
850
851 xor %esi, %esi # Node must be 0
852 bts $FLAG_IS_PRIMARY, %esi # all family 14h cores are primary
853 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
854 _RDMSR
855 bt $APIC_BSC, %eax # Is this the BSC?
856 jc node_core_f14_exit # Br if yes
857 inc %si # Set core to 1
858node_core_f14_exit:
859.endm
860
861
862
863/*****************************************************************************
864** Family 15h MACROS
865*****************************************************************************/
866/*****************************************************************************
867*
868* AMD_ENABLE_STACK_FAMILY_HOOK_F15 Macro - Stackless
869*
870* Set any family specific controls needed to enable the use of
871* cache as general storage before main memory is available.
872*
873* Inputs:
874* ESI - node#, core#, flags from GET_NODE_ID_CORE_ID
875* Outputs:
876* none
877*
878* Family 15h requirements (BKDG #42301 section 2.3.3):
879* * Paging must be disabled.
880* * MSRC001_0015[INVD_WBINVD]=0
881* * MSRC001_1020[DisSS]=1
882* * MSRC001_1021[DIS_SPEC_TLB_RLD]=1
883* * MSRC001_1022[DIS_SPEC_TLB_RLD]=1
884* * MSRC001_1022[DisHwPf]=1
885* * No INVD or WBINVD, no exceptions, page faults or interrupts
886*****************************************************************************/
887.macro AMD_ENABLE_STACK_FAMILY_HOOK_F15
888 LOCAL fam15_enable_stack_hook_exit
889
890 AMD_CPUID $CPUID_MODEL
891 shr $20, %eax # AL = cpu extended family
892 cmp $0x06, %al # Is this family 15h?
893 jnz fam15_enable_stack_hook_exit # Br if no
894
895 bt $FLAG_STACK_REENTRY , %esi # Check if stack has already been set
896 jc fam15_skipClearingBit4
897 mov $HWCR, %ecx # MSR C001_0015
898 _RDMSR
899 btr $INVD_WBINVD, %eax # disable INVD -> WBINVD conversion
900 _WRMSR
zbaoafd141d2012-03-30 15:32:07 +0800901
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000902fam15_skipClearingBit4:
903 mov $LS_CFG, %ecx # MSR:C001_1020
904 _RDMSR
905 bts $DIS_SS, %eax # Turn on Streaming store functionality disabled bit
906 _WRMSR
907
908 inc %ecx #IC_CFG # MSR:C001_1021
909 _RDMSR
910 bts $IC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative IC-TLB reloads bit
911 _WRMSR
912
913 inc %ecx #DC_CFG # MSR:C001_1022
914 _RDMSR
915 bts $DC_DIS_SPEC_TLB_RLD, %eax # Turn on Disable speculative DC-TLB reloads bit
916 bts $DIS_HW_PF, %eax # Turn on Disable hardware prefetches bit
917 _WRMSR
918
919 mov $CU_CFG3, %ecx # MSR:C001_102B
920 _RDMSR
921 btr $(COMBINE_CR0_CD - 32), %edx # Clear CombineCr0Cd bit
922 _WRMSR
923
924fam15_enable_stack_hook_exit:
925.endm
926
927
928/*****************************************************************************
929*
930* AMD_DISABLE_STACK_FAMILY_HOOK_F15 Macro - Stackless
931*
932* Return any family specific controls to their 'standard'
933* settings for using cache with main memory.
934*
935* Inputs:
936* ESI - [31:24] flags; [15,8]= Node#; [7,0]= core#
937* Outputs:
938* none
939*
940* Family 15h requirements:
941* * INVD or WBINVD
942* * MSRC001_0015[INVD_WBINVD]=1
943* * MSRC001_1020[DisSS]=0
944* * MSRC001_1021[DIS_SPEC_TLB_RLD]=0
945* * MSRC001_1022[DIS_SPEC_TLB_RLD]=0
946* * MSRC001_1022[DIS_HW_PF]=0
947*****************************************************************************/
948.macro AMD_DISABLE_STACK_FAMILY_HOOK_F15
949 LOCAL fam15_disable_stack_hook_exit
950
951 AMD_CPUID $CPUID_MODEL
952 mov %eax, %ebx # Save revision info to EBX
953 shr $20, %eax # AL = cpu extended family
954 cmp $0x06, %al # Is this family 15h?
955 jnz fam15_disable_stack_hook_exit # Br if no
956
957 mov $LS_CFG, %ecx # MSR:C001_1020
958 #.if (ebx != 00600F00h) ; Is this rev A0?
959 cmp $0x00600F00, %ebx
960 jz 0f
961 _RDMSR
962 btr $DIS_SS, %eax # Turn on Streaming store functionality
963 _WRMSR
964 #.endif
965 0: # End workaround for errata 495 and 496
966
967 inc %ecx #IC_CFG # MSR:C001_1021
968 _RDMSR
969 btr $IC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative TLB reloads
970 _WRMSR
971
972 inc %ecx #DC_CFG # MSR:C001_1022
973 _RDMSR
974 btr $DC_DIS_SPEC_TLB_RLD, %eax # Turn on speculative TLB reloads
975 #.if (ebx != 00600F00h) # Is this rev A0?
976 cmp $0x00600F00, %ebx
977 jz 0f
978 btr $DIS_HW_PF, %eax # Turn on hardware prefetches
979 #.endif # End workaround for erratum 498
980 0:
zbaoafd141d2012-03-30 15:32:07 +0800981 _WRMSR
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000982 #--------------------------------------------------------------------------
983 # Begin critical sequence in which EAX, BX, ECX, and EDX must be preserved.
984 #--------------------------------------------------------------------------
985
986 bt $FLAG_IS_PRIMARY, %esi
987 #.if (carry?) # Only clear cache from primary core
988 jnc 0f
989 mov $HWCR, %ecx # MSR:C001_0015h
990 _RDMSR
991 btr $INVD_WBINVD, %eax # Disable INVD -> WBINVD conversion
992 _WRMSR
993 invd # Clear the cache tag RAMs
994 bts $INVD_WBINVD, %eax # Turn on Conversion of INVD to WBINVD
995 _WRMSR
996 #.endif # end
997 0:
998
999 #--------------------------------------------------------------------------
1000 # End critical sequence in which EAX, BX, ECX, and EDX must be preserved.
1001 #--------------------------------------------------------------------------
1002
1003 mov $CU_CFG3, %ecx # MSR:C001_102B
1004 _RDMSR
Konstantin Aladyshev7fcbbb02013-03-06 19:58:38 +04001005 bts $(COMBINE_CR0_CD - 32), %edx # Set CombineCr0Cd bit
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001006 _WRMSR
1007
1008fam15_disable_stack_hook_exit:
1009.endm
1010
1011
1012/*****************************************************************************
1013*
1014* GET_NODE_ID_CORE_ID_F15 Macro - Stackless
1015*
1016* Read family specific values to determine the node and core
1017* numbers for the core executing this code.
1018*
1019* Inputs:
1020* none
1021* Outputs:
1022* SI = core#, node# & flags (see GET_NODE_ID_CORE_ID macro above)
1023*****************************************************************************/
1024.macro GET_NODE_ID_CORE_ID_F15
1025
1026 LOCAL node_core_f15_exit
1027 LOCAL node_core_f15_AP
1028 LOCAL node_core_f15_shared
1029
1030 cmp $-1, %si # Has node/core already been discovered?
1031 jnz node_core_f15_exit # Br if yes
1032
1033 AMD_CPUID $CPUID_MODEL
1034 shr $20, %eax # AL = cpu extended family
1035 cmp $06, %al # Is this family 15h?
1036 jnz node_core_f15_exit # Br if no
1037
1038 xor %esi, %esi # Assume BSC, clear local flags
1039 mov $APIC_BASE_ADDRESS, %ecx # MSR:0000_001B
1040 _RDMSR
1041 bt $APIC_BSC, %eax # Is this the BSC?
1042 jnc node_core_f15_AP # Br if no
1043
1044 # This is the BSP.
1045 # Enable routing tables on BSP (just in case the HT init code has not yet enabled them)
1046 mov $0x8000C06C, %eax # PCI address for D18F0x6C Link Initialization Control Register
1047 mov $0x0CF8, %dx
1048 out %eax, %dx
1049 add $4, %dx
1050 in %dx, %eax
1051 btr $0, %eax # Set LinkInitializationControl[RouteTblDis] = 0
1052 out %eax, %dx
1053 jmp node_core_f15_shared #
1054
1055node_core_f15_AP:
1056 #
1057 # This is an AP. Routing tables have been enabled by the HT Init process.
1058 # Also, the MailBox register was set by the BSP during early init
1059 # The Mailbox register content is formatted as follows:
1060 # UINT32 Node:4; // The node id of Core's node.
1061 # UINT32 Socket:4; // The socket of this Core's node.
1062 # UINT32 Module:2; // The internal module number for Core's node.
1063 # UINT32 ModuleType:2; // Single Module = 0, Multi-module = 1.
1064 # UINT32 :20; // Reserved
1065 #
1066 mov $0x0C0000408, %ecx # Read the family 15h mailbox
1067 _RDMSR # MC4_MISC1[63:32]
1068 mov %dx, %si # SI = raw mailbox contents (will extract node# from this)
1069 shr $24, %ebx # BL = CPUID Fn0000_0001_EBX[LocalApicId]
1070 mov %bx, %di # DI = Initial APIC ID (will extract core# from this)
1071
1072 AMD_CPUID $AMD_CPUID_APIC #
1073 shr $4, %ch # CH = ApicIdSize, #bits in APIC ID that show core#
1074 inc %cl # CL = Number of enabled cores in the socket
1075 mov %cx, %bx
1076
1077 mov $NB_CFG, %ecx
1078 _RDMSR # EDX has InitApicIdCpuIdLo bit
1079
1080 mov %bh, %cl # CL = APIC ID size
1081 mov $1, %al # Convert APIC ID size to an AND mask
1082 shl %cl, %al # AL = 2^APIC ID size
1083 dec %al # AL = mask for relative core number
1084 xor %ah, %ah # AX = mask for relative core number
1085 bt $(INIT_APIC_ID_CPU_ID_LO-32), %edx # InitApicIdCpuIdLo == 1?
1086 #.if (!carry?) # Br if yes
1087 jc 0f
1088 mov $8, %ch # Calculate core number shift count
1089 sub %cl, %ch # CH = core shift count
1090 mov %ch, %cl
1091 shr %cl, %di # Right justify core number
1092 #.endif
1093 0:
1094 and %ax, %di # DI = socket-relative core number
1095
1096 mov %si, %cx # CX = raw mailbox value
1097 shr $10, %cx # CL[1:0] = ModuleType or #nodes per socket (0-SCM, 1-MCM)
1098 and $3, %cl # Isolate ModuleType
1099 xor %bh, %bh # BX = Number of enabled cores in the socket
1100 shr %cl, %bx # BX = Number of enabled cores per node
1101 xor %dx, %dx # Clear upper word for div
1102 mov %di, %ax # AX = socket-relative core number
1103 div %bx # DX = node-relative core number
1104 movzx %si, %eax # Prepare return value
1105 and $0x000F, %ax # AX = node number
1106 shl $8,%ax # [15:8]=node#
1107 mov %dl, %al # [7:0]=core# (relative to node)
1108 mov %eax, %esi # ESI = node-relative core number
1109
1110 #
1111 # determine if this core shares MTRRs
1112 #
1113node_core_f15_shared:
1114 mov $0x8000C580, %eax # Compute Unit Status
1115 mov %si, %bx
1116 shl $3, %bh # Move node# to PCI Dev# field
1117 add %bh, %ah # Adjust for node number
1118 mov $0x0CF8, %dx
1119 out %eax, %dx
1120 add $4, %dx
1121 in %dx, %eax # [3:0]=Enabled# [19:16]=DualCore
1122
1123 # BL is MyCore#
1124 mov $0x06, %cx # Use CH as 'first of pair' core#
1125 #.while (cl > 0)
1126 jmp 0f
1127 8:
1128 bt $0, %eax # Is pair enabled?
1129 #.if (carry?) #
1130 jnc 1f
1131 mov $0x01, %bh # flag core as primary
1132 bt $16, %eax # Is there a 2nd in the pair?
1133 #.if (carry?) #
1134 jnc 4f
1135 #.break .if (ch == bl) # Does 1st match MyCore#?
1136 cmp %bl, %ch
1137 je 9f
1138 inc %ch
1139 xor %bh, %bh # flag core as NOT primary
1140 #.break .if (ch == bl) # Does 2nd match MyCore#?
1141 cmp %bl, %ch
1142 je 9f
zbaoafd141d2012-03-30 15:32:07 +08001143 jmp 2f
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001144 #.else # No 2nd core
1145 4:
1146 #.break .if (ch == bl) # Does 1st match MyCore#?
1147 cmp %bl, %ch
1148 je 9f
1149 #.endif
1150 2:
1151 inc %ch
1152 #.endif
1153 1:
1154 shr $1, %eax
1155 dec %cl
1156 #.endw
1157 0:
1158 #.if (cl == 0)
1159 cmp $0x0, %cl
1160 ja 8b
1161 9:
1162 or %cl, %cl
1163 jne 1f
1164 #Error - core# didn't match Compute Unit Status content
1165 bts $FLAG_UNKNOWN_FAMILY, %esi
1166 bts $FLAG_IS_PRIMARY, %esi # Set Is_Primary for unknowns
1167 #.endif
1168 1:
1169 #.if (bh != 0) # Check state of primary for the matched core
1170 or %bh, %bh
1171 je 2f
1172 bts $FLAG_IS_PRIMARY, %esi # Set shared flag into return value
1173 #.endif
1174 2:
1175
1176node_core_f15_exit:
1177
1178.endm
1179
1180/*****************************************************************************
1181* AMD_ENABLE_STACK: Setup a stack
1182*
1183* In:
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +03001184* No inputs
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001185*
1186* Out:
1187* SS:ESP - Our new private stack location
1188*
1189* EAX = AGESA_STATUS
1190*
1191* ECX = Stack size in bytes
1192*
1193* Requirements:
1194* * This routine presently is limited to a max of 64 processor cores
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001195* Destroyed:
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +03001196* EBX, EDX, EDI, ESI, EBP, DS, ES
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001197*
1198* Description:
1199* Fixed MTRR address allocation to cores:
1200* The BSP gets 64K of stack, Core0 of each node gets 16K of stack, all other cores get 4K.
1201* There is a max of 1 BSP, 7 core0s and 56 other cores.
1202* Although each core has it's own cache storage, they share the address space. Each core must
1203* be assigned a private and unique address space for its stack. To support legacy systems,
1204* the stack needs to be within the legacy address space (1st 1Meg). Room must also be reserved
1205* for the other legacy elements (Interrupt vectors, BIOS ROM, video buffer, etc.)
1206*
1207* 80000h 40000h 00000h
1208* +----------+----------+----------+----------+----------+----------+----------+----------+
1209* 64K | | | | | | | | | 64K ea
1210* ea +----------+----------+----------+----------+----------+----------+----------+----------+
1211* | MTRR 0000_0250 MTRRfix64K_00000 |
1212* +----------+----------+----------+----------+----------+----------+----------+----------+
1213* | 7 , 6 | 5 , 4 | 3 , 2 | 1 , 0 | 0 | | | | <-node
1214* |7..1,7..1 |7..1,7..1 |7..1,7..1 |7..1,7..1 | 0 | | | | <-core
1215* +----------+----------+----------+----------+----------+----------+----------+----------+
1216*
1217* C0000h B0000h A0000h 90000h 80000h
1218* +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1219*16K | | | | | | | | | | | | | | | | |
1220* ea +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1221* | MTRR 0259 MTRRfix16K_A0000 | MTRR 0258 MTRRfix16K_80000 |
1222* +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1223* | > Dis|play B|uffer | < | | | | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | | <-node
1224* | > T| e m |p o r |a r y | B u |f f e |r A |r e a<| 0 | 0 | 0 | 0 | 0 | 0 | 0 | | <-core
1225* +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
1226*
1227* E0000h D0000h C0000h
1228* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1229* 4K | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 4K ea
1230* ea +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1231* | 026B MTRRfix4K_D8000 | 026A MTRRfix4K_D0000 | 0269 MTRRfix4K_C8000 | 0268 MTRRfix4K_C0000 |
1232* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1233* | | | | | | | | | | | | | | | | | >| V| I| D| E| O| |B |I |O |S | |A |r |e |a<|
1234* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1235*
1236* 100000h F0000h E0000h
1237* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1238* | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 4K ea
1239* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1240* | 026F MTRRfix4K_F8000 | 026E MTRRfix4K_F0000 | 026D MTRRfix4K_E8000 | 026C MTRRfix4K_E0000 |
1241* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1242* | >|MA|IN| B|IO|S |RA|NG|E | | | | | | |< | >|EX|TE|ND|ED| B|IO|S |ZO|NE| | | | | |< |
1243* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
1244*****************************************************************************/
zbaoafd141d2012-03-30 15:32:07 +08001245.macro AMD_ENABLE_STACK
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001246
1247# These are local labels. Declared so linker doesn't cause 'redefined label' errors
1248 LOCAL SetupStack
1249 LOCAL Real16bMode
1250 LOCAL Protected32Mode
1251 LOCAL ClearTheStack
1252
1253# Note that SS:ESP will be default stack. Note that this stack
1254# routine will not be used after memory has been initialized. Because
1255# of its limited lifetime, it will not conflict with typical PCI devices.
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001256
1257 # get node id and core id of current executing core
1258 GET_NODE_ID_CORE_ID # Sets ESI[23:16]=Shared core## SI[15,8]= Node## SI[7,0]= core# (relative to node)
1259 # Note: ESI[31:24] are used for flags: Unrecognized Family, Is_Primary core, Stack already established
1260
1261 # determine if stack is already enabled. We are using the DefType MSR for this determination.
1262 # It is =0 after reset; CAR setup sets it to enable the MTRRs
1263 mov %cr0, %eax
1264 test $CR0_MASK, %eax # Is cache disabled? (CD & NW bits)
1265 jnz SetupStack # Jump if yes
1266 mov $AMD_MTRR_DEFTYPE, %ecx # MSR:0000_02FF
1267 _RDMSR
1268 test $MSR_MASK, %eax # Are the default types enabled? (MTRR_DEF_TYPE_EN + MTRR_DEF_TYPE_FIX_EN)
1269 jz SetupStack # Jump if no
1270 or $FLAG_STACK_REENTRY, %esi # Bit25, indicate stack has already been initialized
1271
1272SetupStack:
1273 # Set node to map the first 16MB to node 0# 0000_0000 to 00FF_FFFF as DRAM
1274 mov %esi, %ebx # Get my Node/Core info
1275 xor %bl, %bl
1276 shl $3, %bh # Isolate my node#, match alignment for PCI Dev#
1277 mov $0x8000C144, %eax # D18F1x44:DRAM Base/Limit# N is Base, N+4 is Limit
1278 add %bh, %ah
1279 mov %eax, %ebx # Save PCI address for Base/Limit pair
1280
1281 mov $0x0CF8, %dx
1282 out %eax, %dx
1283 add $4, %dx
1284 xor %eax, %eax # Least Significant bit is AD24 so 0 sets mask of 00FF_FFFF (16MB)
1285 out %eax, %dx # DRAM Limit = node0, no interleave
1286
1287 mov %ebx, %eax
1288 sub $4, %eax # Now point to the Base register
1289 mov $0x0CF8, %dx
1290 out %eax, %dx
1291 add $4, %dx
1292 mov $0x00000003, %eax # Set the read and write enable bits
1293 out %eax, %dx # DRAM Base = 0x0000, R/W
1294
1295 AMD_ENABLE_STACK_FAMILY_HOOK
1296
1297 # Init CPU MSRs for our init routines
1298 mov $MTRR_SYS_CFG, %ecx # SYS_CFG
1299 _RDMSR
1300 bts $MTRR_FIX_DRAM_MOD_EN, %eax # Turn on modification enable bit
1301 _WRMSR
1302
1303 mov %esi, %eax
1304 bt $FLAG_STACK_REENTRY, %eax # Is this a 2nd entry?
1305 #.if (!carry?) # On a re-entry, do not clear MTRRs or reset TOM; just reset the stack SS:ESP
1306 jc 0f
1307 bt $FLAG_IS_PRIMARY, %eax # Is this core the primary in a compute unit?
1308 #.if (carry?) # Families using shared groups do not need to clear the MTRRs since that is done at power-on reset
1309 # Note: Relying on MSRs to be cleared to 0's at reset for families w/shared cores
1310 # Clear all variable and Fixed MTRRs for non-shared cores
zbaoafd141d2012-03-30 15:32:07 +08001311 jnc 0f
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001312 mov $AMD_MTRR_VARIABLE_BASE0, %ecx
1313 xor %eax, %eax
1314 xor %edx, %edx
1315 #.while (cl != 10h) # Variable MTRRphysBase[n] and MTRRphysMask[n]
1316 jmp 1f
1317 2:
1318 _WRMSR
1319 inc %cl
1320 #.endw
1321 1:
1322 cmp $0x10, %cl
1323 jne 2b
1324 mov $AMD_MTRR_FIX64k_00000, %cx # MSR:0000_0250
1325 _WRMSR
1326 mov $AMD_MTRR_FIX16k_80000, %cx # MSR:0000_0258
1327 _WRMSR
1328 mov $AMD_MTRR_FIX16k_A0000, %cx # MSR:0000_0259
1329 _WRMSR
1330 mov $AMD_MTRR_FIX4k_C0000, %cx # Fixed 4Ks: MTRRfix4K_C0000 to MTRRfix4K_F8000
1331 #.while (cl != 70h)
1332 jmp 3f
1333 4:
1334 _WRMSR
1335 inc %cl
1336 #.endw
1337 3:
1338 cmp $0x70, %cl
1339 jne 4b
1340 # Set TOP_MEM (C001_001A) for non-shared cores to 16M. This will be increased at heap init.
1341 # - not strictly needed since the FixedMTRRs take presedence.
1342 mov $(16 * 1024 * 1024), %eax
1343 mov $TOP_MEM, %ecx # MSR:C001_001A
1344 _WRMSR
1345 #.endif # End Is_Primary
1346 #.endif # End Stack_ReEntry
zbaoafd141d2012-03-30 15:32:07 +08001347 0:
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001348 # Clear IORRs (C001_0016-19) and TOM2(C001_001D) for all cores
1349 xor %eax, %eax
1350 xor %edx, %edx
1351 mov $IORR_BASE, %ecx # MSR:C001_0016 - 0019
1352 #.while (cl != 1Ah)
1353 jmp 1f
zbaoafd141d2012-03-30 15:32:07 +08001354 2:
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001355 _WRMSR
1356 inc %cl
1357 #.endw
zbaoafd141d2012-03-30 15:32:07 +08001358 1:
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001359 cmp $0x1A, %cl
zbaoafd141d2012-03-30 15:32:07 +08001360 jne 2b
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001361 mov $TOP_MEM2, %ecx # MSR:C001_001D
1362 _WRMSR
1363
Paul Menzel2e0d9442014-01-25 15:59:31 +01001364 # setup MTRRs for stacks
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001365 # A speculative read can be generated by a speculative fetch mis-aligned in a code zone
1366 # or due to a data zone being interpreted as code. When a speculative read occurs outside a
1367 # controlled region (intentionally used by software), it could cause an unwanted cache eviction.
1368 # To prevent speculative reads from causing an eviction, the unused cache ranges are set
1369 # to UC type. Only the actively used regions (stack, heap) are reflected in the MTRRs.
1370 # Note: some core stack regions will share an MTRR since the control granularity is much
1371 # larger than the allocated stack zone. The allocation algorithm must account for this 'extra'
1372 # space covered by the MTRR when parseling out cache space for the various uses. In some cases
1373 # this could reduce the amount of EXE cache available to a core. see cpuCacheInit.c
1374 #
1375 # Outcome of this block is that: (Note the MTRR map at the top of the file)
1376 # ebp - start address of stack block
1377 # ebx - [31:16] - MTRR MSR address
1378 # - [15:8] - slot# in MTRR register
1379 # - [7:0] - block size in #4K blocks
1380 # review: ESI[31:24]=Flags; SI[15,8]= Node#; SI[7,0]= core# (relative to node)
1381 #
1382
1383 mov %si, %ax # Load node, core
1384 #.if (al == 0) # Is a core 0?
1385 or %al, %al
1386 jne 1f
1387 #.if (ah == 0) # Is Node 0? (BSP)
1388 or %ah, %ah
1389 jne 2f
1390 # Is BSP, assign a 64K stack
Stefan Reinauer4a45ec42015-07-07 00:54:05 +02001391 mov $((AMD_MTRR_FIX64k_00000 << 16) + (3 << 8) + (BSP_STACK_SIZE >> 12)), %ebx
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001392 mov $BSP_STACK_BASE_ADDR, %ebp
1393 jmp 0f
1394 #.else # node 1 to 7, core0
1395 2:
1396 # Is a Core0 of secondary node, assign 16K stacks
1397 mov $AMD_MTRR_FIX16k_80000, %bx
1398 shl $16, %ebx #
1399 mov %ah, %bh # Node# is used as slot#
Stefan Reinauer4a45ec42015-07-07 00:54:05 +02001400 mov $(CORE0_STACK_SIZE >> 12), %bl
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001401 mov %ah, %al # Base = (Node# * Size)#
1402 mul %bl #
1403 movzx %ax, %eax #
1404 shl $12, %eax # Expand back to full byte count (* 4K)
1405 add $CORE0_STACK_BASE_ADDR, %eax
1406 mov %eax, %ebp
1407 #.endif
1408 jmp 0f
1409 #.else #core 1 thru core 7
1410 1:
1411 # Is core 1-7 of any node, assign 4K stacks
1412 mov $8, %al # CoreIndex = ( (Node# * 8) ...
1413 mul %ah #
1414 mov %si, %bx #
1415 add %bl, %al # ... + Core#)#
1416
1417 mov $AMD_MTRR_FIX64k_00000, %bx
1418 shl $16, %ebx #
1419 mov %al, %bh # Slot# = (CoreIndex / 16) + 4#
1420 shr $4, %bh #
1421 add $4, %bh #
Stefan Reinauer4a45ec42015-07-07 00:54:05 +02001422 mov $(CORE1_STACK_SIZE >> 12), %bl
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001423
1424 mul %bl # Base = ( (CoreIndex * Size) ...
1425 movzx %ax, %eax #
1426 shl $12, %eax # Expand back to full byte count (* 4K)
1427 add $CORE1_STACK_BASE_ADDR, %eax # ... + Base_Addr)#
1428 mov %eax, %ebp
1429 #.endif
1430 0:
zbaoafd141d2012-03-30 15:32:07 +08001431
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001432 # Now set the MTRR. Add this to already existing settings (don't clear any MTRR)
1433 mov $WB_DRAM_TYPE, %edi # Load Cache type in 1st slot
1434 mov %bh, %cl # ShiftCount = ((slot# ...
1435 and $0x03, %cl # ... % 4) ...
1436 shl $0x03, %cl # ... * 8)#
1437 shl %cl, %edi # Cache type is now in correct position
1438 ror $16, %ebx # Get the MTRR address
1439 movzx %bx, %ecx #
1440 rol $16, %ebx # Put slot# & size back in BX
1441 _RDMSR # Read-modify-write the MSR
1442 #.if (bh < 4) # Is value in lower or upper half of MSR?
1443 cmp $4, %bh
1444 jae 1f
1445 or %edi, %eax #
1446 jmp 0f
1447 #.else
1448 1: #
1449 or %edi, %edx #
1450 #.endif #
1451 0:
1452 _WRMSR #
1453
1454 # Enable MTRR defaults as UC type
1455 mov $AMD_MTRR_DEFTYPE, %ecx # MSR:0000_02FF
1456 _RDMSR # Read-modify-write the MSR
1457 bts $MTRR_DEF_TYPE_EN, %eax # MtrrDefTypeEn
1458 bts $MTRR_DEF_TYPE_FIX_EN, %eax # MtrrDefTypeFixEn
1459 _WRMSR
1460
1461 # Close the modification window on the Fixed MTRRs
1462 mov $MTRR_SYS_CFG, %ecx # MSR:0C001_0010
1463 _RDMSR
1464 bts $MTRR_FIX_DRAM_EN, %eax # MtrrFixDramEn
1465 bts $MTRR_VAR_DRAM_EN, %eax # variable MTRR enable bit
1466 btr $MTRR_FIX_DRAM_MOD_EN, %eax # Turn off modification enable bit
1467 _WRMSR
1468
1469 # Enable caching in CR0
1470 mov %cr0, %eax # Enable WT/WB cache
1471 btr $CR0_PG, %eax # Make sure paging is disabled
1472 btr $CR0_CD, %eax # Clear CR0 NW and CD
1473 btr $CR0_NW, %eax
1474 mov %eax, %cr0
1475
1476 # Use the Stack Base & size to calculate SS and ESP values
1477 # review:
1478 # esi[31:24]=Flags; esi[15,8]= Node#; esi[7,0]= core# (relative to node)
1479 # ebp - start address of stack block
1480 # ebx - [31:16] - MTRR MSR address
1481 # - [15:8] - slot# in MTRR register
1482 # - [7:0] - block size in #4K blocks
1483 #
1484 mov %ebp, %esp # Initialize the stack pointer
1485 mov %esp, %edi # Copy the stack start to edi
1486 movzx %bl, %bx
1487 movzx %bx, %ebx # Clear upper ebx, don't need MSR addr anymore
1488 shl $12, %ebx # Make size full byte count (* 4K)
1489 add %ebx, %esp # Set the Stack Pointer as full linear address
1490 sub $4, %esp
1491 #
1492 # review:
1493 # esi[31:24]=Flags; esi[15,8]= Node#; esi[7,0]= core# (relative to node)
1494 # edi - 32b start address of stack block
1495 # ebx - size of stack block
1496 # esp - 32b linear stack pointer
1497 #
1498
1499 # Determine mode for SS base;
1500 mov %cr0, %ecx # Check for 32-bit protect mode
1501 bt $CR0_PE, %ecx #
1502 #.if (!carry?) # PE=0 means real mode
1503 jc Protected32Mode
1504 mov %cs, %cx # PE=1
1505 cmp $0x0D000, %cx # Check for CS
1506 jb Protected32Mode # If CS < D000, it is a selector instead of a segment
1507 # alter SS:ESP for 16b Real Mode:
1508Real16bMode:
1509 mov %edi, %eax
1510 shr $4, %eax # Create a Real Mode segment for ss, ds, es
1511 mov %ax, %ss
1512 mov %ax, %ds
1513 mov %ax, %es
1514 shl $4, %eax
1515 sub %eax, %edi # Adjust the clearing pointer for Seg:Offset mode
1516 mov %ebx, %esp # Make SP an offset from SS
1517 sub $4, %esp #
1518 # .endif # endif
1519 # #else
1520 # Default is to use Protected 32b Mode
1521 #.endif
1522 ;
1523Protected32Mode:
1524 #
1525 # Clear The Stack
1526 # Now that we have set the location and the MTRRs, initialize the cache by
1527 # reading then writing to zero all of the stack area.
1528 # review:
1529 # ss - Stack base
1530 # esp - stack pointer
1531 # ebx - size of stack block
1532 # esi[31:24]=Flags; esi[15,8]= Node#; esi[7,0]= core# (relative to node)
1533 # edi - address of start of stack block
1534 #
1535
1536ClearTheStack: # Stack base is in SS, stack pointer is in ESP
1537 shr $2, %ebx # ebx = stack block size in dwords
1538 mov %bx, %cx #
1539 # Check our flags - Don't clear an existing stack
1540 #.if ( !(esi & 0FF000000h)) # Check our flags
1541 test $(1 << FLAG_STACK_REENTRY), %esi
1542 jne 1f
1543 cld
1544 mov %edi, %esi
1545 rep lodsl (%esi) # Pre-load the range
1546 xor %eax, %eax
1547 mov %bx, %cx
1548 mov %edi, %esi # Preserve base for push on stack
1549 rep stosl (%edi) # Clear the range
1550 movl $0x0ABCDDCBA, (%esp) # Put marker in top stack dword
1551 shl $2, %ebx # Put stack size and base
1552 push %ebx # in top of stack
1553 push %esi
1554
1555 mov %ebx, %ecx # Return size of stack in bytes
1556 xor %eax, %eax # eax = 0 : no error return code
1557 jmp 0f
1558 #.else
1559 1:
1560 movzx %cx, %ecx
1561 shl $2, %ecx # Return size of stack in bytes
1562 mov %esi, %eax
1563 shr $24, %eax # Keep the flags as part of the error report
1564 or $0x40000000, %eax # eax = AGESA_WARNING (Stack has already been set up)
1565 #.endif
1566 0:
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001567.endm
1568
1569/*****************************************************************************
1570* AMD_DISABLE_STACK: Destroy the stack inside the cache. This routine
1571* should only be executed on the BSP
1572*
1573* In:
1574* none
1575*
1576* Out:
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +03001577* none
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001578*
1579* Preserved:
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +03001580* ESP
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001581* Destroyed:
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +03001582* EAX, EBX, ECX, EDX, EDI, ESI
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001583*****************************************************************************/
zbaoafd141d2012-03-30 15:32:07 +08001584.macro AMD_DISABLE_STACK
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001585
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001586 # get node/core/flags of current executing core
1587 GET_NODE_ID_CORE_ID # Sets ESI[15,8]= Node#; ESI[7,0]= core# (relative to node)
1588
1589 # Turn on modification enable bit
1590 mov $MTRR_SYS_CFG, %ecx # MSR:C001_0010
1591 _RDMSR
1592 bts $MTRR_FIX_DRAM_MOD_EN, %eax # Enable modifications
1593 _WRMSR
1594
1595 # Set lower 640K MTRRs for Write-Back memory caching
1596 mov $AMD_MTRR_FIX64k_00000, %ecx
1597 mov $0x1E1E1E1E, %eax
1598 mov %eax, %edx
1599 _WRMSR # 0 - 512K = WB Mem
1600 mov $AMD_MTRR_FIX16k_80000, %ecx
1601 _WRMSR # 512K - 640K = WB Mem
1602
1603 # Turn off modification enable bit
1604 mov $MTRR_SYS_CFG, %ecx # MSR:C001_0010
1605 _RDMSR
1606 btr $MTRR_FIX_DRAM_MOD_EN, %eax # Disable modification
1607 _WRMSR
1608
1609 AMD_DISABLE_STACK_FAMILY_HOOK # Re-Enable 'normal' cache operations
1610
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001611.endm