1 /* CR16C ELF support for BFD.
2 Copyright (C) 2004-2018 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 #include "elf/reloc-macros.h"
26 /* Creating indices for reloc_map_index array. */
27 START_RELOC_NUMBERS (elf_cr16c_reloc_type
)
28 RELOC_NUMBER (RINDEX_16C_NUM08
, 0)
29 RELOC_NUMBER (RINDEX_16C_NUM08_C
, 1)
30 RELOC_NUMBER (RINDEX_16C_NUM16
, 2)
31 RELOC_NUMBER (RINDEX_16C_NUM16_C
, 3)
32 RELOC_NUMBER (RINDEX_16C_NUM32
, 4)
33 RELOC_NUMBER (RINDEX_16C_NUM32_C
, 5)
34 RELOC_NUMBER (RINDEX_16C_DISP04
, 6)
35 RELOC_NUMBER (RINDEX_16C_DISP04_C
, 7)
36 RELOC_NUMBER (RINDEX_16C_DISP08
, 8)
37 RELOC_NUMBER (RINDEX_16C_DISP08_C
, 9)
38 RELOC_NUMBER (RINDEX_16C_DISP16
, 10)
39 RELOC_NUMBER (RINDEX_16C_DISP16_C
, 11)
40 RELOC_NUMBER (RINDEX_16C_DISP24
, 12)
41 RELOC_NUMBER (RINDEX_16C_DISP24_C
, 13)
42 RELOC_NUMBER (RINDEX_16C_DISP24a
, 14)
43 RELOC_NUMBER (RINDEX_16C_DISP24a_C
, 15)
44 RELOC_NUMBER (RINDEX_16C_REG04
, 16)
45 RELOC_NUMBER (RINDEX_16C_REG04_C
, 17)
46 RELOC_NUMBER (RINDEX_16C_REG04a
, 18)
47 RELOC_NUMBER (RINDEX_16C_REG04a_C
, 19)
48 RELOC_NUMBER (RINDEX_16C_REG14
, 20)
49 RELOC_NUMBER (RINDEX_16C_REG14_C
, 21)
50 RELOC_NUMBER (RINDEX_16C_REG16
, 22)
51 RELOC_NUMBER (RINDEX_16C_REG16_C
, 23)
52 RELOC_NUMBER (RINDEX_16C_REG20
, 24)
53 RELOC_NUMBER (RINDEX_16C_REG20_C
, 25)
54 RELOC_NUMBER (RINDEX_16C_ABS20
, 26)
55 RELOC_NUMBER (RINDEX_16C_ABS20_C
, 27)
56 RELOC_NUMBER (RINDEX_16C_ABS24
, 28)
57 RELOC_NUMBER (RINDEX_16C_ABS24_C
, 29)
58 RELOC_NUMBER (RINDEX_16C_IMM04
, 30)
59 RELOC_NUMBER (RINDEX_16C_IMM04_C
, 31)
60 RELOC_NUMBER (RINDEX_16C_IMM16
, 32)
61 RELOC_NUMBER (RINDEX_16C_IMM16_C
, 33)
62 RELOC_NUMBER (RINDEX_16C_IMM20
, 34)
63 RELOC_NUMBER (RINDEX_16C_IMM20_C
, 35)
64 RELOC_NUMBER (RINDEX_16C_IMM24
, 36)
65 RELOC_NUMBER (RINDEX_16C_IMM24_C
, 37)
66 RELOC_NUMBER (RINDEX_16C_IMM32
, 38)
67 RELOC_NUMBER (RINDEX_16C_IMM32_C
, 39)
68 END_RELOC_NUMBERS (RINDEX_16C_MAX
)
70 /* CR16C Relocation Types ('cr_reloc_type' entry in the reloc_map structure).
71 The relocation constant name is determined as follows :
73 R_16C_<format><size>[_C]
77 <format> is one of the following:
78 NUM - R_NUMBER mnemonic,
79 DISP - R_16C_DISPL mnemonic,
80 REG - R_16C_REGREL mnemonic,
81 ABS - R_16C_ABS mnemonic,
82 IMM - R_16C_IMMED mnemonic,
83 <size> stands for R_S_16C_<size>
84 _C means 'code label' and is only added when R_ADDRTYPE subfield
85 is of type R_CODE_ADDR. */
87 /* The table below shows what the hex digits in the definition of the
88 relocation type constants correspond to.
89 ------------------------------------------------------------------
90 R_SIZESP R_FORMAT R_RELTO R_ADDRTYPE
91 ------------------------------------------------------------------ */
92 /* R_S_16C_08 R_NUMBER R_ABS R_ADDRESS */
93 #define R_16C_NUM08 0X0001
95 /* R_S_16C_08 R_NUMBER R_ABS R_CODE_ADDR */
96 #define R_16C_NUM08_C 0X0006
98 /* R_S_16C_16 R_NUMBER R_ABS R_ADDRESS */
99 #define R_16C_NUM16 0X1001
101 /* R_S_16C_16 R_NUMBER R_ABS R_CODE_ADDR */
102 #define R_16C_NUM16_C 0X1006
104 /* R_S_16C_32 R_NUMBER R_ABS R_ADDRESS */
105 #define R_16C_NUM32 0X2001
107 /* R_S_16C_32 R_NUMBER R_ABS R_CODE_ADDR */
108 #define R_16C_NUM32_C 0X2006
110 /* R_S_16C_04 R_16C_DISPL R_PCREL R_ADDRESS */
111 #define R_16C_DISP04 0X5411
113 /* R_S_16C_04 R_16C_DISPL R_PCREL R_CODE_ADDR */
114 #define R_16C_DISP04_C 0X5416
116 /* R_S_16C_08 R_16C_DISPL R_PCREL R_ADDRESS */
117 #define R_16C_DISP08 0X0411
119 /* R_S_16C_08 R_16C_DISPL R_PCREL R_CODE_ADDR */
120 #define R_16C_DISP08_C 0X0416
122 /* R_S_16C_16 R_16C_DISPL R_PCREL R_ADDRESS */
123 #define R_16C_DISP16 0X1411
125 /* R_S_16C_16 R_16C_DISPL R_PCREL R_CODE_ADDR */
126 #define R_16C_DISP16_C 0X1416
128 /* R_S_16C_24 R_16C_DISPL R_PCREL R_ADDRESS */
129 #define R_16C_DISP24 0X7411
131 /* R_S_16C_24 R_16C_DISPL R_PCREL R_CODE_ADDR */
132 #define R_16C_DISP24_C 0X7416
134 /* R_S_16C_24a R_16C_DISPL R_PCREL R_ADDRESS */
135 #define R_16C_DISP24a 0X6411
137 /* R_S_16C_24a R_16C_DISPL R_PCREL R_CODE_ADDR */
138 #define R_16C_DISP24a_C 0X6416
140 /* R_S_16C_04 R_16C_REGREL R_ABS R_ADDRESS */
141 #define R_16C_REG04 0X5201
143 /* R_S_16C_04 R_16C_REGREL R_ABS R_CODE_ADDR */
144 #define R_16C_REG04_C 0X5206
146 /* R_S_16C_04_a R_16C_REGREL R_ABS R_ADDRESS */
147 #define R_16C_REG04a 0X4201
149 /* R_S_16C_04_a R_16C_REGREL R_ABS R_CODE_ADDR */
150 #define R_16C_REG04a_C 0X4206
152 /* R_S_16C_14 R_16C_REGREL R_ABS R_ADDRESS */
153 #define R_16C_REG14 0X3201
155 /* R_S_16C_14 R_16C_REGREL R_ABS R_CODE_ADDR */
156 #define R_16C_REG14_C 0X3206
158 /* R_S_16C_16 R_16C_REGREL R_ABS R_ADDRESS */
159 #define R_16C_REG16 0X1201
161 /* R_S_16C_16 R_16C_REGREL R_ABS R_CODE_ADDR */
162 #define R_16C_REG16_C 0X1206
164 /* R_S_16C_20 R_16C_REGREL R_ABS R_ADDRESS */
165 #define R_16C_REG20 0X8201
167 /* R_S_16C_20 R_16C_REGREL R_ABS R_CODE_ADDR */
168 #define R_16C_REG20_C 0X8206
170 /* R_S_16C_20 R_16C_ABS R_ABS R_ADDRESS */
171 #define R_16C_ABS20 0X8101
173 /* R_S_16C_20 R_16C_ABS R_ABS R_CODE_ADDR */
174 #define R_16C_ABS20_C 0X8106
176 /* R_S_16C_24 R_16C_ABS R_ABS R_ADDRESS */
177 #define R_16C_ABS24 0X7101
179 /* R_S_16C_24 R_16C_ABS R_ABS R_CODE_ADDR */
180 #define R_16C_ABS24_C 0X7106
182 /* R_S_16C_04 R_16C_IMMED R_ABS R_ADDRESS */
183 #define R_16C_IMM04 0X5301
185 /* R_S_16C_04 R_16C_IMMED R_ABS R_CODE_ADDR */
186 #define R_16C_IMM04_C 0X5306
188 /* R_S_16C_16 R_16C_IMMED R_ABS R_ADDRESS */
189 #define R_16C_IMM16 0X1301
191 /* R_S_16C_16 R_16C_IMMED R_ABS R_CODE_ADDR */
192 #define R_16C_IMM16_C 0X1306
194 /* R_S_16C_20 R_16C_IMMED R_ABS R_ADDRESS */
195 #define R_16C_IMM20 0X8301
197 /* R_S_16C_20 R_16C_IMMED R_ABS R_CODE_ADDR */
198 #define R_16C_IMM20_C 0X8306
200 /* R_S_16C_24 R_16C_IMMED R_ABS R_ADDRESS */
201 #define R_16C_IMM24 0X7301
203 /* R_S_16C_24 R_16C_IMMED R_ABS R_CODE_ADDR */
204 #define R_16C_IMM24_C 0X7306
206 /* R_S_16C_32 R_16C_IMMED R_ABS R_ADDRESS */
207 #define R_16C_IMM32 0X2301
209 /* R_S_16C_32 R_16C_IMMED R_ABS R_CODE_ADDR */
210 #define R_16C_IMM32_C 0X2306
213 /* Relocation item type. */
214 #define R_ADDRTYPE 0x000f
215 #define R_ADDRESS 0x0001 /* Take address of symbol. */
216 #define R_CODE_ADDR 0x0006 /* Take address of symbol divided by 2. */
218 /* Relocation action. */
219 #define R_RELTO 0x00f0
220 #define R_ABS 0x0000 /* Keep symbol's address as such. */
221 #define R_PCREL 0x0010 /* Subtract the pc address of hole. */
223 /* Relocation item data format. */
224 #define R_FORMAT 0x0f00
225 #define R_NUMBER 0x0000 /* Retain as two's complement value. */
226 #define R_16C_DISPL 0x0400 /* CR16C displacement type. */
227 #define R_16C_ABS 0x0100 /* CR16C absolute type. */
228 #define R_16C_REGREL 0x0200 /* CR16C register-relative type. */
229 #define R_16C_IMMED 0x0300 /* CR16C immediate type. */
231 /* Relocation item size. */
232 #define R_SIZESP 0xf000
233 #define R_S_16C_04 0x5000
234 #define R_S_16C_04_a 0x4000
235 #define R_S_16C_08 0x0000
236 #define R_S_16C_14 0x3000
237 #define R_S_16C_16 0x1000
238 #define R_S_16C_20 0x8000
239 #define R_S_16C_24_a 0x6000
240 #define R_S_16C_24 0x7000
241 #define R_S_16C_32 0x2000
244 /* Processor specific section indices. These sections do not actually
245 exist. Symbols with a st_shndx field corresponding to one of these
246 values have a special meaning. */
248 /* Far common symbol. */
249 #define SHN_CR16C_FCOMMON SHN_LORESERVE
250 #define SHN_CR16C_NCOMMON (SHN_LORESERVE + 1)
252 typedef struct reloc_map
254 unsigned short cr_reloc_type
; /* CR relocation type. */
255 bfd_reloc_code_real_type bfd_reloc_enum
; /* BFD relocation enum. */
258 #endif /* _ELF_CR16C_H */