fec59058227ddc0abc604ea5f656d51909651d7d
[coreboot.git] / src / cpu / amd / car / post_cache_as_ram.c
1
2 #include "cpu/amd/car/disable_cache_as_ram.c"
3
4 #include "cpu/amd/car/clear_1m_ram.c"
5
6 static inline void print_debug_pcar(const char *strval, uint32_t val)
7 {
8 #if CONFIG_USE_INIT
9         printk_debug("%s%08x\r\n", strval, val);
10 #else
11         print_debug(strval); print_debug_hex32(val); print_debug("\r\n");
12 #endif
13 }
14
15
16
17 static void post_cache_as_ram(unsigned cpu_reset)
18 {
19
20
21 #if 1
22         {
23         /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
24         unsigned v_esp;
25         __asm__ volatile (
26                 "movl   %%esp, %0\n\t"
27                 : "=a" (v_esp)
28         );
29         print_debug_pcar("v_esp=", v_esp);
30         }
31 #endif
32
33         print_debug_pcar("cpu_reset = ",cpu_reset);
34
35         if(cpu_reset == 0) {
36                 print_debug("Clearing initial memory region: ");
37         }
38         print_debug("No cache as ram now - ");
39
40         /* store cpu_reset to ebx */
41         __asm__ volatile (
42                 "movl %0, %%ebx\n\t"
43                 ::"a" (cpu_reset)
44         );
45
46         disable_cache_as_ram();
47
48         if(cpu_reset==0) { // cpu_reset don't need to clear it 
49                 clear_1m_ram();
50         }
51
52 #if 0
53         int i;
54         for(i=0;i<0x800000;i++) {
55                 outb(0x66, 0x80);
56         }
57 #endif
58
59         __asm__ volatile (
60                 /* set new esp */ /* before _RAMBASE */
61                 "subl   %0, %%ebp\n\t"
62                 "subl   %0, %%esp\n\t"
63                 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- _RAMBASE )
64         );
65
66        {
67                 unsigned new_cpu_reset;
68
69                 /* get back cpu_reset from ebx */
70                 __asm__ volatile (
71                         "movl %%ebx, %0\n\t"
72                         :"=a" (new_cpu_reset)
73                 );
74
75                 print_debug("Use Ram as Stack now - "); /* but We can not go back any more, we lost old stack data in cache as ram*/
76
77                 if(new_cpu_reset==0) {
78                         print_debug("done\r\n");
79                 } else
80                 {
81                         print_debug("\r\n");
82                 }
83
84                 print_debug_pcar("new_cpu_reset = ", new_cpu_reset);
85
86
87                 /*copy and execute linuxbios_ram */
88                 copy_and_run(new_cpu_reset);
89                 /* We will not return */
90         }
91
92         print_debug("should not be here -\r\n");
93
94 }
95