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