0a91326b858190d772633614c507da78a9d80677
[coreboot.git] / src / cpu / amd / car / post_cache_as_ram.c
1 /* 2005.6 by yhlu 
2  * 2006.3 yhlu add copy data from CAR to ram
3  */
4 #include "cpu/amd/car/disable_cache_as_ram.c"
5
6 #include "cpu/amd/car/clear_init_ram.c"
7
8 static inline void print_debug_pcar(const char *strval, uint32_t val)
9 {
10 #if CONFIG_USE_INIT
11         printk_debug("%s%08x\r\n", strval, val);
12 #else
13         print_debug(strval); print_debug_hex32(val); print_debug("\r\n");
14 #endif
15 }
16
17 static void inline __attribute__((always_inline))  memcopy(void *dest, const void *src, unsigned long bytes)
18 {
19         __asm__ volatile(
20                 "cld\n\t"
21                 "rep movsl\n\t"
22                 : /* No outputs */
23                 : "S" (src), "D" (dest), "c" ((bytes)>>2)
24                 );
25 }
26
27 static void post_cache_as_ram(void)
28 {
29
30 #if 1
31         {
32         /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
33         unsigned v_esp;
34         __asm__ volatile (
35                 "movl   %%esp, %0\n\t"
36                 : "=a" (v_esp)
37         );
38         print_debug_pcar("v_esp=", v_esp);
39         }
40 #endif
41
42         unsigned testx = 0x5a5a5a5a;
43         print_debug_pcar("testx = ", testx);
44
45         /* copy data from cache as ram to 
46                 ram need to set CONFIG_LB_MEM_TOPK to 2048 and use var mtrr instead.
47          */
48 #if CONFIG_LB_MEM_TOPK <= 1024
49         #error "You need to set CONFIG_LB_MEM_TOPK greater than 1024"
50 #endif
51         
52         set_init_ram_access();
53
54         print_debug("Copying data from cache to ram -- switching to use ram as stack... ");
55
56         /* from here don't store more data in CAR */
57         __asm__ volatile (
58                 "pushl  %eax\n\t"
59         );
60         memcopy((CONFIG_LB_MEM_TOPK<<10)-DCACHE_RAM_SIZE, DCACHE_RAM_BASE, DCACHE_RAM_SIZE); //inline
61         __asm__ volatile (
62                 /* set new esp */ /* before _RAMBASE */
63                 "subl   %0, %%ebp\n\t"
64                 "subl   %0, %%esp\n\t"
65                 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- (CONFIG_LB_MEM_TOPK<<10) )
66         ); // We need to push %eax to the stack (CAR) before copy stack and pop it later after copy stack and change esp
67         __asm__ volatile (
68                 "popl   %eax\n\t"
69         );
70         /* We can put data to stack again */
71
72         /* only global variable sysinfo in cache need to be offset */
73         print_debug("Done\r\n");
74         print_debug_pcar("testx = ", testx);
75
76         print_debug("Disabling cache as ram now \r\n");
77         disable_cache_as_ram_bsp();  
78
79         print_debug("Clearing initial memory region: ");
80         clear_init_ram(); //except the range from [(CONFIG_LB_MEM_TOPK<<10) - DCACHE_RAM_SIZE, (CONFIG_LB_MEM_TOPK<<10)), that is used as stack in ram
81         print_debug("Done\r\n");
82
83         /*copy and execute linuxbios_ram */
84         copy_and_run();
85         /* We will not return */
86
87         print_debug("should not be here -\r\n");
88
89 }
90