Home | History | Annotate | Line # | Download | only in include
      1 /* $NetBSD: elf_machdep.h,v 1.11 2025/12/04 21:51:10 jkoshy 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 #if !defined(_SYS_ELFDEFINITIONS_H_)
     36 /* Processor specific flags for the ELF header e_flags field.  */
     37 
     38 /* Processor specific relocation types */
     39 
     40 #define R_RISCV_NONE		0
     41 #define R_RISCV_32		1	// A
     42 #define R_RISCV_64		2
     43 #define R_RISCV_RELATIVE	3
     44 #define R_RISCV_COPY		4
     45 #define R_RISCV_JMP_SLOT	5
     46 #define R_RISCV_TLS_DTPMOD32	6
     47 #define R_RISCV_TLS_DTPMOD64	7
     48 #define R_RISCV_TLS_DTPREL32	8
     49 #define R_RISCV_TLS_DTPREL64	9
     50 #define R_RISCV_TLS_TPREL32	10
     51 #define R_RISCV_TLS_TPREL64	11
     52 
     53 /* The rest are not used by the dynamic linker */
     54 #define R_RISCV_BRANCH		16	// (A - P) & 0xffff
     55 #define R_RISCV_JAL		17	// A & 0xff
     56 #define R_RISCV_CALL		18	// (A - P) & 0xff
     57 #define R_RISCV_CALL_PLT	19
     58 #define R_RISCV_GOT_HI20	20
     59 #define R_RISCV_TLS_GOT_HI20	21
     60 #define R_RISCV_TLS_GD_HI20	22
     61 #define R_RISCV_PCREL_HI20	23
     62 #define R_RISCV_PCREL_LO12_I	24
     63 #define R_RISCV_PCREL_LO12_S	25
     64 #define R_RISCV_HI20		26	// A & 0xffff
     65 #define R_RISCV_LO12_I		27	// (A >> 16) & 0xffff
     66 #define R_RISCV_LO12_S		28	// (S + A - P) >> 2
     67 #define R_RISCV_TPREL_HI20	29
     68 #define R_RISCV_TPREL_LO12_I	30
     69 #define R_RISCV_TPREL_LO12_S	31
     70 #define R_RISCV_TPREL_ADD	32
     71 #define R_RISCV_ADD8		33
     72 #define R_RISCV_ADD16		34
     73 #define R_RISCV_ADD32		35
     74 #define R_RISCV_ADD64		36
     75 #define R_RISCV_SUB8		37
     76 #define R_RISCV_SUB16		38
     77 #define R_RISCV_SUB32		39
     78 #define R_RISCV_SUB64		40
     79 #define R_RISCV_GNU_VTINHERIT	41	// A & 0xffff
     80 #define R_RISCV_GNU_VTENTRY	42
     81 #define R_RISCV_ALIGN		43
     82 #define R_RISCV_RVC_BRANCH	44
     83 #define R_RISCV_RVC_JUMP	45
     84 #define R_RISCV_RVC_LUI		46
     85 #define R_RISCV_GPREL_I		47
     86 #define R_RISCV_GPREL_S		48
     87 #define R_RISCV_TPREL_I		49
     88 #define R_RISCV_TPREL_S		50
     89 #define R_RISCV_RELAX		51
     90 #define R_RISCV_SUB6		52
     91 #define R_RISCV_SET6		53
     92 #define R_RISCV_SET8		54
     93 #define R_RISCV_SET16		55
     94 #define R_RISCV_SET32		56
     95 #define R_RISCV_32_PCREL	57
     96 #endif /* !defined(_SYS_ELFDEFINITIONS_H_) */
     97 
     98 /*
     99  * Local symbols.
    100  */
    101 
    102 #define	ELF32_MACHDEP_ID		EM_RISCV
    103 #define	ELF64_MACHDEP_ID		EM_RISCV
    104 
    105 #define ELF32_MACHDEP_ENDIANNESS	ELFDATA2LSB
    106 #define ELF64_MACHDEP_ENDIANNESS	ELFDATA2LSB
    107 
    108 #define ELF32_MACHDEP_ID_CASES		\
    109 		case EM_RISCV:		\
    110 			break;
    111 
    112 #define	ELF64_MACHDEP_ID_CASES		\
    113 		case EM_RISCV:		\
    114 			break;
    115 
    116 #ifdef _LP64
    117 #define	KERN_ELFSIZE		64
    118 #define ARCH_ELFSIZE		64	/* MD native binary size */
    119 #else
    120 #define	KERN_ELFSIZE		32
    121 #define ARCH_ELFSIZE		32	/* MD native binary size */
    122 #endif
    123 
    124 /* These are aliases we can use R_TYPESZ */
    125 #define R_RISCV_ADDR32		R_RISCV_32
    126 #define R_RISCV_ADDR64		R_RISCV_64
    127 
    128 #define R_TYPE(name)		R_RISCV_ ## name
    129 #if ELFSIZE == 32
    130 #define R_TYPESZ(name)		R_RISCV_ ## name ## 32
    131 #else
    132 #define R_TYPESZ(name)		R_RISCV_ ## name ## 64
    133 #endif
    134 
    135 #ifdef _KERNEL
    136 #ifdef ELFSIZE
    137 #define ELF_MD_PROBE_FUNC	ELFNAME2(cpu_netbsd,probe)
    138 #endif
    139 
    140 struct exec_package;
    141 
    142 int cpu_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
    143         vaddr_t *);
    144 
    145 int cpu_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *,
    146         vaddr_t *);
    147 
    148 #endif /* _KERNEL */
    149 
    150 #endif /* _RISCV_ELF_MACHDEP_H_ */
    151