RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
elf_machdep.h
1/* $NetBSD: elf_machdep.h,v 1.6 2017/11/06 03:47:48 christos Exp $ */
2
3/*-
4 * Copyright (c) 2019 Hesham Almatary
5 *
6 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Matt Thomas of 3am Software Foundry.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef _RISCV_ELF_MACHDEP_H_
35#define _RISCV_ELF_MACHDEP_H_
36
37#define EM_RISCV 243
38#define ELF32_MACHDEP_ID EM_RISCV
39#define ELF64_MACHDEP_ID EM_RISCV
40
41#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
42#define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB
43
44#define ELF32_MACHDEP_ID_CASES \
45 case EM_RISCV: \
46 break;
47
48#define ELF64_MACHDEP_ID_CASES \
49 case EM_RISCV: \
50 break;
51
52#define KERN_ELFSIZE 32
53#ifdef _LP64
54#define ARCH_ELFSIZE 64 /* MD native binary size */
55#else
56#define ARCH_ELFSIZE 32 /* MD native binary size */
57#endif
58
59/* Processor specific flags for the ELF header e_flags field. */
60
61/* Processor specific relocation types */
62
63#define R_RISCV_NONE 0
64#define R_RISCV_32 1 // A
65#define R_RISCV_64 2
66#define R_RISCV_RELATIVE 3
67#define R_RISCV_COPY 4
68#define R_RISCV_JMP_SLOT 5
69#define R_RISCV_TLS_DTPMOD32 6
70#define R_RISCV_TLS_DTPREL32 7
71#define R_RISCV_TLS_DTPMOD64 8
72#define R_RISCV_TLS_DTPREL64 9
73#define R_RISCV_TLS_TPREL32 10
74#define R_RISCV_TLS_TPREL64 11
75
76/* The rest are not used by the dynamic linker */
77#define R_RISCV_BRANCH 16 // (A - P) & 0xffff
78#define R_RISCV_JAL 17 // A & 0xff
79#define R_RISCV_CALL 18 // (A - P) & 0xff
80#define R_RISCV_CALL_PLT 19
81#define R_RISCV_GOT_HI20 20
82#define R_RISCV_TLS_GOT_HI20 21
83#define R_RISCV_TLS_GD_HI20 22
84#define R_RISCV_PCREL_HI20 23
85#define R_RISCV_PCREL_LO12_I 24
86#define R_RISCV_PCREL_LO12_S 25
87#define R_RISCV_HI20 26 // A & 0xffff
88#define R_RISCV_LO12_I 27 // (A >> 16) & 0xffff
89#define R_RISCV_LO12_S 28 // (S + A - P) >> 2
90#define R_RISCV_TPREL_HI20 29
91#define R_RISCV_TPREL_LO12_I 30
92#define R_RISCV_TPREL_LO12_S 31
93#define R_RISCV_TPREL_ADD 32
94#define R_RISCV_ADD8 33
95#define R_RISCV_ADD16 34
96#define R_RISCV_ADD32 35
97#define R_RISCV_ADD64 36
98#define R_RISCV_SUB8 37
99#define R_RISCV_SUB16 38
100#define R_RISCV_SUB32 39
101#define R_RISCV_SUB64 40
102#define R_RISCV_GNU_VTINHERIT 41 // A & 0xffff
103#define R_RISCV_GNU_VTENTRY 42
104#define R_RISCV_ALIGN 43
105#define R_RISCV_RVC_BRANCH 44
106#define R_RISCV_RVC_JUMP 45
107#define R_RISCV_RVC_LUI 46
108
109#define R_RISCV_RELAX 51
110#define R_RISCV_SUB6 52
111#define R_RISCV_SET6 53
112#define R_RISCV_SET8 54
113#define R_RISCV_SET16 55
114#define R_RISCV_SET32 56
115
116#define R_RISCV_32_PCREL 57
117
118/* These are aliases we can use R_TYPESZ */
119#define R_RISCV_ADDR32 R_RISCV_32
120#define R_RISCV_ADDR64 R_RISCV_64
121
122#define R_TYPE(name) R_RISCV_ ## name
123#if ELFSIZE == 32
124#define R_TYPESZ(name) R_RISCV_ ## name ## 32
125#else
126#define R_TYPESZ(name) R_RISCV_ ## name ## 64
127#endif
128
129#ifdef _KERNEL
130#ifdef ELFSIZE
131#define ELF_MD_PROBE_FUNC ELFNAME2(cpu_netbsd,probe)
132#endif
133
134struct exec_package;
135
136int cpu_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
137 vaddr_t *);
138
139int cpu_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *,
140 vaddr_t *);
141
142#endif /* _KERNEL */
143
144#endif /* _RISCV_ELF_MACHDEP_H_ */