xref: /netbsd-src/external/gpl3/gdb/dist/include/elf/riscv.h (revision 02f41505626a9ceb584d30d0789203495760ac88)
1796c32c9Schristos /* RISC-V ELF support for BFD.
2*02f41505Schristos    Copyright (C) 2011-2024 Free Software Foundation, Inc.
3796c32c9Schristos 
4796c32c9Schristos    Contributed by Andrew Waterman (andrew@sifive.com).
5796c32c9Schristos    Based on MIPS ELF support for BFD, by Ian Lance Taylor.
6796c32c9Schristos 
7796c32c9Schristos    This file is part of BFD, the Binary File Descriptor library.
8796c32c9Schristos 
9796c32c9Schristos    This program is free software; you can redistribute it and/or modify
10796c32c9Schristos    it under the terms of the GNU General Public License as published by
11796c32c9Schristos    the Free Software Foundation; either version 3 of the License, or
12796c32c9Schristos    (at your option) any later version.
13796c32c9Schristos 
14796c32c9Schristos    This program is distributed in the hope that it will be useful,
15796c32c9Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
16796c32c9Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17796c32c9Schristos    GNU General Public License for more details.
18796c32c9Schristos 
19796c32c9Schristos    You should have received a copy of the GNU General Public License
20796c32c9Schristos    along with this program; see the file COPYING3. If not,
21796c32c9Schristos    see <http://www.gnu.org/licenses/>.  */
22796c32c9Schristos 
23796c32c9Schristos /* This file holds definitions specific to the RISCV ELF ABI.  Note
24796c32c9Schristos    that most of this is not actually implemented by BFD.  */
25796c32c9Schristos 
26796c32c9Schristos #ifndef _ELF_RISCV_H
27796c32c9Schristos #define _ELF_RISCV_H
28796c32c9Schristos 
29796c32c9Schristos #include "elf/reloc-macros.h"
30796c32c9Schristos #include "libiberty.h"
31796c32c9Schristos 
32796c32c9Schristos /* Relocation types.  */
33796c32c9Schristos START_RELOC_NUMBERS (elf_riscv_reloc_type)
34796c32c9Schristos   /* Relocation types used by the dynamic linker.  */
35796c32c9Schristos   RELOC_NUMBER (R_RISCV_NONE, 0)
36796c32c9Schristos   RELOC_NUMBER (R_RISCV_32, 1)
37796c32c9Schristos   RELOC_NUMBER (R_RISCV_64, 2)
38796c32c9Schristos   RELOC_NUMBER (R_RISCV_RELATIVE, 3)
39796c32c9Schristos   RELOC_NUMBER (R_RISCV_COPY, 4)
40796c32c9Schristos   RELOC_NUMBER (R_RISCV_JUMP_SLOT, 5)
41796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_DTPMOD32, 6)
42796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_DTPMOD64, 7)
43796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_DTPREL32, 8)
44796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_DTPREL64, 9)
45796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_TPREL32, 10)
46796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_TPREL64, 11)
47*02f41505Schristos   RELOC_NUMBER (R_RISCV_TLSDESC, 12)
48796c32c9Schristos 
49796c32c9Schristos   /* Relocation types not used by the dynamic linker.  */
50796c32c9Schristos   RELOC_NUMBER (R_RISCV_BRANCH, 16)
51796c32c9Schristos   RELOC_NUMBER (R_RISCV_JAL, 17)
52796c32c9Schristos   RELOC_NUMBER (R_RISCV_CALL, 18)
53796c32c9Schristos   RELOC_NUMBER (R_RISCV_CALL_PLT, 19)
54796c32c9Schristos   RELOC_NUMBER (R_RISCV_GOT_HI20, 20)
55796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_GOT_HI20, 21)
56796c32c9Schristos   RELOC_NUMBER (R_RISCV_TLS_GD_HI20, 22)
57796c32c9Schristos   RELOC_NUMBER (R_RISCV_PCREL_HI20, 23)
58796c32c9Schristos   RELOC_NUMBER (R_RISCV_PCREL_LO12_I, 24)
59796c32c9Schristos   RELOC_NUMBER (R_RISCV_PCREL_LO12_S, 25)
60796c32c9Schristos   RELOC_NUMBER (R_RISCV_HI20, 26)
61796c32c9Schristos   RELOC_NUMBER (R_RISCV_LO12_I, 27)
62796c32c9Schristos   RELOC_NUMBER (R_RISCV_LO12_S, 28)
63796c32c9Schristos   RELOC_NUMBER (R_RISCV_TPREL_HI20, 29)
64796c32c9Schristos   RELOC_NUMBER (R_RISCV_TPREL_LO12_I, 30)
65796c32c9Schristos   RELOC_NUMBER (R_RISCV_TPREL_LO12_S, 31)
66796c32c9Schristos   RELOC_NUMBER (R_RISCV_TPREL_ADD, 32)
67796c32c9Schristos   RELOC_NUMBER (R_RISCV_ADD8, 33)
68796c32c9Schristos   RELOC_NUMBER (R_RISCV_ADD16, 34)
69796c32c9Schristos   RELOC_NUMBER (R_RISCV_ADD32, 35)
70796c32c9Schristos   RELOC_NUMBER (R_RISCV_ADD64, 36)
71796c32c9Schristos   RELOC_NUMBER (R_RISCV_SUB8, 37)
72796c32c9Schristos   RELOC_NUMBER (R_RISCV_SUB16, 38)
73796c32c9Schristos   RELOC_NUMBER (R_RISCV_SUB32, 39)
74796c32c9Schristos   RELOC_NUMBER (R_RISCV_SUB64, 40)
75796c32c9Schristos   RELOC_NUMBER (R_RISCV_ALIGN, 43)
76796c32c9Schristos   RELOC_NUMBER (R_RISCV_RVC_BRANCH, 44)
77796c32c9Schristos   RELOC_NUMBER (R_RISCV_RVC_JUMP, 45)
78796c32c9Schristos   RELOC_NUMBER (R_RISCV_RVC_LUI, 46)
79796c32c9Schristos   RELOC_NUMBER (R_RISCV_GPREL_I, 47)
80796c32c9Schristos   RELOC_NUMBER (R_RISCV_GPREL_S, 48)
81796c32c9Schristos   RELOC_NUMBER (R_RISCV_TPREL_I, 49)
82796c32c9Schristos   RELOC_NUMBER (R_RISCV_TPREL_S, 50)
83796c32c9Schristos   RELOC_NUMBER (R_RISCV_RELAX, 51)
84796c32c9Schristos   RELOC_NUMBER (R_RISCV_SUB6, 52)
85796c32c9Schristos   RELOC_NUMBER (R_RISCV_SET6, 53)
86796c32c9Schristos   RELOC_NUMBER (R_RISCV_SET8, 54)
87796c32c9Schristos   RELOC_NUMBER (R_RISCV_SET16, 55)
88796c32c9Schristos   RELOC_NUMBER (R_RISCV_SET32, 56)
894559860eSchristos   RELOC_NUMBER (R_RISCV_32_PCREL, 57)
904b169a6bSchristos   RELOC_NUMBER (R_RISCV_IRELATIVE, 58)
91*02f41505Schristos   /* Reserved 59 for R_RISCV_PLT32.  */
92*02f41505Schristos   RELOC_NUMBER (R_RISCV_SET_ULEB128, 60)
93*02f41505Schristos   RELOC_NUMBER (R_RISCV_SUB_ULEB128, 61)
94*02f41505Schristos   RELOC_NUMBER (R_RISCV_TLSDESC_HI20, 62)
95*02f41505Schristos   RELOC_NUMBER (R_RISCV_TLSDESC_LOAD_LO12, 63)
96*02f41505Schristos   RELOC_NUMBER (R_RISCV_TLSDESC_ADD_LO12, 64)
97*02f41505Schristos   RELOC_NUMBER (R_RISCV_TLSDESC_CALL, 65)
98796c32c9Schristos END_RELOC_NUMBERS (R_RISCV_max)
99796c32c9Schristos 
100*02f41505Schristos /* Internal relocations used exclusively by the relaxation pass.  */
101*02f41505Schristos #define R_RISCV_DELETE  (R_RISCV_max)
102*02f41505Schristos #define R_RISCV_RVC_LUI (R_RISCV_max + 1)
103*02f41505Schristos #define R_RISCV_GPREL_I (R_RISCV_max + 2)
104*02f41505Schristos #define R_RISCV_GPREL_S (R_RISCV_max + 3)
105*02f41505Schristos #define R_RISCV_TPREL_I (R_RISCV_max + 4)
106*02f41505Schristos #define R_RISCV_TPREL_S (R_RISCV_max + 5)
107*02f41505Schristos 
108796c32c9Schristos /* Processor specific flags for the ELF header e_flags field.  */
109796c32c9Schristos 
110796c32c9Schristos /* File may contain compressed instructions.  */
111796c32c9Schristos #define EF_RISCV_RVC 0x0001
112796c32c9Schristos 
113796c32c9Schristos /* Which floating-point ABI a file uses.  */
114796c32c9Schristos #define EF_RISCV_FLOAT_ABI 0x0006
115796c32c9Schristos 
116796c32c9Schristos /* File uses the soft-float ABI.  */
117796c32c9Schristos #define EF_RISCV_FLOAT_ABI_SOFT 0x0000
118796c32c9Schristos 
119796c32c9Schristos /* File uses the single-float ABI.  */
120796c32c9Schristos #define EF_RISCV_FLOAT_ABI_SINGLE 0x0002
121796c32c9Schristos 
122796c32c9Schristos /* File uses the double-float ABI.  */
123796c32c9Schristos #define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004
124796c32c9Schristos 
125796c32c9Schristos /* File uses the quad-float ABI.  */
126796c32c9Schristos #define EF_RISCV_FLOAT_ABI_QUAD 0x0006
127796c32c9Schristos 
1284559860eSchristos /* File uses the 32E base integer instruction.  */
1294559860eSchristos #define EF_RISCV_RVE 0x0008
1304559860eSchristos 
131796c32c9Schristos /* The name of the global pointer symbol.  */
132796c32c9Schristos #define RISCV_GP_SYMBOL "__global_pointer$"
133796c32c9Schristos 
1344b169a6bSchristos /* Processor specific dynamic array tags.  */
1354b169a6bSchristos #define DT_RISCV_VARIANT_CC (DT_LOPROC + 1)
1364b169a6bSchristos 
1374b169a6bSchristos /* RISC-V specific values for st_other.  */
1384b169a6bSchristos #define STO_RISCV_VARIANT_CC 0x80
1394b169a6bSchristos 
1404b169a6bSchristos /* File uses the TSO model. */
1414b169a6bSchristos #define EF_RISCV_TSO 0x0010
1424b169a6bSchristos 
1434559860eSchristos /* Additional section types.  */
1444559860eSchristos #define SHT_RISCV_ATTRIBUTES 0x70000003 /* Section holds attributes.  */
1454559860eSchristos 
1464b169a6bSchristos /* Processor specific program header types.  */
1474559860eSchristos 
1484b169a6bSchristos /* Location of RISC-V ELF attribute section. */
1494b169a6bSchristos #define PT_RISCV_ATTRIBUTES 0x70000003
1504b169a6bSchristos 
1514b169a6bSchristos /* Object attributes.  */
1524559860eSchristos enum
1534559860eSchristos {
1544559860eSchristos   /* 0-3 are generic.  */
1554559860eSchristos   Tag_RISCV_stack_align = 4,
1564559860eSchristos   Tag_RISCV_arch = 5,
1574559860eSchristos   Tag_RISCV_unaligned_access = 6,
1584559860eSchristos   Tag_RISCV_priv_spec = 8,
1594559860eSchristos   Tag_RISCV_priv_spec_minor = 10,
1604559860eSchristos   Tag_RISCV_priv_spec_revision = 12
1614559860eSchristos };
1624559860eSchristos 
163796c32c9Schristos #endif /* _ELF_RISCV_H */
164