blob: 09302d7d0e85e9840abb5d03d60852dd79de6a66 [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 *
Kyösti Mälkki7076aa52017-09-02 16:20:15 +030019 * $Workfile:: cache_as_ram.S
efdesign987c0c64e2011-06-20 19:56:06 -070020 *
Kyösti Mälkki7076aa52017-09-02 16:20:15 +030021 * Description: cache_as_ram.S - AGESA Module Entry Point for GCC complier
efdesign987c0c64e2011-06-20 19:56:06 -070022 *
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>
Kyösti Mälkki7076aa52017-09-02 16:20:15 +030028#include <cpu/x86/post_code.h>
efdesign987c0c64e2011-06-20 19:56:06 -070029
efdesign987c0c64e2011-06-20 19:56:06 -070030.code32
Kyösti Mälkki7076aa52017-09-02 16:20:15 +030031.globl _cache_as_ram_setup, _cache_as_ram_setup_end
Kyösti Mälkki63fac812017-09-02 16:41:43 +030032.globl chipset_teardown_car
efdesign987c0c64e2011-06-20 19:56:06 -070033
Kyösti Mälkki7076aa52017-09-02 16:20:15 +030034_cache_as_ram_setup:
efdesign984b508342011-07-13 17:16:13 -070035
Elyes HAOUASdea45c12018-12-27 09:14:07 +010036 /* Preserve BIST. */
37 movd %eax, %mm0
Kyösti Mälkki1779d532016-11-23 21:29:26 +020038
Elyes HAOUASdea45c12018-12-27 09:14:07 +010039 post_code(0xa0)
efdesign984b508342011-07-13 17:16:13 -070040
Elyes HAOUASdea45c12018-12-27 09:14:07 +010041 /* enable SSE2 128bit instructions */
42 /* Turn on OSFXSR [BIT9] and OSXMMEXCPT [BIT10] onto CR4 register */
efdesign984b508342011-07-13 17:16:13 -070043
Elyes HAOUASdea45c12018-12-27 09:14:07 +010044 movl %cr4, %eax
45 orl $(3 << 9), %eax
46 movl %eax, %cr4
efdesign984b508342011-07-13 17:16:13 -070047
Elyes HAOUASdea45c12018-12-27 09:14:07 +010048 post_code(0xa1)
efdesign984b508342011-07-13 17:16:13 -070049
Elyes HAOUASdea45c12018-12-27 09:14:07 +010050 AMD_ENABLE_STACK
Kyösti Mälkkif6fe2f12016-11-21 11:26:48 +020051
Elyes HAOUASdea45c12018-12-27 09:14:07 +010052 /* Align the stack. */
53 and $0xFFFFFFF0, %esp
Kyösti Mälkki26929bd2016-11-23 20:40:53 +020054
Stefan Reinauer67b94302015-06-18 01:14:01 -070055#ifdef __x86_64__
Elyes HAOUASdea45c12018-12-27 09:14:07 +010056 /* switch to 64 bit long mode */
57 mov %esi, %ecx
58 add $0, %ecx # core number
59 xor %eax, %eax
60 lea (0x1000+0x23)(%ecx), %edi
61 mov %edi, (%ecx)
62 mov %eax, 4(%ecx)
Stefan Reinauer67b94302015-06-18 01:14:01 -070063
Elyes HAOUASdea45c12018-12-27 09:14:07 +010064 lea 0x1000(%ecx), %edi
65 movl $0x000000e3, 0x00(%edi)
66 movl %eax, 0x04(%edi)
67 movl $0x400000e3, 0x08(%edi)
68 movl %eax, 0x0c(%edi)
69 movl $0x800000e3, 0x10(%edi)
70 movl %eax, 0x14(%edi)
71 movl $0xc00000e3, 0x18(%edi)
72 movl %eax, 0x1c(%edi)
Stefan Reinauer67b94302015-06-18 01:14:01 -070073
Elyes HAOUASdea45c12018-12-27 09:14:07 +010074 # load ROM based identity mapped page tables
75 mov %ecx, %eax
76 mov %eax, %cr3
Stefan Reinauer67b94302015-06-18 01:14:01 -070077
Elyes HAOUASdea45c12018-12-27 09:14:07 +010078 # enable PAE
79 mov %cr4, %eax
80 bts $5, %eax
81 mov %eax, %cr4
Stefan Reinauer67b94302015-06-18 01:14:01 -070082
Elyes HAOUASdea45c12018-12-27 09:14:07 +010083 # enable long mode
84 mov $0xC0000080, %ecx
85 rdmsr
86 bts $8, %eax
87 wrmsr
Stefan Reinauer67b94302015-06-18 01:14:01 -070088
Elyes HAOUASdea45c12018-12-27 09:14:07 +010089 # enable paging
90 mov %cr0, %eax
91 bts $31, %eax
92 mov %eax, %cr0
Stefan Reinauer67b94302015-06-18 01:14:01 -070093
Elyes HAOUASdea45c12018-12-27 09:14:07 +010094 # use call far to switch to 64-bit code segment
95 ljmp $0x18, $1f
Patrick Georgi4a30ab92016-01-22 12:26:52 +0100961:
Kyösti Mälkki13cf1352016-11-21 07:37:13 +020097
Kyösti Mälkkidf7ff312016-11-25 12:02:00 +020098#endif
efdesign984b508342011-07-13 17:16:13 -070099
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100100 call early_all_cores
efdesign984b508342011-07-13 17:16:13 -0700101
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100102 /* Must maintain 16-byte stack alignment here. */
103 pushl $0x0
104 pushl $0x0
105 pushl $0x0
106 movd %mm0, %eax /* bist */
107 pushl %eax
108 call romstage_main
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300109
110#if IS_ENABLED(CONFIG_POSTCAR_STAGE)
111
112/* We do not return. Execution continues with run_postcar_phase()
113 * calling to chipset_teardown_car below.
114 */
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100115 jmp postcar_entry_failure
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300116
117chipset_teardown_car:
118
119/*
120 * Retrieve return address from stack as it will get trashed below if
121 * execution is utilizing the cache-as-ram stack.
122 */
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100123 pop %esp
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300124
125#else
126
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100127 movl %eax, %esp
efdesign984b508342011-07-13 17:16:13 -0700128
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300129/* Register %esp is new stacktop for remaining of romstage. */
efdesign987c0c64e2011-06-20 19:56:06 -0700130
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300131#endif
132
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100133 /* Disable cache */
134 movl %cr0, %eax
135 orl $CR0_CacheDisable, %eax
136 movl %eax, %cr0
zbaof7223732012-04-13 13:42:15 +0800137
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300138/* Register %esp is preserved in AMD_DISABLE_STACK. */
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100139 AMD_DISABLE_STACK
efdesign984b508342011-07-13 17:16:13 -0700140
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300141#if IS_ENABLED(CONFIG_POSTCAR_STAGE)
142
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100143 jmp *%esp
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300144
145#else
146
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100147 /* enable cache */
148 movl %cr0, %eax
149 andl $0x9fffffff, %eax
150 movl %eax, %cr0
Siyuan Wangf3b86b32012-11-01 18:51:15 +0800151
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100152 call romstage_after_car
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200153
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300154#endif
155
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100156 /* Should never see this postcode */
157 post_code(0xaf)
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300158
Kyösti Mälkkiba22e152016-11-23 06:47:15 +0200159stop:
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100160 hlt
161 jmp stop
Kyösti Mälkki63fac812017-09-02 16:41:43 +0300162
163/* These are here for linking purposes. */
164.weak early_all_cores, romstage_main
165early_all_cores:
166romstage_main:
167postcar_entry_failure:
Elyes HAOUASdea45c12018-12-27 09:14:07 +0100168 /* Should never see this postcode */
169 post_code(0xae)
170 jmp stop
efdesign984b508342011-07-13 17:16:13 -0700171
Kyösti Mälkki7076aa52017-09-02 16:20:15 +0300172_cache_as_ram_setup_end: