elf_machdep.h revision 1.1 1 /* $NetBSD: elf_machdep.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */
2
3 /*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _RISCV_ELF_MACHDEP_H_
33 #define _RISCV_ELF_MACHDEP_H_
34
35 #define ELF32_MACHDEP_ID EM_RISCV
36
37 #define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
38 #define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB
39
40 #define ELF32_MACHDEP_ID_CASES \
41 case EM_RISCV: \
42 break;
43
44 #define ELF64_MACHDEP_ID_CASES \
45 case EM_RISCV: \
46 break;
47
48 #ifdef _LP64
49 #define ARCH_ELFSIZE 64 /* MD native binary size */
50 #else
51 #define ARCH_ELFSIZE 32 /* MD native binary size */
52 #endif
53
54 /* Processor specific flags for the ELF header e_flags field. */
55
56 /* Processor specific relocation types */
57
58 #define R_RISCV_NONE 0
59 #define R_RISCV_32 2 // A
60 #define R_RISCV_REL32 3 // A & 0xffff
61 #define R_RISCV_JAL 4 // A & 0xff
62 #define R_RISCV_HI20 5 // A & 0xffff
63 #define R_RISCV_LO12_I 6 // (A >> 16) & 0xffff
64 #define R_RISCV_LO12_S 7 // (S + A - P) >> 2
65 #define R_RISCV_PCREL_LO12_I 8
66 #define R_RISCV_PCREL_LO12_S 9
67 #define R_RISCV_BRANCH 10 // (A - P) & 0xffff
68 #define R_RISCV_CALL 11 // (A - P) & 0xff
69 #define R_RISCV_PCREL_HI20 12
70 #define R_RISCV_CALL_PLT 13
71 #define R_RISCV_64 18
72 #define R_RISCV_GOT_HI20 22
73 #define R_RISCV_GOT_LO12 23
74 #define R_RISCV_COPY 24
75 #define R_RISCV_JMP_SLOT 25
76 /* TLS relocations. */
77 #define R_RISCV_TLS_IE_HI20 29
78 #define R_RISCV_TLS_IE_LO12 30
79 #define R_RISCV_TLS_IE_ADD 31
80 #define R_RISCV_TLS_IE_LO12_I 32
81 #define R_RISCV_TLS_IE_LO12_S 33
82 #define R_RISCV_TPREL_HI20 34
83 #define R_RISCV_TLREL_LO12_I 35
84 #define R_RISCV_TLREL_LO12_S 36
85 #define R_RISCV_TLREL_ADD 37
86
87 #define R_RISCV_TLS_DTPMOD32 38
88 #define R_RISCV_TLS_DTPREL32 39
89 #define R_RISCV_TLS_DTPMOD64 40
90 #define R_RISCV_TLS_DTPREL64 41
91 #define R_RISCV_TLS_DTPREL_HI16 44
92 #define R_RISCV_TLS_DTPREL_LO16 45
93 #define R_RISCV_TLS_PCREL_LO12 50
94 #define R_RISCV_TLS_GOT_HI20 51
95 #define R_RISCV_TLS_GOT_LO20 52
96 #define R_RISCV_TLS_GD_HI20 53
97 #define R_RISCV_TLS_GD_LO20 54
98
99 #define R_RISCV_GLOB_DAT 57
100 #define R_RISCV_ADD32 58
101 #define R_RISCV_SUB32 59
102 #define R_RISCV_ADD64 60
103 #define R_RISCV_SUB64 61
104
105 #define R_TYPE(name) R_RISCV_ ## name
106 #define R_TLS_TYPE(name) R_RISCV_ ## name ## 64
107
108 #define DT_RISCV_LOCAL_GOTNO (DT_LOPROC + 0)
109 #define DT_RISCV_SYMTABNO (DT_LOPROC + 1)
110 #define DT_RISCV_GOTSYM (DT_LOPROC + 2)
111 #define DT_RISCV_PLTGOT (DT_LOPROC + 3)
112
113 #ifdef _KERNEL
114 #ifdef ELFSIZE
115 #define ELF_MD_PROBE_FUNC ELFNAME2(cpu_netbsd,probe)
116 #endif
117
118 struct exec_package;
119
120 int cpu_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
121 vaddr_t *);
122
123 int cpu_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *,
124 vaddr_t *);
125
126 #endif /* _KERNEL */
127
128 #endif /* _RISCV_ELF_MACHDEP_H_ */
129