| 1 |
1325 |
phoenix |
/*
|
| 2 |
|
|
* Various assmbly language/system dependent hacks that are required
|
| 3 |
|
|
* so that we can minimize the amount of platform specific code.
|
| 4 |
|
|
*/
|
| 5 |
|
|
|
| 6 |
|
|
/*
|
| 7 |
|
|
* Define this if the system uses RELOCA.
|
| 8 |
|
|
*/
|
| 9 |
|
|
#define ELF_USES_RELOCA
|
| 10 |
|
|
|
| 11 |
|
|
/*
|
| 12 |
|
|
* Get a pointer to the argv array. On many platforms this can be just
|
| 13 |
|
|
* the address if the first argument, on other platforms we need to
|
| 14 |
|
|
* do something a little more subtle here.
|
| 15 |
|
|
*/
|
| 16 |
|
|
#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1)
|
| 17 |
|
|
|
| 18 |
|
|
/*
|
| 19 |
|
|
* Initialization sequence for a GOT.
|
| 20 |
|
|
*/
|
| 21 |
|
|
#define INIT_GOT(GOT_BASE,MODULE) _dl_init_got(GOT_BASE,MODULE)
|
| 22 |
|
|
|
| 23 |
|
|
/* Stuff for the PLT. */
|
| 24 |
|
|
#define PLT_INITIAL_ENTRY_WORDS 18
|
| 25 |
|
|
#define PLT_LONGBRANCH_ENTRY_WORDS 0
|
| 26 |
|
|
#define PLT_TRAMPOLINE_ENTRY_WORDS 6
|
| 27 |
|
|
#define PLT_DOUBLE_SIZE (1<<13)
|
| 28 |
|
|
#define PLT_ENTRY_START_WORDS(entry_number) \
|
| 29 |
|
|
(PLT_INITIAL_ENTRY_WORDS + (entry_number)*2 \
|
| 30 |
|
|
+ ((entry_number) > PLT_DOUBLE_SIZE \
|
| 31 |
|
|
? ((entry_number) - PLT_DOUBLE_SIZE)*2 \
|
| 32 |
|
|
: 0))
|
| 33 |
|
|
#define PLT_DATA_START_WORDS(num_entries) PLT_ENTRY_START_WORDS(num_entries)
|
| 34 |
|
|
|
| 35 |
|
|
/* Macros to build PowerPC opcode words. */
|
| 36 |
|
|
#define OPCODE_ADDI(rd,ra,simm) \
|
| 37 |
|
|
(0x38000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff))
|
| 38 |
|
|
#define OPCODE_ADDIS(rd,ra,simm) \
|
| 39 |
|
|
(0x3c000000 | (rd) << 21 | (ra) << 16 | ((simm) & 0xffff))
|
| 40 |
|
|
#define OPCODE_ADD(rd,ra,rb) \
|
| 41 |
|
|
(0x7c000214 | (rd) << 21 | (ra) << 16 | (rb) << 11)
|
| 42 |
|
|
#define OPCODE_B(target) (0x48000000 | ((target) & 0x03fffffc))
|
| 43 |
|
|
#define OPCODE_BA(target) (0x48000002 | ((target) & 0x03fffffc))
|
| 44 |
|
|
#define OPCODE_BCTR() 0x4e800420
|
| 45 |
|
|
#define OPCODE_LWZ(rd,d,ra) \
|
| 46 |
|
|
(0x80000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff))
|
| 47 |
|
|
#define OPCODE_LWZU(rd,d,ra) \
|
| 48 |
|
|
(0x84000000 | (rd) << 21 | (ra) << 16 | ((d) & 0xffff))
|
| 49 |
|
|
#define OPCODE_MTCTR(rd) (0x7C0903A6 | (rd) << 21)
|
| 50 |
|
|
#define OPCODE_RLWINM(ra,rs,sh,mb,me) \
|
| 51 |
|
|
(0x54000000 | (rs) << 21 | (ra) << 16 | (sh) << 11 | (mb) << 6 | (me) << 1)
|
| 52 |
|
|
|
| 53 |
|
|
#define OPCODE_LI(rd,simm) OPCODE_ADDI(rd,0,simm)
|
| 54 |
|
|
#define OPCODE_ADDIS_HI(rd,ra,value) \
|
| 55 |
|
|
OPCODE_ADDIS(rd,ra,((value) + 0x8000) >> 16)
|
| 56 |
|
|
#define OPCODE_LIS_HI(rd,value) OPCODE_ADDIS_HI(rd,0,value)
|
| 57 |
|
|
#define OPCODE_SLWI(ra,rs,sh) OPCODE_RLWINM(ra,rs,sh,0,31-sh)
|
| 58 |
|
|
|
| 59 |
|
|
|
| 60 |
|
|
#define PPC_DCBST(where) asm volatile ("dcbst 0,%0" : : "r"(where) : "memory")
|
| 61 |
|
|
#define PPC_SYNC asm volatile ("sync" : : : "memory")
|
| 62 |
|
|
#define PPC_ISYNC asm volatile ("sync; isync" : : : "memory")
|
| 63 |
|
|
#define PPC_ICBI(where) asm volatile ("icbi 0,%0" : : "r"(where) : "memory")
|
| 64 |
|
|
#define PPC_DIE asm volatile ("tweq 0,0")
|
| 65 |
|
|
|
| 66 |
|
|
/*
|
| 67 |
|
|
* Here is a macro to perform a relocation. This is only used when
|
| 68 |
|
|
* bootstrapping the dynamic loader. RELP is the relocation that we
|
| 69 |
|
|
* are performing, REL is the pointer to the address we are relocating.
|
| 70 |
|
|
* SYMBOL is the symbol involved in the relocation, and LOAD is the
|
| 71 |
|
|
* load address.
|
| 72 |
|
|
*/
|
| 73 |
|
|
// finaladdr = LOAD ?
|
| 74 |
|
|
#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
|
| 75 |
|
|
{int type=ELF32_R_TYPE((RELP)->r_info); \
|
| 76 |
|
|
if(type==R_PPC_NONE){ \
|
| 77 |
|
|
}else if(type==R_PPC_ADDR32){ \
|
| 78 |
|
|
*REL += (SYMBOL); \
|
| 79 |
|
|
}else if(type==R_PPC_RELATIVE){ \
|
| 80 |
|
|
*REL = (Elf32_Word)(LOAD) + (RELP)->r_addend; \
|
| 81 |
|
|
}else if(type==R_PPC_REL24){ \
|
| 82 |
|
|
Elf32_Sword delta = (Elf32_Word)(SYMBOL) - (Elf32_Word)(REL); \
|
| 83 |
|
|
*REL &= 0xfc000003; \
|
| 84 |
|
|
*REL |= (delta & 0x03fffffc); \
|
| 85 |
|
|
}else if(type==R_PPC_JMP_SLOT){ \
|
| 86 |
|
|
Elf32_Sword delta = (Elf32_Word)(SYMBOL) - (Elf32_Word)(REL); \
|
| 87 |
|
|
/*if (delta << 6 >> 6 != delta)_dl_exit(99);*/ \
|
| 88 |
|
|
*REL = OPCODE_B(delta); \
|
| 89 |
|
|
}else{ \
|
| 90 |
|
|
_dl_exit(100+ELF32_R_TYPE((RELP)->r_info)); \
|
| 91 |
|
|
} \
|
| 92 |
|
|
if(type!=R_PPC_NONE){ \
|
| 93 |
|
|
PPC_DCBST(REL); PPC_SYNC; PPC_ICBI(REL);\
|
| 94 |
|
|
} \
|
| 95 |
|
|
}
|
| 96 |
|
|
|
| 97 |
|
|
/*
|
| 98 |
|
|
* Transfer control to the user's application, once the dynamic loader
|
| 99 |
|
|
* is done. This routine has to exit the current function, then
|
| 100 |
|
|
* call the _dl_elf_main function.
|
| 101 |
|
|
*/
|
| 102 |
|
|
|
| 103 |
|
|
/* hgb@ifi.uio.no:
|
| 104 |
|
|
* Adding a clobber list consisting of r0 for %1. addi on PowerPC
|
| 105 |
|
|
* takes a register as the second argument, but if the register is
|
| 106 |
|
|
* r0, the value 0 is used instead. If r0 is used here, the stack
|
| 107 |
|
|
* pointer (r1) will be zeroed, and the dynamically linked
|
| 108 |
|
|
* application will seg.fault immediatly when receiving control.
|
| 109 |
|
|
*/
|
| 110 |
|
|
#define START() \
|
| 111 |
|
|
__asm__ volatile ( \
|
| 112 |
|
|
"addi 1,%1,0\n\t" \
|
| 113 |
|
|
"mtlr %0\n\t" \
|
| 114 |
|
|
"blrl\n\t" \
|
| 115 |
|
|
: : "r" (_dl_elf_main), "r" (args) \
|
| 116 |
|
|
: "r0")
|
| 117 |
|
|
|
| 118 |
|
|
|
| 119 |
|
|
/* Here we define the magic numbers that this dynamic loader should accept */
|
| 120 |
|
|
|
| 121 |
|
|
#define MAGIC1 EM_PPC
|
| 122 |
|
|
#undef MAGIC2
|
| 123 |
|
|
/* Used for error messages */
|
| 124 |
|
|
#define ELF_TARGET "powerpc"
|
| 125 |
|
|
|
| 126 |
|
|
struct elf_resolve;
|
| 127 |
|
|
extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
|
| 128 |
|
|
void _dl_init_got(unsigned long *lpnt,struct elf_resolve *tpnt);
|
| 129 |
|
|
|
| 130 |
|
|
|
| 131 |
|
|
#define do_rem(result, n, base) result = (n % base)
|
| 132 |
|
|
|
| 133 |
|
|
/* 4096 bytes alignment */
|
| 134 |
|
|
#define PAGE_ALIGN 0xfffff000
|
| 135 |
|
|
#define ADDR_ALIGN 0xfff
|
| 136 |
|
|
#define OFFS_ALIGN 0x7ffff000
|