xref: /netbsd/sys/compat/freebsd/freebsd_exec.h (revision 6550d01e)
1 /*	$NetBSD: freebsd_exec.h,v 1.17 2009/12/10 14:13:53 matt Exp $	*/
2 
3 /*-
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	from: @(#)exec.h	8.1 (Berkeley) 6/11/93
32  *	from: imgact_aout.h,v 1.2 1994/12/30 08:06:19 bde Exp
33  */
34 
35 #ifndef	_FREEBSD_EXEC_H
36 #define	_FREEBSD_EXEC_H
37 
38 #ifdef EXEC_AOUT
39 #define FREEBSD_N_GETMAGIC(ex) \
40 	( (ex).a_midmag & 0xffff )
41 #define FREEBSD_N_GETMID(ex) \
42 	( ((ex).a_midmag >> 16) & 0x03ff )
43 #define FREEBSD_N_GETFLAG(ex) \
44 	( ((ex).a_midmag >> 26) & 0x3f )
45 #define FREEBSD_N_SETMAGIC(ex,mag,mid,flag) \
46 	( (ex).a_midmag = (((flag) & 0x3f) <<26) | (((mid) & 0x03ff) << 16) | \
47 	((mag) & 0xffff) )
48 
49 #define FREEBSD_N_ALIGN(ex,x) \
50 	(FREEBSD_N_GETMAGIC(ex) == ZMAGIC || \
51 	 FREEBSD_N_GETMAGIC(ex) == QMAGIC ? \
52 	 ((x) + FREEBSD___LDPGSZ - 1) & \
53 	 ~(unsigned long)(FREEBSD___LDPGSZ - 1) : (x))
54 
55 /* Valid magic number check. */
56 #define	FREEBSD_N_BADMAG(ex) \
57 	(FREEBSD_N_GETMAGIC(ex) != OMAGIC && \
58 	 FREEBSD_N_GETMAGIC(ex) != NMAGIC && \
59 	 FREEBSD_N_GETMAGIC(ex) != ZMAGIC && \
60 	 FREEBSD_N_GETMAGIC(ex) != QMAGIC)
61 
62 /* Address of the bottom of the text segment. */
63 #define FREEBSD_N_TXTADDR(ex) \
64 	((FREEBSD_N_GETMAGIC(ex) == OMAGIC || \
65 	  FREEBSD_N_GETMAGIC(ex) == NMAGIC || \
66 	  FREEBSD_N_GETMAGIC(ex) == ZMAGIC) ? 0 : AOUT_LDPGSZ)
67 
68 /* Address of the bottom of the data segment. */
69 #define FREEBSD_N_DATADDR(ex) \
70 	FREEBSD_N_ALIGN(ex, FREEBSD_N_TXTADDR(ex) + (ex).a_text)
71 
72 /* Text segment offset. */
73 #define	FREEBSD_N_TXTOFF(ex) \
74 	(FREEBSD_N_GETMAGIC(ex) == ZMAGIC ? AOUT_LDPGSZ : \
75 	 FREEBSD_N_GETMAGIC(ex) == QMAGIC ? 0 : sizeof(struct exec))
76 
77 /* Data segment offset. */
78 #define	FREEBSD_N_DATOFF(ex) \
79 	FREEBSD_N_ALIGN(ex, FREEBSD_N_TXTOFF(ex) + (ex).a_text)
80 
81 /* Relocation table offset. */
82 #define FREEBSD_N_RELOFF(ex) \
83 	FREEBSD_N_ALIGN(ex, FREEBSD_N_DATOFF(ex) + (ex).a_data)
84 
85 /* Symbol table offset. */
86 #define FREEBSD_N_SYMOFF(ex) \
87 	(FREEBSD_N_RELOFF(ex) + (ex).a_trsize + (ex).a_drsize)
88 
89 /* String table offset. */
90 #define	FREEBSD_N_STROFF(ex) 	(FREEBSD_N_SYMOFF(ex) + (ex).a_syms)
91 
92 #define	FREEBSD_AOUT_HDR_SIZE	sizeof(struct exec)
93 
94 int exec_freebsd_aout_makecmds(struct lwp *, struct exec_package *);
95 
96 #endif /* EXEC_AOUT */
97 
98 #ifdef EXEC_ELF32
99 #define FREEBSD_ELF_BRAND_STRING "FreeBSD"
100 #define FREEBSD_ELF_INTERP_PREFIX_STRING "/usr/libexec/ld-elf.so"
101 
102 int freebsd_elf32_probe(struct lwp *, struct exec_package *, void *,
103     char *, vaddr_t *);
104 #endif /* EXEC_ELF32 */
105 
106 void freebsd_setregs(struct lwp *, struct exec_package *, vaddr_t);
107 
108 extern char freebsd_sigcode[], freebsd_esigcode[];
109 extern struct emul emul_freebsd;
110 
111 #endif /* !_FREEBSD_EXEC_H */
112