coff_machdep.h revision 1.2 1 /* $NetBSD: coff_machdep.h,v 1.2 2000/01/02 13:39:51 msaitoh Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Scott Bartram
5 * All rights reserved.
6 *
7 * adapted from sys/sys/exec_ecoff.h
8 * based on Intel iBCS2
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef _SH3_COFF_MACHDEP_H_
34 #define _SH3_COFF_MACHDEP_H_
35
36 /*
37 * COFF file header
38 */
39
40 struct coff_filehdr {
41 u_short f_magic; /* magic number */
42 u_short f_nscns; /* # of sections */
43 long f_timdat; /* timestamp */
44 long f_symptr; /* file offset of symbol table */
45 long f_nsyms; /* # of symbol table entries */
46 u_short f_opthdr; /* size of optional header */
47 u_short f_flags; /* flags */
48 };
49
50 /* f_magic flags */
51 #define COFF_MAGIC_SH3_BIG 0x500
52 #define COFF_MAGIC_SH3_LITTLE 0x550
53
54 /* f_flags */
55 #define COFF_F_RELFLG 0x1
56 #define COFF_F_EXEC 0x2
57 #define COFF_F_LNNO 0x4
58 #define COFF_F_LSYMS 0x8
59 #define COFF_F_SWABD 0x40
60 #define COFF_F_AR16WR 0x80
61 #define COFF_F_AR32WR 0x100
62 #define COFF_F_AR32W 0x200
63
64 /*
65 * COFF system header
66 */
67
68 struct coff_aouthdr {
69 short a_magic;
70 short a_vstamp;
71 long a_tsize;
72 long a_dsize;
73 long a_bsize;
74 long a_entry;
75 long a_tstart;
76 long a_dstart;
77 };
78
79 /* magic */
80 #define COFF_OMAGIC 0444 /* text not write-protected; data seg
81 is contiguous with text */
82 #define COFF_NMAGIC 0410 /* text is write-protected; data starts
83 at next seg following text */
84 #define COFF_ZMAGIC 0000 /* text and data segs are aligned for
85 direct paging */
86 #define COFF_SMAGIC 0443 /* shared lib */
87
88 /*
89 * COFF section header
90 */
91
92 struct coff_scnhdr {
93 char s_name[8];
94 long s_paddr;
95 long s_vaddr;
96 long s_size;
97 long s_scnptr;
98 long s_relptr;
99 long s_lnnoptr;
100 u_short s_nreloc;
101 u_short s_nlnno;
102 long s_flags;
103 };
104
105 /* s_flags */
106 #define COFF_STYP_REG 0x00
107 #define COFF_STYP_DSECT 0x01
108 #define COFF_STYP_NOLOAD 0x02
109 #define COFF_STYP_GROUP 0x04
110 #define COFF_STYP_PAD 0x08
111 #define COFF_STYP_COPY 0x10
112 #define COFF_STYP_TEXT 0x20
113 #define COFF_STYP_DATA 0x40
114 #define COFF_STYP_BSS 0x80
115 #define COFF_STYP_INFO 0x200
116 #define COFF_STYP_OVER 0x400
117 #define COFF_STYP_SHLIB 0x800
118
119 /*
120 * COFF shared library header
121 */
122
123 struct coff_slhdr {
124 long entry_len; /* in words */
125 long path_index; /* in words */
126 char sl_name[1];
127 };
128
129 struct coff_exechdr {
130 struct coff_filehdr f;
131 struct coff_aouthdr a;
132 };
133
134 #define COFF_ROUND(val, by) (((val) + by - 1) & ~(by - 1))
135
136 #define COFF_ALIGN(a) ((a) & ~(COFF_LDPGSZ - 1))
137
138 #define COFF_HDR_SIZE \
139 (sizeof(struct coff_filehdr) + sizeof(struct coff_aouthdr))
140
141 #define COFF_BLOCK_ALIGN(ap, value) \
142 ((ap)->a_magic == COFF_ZMAGIC ? COFF_ROUND(value, COFF_LDPGSZ) : \
143 value)
144
145 #define COFF_TXTOFF(fp, ap) \
146 ((ap)->a_magic == COFF_ZMAGIC ? 0 : \
147 COFF_ROUND(COFF_HDR_SIZE + (fp)->f_nscns * \
148 sizeof(struct coff_scnhdr), \
149 COFF_SEGMENT_ALIGNMENT(fp, ap)))
150
151 #define COFF_DATOFF(fp, ap) \
152 (COFF_BLOCK_ALIGN(ap, COFF_TXTOFF(fp, ap) + (ap)->a_tsize))
153
154 #define COFF_SEGMENT_ALIGN(fp, ap, value) \
155 (COFF_ROUND(value, ((ap)->a_magic == COFF_ZMAGIC ? COFF_LDPGSZ : \
156 COFF_SEGMENT_ALIGNMENT(fp, ap))))
157
158 #define COFF_LDPGSZ 4096
159
160 #define COFF_SEGMENT_ALIGNMENT(fp, ap) \
161 (((fp)->f_flags & COFF_F_EXEC) == 0 ? 4 : 16)
162
163 #ifndef BYTE_ORDER
164 #error Define BYTE_ORDER!
165 #endif
166
167 #if BYTE_ORDER == BIG_ENDIAN
168 #define COFF_BADMAG(ex) ((ex)->f_magic != COFF_MAGIC_SH3_BIG)
169 #endif
170 #if BYTE_ORDER == LITTLE_ENDIAN
171 #define COFF_BADMAG(ex) ((ex)->f_magic != COFF_MAGIC_SH3_LITTLE)
172 #endif
173
174 #define IBCS2_HIGH_SYSCALL(n) (((n) & 0x7f) == 0x28)
175 #define IBCS2_CVT_HIGH_SYSCALL(n) (((n) >> 8) + 128)
176
177 #ifdef DEBUG_COFF
178 #define DPRINTF(a) printf a;
179 #else
180 #define DPRINTF(a)
181 #endif
182
183 #define COFF_ES_SYMNMLEN 8
184 #define COFF_ES_SYMENTSZ 18
185
186 struct external_syment {
187 union {
188 char e_name[COFF_ES_SYMNMLEN];
189 struct {
190 char e_zeroes[4];
191 char e_offset[4];
192 } e;
193 } e;
194 char e_value[4];
195 char e_scnum[2];
196 char e_type[2];
197 char e_sclass[1];
198 char e_numaux[1];
199 };
200
201 #endif /* !_SH3_COFF_MACHDEP_H_ */
202
203