archdep.h revision 1.7
1/*	$OpenBSD: archdep.h,v 1.7 2003/04/28 21:32:08 drahn Exp $ */
2
3/*
4 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed under OpenBSD by
17 *	Per Fogelstrom, Opsycon AB, Sweden.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 */
34
35#ifndef _I386_ARCHDEP_H_
36#define _I386_ARCHDEP_H_
37
38#define	DL_MALLOC_ALIGN	8	/* Arch constraint or otherwise */
39
40#define	MACHID	EM_386		/* ELF e_machine ID value checked */
41
42#define	RELTYPE	Elf32_Rela
43#define	RELSIZE	sizeof(Elf32_Rela)
44
45#include <sys/mman.h>
46#include <elf_abi.h>
47#include <machine/reloc.h>
48#include "syscall.h"
49#include "util.h"
50
51static inline void *
52_dl_mmap(void *addr, unsigned int len, unsigned int prot,
53	unsigned int flags, int fd, off_t offset)
54{
55	return((void *)_dl__syscall((quad_t)SYS_mmap, addr, len, prot,
56		flags, fd, 0, offset));
57}
58
59static inline void *
60_dl_mquery(void *addr, unsigned int len, unsigned int prot,
61	unsigned int flags, int fd, off_t offset)
62{
63	return((void *)_dl__syscall((quad_t)SYS_mquery, addr, len, prot,
64		flags, fd, 0, offset));
65}
66
67
68static inline void
69RELOC_REL(Elf32_Rel *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v)
70{
71
72	if (ELF32_R_TYPE(r->r_info) == RELOC_RELATIVE) {
73		*p += v;
74	} else if (ELF32_R_TYPE(r->r_info) == RELOC_GLOB_DAT) {
75		*p += v + s->st_value;
76	} else {
77		_dl_printf("unknown bootstrap relocation\n");
78		_dl_exit(6);
79	}
80}
81
82static inline void
83RELOC_RELA(Elf32_Rela *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v)
84{
85	/* does i386 use RELA type relocations? - XXX */
86
87	if (ELF32_R_TYPE(r->r_info) == RELOC_RELATIVE) {
88		*p = v + r->r_addend;
89	} else if (ELF32_R_TYPE(r->r_info) == RELOC_GLOB_DAT) {
90		*p = v + s->st_value + r->r_addend;
91	} else {
92		_dl_printf("unknown bootstrap relocation\n");
93		_dl_exit(6);
94	}
95}
96
97#define RELOC_GOT(obj, offs)
98
99#define GOT_PERMS PROT_READ
100
101#endif /* _I386_ARCHDEP_H_ */
102