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