1292407Sbr/*-
2292407Sbr * Copyright (c) 1996-1997 John D. Polstra.
3292407Sbr * All rights reserved.
4292407Sbr *
5292407Sbr * Redistribution and use in source and binary forms, with or without
6292407Sbr * modification, are permitted provided that the following conditions
7292407Sbr * are met:
8292407Sbr * 1. Redistributions of source code must retain the above copyright
9292407Sbr *    notice, this list of conditions and the following disclaimer.
10292407Sbr * 2. Redistributions in binary form must reproduce the above copyright
11292407Sbr *    notice, this list of conditions and the following disclaimer in the
12292407Sbr *    documentation and/or other materials provided with the distribution.
13292407Sbr *
14292407Sbr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15292407Sbr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16292407Sbr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17292407Sbr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18292407Sbr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19292407Sbr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20292407Sbr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21292407Sbr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22292407Sbr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23292407Sbr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24292407Sbr * SUCH DAMAGE.
25292407Sbr *
26292407Sbr * $FreeBSD: stable/11/sys/riscv/include/elf.h 325810 2017-11-14 16:03:07Z jhb $
27292407Sbr */
28292407Sbr
29292407Sbr#ifndef	_MACHINE_ELF_H_
30292407Sbr#define	_MACHINE_ELF_H_
31292407Sbr
32292407Sbr/*
33292407Sbr * ELF definitions for the RISC-V architecture.
34292407Sbr */
35292407Sbr
36292407Sbr#include <sys/elf32.h>	/* Definitions common to all 32 bit architectures. */
37292407Sbr#include <sys/elf64.h>	/* Definitions common to all 64 bit architectures. */
38292407Sbr
39292407Sbr#define	__ELF_WORD_SIZE	64	/* Used by <sys/elf_generic.h> */
40292407Sbr#include <sys/elf_generic.h>
41292407Sbr
42292407Sbr/*
43292407Sbr * Auxiliary vector entries for passing information to the interpreter.
44292407Sbr */
45292407Sbr
46292407Sbrtypedef struct {	/* Auxiliary vector entry on initial stack */
47292407Sbr	int	a_type;			/* Entry type. */
48292407Sbr	union {
49292407Sbr		int	a_val;		/* Integer value. */
50292407Sbr	} a_un;
51292407Sbr} Elf32_Auxinfo;
52292407Sbr
53292407Sbrtypedef struct {	/* Auxiliary vector entry on initial stack */
54292407Sbr	long	a_type;			/* Entry type. */
55292407Sbr	union {
56292407Sbr		long	a_val;		/* Integer value. */
57292407Sbr		void	*a_ptr;		/* Address. */
58292407Sbr		void	(*a_fcn)(void);	/* Function pointer (not used). */
59292407Sbr	} a_un;
60292407Sbr} Elf64_Auxinfo;
61292407Sbr
62292407Sbr__ElfType(Auxinfo);
63292407Sbr
64292407Sbr#define	ELF_ARCH	EM_RISCV
65292407Sbr
66292407Sbr#define	ELF_MACHINE_OK(x) ((x) == (ELF_ARCH))
67292407Sbr
68292407Sbr/* Values for a_type. */
69292407Sbr#define	AT_NULL		0	/* Terminates the vector. */
70292407Sbr#define	AT_IGNORE	1	/* Ignored entry. */
71292407Sbr#define	AT_EXECFD	2	/* File descriptor of program to load. */
72292407Sbr#define	AT_PHDR		3	/* Program header of program already loaded. */
73292407Sbr#define	AT_PHENT	4	/* Size of each program header entry. */
74292407Sbr#define	AT_PHNUM	5	/* Number of program header entries. */
75292407Sbr#define	AT_PAGESZ	6	/* Page size in bytes. */
76292407Sbr#define	AT_BASE		7	/* Interpreter's base address. */
77292407Sbr#define	AT_FLAGS	8	/* Flags (unused). */
78292407Sbr#define	AT_ENTRY	9	/* Where interpreter should transfer control. */
79292407Sbr#define	AT_NOTELF	10	/* Program is not ELF ?? */
80292407Sbr#define	AT_UID		11	/* Real uid. */
81292407Sbr#define	AT_EUID		12	/* Effective uid. */
82292407Sbr#define	AT_GID		13	/* Real gid. */
83292407Sbr#define	AT_EGID		14	/* Effective gid. */
84292407Sbr#define	AT_EXECPATH	15	/* Path to the executable. */
85292407Sbr#define	AT_CANARY	16	/* Canary for SSP */
86292407Sbr#define	AT_CANARYLEN	17	/* Length of the canary. */
87292407Sbr#define	AT_OSRELDATE	18	/* OSRELDATE. */
88292407Sbr#define	AT_NCPUS	19	/* Number of CPUs. */
89292407Sbr#define	AT_PAGESIZES	20	/* Pagesizes. */
90292407Sbr#define	AT_PAGESIZESLEN	21	/* Number of pagesizes. */
91292407Sbr#define	AT_TIMEKEEP	22	/* Pointer to timehands. */
92292407Sbr#define	AT_STACKPROT	23	/* Initial stack protection. */
93324687Sjhb#define	AT_EHDRFLAGS	24	/* e_flags field from elf hdr */
94324687Sjhb#define	AT_HWCAP	25	/* CPU feature flags. */
95325810Sjhb#define	AT_HWCAP2	26	/* CPU feature flags 2. */
96292407Sbr
97325810Sjhb#define	AT_COUNT	27	/* Count of defined aux entry types. */
98292407Sbr
99292407Sbr/* Define "machine" characteristics */
100292407Sbr#define	ELF_TARG_CLASS	ELFCLASS64
101292407Sbr#define	ELF_TARG_DATA	ELFDATA2LSB
102292407Sbr#define	ELF_TARG_MACH	EM_RISCV
103292407Sbr#define	ELF_TARG_VER	1
104292407Sbr
105292407Sbr/* TODO: set correct value */
106292407Sbr#define	ET_DYN_LOAD_ADDR 0x100000
107292407Sbr
108292407Sbr#endif /* !_MACHINE_ELF_H_ */
109