pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / aal / rd.c
blob2618750de72d10cfd7ad2f69a03ce1e132a4fc27
1 /* $Header$ */
2 /*
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 */
6 #include <out.h>
7 #include "object.h"
9 extern long lseek();
12 * Parts of the output file.
14 #undef PARTEMIT
15 #undef PARTRELO
16 #undef PARTNAME
17 #undef PARTCHAR
18 #undef PARTDBUG
19 #undef NPARTS
21 #define PARTEMIT 0
22 #define PARTRELO 1
23 #define PARTNAME 2
24 #define PARTCHAR 3
25 #ifdef SYMDBUG
26 #define PARTDBUG 4
27 #else
28 #define PARTDBUG 3
29 #endif
30 #define NPARTS (PARTDBUG + 1)
32 static long offset[MAXSECT];
34 static int outfile;
35 static long outseek[NPARTS];
36 static long currpos;
37 static long rd_base;
38 #define OUTSECT(i) \
39 (outseek[PARTEMIT] = offset[i])
40 #define BEGINSEEK(p, o) \
41 (outseek[(p)] = (o))
43 static int sectionnr;
45 static
46 OUTREAD(p, b, n)
47 char *b;
48 long n;
50 register long l = outseek[p];
52 if (currpos != l) {
53 lseek(outfile, l, 0);
55 rd_bytes(outfile, b, n);
56 l += n;
57 currpos = l;
58 outseek[p] = l;
62 * Open the output file according to the chosen strategy.
64 int
65 rd_open(f)
66 char *f;
69 if ((outfile = open(f, 0)) < 0)
70 return 0;
71 return rd_fdopen(outfile);
74 static int offcnt;
76 rd_fdopen(fd)
78 register int i;
80 for (i = 0; i < NPARTS; i++) outseek[i] = 0;
81 offcnt = 0;
82 rd_base = lseek(fd, 0L, 1);
83 if (rd_base < 0) {
84 return 0;
86 currpos = rd_base;
87 outseek[PARTEMIT] = currpos;
88 outfile = fd;
89 sectionnr = 0;
90 return 1;
93 rd_close()
96 close(outfile);
97 outfile = -1;
100 rd_fd()
102 return outfile;
105 rd_ohead(head)
106 register struct outhead *head;
108 register long off;
110 OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD);
111 #if ! (BYTES_REVERSED || WORDS_REVERSED)
112 if (sizeof(struct outhead) != SZ_HEAD)
113 #endif
115 register char *c = (char *) head + (SZ_HEAD-4);
117 head->oh_nchar = get4(c);
118 c -= 4; head->oh_nemit = get4(c);
119 c -= 2; head->oh_nname = uget2(c);
120 c -= 2; head->oh_nrelo = uget2(c);
121 c -= 2; head->oh_nsect = uget2(c);
122 c -= 2; head->oh_flags = uget2(c);
123 c -= 2; head->oh_stamp = uget2(c);
124 c -= 2; head->oh_magic = uget2(c);
126 off = OFF_RELO(*head) + rd_base;
127 BEGINSEEK(PARTRELO, off);
128 off += (long) head->oh_nrelo * SZ_RELO;
129 BEGINSEEK(PARTNAME, off);
130 off += (long) head->oh_nname * SZ_NAME;
131 BEGINSEEK(PARTCHAR, off);
132 #ifdef SYMDBUG
133 off += head->oh_nchar;
134 BEGINSEEK(PARTDBUG, off);
135 #endif
138 rd_rew_relos(head)
139 register struct outhead *head;
141 register long off = OFF_RELO(*head) + rd_base;
143 BEGINSEEK(PARTRELO, off);
146 rd_sect(sect, cnt)
147 register struct outsect *sect;
148 register unsigned int cnt;
150 register char *c = (char *) sect + cnt * SZ_SECT;
152 OUTREAD(PARTEMIT, (char *) sect, (long)cnt * SZ_SECT);
153 sect += cnt;
154 offcnt += cnt;
155 while (cnt--) {
156 sect--;
157 #if ! (BYTES_REVERSED || WORDS_REVERSED)
158 if (sizeof(struct outsect) != SZ_SECT)
159 #endif
161 c -= 4; sect->os_lign = get4(c);
162 c -= 4; sect->os_flen = get4(c);
163 c -= 4; sect->os_foff = get4(c);
165 offset[--offcnt] = sect->os_foff + rd_base;
166 #if ! (BYTES_REVERSED || WORDS_REVERSED)
167 if (sizeof(struct outsect) != SZ_SECT)
168 #endif
170 c -= 4; sect->os_size = get4(c);
171 c -= 4; sect->os_base = get4(c);
176 rd_outsect(s)
178 OUTSECT(s);
179 sectionnr = s;
183 * We don't have to worry about byte order here.
185 rd_emit(emit, cnt)
186 char *emit;
187 long cnt;
189 OUTREAD(PARTEMIT, emit, cnt);
190 offset[sectionnr] += cnt;
193 rd_relo(relo, cnt)
194 register struct outrelo *relo;
195 register unsigned int cnt;
198 OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO);
199 #if ! (BYTES_REVERSED || WORDS_REVERSED)
200 if (sizeof(struct outrelo) != SZ_RELO)
201 #endif
203 register char *c = (char *) relo + (long) cnt * SZ_RELO;
205 relo += cnt;
206 while (cnt--) {
207 relo--;
208 c -= 4; relo->or_addr = get4(c);
209 c -= 2; relo->or_nami = uget2(c);
210 relo->or_sect = *--c;
211 relo->or_type = *--c;
216 rd_name(name, cnt)
217 register struct outname *name;
218 register unsigned int cnt;
221 OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME);
222 #if ! (BYTES_REVERSED || WORDS_REVERSED)
223 if (sizeof(struct outname) != SZ_NAME)
224 #endif
226 register char *c = (char *) name + (long) cnt * SZ_NAME;
228 name += cnt;
229 while (cnt--) {
230 name--;
231 c -= 4; name->on_valu = get4(c);
232 c -= 2; name->on_desc = uget2(c);
233 c -= 2; name->on_type = uget2(c);
234 c -= 4; name->on_foff = get4(c);
239 rd_string(addr, len)
240 char *addr;
241 long len;
244 OUTREAD(PARTCHAR, addr, len);
247 #ifdef SYMDBUG
248 rd_dbug(buf, size)
249 char *buf;
250 long size;
252 OUTREAD(PARTDBUG, buf, size);
254 #endif