- copy_and_run() gets the same calling convention on AMD and on all the others.
[coreboot.git] / src / cpu / via / car / cache_as_ram.inc
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com>
5  * Copyright (C) 2005 Eswar Nallusamy, LANL
6  * Copyright (C) 2005 Tyan
7  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
8  * Copyright (C) 2007 coresystems GmbH
9  * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
10  * Copyright (C) 2007,2008 Carl-Daniel Hailfinger
11  * Copyright (C) 2008 VIA Technologies, Inc.
12  * (Written by Jason Zhao <jasonzhao@viatech.com.cn> for VIA)
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; version 2 of the License.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
26  */
27
28 #define CacheSize CONFIG_DCACHE_RAM_SIZE
29 #define CacheBase CONFIG_DCACHE_RAM_BASE
30
31
32 #include <cpu/x86/mtrr.h>
33
34         /* Save the BIST result */
35         movl    %eax, %ebp
36
37 CacheAsRam:
38
39         /* disable cache */
40         movl    %cr0, %eax
41         orl     $(0x1<<30),%eax
42         movl    %eax,%cr0
43         invd
44
45         /* Set the default memory type and enable fixed and variable MTRRs */
46         movl    $MTRRdefType_MSR, %ecx
47         xorl    %edx, %edx
48         /* Enable Variable and Fixed MTRRs */
49         movl    $0x00000c00, %eax
50         wrmsr
51
52         /* Clear all MTRRs */
53         xorl    %edx, %edx
54         movl    $fixed_mtrr_msr, %esi
55
56 clear_fixed_var_mtrr:
57         lodsl   (%esi), %eax
58         testl   %eax, %eax
59         jz      clear_fixed_var_mtrr_out
60
61         movl    %eax, %ecx
62         xorl    %eax, %eax
63         wrmsr
64
65         jmp     clear_fixed_var_mtrr
66 clear_fixed_var_mtrr_out:
67         /* MTRRPhysBase */
68         movl    $0x200, %ecx
69         xorl    %edx, %edx
70         movl    $(CacheBase|MTRR_TYPE_WRBACK),%eax
71         wrmsr
72
73         /* MTRRPhysMask */
74         movl    $0x201, %ecx
75         /* This assumes we never access addresses above 2^36 in CAR. */
76         movl    $0x0000000f,%edx
77         movl    $(~(CacheSize-1)|0x800),%eax
78         wrmsr
79
80         /* enable write base caching so we can do execute in place
81          * on the flash rom.
82          */
83         /* MTRRPhysBase */
84         movl    $0x202, %ecx
85         xorl    %edx, %edx
86 #if defined(CONFIG_TINY_BOOTBLOCK) && CONFIG_TINY_BOOTBLOCK
87 #define REAL_XIP_ROM_BASE AUTO_XIP_ROM_BASE
88 #else
89 #define REAL_XIP_ROM_BASE CONFIG_XIP_ROM_BASE
90 #endif
91         movl    $REAL_XIP_ROM_BASE, %eax
92         orl     $MTRR_TYPE_WRBACK, %eax
93         wrmsr
94
95         /* MTRRPhysMask */
96         movl    $0x203, %ecx
97         movl    $0x0000000f, %edx
98         movl    $(~(CONFIG_XIP_ROM_SIZE - 1) | 0x800), %eax
99         wrmsr
100
101         movl    $MTRRdefType_MSR, %ecx
102         xorl    %edx, %edx
103         /* Enable Variable and Fixed MTRRs */
104         movl    $0x00000800, %eax
105         wrmsr
106
107         movl    %cr0, %eax
108         andl    $0x9fffffff, %eax
109         movl    %eax, %cr0
110
111         /* Read the range with lodsl*/
112         cld
113         movl    $CacheBase, %esi
114         movl    %esi, %edi
115         movl    $(CacheSize>>2), %ecx
116         rep     lodsl
117
118         movl    $CacheBase, %esi
119         movl    %esi, %edi
120         movl    $(CacheSize >> 2), %ecx
121
122         /* 0x5c5c5c5c is a memory test pattern.
123          * TODO: Check if everything works with the zero pattern as well. */
124         /*xorl  %eax, %eax*/
125         xorl    $0x5c5c5c5c,%eax
126         rep     stosl
127
128         movl    CONFIG_XIP_ROM_BASE, %esi
129         movl    %esi, %edi
130         movl    $(CONFIG_XIP_ROM_SIZE>>2), %ecx
131         rep     lodsl
132
133         /* The key point of this CAR code is C7 cache does not turn into
134          * "no fill" mode, which is not compatible with general CAR code.
135          */
136
137         movl    $(CacheBase + CacheSize - 4), %eax
138         movl    %eax, %esp
139
140 #ifdef CARTEST
141 testok: movb $0x40,%al
142         outb %al, $0x80
143         xorl    %edx, %edx
144         xorl    %eax, %eax
145         movl    $0x5c5c,%edx
146         pushl %edx
147         pushl %edx
148         pushl %edx
149         pushl %edx
150         pushl %edx
151         popl    %esi
152         popl    %esi
153         popl    %eax
154         popl    %eax
155         popl    %eax
156         cmpl %edx,%eax
157         jne stackerr
158 #endif
159
160         /* Restore the BIST result */
161         movl    %ebp, %eax
162
163         /* We need to set ebp ? No need */
164         movl    %esp, %ebp
165         pushl   %eax  /* bist */
166         call    stage1_main
167         /* We will not go back */
168
169 fixed_mtrr_msr:
170         .long   0x250, 0x258, 0x259
171         .long   0x268, 0x269, 0x26A
172         .long   0x26B, 0x26C, 0x26D
173         .long   0x26E, 0x26F
174 var_mtrr_msr:
175         .long   0x200, 0x201, 0x202, 0x203
176         .long   0x204, 0x205, 0x206, 0x207
177         .long   0x208, 0x209, 0x20A, 0x20B
178         .long   0x20C, 0x20D, 0x20E, 0x20F
179         .long   0x000 /* NULL, end of table */