aboutsummaryrefslogtreecommitdiff
path: root/src/cpu/amd/car/post_cache_as_ram.c
blob: 345e4c34b0191450fda75d2017b0265b187448e4 (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
82
83
84
85
86
87
88
89
90
91
#include "cpu/amd/car/disable_cache_as_ram.c"

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

static inline void print_debug_pcar(const char *strval, uint32_t val)
{
#if CONFIG_USE_INIT
        printk_debug("%s%08x\r\n", strval, val);
#else
        print_debug(strval); print_debug_hex32(val); print_debug("\r\n");
#endif
}



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)
        );
        print_debug_pcar("v_esp=", v_esp);
        }
#endif

        print_debug_pcar("cpu_reset = ",cpu_reset);

        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)
        );

	disable_cache_as_ram();

        if(cpu_reset==0) { // cpu_reset don't need to clear it 
		clear_1m_ram();
        }
	else {
		set_1m_ram();
	}

        __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");
                }

                print_debug_pcar("new_cpu_reset = ", new_cpu_reset);


                /*copy and execute linuxbios_ram */
                copy_and_run(new_cpu_reset);
                /* We will not return */
        }

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

}