Zephyr API Documentation 4.0.0-rc3
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
elf.h
Go to the documentation of this file.
1
8/*
9 * Copyright (c) 2024 CISPA Helmholtz Center for Information Security gGmbH
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13#ifndef ZEPHYR_ARCH_RISCV_ELF_H
14#define ZEPHYR_ARCH_RISCV_ELF_H
15
16#include <stdint.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
28#define R_RISCV_NONE 0
29#define R_RISCV_32 1
30#define R_RISCV_64 2
31#define R_RISCV_RELATIVE 3
32#define R_RISCV_COPY 4
33#define R_RISCV_JUMP_SLOT 5
34#define R_RISCV_TLS_DTPMOD32 6
35#define R_RISCV_TLS_DTPMOD64 7
36#define R_RISCV_TLS_DTPREL32 8
37#define R_RISCV_TLS_DTPREL64 9
38#define R_RISCV_TLS_TPREL32 10
39#define R_RISCV_TLS_TPREL64 11
40#define R_RISCV_TLSDESC 12
41/* 13-15 reserved */
42#define R_RISCV_BRANCH 16
43#define R_RISCV_JAL 17
44#define R_RISCV_CALL 18
45#define R_RISCV_CALL_PLT 19
46#define R_RISCV_GOT_HI20 20
47#define R_RISCV_TLS_GOT_HI20 21
48#define R_RISCV_TLS_GD_HI20 22
49#define R_RISCV_PCREL_HI20 23
50#define R_RISCV_PCREL_LO12_I 24
51#define R_RISCV_PCREL_LO12_S 25
52#define R_RISCV_HI20 26
53#define R_RISCV_LO12_I 27
54#define R_RISCV_LO12_S 28
55#define R_RISCV_TPREL_HI20 29
56#define R_RISCV_TPREL_LO12_I 30
57#define R_RISCV_TPREL_LO12_S 31
58#define R_RISCV_TPREL_ADD 32
59#define R_RISCV_ADD8 33
60#define R_RISCV_ADD16 34
61#define R_RISCV_ADD32 35
62#define R_RISCV_ADD64 36
63#define R_RISCV_SUB8 37
64#define R_RISCV_SUB16 38
65#define R_RISCV_SUB32 39
66#define R_RISCV_SUB64 40
67#define R_RISCV_GOT32_PCREL 41
68/* 42 reserved */
69#define R_RISCV_ALIGN 43
70/* next two refer to compressed instructions */
71#define R_RISCV_RVC_BRANCH 44
72#define R_RISCV_RVC_JUMP 45
73/* 46-50 reserved */
74#define R_RISCV_RELAX 51
75#define R_RISCV_SUB6 52
76#define R_RISCV_SET6 53
77#define R_RISCV_SET8 54
78#define R_RISCV_SET16 55
79#define R_RISCV_SET32 56
80#define R_RISCV_32_PCREL 57
81#define R_RISCV_IRELATIVE 58
82#define R_RISCV_PLT32 59
83#define R_RISCV_SET_ULEB128 60
84#define R_RISCV_SUB_ULEB128 61
85#define R_RISCV_TLSDESC_HI20 62
86#define R_RISCV_TLSDESC_LOAD_LO12 63
87#define R_RISCV_TLSDESC_ADD_LO12 64
88#define R_RISCV_TLSDESC_CALL 65
89/* 66-190 reserved */
90#define R_RISCV_VENDOR 191
91/* 192-255 reserved */
98#if defined(CONFIG_64BIT)
99typedef uint64_t r_riscv_wordclass_t;
100#else
101typedef uint32_t r_riscv_wordclass_t;
102#endif
110#define R_RISCV_IMM8_GET_BIT(imm8, bit) (((imm8) & BIT(bit)) >> (bit))
111
118#define R_RISCV_BTYPE_IMM8_MASK(imm8) \
119 ((R_RISCV_IMM8_GET_BIT(imm8, 12) << 31) | (R_RISCV_IMM8_GET_BIT(imm8, 10) << 30) | \
120 (R_RISCV_IMM8_GET_BIT(imm8, 9) << 29) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 28) | \
121 (R_RISCV_IMM8_GET_BIT(imm8, 7) << 27) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 26) | \
122 (R_RISCV_IMM8_GET_BIT(imm8, 5) << 25) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
123 (R_RISCV_IMM8_GET_BIT(imm8, 3) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 9) | \
124 (R_RISCV_IMM8_GET_BIT(imm8, 1) << 8) | (R_RISCV_IMM8_GET_BIT(imm8, 11) << 7))
125
132#define R_RISCV_JTYPE_IMM8_MASK(imm8) \
133 ((R_RISCV_IMM8_GET_BIT(imm8, 20) << 31) | (R_RISCV_IMM8_GET_BIT(imm8, 10) << 30) | \
134 (R_RISCV_IMM8_GET_BIT(imm8, 9) << 29) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 28) | \
135 (R_RISCV_IMM8_GET_BIT(imm8, 7) << 27) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 26) | \
136 (R_RISCV_IMM8_GET_BIT(imm8, 5) << 25) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 24) | \
137 (R_RISCV_IMM8_GET_BIT(imm8, 3) << 23) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 22) | \
138 (R_RISCV_IMM8_GET_BIT(imm8, 1) << 21) | (R_RISCV_IMM8_GET_BIT(imm8, 11) << 20) | \
139 (R_RISCV_IMM8_GET_BIT(imm8, 19) << 19) | (R_RISCV_IMM8_GET_BIT(imm8, 18) << 18) | \
140 (R_RISCV_IMM8_GET_BIT(imm8, 17) << 17) | (R_RISCV_IMM8_GET_BIT(imm8, 16) << 16) | \
141 (R_RISCV_IMM8_GET_BIT(imm8, 15) << 15) | (R_RISCV_IMM8_GET_BIT(imm8, 14) << 14) | \
142 (R_RISCV_IMM8_GET_BIT(imm8, 13) << 13) | (R_RISCV_IMM8_GET_BIT(imm8, 12) << 12))
143
149#define R_RISCV_STYPE_IMM8_MASK(imm8) \
150 ((R_RISCV_IMM8_GET_BIT(imm8, 11) << 31) | (R_RISCV_IMM8_GET_BIT(imm8, 10) << 30) | \
151 (R_RISCV_IMM8_GET_BIT(imm8, 9) << 29) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 28) | \
152 (R_RISCV_IMM8_GET_BIT(imm8, 7) << 27) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 26) | \
153 (R_RISCV_IMM8_GET_BIT(imm8, 5) << 25) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
154 (R_RISCV_IMM8_GET_BIT(imm8, 3) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 9) | \
155 (R_RISCV_IMM8_GET_BIT(imm8, 1) << 8) | (R_RISCV_IMM8_GET_BIT(imm8, 0) << 7))
156
163#define R_RISCV_CJTYPE_IMM8_MASK(imm8) \
164 ((R_RISCV_IMM8_GET_BIT(imm8, 11) << 12) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
165 (R_RISCV_IMM8_GET_BIT(imm8, 9) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 8) << 9) | \
166 (R_RISCV_IMM8_GET_BIT(imm8, 10) << 8) | (R_RISCV_IMM8_GET_BIT(imm8, 6) << 7) | \
167 (R_RISCV_IMM8_GET_BIT(imm8, 7) << 6) | (R_RISCV_IMM8_GET_BIT(imm8, 3) << 5) | \
168 (R_RISCV_IMM8_GET_BIT(imm8, 2) << 4) | (R_RISCV_IMM8_GET_BIT(imm8, 1) << 3) | \
169 (R_RISCV_IMM8_GET_BIT(imm8, 5) << 2))
170
177#define R_RISCV_CBTYPE_IMM8_MASK(imm8) \
178 ((R_RISCV_IMM8_GET_BIT(imm8, 8) << 12) | (R_RISCV_IMM8_GET_BIT(imm8, 4) << 11) | \
179 (R_RISCV_IMM8_GET_BIT(imm8, 3) << 10) | (R_RISCV_IMM8_GET_BIT(imm8, 7) << 6) | \
180 (R_RISCV_IMM8_GET_BIT(imm8, 6) << 5) | (R_RISCV_IMM8_GET_BIT(imm8, 2) << 4) | \
181 (R_RISCV_IMM8_GET_BIT(imm8, 1) << 3) | (R_RISCV_IMM8_GET_BIT(imm8, 5) << 2))
182
188#define R_RISCV_CLEAR_BTYPE_IMM8(operand) ((operand) & ~R_RISCV_BTYPE_IMM8_MASK((uint32_t) -1))
189
196#define R_RISCV_SET_BTYPE_IMM8(operand, imm8) \
197 ((R_RISCV_CLEAR_BTYPE_IMM8(operand)) | R_RISCV_BTYPE_IMM8_MASK(imm8))
198
204#define R_RISCV_CLEAR_JTYPE_IMM8(operand) ((operand) & ~R_RISCV_JTYPE_IMM8_MASK((uint32_t) -1))
205
212#define R_RISCV_SET_JTYPE_IMM8(operand, imm8) \
213 ((R_RISCV_CLEAR_JTYPE_IMM8(operand)) | R_RISCV_JTYPE_IMM8_MASK(imm8))
214
220#define R_RISCV_CLEAR_STYPE_IMM8(operand) ((operand) & ~R_RISCV_STYPE_IMM8_MASK((uint32_t) -1))
221
228#define R_RISCV_SET_STYPE_IMM8(operand, imm8) \
229 ((R_RISCV_CLEAR_STYPE_IMM8(operand)) | R_RISCV_STYPE_IMM8_MASK(imm8))
230
236#define R_RISCV_CLEAR_CJTYPE_IMM8(operand) ((operand) & ~R_RISCV_CJTYPE_IMM8_MASK((uint32_t) -1))
237
244#define R_RISCV_SET_CJTYPE_IMM8(operand, imm8) \
245 ((R_RISCV_CLEAR_CJTYPE_IMM8(operand)) | R_RISCV_CJTYPE_IMM8_MASK(imm8))
246
252#define R_RISCV_CLEAR_CBTYPE_IMM8(operand) ((operand) & ~R_RISCV_CBTYPE_IMM8_MASK((uint32_t) -1))
253
260#define R_RISCV_SET_CBTYPE_IMM8(operand, imm8) \
261 ((R_RISCV_CLEAR_CBTYPE_IMM8(operand)) | R_RISCV_CBTYPE_IMM8_MASK(imm8))
262
268#define R_RISCV_CLEAR_UTYPE_IMM8(operand) ((operand) & ~(0xFFFFF000))
269
276#define R_RISCV_SET_UTYPE_IMM8(operand, imm8) \
277 ((R_RISCV_CLEAR_UTYPE_IMM8(operand)) | ((imm8) & 0xFFFFF000))
278
284#define R_RISCV_CLEAR_ITYPE_IMM8(operand) ((operand) & ~(0xFFF00000))
285
292#define R_RISCV_SET_ITYPE_IMM8(operand, imm8) ((R_RISCV_CLEAR_ITYPE_IMM8(operand)) | ((imm8) << 20))
293
294#ifdef __cplusplus
295}
296#endif
297
298#endif /* ZEPHYR_ARCH_RISCV_ELF_H */
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
Macro utilities.