xref: /illumos-gate/usr/src/tools/btxld/imgact_aout.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*-
2  * Copyright (c) 1992, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *	from: @(#)exec.h	8.1 (Berkeley) 6/11/93
30  * $FreeBSD$
31  */
32 
33 #ifndef	_IMGACT_AOUT_H_
34 #define	_IMGACT_AOUT_H_
35 
36 #define N_GETMAGIC(ex) \
37 	( LE_32((ex).a_midmag) & 0xffff )
38 #define N_GETMID(ex) \
39 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETMID_NET(ex) : \
40 	((ex).a_midmag >> 16) & 0x03ff )
41 #define N_GETFLAG(ex) \
42 	( (N_GETMAGIC_NET(ex) == ZMAGIC) ? N_GETFLAG_NET(ex) : \
43 	((ex).a_midmag >> 26) & 0x3f )
44 #define N_SETMAGIC(ex,mag,mid,flag) \
45 	( (ex).a_midmag = LE_32((((flag) & 0x3f) <<26) | \
46 	(((mid) & 0x03ff) << 16) | \
47 	((mag) & 0xffff)) )
48 
49 #define N_GETMAGIC_NET(ex) \
50 	(ntohl((ex).a_midmag) & 0xffff)
51 #define N_GETMID_NET(ex) \
52 	((ntohl((ex).a_midmag) >> 16) & 0x03ff)
53 #define N_GETFLAG_NET(ex) \
54 	((ntohl((ex).a_midmag) >> 26) & 0x3f)
55 #define N_SETMAGIC_NET(ex,mag,mid,flag) \
56 	( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) \
57 	| (((mag)&0xffff)) ) )
58 
59 #define N_ALIGN(ex,x) \
60 	(N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC || \
61 	 N_GETMAGIC_NET(ex) == ZMAGIC || N_GETMAGIC_NET(ex) == QMAGIC ? \
62 	 ((x) + __LDPGSZ - 1) & ~(uint32_t)(__LDPGSZ - 1) : (x))
63 
64 /* Valid magic number check. */
65 #define	N_BADMAG(ex) \
66 	(N_GETMAGIC(ex) != OMAGIC && N_GETMAGIC(ex) != NMAGIC && \
67 	 N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC && \
68 	 N_GETMAGIC_NET(ex) != OMAGIC && N_GETMAGIC_NET(ex) != NMAGIC && \
69 	 N_GETMAGIC_NET(ex) != ZMAGIC && N_GETMAGIC_NET(ex) != QMAGIC)
70 
71 
72 /* Address of the bottom of the text segment. */
73 /*
74  * This can not be done right.  Abuse a_entry in some cases to handle kernels.
75  */
76 #define N_TXTADDR(ex) \
77 	((N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC || \
78 	N_GETMAGIC(ex) == ZMAGIC) ? \
79 	(le32toh((ex).a_entry) < le32toh((ex).a_text) ? 0 : \
80 	le32toh((ex).a_entry) & ~__LDPGSZ) : __LDPGSZ)
81 
82 /* Address of the bottom of the data segment. */
83 #define N_DATADDR(ex) \
84 	N_ALIGN(ex, N_TXTADDR(ex) + le32toh((ex).a_text))
85 
86 /* Text segment offset. */
87 #define	N_TXTOFF(ex) \
88 	(N_GETMAGIC(ex) == ZMAGIC ? __LDPGSZ : (N_GETMAGIC(ex) == QMAGIC || \
89 	N_GETMAGIC_NET(ex) == ZMAGIC) ? 0 : sizeof(struct exec))
90 
91 /* Data segment offset. */
92 #define	N_DATOFF(ex) \
93 	N_ALIGN(ex, N_TXTOFF(ex) + le32toh((ex).a_text))
94 
95 /* Relocation table offset. */
96 #define N_RELOFF(ex) \
97 	N_ALIGN(ex, N_DATOFF(ex) + le32toh((ex).a_data))
98 
99 /* Symbol table offset. */
100 #define N_SYMOFF(ex) \
101 	(N_RELOFF(ex) + le32toh((ex).a_trsize) + le32toh((ex).a_drsize))
102 
103 /* String table offset. */
104 #define	N_STROFF(ex) 	(N_SYMOFF(ex) + le32toh((ex).a_syms))
105 
106 /*
107  * Header prepended to each a.out file.
108  * Only manipulate the a_midmag field via the
109  * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros.
110  */
111 
112 struct exec {
113      uint32_t	a_midmag;	/* flags<<26 | mid<<16 | magic */
114      uint32_t	a_text;		/* text segment size */
115      uint32_t	a_data;		/* initialized data size */
116      uint32_t	a_bss;		/* uninitialized data size */
117      uint32_t	a_syms;		/* symbol table size */
118      uint32_t	a_entry;	/* entry point */
119      uint32_t	a_trsize;	/* text relocation size */
120      uint32_t	a_drsize;	/* data relocation size */
121 };
122 #define a_magic a_midmag	/* Hack for emulators */
123 
124 /* a_magic */
125 #define	OMAGIC		0407	/* old impure format */
126 #define	NMAGIC		0410	/* read-only text */
127 #define	ZMAGIC		0413	/* demand load format */
128 #define QMAGIC          0314    /* "compact" demand load format */
129 
130 /* a_mid */
131 #define	MID_ZERO	0	/* unknown - implementation dependent */
132 #define	MID_SUN010	1	/* sun 68010/68020 binary */
133 #define	MID_SUN020	2	/* sun 68020-only binary */
134 #define MID_I386	134	/* i386 BSD binary */
135 #define MID_SPARC	138	/* sparc */
136 #define MID_ARM6	143	/* ARM6 */
137 #define	MID_HP200	200	/* hp200 (68010) BSD binary */
138 #define	MID_HP300	300	/* hp300 (68020+68881) BSD binary */
139 #define	MID_HPUX	0x20C	/* hp200/300 HP-UX binary */
140 #define	MID_HPUX800     0x20B   /* hp800 HP-UX binary */
141 
142 /*
143  * a_flags
144  */
145 #define EX_PIC		0x10	/* contains position independent code */
146 #define EX_DYNAMIC	0x20	/* contains run-time link-edit info */
147 #define EX_DPMASK	0x30	/* mask for the above */
148 
149 #ifdef _KERNEL
150 struct thread;
151 struct vnode;
152 
153 int	aout_coredump(struct thread *td, struct vnode *vp, off_t limit,
154     int flags);
155 #endif
156 
157 #endif /* !_IMGACT_AOUT_H_ */
158