wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 1 | #include <exports.h> |
Masahiro Yamada | 8400275 | 2014-09-04 02:40:59 +0900 | [diff] [blame] | 2 | #include <linux/compiler.h> |
wdenk | 3337af4 | 2004-07-01 20:28:03 +0000 | [diff] [blame] | 3 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 4 | struct cmd_tbl; |
| 5 | |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 6 | #define FO(x) offsetof(struct jt_funcs, x) |
| 7 | |
Graeme Russ | cbfce1d | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 8 | #if defined(CONFIG_X86) |
wdenk | 874ac26 | 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 | */ |
Alistair Delva | 02a695c | 2022-09-26 20:47:10 +0000 | [diff] [blame] | 16 | struct jt_funcs *jt; |
wdenk | b846356 | 2003-07-26 08:08:08 +0000 | [diff] [blame] | 17 | gd_t *global_data; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 18 | |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 19 | #define EXPORT_FUNC(f, a, x, ...) \ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 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" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 26 | : : "i"(FO(x)) : "eax", "ecx"); |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 27 | #elif defined(CONFIG_PPC) |
| 28 | /* |
Wolfgang Denk | 69c0964 | 2008-02-14 22:43:22 +0100 | [diff] [blame] | 29 | * r2 holds the pointer to the global_data, r11 is a call-clobbered |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 30 | * register |
| 31 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 32 | #define EXPORT_FUNC(f, a, x, ...) \ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 33 | asm volatile ( \ |
| 34 | " .globl " #x "\n" \ |
| 35 | #x ":\n" \ |
Wolfgang Denk | 69c0964 | 2008-02-14 22:43:22 +0100 | [diff] [blame] | 36 | " lwz %%r11, %0(%%r2)\n" \ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 37 | " lwz %%r11, %1(%%r11)\n" \ |
| 38 | " mtctr %%r11\n" \ |
| 39 | " bctr\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 40 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11"); |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 41 | #elif defined(CONFIG_ARM) |
David Feng | 85fd5f1 | 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 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 47 | #define EXPORT_FUNC(f, a, x, ...) \ |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 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" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 54 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9"); |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 55 | #else |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 56 | /* |
Jeroen Hofstee | b00867b | 2013-11-21 22:32:51 +0100 | [diff] [blame] | 57 | * r9 holds the pointer to the global_data, ip is a call-clobbered |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 58 | * register |
| 59 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 60 | #define EXPORT_FUNC(f, a, x, ...) \ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 61 | asm volatile ( \ |
| 62 | " .globl " #x "\n" \ |
| 63 | #x ":\n" \ |
Jeroen Hofstee | b00867b | 2013-11-21 22:32:51 +0100 | [diff] [blame] | 64 | " ldr ip, [r9, %0]\n" \ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 65 | " ldr pc, [ip, %1]\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 66 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip"); |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 67 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 68 | #elif defined(CONFIG_MIPS) |
Stanislav Galabov | 26f182d | 2016-02-17 15:23:33 +0200 | [diff] [blame] | 69 | #ifdef CONFIG_CPU_MIPS64 |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 70 | /* |
| 71 | * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call- |
| 72 | * clobbered register that is also used to set gp ($26). Note that the |
| 73 | * jr instruction also executes the instruction immediately following |
| 74 | * it; however, GCC/mips generates an additional `nop' after each asm |
| 75 | * statement |
| 76 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 77 | #define EXPORT_FUNC(f, a, x, ...) \ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 78 | asm volatile ( \ |
| 79 | " .globl " #x "\n" \ |
| 80 | #x ":\n" \ |
Stanislav Galabov | 26f182d | 2016-02-17 15:23:33 +0200 | [diff] [blame] | 81 | " ld $25, %0($26)\n" \ |
| 82 | " ld $25, %1($25)\n" \ |
| 83 | " jr $25\n" \ |
| 84 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9"); |
| 85 | #else |
| 86 | /* |
| 87 | * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call- |
| 88 | * clobbered register that is also used to set gp ($26). Note that the |
| 89 | * jr instruction also executes the instruction immediately following |
| 90 | * it; however, GCC/mips generates an additional `nop' after each asm |
| 91 | * statement |
| 92 | */ |
| 93 | #define EXPORT_FUNC(f, a, x, ...) \ |
| 94 | asm volatile ( \ |
| 95 | " .globl " #x "\n" \ |
| 96 | #x ":\n" \ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 97 | " lw $25, %0($26)\n" \ |
| 98 | " lw $25, %1($25)\n" \ |
| 99 | " jr $25\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 100 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9"); |
Stanislav Galabov | 26f182d | 2016-02-17 15:23:33 +0200 | [diff] [blame] | 101 | #endif |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 102 | #elif defined(CONFIG_NIOS2) |
| 103 | /* |
Thomas Chou | 8fa3858 | 2010-05-21 11:08:03 +0800 | [diff] [blame] | 104 | * gp holds the pointer to the global_data, r8 is call-clobbered |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 105 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 106 | #define EXPORT_FUNC(f, a, x, ...) \ |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 107 | asm volatile ( \ |
| 108 | " .globl " #x "\n" \ |
| 109 | #x ":\n" \ |
| 110 | " movhi r8, %%hi(%0)\n" \ |
| 111 | " ori r8, r0, %%lo(%0)\n" \ |
Thomas Chou | 8fa3858 | 2010-05-21 11:08:03 +0800 | [diff] [blame] | 112 | " add r8, r8, gp\n" \ |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 113 | " ldw r8, 0(r8)\n" \ |
| 114 | " ldw r8, %1(r8)\n" \ |
| 115 | " jmp r8\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 116 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp"); |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 117 | #elif defined(CONFIG_M68K) |
| 118 | /* |
| 119 | * d7 holds the pointer to the global_data, a0 is a call-clobbered |
| 120 | * register |
| 121 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 122 | #define EXPORT_FUNC(f, a, x, ...) \ |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 123 | asm volatile ( \ |
| 124 | " .globl " #x "\n" \ |
| 125 | #x ":\n" \ |
| 126 | " move.l %%d7, %%a0\n" \ |
| 127 | " adda.l %0, %%a0\n" \ |
| 128 | " move.l (%%a0), %%a0\n" \ |
| 129 | " adda.l %1, %%a0\n" \ |
| 130 | " move.l (%%a0), %%a0\n" \ |
| 131 | " jmp (%%a0)\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 132 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0"); |
wdenk | 20a6122 | 2004-07-10 23:48:41 +0000 | [diff] [blame] | 133 | #elif defined(CONFIG_MICROBLAZE) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 134 | /* |
| 135 | * r31 holds the pointer to the global_data. r5 is a call-clobbered. |
| 136 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 137 | #define EXPORT_FUNC(f, a, x, ...) \ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 138 | asm volatile ( \ |
| 139 | " .globl " #x "\n" \ |
| 140 | #x ":\n" \ |
| 141 | " lwi r5, r31, %0\n" \ |
| 142 | " lwi r5, r5, %1\n" \ |
| 143 | " bra r5\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 144 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5"); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 145 | #elif defined(CONFIG_SH) |
| 146 | /* |
| 147 | * r13 holds the pointer to the global_data. r1 is a call clobbered. |
| 148 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 149 | #define EXPORT_FUNC(f, a, x, ...) \ |
Wolfgang Denk | 0a5c214 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 150 | asm volatile ( \ |
| 151 | " .align 2\n" \ |
| 152 | " .globl " #x "\n" \ |
| 153 | #x ":\n" \ |
| 154 | " mov r13, r1\n" \ |
| 155 | " add %0, r1\n" \ |
Nobuhiro Iwamatsu | d1d1850 | 2008-10-09 13:54:33 +0900 | [diff] [blame] | 156 | " mov.l @r1, r2\n" \ |
| 157 | " add %1, r2\n" \ |
| 158 | " mov.l @r2, r1\n" \ |
Wolfgang Denk | 0a5c214 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 159 | " jmp @r1\n" \ |
| 160 | " nop\n" \ |
| 161 | " nop\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 162 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2"); |
Rick Chen | ba06a9a | 2017-12-26 13:55:57 +0800 | [diff] [blame] | 163 | #elif defined(CONFIG_RISCV) |
| 164 | /* |
Lukas Auer | af68f82 | 2019-01-04 01:37:32 +0100 | [diff] [blame] | 165 | * gp holds the pointer to the global_data. t0 is call clobbered. |
Rick Chen | ba06a9a | 2017-12-26 13:55:57 +0800 | [diff] [blame] | 166 | */ |
Lukas Auer | db2fea2 | 2019-01-04 01:37:33 +0100 | [diff] [blame] | 167 | #ifdef CONFIG_ARCH_RV64I |
Rick Chen | ba06a9a | 2017-12-26 13:55:57 +0800 | [diff] [blame] | 168 | #define EXPORT_FUNC(f, a, x, ...) \ |
| 169 | asm volatile ( \ |
| 170 | " .globl " #x "\n" \ |
| 171 | #x ":\n" \ |
Lukas Auer | db2fea2 | 2019-01-04 01:37:33 +0100 | [diff] [blame] | 172 | " ld t0, %0(gp)\n" \ |
| 173 | " ld t0, %1(t0)\n" \ |
| 174 | " jr t0\n" \ |
| 175 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0"); |
| 176 | #else |
| 177 | #define EXPORT_FUNC(f, a, x, ...) \ |
| 178 | asm volatile ( \ |
| 179 | " .globl " #x "\n" \ |
| 180 | #x ":\n" \ |
Lukas Auer | af68f82 | 2019-01-04 01:37:32 +0100 | [diff] [blame] | 181 | " lw t0, %0(gp)\n" \ |
| 182 | " lw t0, %1(t0)\n" \ |
| 183 | " jr t0\n" \ |
| 184 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0"); |
Lukas Auer | db2fea2 | 2019-01-04 01:37:33 +0100 | [diff] [blame] | 185 | #endif |
Alexey Brodkin | cb25a73 | 2014-02-04 12:56:17 +0400 | [diff] [blame] | 186 | #elif defined(CONFIG_ARC) |
| 187 | /* |
| 188 | * r25 holds the pointer to the global_data. r10 is call clobbered. |
| 189 | */ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 190 | #define EXPORT_FUNC(f, a, x, ...) \ |
Alexey Brodkin | cb25a73 | 2014-02-04 12:56:17 +0400 | [diff] [blame] | 191 | asm volatile( \ |
| 192 | " .align 4\n" \ |
| 193 | " .globl " #x "\n" \ |
| 194 | #x ":\n" \ |
| 195 | " ld r10, [r25, %0]\n" \ |
| 196 | " ld r10, [r10, %1]\n" \ |
| 197 | " j [r10]\n" \ |
Martin Dorwig | cb2c286 | 2015-01-26 15:22:54 -0700 | [diff] [blame] | 198 | : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10"); |
Chris Zankel | 41e3737 | 2016-08-10 18:36:43 +0300 | [diff] [blame] | 199 | #elif defined(CONFIG_XTENSA) |
| 200 | /* |
| 201 | * Global data ptr is in global_data, jump table ptr is in jt. |
| 202 | * Windowed ABI: Jump just past 'entry' in target and adjust stack frame |
| 203 | * (extract stack frame size from target 'entry' instruction). |
| 204 | */ |
| 205 | |
| 206 | static void **jt; |
| 207 | |
| 208 | #if defined(__XTENSA_CALL0_ABI__) |
| 209 | #define EXPORT_FUNC(f, a, x, ...) \ |
| 210 | asm volatile ( \ |
| 211 | " .extern jt\n" \ |
| 212 | " .globl " #x "\n" \ |
| 213 | " .align 4\n" \ |
| 214 | #x ":\n" \ |
| 215 | " l32i a8, %0, 0\n" \ |
| 216 | " l32i a8, a8, %1\n" \ |
| 217 | " jx a8\n" \ |
| 218 | : : "r"(jt), "i" (FO(x)) : "a8"); |
| 219 | #elif defined(__XTENSA_WINDOWED_ABI__) |
| 220 | #if XCHAL_HAVE_BE |
| 221 | # define SFT "8" |
| 222 | #else |
| 223 | # define SFT "12" |
| 224 | #endif |
| 225 | #define EXPORT_FUNC(f, a, x, ...) \ |
| 226 | asm volatile ( \ |
| 227 | " .extern jt\n" \ |
| 228 | " .globl " #x "\n" \ |
| 229 | " .align 4\n" \ |
| 230 | #x ":\n" \ |
| 231 | " entry sp, 16\n" \ |
| 232 | " l32i a8, %0, 0\n" \ |
| 233 | " l32i a8, a8, %1\n" \ |
| 234 | " l32i a9, a8, 0\n" \ |
| 235 | " extui a9, a9, " SFT ", 12\n" \ |
| 236 | " subx8 a9, a9, sp\n" \ |
| 237 | " movi a10, 16\n" \ |
| 238 | " sub a9, a10, a9\n" \ |
| 239 | " movsp sp, a9\n" \ |
| 240 | " addi a8, a8, 3\n" \ |
| 241 | " jx a8\n" \ |
| 242 | : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10"); |
| 243 | #else |
| 244 | #error Unsupported Xtensa ABI |
| 245 | #endif |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 246 | #else |
Macpaul Lin | 394c76a | 2011-10-11 22:33:20 +0000 | [diff] [blame] | 247 | /*" addi $sp, $sp, -24\n" \ |
| 248 | " br $r16\n" \*/ |
| 249 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 250 | #error stubs definition missing for this architecture |
| 251 | #endif |
| 252 | |
| 253 | /* This function is necessary to prevent the compiler from |
| 254 | * generating prologue/epilogue, preparing stack frame etc. |
| 255 | * The stub functions are special, they do not use the stack |
| 256 | * frame passed to them, but pass it intact to the actual |
| 257 | * implementation. On the other hand, asm() statements with |
| 258 | * arguments can be used only inside the functions (gcc limitation) |
| 259 | */ |
Masahiro Yamada | 8400275 | 2014-09-04 02:40:59 +0900 | [diff] [blame] | 260 | #if GCC_VERSION < 30400 |
wdenk | 3337af4 | 2004-07-01 20:28:03 +0000 | [diff] [blame] | 261 | static |
| 262 | #endif /* GCC_VERSION */ |
| 263 | void __attribute__((unused)) dummy(void) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 264 | { |
| 265 | #include <_exports.h> |
| 266 | } |
| 267 | |
Simon Glass | 5b92820 | 2013-03-05 14:39:39 +0000 | [diff] [blame] | 268 | #include <asm/sections.h> |
wdenk | 2fb7390 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 269 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 270 | void app_startup(char * const *argv) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 271 | { |
Simon Glass | 5b92820 | 2013-03-05 14:39:39 +0000 | [diff] [blame] | 272 | char *cp = __bss_start; |
wdenk | 2fb7390 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 273 | |
| 274 | /* Zero out BSS */ |
Simon Glass | 5b92820 | 2013-03-05 14:39:39 +0000 | [diff] [blame] | 275 | while (cp < _end) |
wdenk | 2fb7390 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 276 | *cp++ = 0; |
wdenk | 2fb7390 | 2004-04-12 16:12:49 +0000 | [diff] [blame] | 277 | |
Graeme Russ | cbfce1d | 2011-04-13 19:43:28 +1000 | [diff] [blame] | 278 | #if defined(CONFIG_X86) |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 279 | /* x86 does not have a dedicated register for passing global_data */ |
wdenk | b846356 | 2003-07-26 08:08:08 +0000 | [diff] [blame] | 280 | global_data = (gd_t *)argv[-1]; |
| 281 | jt = global_data->jt; |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 282 | #endif |
| 283 | } |
| 284 | |
| 285 | #undef EXPORT_FUNC |