annotate lwlink/output.c @ 151:3b58d76ea032

Fix up some minor thinkos in handling the module layout and header
author lost@l-w.ca
date Fri, 26 Aug 2011 23:44:44 -0600
parents 08fb11004df9
children 11b710d231bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 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 LWLINK.
2c24602be78f 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 LWLINK 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 Actually output the binary
2c24602be78f 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
2c24602be78f 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 <stdlib.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
26 #include <string.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
27
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
28 #include "lwlink.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
29
2c24602be78f 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 // this prevents warnings about not using the return value of fwrite()
2c24602be78f 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 // and, theoretically, can be replaced with a function that handles things
2c24602be78f 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 // better in the future
2c24602be78f 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 #define writebytes(s, l, c, f) do { int r; r = fwrite((s), (l), (c), (f)); } while (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
34
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
35 void do_output_os9(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
36 void do_output_decb(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 do_output_raw(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 do_output_lwex0(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
2c24602be78f 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 do_output(void)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
41 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
42 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
43
2c24602be78f 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 of = fopen(outfile, "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
45 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
46 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
47 fprintf(stderr, "Cannot open output file %s: ", outfile);
2c24602be78f 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 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
49 exit(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
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
2c24602be78f 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 switch (outformat)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
53 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
54 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
55 do_output_decb(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
56 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
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 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
59 do_output_raw(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
60 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
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 case OUTPUT_LWEX0:
2c24602be78f 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 do_output_lwex0(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
64 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
65
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
66 case OUTPUT_OS9:
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
67 do_output_os9(of);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
68 break;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
69
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
70 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
71 fprintf(stderr, "Unknown output format doing output!\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
72 exit(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
73 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
74
2c24602be78f 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 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
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
2c24602be78f 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 void do_output_decb(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
79 {
2c24602be78f 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 int sn, sn2;
2c24602be78f 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 int cloc, olen;
2c24602be78f 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 unsigned char buf[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
83
2c24602be78f 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 for (sn = 0; sn < nsects; sn++)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
85 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
86 if (sectlist[sn].ptr -> flags & SECTION_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
87 {
2c24602be78f 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 // no output for a BSS 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
89 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
90 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
91 if (sectlist[sn].ptr -> codesize == 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
92 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
93 // don't generate output for a zero size 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
94 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
95 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
96
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
97 // calculate the length of this output block
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
98 cloc = sectlist[sn].ptr -> loadaddress;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
99 olen = 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
100 for (sn2 = sn; sn2 < nsects; sn2++)
2c24602be78f 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 {
2c24602be78f 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 // ignore BSS 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
103 if (sectlist[sn2].ptr -> flags & SECTION_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
104 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
105 // ignore zero length 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
106 if (sectlist[sn2].ptr -> codesize == 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
107 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
108 if (cloc != sectlist[sn2].ptr -> loadaddress)
2c24602be78f 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 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
110 olen += sectlist[sn2].ptr -> codesize;
2c24602be78f 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 cloc += sectlist[sn2].ptr -> codesize;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
112 }
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
113
2c24602be78f 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 // write a preamble
2c24602be78f 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 buf[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
116 buf[1] = olen >> 8;
2c24602be78f 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 buf[2] = olen & 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
118 buf[3] = sectlist[sn].ptr -> loadaddress >> 8;
2c24602be78f 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 buf[4] = sectlist[sn].ptr -> loadaddress & 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
120 writebytes(buf, 1, 5, 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 for (; sn < sn2; sn++)
2c24602be78f 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 {
2c24602be78f 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 if (sectlist[sn].ptr -> flags & SECTION_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
124 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
125 if (sectlist[sn].ptr -> codesize == 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
126 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
127 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, 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
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 sn--;
2c24602be78f 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 }
2c24602be78f 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 // write a 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
132 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
133 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
134 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
135 buf[3] = linkscript.execaddr >> 8;
2c24602be78f 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 buf[4] = linkscript.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
137 writebytes(buf, 1, 5, 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
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
2c24602be78f 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 void do_output_raw(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
141 {
2c24602be78f 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 int nskips = 0; // used to output blanks for BSS inline
2c24602be78f 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 int sn;
2c24602be78f 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 for (sn = 0; sn < nsects; sn++)
2c24602be78f 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 if (sectlist[sn].ptr -> flags & SECTION_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
148 {
2c24602be78f 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 // no output for a BSS 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
150 nskips += sectlist[sn].ptr -> codesize;
2c24602be78f 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 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
152 }
2c24602be78f 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 while (nskips > 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
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 // the "" is not an error - it turns into a single NUL byte!
2c24602be78f 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 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
157 nskips--;
2c24602be78f 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 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, 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
160 }
2c24602be78f 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
2c24602be78f 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 void do_output_lwex0(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
164 {
2c24602be78f 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 int nskips = 0; // used to output blanks for BSS inline
2c24602be78f 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 int sn;
2c24602be78f 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 int codedatasize = 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
168 unsigned char buf[32];
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
169
2c24602be78f 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 // calculate items for the 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
171 for (sn = 0; sn < nsects; sn++)
2c24602be78f 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 {
2c24602be78f 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 if (sectlist[sn].ptr -> flags & SECTION_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
174 {
2c24602be78f 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 // no output for a BSS 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
176 nskips += sectlist[sn].ptr -> codesize;
2c24602be78f 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 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
178 }
2c24602be78f 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 codedatasize += nskips;
2c24602be78f 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 nskips = 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
181 codedatasize += sectlist[sn].ptr -> codesize;
2c24602be78f 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 }
2c24602be78f 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 // output the 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
185 buf[0] = '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
186 buf[1] = 'W';
2c24602be78f 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 buf[2] = '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
188 buf[3] = 'X';
2c24602be78f 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 buf[4] = 0; // version 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
190 buf[5] = 0; // low stack
2c24602be78f 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 buf[6] = linkscript.stacksize / 256;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
192 buf[7] = linkscript.stacksize & 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
193 buf[8] = nskips / 256;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
194 buf[9] = nskips & 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
195 buf[10] = codedatasize / 256;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
196 buf[11] = codedatasize & 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
197 buf[12] = linkscript.execaddr / 256;
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
198 buf[13] = linkscript.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
199 memset(buf + 14, 0, 18);
2c24602be78f 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 writebytes(buf, 1, 32, 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
202 // output the data
2c24602be78f 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 // NOTE: disjoint load addresses will not work correctly!!!!!
2c24602be78f 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 for (sn = 0; sn < nsects; sn++)
2c24602be78f 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 {
2c24602be78f 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 if (sectlist[sn].ptr -> flags & SECTION_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
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 // no output for a BSS 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
209 nskips += sectlist[sn].ptr -> codesize;
2c24602be78f 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 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
211 }
2c24602be78f 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 while (nskips > 0)
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
213 {
2c24602be78f Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff changeset
214 // the "" is not an error - it turns into a single NUL byte!
2c24602be78f 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 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
216 nskips--;
2c24602be78f 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 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, 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
219 }
2c24602be78f 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 }
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
221
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
222 void os9crc(unsigned char crc[3], unsigned char b)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
223 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
224 b ^= crc[0];
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
225 crc[0] = crc[1];
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
226 crc[1] = crc[2];
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
227 crc[1] ^= b >> 7;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
228 crc[2] = b << 1;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
229 crc[1] ^= b >> 2;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
230 crc[2] ^= b << 6;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
231 b ^= b << 1;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
232 b ^= b << 2;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
233 b ^= b << 4;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
234 if (b & 0x80)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
235 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
236 crc[0] ^= 0x80;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
237 crc[2] ^= 0x21;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
238 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
239 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
240
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
241
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
242 void do_output_os9(FILE *of)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
243 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
244 int sn;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
245 int codedatasize = 0;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
246 int bsssize = 0;
151
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
247 int nameoff;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
248 int i;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
249
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
250 unsigned char buf[16];
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
251 unsigned char crc[3];
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
252
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
253 // calculate items for the file header
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
254 for (sn = 0; sn < nsects; sn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
255 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
256 if (sectlist[sn].ptr -> flags & SECTION_BSS)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
257 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
258 // no output for a BSS section
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
259 bsssize += sectlist[sn].ptr -> codesize;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
260 continue;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
261 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
262 codedatasize += sectlist[sn].ptr -> codesize;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
263 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
264
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
265 // now bss size is the data size for the module
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
266 // and codesize is the length of the module minus the module header
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
267 // and CRC
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
268
151
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
269 codedatasize += 13; // add in headers
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
270 nameoff = codedatasize; // we'll put the name at the end
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
271 codedatasize += 3; // add in CRC
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
272 codedatasize += strlen(linkscript.name); // add in name length
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
273
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
274 // output the file header
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
275 buf[0] = 0x87;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
276 buf[1] = 0xCD;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
277 buf[2] = (codedatasize >> 8) & 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
278 buf[3] = codedatasize & 0xff;
151
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
279 buf[4] = (nameoff >> 8) & 0xff;
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
280 buf[5] = nameoff & 0xff;
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
281 buf[6] = (linkscript.modtype << 4) | (linkscript.modlang);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
282 buf[7] = (linkscript.modattr << 4) | (linkscript.modrev);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
283 buf[8] = (~(buf[0] ^ buf[1] ^ buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6] ^ buf[7])) & 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
284 buf[9] = (linkscript.execaddr >> 8) & 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
285 buf[10] = linkscript.execaddr & 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
286 buf[11] = (bsssize >> 8) & 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
287 buf[12] = bsssize & 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
288
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
289 crc[0] = 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
290 crc[1] = 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
291 crc[2] = 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
292
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
293 os9crc(crc, buf[0]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
294 os9crc(crc, buf[1]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
295 os9crc(crc, buf[2]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
296 os9crc(crc, buf[3]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
297 os9crc(crc, buf[4]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
298 os9crc(crc, buf[5]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
299 os9crc(crc, buf[6]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
300 os9crc(crc, buf[7]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
301 os9crc(crc, buf[8]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
302 os9crc(crc, buf[9]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
303 os9crc(crc, buf[10]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
304 os9crc(crc, buf[11]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
305 os9crc(crc, buf[12]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
306
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
307
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
308 writebytes(buf, 1, 13, of);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
309
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
310 // output the data
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
311 // NOTE: disjoint load addresses will not work correctly!!!!!
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
312 for (sn = 0; sn < nsects; sn++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
313 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
314 if (sectlist[sn].ptr -> flags & SECTION_BSS)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
315 {
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
316 // no output for a BSS section
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
317 continue;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
318 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
319 writebytes(sectlist[sn].ptr -> code, 1, sectlist[sn].ptr -> codesize, of);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
320 for (i = 0; i < sectlist[sn].ptr -> codesize; i++)
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
321 os9crc(crc, sectlist[sn].ptr -> code[i]);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
322 }
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
323
151
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
324 // output the name
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
325 for (i = 0; linkscript.name[i + 1]; i++)
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
326 {
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
327 writebytes(linkscript.name + i, 1, 1, of);
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
328 os9crc(crc, linkscript.name[i]);
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
329 }
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
330 buf[0] = linkscript.name[i] | 0x80;
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
331 writebytes(buf, 1, 1, of);
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
332 os9crc(crc, buf[0]);
3b58d76ea032 Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents: 148
diff changeset
333
148
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
334 crc[0] ^= 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
335 crc[1] ^= 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
336 crc[2] ^= 0xff;
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
337 writebytes(crc, 1, 3, of);
08fb11004df9 Initial pass at OS9 module support for lwlink
lost@l-w.ca
parents: 0
diff changeset
338 }