OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [ldso/] [ldso/] [sh64/] [ld_sysdep.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* vi: set sw=8 ts=8: */
2
/*
3
 * Various assmbly language/system dependent  hacks that are required
4
 * so that we can minimize the amount of platform specific code.
5
 */
6
 
7
/*
8
 * Define this if the system uses RELOCA.
9
 */
10
#define ELF_USES_RELOCA
11
 
12
/*
13
 * Get a pointer to the argv array.  On many platforms this can be just
14
 * the address if the first argument, on other platforms we need to
15
 * do something a little more subtle here.
16
 */
17
#define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long *)ARGS)
18
 
19
/*
20
 * Initialization sequence for a GOT.
21
 */
22
#define INIT_GOT(GOT_BASE,MODULE)                               \
23
{                                                               \
24
        GOT_BASE[2] = (unsigned long)_dl_linux_resolve;         \
25
        GOT_BASE[1] = (unsigned long)(MODULE);                  \
26
}
27
 
28
/*
29
 * Here is a macro to perform a relocation.  This is only used when
30
 * bootstrapping the dynamic loader.  RELP is the relocation that we
31
 * are performing, REL is the pointer to the address we are relocating.
32
 * SYMBOL is the symbol involved in the relocation, and LOAD is the
33
 * load address.
34
 */
35
 
36
/*
37
 * We need to do this stupidity here as the preprocessor will choke when
38
 * SYMTAB is NULL if we do this in PERFORM_BOOTSTRAP_RELOC().
39
 */
40
 
41
#include <elf.h>
42
 
43
static inline int __extract_lsb_from_symtab(Elf32_Sym *symtab)
44
{
45
        static int lsb = 0;
46
 
47
        /* Check for SHmedia/SHcompact */
48
        if (symtab)
49
                lsb = symtab->st_other & 4;
50
 
51
        return lsb;
52
}
53
 
54
/*
55
 * While on the subject of stupidity, there appear to be some conflicts with
56
 * regards to several relocation types as far as binutils is concerned
57
 * (Barcelona and Madrid both appear to use an out of date elf.h, whereas
58
 * native Catalonia has all of the necessary definitions. As a workaround,
59
 * we'll just define them here for sanity..
60
 */
61
#ifndef R_SH_RELATIVE_LOW16
62
#  define R_SH_RELATIVE_LOW16           197
63
#  define R_SH_RELATIVE_MEDLOW16        198
64
#  define R_SH_IMM_LOW16                246
65
#  define R_SH_IMM_LOW16_PCREL          247
66
#  define R_SH_IMM_MEDLOW16             248
67
#  define R_SH_IMM_MEDLOW16_PCREL       249
68
#endif
69
 
70
#define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB)            \
71
        const unsigned int r_type = ELF32_R_TYPE((RELP)->r_info);       \
72
        int lsb = __extract_lsb_from_symtab(SYMTAB);                    \
73
                                                                        \
74
        switch (r_type) {                                               \
75
        case R_SH_REL32:                                                \
76
                *(REL)  = (SYMBOL) + (RELP)->r_addend                   \
77
                            - (unsigned long)(REL);                     \
78
                break;                                                  \
79
        case R_SH_DIR32:                                                \
80
        case R_SH_GLOB_DAT:                                             \
81
        case R_SH_JMP_SLOT:                                             \
82
                *(REL)  = ((SYMBOL) + (RELP)->r_addend) | lsb;          \
83
                break;                                                  \
84
        case R_SH_RELATIVE:                                             \
85
                *(REL)  = (LOAD) + (RELP)->r_addend;                    \
86
                break;                                                  \
87
        case R_SH_RELATIVE_LOW16:                                       \
88
        case R_SH_RELATIVE_MEDLOW16:                                    \
89
        {                                                               \
90
                unsigned long word, value;                              \
91
                                                                        \
92
                word = (unsigned long)(REL) & ~0x3fffc00;               \
93
                value = (LOAD) + (RELP)->r_addend;                      \
94
                                                                        \
95
                if (r_type == R_SH_RELATIVE_MEDLOW16)                   \
96
                        value >>= 16;                                   \
97
                                                                        \
98
                word |= (value & 0xffff) << 10;                         \
99
                *(REL)  = word;                                         \
100
                break;                                                  \
101
        }                                                               \
102
        case R_SH_IMM_LOW16:                                            \
103
        case R_SH_IMM_MEDLOW16:                                         \
104
        {                                                               \
105
                unsigned long word, value;                              \
106
                                                                        \
107
                word = (unsigned long)(REL) & ~0x3fffc00;               \
108
                value = ((SYMBOL) + (RELP)->r_addend) | lsb;            \
109
                                                                        \
110
                if (r_type == R_SH_IMM_MEDLOW16)                        \
111
                        value >>= 16;                                   \
112
                                                                        \
113
                word |= (value & 0xffff) << 10;                         \
114
                *(REL)  = word;                                         \
115
                break;                                                  \
116
        }                                                               \
117
        case R_SH_IMM_LOW16_PCREL:                                      \
118
        case R_SH_IMM_MEDLOW16_PCREL:                                   \
119
        {                                                               \
120
                unsigned long word, value;                              \
121
                                                                        \
122
                word = (unsigned long)(REL) & ~0x3fffc00;               \
123
                value = (SYMBOL) + (RELP)->r_addend                     \
124
                          - (unsigned long)(REL);                       \
125
                                                                        \
126
                if (r_type == R_SH_IMM_MEDLOW16_PCREL)                  \
127
                        value >>= 16;                                   \
128
                                                                        \
129
                word |= (value & 0xffff) << 10;                         \
130
                *(REL)  = word;                                         \
131
                break;                                                  \
132
        }                                                               \
133
        case R_SH_NONE:                                                 \
134
                break;                                                  \
135
        default:                                                        \
136
                SEND_STDERR("BOOTSTRAP_RELOC: unhandled reloc type ");  \
137
                SEND_NUMBER_STDERR(ELF32_R_TYPE((RELP)->r_info), 1);    \
138
                SEND_STDERR("REL, SYMBOL, LOAD: ");                     \
139
                SEND_ADDRESS_STDERR(REL, 0);                             \
140
                SEND_STDERR(", ");                                      \
141
                SEND_ADDRESS_STDERR(SYMBOL, 0);                          \
142
                SEND_STDERR(", ");                                      \
143
                SEND_ADDRESS_STDERR(LOAD, 1);                           \
144
                _dl_exit(1);                                            \
145
        }
146
 
147
/*
148
 * Transfer control to the user's application, once the dynamic loader
149
 * is done.  This routine has to exit the current function, then
150
 * call the _dl_elf_main function.
151
 */
152
 
153
#define START()   return _dl_elf_main;
154
 
155
/* Here we define the magic numbers that this dynamic loader should accept */
156
#define MAGIC1 EM_SH
157
#undef  MAGIC2
158
/* Used for error messages */
159
#define ELF_TARGET "sh64"
160
 
161
struct elf_resolve;
162
extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
163
 
164
#define do_rem(result, n, base)  result = (n % base)
165
 
166
/* 4096 bytes alignment */
167
#define PAGE_ALIGN 0xfffff000
168
#define ADDR_ALIGN 0xfff
169
#define OFFS_ALIGN 0x7ffff000
170
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.