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