Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:25

0001 /* $NetBSD: elf_machdep.h,v 1.6 2017/11/06 03:47:48 christos Exp $ */
0002 
0003 /*-
0004  * Copyright (c) 2019 Hesham Almatary
0005  *
0006  * Copyright (c) 2014 The NetBSD Foundation, Inc.
0007  * All rights reserved.
0008  *
0009  * This code is derived from software contributed to The NetBSD Foundation
0010  * by Matt Thomas of 3am Software Foundry.
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
0022  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
0023  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0024  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
0025  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 #ifndef _RISCV_ELF_MACHDEP_H_
0035 #define _RISCV_ELF_MACHDEP_H_
0036 
0037 #define EM_RISCV                243
0038 #define ELF32_MACHDEP_ID        EM_RISCV
0039 #define ELF64_MACHDEP_ID        EM_RISCV
0040 
0041 #define ELF32_MACHDEP_ENDIANNESS    ELFDATA2LSB
0042 #define ELF64_MACHDEP_ENDIANNESS    ELFDATA2LSB
0043 
0044 #define ELF32_MACHDEP_ID_CASES      \
0045         case EM_RISCV:      \
0046             break;
0047 
0048 #define ELF64_MACHDEP_ID_CASES      \
0049         case EM_RISCV:      \
0050             break;
0051 
0052 #define KERN_ELFSIZE        32
0053 #ifdef _LP64
0054 #define ARCH_ELFSIZE        64  /* MD native binary size */
0055 #else
0056 #define ARCH_ELFSIZE        32  /* MD native binary size */
0057 #endif
0058 
0059 /* Processor specific flags for the ELF header e_flags field.  */
0060 
0061 /* Processor specific relocation types */
0062 
0063 #define R_RISCV_NONE        0
0064 #define R_RISCV_32      1   // A
0065 #define R_RISCV_64      2
0066 #define R_RISCV_RELATIVE    3
0067 #define R_RISCV_COPY        4
0068 #define R_RISCV_JMP_SLOT    5
0069 #define R_RISCV_TLS_DTPMOD32    6
0070 #define R_RISCV_TLS_DTPREL32    7
0071 #define R_RISCV_TLS_DTPMOD64    8
0072 #define R_RISCV_TLS_DTPREL64    9
0073 #define R_RISCV_TLS_TPREL32 10
0074 #define R_RISCV_TLS_TPREL64 11
0075 
0076 /* The rest are not used by the dynamic linker */
0077 #define R_RISCV_BRANCH      16  // (A - P) & 0xffff
0078 #define R_RISCV_JAL     17  // A & 0xff
0079 #define R_RISCV_CALL        18  // (A - P) & 0xff
0080 #define R_RISCV_CALL_PLT    19
0081 #define R_RISCV_GOT_HI20    20
0082 #define R_RISCV_TLS_GOT_HI20    21
0083 #define R_RISCV_TLS_GD_HI20 22
0084 #define R_RISCV_PCREL_HI20  23
0085 #define R_RISCV_PCREL_LO12_I    24
0086 #define R_RISCV_PCREL_LO12_S    25
0087 #define R_RISCV_HI20        26  // A & 0xffff
0088 #define R_RISCV_LO12_I      27  // (A >> 16) & 0xffff
0089 #define R_RISCV_LO12_S      28  // (S + A - P) >> 2
0090 #define R_RISCV_TPREL_HI20  29
0091 #define R_RISCV_TPREL_LO12_I    30
0092 #define R_RISCV_TPREL_LO12_S    31
0093 #define R_RISCV_TPREL_ADD   32
0094 #define R_RISCV_ADD8        33
0095 #define R_RISCV_ADD16       34
0096 #define R_RISCV_ADD32       35
0097 #define R_RISCV_ADD64       36
0098 #define R_RISCV_SUB8        37
0099 #define R_RISCV_SUB16       38
0100 #define R_RISCV_SUB32       39
0101 #define R_RISCV_SUB64       40
0102 #define R_RISCV_GNU_VTINHERIT   41  // A & 0xffff
0103 #define R_RISCV_GNU_VTENTRY 42
0104 #define R_RISCV_ALIGN       43
0105 #define R_RISCV_RVC_BRANCH  44
0106 #define R_RISCV_RVC_JUMP    45
0107 #define R_RISCV_RVC_LUI   46
0108 
0109 #define R_RISCV_RELAX       51
0110 #define R_RISCV_SUB6        52
0111 #define R_RISCV_SET6        53
0112 #define R_RISCV_SET8        54
0113 #define R_RISCV_SET16       55
0114 #define R_RISCV_SET32       56
0115 
0116 #define R_RISCV_32_PCREL    57
0117 
0118 /* These are aliases we can use R_TYPESZ */
0119 #define R_RISCV_ADDR32      R_RISCV_32
0120 #define R_RISCV_ADDR64      R_RISCV_64
0121 
0122 #define R_TYPE(name)        R_RISCV_ ## name
0123 #if ELFSIZE == 32
0124 #define R_TYPESZ(name)      R_RISCV_ ## name ## 32
0125 #else
0126 #define R_TYPESZ(name)      R_RISCV_ ## name ## 64
0127 #endif
0128 
0129 #ifdef _KERNEL
0130 #ifdef ELFSIZE
0131 #define ELF_MD_PROBE_FUNC       ELFNAME2(cpu_netbsd,probe)
0132 #endif
0133 
0134 struct exec_package;
0135 
0136 int cpu_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
0137         vaddr_t *);
0138 
0139 int cpu_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *,
0140         vaddr_t *);
0141 
0142 #endif /* _KERNEL */
0143 
0144 #endif /* _RISCV_ELF_MACHDEP_H_ */