Add field ``name'' to floatformat.
[binutils.git] / bfd / elf32-arc.c
blob318dc704e06c829203f7a17cd6097c3b8223ee47
1 /* ARC-specific support for 32-bit ELF
2 Copyright (C) 1994, 1995, 1997, 1999 Free Software Foundation, Inc.
3 Contributed by Doug Evans (dje@cygnus.com).
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24 #include "elf-bfd.h"
25 #include "elf/arc.h"
27 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
28 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
29 static void arc_info_to_howto_rel
30 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
31 static boolean arc_elf_object_p PARAMS ((bfd *));
32 static void arc_elf_final_write_processing PARAMS ((bfd *, boolean));
34 /* Try to minimize the amount of space occupied by relocation tables
35 on the ROM (not that the ROM won't be swamped by other ELF overhead). */
36 #define USE_REL
38 static reloc_howto_type elf_arc_howto_table[] =
40 /* This reloc does nothing. */
41 HOWTO (R_ARC_NONE, /* type */
42 0, /* rightshift */
43 2, /* size (0 = byte, 1 = short, 2 = long) */
44 32, /* bitsize */
45 false, /* pc_relative */
46 0, /* bitpos */
47 complain_overflow_bitfield, /* complain_on_overflow */
48 bfd_elf_generic_reloc, /* special_function */
49 "R_ARC_NONE", /* name */
50 false, /* partial_inplace */
51 0, /* src_mask */
52 0, /* dst_mask */
53 false), /* pcrel_offset */
55 /* A standard 32 bit relocation. */
56 HOWTO (R_ARC_32, /* type */
57 0, /* rightshift */
58 2, /* size (0 = byte, 1 = short, 2 = long) */
59 32, /* bitsize */
60 false, /* pc_relative */
61 0, /* bitpos */
62 complain_overflow_bitfield, /* complain_on_overflow */
63 bfd_elf_generic_reloc, /* special_function */
64 "R_ARC_32", /* name */
65 false, /* partial_inplace */
66 0xffffffff, /* src_mask */
67 0xffffffff, /* dst_mask */
68 false), /* pcrel_offset */
70 /* A 26 bit absolute branch, right shifted by 2. */
71 HOWTO (R_ARC_B26, /* type */
72 2, /* rightshift */
73 2, /* size (0 = byte, 1 = short, 2 = long) */
74 26, /* bitsize */
75 false, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_bitfield, /* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_ARC_B26", /* name */
80 false, /* partial_inplace */
81 0x00ffffff, /* src_mask */
82 0x00ffffff, /* dst_mask */
83 false), /* pcrel_offset */
85 /* A relative 22 bit branch; bits 21-2 are stored in bits 26-7. */
86 HOWTO (R_ARC_B22_PCREL, /* type */
87 2, /* rightshift */
88 2, /* size (0 = byte, 1 = short, 2 = long) */
89 22, /* bitsize */
90 true, /* pc_relative */
91 7, /* bitpos */
92 complain_overflow_signed, /* complain_on_overflow */
93 bfd_elf_generic_reloc, /* special_function */
94 "R_ARC_B22_PCREL", /* name */
95 false, /* partial_inplace */
96 0x07ffff80, /* src_mask */
97 0x07ffff80, /* dst_mask */
98 true), /* pcrel_offset */
102 /* Map BFD reloc types to ARC ELF reloc types. */
104 struct arc_reloc_map
106 bfd_reloc_code_real_type bfd_reloc_val;
107 unsigned char elf_reloc_val;
110 static const struct arc_reloc_map arc_reloc_map[] =
112 { BFD_RELOC_NONE, R_ARC_NONE, },
113 { BFD_RELOC_32, R_ARC_32 },
114 { BFD_RELOC_CTOR, R_ARC_32 },
115 { BFD_RELOC_ARC_B26, R_ARC_B26 },
116 { BFD_RELOC_ARC_B22_PCREL, R_ARC_B22_PCREL },
119 static reloc_howto_type *
120 bfd_elf32_bfd_reloc_type_lookup (abfd, code)
121 bfd *abfd ATTRIBUTE_UNUSED;
122 bfd_reloc_code_real_type code;
124 unsigned int i;
126 for (i = 0;
127 i < sizeof (arc_reloc_map) / sizeof (struct arc_reloc_map);
128 i++)
130 if (arc_reloc_map[i].bfd_reloc_val == code)
131 return &elf_arc_howto_table[arc_reloc_map[i].elf_reloc_val];
134 return NULL;
137 /* Set the howto pointer for an ARC ELF reloc. */
139 static void
140 arc_info_to_howto_rel (abfd, cache_ptr, dst)
141 bfd *abfd ATTRIBUTE_UNUSED;
142 arelent *cache_ptr;
143 Elf32_Internal_Rel *dst;
145 unsigned int r_type;
147 r_type = ELF32_R_TYPE (dst->r_info);
148 BFD_ASSERT (r_type < (unsigned int) R_ARC_max);
149 cache_ptr->howto = &elf_arc_howto_table[r_type];
152 /* Set the right machine number for an ARC ELF file. */
154 static boolean
155 arc_elf_object_p (abfd)
156 bfd *abfd;
158 int mach;
159 unsigned long arch = elf_elfheader (abfd)->e_flags & EF_ARC_MACH;
161 switch (arch)
163 case E_ARC_MACH_BASE:
164 mach = bfd_mach_arc_base;
165 break;
166 default:
167 /* Unknown cpu type. ??? What to do? */
168 return false;
171 (void) bfd_default_set_arch_mach (abfd, bfd_arch_arc, mach);
172 return true;
175 /* The final processing done just before writing out an ARC ELF object file.
176 This gets the ARC architecture right based on the machine number. */
178 static void
179 arc_elf_final_write_processing (abfd, linker)
180 bfd *abfd;
181 boolean linker ATTRIBUTE_UNUSED;
183 int mach;
184 unsigned long val;
186 switch (mach = bfd_get_mach (abfd))
188 case bfd_mach_arc_base:
189 val = E_ARC_MACH_BASE;
190 break;
191 default:
192 return;
195 elf_elfheader (abfd)->e_flags &=~ EF_ARC_MACH;
196 elf_elfheader (abfd)->e_flags |= val;
199 #define TARGET_LITTLE_SYM bfd_elf32_littlearc_vec
200 #define TARGET_LITTLE_NAME "elf32-littlearc"
201 #define TARGET_BIG_SYM bfd_elf32_bigarc_vec
202 #define TARGET_BIG_NAME "elf32-bigarc"
203 #define ELF_ARCH bfd_arch_arc
204 #define ELF_MACHINE_CODE EM_CYGNUS_ARC
205 #define ELF_MAXPAGESIZE 0x1000
207 #define elf_info_to_howto 0
208 #define elf_info_to_howto_rel arc_info_to_howto_rel
209 #define elf_backend_object_p arc_elf_object_p
210 #define elf_backend_final_write_processing \
211 arc_elf_final_write_processing
213 #include "elf32-target.h"