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