Rename almost all occurences of LinuxBIOS to coreboot.
[coreboot.git] / src / cpu / amd / car / copy_and_run.c
1 /* by yhlu 6.2005 
2         moved from nrv2v.c and some lines from crt0.S
3    2006/05/02 - stepan: move nrv2b to an extra file.
4 */
5 static inline void print_debug_cp_run(const char *strval, uint32_t val)
6 {
7 #if CONFIG_USE_PRINTK_IN_CAR
8         printk_debug("%s%08x\r\n", strval, val);
9 #else
10         print_debug(strval); print_debug_hex32(val); print_debug("\r\n");
11 #endif
12 }
13
14 #if CONFIG_COMPRESS
15 #define ENDIAN   0
16 #define BITSIZE 32
17 #include "lib/nrv2b.c"
18 #endif
19
20
21 static void copy_and_run(void)
22 {
23         uint8_t *src, *dst; 
24         unsigned long ilen, olen;
25
26         print_debug("Copying coreboot to RAM.\r\n");
27
28 #if !CONFIG_COMPRESS 
29         __asm__ volatile (
30                 "leal _liseg, %0\n\t"
31                 "leal _iseg, %1\n\t"
32                 "leal _eiseg, %2\n\t"
33                 "subl %1, %2\n\t"
34                 : "=a" (src), "=b" (dst), "=c" (olen)
35         );
36         memcpy(dst, src, olen);
37 #else 
38
39         __asm__ volatile (
40                 "leal _liseg, %0\n\t"
41                 "leal _iseg,  %1\n\t"
42                 : "=a" (src) , "=b" (dst)
43         );
44
45         print_debug_cp_run("src=",(uint32_t)src); 
46         print_debug_cp_run("dst=",(uint32_t)dst);
47
48 //      dump_mem(src, src+0x100);
49
50         olen = unrv2b(src, dst, &ilen);
51         print_debug_cp_run("linxbios_ram.nrv2b length = ", ilen);
52
53 #endif
54 //      dump_mem(dst, dst+0x100);
55
56         print_debug_cp_run("linxbios_ram.bin   length = ", olen);
57
58         print_debug("Jumping to coreboot.\r\n");
59
60         __asm__ volatile (
61                 "xorl %ebp, %ebp\n\t" /* cpu_reset for hardwaremain dummy */
62                 "cli\n\t"
63                 "leal    _iseg, %edi\n\t"
64                 "jmp     *%edi\n\t"
65         );
66
67 }
68
69 #if CONFIG_AP_CODE_IN_CAR == 1
70
71 static void copy_and_run_ap_code_in_car(unsigned ret_addr)
72 {
73         uint8_t *src, *dst;
74         unsigned long ilen, olen;
75
76 //        print_debug("Copying coreboot AP code to CAR.\r\n");
77
78 #if !CONFIG_COMPRESS
79         __asm__ volatile (
80                 "leal _liseg_apc, %0\n\t"
81                 "leal _iseg_apc, %1\n\t"
82                 "leal _eiseg_apc, %2\n\t"
83                 "subl %1, %2\n\t"
84                 : "=a" (src), "=b" (dst), "=c" (olen)
85         );
86         memcpy(dst, src, olen);
87 #else
88
89         __asm__ volatile (
90                 "leal _liseg_apc, %0\n\t"
91                 "leal _iseg_apc,  %1\n\t"
92                 : "=a" (src) , "=b" (dst)
93         );
94
95 //        print_debug_cp_run("src=",(uint32_t)src);
96 //        print_debug_cp_run("dst=",(uint32_t)dst);
97
98 //      dump_mem(src, src+0x100);
99
100         olen = unrv2b(src, dst, &ilen);
101 //        print_debug_cp_run("linxbios_apc.nrv2b length = ", ilen);
102
103 #endif
104 //      dump_mem(dst, dst+0x100);
105
106 //        print_debug_cp_run("linxbios_apc.bin   length = ", olen);
107
108 //        print_debug("Jumping to coreboot AP code in CAR.\r\n");
109
110         __asm__ volatile (
111                 "movl %0, %%ebp\n\t" /* cpu_reset for hardwaremain dummy */
112                 "cli\n\t"
113                 "leal    _iseg_apc, %%edi\n\t"
114                 "jmp     *%%edi\n\t"
115                 :: "a"(ret_addr)
116         );
117
118 }
119 #endif