2010-10-27 10:31:09 +00:00
|
|
|
#include <common.h>
|
2003-07-24 23:38:38 +00:00
|
|
|
#include <exports.h>
|
|
|
|
|
2004-07-01 20:28:03 +00:00
|
|
|
#ifndef GCC_VERSION
|
|
|
|
#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
|
|
|
|
#endif /* GCC_VERSION */
|
|
|
|
|
2011-04-13 09:43:28 +00:00
|
|
|
#if defined(CONFIG_X86)
|
2003-07-24 23:38:38 +00:00
|
|
|
/*
|
|
|
|
* x86 does not have a dedicated register to store the pointer to
|
|
|
|
* the global_data. Thus the jump table address is stored in a
|
|
|
|
* global variable, but such approach does not allow for execution
|
|
|
|
* from flash memory. The global_data address is passed as argv[-1]
|
|
|
|
* to the application program.
|
|
|
|
*/
|
|
|
|
static void **jt;
|
2003-07-26 08:08:08 +00:00
|
|
|
gd_t *global_data;
|
2003-07-24 23:38:38 +00:00
|
|
|
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" movl %0, %%eax\n" \
|
|
|
|
" movl jt, %%ecx\n" \
|
|
|
|
" jmp *(%%ecx, %%eax)\n" \
|
|
|
|
: : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx");
|
|
|
|
#elif defined(CONFIG_PPC)
|
|
|
|
/*
|
2008-02-14 21:43:22 +00:00
|
|
|
* r2 holds the pointer to the global_data, r11 is a call-clobbered
|
2003-07-24 23:38:38 +00:00
|
|
|
* register
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
2008-02-14 21:43:22 +00:00
|
|
|
" lwz %%r11, %0(%%r2)\n" \
|
2003-07-24 23:38:38 +00:00
|
|
|
" lwz %%r11, %1(%%r11)\n" \
|
|
|
|
" mtctr %%r11\n" \
|
|
|
|
" bctr\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
|
|
|
|
#elif defined(CONFIG_ARM)
|
2013-12-14 03:47:35 +00:00
|
|
|
#ifdef CONFIG_ARM64
|
|
|
|
/*
|
|
|
|
* x18 holds the pointer to the global_data, x9 is a call-clobbered
|
|
|
|
* register
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" ldr x9, [x18, %0]\n" \
|
|
|
|
" ldr x9, [x9, %1]\n" \
|
|
|
|
" br x9\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "x9");
|
|
|
|
#else
|
2003-07-24 23:38:38 +00:00
|
|
|
/*
|
2013-11-21 21:32:51 +00:00
|
|
|
* r9 holds the pointer to the global_data, ip is a call-clobbered
|
2003-07-24 23:38:38 +00:00
|
|
|
* register
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
2013-11-21 21:32:51 +00:00
|
|
|
" ldr ip, [r9, %0]\n" \
|
2003-07-24 23:38:38 +00:00
|
|
|
" ldr pc, [ip, %1]\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
|
2013-12-14 03:47:35 +00:00
|
|
|
#endif
|
2003-07-24 23:38:38 +00:00
|
|
|
#elif defined(CONFIG_MIPS)
|
|
|
|
/*
|
|
|
|
* k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
|
|
|
|
* clobbered register that is also used to set gp ($26). Note that the
|
|
|
|
* jr instruction also executes the instruction immediately following
|
|
|
|
* it; however, GCC/mips generates an additional `nop' after each asm
|
|
|
|
* statement
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" lw $25, %0($26)\n" \
|
|
|
|
" lw $25, %1($25)\n" \
|
|
|
|
" jr $25\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9");
|
2004-10-10 21:27:30 +00:00
|
|
|
#elif defined(CONFIG_NIOS2)
|
|
|
|
/*
|
2010-05-21 03:08:03 +00:00
|
|
|
* gp holds the pointer to the global_data, r8 is call-clobbered
|
2004-10-10 21:27:30 +00:00
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" movhi r8, %%hi(%0)\n" \
|
|
|
|
" ori r8, r0, %%lo(%0)\n" \
|
2010-05-21 03:08:03 +00:00
|
|
|
" add r8, r8, gp\n" \
|
2004-10-10 21:27:30 +00:00
|
|
|
" ldw r8, 0(r8)\n" \
|
|
|
|
" ldw r8, %1(r8)\n" \
|
|
|
|
" jmp r8\n" \
|
2010-05-21 03:08:03 +00:00
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "gp");
|
2004-02-12 00:47:09 +00:00
|
|
|
#elif defined(CONFIG_M68K)
|
|
|
|
/*
|
|
|
|
* d7 holds the pointer to the global_data, a0 is a call-clobbered
|
|
|
|
* register
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" move.l %%d7, %%a0\n" \
|
|
|
|
" adda.l %0, %%a0\n" \
|
|
|
|
" move.l (%%a0), %%a0\n" \
|
|
|
|
" adda.l %1, %%a0\n" \
|
|
|
|
" move.l (%%a0), %%a0\n" \
|
|
|
|
" jmp (%%a0)\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
|
2004-07-10 23:48:41 +00:00
|
|
|
#elif defined(CONFIG_MICROBLAZE)
|
2004-04-18 21:13:41 +00:00
|
|
|
/*
|
|
|
|
* r31 holds the pointer to the global_data. r5 is a call-clobbered.
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" lwi r5, r31, %0\n" \
|
|
|
|
" lwi r5, r5, %1\n" \
|
|
|
|
" bra r5\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5");
|
2006-03-12 01:10:00 +00:00
|
|
|
#elif defined(CONFIG_BLACKFIN)
|
|
|
|
/*
|
2009-08-17 15:23:02 +00:00
|
|
|
* P3 holds the pointer to the global_data, P0 is a call-clobbered
|
2006-03-12 01:10:00 +00:00
|
|
|
* register
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
2006-03-12 01:55:22 +00:00
|
|
|
asm volatile ( \
|
2007-12-27 00:52:50 +00:00
|
|
|
" .globl _" #x "\n_" \
|
2006-03-12 01:10:00 +00:00
|
|
|
#x ":\n" \
|
2009-08-17 15:23:02 +00:00
|
|
|
" P0 = [P3 + %0]\n" \
|
2006-03-12 01:10:00 +00:00
|
|
|
" P0 = [P0 + %1]\n" \
|
|
|
|
" JUMP (P0)\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "P0");
|
2006-10-24 12:21:16 +00:00
|
|
|
#elif defined(CONFIG_AVR32)
|
|
|
|
/*
|
|
|
|
* r6 holds the pointer to the global_data. r8 is call clobbered.
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile( \
|
|
|
|
" .globl\t" #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" ld.w r8, r6[%0]\n" \
|
|
|
|
" ld.w pc, r8[%1]\n" \
|
|
|
|
: \
|
|
|
|
: "i"(offsetof(gd_t, jt)), "i"(XF_ ##x) \
|
|
|
|
: "r8");
|
2007-05-13 11:58:00 +00:00
|
|
|
#elif defined(CONFIG_SH)
|
|
|
|
/*
|
|
|
|
* r13 holds the pointer to the global_data. r1 is a call clobbered.
|
|
|
|
*/
|
2007-12-27 00:52:50 +00:00
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .align 2\n" \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" mov r13, r1\n" \
|
|
|
|
" add %0, r1\n" \
|
2008-10-09 04:54:33 +00:00
|
|
|
" mov.l @r1, r2\n" \
|
|
|
|
" add %1, r2\n" \
|
|
|
|
" mov.l @r2, r1\n" \
|
2007-12-27 00:52:50 +00:00
|
|
|
" jmp @r1\n" \
|
|
|
|
" nop\n" \
|
|
|
|
" nop\n" \
|
2008-10-09 04:54:33 +00:00
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r1", "r2");
|
2008-03-28 08:47:00 +00:00
|
|
|
#elif defined(CONFIG_SPARC)
|
|
|
|
/*
|
|
|
|
* g7 holds the pointer to the global_data. g1 is call clobbered.
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile( \
|
|
|
|
" .globl\t" #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" set %0, %%g1\n" \
|
|
|
|
" or %%g1, %%g7, %%g1\n" \
|
|
|
|
" ld [%%g1], %%g1\n" \
|
|
|
|
" ld [%%g1 + %1], %%g1\n" \
|
2009-09-23 12:47:38 +00:00
|
|
|
" jmp %%g1\n" \
|
2008-03-28 08:47:00 +00:00
|
|
|
" nop\n" \
|
2009-09-23 12:47:38 +00:00
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "g1" );
|
2011-10-11 22:33:20 +00:00
|
|
|
#elif defined(CONFIG_NDS32)
|
|
|
|
/*
|
|
|
|
* r16 holds the pointer to the global_data. gp is call clobbered.
|
|
|
|
* not support reduced register (16 GPR).
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" lwi $r16, [$gp + (%0)]\n" \
|
|
|
|
" lwi $r16, [$r16 + (%1)]\n" \
|
|
|
|
" jr $r16\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "$r16");
|
2011-11-18 19:21:35 +00:00
|
|
|
#elif defined(CONFIG_OPENRISC)
|
|
|
|
/*
|
|
|
|
* r10 holds the pointer to the global_data, r13 is a call-clobbered
|
|
|
|
* register
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile ( \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" l.lwz r13, %0(r10)\n" \
|
|
|
|
" l.lwz r13, %1(r13)\n" \
|
|
|
|
" l.jr r13\n" \
|
|
|
|
" l.nop\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r13");
|
2014-02-04 08:56:17 +00:00
|
|
|
#elif defined(CONFIG_ARC)
|
|
|
|
/*
|
|
|
|
* r25 holds the pointer to the global_data. r10 is call clobbered.
|
|
|
|
*/
|
|
|
|
#define EXPORT_FUNC(x) \
|
|
|
|
asm volatile( \
|
|
|
|
" .align 4\n" \
|
|
|
|
" .globl " #x "\n" \
|
|
|
|
#x ":\n" \
|
|
|
|
" ld r10, [r25, %0]\n" \
|
|
|
|
" ld r10, [r10, %1]\n" \
|
|
|
|
" j [r10]\n" \
|
|
|
|
: : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r10");
|
2003-07-24 23:38:38 +00:00
|
|
|
#else
|
2011-10-11 22:33:20 +00:00
|
|
|
/*" addi $sp, $sp, -24\n" \
|
|
|
|
" br $r16\n" \*/
|
|
|
|
|
2003-07-24 23:38:38 +00:00
|
|
|
#error stubs definition missing for this architecture
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This function is necessary to prevent the compiler from
|
|
|
|
* generating prologue/epilogue, preparing stack frame etc.
|
|
|
|
* The stub functions are special, they do not use the stack
|
|
|
|
* frame passed to them, but pass it intact to the actual
|
|
|
|
* implementation. On the other hand, asm() statements with
|
|
|
|
* arguments can be used only inside the functions (gcc limitation)
|
|
|
|
*/
|
2004-07-01 20:28:03 +00:00
|
|
|
#if GCC_VERSION < 3004
|
|
|
|
static
|
|
|
|
#endif /* GCC_VERSION */
|
|
|
|
void __attribute__((unused)) dummy(void)
|
2003-07-24 23:38:38 +00:00
|
|
|
{
|
|
|
|
#include <_exports.h>
|
|
|
|
}
|
|
|
|
|
2013-03-05 14:39:39 +00:00
|
|
|
#include <asm/sections.h>
|
2004-04-12 16:12:49 +00:00
|
|
|
|
2010-06-28 20:00:46 +00:00
|
|
|
void app_startup(char * const *argv)
|
2003-07-24 23:38:38 +00:00
|
|
|
{
|
2013-03-05 14:39:39 +00:00
|
|
|
char *cp = __bss_start;
|
2004-04-12 16:12:49 +00:00
|
|
|
|
|
|
|
/* Zero out BSS */
|
2013-03-05 14:39:39 +00:00
|
|
|
while (cp < _end)
|
2004-04-12 16:12:49 +00:00
|
|
|
*cp++ = 0;
|
|
|
|
|
2011-04-13 09:43:28 +00:00
|
|
|
#if defined(CONFIG_X86)
|
2003-07-24 23:38:38 +00:00
|
|
|
/* x86 does not have a dedicated register for passing global_data */
|
2003-07-26 08:08:08 +00:00
|
|
|
global_data = (gd_t *)argv[-1];
|
|
|
|
jt = global_data->jt;
|
2003-07-24 23:38:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef EXPORT_FUNC
|