Mercurial > hg > index.cgi
annotate lwasm/output.c @ 370:8764142b3192
Convert internal error/warning handling framework to a new unified system
Replace the ad hoc error and warning handling with a new system that
codifies the errors with specific codes. This makes it possible in the
future for error numbers to be used for testing and other purposes. It also
makes sure the error strings themselves are consistent.
Thanks to Erik G <erik@6809.org> for the patch.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 22 Jun 2015 18:49:38 -0600 |
parents | ade217fd76a5 |
children | 4411a6123716 |
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); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 |
2c24602be78f
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 // this prevents warnings about not using the return value of fwrite() |
221 | 46 // r++ prevents the "set but not used" warnings; should be optimized out |
47 #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
|
48 |
2c24602be78f
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 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
|
50 { |
2c24602be78f
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 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
|
52 |
2c24602be78f
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 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
|
54 { |
2c24602be78f
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 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
|
56 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
|
57 } |
2c24602be78f
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 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
|
60 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
|
61 { |
2c24602be78f
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 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
|
63 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
|
64 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
|
65 } |
2c24602be78f
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 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
|
68 { |
2c24602be78f
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 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
|
70 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
|
71 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
|
72 |
2c24602be78f
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 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
|
74 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
|
75 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
|
76 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 |
2c24602be78f
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 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
|
82 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
|
83 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
|
84 |
2c24602be78f
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 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
|
86 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
|
87 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
|
88 |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
89 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
|
90 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
|
91 break; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
92 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
93 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
|
94 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
|
95 break; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
96 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
97 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
|
98 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
|
99 break; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
100 |
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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 } |
2c24602be78f
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 |
2c24602be78f
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 } |
2c24602be78f
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 |
2c24602be78f
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 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
|
113 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
|
114 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
|
115 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
|
116 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
117 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
|
118 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
|
119 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
120 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
|
121 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
122 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
|
123 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
124 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
|
125 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
126 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
|
127 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
|
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
|
129 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
|
130 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
|
131 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
132 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
133 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
134 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
139 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
|
140 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
141 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
|
142 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
143 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
|
144 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
145 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
|
146 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 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
|
151 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
152 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
|
153 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
|
154 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
155 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
156 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
157 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
158 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
159 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
|
160 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
|
161 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
162 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
|
163 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
164 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
|
165 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
166 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
|
167 { |
127
d92b9c968731
Removed protection from outputting code outside os9 module in os9 target
lost@l-w.ca
parents:
12
diff
changeset
|
168 // if (cl -> inmod == 0) |
d92b9c968731
Removed protection from outputting code outside os9 module in os9 target
lost@l-w.ca
parents:
12
diff
changeset
|
169 // 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
|
170 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
|
171 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 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
|
176 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
177 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
|
178 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
|
179 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
180 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
181 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
182 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
|
183 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
191 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
|
192 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
193 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
|
194 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
|
195 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
|
196 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
|
197 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
198 // 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
|
199 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
|
200 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
201 // 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 } |
2c24602be78f
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 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
|
219 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
|
220 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
|
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 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
|
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 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 } |
2c24602be78f
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 // 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 } |
2c24602be78f
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 |
321
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
240 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
|
241 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
242 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
|
243 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
|
244 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
245 // 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
|
246 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
|
247 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
248 *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
|
249 *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
|
250 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
251 // 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
|
252 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
|
253 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
254 lastaddr = *addr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
255 return 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
256 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
257 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
258 // 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
|
259 else |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
260 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
261 lastaddr = *addr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
262 return -1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
263 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
264 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
265 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
266 // 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
|
267 else |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
268 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
269 outidx = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
270 return 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
271 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
272 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
273 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
274 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
275 /* 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
|
276 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
277 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
|
278 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
279 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
|
280 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
281 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
|
282 char outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
283 int outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
284 int rc; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
285 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
286 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
|
287 do |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
288 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
289 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
|
290 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
291 // 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
|
292 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
|
293 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
294 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
|
295 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
|
296 rc = -1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
297 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
298 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
|
299 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
|
300 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
301 while (rc); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
302 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
303 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
304 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
305 /* 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
|
306 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
307 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
|
308 { |
360
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
309 #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
|
310 #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
|
311 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
312 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
|
313 char outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
314 int outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 int recsum; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
321 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
|
322 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
|
323 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
324 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
|
325 do |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
326 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
327 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
|
328 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
329 // 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
|
330 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
|
331 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
332 // 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
|
333 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
|
334 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
335 // 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
|
336 // 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
|
337 strcpy(rechdr, "["); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
338 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
|
339 strcat(rechdr, "] "); |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
346 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
|
347 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
|
348 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
349 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
|
350 reccnt = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
351 } |
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 // 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
|
354 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
|
355 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
356 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
|
357 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
|
358 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
|
359 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
360 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
|
361 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
|
362 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 reccnt += 1; |
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 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
369 // 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
|
370 recdlen = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
371 recaddr = outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
372 rc = 1; |
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 // 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
|
376 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
|
377 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
|
378 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
379 while (rc); |
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 // 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
|
382 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
|
383 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
388 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
|
389 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
|
390 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
391 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
|
392 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
|
393 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
|
394 reccnt += 1; |
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 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
397 // 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
|
398 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
|
399 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
400 // 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
|
401 recsum = 3; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
402 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
|
403 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
|
404 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
|
405 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
|
406 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
407 // 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
|
408 recsum = 3; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 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
|
413 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
414 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
415 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
416 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
417 /* 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
|
418 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
419 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
|
420 { |
360
ade217fd76a5
Use #define instead of const int to avoid issues with some compilers
William Astle <lost@l-w.ca>
parents:
321
diff
changeset
|
421 #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
|
422 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
423 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
|
424 char outbyte; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
425 int outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
426 int rc; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
427 int i; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
428 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
|
429 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
|
430 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
|
431 int recsum; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
432 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
|
433 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
434 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
|
435 do |
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 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
|
438 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
439 // 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
|
440 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
|
441 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
442 // 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
|
443 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
|
444 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
445 recsum = recdlen; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
446 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
|
447 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
|
448 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
449 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
|
450 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
|
451 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
452 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
|
453 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
|
454 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
|
455 reccnt += 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
456 } |
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 // 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
|
459 recdlen = 0; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
460 recaddr = outaddr; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
461 rc = 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
462 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
463 |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
464 // 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
|
465 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
|
466 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
|
467 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
468 while (rc); |
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 // 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
|
471 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
|
472 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
473 recsum = recdlen; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
474 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
|
475 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
|
476 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
477 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
|
478 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
|
479 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 reccnt += 1; |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
484 } |
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 // 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
|
487 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
|
488 { |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
489 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
|
490 } |
d4ac484d0ec6
Add support for Motorola SREC and Intel Hex output formats to lwasm.
Tom LeMense <tlemense@yahoo.com>
parents:
221
diff
changeset
|
491 } |
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 |
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
|
494 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
|
495 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
496 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
|
497 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
498 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
|
499 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
|
500 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
501 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
|
502 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
|
503 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
504 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
505 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
506 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
|
507 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 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
|
512 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
513 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
|
514 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
515 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
|
516 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
517 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
|
518 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
|
519 |
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
|
520 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
|
521 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 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
|
526 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
531 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
|
532 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
|
533 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
|
534 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
|
535 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
536 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
|
537 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
|
538 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
|
539 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
540 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
|
541 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
|
542 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
|
543 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
552 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
|
553 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
|
554 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
|
555 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
556 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
|
557 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
|
558 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
|
559 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
560 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
|
561 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
|
562 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
|
563 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
564 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
|
565 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
|
566 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
|
567 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
568 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
|
569 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
|
570 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
|
571 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
572 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
|
573 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
|
574 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
|
575 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
576 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
|
577 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
|
578 } |
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
|
579 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
|
580 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
|
581 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
|
582 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
583 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
|
584 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
591 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
|
592 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
|
593 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
|
594 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
595 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
|
596 { |
2c24602be78f
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 // 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
|
598 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
|
599 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
|
600 |
2c24602be78f
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 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
|
602 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
|
603 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
|
604 } |
2c24602be78f
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 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
|
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 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 } |
2c24602be78f
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 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
|
615 { |
2c24602be78f
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 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 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
|
622 { |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
623 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
|
624 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
|
625 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
626 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
|
627 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
|
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 } |
2c24602be78f
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 |
2c24602be78f
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 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
|
632 // 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
|
633 // 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 } |
2c24602be78f
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 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
|
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 |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
643 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
|
644 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
645 struct symtabe *se; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
646 unsigned char buf[16]; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
647 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
648 if (!se2) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
649 return; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
650 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
|
651 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
652 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
|
653 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
654 lw_expr_t te; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
655 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
656 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
|
657 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
658 // 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
|
659 if (se -> section != s) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
660 continue; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
661 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
662 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
|
663 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
664 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
|
665 continue; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
666 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
667 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
|
668 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
669 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
|
670 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
|
671 as -> exportcheck = 1; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
672 as -> csect = s; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
673 lwasm_reduce_expr(as, te); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
674 as -> exportcheck = 0; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
675 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
676 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
|
677 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
678 // 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
|
679 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
|
680 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
681 lw_expr_destroy(te); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
682 continue; |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
683 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
684 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
685 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
|
686 if (se -> context >= 0) |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
687 { |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
688 writebytes("\x01", 1, 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
689 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
|
690 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
|
691 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
692 // the "" is NOT an error |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
693 writebytes("", 1, 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
694 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
695 // write the address |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
696 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
|
697 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
|
698 writebytes(buf, 2, 1, of); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
699 lw_expr_destroy(te); |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
700 } |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
701 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
|
702 } |
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
|
703 |
2c24602be78f
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 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
|
705 { |
2c24602be78f
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 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
|
707 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
|
708 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
|
709 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
|
710 |
2c24602be78f
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 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
|
712 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
|
713 |
2c24602be78f
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 // 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
|
715 // 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
|
716 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
|
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 // 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
|
719 // 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
|
720 // 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
|
721 // 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
|
722 // 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
|
723 // 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
|
724 // 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
|
725 // 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
|
726 // 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
|
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 // 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
|
729 // 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
|
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 // 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
|
732 // 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
|
733 // 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
|
734 // 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
|
735 // (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
|
736 // 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
|
737 // 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
|
738 |
2c24602be78f
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 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
|
740 { |
2c24602be78f
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 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
|
742 { |
2c24602be78f
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 // 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
|
744 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
|
745 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
|
746 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
|
747 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
|
748 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
|
749 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
|
750 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
751 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
752 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
753 // 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
|
754 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
|
755 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
756 // 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
|
757 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
|
758 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
759 // 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 |
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
|
765 // 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
|
766 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
|
767 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
768 // 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
|
769 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
770 // 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
|
771 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
|
772 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
773 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
|
774 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
|
775 // 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
|
776 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
|
777 } |
195
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
778 |
17bd59f045af
Changed symbol table to use a binary tree.
William Astle <lost@l-w.ca>
parents:
156
diff
changeset
|
779 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
|
780 // 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
|
781 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
|
782 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
783 // 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
|
784 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
|
785 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
786 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
|
787 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
|
788 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
|
789 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
790 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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 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
|
803 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
804 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
|
805 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
|
806 } |
2c24602be78f
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 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
|
808 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
|
809 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
|
810 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
|
811 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
|
812 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
|
813 } |
2c24602be78f
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 |
2c24602be78f
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 // 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
|
816 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
|
817 |
2c24602be78f
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 // 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
|
819 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
|
820 { |
2c24602be78f
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 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
|
822 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
|
823 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
|
824 |
2c24602be78f
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 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
|
826 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
|
827 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
|
828 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
|
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 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
|
831 { |
2c24602be78f
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 // 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
|
833 // 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
|
834 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
|
835 } |
2c24602be78f
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 |
2c24602be78f
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 // 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
|
838 // 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
|
839 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
|
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 // 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
|
842 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
|
843 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
|
844 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
|
845 } |
2c24602be78f
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 |
2c24602be78f
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 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
|
848 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
|
849 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
|
850 { |
2c24602be78f
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 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
|
852 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
|
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 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
|
855 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
|
856 |
2c24602be78f
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 // 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
|
858 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
|
859 |
2c24602be78f
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 // 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
|
861 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
|
862 |
2c24602be78f
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 // 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
|
864 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
|
865 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
|
866 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
|
867 } |
2c24602be78f
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 |
2c24602be78f
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 // 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
|
870 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
|
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 // 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
|
873 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
874 // length |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
875 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
|
876 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
877 buf[0] = 0; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
878 buf[1] = 0; |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
879 } |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
880 else |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
881 { |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
882 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
|
883 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
|
884 } |
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
|
885 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
|
886 |
156
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
887 |
fc8386b13399
Added 'constant' sections to object file handling for lwasm and lwlink
lost@l-w.ca
parents:
127
diff
changeset
|
888 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
|
889 { |
2c24602be78f
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 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
|
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 } |
2c24602be78f
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 |
2c24602be78f
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 // 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
|
895 // 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
|
896 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
|
897 } |