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