blob: 80fc84072bcc7435cd76445f8508bafadbb10007 [file] [log] [blame]
arch import user (historical)6ca76362005-07-06 17:17:25 +00001/* by yhlu 6.2005
2 moved from nrv2v.c and some lines from crt0.S
Stefan Reinaueread73682006-05-02 12:05:13 +00003 2006/05/02 - stepan: move nrv2b to an extra file.
arch import user (historical)6ca76362005-07-06 17:17:25 +00004*/
Stefan Reinauer7ce8c542005-12-02 21:52:30 +00005static inline void print_debug_cp_run(const char *strval, uint32_t val)
6{
Yinghai Lu5f9624d2006-10-04 22:56:21 +00007#if CONFIG_USE_PRINTK_IN_CAR
Stefan Reinauer7ce8c542005-12-02 21:52:30 +00008 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
Yinghai Lu608d4b22006-05-04 00:47:15 +000014#if CONFIG_COMPRESS
15#define ENDIAN 0
16#define BITSIZE 32
17#include "lib/nrv2b.c"
18#endif
19
20
Yinghai Lu9a791df2006-04-03 20:38:34 +000021static void copy_and_run(void)
arch import user (historical)6ca76362005-07-06 17:17:25 +000022{
23 uint8_t *src, *dst;
Yinghai Lu608d4b22006-05-04 00:47:15 +000024 unsigned long ilen, olen;
arch import user (historical)6ca76362005-07-06 17:17:25 +000025
arch import user (historical)6ca76362005-07-06 17:17:25 +000026
27#if !CONFIG_COMPRESS
Stefan Reinauer87c938f2008-08-02 19:17:42 +000028 print_debug("Copying coreboot to RAM.\r\n");
arch import user (historical)6ca76362005-07-06 17:17:25 +000029 __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"
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000034 : "=a" (src), "=b" (dst), "=c" (olen)
arch import user (historical)6ca76362005-07-06 17:17:25 +000035 );
Yinghai Lu9a791df2006-04-03 20:38:34 +000036 memcpy(dst, src, olen);
arch import user (historical)6ca76362005-07-06 17:17:25 +000037#else
Stefan Reinauer87c938f2008-08-02 19:17:42 +000038 print_debug("Uncompressing coreboot to RAM.\r\n");
arch import user (historical)6ca76362005-07-06 17:17:25 +000039
40 __asm__ volatile (
Stefan Reinauerab4f5d02006-05-04 10:08:04 +000041 "leal _liseg, %0\n\t"
42 "leal _iseg, %1\n\t"
arch import user (historical)6ca76362005-07-06 17:17:25 +000043 : "=a" (src) , "=b" (dst)
44 );
45
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000046 print_debug_cp_run("src=",(uint32_t)src);
47 print_debug_cp_run("dst=",(uint32_t)dst);
arch import user (historical)6ca76362005-07-06 17:17:25 +000048
Yinghai Lud4b278c2006-10-04 20:46:15 +000049// dump_mem(src, src+0x100);
50
51 olen = unrv2b(src, dst, &ilen);
Stefan Reinauer87c938f2008-08-02 19:17:42 +000052 print_debug_cp_run("coreboot_ram.nrv2b length = ", ilen);
Yinghai Lud4b278c2006-10-04 20:46:15 +000053
arch import user (historical)6ca76362005-07-06 17:17:25 +000054#endif
Yinghai Lud4b278c2006-10-04 20:46:15 +000055// dump_mem(dst, dst+0x100);
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000056
Stefan Reinauer87c938f2008-08-02 19:17:42 +000057 print_debug_cp_run("coreboot_ram.bin length = ", olen);
Stefan Reinauer7ce8c542005-12-02 21:52:30 +000058
Stefan Reinauerf8ee1802008-01-18 15:08:58 +000059 print_debug("Jumping to coreboot.\r\n");
arch import user (historical)6ca76362005-07-06 17:17:25 +000060
Yinghai Lu9a791df2006-04-03 20:38:34 +000061 __asm__ volatile (
62 "xorl %ebp, %ebp\n\t" /* cpu_reset for hardwaremain dummy */
arch import user (historical)6ca76362005-07-06 17:17:25 +000063 "cli\n\t"
64 "leal _iseg, %edi\n\t"
Yinghai Lu6c02eb22005-12-14 23:13:13 +000065 "jmp *%edi\n\t"
arch import user (historical)6ca76362005-07-06 17:17:25 +000066 );
67
68}
Yinghai Lud4b278c2006-10-04 20:46:15 +000069
70#if CONFIG_AP_CODE_IN_CAR == 1
71
72static void copy_and_run_ap_code_in_car(unsigned ret_addr)
73{
74 uint8_t *src, *dst;
75 unsigned long ilen, olen;
76
Stefan Reinauerf8ee1802008-01-18 15:08:58 +000077// print_debug("Copying coreboot AP code to CAR.\r\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +000078
79#if !CONFIG_COMPRESS
80 __asm__ volatile (
81 "leal _liseg_apc, %0\n\t"
82 "leal _iseg_apc, %1\n\t"
83 "leal _eiseg_apc, %2\n\t"
84 "subl %1, %2\n\t"
85 : "=a" (src), "=b" (dst), "=c" (olen)
86 );
87 memcpy(dst, src, olen);
88#else
89
90 __asm__ volatile (
91 "leal _liseg_apc, %0\n\t"
92 "leal _iseg_apc, %1\n\t"
93 : "=a" (src) , "=b" (dst)
94 );
95
96// print_debug_cp_run("src=",(uint32_t)src);
97// print_debug_cp_run("dst=",(uint32_t)dst);
98
99// dump_mem(src, src+0x100);
100
101 olen = unrv2b(src, dst, &ilen);
Stefan Reinauer87c938f2008-08-02 19:17:42 +0000102// print_debug_cp_run("coreboot_apc.nrv2b length = ", ilen);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000103
104#endif
105// dump_mem(dst, dst+0x100);
106
Stefan Reinauer87c938f2008-08-02 19:17:42 +0000107// print_debug_cp_run("coreboot_apc.bin length = ", olen);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000108
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000109// print_debug("Jumping to coreboot AP code in CAR.\r\n");
Yinghai Lud4b278c2006-10-04 20:46:15 +0000110
111 __asm__ volatile (
112 "movl %0, %%ebp\n\t" /* cpu_reset for hardwaremain dummy */
113 "cli\n\t"
114 "leal _iseg_apc, %%edi\n\t"
115 "jmp *%%edi\n\t"
116 :: "a"(ret_addr)
117 );
118
119}
120#endif