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