Mike Partington | 0910d0b | 2010-10-27 10:31:09 +0000 | [diff] [blame] | 1 | #include <common.h> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 2 | #include <exports.h> |
| 3 | |
wdenk | 93f6a67 | 2004-07-01 20:28:03 +0000 | [diff] [blame] | 4 | #ifndef GCC_VERSION |
| 5 | #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) |
| 6 | #endif /* GCC_VERSION */ |
| 7 | |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 8 | #if defined(CONFIG_X86) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 9 | /* |
| 10 | * x86 does not have a dedicated register to store the pointer to |
| 11 | * the global_data. Thus the jump table address is stored in a |
| 12 | * global variable, but such approach does not allow for execution |
| 13 | * from flash memory. The global_data address is passed as argv[-1] |
| 14 | * to the application program. |
| 15 | */ |
| 16 | static void **jt; |
wdenk | 7784674 | 2003-07-26 08:08:08 +0000 | [diff] [blame] | 17 | gd_t *global_data; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 18 | |
| 19 | #define EXPORT_FUNC(x) \ |
| 20 | asm volatile ( \ |
| 21 | " .globl " #x "\n" \ |
| 22 | #x ":\n" \ |
| 23 | " movl %0, %%eax\n" \ |
| 24 | " movl jt, %%ecx\n" \ |
| 25 | " jmp *(%%ecx, %%eax)\n" \ |
| 26 | : : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx"); |
| 27 | #elif defined(CONFIG_PPC) |
| 28 | /* |
Wolfgang Denk | e7670f6 | 2008-02-14 22:43:22 +0100 | [diff] [blame] | 29 | * r2 holds the pointer to the global_data, r11 is a call-clobbered |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 30 | * register |
| 31 | */ |
| 32 | #define EXPORT_FUNC(x) \ |
| 33 | asm volatile ( \ |
| 34 | " .globl " #x "\n" \ |
| 35 | #x ":\n" \ |
Wolfgang Denk | e7670f6 | 2008-02-14 22:43:22 +0100 | [diff] [blame] | 36 | " lwz %%r11, %0(%%r2)\n" \ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 37 | " lwz %%r11, %1(%%r11)\n" \ |
| 38 | " mtctr %%r11\n" \ |
| 39 | " bctr\n" \ |
| 40 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11"); |
| 41 | #elif defined(CONFIG_ARM) |
| 42 | /* |
| 43 | * r8 holds the pointer to the global_data, ip is a call-clobbered |
| 44 | * register |
| 45 | */ |
| 46 | #define EXPORT_FUNC(x) \ |
| 47 | asm volatile ( \ |
| 48 | " .globl " #x "\n" \ |
| 49 | #x ":\n" \ |
| 50 | " ldr ip, [r8, %0]\n" \ |
| 51 | " ldr pc, [ip, %1]\n" \ |
| 52 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip"); |
| 53 | #elif defined(CONFIG_MIPS) |
| 54 | /* |
| 55 | * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call- |
| 56 | * clobbered register that is also used to set gp ($26). Note that the |
| 57 | * jr instruction also executes the instruction immediately following |
| 58 | * it; however, GCC/mips generates an additional `nop' after each asm |
| 59 | * statement |
| 60 | */ |
| 61 | #define EXPORT_FUNC(x) \ |
| 62 | asm volatile ( \ |
| 63 | " .globl " #x "\n" \ |
| 64 | #x ":\n" \ |
| 65 | " lw $25, %0($26)\n" \ |
| 66 | " lw $25, %1($25)\n" \ |
| 67 | " jr $25\n" \ |
| 68 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9"); |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 69 | #elif defined(CONFIG_NIOS2) |
| 70 | /* |
Thomas Chou | 0df01fd | 2010-05-21 11:08:03 +0800 | [diff] [blame] | 71 | * gp holds the pointer to the global_data, r8 is call-clobbered |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 72 | */ |
| 73 | #define EXPORT_FUNC(x) \ |
| 74 | asm volatile ( \ |
| 75 | " .globl " #x "\n" \ |
| 76 | #x ":\n" \ |
| 77 | " movhi r8, %%hi(%0)\n" \ |
| 78 | " ori r8, r0, %%lo(%0)\n" \ |
Thomas Chou | 0df01fd | 2010-05-21 11:08:03 +0800 | [diff] [blame] | 79 | " add r8, r8, gp\n" \ |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 80 | " ldw r8, 0(r8)\n" \ |
| 81 | " ldw r8, %1(r8)\n" \ |
| 82 | " jmp r8\n" \ |
Thomas Chou | 0df01fd | 2010-05-21 11:08:03 +0800 | [diff] [blame] | 83 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "gp"); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 84 | #elif defined(CONFIG_M68K) |
| 85 | /* |
| 86 | * d7 holds the pointer to the global_data, a0 is a call-clobbered |
| 87 | * register |
| 88 | */ |
| 89 | #define EXPORT_FUNC(x) \ |
| 90 | asm volatile ( \ |
| 91 | " .globl " #x "\n" \ |
| 92 | #x ":\n" \ |
| 93 | " move.l %%d7, %%a0\n" \ |
| 94 | " adda.l %0, %%a0\n" \ |
| 95 | " move.l (%%a0), %%a0\n" \ |
| 96 | " adda.l %1, %%a0\n" \ |
| 97 | " move.l (%%a0), %%a0\n" \ |
| 98 | " jmp (%%a0)\n" \ |
| 99 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0"); |
wdenk | 857cad3 | 2004-07-10 23:48:41 +0000 | [diff] [blame] | 100 | #elif defined(CONFIG_MICROBLAZE) |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 101 | /* |
| 102 | * r31 holds the pointer to the global_data. r5 is a call-clobbered. |
| 103 | */ |
| 104 | #define EXPORT_FUNC(x) \ |
| 105 | asm volatile ( \ |
| 106 | " .globl " #x "\n" \ |
| 107 | #x ":\n" \ |
| 108 | " lwi r5, r31, %0\n" \ |
| 109 | " lwi r5, r5, %1\n" \ |
| 110 | " bra r5\n" \ |
| 111 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5"); |
Wolfgang Denk | 0afe519 | 2006-03-12 02:10:00 +0100 | [diff] [blame] | 112 | #elif defined(CONFIG_BLACKFIN) |
| 113 | /* |
Robin Getz | c4db335 | 2009-08-17 15:23:02 +0000 | [diff] [blame] | 114 | * P3 holds the pointer to the global_data, P0 is a call-clobbered |
Wolfgang Denk | 0afe519 | 2006-03-12 02:10:00 +0100 | [diff] [blame] | 115 | * register |
| 116 | */ |
| 117 | #define EXPORT_FUNC(x) \ |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 118 | asm volatile ( \ |
Wolfgang Denk | 61fb15c5 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 119 | " .globl _" #x "\n_" \ |
Wolfgang Denk | 0afe519 | 2006-03-12 02:10:00 +0100 | [diff] [blame] | 120 | #x ":\n" \ |
Robin Getz | c4db335 | 2009-08-17 15:23:02 +0000 | [diff] [blame] | 121 | " P0 = [P3 + %0]\n" \ |
Wolfgang Denk | 0afe519 | 2006-03-12 02:10:00 +0100 | [diff] [blame] | 122 | " P0 = [P0 + %1]\n" \ |
| 123 | " JUMP (P0)\n" \ |
| 124 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "P0"); |
Wolfgang Denk | 7b64fef | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 125 | #elif defined(CONFIG_AVR32) |
| 126 | /* |
| 127 | * r6 holds the pointer to the global_data. r8 is call clobbered. |
| 128 | */ |
| 129 | #define EXPORT_FUNC(x) \ |
| 130 | asm volatile( \ |
| 131 | " .globl\t" #x "\n" \ |
| 132 | #x ":\n" \ |
| 133 | " ld.w r8, r6[%0]\n" \ |
| 134 | " ld.w pc, r8[%1]\n" \ |
| 135 | : \ |
| 136 | : "i"(offsetof(gd_t, jt)), "i"(XF_ ##x) \ |
| 137 | : "r8"); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 138 | #elif defined(CONFIG_SH) |
| 139 | /* |
| 140 | * r13 holds the pointer to the global_data. r1 is a call clobbered. |
| 141 | */ |
Wolfgang Denk | 61fb15c5 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 142 | #define EXPORT_FUNC(x) \ |
| 143 | asm volatile ( \ |
| 144 | " .align 2\n" \ |
| 145 | " .globl " #x "\n" \ |
| 146 | #x ":\n" \ |
| 147 | " mov r13, r1\n" \ |
| 148 | " add %0, r1\n" \ |
Nobuhiro Iwamatsu | cae6f90 | 2008-10-09 13:54:33 +0900 | [diff] [blame] | 149 | " mov.l @r1, r2\n" \ |
| 150 | " add %1, r2\n" \ |
| 151 | " mov.l @r2, r1\n" \ |
Wolfgang Denk | 61fb15c5 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 152 | " jmp @r1\n" \ |
| 153 | " nop\n" \ |
| 154 | " nop\n" \ |
Nobuhiro Iwamatsu | cae6f90 | 2008-10-09 13:54:33 +0900 | [diff] [blame] | 155 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r1", "r2"); |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 156 | #elif defined(CONFIG_SPARC) |
| 157 | /* |
| 158 | * g7 holds the pointer to the global_data. g1 is call clobbered. |
| 159 | */ |
| 160 | #define EXPORT_FUNC(x) \ |
| 161 | asm volatile( \ |
| 162 | " .globl\t" #x "\n" \ |
| 163 | #x ":\n" \ |
| 164 | " set %0, %%g1\n" \ |
| 165 | " or %%g1, %%g7, %%g1\n" \ |
| 166 | " ld [%%g1], %%g1\n" \ |
| 167 | " ld [%%g1 + %1], %%g1\n" \ |
Sergey Mironov | 2c0c58b | 2009-09-23 16:47:38 +0400 | [diff] [blame] | 168 | " jmp %%g1\n" \ |
Daniel Hellstrom | c2f02da | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 169 | " nop\n" \ |
Sergey Mironov | 2c0c58b | 2009-09-23 16:47:38 +0400 | [diff] [blame] | 170 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "g1" ); |
Macpaul Lin | 72c73dd | 2011-10-11 22:33:20 +0000 | [diff] [blame] | 171 | #elif defined(CONFIG_NDS32) |
| 172 | /* |
| 173 | * r16 holds the pointer to the global_data. gp is call clobbered. |
| 174 | * not support reduced register (16 GPR). |
| 175 | */ |
| 176 | #define EXPORT_FUNC(x) \ |
| 177 | asm volatile ( \ |
| 178 | " .globl " #x "\n" \ |
| 179 | #x ":\n" \ |
| 180 | " lwi $r16, [$gp + (%0)]\n" \ |
| 181 | " lwi $r16, [$r16 + (%1)]\n" \ |
| 182 | " jr $r16\n" \ |
| 183 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "$r16"); |
Stefan Kristiansson | 3553493 | 2011-11-18 19:21:35 +0000 | [diff] [blame] | 184 | #elif defined(CONFIG_OPENRISC) |
| 185 | /* |
| 186 | * r10 holds the pointer to the global_data, r13 is a call-clobbered |
| 187 | * register |
| 188 | */ |
| 189 | #define EXPORT_FUNC(x) \ |
| 190 | asm volatile ( \ |
| 191 | " .globl " #x "\n" \ |
| 192 | #x ":\n" \ |
| 193 | " l.lwz r13, %0(r10)\n" \ |
| 194 | " l.lwz r13, %1(r13)\n" \ |
| 195 | " l.jr r13\n" \ |
| 196 | " l.nop\n" \ |
| 197 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r13"); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 198 | #else |
Macpaul Lin | 72c73dd | 2011-10-11 22:33:20 +0000 | [diff] [blame] | 199 | /*" addi $sp, $sp, -24\n" \ |
| 200 | " br $r16\n" \*/ |
| 201 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 202 | #error stubs definition missing for this architecture |
| 203 | #endif |
| 204 | |
| 205 | /* This function is necessary to prevent the compiler from |
| 206 | * generating prologue/epilogue, preparing stack frame etc. |
| 207 | * The stub functions are special, they do not use the stack |
| 208 | * frame passed to them, but pass it intact to the actual |
| 209 | * implementation. On the other hand, asm() statements with |
| 210 | * arguments can be used only inside the functions (gcc limitation) |
| 211 | */ |
wdenk | 93f6a67 | 2004-07-01 20:28:03 +0000 | [diff] [blame] | 212 | #if GCC_VERSION < 3004 |
| 213 | static |
| 214 | #endif /* GCC_VERSION */ |
| 215 | void __attribute__((unused)) dummy(void) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 216 | { |
| 217 | #include <_exports.h> |
| 218 | } |
| 219 | |
Simon Glass | 716cc8c | 2013-03-05 14:39:39 +0000 | [diff] [blame] | 220 | #include <asm/sections.h> |
wdenk | d716b12 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 221 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 222 | void app_startup(char * const *argv) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 223 | { |
Simon Glass | 716cc8c | 2013-03-05 14:39:39 +0000 | [diff] [blame] | 224 | char *cp = __bss_start; |
wdenk | d716b12 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 225 | |
| 226 | /* Zero out BSS */ |
Simon Glass | 716cc8c | 2013-03-05 14:39:39 +0000 | [diff] [blame] | 227 | while (cp < _end) |
wdenk | d716b12 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 228 | *cp++ = 0; |
wdenk | d716b12 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 229 | |
Graeme Russ | fea2572 | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 230 | #if defined(CONFIG_X86) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 231 | /* x86 does not have a dedicated register for passing global_data */ |
wdenk | 7784674 | 2003-07-26 08:08:08 +0000 | [diff] [blame] | 232 | global_data = (gd_t *)argv[-1]; |
| 233 | jt = global_data->jt; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 234 | #endif |
| 235 | } |
| 236 | |
| 237 | #undef EXPORT_FUNC |