d4c6600247e8101c59b4fe4c2224bb0028207fe3
[coreboot.git] / src / cpu / amd / car / clear_1m_ram.c
1 /* by yhlu 6.2005 */
2 /* be warned, this file will be used core 0/node 0 only */
3 static inline __attribute__((always_inline)) void clear_1m_ram(void)
4 {
5         __asm__ volatile (
6
7         /* disable cache */
8         "movl    %%cr0, %%eax\n\t"
9         "orl    $(0x1<<30),%%eax\n\t"
10         "movl    %%eax, %%cr0\n\t"
11
12         /* enable caching for first 1M using variable mtrr */
13         "movl    $0x200, %%ecx\n\t"
14         "xorl    %%edx, %%edx\n\t"
15         "movl     $(0 | 1), %%eax\n\t"
16 //      "movl     $(0 | MTRR_TYPE_WRCOMB), %%eax\n\t"
17         "wrmsr\n\t"
18
19         "movl    $0x201, %%ecx\n\t"
20         "movl    $0x0000000f, %%edx\n\t" 
21 #if CONFIG_USE_INIT
22         "movl  %%esi, %%eax\n\t"
23 #else
24         "movl    $((~(( 0 + (CONFIG_LB_MEM_TOPK<<10) ) -1)) | 0x800), %%eax\n\t"
25 #endif
26         "wrmsr\n\t"
27
28         /* clear the first 1M */
29 #if CONFIG_USE_INIT
30         "movl    %%edi, %%ecx\n\t"
31 #else
32         "movl    $((CONFIG_LB_MEM_TOPK<<10)>>2), %%ecx\n\t"     
33 #endif
34         "xorl %%edi, %%edi\n\t"
35         "cld\n\t"
36         "xorl    %%eax, %%eax\n\t"
37         "rep     stosl\n\t"
38
39         /* disable cache */
40         "movl   %%cr0, %%eax\n\t"
41         "orl    $(0x1<<30),%%eax\n\t"
42         "movl    %%eax, %%cr0\n\t"
43
44         /* enable caching for first 1M using variable mtrr */
45         "movl    $0x200, %%ecx\n\t"
46         "xorl    %%edx, %%edx\n\t"
47         "movl     $(0 | 6), %%eax\n\t"
48 //      "movl     $(0 | MTRR_TYPE_WRBACK), %%eax\n\t"
49         "wrmsr\n\t"
50
51         "movl    $0x201, %%ecx\n\t"
52         "movl    $0x0000000f, %%edx\n\t" 
53 #if CONFIG_USE_INIT
54         "movl    %%esi, %%eax\n\t"
55 #else
56         "movl    $((~(( 0 + (CONFIG_LB_MEM_TOPK<<10) ) -1)) | 0x800), %%eax\n\t"
57 #endif
58         "wrmsr\n\t"
59
60         /* enable cache */
61         "movl    %%cr0, %%eax\n\t"
62         "andl    $0x9fffffff,%%eax\n\t"
63         "movl    %%eax, %%cr0\n\t"
64         "invd\n\t"
65         :
66         :
67 #if CONFIG_USE_INIT
68         "S"((~(( 0 + (CONFIG_LB_MEM_TOPK<<10) ) -1)) | 0x800), "D" ((CONFIG_LB_MEM_TOPK<<10)>>2)
69 #endif
70         );
71 }