annotate old-trunk/lwasm/old/output.c @ 377:55ed7d06b136

Fixed intersection internal references in object target
author lost@starbug
date Mon, 26 Apr 2010 18:37:06 -0600
parents eb230fa7d28e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 output.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 Contains the code for actually outputting the assembled code
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 //#include <ctype.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <errno.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 //#include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include <unistd.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #define __output_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 //#include "instab.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 #include "util.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 void write_code_raw(asmstate_t *as, FILE *of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 void write_code_decb(asmstate_t *as, FILE *of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 void write_code_rawrel(asmstate_t *as, FILE *of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 void write_code_obj(asmstate_t *as, FILE *of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 void write_code_os9(asmstate_t *as, FILE *of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 // this prevents warnings about not using the return value of fwrite()
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 #define writebytes(s, l, c, f) do { int r; r = fwrite((s), (l), (c), (f)); } while (0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 void lwasm_output(asmstate_t *as)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 FILE *of;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 if (as -> errorcount > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 fprintf(stderr, "Not doing output due to assembly errors.\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 of = fopen(as -> outfile, "wb");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 if (!of)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 fprintf(stderr, "Cannot open '%s' for output", as -> outfile);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 perror("");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 switch (as -> outformat)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 case OUTPUT_RAW:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 write_code_raw(as, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 case OUTPUT_DECB:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 write_code_decb(as, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 case OUTPUT_RAWREL:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 write_code_rawrel(as, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 case OUTPUT_OBJ:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 write_code_obj(as, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 case OUTPUT_OS9:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 write_code_os9(as, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 default:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 fprintf(stderr, "BUG: unrecognized output format when generating output file\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 fclose(of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 unlink(as -> outfile);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 fclose(of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 rawrel output treats an ORG directive as an offset from the start of the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 file. Undefined results will occur if an ORG directive moves the output
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 pointer backward. This particular implementation uses "fseek" to handle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 ORG requests and to skip over RMBs.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 This simple brain damanged method simply does an fseek before outputting
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 each instruction.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 void write_code_rawrel(asmstate_t *as, FILE *of)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 lwasm_line_t *cl;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 for (cl = as -> lineshead; cl; cl = cl -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 if (cl -> codelen == 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 fseek(of, cl -> codeaddr, SEEK_SET);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 writebytes(cl -> bytes, cl -> codelen, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 raw merely writes all the bytes directly to the file as is. ORG is just a
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 reference for the assembler to handle absolute references. Multiple ORG
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 statements will produce mostly useless results
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 void write_code_raw(asmstate_t *as, FILE *of)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 lwasm_line_t *cl;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 for (cl = as -> lineshead; cl; cl = cl -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 if (cl -> nocodelen)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 int i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 for (i = 0; i < cl -> nocodelen; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 writebytes("\0", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 writebytes(cl -> bytes, cl -> codelen, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 OS9 target also just writes all the bytes in order. No need for anything
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 else.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 void write_code_os9(asmstate_t *as, FILE *of)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 lwasm_line_t *cl;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 for (cl = as -> lineshead; cl; cl = cl -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 if (cl -> inmod == 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 if (cl -> nocodelen)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 int i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155 for (i = 0; i < cl -> nocodelen; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 writebytes("\0", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 writebytes(cl -> bytes, cl -> codelen, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 void write_code_decb(asmstate_t *as, FILE *of)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 long preambloc;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166 lwasm_line_t *cl;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 int blocklen = -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 int nextcalc = -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 unsigned char outbuf[5];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 for (cl = as -> lineshead; cl; cl = cl -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 if (cl -> nocodelen)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 if (cl -> codeaddr != nextcalc && cl -> codelen > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177 // need preamble here
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 if (blocklen > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180 // update previous preamble if needed
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 fseek(of, preambloc, SEEK_SET);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182 outbuf[0] = (blocklen >> 8) & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
183 outbuf[1] = blocklen & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 writebytes(outbuf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185 fseek(of, 0, SEEK_END);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187 blocklen = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
188 nextcalc = cl -> codeaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189 outbuf[0] = 0x00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190 outbuf[1] = 0x00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191 outbuf[2] = 0x00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 outbuf[3] = (nextcalc >> 8) & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193 outbuf[4] = nextcalc & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194 preambloc = ftell(of) + 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195 writebytes(outbuf, 5, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197 nextcalc += cl -> codelen;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
198 writebytes(cl -> bytes, cl -> codelen, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
199 blocklen += cl -> codelen;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
201 if (blocklen > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 fseek(of, preambloc, SEEK_SET);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
204 outbuf[0] = (blocklen >> 8) & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
205 outbuf[1] = blocklen & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206 writebytes(outbuf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207 fseek(of, 0, SEEK_END);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
209
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210 // now write postamble
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
211 outbuf[0] = 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
212 outbuf[1] = 0x00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
213 outbuf[2] = 0x00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214 outbuf[3] = (as -> execaddr >> 8) & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 outbuf[4] = (as -> execaddr) & 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 writebytes(outbuf, 5, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
217 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 void write_code_obj_sbadd(sectiontab_t *s, unsigned char b)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221 if (s -> oblen >= s -> obsize)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223 s -> obytes = lwasm_realloc(s -> obytes, s -> obsize + 128);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224 s -> obsize += 128;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
225 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226 s -> obytes[s -> oblen] = b;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227 s -> oblen += 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 void write_code_obj(asmstate_t *as, FILE *of)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 lwasm_line_t *l;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233 sectiontab_t *s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234 lwasm_symbol_ent_t *se;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
235 export_list_t *ex;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 section_reloc_list_t *re;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
237 lwasm_expr_stack_node_t *sn;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239 int i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
240 unsigned char buf[16];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
241
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242 // output the magic number and file header
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
243 // the 8 is NOT an error
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
244 writebytes("LWOBJ16", 8, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
245
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
246 // run through the entire system and build the byte streams for each
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
247 // section; at the same time, generate a list of "local" symbols to
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
248 // output for each section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
249 // NOTE: for "local" symbols, we will append \x01 and the ascii string
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
250 // of the context identifier (so sym in context 1 would be "sym\x011"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
251 // we can do this because the linker can handle symbols with any
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
252 // character other than NUL.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
253 // also we will generate a list of incomplete references for each
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
254 // section along with the actual definition that will be output
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
255
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
256 // once all this information is generated, we will output each section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
257 // to the file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
258
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
259 // NOTE: we build everything in memory then output it because the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
260 // assembler accepts multiple instances of the same section but the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
261 // linker expects only one instance of each section in the object file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
262 // so we need to collect all the various pieces of a section together
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
263 // (also, the assembler treated multiple instances of the same section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
264 // as continuations of previous sections so we would need to collect
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
265 // them together anyway.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
266
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
267 for (l = as -> lineshead; l; l = l -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
268 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
269 if (l -> sect)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
270 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
271 // we're in a section - need to output some bytes
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
272 for (i = 0; i < l -> codelen; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
273 write_code_obj_sbadd(l -> sect, l -> bytes[i]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
274 for (i = 0; i < l -> nocodelen; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
275 write_code_obj_sbadd(l -> sect, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
276
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
277 // do we have a "relocation"? If so, add a reference to the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
278 // relocation table
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
279 if (l -> relocoff >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
280 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
281 // build the relocation reference for the linker
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
282 re = lwasm_alloc(sizeof(section_reloc_list_t));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
283 re -> next = l -> sect -> rl;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
284 l -> sect -> rl = re;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
285
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
286 re -> offset = l -> codeaddr + l -> relocoff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
287 re -> expr = l -> exprs[0];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
288 re -> context = l -> context;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
289 re -> relocsize = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
290 if (l -> reloc8bit)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
291 re -> relocsize = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
292 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
293 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
294 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
295
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
296 // run through the sections
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
297 for (s = as -> sections; s; s = s -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
298 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
299 // write the name
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
300 writebytes(s -> name, strlen(s -> name) + 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
301
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
302 // write the flags
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
303 if (s -> flags & SECTION_BSS)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
304 writebytes("\x01", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
305
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
306 // indicate end of flags - the "" is NOT an error
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
307 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
308
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
309
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
310 // now the local symbols
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
311 for (se = as -> symhead; se; se = se -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
312 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
313 // ignore symbols not in this section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
314 if (se -> sect != s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
315 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
316
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
317 if (se -> flags & SYMBOL_SET)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
318 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
319
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
320 if (se -> flags & SYMBOL_EXTERN)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
321 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
322
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
323 writebytes(se -> sym, strlen(se -> sym), 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
324 if (se -> context >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
325 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
326 writebytes("\x01", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
327 sprintf(buf, "%d", se -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
328 writebytes(buf, strlen(buf), 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
329 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
330 // the "" is NOT an error
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
331 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
332
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
333 // write the address
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
334 buf[0] = (se -> value >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
335 buf[1] = se -> value & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
336 writebytes(buf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
337 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
338 // flag end of local symbol table - "" is NOT an error
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
339 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
340
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
341 // now the exports
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
342 for (ex = s -> exports; ex; ex = ex -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
343 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
344 writebytes(ex -> sym, strlen(ex -> sym) + 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
345 buf[0] = (ex -> offset >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
346 buf[1] = ex -> offset & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
347 writebytes(buf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
348 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
349
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
350 // flag end of exported symbols - "" is NOT an error
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
351 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
352
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
353 // now output the "incomplete references"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
354 // this being the most complex bit
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
355 for (re = s -> rl; re; re = re -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
356 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
357 if (re -> expr == NULL)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
358 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
359 // this is an error but we'll simply ignore it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
360 // and not output this expression
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
361 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
362 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
363
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
364 // work through each term in the expression and output
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
365 // the proper equivalent to the object file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
366 if (re -> relocsize == 1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
367 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
368 // flag an 8 bit relocation (low 8 bits will be used)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
369 buf[0] = 0xFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
370 buf[1] = 0x01;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
371 writebytes(buf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
372 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
373 for (sn = re -> expr -> head; sn; sn = sn -> next)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
374 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
375 switch (sn -> term -> term_type)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
376 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
377 case LWASM_TERM_OPER:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
378 buf[0] = 0x04;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
379 buf[1] = sn -> term -> value;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
380 writebytes(buf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
381 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
382
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
383 case LWASM_TERM_INT:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
384 buf[0] = 0x01;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
385 buf[1] = (sn -> term -> value >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
386 buf[2] = sn -> term -> value & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
387 writebytes(buf, 3, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
388 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
389
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
390 case LWASM_TERM_SECBASE:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
391 writebytes("\x05", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
392 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
393
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
394 case LWASM_TERM_SYM:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
395 // now for the ugly part - resolve a symbol reference
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
396 // and determine whether it's internal, external, or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
397 // a section base
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
398 se = lwasm_find_symbol(as, sn -> term -> symbol, re -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
399 if (!se)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
400 se = lwasm_find_symbol(as, sn -> term -> symbol, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
401 if (!se || se -> flags & SYMBOL_EXTERN)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
402 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
403 // not found - assume external reference
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
404 // found but flagged external - handle it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
405 writebytes("\x02", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
406 writebytes(se -> sym, strlen(se -> sym) + 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
407 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
408 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
409 // a local symbol reference here
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
410 writebytes("\x03", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
411 writebytes(se -> sym, strlen(se -> sym), 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
412 if (se -> context >= 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
413 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
414 writebytes("\x01", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
415 sprintf(buf, "%d", se -> context);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
416 writebytes(buf, strlen(buf), 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
417 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
418 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
419 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
420
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
421 default:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
422 // unrecognized term type - replace with integer 0
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
423 buf[0] = 0x01;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
424 buf[1] = 0x00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
425 buf[2] = 0x00;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
426 writebytes(buf, 3, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
427 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
428 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
429 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
430
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
431 // flag end of expressions
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
432 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
433
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
434 // write the offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
435 buf[0] = (re -> offset >> 8) & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
436 buf[1] = re -> offset & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
437 writebytes(buf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
438 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
439 // flag end of incomplete references list
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
440 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
441
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
442 // now blast out the code
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
443
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
444 // length
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
445 buf[0] = s -> oblen >> 8 & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
446 buf[1] = s -> oblen & 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
447 writebytes(buf, 2, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
448
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
449 if (!(s -> flags & SECTION_BSS))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
450 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
451 writebytes(s -> obytes, s -> oblen, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
452 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
453 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
454
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
455 // flag no more sections
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
456 // the "" is NOT an error
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
457 writebytes("", 1, 1, of);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
458 }