elf.h revision 77931
1179193Sjb/*-
2179193Sjb * Copyright (c) 1996-1997 John D. Polstra.
3179193Sjb * All rights reserved.
4179193Sjb *
5179193Sjb * Redistribution and use in source and binary forms, with or without
6179193Sjb * modification, are permitted provided that the following conditions
7179193Sjb * are met:
8179193Sjb * 1. Redistributions of source code must retain the above copyright
9179193Sjb *    notice, this list of conditions and the following disclaimer.
10179193Sjb * 2. Redistributions in binary form must reproduce the above copyright
11179193Sjb *    notice, this list of conditions and the following disclaimer in the
12179193Sjb *    documentation and/or other materials provided with the distribution.
13179193Sjb *
14179193Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15179193Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16179193Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17179193Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18179193Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19179193Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20211738Srpaulo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21211738Srpaulo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22211738Srpaulo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23211738Srpaulo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24179193Sjb * SUCH DAMAGE.
25179193Sjb *
26179193Sjb * $FreeBSD: head/sys/i386/include/elf.h 77931 2001-06-09 05:21:17Z obrien $
27179198Sjb */
28179193Sjb
29179193Sjb#ifndef _MACHINE_ELF_H_
30179193Sjb#define	_MACHINE_ELF_H_ 1
31211738Srpaulo
32179193Sjb/*
33211738Srpaulo * ELF definitions for the i386 architecture.
34179193Sjb */
35179193Sjb
36179193Sjb#include <sys/elf32.h>	/* Definitions common to all 32 bit architectures. */
37179193Sjb
38179193Sjb#define	__ELF_WORD_SIZE	32	/* Used by <sys/elf_generic.h> */
39179193Sjb#include <sys/elf_generic.h>
40179193Sjb
41211738Srpaulo#define	ELF_ARCH	EM_386
42179193Sjb
43211738Srpaulo#define	ELF_MACHINE_OK(x) ((x) == EM_386 || (x) == EM_486)
44179193Sjb
45179193Sjb/*
46179193Sjb * Auxiliary vector entries for passing information to the interpreter.
47211738Srpaulo *
48179193Sjb * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
49211738Srpaulo * but POSIX lays claim to all symbols ending with "_t".
50179193Sjb */
51179193Sjb
52179193Sjbtypedef struct {	/* Auxiliary vector entry on initial stack */
53179193Sjb	int	a_type;			/* Entry type. */
54179193Sjb	union {
55179193Sjb		long	a_val;		/* Integer value. */
56179193Sjb		void	*a_ptr;		/* Address. */
57179193Sjb		void	(*a_fcn)(void);	/* Function pointer (not used). */
58211738Srpaulo	} a_un;
59179193Sjb} Elf32_Auxinfo;
60211738Srpaulo
61211738Srpaulo__ElfType(Auxinfo);
62211738Srpaulo
63211738Srpaulo/* Values for a_type. */
64211738Srpaulo#define	AT_NULL		0	/* Terminates the vector. */
65211738Srpaulo#define	AT_IGNORE	1	/* Ignored entry. */
66211738Srpaulo#define	AT_EXECFD	2	/* File descriptor of program to load. */
67211738Srpaulo#define	AT_PHDR		3	/* Program header of program already loaded. */
68179193Sjb#define	AT_PHENT	4	/* Size of each program header entry. */
69179193Sjb#define	AT_PHNUM	5	/* Number of program header entries. */
70179193Sjb#define	AT_PAGESZ	6	/* Page size in bytes. */
71179193Sjb#define	AT_BASE		7	/* Interpreter's base address. */
72179193Sjb#define	AT_FLAGS	8	/* Flags (unused for i386). */
73179193Sjb#define	AT_ENTRY	9	/* Where interpreter should transfer control. */
74179193Sjb
75179193Sjb/*
76179193Sjb * The following non-standard values are used for passing information
77179193Sjb * from John Polstra's testbed program to the dynamic linker.  These
78179193Sjb * are expected to go away soon.
79179193Sjb *
80179193Sjb * Unfortunately, these overlap the Linux non-standard values, so they
81179193Sjb * must not be used in the same context.
82179193Sjb */
83179193Sjb#define	AT_BRK		10	/* Starting point for sbrk and brk. */
84179193Sjb#define	AT_DEBUG	11	/* Debugging level. */
85179193Sjb
86179193Sjb/*
87179193Sjb * The following non-standard values are used in Linux ELF binaries.
88179193Sjb */
89179193Sjb#define	AT_NOTELF	10	/* Program is not ELF ?? */
90179193Sjb#define	AT_UID		11	/* Real uid. */
91179193Sjb#define	AT_EUID		12	/* Effective uid. */
92179193Sjb#define	AT_GID		13	/* Real gid. */
93179193Sjb#define	AT_EGID		14	/* Effective gid. */
94179193Sjb
95179193Sjb#define	AT_COUNT	15	/* Count of defined aux entry types. */
96179193Sjb
97179193Sjb/*
98179193Sjb * Relocation types.
99179193Sjb */
100179193Sjb
101179193Sjb#define	R_386_NONE	0	/* No relocation. */
102179193Sjb#define	R_386_32	1	/* Add symbol value. */
103179193Sjb#define	R_386_PC32	2	/* Add PC-relative symbol value. */
104179193Sjb#define	R_386_GOT32	3	/* Add PC-relative GOT offset. */
105179193Sjb#define	R_386_PLT32	4	/* Add PC-relative PLT offset. */
106179193Sjb#define	R_386_COPY	5	/* Copy data from shared object. */
107179193Sjb#define	R_386_GLOB_DAT	6	/* Set GOT entry to data address. */
108179193Sjb#define	R_386_JMP_SLOT	7	/* Set GOT entry to code address. */
109179193Sjb#define	R_386_RELATIVE	8	/* Add load address of shared object. */
110179193Sjb#define	R_386_GOTOFF	9	/* Add GOT-relative symbol address. */
111179193Sjb#define	R_386_GOTPC	10	/* Add PC-relative GOT table address. */
112179193Sjb
113179193Sjb#define	R_386_COUNT	11	/* Count of defined relocation types. */
114179193Sjb
115179193Sjb/* Define "machine" characteristics */
116179193Sjb#define	ELF_TARG_CLASS	ELFCLASS32
117179193Sjb#define	ELF_TARG_DATA	ELFDATA2LSB
118179193Sjb#define	ELF_TARG_MACH	EM_386
119179193Sjb#define	ELF_TARG_VER	1
120179193Sjb
121179193Sjb#ifdef _KERNEL
122179193Sjb
123179193Sjb/*
124179193Sjb * On the i386 we load the dynamic linker where a userland call
125179193Sjb * to mmap(0, ...) would put it.  The rationale behind this
126179193Sjb * calculation is that it leaves room for the heap to grow to
127179193Sjb * its maximum allowed size.
128179193Sjb */
129179193Sjb#define ELF_RTLD_ADDR(vmspace) \
130179193Sjb    (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ))
131179193Sjb
132179193Sjb#endif /* _KERNEL */
133179193Sjb#endif /* !_MACHINE_ELF_H_ */
134179193Sjb