blob: b7619ff58a46ff31c87a623498d548037fe73700 [file] [log] [blame]
efdesign987c0c64e2011-06-20 19:56:06 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
efdesign987c0c64e2011-06-20 19:56:06 -070014 */
efdesign984b508342011-07-13 17:16:13 -070015
efdesign987c0c64e2011-06-20 19:56:06 -070016/******************************************************************************
17 * AMD Generic Encapsulated Software Architecture
18 *
19 * $Workfile:: cache_as_ram.inc
20 *
21 * Description: cache_as_ram.inc - AGESA Module Entry Point for GCC complier
22 *
23 ******************************************************************************
efdesign984b508342011-07-13 17:16:13 -070024 */
25
efdesign987c0c64e2011-06-20 19:56:06 -070026#include "gcccar.inc"
Patrick Georgi05e740f2012-03-31 12:52:21 +020027#include <cpu/x86/cache.h>
efdesign987c0c64e2011-06-20 19:56:06 -070028
29/*
30 * XMM map:
31 * xmm0: BIST
32 * xmm1: backup ebx -- cpu_init_detected
33 */
34
35.code32
36.globl cache_as_ram_setup, disable_cache_as_ram, cache_as_ram_setup_out
37
38cache_as_ram_setup:
efdesign984b508342011-07-13 17:16:13 -070039
efdesign987c0c64e2011-06-20 19:56:06 -070040 post_code(0xa0)
efdesign984b508342011-07-13 17:16:13 -070041
42 /* enable SSE2 128bit instructions */
efdesign987c0c64e2011-06-20 19:56:06 -070043 /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */
efdesign984b508342011-07-13 17:16:13 -070044
efdesign987c0c64e2011-06-20 19:56:06 -070045 movl %cr4, %eax
46 orl $(3<<9), %eax
efdesign984b508342011-07-13 17:16:13 -070047 movl %eax, %cr4
48
efdesign987c0c64e2011-06-20 19:56:06 -070049 /* Get the cpu_init_detected */
50 mov $1, %eax
51 cpuid
52 shr $24, %ebx
efdesign984b508342011-07-13 17:16:13 -070053
efdesign987c0c64e2011-06-20 19:56:06 -070054 /* Save the BIST result */
55 cvtsi2sd %ebp, %xmm0
efdesign984b508342011-07-13 17:16:13 -070056
efdesign987c0c64e2011-06-20 19:56:06 -070057 /* for normal part %ebx already contain cpu_init_detected from fallback call */
efdesign984b508342011-07-13 17:16:13 -070058
efdesign987c0c64e2011-06-20 19:56:06 -070059 /* Save the cpu_init_detected */
60 cvtsi2sd %ebx, %xmm1
efdesign984b508342011-07-13 17:16:13 -070061
efdesign987c0c64e2011-06-20 19:56:06 -070062 post_code(0xa1)
efdesign984b508342011-07-13 17:16:13 -070063
Kyösti Mälkkif6fe2f12016-11-21 11:26:48 +020064 AMD_ENABLE_STACK
65
Kyösti Mälkki26929bd2016-11-23 20:40:53 +020066 /* Align the stack. */
67 and $0xFFFFFFF0, %esp
68
Stefan Reinauer67b94302015-06-18 01:14:01 -070069#ifdef __x86_64__
70 /* switch to 64 bit long mode */
Patrick Georgi4a30ab92016-01-22 12:26:52 +010071 mov %esi, %ecx
72 add $0, %ecx # core number
73 xor %eax, %eax
74 lea (0x1000+0x23)(%ecx), %edi
75 mov %edi, (%ecx)
76 mov %eax, 4(%ecx)
Stefan Reinauer67b94302015-06-18 01:14:01 -070077
Patrick Georgi4a30ab92016-01-22 12:26:52 +010078 lea 0x1000(%ecx), %edi
79 movl $0x000000e3, 0x00(%edi)
80 movl %eax, 0x04(%edi)
81 movl $0x400000e3, 0x08(%edi)
82 movl %eax, 0x0c(%edi)
83 movl $0x800000e3, 0x10(%edi)
84 movl %eax, 0x14(%edi)
85 movl $0xc00000e3, 0x18(%edi)
86 movl %eax, 0x1c(%edi)
Stefan Reinauer67b94302015-06-18 01:14:01 -070087
Elyes HAOUAS585d1a02016-07-28 19:15:34 +020088 # load ROM based identity mapped page tables
Patrick Georgi4a30ab92016-01-22 12:26:52 +010089 mov %ecx, %eax
90 mov %eax, %cr3
Stefan Reinauer67b94302015-06-18 01:14:01 -070091
92 # enable PAE
Patrick Georgi4a30ab92016-01-22 12:26:52 +010093 mov %cr4, %eax
94 bts $5, %eax
95 mov %eax, %cr4
Stefan Reinauer67b94302015-06-18 01:14:01 -070096
97 # enable long mode
Patrick Georgi4a30ab92016-01-22 12:26:52 +010098 mov $0xC0000080, %ecx
Stefan Reinauer67b94302015-06-18 01:14:01 -070099 rdmsr
Patrick Georgi4a30ab92016-01-22 12:26:52 +0100100 bts $8, %eax
Stefan Reinauer67b94302015-06-18 01:14:01 -0700101 wrmsr
102
103 # enable paging
Patrick Georgi4a30ab92016-01-22 12:26:52 +0100104 mov %cr0, %eax
105 bts $31, %eax
106 mov %eax, %cr0
Stefan Reinauer67b94302015-06-18 01:14:01 -0700107
108 # use call far to switch to 64-bit code segment
Patrick Georgi4a30ab92016-01-22 12:26:52 +0100109 ljmp $0x18, $1f
1101:
Kyösti Mälkki13cf1352016-11-21 07:37:13 +0200111
112 .code64
113
114 call early_all_cores
115
Kyösti Mälkkif6fe2f12016-11-21 11:26:48 +0200116 /* Pass the cpu_init_detected */
Patrick Georgi4a30ab92016-01-22 12:26:52 +0100117 cvtsd2si %xmm1, %esi
Stefan Reinauer67b94302015-06-18 01:14:01 -0700118
Kyösti Mälkkif6fe2f12016-11-21 11:26:48 +0200119 /* Pass the BIST result */
Patrick Georgi4a30ab92016-01-22 12:26:52 +0100120 cvtsd2si %xmm0, %edi
Stefan Reinauer67b94302015-06-18 01:14:01 -0700121
Stefan Reinauer67b94302015-06-18 01:14:01 -0700122 call cache_as_ram_main
123 .code32
124
Stefan Reinauer67b94302015-06-18 01:14:01 -0700125#else
efdesign984b508342011-07-13 17:16:13 -0700126
Kyösti Mälkki13cf1352016-11-21 07:37:13 +0200127 call early_all_cores
128
efdesign987c0c64e2011-06-20 19:56:06 -0700129 /* Restore the BIST result */
130 cvtsd2si %xmm0, %edx
efdesign984b508342011-07-13 17:16:13 -0700131
efdesign987c0c64e2011-06-20 19:56:06 -0700132 /* Restore the cpu_init_detected */
133 cvtsd2si %xmm1, %ebx
efdesign984b508342011-07-13 17:16:13 -0700134
Kyösti Mälkki26929bd2016-11-23 20:40:53 +0200135 /* Must maintain 16-byte stack alignment here. */
136 pushl $0x0
137 pushl $0x0
efdesign987c0c64e2011-06-20 19:56:06 -0700138 pushl %ebx /* init detected */
139 pushl %edx /* bist */
140 call cache_as_ram_main
Stefan Reinauer67b94302015-06-18 01:14:01 -0700141#endif
efdesign984b508342011-07-13 17:16:13 -0700142
143 /* Should never see this postcode */
144 post_code(0xaf)
efdesign987c0c64e2011-06-20 19:56:06 -0700145stop:
146 jmp stop
147
148disable_cache_as_ram:
149 /* Save return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600150 movd 0(%esp), %xmm1
efdesign984b508342011-07-13 17:16:13 -0700151 movd %esp, %xmm0
152
zbaof7223732012-04-13 13:42:15 +0800153 /* Disable cache */
154 movl %cr0, %eax
Patrick Georgi05e740f2012-03-31 12:52:21 +0200155 orl $CR0_CacheDisable, %eax
zbaof7223732012-04-13 13:42:15 +0800156 movl %eax, %cr0
157
efdesign987c0c64e2011-06-20 19:56:06 -0700158 AMD_DISABLE_STACK
efdesign984b508342011-07-13 17:16:13 -0700159
Siyuan Wangf3b86b32012-11-01 18:51:15 +0800160 /* enable cache */
161 movl %cr0, %eax
162 andl $0x9fffffff, %eax
163 movl %eax, %cr0
164 xorl %eax, %eax
165
efdesign987c0c64e2011-06-20 19:56:06 -0700166 /* Restore the return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600167 wbinvd
efdesign984b508342011-07-13 17:16:13 -0700168 movd %xmm0, %esp
Bruce Griffith59c3a062013-08-12 01:53:13 -0600169 movd %xmm1, (%esp)
efdesign987c0c64e2011-06-20 19:56:06 -0700170 ret
efdesign984b508342011-07-13 17:16:13 -0700171
efdesign987c0c64e2011-06-20 19:56:06 -0700172cache_as_ram_setup_out:
Stefan Reinauer67b94302015-06-18 01:14:01 -0700173#ifdef __x86_64__
174.code64
175#endif