-
Notifications
You must be signed in to change notification settings - Fork 9
/
t_elf32m68k.c
212 lines (177 loc) · 6.45 KB
/
t_elf32m68k.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* $VER: vlink t_elf32m68k.c V0.13 (02.11.10)
*
* This file is part of vlink, a portable linker for multiple
* object formats.
* Copyright (c) 1997-2010 Frank Wille
*/
#include "config.h"
#if defined(ELF32_M68K)
#define T_ELF32M68K_C
#include "vlink.h"
#include "elf32.h"
#include "rel_elfm68k.h"
static int m68k_identify(struct GlobalVars *gv,char *,uint8_t *,
unsigned long,bool);
static void m68k_readconv(struct GlobalVars *,struct LinkFile *);
static struct Symbol *m68k_dynentry(struct GlobalVars *,DynArg,int);
static void m68k_dyncreate(struct GlobalVars *);
static void m68k_writeobject(struct GlobalVars *,FILE *);
static void m68k_writeshared(struct GlobalVars *,FILE *);
static void m68k_writeexec(struct GlobalVars *,FILE *);
struct FFFuncs fff_elf32m68k = {
"elf32m68k",
NULL,
NULL,
NULL,
NULL,
elf32_headersize,
m68k_identify,
m68k_readconv,
NULL,
elf_targetlink,
NULL,
elf_lnksym,
elf_setlnksym,
elf32_initdynlink,
m68k_dynentry,
m68k_dyncreate,
m68k_writeobject,
m68k_writeshared,
m68k_writeexec,
bss_name,sbss_name,
0x2000,
0x8000,
0,
0,
RTAB_ADDEND,RTAB_STANDARD|RTAB_ADDEND,
_BIG_ENDIAN_,
32,2
};
/*****************************************************************/
/* Read ELF */
/*****************************************************************/
static int m68k_identify(struct GlobalVars *gv,char *name,uint8_t *p,
unsigned long plen,bool lib)
/* identify ELF-M68k-32Bit-BigEndian */
{
return (elf_identify(&fff_elf32m68k,name,p,plen,
ELFCLASS32,ELFDATA2MSB,EM_68K,ELF_VER));
}
static uint8_t m68k_reloc_elf2vlink(uint8_t rtype,struct RelocInsert *ri)
/* Determine vlink internal reloc type from ELF reloc type and fill in
reloc-insert description information.
All fields of the RelocInsert structure are preset to zero. */
{
static struct ELF2vlink convertV4[] = {
R_NONE,0,0,-1,
R_ABS,0,32,-1, /* R_68K_32 */
R_ABS,0,16,-1, /* R_68K_16 */
R_ABS,0,8,-1, /* R_68K_8 */
R_PC,0,32,-1, /* R_68K_PC32 */
R_PC,0,16,-1, /* R_68K_PC16 */
R_PC,0,8,-1, /* R_68K_PC8 */
R_GOT,0,32,-1, /* R_68K_GOT32 */
R_GOT,0,16,-1, /* R_68K_GOT16 */
R_GOT,0,8,-1, /* R_68K_GOT8 */
R_GOTOFF,0,32,-1, /* R_68K_GOT32O */
R_GOTOFF,0,16,-1, /* R_68K_GOT16O */
R_GOTOFF,0,8,-1, /* R_68K_GOT8O */
R_PLT,0,32,-1, /* R_68K_PLT32 */
R_PLT,0,16,-1, /* R_68K_PLT16 */
R_PLT,0,8,-1, /* R_68K_PLT8 */
R_PLTOFF,0,32,-1, /* R_68K_PLT32O */
R_PLTOFF,0,16,-1, /* R_68K_PLT16O */
R_PLTOFF,0,8,-1, /* R_68K_PLT8O */
R_COPY,0,32,-1, /* R_68K_COPY */
R_GLOBDAT,0,32,-1, /* R_68K_GLOB_DAT */
R_JMPSLOT,0,0,-1, /* R_68K_JMP_SLOT */
R_LOADREL,0,32,-1 /* R_68K_RELATIVE */
};
if (rtype <= R_68K_RELATIVE) {
ri->bpos = convertV4[rtype].bpos;
ri->bsiz = convertV4[rtype].bsiz;
ri->mask = convertV4[rtype].mask;
rtype = convertV4[rtype].rtype;
}
else
rtype = R_NONE;
return (rtype);
}
static void m68k_readconv(struct GlobalVars *gv,struct LinkFile *lf)
/* Read ELF-68k executable / object / shared obj. */
{
if (lf->type == ID_LIBARCH) {
struct ar_info ai;
if (ar_init(&ai,(char *)lf->data,lf->length,lf->filename)) {
while (ar_extract(&ai)) {
lf->objname = allocstring(ai.name);
if (elf_check_ar_type(fff[lf->format],lf->pathname,ai.data,
ELFCLASS32,ELFDATA2MSB,ELF_VER,1,EM_68K))
elf32_parse(gv,lf,(struct Elf32_Ehdr *)ai.data,m68k_reloc_elf2vlink);
}
}
else
ierror("m68k_readconv(): archive %s corrupted since last access",
lf->pathname);
}
else {
lf->objname = lf->filename;
elf32_parse(gv,lf,(struct Elf32_Ehdr *)lf->data,m68k_reloc_elf2vlink);
}
}
static struct Symbol *m68k_dynentry(struct GlobalVars *gv,DynArg a,int etype)
{
ierror("m68k_dynentry(): needs to be written");
return NULL;
}
static void m68k_dyncreate(struct GlobalVars *gv)
{
elf32_dyncreate(gv,plt_name);
}
/*****************************************************************/
/* Write ELF */
/*****************************************************************/
static uint8_t m68k_reloc_vlink2elf(struct Reloc *r)
/* Try to map vlink-internal representation to a valid ELF reloc type */
{
if (isstdreloc(r,R_ABS,32)) return R_68K_32;
else if (isstdreloc(r,R_ABS,16)) return R_68K_16;
else if (isstdreloc(r,R_ABS,8)) return R_68K_8;
else if (isstdreloc(r,R_PC,32)) return R_68K_PC32;
else if (isstdreloc(r,R_PC,16)) return R_68K_PC16;
else if (isstdreloc(r,R_PC,8)) return R_68K_PC8;
else if (isstdreloc(r,R_GOT,32)) return R_68K_GOT32;
else if (isstdreloc(r,R_GOT,16)) return R_68K_GOT16;
else if (isstdreloc(r,R_GOT,8)) return R_68K_GOT8;
else if (isstdreloc(r,R_GOTOFF,32)) return R_68K_GOT32O;
else if (isstdreloc(r,R_GOTOFF,16)) return R_68K_GOT16O;
else if (isstdreloc(r,R_GOTOFF,8)) return R_68K_GOT8O;
else if (isstdreloc(r,R_PLT,32)) return R_68K_PLT32;
else if (isstdreloc(r,R_PLT,16)) return R_68K_PLT16;
else if (isstdreloc(r,R_PLT,8)) return R_68K_PLT8;
else if (isstdreloc(r,R_PLTOFF,32)) return R_68K_PLT32O;
else if (isstdreloc(r,R_PLTOFF,16)) return R_68K_PLT16O;
else if (isstdreloc(r,R_PLTOFF,8)) return R_68K_PLT8O;
else if (r->rtype == R_COPY) return R_68K_COPY;
else if (r->rtype == R_GLOBDAT) return R_68K_GLOB_DAT;
else if (r->rtype == R_JMPSLOT) return R_68K_JMP_SLOT;
else if (r->rtype == R_LOADREL) return R_68K_RELATIVE;
return R_NONE;
}
static void m68k_writeshared(struct GlobalVars *gv,FILE *f)
/* creates a target-elf32m68k shared object (which is pos. independent) */
{
ierror("m68k_writeshared(): Shared object generation has not "
"yet been implemented");
}
static void m68k_writeobject(struct GlobalVars *gv,FILE *f)
/* creates a target-elf32m68k relocatable object file */
{
elf32_writeobject(gv,f,EM_68K,_BIG_ENDIAN_,m68k_reloc_vlink2elf);
}
static void m68k_writeexec(struct GlobalVars *gv,FILE *f)
/* creates a target-elf32m68k executable file (with absolute addresses) */
{
elf32_writeexec(gv,f,EM_68K,_BIG_ENDIAN_,m68k_reloc_vlink2elf);
}
#endif /* ELF32_M68K */