blob: cfad2f7d1a3c1d6b0a0c65c49199d3aa2233f427 [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
efdesign987c0c64e2011-06-20 19:56:06 -070029.code32
Kyösti Mälkkiba22e152016-11-23 06:47:15 +020030.globl cache_as_ram_setup, cache_as_ram_setup_out
efdesign987c0c64e2011-06-20 19:56:06 -070031
32cache_as_ram_setup:
efdesign984b508342011-07-13 17:16:13 -070033
Kyösti Mälkki1779d532016-11-23 21:29:26 +020034 /* Preserve BIST. */
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +030035 movd %eax, %mm0
Kyösti Mälkki1779d532016-11-23 21:29:26 +020036
efdesign987c0c64e2011-06-20 19:56:06 -070037 post_code(0xa0)
efdesign984b508342011-07-13 17:16:13 -070038
39 /* enable SSE2 128bit instructions */
efdesign987c0c64e2011-06-20 19:56:06 -070040 /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */
efdesign984b508342011-07-13 17:16:13 -070041
efdesign987c0c64e2011-06-20 19:56:06 -070042 movl %cr4, %eax
Elyes HAOUAS168ef392017-06-27 22:54:42 +020043 orl $(3 << 9), %eax
efdesign984b508342011-07-13 17:16:13 -070044 movl %eax, %cr4
45
efdesign987c0c64e2011-06-20 19:56:06 -070046 post_code(0xa1)
efdesign984b508342011-07-13 17:16:13 -070047
Kyösti Mälkkif6fe2f12016-11-21 11:26:48 +020048 AMD_ENABLE_STACK
49
Kyösti Mälkki26929bd2016-11-23 20:40:53 +020050 /* Align the stack. */
51 and $0xFFFFFFF0, %esp
52
Stefan Reinauer67b94302015-06-18 01:14:01 -070053#ifdef __x86_64__
54 /* switch to 64 bit long mode */
Patrick Georgi4a30ab92016-01-22 12:26:52 +010055 mov %esi, %ecx
56 add $0, %ecx # core number
57 xor %eax, %eax
58 lea (0x1000+0x23)(%ecx), %edi
59 mov %edi, (%ecx)
60 mov %eax, 4(%ecx)
Stefan Reinauer67b94302015-06-18 01:14:01 -070061
Patrick Georgi4a30ab92016-01-22 12:26:52 +010062 lea 0x1000(%ecx), %edi
63 movl $0x000000e3, 0x00(%edi)
64 movl %eax, 0x04(%edi)
65 movl $0x400000e3, 0x08(%edi)
66 movl %eax, 0x0c(%edi)
67 movl $0x800000e3, 0x10(%edi)
68 movl %eax, 0x14(%edi)
69 movl $0xc00000e3, 0x18(%edi)
70 movl %eax, 0x1c(%edi)
Stefan Reinauer67b94302015-06-18 01:14:01 -070071
Elyes HAOUAS585d1a02016-07-28 19:15:34 +020072 # load ROM based identity mapped page tables
Patrick Georgi4a30ab92016-01-22 12:26:52 +010073 mov %ecx, %eax
74 mov %eax, %cr3
Stefan Reinauer67b94302015-06-18 01:14:01 -070075
76 # enable PAE
Patrick Georgi4a30ab92016-01-22 12:26:52 +010077 mov %cr4, %eax
78 bts $5, %eax
79 mov %eax, %cr4
Stefan Reinauer67b94302015-06-18 01:14:01 -070080
81 # enable long mode
Patrick Georgi4a30ab92016-01-22 12:26:52 +010082 mov $0xC0000080, %ecx
Stefan Reinauer67b94302015-06-18 01:14:01 -070083 rdmsr
Patrick Georgi4a30ab92016-01-22 12:26:52 +010084 bts $8, %eax
Stefan Reinauer67b94302015-06-18 01:14:01 -070085 wrmsr
86
87 # enable paging
Patrick Georgi4a30ab92016-01-22 12:26:52 +010088 mov %cr0, %eax
89 bts $31, %eax
90 mov %eax, %cr0
Stefan Reinauer67b94302015-06-18 01:14:01 -070091
92 # use call far to switch to 64-bit code segment
Patrick Georgi4a30ab92016-01-22 12:26:52 +010093 ljmp $0x18, $1f
941:
Kyösti Mälkki13cf1352016-11-21 07:37:13 +020095
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020096#endif
efdesign984b508342011-07-13 17:16:13 -070097
Kyösti Mälkki1779d532016-11-23 21:29:26 +020098 call early_all_cores
efdesign984b508342011-07-13 17:16:13 -070099
Kyösti Mälkki26929bd2016-11-23 20:40:53 +0200100 /* Must maintain 16-byte stack alignment here. */
101 pushl $0x0
102 pushl $0x0
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200103 pushl $0x0
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +0300104 movd %mm0, %eax /* bist */
105 pushl %eax
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +0200106 call romstage_main
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +0300107 movl %eax, %esp
efdesign984b508342011-07-13 17:16:13 -0700108
Kyösti Mälkkifec6fa72017-07-12 16:30:47 +0300109/* Register %esp is new stacktop for remaining of romstage.
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200110 * It is the only register preserved in AMD_DISABLE_STACK.
111 */
efdesign987c0c64e2011-06-20 19:56:06 -0700112
113disable_cache_as_ram:
zbaof7223732012-04-13 13:42:15 +0800114 /* Disable cache */
115 movl %cr0, %eax
Patrick Georgi05e740f2012-03-31 12:52:21 +0200116 orl $CR0_CacheDisable, %eax
zbaof7223732012-04-13 13:42:15 +0800117 movl %eax, %cr0
118
efdesign987c0c64e2011-06-20 19:56:06 -0700119 AMD_DISABLE_STACK
efdesign984b508342011-07-13 17:16:13 -0700120
Siyuan Wangf3b86b32012-11-01 18:51:15 +0800121 /* enable cache */
122 movl %cr0, %eax
123 andl $0x9fffffff, %eax
124 movl %eax, %cr0
Siyuan Wangf3b86b32012-11-01 18:51:15 +0800125
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200126 call romstage_after_car
127
128 /* Should never see this postcode */
129 post_code(0xaf)
130stop:
131 jmp stop
efdesign984b508342011-07-13 17:16:13 -0700132
efdesign987c0c64e2011-06-20 19:56:06 -0700133cache_as_ram_setup_out: