OSDN Git Service

- trim any trailing whitespace
[uclinux-h8/uClibc.git] / ldso / ldso / xtensa / dl-startup.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Xtensa ELF code used by dl-startup.c.
4  *
5  * Copyright (C) 2007 Tensilica Inc.
6  *
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.
9  */
10
11 __asm__ (
12     "   .text\n"
13     "   .align  4\n"
14     "   .global _start\n"
15     "   .type   _start, @function\n"
16     "_start:\n"
17     "   # Compute load offset in a2: the GOT has not yet been relocated\n"
18     "   # but the entries for local symbols contain the relative offsets\n"
19     "   # and we can explicitly add the load offset in this code.\n"
20     "   _call0  0f\n"
21     "   .align  4\n"
22     "0: movi    a3, _start+3\n"
23     "   sub     a2, a0, a3\n"
24     "   # Make sure a0 is cleared to mark the top of stack.\n"
25     "   movi    a0, 0\n"
26     "   # user_entry_point = _dl_start(pointer to argument block)\n"
27     "   movi    a4, _dl_start\n"
28     "   mov     a6, sp\n"
29     "   add     a4, a4, a2\n"
30     "   callx4  a4\n"
31     "   # Save user_entry_point so we can jump to it.\n"
32     "   mov     a3, a6\n"
33     "   l32i    a7, sp, 0   # load argc\n"
34     "   # Load _dl_skip_args into a4.\n"
35     "   movi    a4, _dl_skip_args\n"
36     "   l32i    a4, a4, 0\n"
37     "   bnez    a4, .Lfixup_stack\n"
38     ".Lfixup_stack_ret:\n"
39     "   # Pass finalizer (_dl_fini) in a2 to the user entry point.\n"
40     "   movi    a2, _dl_fini\n"
41     "   # Jump to user's entry point (_start).\n"
42     "   jx      a3\n"
43     ".Lfixup_stack:\n"
44     "   # argc -= _dl_skip_args (with argc @ sp+0)\n"
45     "   sub     a7, a7, a4\n"
46     "   s32i    a7, sp, 0\n"
47     "   # Shift everything by _dl_skip_args.\n"
48     "   addi    a5, sp, 4   # a5 = destination ptr = argv\n"
49     "   add     a4, a5, a4  # a4 = source ptr = argv + _dl_skip_args\n"
50     "   # Shift argv.\n"
51     "1: l32i    a6, a4, 0\n"
52     "   addi    a4, a4, 4\n"
53     "   s32i    a6, a5, 0\n"
54     "   addi    a5, a5, 4\n"
55     "   bnez    a6, 1b\n"
56     "   # Shift envp.\n"
57     "2: l32i    a6, a4, 0\n"
58     "   addi    a4, a4, 4\n"
59     "   s32i    a6, a5, 0\n"
60     "   addi    a5, a5, 4\n"
61     "   bnez    a6, 2b\n"
62     "   # Shift auxiliary table.\n"
63     "3: l32i    a6, a4, 0\n"
64     "   l32i    a8, a4, 4\n"
65     "   addi    a4, a4, 8\n"
66     "   s32i    a6, a5, 0\n"
67     "   s32i    a8, a5, 4\n"
68     "   addi    a5, a5, 8\n"
69     "   bnez    a6, 3b\n"
70     "   j      .Lfixup_stack_ret");
71
72 /* Get a pointer to the argv value.  */
73 #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS) + 1)
74
75 /* Function calls are not safe until the GOT relocations have been done.  */
76 #define NO_FUNCS_BEFORE_BOOTSTRAP
77
78 #define PERFORM_BOOTSTRAP_GOT(tpnt) \
79 do { \
80         xtensa_got_location *got_loc; \
81         unsigned long l_addr = tpnt->loadaddr; \
82         Elf32_Word relative_count; \
83         unsigned long rel_addr; \
84         int x; \
85 \
86         got_loc = (xtensa_got_location *) \
87                 (tpnt->dynamic_info[DT_XTENSA (GOT_LOC_OFF)] + l_addr); \
88 \
89         for (x = 0; x < tpnt->dynamic_info[DT_XTENSA (GOT_LOC_SZ)]; x++) { \
90                 Elf32_Addr got_start, got_end; \
91                 got_start = got_loc[x].offset & ~(PAGE_SIZE - 1); \
92                 got_end = ((got_loc[x].offset + got_loc[x].length + PAGE_SIZE - 1) \
93                                    & ~(PAGE_SIZE - 1)); \
94                 _dl_mprotect ((void *)(got_start + l_addr), got_end - got_start, \
95                                           PROT_READ | PROT_WRITE | PROT_EXEC); \
96         } \
97 \
98         /* The following is a stripped down version of the code following \
99            the invocation of PERFORM_BOOTSTRAP_GOT in dl-startup.c.      That \
100            code is skipped when PERFORM_BOOTSTRAP_GOT is defined, so it has \
101            to be done here instead.      */ \
102         relative_count = tpnt->dynamic_info[DT_RELCONT_IDX]; \
103         rel_addr = tpnt->dynamic_info[DT_RELOC_TABLE_ADDR]; \
104         if (rel_addr) \
105           elf_machine_relative(load_addr, rel_addr, relative_count); \
106 } while (0)