blob: b19f03b0a688acd291ed645b733bafe650c420ae [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
efdesign987c0c64e2011-06-20 19:56:06 -070018 */
efdesign984b508342011-07-13 17:16:13 -070019
efdesign987c0c64e2011-06-20 19:56:06 -070020/******************************************************************************
21 * AMD Generic Encapsulated Software Architecture
22 *
23 * $Workfile:: cache_as_ram.inc
24 *
25 * Description: cache_as_ram.inc - AGESA Module Entry Point for GCC complier
26 *
27 ******************************************************************************
efdesign984b508342011-07-13 17:16:13 -070028 */
29
efdesign987c0c64e2011-06-20 19:56:06 -070030#include "gcccar.inc"
Patrick Georgi05e740f2012-03-31 12:52:21 +020031#include <cpu/x86/cache.h>
efdesign987c0c64e2011-06-20 19:56:06 -070032
33/*
34 * XMM map:
35 * xmm0: BIST
36 * xmm1: backup ebx -- cpu_init_detected
37 */
38
39.code32
40.globl cache_as_ram_setup, disable_cache_as_ram, cache_as_ram_setup_out
41
42cache_as_ram_setup:
efdesign984b508342011-07-13 17:16:13 -070043
efdesign987c0c64e2011-06-20 19:56:06 -070044 post_code(0xa0)
efdesign984b508342011-07-13 17:16:13 -070045
46 /* enable SSE2 128bit instructions */
efdesign987c0c64e2011-06-20 19:56:06 -070047 /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */
efdesign984b508342011-07-13 17:16:13 -070048
efdesign987c0c64e2011-06-20 19:56:06 -070049 movl %cr4, %eax
50 orl $(3<<9), %eax
efdesign984b508342011-07-13 17:16:13 -070051 movl %eax, %cr4
52
efdesign987c0c64e2011-06-20 19:56:06 -070053 /* Get the cpu_init_detected */
54 mov $1, %eax
55 cpuid
56 shr $24, %ebx
efdesign984b508342011-07-13 17:16:13 -070057
efdesign987c0c64e2011-06-20 19:56:06 -070058 /* Save the BIST result */
59 cvtsi2sd %ebp, %xmm0
efdesign984b508342011-07-13 17:16:13 -070060
efdesign987c0c64e2011-06-20 19:56:06 -070061 /* for normal part %ebx already contain cpu_init_detected from fallback call */
efdesign984b508342011-07-13 17:16:13 -070062
efdesign987c0c64e2011-06-20 19:56:06 -070063 /* Save the cpu_init_detected */
64 cvtsi2sd %ebx, %xmm1
efdesign984b508342011-07-13 17:16:13 -070065
efdesign987c0c64e2011-06-20 19:56:06 -070066 post_code(0xa1)
efdesign984b508342011-07-13 17:16:13 -070067
Stefan Reinauer67b94302015-06-18 01:14:01 -070068#ifdef __x86_64__
69 /* switch to 64 bit long mode */
70 .intel_syntax noprefix
71
72 mov ecx, esi
73 add ecx, 0 # core number
74 xor eax, eax
75 lea edi, [ecx+0x1000+0x23]
76 mov dword ptr [ecx+0], edi
77 mov dword ptr [ecx+4], eax
78
79 lea edi, [ecx+0x1000]
80 mov dword ptr [edi+0x00], 0x000000e3
81 mov dword ptr [edi+0x04], eax
82 mov dword ptr [edi+0x08], 0x400000e3
83 mov dword ptr [edi+0x0c], eax
84 mov dword ptr [edi+0x10], 0x800000e3
85 mov dword ptr [edi+0x14], eax
86 mov dword ptr [edi+0x18], 0xc00000e3
87 mov dword ptr [edi+0x1c], eax
88
89 # load rom based identity mapped page tables
90 mov eax, ecx
91 mov cr3,eax
92
93 # enable PAE
94 mov eax, cr4
95 bts eax, 5
96 mov cr4, eax
97
98 # enable long mode
99 mov ecx, 0xC0000080
100 rdmsr
101 bts eax, 8
102 wrmsr
103
104 # enable paging
105 mov eax, cr0
106 bts eax, 31
107 mov cr0, eax
108
109 # use call far to switch to 64-bit code segment
110 jmp 0x18,.+7
111
112 /* Pass the BIST result */
113 cvtsd2si esi, xmm1
114
115 /* Pass the cpu_init_detected */
116 cvtsd2si edi, xmm0
117
118 /* align the stack */
119 and esp, 0xFFFFFFF0
120
121 .code64
122 call cache_as_ram_main
123 .code32
124
125 .att_syntax prefix
126#else
127 AMD_ENABLE_STACK
efdesign984b508342011-07-13 17:16:13 -0700128
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
efdesign987c0c64e2011-06-20 19:56:06 -0700135 pushl %ebx /* init detected */
136 pushl %edx /* bist */
137 call cache_as_ram_main
Stefan Reinauer67b94302015-06-18 01:14:01 -0700138#endif
efdesign984b508342011-07-13 17:16:13 -0700139
140 /* Should never see this postcode */
141 post_code(0xaf)
efdesign987c0c64e2011-06-20 19:56:06 -0700142stop:
143 jmp stop
144
145disable_cache_as_ram:
146 /* Save return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600147 movd 0(%esp), %xmm1
efdesign984b508342011-07-13 17:16:13 -0700148 movd %esp, %xmm0
149
zbaof7223732012-04-13 13:42:15 +0800150 /* Disable cache */
151 movl %cr0, %eax
Patrick Georgi05e740f2012-03-31 12:52:21 +0200152 orl $CR0_CacheDisable, %eax
zbaof7223732012-04-13 13:42:15 +0800153 movl %eax, %cr0
154
efdesign987c0c64e2011-06-20 19:56:06 -0700155 AMD_DISABLE_STACK
efdesign984b508342011-07-13 17:16:13 -0700156
Siyuan Wangf3b86b32012-11-01 18:51:15 +0800157 /* enable cache */
158 movl %cr0, %eax
159 andl $0x9fffffff, %eax
160 movl %eax, %cr0
161 xorl %eax, %eax
162
efdesign987c0c64e2011-06-20 19:56:06 -0700163 /* Restore the return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600164 wbinvd
efdesign984b508342011-07-13 17:16:13 -0700165 movd %xmm0, %esp
Bruce Griffith59c3a062013-08-12 01:53:13 -0600166 movd %xmm1, (%esp)
efdesign987c0c64e2011-06-20 19:56:06 -0700167 ret
efdesign984b508342011-07-13 17:16:13 -0700168
efdesign987c0c64e2011-06-20 19:56:06 -0700169cache_as_ram_setup_out:
Stefan Reinauer67b94302015-06-18 01:14:01 -0700170#ifdef __x86_64__
171.code64
172#endif