1 /* vi: set sw=4 ts=4: */
3 * Xtensa ELF code used by dl-startup.c.
5 * Copyright (C) 2007 Tensilica Inc.
7 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8 * Parts taken from glibc/sysdeps/xtensa/dl-machine.h.
14 " .literal_position\n"
16 " .type _start, @function\n"
19 " # Compute load offset in a2: the GOT has not yet been relocated\n"
20 " # but the entries for local symbols contain the relative offsets\n"
21 " # and we can explicitly add the load offset in this code.\n"
24 "0: movi a3, _start+3\n"
26 " # Make sure a0 is cleared to mark the top of stack.\n"
28 " # user_entry_point = _dl_start(pointer to argument block)\n"
29 " movi a4, _dl_start\n"
33 " # Save user_entry_point so we can jump to it.\n"
35 " l32i a7, sp, 0 # load argc\n"
36 " # Load _dl_skip_args into a4.\n"
37 " movi a4, _dl_skip_args\n"
39 " bnez a4, .Lfixup_stack\n"
40 ".Lfixup_stack_ret:\n"
41 " # Pass finalizer (_dl_fini) in a2 to the user entry point.\n"
42 " movi a2, _dl_fini\n"
43 " # Jump to user's entry point (_start).\n"
46 " # argc -= _dl_skip_args (with argc @ sp+0)\n"
49 " # Shift everything by _dl_skip_args.\n"
50 " addi a5, sp, 4 # a5 = destination ptr = argv\n"
51 " add a4, a5, a4 # a4 = source ptr = argv + _dl_skip_args\n"
64 " # Shift auxiliary table.\n"
72 " j .Lfixup_stack_ret");
74 /* Get a pointer to the argv value. */
75 #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS) + 1)
77 /* Function calls are not safe until the GOT relocations have been done. */
78 #define NO_FUNCS_BEFORE_BOOTSTRAP
80 #define PERFORM_BOOTSTRAP_GOT(tpnt) \
82 xtensa_got_location *got_loc; \
83 unsigned long l_addr = tpnt->loadaddr; \
84 Elf32_Word relative_count; \
85 unsigned long rel_addr; \
86 Elf32_Addr prev_got_start = 0, prev_got_end = 0; \
89 got_loc = (xtensa_got_location *) \
90 (tpnt->dynamic_info[DT_XTENSA (GOT_LOC_OFF)] + l_addr); \
92 for (x = 0; x < tpnt->dynamic_info[DT_XTENSA (GOT_LOC_SZ)]; x++) { \
93 Elf32_Addr got_start, got_end; \
94 got_start = got_loc[x].offset & ~(PAGE_SIZE - 1); \
95 got_end = ((got_loc[x].offset + got_loc[x].length + PAGE_SIZE - 1) \
96 & ~(PAGE_SIZE - 1)); \
97 if (got_end >= prev_got_start && got_start <= prev_got_end) { \
98 if (got_end > prev_got_end) \
99 prev_got_end = got_end; \
100 if (got_start < prev_got_start) \
101 prev_got_start = got_start; \
103 } else if (prev_got_start != prev_got_end) { \
104 _dl_mprotect ((void *)(prev_got_start + l_addr), \
105 prev_got_end - prev_got_start, \
106 PROT_READ | PROT_WRITE | PROT_EXEC); \
108 prev_got_start = got_start; \
109 prev_got_end = got_end; \
112 if (prev_got_start != prev_got_end) { \
113 _dl_mprotect ((void *)(prev_got_start + l_addr), \
114 prev_got_end - prev_got_start, \
115 PROT_READ | PROT_WRITE | PROT_EXEC); \
118 /* The following is a stripped down version of the code following \
119 the invocation of PERFORM_BOOTSTRAP_GOT in dl-startup.c. That \
120 code is skipped when PERFORM_BOOTSTRAP_GOT is defined, so it has \
121 to be done here instead. */ \
122 relative_count = tpnt->dynamic_info[DT_RELCONT_IDX]; \
123 rel_addr = tpnt->dynamic_info[DT_RELOC_TABLE_ADDR]; \
125 elf_machine_relative(load_addr, rel_addr, relative_count); \