arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 1 | /* by yhlu 6.2005 |
| 2 | moved from nrv2v.c and some lines from crt0.S |
Stefan Reinauer | ead7368 | 2006-05-02 12:05:13 +0000 | [diff] [blame] | 3 | 2006/05/02 - stepan: move nrv2b to an extra file. |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 4 | */ |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 5 | static inline void print_debug_cp_run(const char *strval, uint32_t val) |
| 6 | { |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 7 | #if CONFIG_USE_PRINTK_IN_CAR |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 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 | |
Yinghai Lu | 608d4b2 | 2006-05-04 00:47:15 +0000 | [diff] [blame] | 14 | #if CONFIG_COMPRESS |
| 15 | #define ENDIAN 0 |
| 16 | #define BITSIZE 32 |
| 17 | #include "lib/nrv2b.c" |
| 18 | #endif |
| 19 | |
| 20 | |
Yinghai Lu | 9a791df | 2006-04-03 20:38:34 +0000 | [diff] [blame] | 21 | static void copy_and_run(void) |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 22 | { |
| 23 | uint8_t *src, *dst; |
Yinghai Lu | 608d4b2 | 2006-05-04 00:47:15 +0000 | [diff] [blame] | 24 | unsigned long ilen, olen; |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 25 | |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 26 | |
| 27 | #if !CONFIG_COMPRESS |
Stefan Reinauer | 87c938f | 2008-08-02 19:17:42 +0000 | [diff] [blame^] | 28 | print_debug("Copying coreboot to RAM.\r\n"); |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 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" |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 34 | : "=a" (src), "=b" (dst), "=c" (olen) |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 35 | ); |
Yinghai Lu | 9a791df | 2006-04-03 20:38:34 +0000 | [diff] [blame] | 36 | memcpy(dst, src, olen); |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 37 | #else |
Stefan Reinauer | 87c938f | 2008-08-02 19:17:42 +0000 | [diff] [blame^] | 38 | print_debug("Uncompressing coreboot to RAM.\r\n"); |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 39 | |
| 40 | __asm__ volatile ( |
Stefan Reinauer | ab4f5d0 | 2006-05-04 10:08:04 +0000 | [diff] [blame] | 41 | "leal _liseg, %0\n\t" |
| 42 | "leal _iseg, %1\n\t" |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 43 | : "=a" (src) , "=b" (dst) |
| 44 | ); |
| 45 | |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 46 | print_debug_cp_run("src=",(uint32_t)src); |
| 47 | print_debug_cp_run("dst=",(uint32_t)dst); |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 48 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 49 | // dump_mem(src, src+0x100); |
| 50 | |
| 51 | olen = unrv2b(src, dst, &ilen); |
Stefan Reinauer | 87c938f | 2008-08-02 19:17:42 +0000 | [diff] [blame^] | 52 | print_debug_cp_run("coreboot_ram.nrv2b length = ", ilen); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 53 | |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 54 | #endif |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 55 | // dump_mem(dst, dst+0x100); |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 56 | |
Stefan Reinauer | 87c938f | 2008-08-02 19:17:42 +0000 | [diff] [blame^] | 57 | print_debug_cp_run("coreboot_ram.bin length = ", olen); |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 58 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 59 | print_debug("Jumping to coreboot.\r\n"); |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 60 | |
Yinghai Lu | 9a791df | 2006-04-03 20:38:34 +0000 | [diff] [blame] | 61 | __asm__ volatile ( |
| 62 | "xorl %ebp, %ebp\n\t" /* cpu_reset for hardwaremain dummy */ |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 63 | "cli\n\t" |
| 64 | "leal _iseg, %edi\n\t" |
Yinghai Lu | 6c02eb2 | 2005-12-14 23:13:13 +0000 | [diff] [blame] | 65 | "jmp *%edi\n\t" |
arch import user (historical) | 6ca7636 | 2005-07-06 17:17:25 +0000 | [diff] [blame] | 66 | ); |
| 67 | |
| 68 | } |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 69 | |
| 70 | #if CONFIG_AP_CODE_IN_CAR == 1 |
| 71 | |
| 72 | static void copy_and_run_ap_code_in_car(unsigned ret_addr) |
| 73 | { |
| 74 | uint8_t *src, *dst; |
| 75 | unsigned long ilen, olen; |
| 76 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 77 | // print_debug("Copying coreboot AP code to CAR.\r\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 78 | |
| 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 Reinauer | 87c938f | 2008-08-02 19:17:42 +0000 | [diff] [blame^] | 102 | // print_debug_cp_run("coreboot_apc.nrv2b length = ", ilen); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 103 | |
| 104 | #endif |
| 105 | // dump_mem(dst, dst+0x100); |
| 106 | |
Stefan Reinauer | 87c938f | 2008-08-02 19:17:42 +0000 | [diff] [blame^] | 107 | // print_debug_cp_run("coreboot_apc.bin length = ", olen); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 108 | |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 109 | // print_debug("Jumping to coreboot AP code in CAR.\r\n"); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 110 | |
| 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 |