blob: 1258d154c38b5f7b947911ad1e5e7cb0437b327b [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:
efdesign987c0c64e2011-06-20 19:56:06 -070031 */
32
33.code32
34.globl cache_as_ram_setup, disable_cache_as_ram, cache_as_ram_setup_out
35
36cache_as_ram_setup:
efdesign984b508342011-07-13 17:16:13 -070037
Kyösti Mälkki1779d532016-11-23 21:29:26 +020038 /* Preserve BIST. */
39 movl %eax, %ebp
40
efdesign987c0c64e2011-06-20 19:56:06 -070041 post_code(0xa0)
efdesign984b508342011-07-13 17:16:13 -070042
43 /* enable SSE2 128bit instructions */
efdesign987c0c64e2011-06-20 19:56:06 -070044 /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */
efdesign984b508342011-07-13 17:16:13 -070045
efdesign987c0c64e2011-06-20 19:56:06 -070046 movl %cr4, %eax
47 orl $(3<<9), %eax
efdesign984b508342011-07-13 17:16:13 -070048 movl %eax, %cr4
49
efdesign987c0c64e2011-06-20 19:56:06 -070050 post_code(0xa1)
efdesign984b508342011-07-13 17:16:13 -070051
Kyösti Mälkki1779d532016-11-23 21:29:26 +020052 /* NOTE: %ebx, %ebp are preserved in AMD_ENABLE_STACK. */
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älkki1779d532016-11-23 21:29:26 +0200103 /* Calling conventions preserve BIST in %ebp. */
Kyösti Mälkki13cf1352016-11-21 07:37:13 +0200104
Kyösti Mälkki1779d532016-11-23 21:29:26 +0200105 call early_all_cores
efdesign984b508342011-07-13 17:16:13 -0700106
Kyösti Mälkki26929bd2016-11-23 20:40:53 +0200107 /* Must maintain 16-byte stack alignment here. */
108 pushl $0x0
109 pushl $0x0
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200110 pushl $0x0
Kyösti Mälkki1779d532016-11-23 21:29:26 +0200111 pushl %ebp
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200112 call romstage_main
efdesign984b508342011-07-13 17:16:13 -0700113
114 /* Should never see this postcode */
115 post_code(0xaf)
efdesign987c0c64e2011-06-20 19:56:06 -0700116stop:
117 jmp stop
118
119disable_cache_as_ram:
120 /* Save return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600121 movd 0(%esp), %xmm1
efdesign984b508342011-07-13 17:16:13 -0700122 movd %esp, %xmm0
123
zbaof7223732012-04-13 13:42:15 +0800124 /* Disable cache */
125 movl %cr0, %eax
Patrick Georgi05e740f2012-03-31 12:52:21 +0200126 orl $CR0_CacheDisable, %eax
zbaof7223732012-04-13 13:42:15 +0800127 movl %eax, %cr0
128
efdesign987c0c64e2011-06-20 19:56:06 -0700129 AMD_DISABLE_STACK
efdesign984b508342011-07-13 17:16:13 -0700130
Siyuan Wangf3b86b32012-11-01 18:51:15 +0800131 /* enable cache */
132 movl %cr0, %eax
133 andl $0x9fffffff, %eax
134 movl %eax, %cr0
135 xorl %eax, %eax
136
efdesign987c0c64e2011-06-20 19:56:06 -0700137 /* Restore the return stack */
Bruce Griffith59c3a062013-08-12 01:53:13 -0600138 wbinvd
efdesign984b508342011-07-13 17:16:13 -0700139 movd %xmm0, %esp
Bruce Griffith59c3a062013-08-12 01:53:13 -0600140 movd %xmm1, (%esp)
efdesign987c0c64e2011-06-20 19:56:06 -0700141 ret
efdesign984b508342011-07-13 17:16:13 -0700142
efdesign987c0c64e2011-06-20 19:56:06 -0700143cache_as_ram_setup_out: