Mercurial > hg > index.cgi
annotate lwasm/output.c @ 406:4411a6123716
Add "basic" output format
Add "basic" output format. This outputs the code in the form of a Basic
program that installs the assembled output. If an execution address is
provided to the END pseudo operation, it will transfer control there using
the Basic EXEC command.
Thanks to Tim Lindner <tlindner@macmess.org> for the original patch. I used
it mostly as is except for a couple of minor fixes for coding style and
removing a variable declaration from inside a for() statement for
portability reasons.
author | William Astle <lost@l-w.ca> |
---|---|
date | Thu, 03 Mar 2016 21:04:39 -0700 |
parents | ade217fd76a5 |
children | 7f538053492c |
rev | line source |
---|---|
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
2 output.c |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
3 Copyright © 2009, 2010 William Astle |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
4 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
5 This file is part of LWASM. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
6 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
7 LWASM is free software: you can redistribute it and/or modify it under the |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
10 version. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
11 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
15 more details. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
16 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
19 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
20 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
21 Contains the code for actually outputting the assembled code |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
22 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
23 #include <errno.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
24 #include <stdio.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
25 #include <string.h> |
360
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
26 |
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
27 #ifndef _MSC_VER |
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
28 #include <unistd.h> // for unlink |
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
29 #endif |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
30 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
31 #include <lw_alloc.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
32 #include <lw_expr.h> |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
33 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
34 #include "lwasm.h" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
35 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
36 void write_code_raw(asmstate_t *as, FILE *of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
37 void write_code_decb(asmstate_t *as, FILE *of); |
406 | 38 void write_code_BASIC(asmstate_t *as, FILE *of); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
39 void write_code_rawrel(asmstate_t *as, FILE *of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
40 void write_code_obj(asmstate_t *as, FILE *of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
41 void write_code_os9(asmstate_t *as, FILE *of); |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
42 void write_code_hex(asmstate_t *as, FILE *of); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
43 void write_code_srec(asmstate_t *as, FILE *of); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
44 void write_code_ihex(asmstate_t *as, FILE *of); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
45 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
46 // this prevents warnings about not using the return value of fwrite() |
221 | 47 // r++ prevents the "set but not used" warnings; should be optimized out |
48 #define writebytes(s, l, c, f) do { int r; r = fwrite((s), (l), (c), (f)); r++; } while (0) | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
49 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
50 void do_output(asmstate_t *as) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
51 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
52 FILE *of; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
53 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
54 if (as -> errorcount > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
55 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
56 fprintf(stderr, "Not doing output due to assembly errors.\n"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
57 return; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
58 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
59 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
60 of = fopen(as -> output_file, "wb"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
61 if (!of) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
62 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
63 fprintf(stderr, "Cannot open '%s' for output", as -> output_file); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
64 perror(""); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
65 return; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
66 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
67 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
68 switch (as -> output_format) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
69 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
70 case OUTPUT_RAW: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
71 write_code_raw(as, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
72 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
73 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
74 case OUTPUT_DECB: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
75 write_code_decb(as, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
76 break; |
406 | 77 |
78 case OUTPUT_BASIC: | |
79 write_code_BASIC(as, of); | |
80 break; | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
81 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
82 case OUTPUT_RAWREL: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
83 write_code_rawrel(as, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
84 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
85 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
86 case OUTPUT_OBJ: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
87 write_code_obj(as, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
88 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
89 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
90 case OUTPUT_OS9: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
91 write_code_os9(as, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
92 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
93 |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
94 case OUTPUT_HEX: |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
95 write_code_hex(as, of); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
96 break; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
97 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
98 case OUTPUT_SREC: |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
99 write_code_srec(as, of); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
100 break; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
101 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
102 case OUTPUT_IHEX: |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
103 write_code_ihex(as, of); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
104 break; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
105 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
106 default: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
107 fprintf(stderr, "BUG: unrecognized output format when generating output file\n"); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
108 fclose(of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
109 unlink(as -> output_file); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
110 return; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
111 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
112 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
113 fclose(of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
114 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
115 |
406 | 116 int write_code_BASIC_fprintf(FILE *of, int linelength, int *linenumber, int value) |
117 { | |
118 if (linelength > 247) | |
119 { | |
120 fprintf(of, "\n"); | |
121 linelength = fprintf(of, "%d DATA ", *linenumber); | |
122 *linenumber += 10; | |
123 } | |
124 else | |
125 { | |
126 linelength += fprintf(of, ","); | |
127 } | |
128 linelength += fprintf(of, "%d", value); | |
129 | |
130 return linelength; | |
131 } | |
132 | |
133 void write_code_BASIC(asmstate_t *as, FILE *of) | |
134 { | |
135 line_t *cl; | |
136 line_t *startblock = as -> line_head; | |
137 line_t *endblock; | |
138 int linenumber, linelength, startaddress, lastaddress, address; | |
139 int outidx; | |
140 | |
141 fprintf(of, "10 READ A,B\n"); | |
142 fprintf(of, "20 IF A=-1 THEN 70\n"); | |
143 fprintf(of, "30 FOR C = A TO B\n"); | |
144 fprintf(of, "40 READ D:POKE C,D\n"); | |
145 fprintf(of, "50 NEXT C\n"); | |
146 fprintf(of, "60 GOTO 10\n"); | |
147 | |
148 if (as -> execaddr == 0) | |
149 { | |
150 fprintf(of, "70 END"); | |
151 } | |
152 else | |
153 { | |
154 fprintf(of, "70 EXEC %d", as -> execaddr); | |
155 } | |
156 | |
157 linenumber = 80; | |
158 linelength = 255; | |
159 | |
160 while(startblock) | |
161 { | |
162 startaddress = -1; | |
163 endblock = NULL; | |
164 | |
165 for (cl = startblock; cl; cl = cl -> next) | |
166 { | |
167 if (cl -> outputl < 0) | |
168 continue; | |
169 | |
170 address = lw_expr_intval(cl -> addr); | |
171 | |
172 if (startaddress == -1) | |
173 { | |
174 startaddress = address; | |
175 lastaddress = address + cl -> outputl - 1; | |
176 } | |
177 else | |
178 { | |
179 if (lastaddress != address - 1) | |
180 { | |
181 endblock = cl; | |
182 break; | |
183 } | |
184 | |
185 lastaddress += cl -> outputl; | |
186 } | |
187 } | |
188 | |
189 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, startaddress); | |
190 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, lastaddress); | |
191 | |
192 for (cl = startblock; cl != endblock; cl = cl -> next) | |
193 { | |
194 if (cl -> outputl < 0) | |
195 continue; | |
196 | |
197 for (outidx=0; outidx<cl -> outputl; outidx++) | |
198 { | |
199 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, cl -> output[outidx]); | |
200 } | |
201 } | |
202 | |
203 startblock = cl; | |
204 } | |
205 | |
206 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, -1); | |
207 linelength = write_code_BASIC_fprintf(of, linelength, &linenumber, -1); | |
208 | |
209 fprintf(of, "\n"); | |
210 } | |
211 | |
212 | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
213 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
214 rawrel output treats an ORG directive as an offset from the start of the |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
215 file. Undefined results will occur if an ORG directive moves the output |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
216 pointer backward. This particular implementation uses "fseek" to handle |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
217 ORG requests and to skip over RMBs. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
218 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
219 This simple brain damanged method simply does an fseek before outputting |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
220 each instruction. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
221 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
222 void write_code_rawrel(asmstate_t *as, FILE *of) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
223 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
224 line_t *cl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
225 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
226 for (cl = as -> line_head; cl; cl = cl -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
227 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
228 if (cl -> outputl <= 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
229 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
230 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
231 fseek(of, lw_expr_intval(cl -> addr), SEEK_SET); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
232 writebytes(cl -> output, cl -> outputl, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
233 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
234 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
235 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
236 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
237 raw merely writes all the bytes directly to the file as is. ORG is just a |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
238 reference for the assembler to handle absolute references. Multiple ORG |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
239 statements will produce mostly useless results |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
240 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
241 void write_code_raw(asmstate_t *as, FILE *of) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
242 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
243 line_t *cl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
244 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
245 for (cl = as -> line_head; cl; cl = cl -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
246 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
247 if (cl -> len > 0 && cl -> outputl == 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
248 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
249 int i; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
250 for (i = 0; i < cl -> len; i++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
251 writebytes("\0", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
252 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
253 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
254 else if (cl -> outputl > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
255 writebytes(cl -> output, cl -> outputl, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
256 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
257 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
258 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
259 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
260 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
261 OS9 target also just writes all the bytes in order. No need for anything |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
262 else. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
263 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
264 void write_code_os9(asmstate_t *as, FILE *of) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
265 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
266 line_t *cl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
267 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
268 for (cl = as -> line_head; cl; cl = cl -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
269 { |
127
d92b9c968731
Removed protection from outputting code outside os9 module in os9 target
lost@l-w.ca
parents:
12
diff
changeset
|
270 // if (cl -> inmod == 0) |
d92b9c968731
Removed protection from outputting code outside os9 module in os9 target
lost@l-w.ca
parents:
12
diff
changeset
|
271 // continue; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
272 if (cl -> len > 0 && cl -> outputl == 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
273 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
274 int i; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
275 for (i = 0; i < cl -> len; i++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
276 writebytes("\0", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
277 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
278 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
279 else if (cl -> outputl > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
280 writebytes(cl -> output, cl -> outputl, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
281 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
282 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
283 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
284 void write_code_decb(asmstate_t *as, FILE *of) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
285 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
286 long preambloc; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
287 line_t *cl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
288 int blocklen = -1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
289 int nextcalc = -1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
290 unsigned char outbuf[5]; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
291 int caddr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
292 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
293 for (cl = as -> line_head; cl; cl = cl -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
294 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
295 if (cl -> outputl < 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
296 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
297 caddr = lw_expr_intval(cl -> addr); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
298 if (caddr != nextcalc && cl -> outputl > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
299 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
300 // need preamble here |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
301 if (blocklen > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
302 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
303 // update previous preamble if needed |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
304 fseek(of, preambloc, SEEK_SET); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
305 outbuf[0] = (blocklen >> 8) & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
306 outbuf[1] = blocklen & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
307 writebytes(outbuf, 2, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
308 fseek(of, 0, SEEK_END); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
309 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
310 blocklen = 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
311 nextcalc = caddr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
312 outbuf[0] = 0x00; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
313 outbuf[1] = 0x00; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
314 outbuf[2] = 0x00; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
315 outbuf[3] = (nextcalc >> 8) & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
316 outbuf[4] = nextcalc & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
317 preambloc = ftell(of) + 1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
318 writebytes(outbuf, 5, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
319 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
320 nextcalc += cl -> outputl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
321 writebytes(cl -> output, cl -> outputl, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
322 blocklen += cl -> outputl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
323 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
324 if (blocklen > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
325 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
326 fseek(of, preambloc, SEEK_SET); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
327 outbuf[0] = (blocklen >> 8) & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
328 outbuf[1] = blocklen & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
329 writebytes(outbuf, 2, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
330 fseek(of, 0, SEEK_END); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
331 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
332 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
333 // now write postamble |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
334 outbuf[0] = 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
335 outbuf[1] = 0x00; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
336 outbuf[2] = 0x00; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
337 outbuf[3] = (as -> execaddr >> 8) & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
338 outbuf[4] = (as -> execaddr) & 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
339 writebytes(outbuf, 5, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
340 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
341 |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
342 int fetch_output_byte(line_t *cl, char *value, int *addr) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
343 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
344 static int outidx = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
345 static int lastaddr = -2; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
346 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
347 // try to read next byte in current line's output field |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
348 if ((cl -> outputl > 0) && (outidx < cl -> outputl)) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
349 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
350 *addr = lw_expr_intval(cl -> addr) + outidx; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
351 *value = *(cl -> output + outidx++); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
352 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
353 // this byte follows the previous byte (contiguous, rc = 1) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
354 if (*addr == lastaddr + 1) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
355 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
356 lastaddr = *addr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
357 return 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
358 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
359 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
360 // this byte does not follow prev byte (disjoint, rc = -1) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
361 else |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
362 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
363 lastaddr = *addr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
364 return -1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
365 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
366 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
367 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
368 // no (more) output from this line (rc = 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
369 else |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
370 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
371 outidx = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
372 return 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
373 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
374 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
375 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
376 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
377 /* a simple ASCII hex file format */ |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
378 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
379 void write_code_hex(asmstate_t *as, FILE *of) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
380 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
381 const int RECLEN = 16; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
382 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
383 line_t *cl; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
384 char outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
385 int outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
386 int rc; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
387 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
388 for (cl = as -> line_head; cl; cl = cl -> next) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
389 do |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
390 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
391 rc = fetch_output_byte(cl, &outbyte, &outaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
392 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
393 // if address jump or xxx0 address, start new line |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
394 if ((rc == -1) || ((rc == 1) && (outaddr % RECLEN == 0))) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
395 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
396 fprintf(of, "\r\n%04X:", (unsigned int)outaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
397 fprintf(of, "%02X", (unsigned char)outbyte); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
398 rc = -1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
399 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
400 if (rc == 1) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
401 fprintf(of, ",%02X", (unsigned char)outbyte); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
402 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
403 while (rc); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
404 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
405 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
406 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
407 /* Motorola S19 hex file format */ |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
408 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
409 void write_code_srec(asmstate_t *as, FILE *of) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
410 { |
360
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
411 #define SRECLEN 16 |
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
412 #define HDRLEN 51 |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
413 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
414 line_t *cl; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
415 char outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
416 int outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
417 int rc; |
360
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
418 unsigned int i; |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
419 int recaddr = 0; |
360
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
420 unsigned int recdlen = 0; |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
421 unsigned char recdata[SRECLEN]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
422 int recsum; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
423 int reccnt = -1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
424 char rechdr[HDRLEN]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
425 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
426 for (cl = as -> line_head; cl; cl = cl -> next) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
427 do |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
428 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
429 rc = fetch_output_byte(cl, &outbyte, &outaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
430 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
431 // if address jump or xxx0 address, start new S1 record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
432 if ((rc == -1) || ((rc == 1) && (outaddr % SRECLEN == 0))) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
433 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
434 // if not already done so, emit an S0 header record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
435 if (reccnt < 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
436 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
437 // build header from version and filespec |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
438 // e.g. "[lwtools X.Y] filename.asm" |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
439 strcpy(rechdr, "["); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
440 strcat(rechdr, PACKAGE_STRING); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
441 strcat(rechdr, "] "); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
442 i = strlen(rechdr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
443 strncat(rechdr, cl -> linespec, HDRLEN - 1 - i); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
444 recsum = strlen(rechdr) + 3; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
445 fprintf(of, "S0%02X0000", recsum); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
446 for (i = 0; i < strlen(rechdr); i++) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
447 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
448 fprintf(of, "%02X", (unsigned char)rechdr[i]); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
449 recsum += (unsigned char)rechdr[i]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
450 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
451 fprintf(of, "%02X\r\n", (unsigned char)(~recsum)); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
452 reccnt = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
453 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
454 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
455 // flush any current S1 record before starting new one |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
456 if (recdlen > 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
457 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
458 recsum = recdlen + 3; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
459 fprintf(of, "S1%02X%04X", recdlen + 3, recaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
460 for (i = 0; i < recdlen; i++) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
461 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
462 fprintf(of, "%02X", (unsigned char)recdata[i]); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
463 recsum += (unsigned char)recdata[i]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
464 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
465 recsum += (recaddr >> 8) & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
466 recsum += recaddr & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
467 fprintf(of, "%02X\r\n", (unsigned char)(~recsum)); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
468 reccnt += 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
469 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
470 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
471 // now start the new S1 record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
472 recdlen = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
473 recaddr = outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
474 rc = 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
475 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
476 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
477 // for each new byte read, add to recdata[] |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
478 if (rc == 1) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
479 recdata[recdlen++] = outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
480 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
481 while (rc); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
482 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
483 // done with all output lines, flush the final S1 record (if any) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
484 if (recdlen > 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
485 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
486 recsum = recdlen + 3; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
487 fprintf(of, "S1%02X%04X", recdlen + 3, recaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
488 for (i = 0; i < recdlen; i++) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
489 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
490 fprintf(of, "%02X", (unsigned char)recdata[i]); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
491 recsum += (unsigned char)recdata[i]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
492 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
493 recsum += (recaddr >> 8) & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
494 recsum += recaddr & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
495 fprintf(of, "%02X\r\n", (unsigned char)(~recsum)); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
496 reccnt += 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
497 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
498 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
499 // if any S1 records were output, close with S5 and S9 records |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
500 if (reccnt > 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
501 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
502 // emit S5 count record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
503 recsum = 3; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
504 recsum += (reccnt >> 8) & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
505 recsum += reccnt & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
506 fprintf(of, "S503%04X", (unsigned int)reccnt); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
507 fprintf(of, "%02X\r\n", (unsigned char)(~recsum)); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
508 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
509 // emit S9 end-of-file record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
510 recsum = 3; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
511 recsum += (as -> execaddr >> 8) & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
512 recsum += (as -> execaddr) & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
513 fprintf(of, "S903%04X", as -> execaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
514 fprintf(of, "%02X\r\n", (unsigned char)(~recsum)); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
515 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
516 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
517 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
518 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
519 /* Intel hex file format */ |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
520 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
521 void write_code_ihex(asmstate_t *as, FILE *of) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
522 { |
360
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
523 #define IRECLEN 16 |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
524 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
525 line_t *cl; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
526 char outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
527 int outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
528 int rc; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
529 int i; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
530 int recaddr = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
531 int recdlen = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
532 unsigned char recdata[IRECLEN]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
533 int recsum; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
534 int reccnt = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
535 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
536 for (cl = as -> line_head; cl; cl = cl -> next) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
537 do |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
538 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
539 rc = fetch_output_byte(cl, &outbyte, &outaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
540 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
541 // if address jump or xxx0 address, start new ihx record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
542 if ((rc == -1) || ((rc == 1) && (outaddr % IRECLEN == 0))) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
543 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
544 // flush any current ihex record before starting new one |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
545 if (recdlen > 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
546 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
547 recsum = recdlen; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
548 fprintf(of, ":%02X%04X00", recdlen, recaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
549 for (i = 0; i < recdlen; i++) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
550 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
551 fprintf(of, "%02X", (unsigned char)recdata[i]); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
552 recsum += (unsigned char)recdata[i]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
553 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
554 recsum += (recaddr >> 8) & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
555 recsum += recaddr & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
556 fprintf(of, "%02X\r\n", (unsigned char)(256 - recsum)); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
557 reccnt += 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
558 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
559 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
560 // now start the new ihex record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
561 recdlen = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
562 recaddr = outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
563 rc = 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
564 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
565 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
566 // for each new byte read, add to recdata[] |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
567 if (rc == 1) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
568 recdata[recdlen++] = outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
569 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
570 while (rc); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
571 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
572 // done with all output lines, flush the final ihex record (if any) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
573 if (recdlen > 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
574 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
575 recsum = recdlen; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
576 fprintf(of, ":%02X%04X00", recdlen, recaddr); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
577 for (i = 0; i < recdlen; i++) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
578 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
579 fprintf(of, "%02X", (unsigned char)recdata[i]); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
580 recsum += (unsigned char)recdata[i]; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
581 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
582 recsum += (recaddr >> 8) & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
583 recsum += recaddr & 0xFF; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
584 fprintf(of, "%02X\r\n", (unsigned char)(256 - recsum)); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
585 reccnt += 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
586 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
587 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
588 // if any ihex records were output, close with a "01" record |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
589 if (reccnt > 0) |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
590 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
591 fprintf(of, ":00000001FF"); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
592 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
593 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
594 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
595 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
596 void write_code_obj_sbadd(sectiontab_t *s, unsigned char b) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
597 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
598 if (s -> oblen >= s -> obsize) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
599 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
600 s -> obytes = lw_realloc(s -> obytes, s -> obsize + 128); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
601 s -> obsize += 128; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
602 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
603 s -> obytes[s -> oblen] = b; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
604 s -> oblen += 1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
605 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
606 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
607 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
608 int write_code_obj_expraux(lw_expr_t e, void *of) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
609 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
610 int tt; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
611 int v; |
12
6b9991fb39b6
Brought forward patch to fix bug with complex external references generating invalid relocations in the object file
lost@l-w.ca
parents:
2
diff
changeset
|
612 int count = 1; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
613 unsigned char buf[16]; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
614 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
615 tt = lw_expr_type(e); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
616 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
617 switch (tt) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
618 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
619 case lw_expr_type_oper: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
620 buf[0] = 0x04; |
12
6b9991fb39b6
Brought forward patch to fix bug with complex external references generating invalid relocations in the object file
lost@l-w.ca
parents:
2
diff
changeset
|
621 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
622 switch (lw_expr_whichop(e)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
623 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
624 case lw_expr_oper_plus: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
625 buf[1] = 0x01; |
12
6b9991fb39b6
Brought forward patch to fix bug with complex external references generating invalid relocations in the object file
lost@l-w.ca
parents:
2
diff
changeset
|
626 count = lw_expr_operandcount(e) - 1; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
627 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
628 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
629 case lw_expr_oper_minus: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
630 buf[1] = 0x02; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
631 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
632 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
633 case lw_expr_oper_times: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
634 buf[1] = 0x03; |
12
6b9991fb39b6
Brought forward patch to fix bug with complex external references generating invalid relocations in the object file
lost@l-w.ca
parents:
2
diff
changeset
|
635 count = lw_expr_operandcount(e) - 1; |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
636 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
637 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
638 case lw_expr_oper_divide: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
639 buf[1] = 0x04; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
640 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
641 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
642 case lw_expr_oper_mod: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
643 buf[1] = 0x05; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
644 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
645 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
646 case lw_expr_oper_intdiv: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
647 buf[1] = 0x06; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
648 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
649 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
650 case lw_expr_oper_bwand: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
651 buf[1] = 0x07; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
652 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
653 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
654 case lw_expr_oper_bwor: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
655 buf[1] = 0x08; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
656 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
657 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
658 case lw_expr_oper_bwxor: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
659 buf[1] = 0x09; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
660 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
661 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
662 case lw_expr_oper_and: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
663 buf[1] = 0x0A; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
664 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
665 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
666 case lw_expr_oper_or: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
667 buf[1] = 0x0B; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
668 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
669 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
670 case lw_expr_oper_neg: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
671 buf[1] = 0x0C; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
672 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
673 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
674 case lw_expr_oper_com: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
675 buf[1] = 0x0D; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
676 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
677 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
678 default: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
679 buf[1] = 0xff; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
680 } |
12
6b9991fb39b6
Brought forward patch to fix bug with complex external references generating invalid relocations in the object file
lost@l-w.ca
parents:
2
diff
changeset
|
681 while (count--) |
6b9991fb39b6
Brought forward patch to fix bug with complex external references generating invalid relocations in the object file
lost@l-w.ca
parents:
2
diff
changeset
|
682 writebytes(buf, 2, 1, of); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
683 return 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
684 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
685 case lw_expr_type_int: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
686 v = lw_expr_intval(e); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
687 buf[0] = 0x01; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
688 buf[1] = (v >> 8) & 0xff; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
689 buf[2] = v & 0xff; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
690 writebytes(buf, 3, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
691 return 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
692 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
693 case lw_expr_type_special: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
694 v = lw_expr_specint(e); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
695 switch (v) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
696 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
697 case lwasm_expr_secbase: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
698 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
699 // replaced with a synthetic symbol |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
700 sectiontab_t *se; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
701 se = lw_expr_specptr(e); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
702 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
703 writebytes("\x03\x02", 2, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
704 writebytes(se -> name, strlen(se -> name) + 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
705 return 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
706 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
707 case lwasm_expr_import: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
708 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
709 importlist_t *ie; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
710 ie = lw_expr_specptr(e); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
711 buf[0] = 0x02; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
712 writebytes(buf, 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
713 writebytes(ie -> symbol, strlen(ie -> symbol) + 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
714 return 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
715 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
716 case lwasm_expr_syment: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
717 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
718 struct symtabe *se; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
719 se = lw_expr_specptr(e); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
720 buf[0] = 0x03; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
721 writebytes(buf, 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
722 writebytes(se -> symbol, strlen(se -> symbol), 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
723 if (se -> context != -1) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
724 { |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
725 sprintf((char *)buf, "\x01%d", se -> context); |
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
726 writebytes(buf, strlen((char *)buf), 1, of); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
727 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
728 writebytes("", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
729 return 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
730 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
731 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
732 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
733 default: |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
734 // unrecognized term type - replace with integer 0 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
735 // fprintf(stderr, "Unrecognized term type: %s\n", lw_expr_print(e)); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
736 buf[0] = 0x01; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
737 buf[1] = 0x00; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
738 buf[2] = 0x00; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
739 writebytes(buf, 3, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
740 break; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
741 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
742 return 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
743 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
744 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
745 void write_code_obj_auxsym(asmstate_t *as, FILE *of, sectiontab_t *s, struct symtabe *se2) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
746 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
747 struct symtabe *se; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
748 unsigned char buf[16]; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
749 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
750 if (!se2) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
751 return; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
752 write_code_obj_auxsym(as, of, s, se2 -> left); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
753 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
754 for (se = se2; se; se = se -> nextver) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
755 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
756 lw_expr_t te; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
757 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
758 debug_message(as, 200, "Consider symbol %s (%p) for export in section %p", se -> symbol, se -> section, s); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
759 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
760 // ignore symbols not in this section |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
761 if (se -> section != s) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
762 continue; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
763 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
764 debug_message(as, 200, " In section"); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
765 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
766 if (se -> flags & symbol_flag_set) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
767 continue; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
768 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
769 debug_message(as, 200, " Not symbol_flag_set"); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
770 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
771 te = lw_expr_copy(se -> value); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
772 debug_message(as, 200, " Value=%s", lw_expr_print(te)); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
773 as -> exportcheck = 1; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
774 as -> csect = s; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
775 lwasm_reduce_expr(as, te); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
776 as -> exportcheck = 0; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
777 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
778 debug_message(as, 200, " Value2=%s", lw_expr_print(te)); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
779 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
780 // don't output non-constant symbols |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
781 if (!lw_expr_istype(te, lw_expr_type_int)) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
782 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
783 lw_expr_destroy(te); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
784 continue; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
785 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
786 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
787 writebytes(se -> symbol, strlen(se -> symbol), 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
788 if (se -> context >= 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
789 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
790 writebytes("\x01", 1, 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
791 sprintf((char *)buf, "%d", se -> context); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
792 writebytes(buf, strlen((char *)buf), 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
793 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
794 // the "" is NOT an error |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
795 writebytes("", 1, 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
796 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
797 // write the address |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
798 buf[0] = (lw_expr_intval(te) >> 8) & 0xff; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
799 buf[1] = lw_expr_intval(te) & 0xff; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
800 writebytes(buf, 2, 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
801 lw_expr_destroy(te); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
802 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
803 write_code_obj_auxsym(as, of, s, se2 -> right); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
804 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
805 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
806 void write_code_obj(asmstate_t *as, FILE *of) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
807 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
808 line_t *l; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
809 sectiontab_t *s; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
810 reloctab_t *re; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
811 exportlist_t *ex; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
812 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
813 int i; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
814 unsigned char buf[16]; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
815 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
816 // output the magic number and file header |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
817 // the 8 is NOT an error |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
818 writebytes("LWOBJ16", 8, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
819 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
820 // run through the entire system and build the byte streams for each |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
821 // section; at the same time, generate a list of "local" symbols to |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
822 // output for each section |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
823 // NOTE: for "local" symbols, we will append \x01 and the ascii string |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
824 // of the context identifier (so sym in context 1 would be "sym\x011" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
825 // we can do this because the linker can handle symbols with any |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
826 // character other than NUL. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
827 // also we will generate a list of incomplete references for each |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
828 // section along with the actual definition that will be output |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
829 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
830 // once all this information is generated, we will output each section |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
831 // to the file |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
832 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
833 // NOTE: we build everything in memory then output it because the |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
834 // assembler accepts multiple instances of the same section but the |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
835 // linker expects only one instance of each section in the object file |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
836 // so we need to collect all the various pieces of a section together |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
837 // (also, the assembler treated multiple instances of the same section |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
838 // as continuations of previous sections so we would need to collect |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
839 // them together anyway. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
840 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
841 for (l = as -> line_head; l; l = l -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
842 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
843 if (l -> csect) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
844 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
845 // we're in a section - need to output some bytes |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
846 if (l -> outputl > 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
847 for (i = 0; i < l -> outputl; i++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
848 write_code_obj_sbadd(l -> csect, l -> output[i]); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
849 else if (l -> outputl == 0 || l -> outputl == -1) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
850 for (i = 0; i < l -> len; i++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
851 write_code_obj_sbadd(l -> csect, 0); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
852 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
853 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
854 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
855 // run through the sections |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
856 for (s = as -> sections; s; s = s -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
857 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
858 // write the name |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
859 writebytes(s -> name, strlen(s -> name) + 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
860 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
861 // write the flags |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
862 if (s -> flags & section_flag_bss) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
863 writebytes("\x01", 1, 1, of); |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
864 if (s -> flags & section_flag_constant) |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
865 writebytes("\x02", 1, 1, of); |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
866 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
867 // indicate end of flags - the "" is NOT an error |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
868 writebytes("", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
869 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
870 // now the local symbols |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
871 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
872 // a symbol for section base address |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
873 if ((s -> flags & section_flag_constant) == 0) |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
874 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
875 writebytes("\x02", 1, 1, of); |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
876 writebytes(s -> name, strlen(s -> name) + 1, 1, of); |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
877 // address 0; "\0" is not an error |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
878 writebytes("\0", 2, 1, of); |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
879 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
880 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
881 write_code_obj_auxsym(as, of, s, as -> symtab.head); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
882 // flag end of local symbol table - "" is NOT an error |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
883 writebytes("", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
884 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
885 // now the exports -- FIXME |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
886 for (ex = as -> exportlist; ex; ex = ex -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
887 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
888 int eval; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
889 lw_expr_t te; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
890 line_t tl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
891 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
892 if (ex -> se == NULL) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
893 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
894 if (ex -> se -> section != s) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
895 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
896 te = lw_expr_copy(ex -> se -> value); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
897 as -> csect = ex -> se -> section; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
898 as -> exportcheck = 1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
899 tl.as = as; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
900 as -> cl = &tl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
901 lwasm_reduce_expr(as, te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
902 as -> exportcheck = 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
903 as -> cl = NULL; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
904 if (!lw_expr_istype(te, lw_expr_type_int)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
905 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
906 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
907 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
908 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
909 eval = lw_expr_intval(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
910 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
911 writebytes(ex -> symbol, strlen(ex -> symbol) + 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
912 buf[0] = (eval >> 8) & 0xff; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
913 buf[1] = eval & 0xff; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
914 writebytes(buf, 2, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
915 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
916 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
917 // flag end of exported symbols - "" is NOT an error |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
918 writebytes("", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
919 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
920 // FIXME - relocation table |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
921 for (re = s -> reloctab; re; re = re -> next) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
922 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
923 int offset; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
924 lw_expr_t te; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
925 line_t tl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
926 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
927 tl.as = as; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
928 as -> cl = &tl; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
929 as -> csect = s; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
930 as -> exportcheck = 1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
931 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
932 if (re -> expr == NULL) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
933 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
934 // this is an error but we'll simply ignore it |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
935 // and not output this expression |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
936 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
937 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
938 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
939 // work through each term in the expression and output |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
940 // the proper equivalent to the object file |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
941 if (re -> size == 1) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
942 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
943 // flag an 8 bit relocation (low 8 bits will be used) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
944 buf[0] = 0xFF; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
945 buf[1] = 0x01; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
946 writebytes(buf, 2, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
947 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
948 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
949 te = lw_expr_copy(re -> offset); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
950 lwasm_reduce_expr(as, te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
951 if (!lw_expr_istype(te, lw_expr_type_int)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
952 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
953 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
954 continue; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
955 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
956 offset = lw_expr_intval(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
957 lw_expr_destroy(te); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
958 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
959 // output expression |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
960 lw_expr_testterms(re -> expr, write_code_obj_expraux, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
961 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
962 // flag end of expressions |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
963 writebytes("", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
964 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
965 // write the offset |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
966 buf[0] = (offset >> 8) & 0xff; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
967 buf[1] = offset & 0xff; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
968 writebytes(buf, 2, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
969 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
970 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
971 // flag end of incomplete references list |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
972 writebytes("", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
973 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
974 // now blast out the code |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
975 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
976 // length |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
977 if (s -> flags & section_flag_constant) |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
978 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
979 buf[0] = 0; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
980 buf[1] = 0; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
981 } |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
982 else |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
983 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
984 buf[0] = s -> oblen >> 8 & 0xff; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
985 buf[1] = s -> oblen & 0xff; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
986 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
987 writebytes(buf, 2, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
988 |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
989 |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
990 if (!(s -> flags & section_flag_bss) && !(s -> flags & section_flag_constant)) |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
991 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
992 writebytes(s -> obytes, s -> oblen, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
993 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
994 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
995 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
996 // flag no more sections |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
997 // the "" is NOT an error |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
998 writebytes("", 1, 1, of); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
999 } |