summaryrefslogtreecommitdiff
path: root/src/cpu/amd/car/post_cache_as_ram.c
blob: b78ce77211789af87ab9e6a3a1ba95eaf31120c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
static void post_cache_as_ram(unsigned cpu_reset)
{


#if 1
        {
        /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
        unsigned v_esp;
        __asm__ volatile (
                "movl   %%esp, %0\n\t"
                : "=a" (v_esp)
        );
#if CONFIG_USE_INIT
        printk_debug("v_esp=%08x\r\n", v_esp);
#else
        print_debug("v_esp="); print_debug_hex32(v_esp); print_debug("\r\n");
#endif
        }
#endif

#if CONFIG_USE_INIT
        printk_debug("cpu_reset = %08x\r\n",cpu_reset);
#else
        print_debug("cpu_reset = "); print_debug_hex32(cpu_reset); print_debug("\r\n");
#endif

        if(cpu_reset == 0) {
                print_debug("Clearing initial memory region: ");
        }
        print_debug("No cache as ram now - ");

        /* store cpu_reset to ebx */
        __asm__ volatile (
                "movl %0, %%ebx\n\t"
                ::"a" (cpu_reset)
        );

#include "cpu/amd/car/disable_cache_as_ram.c"

        if(cpu_reset==0) { // cpu_reset don't need to clear it 
#include "cpu/amd/car/clear_1m_ram.c"
        }

        __asm__ volatile (
                /* set new esp */ /* before _RAMBASE */
                "subl   %0, %%ebp\n\t"
                "subl   %0, %%esp\n\t"
                ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- _RAMBASE )
        );

       {
                unsigned new_cpu_reset;

                /* get back cpu_reset from ebx */
                __asm__ volatile (
                        "movl %%ebx, %0\n\t"
                        :"=a" (new_cpu_reset)
                );

                print_debug("Use Ram as Stack now - "); /* but We can not go back any more, we lost old stack data in cache as ram*/
                if(new_cpu_reset==0) {
                        print_debug("done\r\n");
                } else
                {
                        print_debug("\r\n");
                }

#if CONFIG_USE_INIT
                printk_debug("new_cpu_reset = %08x\r\n", new_cpu_reset);
#else
                print_debug("new_cpu_reset = "); print_debug_hex32(new_cpu_reset); print_debug("\r\n");
#endif
                /*copy and execute linuxbios_ram */
                copy_and_run(new_cpu_reset);
                /* We will not return */
        }

	print_debug("should not be here -\r\n");

}