6a129b258a60fa8b42699045b37b444013ba6676
[coreboot.git] / src / cpu / amd / car / cache_as_ram_post.c
1 /* by yhlu 6.2005 */
2 /* be warned, this file will be used other cores and core0/node0 */
3         __asm__ volatile (
4         /* 
5         FIXME : backup stack in CACHE_AS_RAM into mmx and sse and after we get STACK up, we restore that.
6                 It is only needed if we want to go back
7         */
8         
9         /* We don't need cache as ram for now on */
10         /* disable cache */
11         "movl    %cr0, %eax\n\t"
12         "orl    $(0x1<<30),%eax\n\t"
13         "movl    %eax, %cr0\n\t"
14
15         /* clear sth */
16         "movl    $0x269, %ecx\n\t"  /* fix4k_c8000*/
17         "xorl    %edx, %edx\n\t"
18         "xorl    %eax, %eax\n\t"
19         "wrmsr\n\t"
20 #if DCACHE_RAM_SIZE > 0x8000
21         "movl    $0x268, %ecx\n\t"  /* fix4k_c0000*/
22         "wrmsr\n\t"
23 #endif
24
25         /* disable fixed mtrr from now on, it will be enabled by linuxbios_ram again*/
26         "movl    $0xC0010010, %ecx\n\t"
27 //        "movl    $SYSCFG_MSR, %ecx\n\t"
28         "rdmsr\n\t"
29         "andl    $(~(3<<18)), %eax\n\t"
30 //        "andl    $(~(SYSCFG_MSR_MtrrFixDramModEn | SYSCFG_MSR_MtrrFixDramEn)), %eax\n\t"
31         "wrmsr\n\t"
32
33         /* Set the default memory type and disable fixed and enable variable MTRRs */
34         "movl    $0x2ff, %ecx\n\t"
35 //        "movl    $MTRRdefType_MSR, %ecx\n\t"
36         "xorl    %edx, %edx\n\t"
37         /* Enable Variable and Disable Fixed MTRRs */
38         "movl    $0x00000800, %eax\n\t"
39         "wrmsr\n\t"
40
41 #if defined(CLEAR_FIRST_1M_RAM)
42         /* enable caching for first 1M using variable mtrr */
43         "movl    $0x200, %ecx\n\t"
44         "xorl    %edx, %edx\n\t"
45         "movl     $(0 | 1), %eax\n\t"
46 //      "movl     $(0 | MTRR_TYPE_WRCOMB), %eax\n\t"
47         "wrmsr\n\t"
48
49         "movl    $0x201, %ecx\n\t"
50         "movl    $0x0000000f, %edx\n\t" 
51         "movl    $((~(( 0 + 0x100000) - 1)) | 0x800), %eax\n\t"
52         "wrmsr\n\t"
53 #endif
54
55         /* enable cache */
56         "movl    %cr0, %eax\n\t"
57         "andl    $0x9fffffff,%eax\n\t"
58         "movl    %eax, %cr0\n\t"
59 #if defined(CLEAR_FIRST_1M_RAM)
60         /* clear the first 1M */
61         "movl    $0x0, %edi\n\t"
62         "cld\n\t"
63         "movl    $(0x100000>>2), %ecx\n\t"
64         "xorl    %eax, %eax\n\t"
65         "rep     stosl\n\t"
66
67         /* disable cache */
68         "movl    %cr0, %eax\n\t"
69         "orl    $(0x1<<30),%eax\n\t"
70         "movl    %eax, %cr0\n\t"
71
72         /* enable caching for first 1M using variable mtrr */
73         "movl    $0x200, %ecx\n\t"
74         "xorl    %edx, %edx\n\t"
75         "movl     $(0 | 6), %eax\n\t"
76 //      "movl     $(0 | MTRR_TYPE_WRBACK), %eax\n\t"
77         "wrmsr\n\t"
78
79         "movl    $0x201, %ecx\n\t"
80         "movl    $0x0000000f, %edx\n\t" 
81         "movl    $((~(( 0 + 0x100000) - 1)) | 0x800), %eax\n\t"
82         "wrmsr\n\t"
83
84         /* enable cache */
85         "movl    %cr0, %eax\n\t"
86         "andl    $0x9fffffff,%eax\n\t"
87         "movl    %eax, %cr0\n\t"
88         "invd\n\t"
89
90         /* 
91         FIXME: I hope we don't need to change esp and ebp value here, so we can restore value from mmx sse back
92                 But the problem is the range is some io related, So don't go back
93         */
94 #endif
95         );