Annotation of src/external/gpl3/binutils.old/dist/include/elf/riscv.h, Revision 1.4.8.1
1.1 christos 1: /* RISC-V ELF support for BFD.
2: Copyright 2011-2014 Free Software Foundation, Inc.
3:
4: Contributed by Andrw Waterman <waterman@cs.berkeley.edu> at UC Berkeley.
5: Based on MIPS ELF support for BFD, by Ian Lance Taylor.
6:
7: This file is part of BFD, the Binary File Descriptor library.
8:
9: This program is free software; you can redistribute it and/or modify
10: it under the terms of the GNU General Public License as published by
11: the Free Software Foundation; either version 3 of the License, or
12: (at your option) any later version.
13:
14: This program is distributed in the hope that it will be useful,
15: but WITHOUT ANY WARRANTY; without even the implied warranty of
16: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: GNU General Public License for more details.
18:
19: You should have received a copy of the GNU General Public License
20: along with this program; if not, write to the Free Software
21: Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22: MA 02110-1301, USA. */
23:
24: /* This file holds definitions specific to the RISCV ELF ABI. Note
25: that most of this is not actually implemented by BFD. */
26:
27: #ifndef _ELF_RISCV_H
28: #define _ELF_RISCV_H
29:
30: #include "elf/reloc-macros.h"
31:
32: /* Relocation types. */
33: START_RELOC_NUMBERS (elf_riscv_reloc_type)
34: /* Relocation types used by the dynamic linker. */
35: RELOC_NUMBER (R_RISCV_NONE, 0)
36: RELOC_NUMBER (R_RISCV_32, 1)
37: RELOC_NUMBER (R_RISCV_64, 2)
38: RELOC_NUMBER (R_RISCV_RELATIVE, 3)
39: RELOC_NUMBER (R_RISCV_COPY, 4)
40: RELOC_NUMBER (R_RISCV_JUMP_SLOT, 5)
41: RELOC_NUMBER (R_RISCV_TLS_DTPMOD32, 6)
42: RELOC_NUMBER (R_RISCV_TLS_DTPMOD64, 7)
43: RELOC_NUMBER (R_RISCV_TLS_DTPREL32, 8)
44: RELOC_NUMBER (R_RISCV_TLS_DTPREL64, 9)
45: RELOC_NUMBER (R_RISCV_TLS_TPREL32, 10)
46: RELOC_NUMBER (R_RISCV_TLS_TPREL64, 11)
47:
48: /* Relocation types not used by the dynamic linker. */
49: RELOC_NUMBER (R_RISCV_BRANCH, 16)
50: RELOC_NUMBER (R_RISCV_JAL, 17)
51: RELOC_NUMBER (R_RISCV_CALL, 18)
52: RELOC_NUMBER (R_RISCV_CALL_PLT, 19)
53: RELOC_NUMBER (R_RISCV_GOT_HI20, 20)
54: RELOC_NUMBER (R_RISCV_TLS_GOT_HI20, 21)
55: RELOC_NUMBER (R_RISCV_TLS_GD_HI20, 22)
56: RELOC_NUMBER (R_RISCV_PCREL_HI20, 23)
57: RELOC_NUMBER (R_RISCV_PCREL_LO12_I, 24)
58: RELOC_NUMBER (R_RISCV_PCREL_LO12_S, 25)
59: RELOC_NUMBER (R_RISCV_HI20, 26)
60: RELOC_NUMBER (R_RISCV_LO12_I, 27)
61: RELOC_NUMBER (R_RISCV_LO12_S, 28)
62: RELOC_NUMBER (R_RISCV_TPREL_HI20, 29)
63: RELOC_NUMBER (R_RISCV_TPREL_LO12_I, 30)
64: RELOC_NUMBER (R_RISCV_TPREL_LO12_S, 31)
65: RELOC_NUMBER (R_RISCV_TPREL_ADD, 32)
66: RELOC_NUMBER (R_RISCV_ADD8, 33)
67: RELOC_NUMBER (R_RISCV_ADD16, 34)
68: RELOC_NUMBER (R_RISCV_ADD32, 35)
69: RELOC_NUMBER (R_RISCV_ADD64, 36)
70: RELOC_NUMBER (R_RISCV_SUB8, 37)
71: RELOC_NUMBER (R_RISCV_SUB16, 38)
72: RELOC_NUMBER (R_RISCV_SUB32, 39)
73: RELOC_NUMBER (R_RISCV_SUB64, 40)
74: RELOC_NUMBER (R_RISCV_GNU_VTINHERIT, 41)
75: RELOC_NUMBER (R_RISCV_GNU_VTENTRY, 42)
76: RELOC_NUMBER (R_RISCV_ALIGN, 43)
77: END_RELOC_NUMBERS (R_RISCV_max)
78:
79: /* Processor specific flags for the ELF header e_flags field. */
80:
81: /* Custom flag definitions. */
82:
83: #define EF_RISCV_EXT_MASK 0xffff
84: #define EF_RISCV_EXT_SH 16
85: #define E_RISCV_EXT_Xcustom 0x0000
86: #define E_RISCV_EXT_Xhwacha 0x0001
87: #define E_RISCV_EXT_RESERVED 0xffff
88:
89: #define EF_GET_RISCV_EXT(x) \
90: ((x >> EF_RISCV_EXT_SH) & EF_RISCV_EXT_MASK)
91:
92: #define EF_SET_RISCV_EXT(x, ext) \
93: do { x |= ((ext & EF_RISCV_EXT_MASK) << EF_RISCV_EXT_SH); } while (0)
94:
95: #define EF_IS_RISCV_EXT_Xcustom(x) \
96: (EF_GET_RISCV_EXT(x) == E_RISCV_EXT_Xcustom)
97:
98: /* A mapping from extension names to elf flags */
99:
100: struct riscv_extension_entry
101: {
102: const char* name;
103: unsigned int flag;
104: };
105:
106: static const struct riscv_extension_entry riscv_extension_map[] =
107: {
108: {"Xcustom", E_RISCV_EXT_Xcustom},
109: {"Xhwacha", E_RISCV_EXT_Xhwacha},
110: };
111:
112: /* Given an extension name, return an elf flag. */
113:
114: static inline const char* riscv_elf_flag_to_name(unsigned int flag)
115: {
116: unsigned int i;
117:
118: for (i=0; i<sizeof(riscv_extension_map)/sizeof(riscv_extension_map[0]); i++)
119: if (riscv_extension_map[i].flag == flag)
120: return riscv_extension_map[i].name;
121:
122: return NULL;
123: }
124:
125: /* Given an elf flag, return an extension name. */
126:
127: static inline unsigned int riscv_elf_name_to_flag(const char* name)
128: {
129: unsigned int i;
130:
131: for (i=0; i<sizeof(riscv_extension_map)/sizeof(riscv_extension_map[0]); i++)
132: if (strcmp(riscv_extension_map[i].name, name) == 0)
133: return riscv_extension_map[i].flag;
134:
135: return E_RISCV_EXT_Xcustom;
136: }
137:
138: #endif /* _ELF_RISCV_H */
CVSweb <webmaster@jp.NetBSD.org>