xref: /titanic_51/usr/src/lib/libbc/inc/include/sun4/a.out.h (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #ifndef _sparc_a_out_h
30 #define _sparc_a_out_h
31 
32 #include <sys/exec.h>
33 
34 /*
35  * memory management parameters
36  */
37 
38 #define PAGSIZ		0x02000
39 #define SEGSIZ		PAGSIZ
40 #define	OLD_PAGSIZ	0x00800	/*  Page   size under Release 2.0 */
41 #define	OLD_SEGSIZ	0x08000	/* Segment size under Release 2.0 */
42 
43 /*
44  * returns 1 if an object file type is invalid, i.e., if the other macros
45  * defined below will not yield the correct offsets.  Note that a file may
46  * have N_BADMAG(x) = 0 and may be fully linked, but still may not be
47  * executable.
48  */
49 
50 #define	N_BADMAG(x) \
51 	((x).a_magic!=OMAGIC && (x).a_magic!=NMAGIC && (x).a_magic!=ZMAGIC)
52 
53 /*
54  * relocation parameters. These are architecture-dependent
55  * and can be deduced from the machine type.  They are used
56  * to calculate offsets of segments within the object file;
57  * See N_TXTOFF(x), etc. below.
58  */
59 
60 #define	N_PAGSIZ(x) \
61 	((x).a_machtype == M_OLDSUN2? OLD_PAGSIZ : PAGSIZ)
62 #define	N_SEGSIZ(x) \
63 	((x).a_machtype == M_OLDSUN2? OLD_SEGSIZ : SEGSIZ)
64 
65 /*
66  * offsets of various sections of an object file.
67  */
68 
69 #define	N_TXTOFF(x) \
70 	/* text segment */ \
71 	( (x).a_machtype == M_OLDSUN2 \
72 	? ((x).a_magic==ZMAGIC ? N_PAGSIZ(x) : sizeof (struct exec)) \
73 	: ((x).a_magic==ZMAGIC ? 0 : sizeof (struct exec)) )
74 
75 #define	N_DATOFF(x)   /* data segment */	\
76 	(N_TXTOFF(x) + (x).a_text)
77 
78 #define	N_TRELOFF(x)  /* text reloc'n */	\
79 	(N_DATOFF(x) + (x).a_data)
80 
81 #define	N_DRELOFF(x) /* data relocation*/	\
82 	(N_TRELOFF(x) + (x).a_trsize)
83 
84 #define	N_SYMOFF(x) \
85 	/* symbol table */ \
86 	(N_TXTOFF(x)+(x).a_text+(x).a_data+(x).a_trsize+(x).a_drsize)
87 
88 #define	N_STROFF(x) \
89 	/* string table */ \
90 	(N_SYMOFF(x) + (x).a_syms)
91 
92 /*
93  * Macros which take exec structures as arguments and tell where the
94  * various pieces will be loaded.
95  */
96 
97 #define	_N_BASEADDR(x) \
98 	(((x).a_magic == ZMAGIC) && ((x).a_entry < N_PAGSIZ(x)) ? \
99 	    0 : N_PAGSIZ(x))
100 
101 #define N_TXTADDR(x) \
102 	((x).a_machtype == M_OLDSUN2 ? N_SEGSIZ(x) : _N_BASEADDR(x))
103 
104 #define N_DATADDR(x) \
105 	(((x).a_magic==OMAGIC)? (N_TXTADDR(x)+(x).a_text) \
106 	: (N_SEGSIZ(x)+((N_TXTADDR(x)+(x).a_text-1) & ~(N_SEGSIZ(x)-1))))
107 
108 #define N_BSSADDR(x)  (N_DATADDR(x)+(x).a_data)
109 
110 /*
111  * Format of a relocation datum.
112  */
113 
114 /*
115  * Sparc relocation types
116  */
117 
118 enum reloc_type
119 {
120 	RELOC_8,	RELOC_16,	RELOC_32,	/* simplest relocs    */
121 	RELOC_DISP8,	RELOC_DISP16,	RELOC_DISP32,	/* Disp's (pc-rel)    */
122 	RELOC_WDISP30,	RELOC_WDISP22,			/* SR word disp's     */
123 	RELOC_HI22,	RELOC_22,			/* SR 22-bit relocs   */
124 	RELOC_13,	RELOC_LO10,			/* SR 13&10-bit relocs*/
125 	RELOC_SFA_BASE,	RELOC_SFA_OFF13,		/* SR S.F.A. relocs   */
126 	RELOC_BASE10,	RELOC_BASE13,	RELOC_BASE22,	/* base_relative pic */
127 	RELOC_PC10,	RELOC_PC22,			/* special pc-rel pic*/
128 	RELOC_JMP_TBL,					/* jmp_tbl_rel in pic */
129 	RELOC_SEGOFF16,					/* ShLib offset-in-seg*/
130 	RELOC_GLOB_DAT, RELOC_JMP_SLOT, RELOC_RELATIVE, /* rtld relocs        */
131 };
132 
133 /*
134  * Format of a relocation datum.
135  */
136 
137 struct reloc_info_sparc	/* used when header.a_machtype == M_SPARC */
138 {
139 	unsigned long int r_address;	/* relocation addr (offset in segment)*/
140 	unsigned int	r_index   :24;	/* segment index or symbol index      */
141 	unsigned int	r_extern  : 1;	/* if F, r_index==SEG#; if T, SYM idx */
142 	int			  : 2;	/* <unused>			      */
143 	enum reloc_type r_type    : 5;	/* type of relocation to perform      */
144 	long int	r_addend;	/* addend for relocation value	      */
145 };
146 
147 
148 
149 /*
150  * Format of a symbol table entry
151  */
152 struct	nlist {
153 	union {
154 		char	*n_name;	/* for use when in-core */
155 		long	n_strx;		/* index into file string table */
156 	} n_un;
157 	unsigned char	n_type;		/* type flag (N_TEXT,..)  */
158 	char	n_other;		/* unused */
159 	short	n_desc;			/* see <stab.h> */
160 	unsigned long	n_value;	/* value of symbol (or sdb offset) */
161 };
162 
163 /*
164  * Simple values for n_type.
165  */
166 #define	N_UNDF	0x0		/* undefined */
167 #define	N_ABS	0x2		/* absolute */
168 #define	N_TEXT	0x4		/* text */
169 #define	N_DATA	0x6		/* data */
170 #define	N_BSS	0x8		/* bss */
171 #define	N_COMM	0x12		/* common (internal to ld) */
172 #define	N_FN	0x1e		/* file name symbol */
173 
174 #define	N_EXT	01		/* external bit, or'ed in */
175 #define	N_TYPE	0x1e		/* mask for all the type bits */
176 
177 /*
178  * Dbx entries have some of the N_STAB bits set.
179  * These are given in <stab.h>
180  */
181 #define	N_STAB	0xe0		/* if any of these bits set, a dbx symbol */
182 
183 /*
184  * Format for namelist values.
185  */
186 #define	N_FORMAT	"%08x"
187 
188 /*
189  * secondary sections.
190  * this stuff follows the string table.
191  * not even its presence or absence is noted in the
192  * exec header (?). the secondary header gives
193  * the number of sections. following it is an
194  * array of "extra_nsects" int's which give the
195  * sizeof of the individual sections. the presence of
196  * even the header is optional.
197  */
198 
199 #define EXTRA_MAGIC     1040            /* taxing concept  */
200 #define EXTRA_IDENT     0               /* ident's in 0th extra section */
201 
202 struct extra_sections {
203 	   	int     extra_magic;            /* should be EXTRA_MAGIC */
204 	   	int     extra_nsects;           /* number of extra sections */
205 };
206 
207 #endif /*!_sparc_a_out_h*/
208