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