blob: 2a9beb8aa454d3f65e9cb5b22642143875a6362a [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
efdesign987c0c64e2011-06-20 19:56:06 -070032 */
33
34.code32
35.globl cache_as_ram_setup, disable_cache_as_ram, cache_as_ram_setup_out
36
37cache_as_ram_setup:
efdesign984b508342011-07-13 17:16:13 -070038
efdesign987c0c64e2011-06-20 19:56:06 -070039 post_code(0xa0)
efdesign984b508342011-07-13 17:16:13 -070040
41 /* enable SSE2 128bit instructions */
efdesign987c0c64e2011-06-20 19:56:06 -070042 /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */
efdesign984b508342011-07-13 17:16:13 -070043
efdesign987c0c64e2011-06-20 19:56:06 -070044 movl %cr4, %eax
45 orl $(3<<9), %eax
efdesign984b508342011-07-13 17:16:13 -070046 movl %eax, %cr4
47
efdesign987c0c64e2011-06-20 19:56:06 -070048 /* Save the BIST result */
49 cvtsi2sd %ebp, %xmm0
efdesign984b508342011-07-13 17:16:13 -070050
efdesign987c0c64e2011-06-20 19:56:06 -070051 post_code(0xa1)
efdesign984b508342011-07-13 17:16:13 -070052
Kyösti Mälkkif6fe2f12016-11-21 11:26:48 +020053 AMD_ENABLE_STACK
54
Kyösti Mälkki26929bd2016-11-23 20:40:53 +020055 /* Align the stack. */
56 and $0xFFFFFFF0, %esp
57
Stefan Reinauer67b94302015-06-18 01:14:01 -070058#ifdef __x86_64__
59 /* switch to 64 bit long mode */
Patrick Georgi4a30ab92016-01-22 12:26:52 +010060 mov %esi, %ecx
61 add $0, %ecx # core number
62 xor %eax, %eax
63 lea (0x1000+0x23)(%ecx), %edi
64 mov %edi, (%ecx)
65 mov %eax, 4(%ecx)
Stefan Reinauer67b94302015-06-18 01:14:01 -070066
Patrick Georgi4a30ab92016-01-22 12:26:52 +010067 lea 0x1000(%ecx), %edi
68 movl $0x000000e3, 0x00(%edi)
69 movl %eax, 0x04(%edi)
70 movl $0x400000e3, 0x08(%edi)
71 movl %eax, 0x0c(%edi)
72 movl $0x800000e3, 0x10(%edi)
73 movl %eax, 0x14(%edi)
74 movl $0xc00000e3, 0x18(%edi)
75 movl %eax, 0x1c(%edi)
Stefan Reinauer67b94302015-06-18 01:14:01 -070076
Elyes HAOUAS585d1a02016-07-28 19:15:34 +020077 # load ROM based identity mapped page tables
Patrick Georgi4a30ab92016-01-22 12:26:52 +010078 mov %ecx, %eax
79 mov %eax, %cr3
Stefan Reinauer67b94302015-06-18 01:14:01 -070080
81 # enable PAE
Patrick Georgi4a30ab92016-01-22 12:26:52 +010082 mov %cr4, %eax
83 bts $5, %eax
84 mov %eax, %cr4
Stefan Reinauer67b94302015-06-18 01:14:01 -070085
86 # enable long mode
Patrick Georgi4a30ab92016-01-22 12:26:52 +010087 mov $0xC0000080, %ecx
Stefan Reinauer67b94302015-06-18 01:14:01 -070088 rdmsr
Patrick Georgi4a30ab92016-01-22 12:26:52 +010089 bts $8, %eax
Stefan Reinauer67b94302015-06-18 01:14:01 -070090 wrmsr
91
92 # enable paging
Patrick Georgi4a30ab92016-01-22 12:26:52 +010093 mov %cr0, %eax
94 bts $31, %eax
95 mov %eax, %cr0
Stefan Reinauer67b94302015-06-18 01:14:01 -070096
97 # use call far to switch to 64-bit code segment
Patrick Georgi4a30ab92016-01-22 12:26:52 +010098 ljmp $0x18, $1f
991:
Kyösti Mälkki13cf1352016-11-21 07:37:13 +0200100
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200101#endif
efdesign984b508342011-07-13 17:16:13 -0700102
Kyösti Mälkki13cf1352016-11-21 07:37:13 +0200103 call early_all_cores
104
efdesign987c0c64e2011-06-20 19:56:06 -0700105 /* Restore the BIST result */
106 cvtsd2si %xmm0, %edx
efdesign984b508342011-07-13 17:16:13 -0700107
Kyösti Mälkki26929bd2016-11-23 20:40:53 +0200108 /* Must maintain 16-byte stack alignment here. */
109 pushl $0x0
110 pushl $0x0
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200111 pushl $0x0
efdesign987c0c64e2011-06-20 19:56:06 -0700112 pushl %edx /* bist */
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200113 call romstage_main
efdesign984b508342011-07-13 17:16:13 -0700114
115 /* Should never see this postcode */
116 post_code(0xaf)
efdesign987c0c64e2011-06-20 19:56:06 -0700117stop:
118 jmp stop
119
120disable_cache_as_ram:
121 /* Save return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600122 movd 0(%esp), %xmm1
efdesign984b508342011-07-13 17:16:13 -0700123 movd %esp, %xmm0
124
zbaof7223732012-04-13 13:42:15 +0800125 /* Disable cache */
126 movl %cr0, %eax
Patrick Georgi05e740f2012-03-31 12:52:21 +0200127 orl $CR0_CacheDisable, %eax
zbaof7223732012-04-13 13:42:15 +0800128 movl %eax, %cr0
129
efdesign987c0c64e2011-06-20 19:56:06 -0700130 AMD_DISABLE_STACK
efdesign984b508342011-07-13 17:16:13 -0700131
Siyuan Wangf3b86b32012-11-01 18:51:15 +0800132 /* enable cache */
133 movl %cr0, %eax
134 andl $0x9fffffff, %eax
135 movl %eax, %cr0
136 xorl %eax, %eax
137
efdesign987c0c64e2011-06-20 19:56:06 -0700138 /* Restore the return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600139 wbinvd
efdesign984b508342011-07-13 17:16:13 -0700140 movd %xmm0, %esp
Bruce Griffith59c3a062013-08-12 01:53:13 -0600141 movd %xmm1, (%esp)
efdesign987c0c64e2011-06-20 19:56:06 -0700142 ret
efdesign984b508342011-07-13 17:16:13 -0700143
efdesign987c0c64e2011-06-20 19:56:06 -0700144cache_as_ram_setup_out: