Mercurial > hg > index.cgi
annotate lwlink/script.c @ 368:362f8fb0695b
Make psh/pul error out if no registers given
While the generated object code was technically correct for bare pshs, puls,
pshu, and pulu, it was not helpful. Throw a bad operand error if no
registers are given as an operand to such instructions.
Thanks to Erik G <erik@6809.org> for reporting the problem.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 15 Jun 2015 21:26:33 -0600 |
parents | 55c1f9a321e9 |
children | b8e9ac01deda |
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 script.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 Read and parse linker scripts |
2c24602be78f
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 |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
24 #include <ctype.h> |
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
|
25 #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
|
26 #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
|
27 #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
|
28 #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
|
29 |
8
fdc11ef4115b
Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents:
2
diff
changeset
|
30 #include <lw_alloc.h> |
fdc11ef4115b
Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents:
2
diff
changeset
|
31 #include <lw_string.h> |
fdc11ef4115b
Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents:
2
diff
changeset
|
32 |
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
|
33 #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
|
34 |
148 | 35 // the built-in OS9 script |
151
3b58d76ea032
Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents:
148
diff
changeset
|
36 // the 000D bit is to handle the module header! |
148 | 37 static char *os9_script = |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
38 "define basesympat s_%s\n" |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
39 "define lensympat l_%s\n" |
151
3b58d76ea032
Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents:
148
diff
changeset
|
40 "section code load 000D\n" |
148 | 41 "section .text\n" |
42 "section data\n" | |
43 "section .data\n" | |
44 "section bss,bss load 0000\n" | |
45 "section .bss,bss\n" | |
258
ebda5c96665e
Improved stack handling for os9 target in lwlink
William Astle <lost@l-w.ca>
parents:
236
diff
changeset
|
46 "stacksize 32\n" |
151
3b58d76ea032
Fix up some minor thinkos in handling the module layout and header
lost@l-w.ca
parents:
148
diff
changeset
|
47 "entry __start\n" |
148 | 48 ; |
49 | |
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
|
50 // the built-in DECB target linker script |
2c24602be78f
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 static char *decb_script = |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
52 "define basesympat s_%s\n" |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
53 "define lensympat l_%s\n" |
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 "section init load 2000\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
|
55 "section code\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 "section *,!bss\n" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
57 "section *,bss\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
|
58 "entry 2000\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
|
59 ; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
60 |
344
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
61 // the built-in SREC target linker script |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
62 static char *srec_script = |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
63 "define basesympat s_%s\n" |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
64 "define lensympat l_%s\n" |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
65 "section init load 0400\n" |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
66 "section code\n" |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
67 "section *,!bss\n" |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
68 "section *,bss\n" |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
69 "entry __start\n" |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
70 ; |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
71 |
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
|
72 // the built-in RAW target linker script |
2c24602be78f
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 static char *raw_script = |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
74 "define basesympat s_%s\n" |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
75 "define lensympat l_%s\n" |
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
|
76 "section init load 0000\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
|
77 "section code\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
|
78 "section *,!bss\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
|
79 "section *,bss\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
|
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 |
2c24602be78f
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 static char *lwex0_script = |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
83 "define basesympat s_%s\n" |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
84 "define lensympat l_%s\n" |
236
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
85 "sectopt .ctors padafter 00,00\n" |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
86 "sectopt .dtors padafter 00,00\n" |
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
|
87 "section init load 0100\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
|
88 "section .text\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
|
89 "section .data\n" |
78 | 90 "section .ctors_start\n" |
91 "section .ctors\n" | |
92 "section .ctors_end\n" | |
93 "section .dtors_start\n" | |
94 "section .dtors\n" | |
95 "section .dtors_end\n" | |
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
|
96 "section *,!bss\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
|
97 "section *,bss\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
|
98 "entry __start\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
|
99 "stacksize 0100\n" // default 256 byte 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
|
100 ; |
2c24602be78f
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 // the "simple" script |
2c24602be78f
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 static char *simple_script = |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
104 "define basesympat s_%s\n" |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
105 "define lensympat l_%s\n" |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
106 "section *,!bss\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
|
107 "section *,bss\n" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
108 ; |
2c24602be78f
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 linkscript_t linkscript = { 0, NULL, -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
|
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 void setup_script() |
2c24602be78f
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 char *script, *oscript; |
2c24602be78f
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 long size; |
2c24602be78f
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 // read the file 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
|
118 if (scriptfile) |
2c24602be78f
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 FILE *f; |
2c24602be78f
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 long bread; |
2c24602be78f
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 f = fopen(scriptfile, "rb"); |
2c24602be78f
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 if (!f) |
2c24602be78f
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 fprintf(stderr, "Can't open file %s:", scriptfile); |
2c24602be78f
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 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
|
128 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
|
129 } |
2c24602be78f
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 fseek(f, 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
|
131 size = ftell(f); |
2c24602be78f
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 rewind(f); |
2c24602be78f
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 |
8
fdc11ef4115b
Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents:
2
diff
changeset
|
134 script = lw_alloc(size + 2); |
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
|
135 |
2c24602be78f
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 bread = fread(script, 1, size, f); |
2c24602be78f
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 if (bread < size) |
2c24602be78f
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 fprintf(stderr, "Short read on file %s (%ld/%ld):", scriptfile, bread, size); |
2c24602be78f
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 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
|
141 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
|
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 fclose(f); |
2c24602be78f
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 script[size] = '\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
|
146 script[size + 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
|
147 } |
2c24602be78f
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 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
|
149 { |
2c24602be78f
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 // fetch defaults based on output mode |
2c24602be78f
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 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
|
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 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
|
154 script = raw_script; |
2c24602be78f
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 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
|
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 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
|
158 script = decb_script; |
2c24602be78f
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 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
|
160 |
344
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
161 case OUTPUT_SREC: |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
162 script = srec_script; |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
163 break; |
55c1f9a321e9
Add S-record output support to lwlink
William Astle <lost@l-w.ca>
parents:
315
diff
changeset
|
164 |
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
|
165 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
|
166 script = lwex0_script; |
2c24602be78f
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 break; |
148 | 168 |
169 case OUTPUT_OS9: | |
170 script = os9_script; | |
171 break; | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
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 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
|
174 script = simple_script; |
2c24602be78f
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 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
|
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 |
2c24602be78f
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 size = strlen(script); |
2c24602be78f
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 if (nscriptls) |
2c24602be78f
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 char *rscript; |
2c24602be78f
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 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
|
183 // prepend the "extra" script lines |
2c24602be78f
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 for (i = 0; i < nscriptls; 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
|
185 size += strlen(scriptls[i]) + 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
|
186 |
8
fdc11ef4115b
Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents:
2
diff
changeset
|
187 rscript = lw_alloc(size + 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
|
188 oscript = rscript; |
2c24602be78f
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 for (i = 0; i < nscriptls; 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
|
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 oscript += sprintf(oscript, "%s\n", scriptls[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
|
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 strcpy(oscript, script); |
2c24602be78f
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 script = rscript; |
2c24602be78f
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 } |
2c24602be78f
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 } |
2c24602be78f
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 if (outformat == 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
|
199 linkscript.stacksize = 0x100; |
2c24602be78f
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 |
148 | 201 if (outformat == OUTPUT_OS9) |
202 { | |
203 linkscript.modtype = 0x01; | |
204 linkscript.modlang = 0x01; | |
205 linkscript.modattr = 0x08; | |
206 linkscript.modrev = 0x00; | |
262
7de7b14ebaee
Add support for os9 module edition byte
William Astle <lost@l-w.ca>
parents:
258
diff
changeset
|
207 linkscript.edition = -1; |
148 | 208 linkscript.name = NULL; |
209 } | |
210 | |
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
|
211 oscript = script; |
2c24602be78f
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 // now parse the script 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
|
213 while (*script) |
2c24602be78f
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 { |
2c24602be78f
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 char *ptr, *ptr2, *line; |
2c24602be78f
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 |
2c24602be78f
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 for (ptr = script; *ptr && *ptr != '\n' && *ptr != '\r'; ptr++) |
2c24602be78f
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 /* do nothing */ ; |
2c24602be78f
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 |
8
fdc11ef4115b
Switched lwlink to lw_cmdline from argp and also brought in lw_alloc and lw_string to replace util.c
lost@l-w.ca
parents:
2
diff
changeset
|
220 line = lw_alloc(ptr - script + 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
|
221 memcpy(line, script, ptr - script); |
2c24602be78f
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 line[ptr - script] = '\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 // skip line terms |
2c24602be78f
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 for (script = ptr + 1; *script == '\n' || *script == '\r'; script++) |
2c24602be78f
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 /* do nothing */ ; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
227 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
228 // ignore leading whitespace |
2c24602be78f
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 for (ptr = line; *ptr && isspace(*ptr); ptr++) |
2c24602be78f
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 /* do nothing */ ; |
2c24602be78f
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 |
310
86eb8814a05c
Add comments to linker scripts.
William Astle <lost@l-w.ca>
parents:
262
diff
changeset
|
232 // ignore blank lines and comments |
86eb8814a05c
Add comments to linker scripts.
William Astle <lost@l-w.ca>
parents:
262
diff
changeset
|
233 if (!*ptr || *ptr == '#' || *ptr == ';') |
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
|
234 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
|
235 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
236 for (ptr = line; *ptr && !isspace(*ptr); ptr++) |
2c24602be78f
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 /* do nothing */ ; |
2c24602be78f
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 // now ptr points to the char past the first word |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
240 // NUL it out |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
241 if (*ptr) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
242 *ptr++ = '\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
|
243 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
244 // skip spaces after the first word |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
245 for ( ; *ptr && isspace(*ptr); ptr++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
246 /* do nothing */ ; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
247 |
236
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
248 if (!strcmp(line, "sectopt")) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
249 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
250 char *sn; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
251 char *ptr3; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
252 sectopt_t *so; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
253 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
254 for (ptr2 = ptr; *ptr && !isspace(*ptr2); ptr2++) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
255 /* do nothing */ ; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
256 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
257 if (*ptr2) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
258 *ptr2++ = '\0'; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
259 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
260 while (*ptr2 && isspace(*ptr2)) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
261 ptr2++; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
262 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
263 // section name is at ptr |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
264 // ptr2 is the option type |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
265 sn = ptr; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
266 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
267 // now ptr2 points to the section option name |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
268 for (ptr3 = ptr2; *ptr3 && !isspace(*ptr3); ptr3++) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
269 /* do nothing */ ; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
270 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
271 if (*ptr3) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
272 *ptr3++ = 0; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
273 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
274 while (*ptr3 && isspace(*ptr3)) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
275 ptr3++; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
276 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
277 // now ptr3 points to option value |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
278 for (so = section_opts; so; so = so -> next) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
279 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
280 if (!strcmp(so -> name, sn)) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
281 break; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
282 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
283 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
284 if (!so) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
285 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
286 so = lw_alloc(sizeof(sectopt_t)); |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
287 so -> name = lw_strdup(sn); |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
288 so -> aftersize = 0; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
289 so -> afterbytes = NULL; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
290 so -> next = section_opts; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
291 section_opts = so; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
292 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
293 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
294 if (!strcmp(ptr2, "padafter")) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
295 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
296 if (so -> afterbytes) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
297 lw_free(so -> afterbytes); |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
298 so -> aftersize = 0; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
299 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
300 for (;;) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
301 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
302 int v; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
303 char *ptr4; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
304 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
305 while (*ptr3 && isspace(*ptr3)) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
306 ptr3++; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
307 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
308 if (!ptr3) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
309 break; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
310 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
311 v = strtoul(ptr3, &ptr4, 16); |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
312 if (ptr3 == ptr4) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
313 break; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
314 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
315 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
316 so -> afterbytes = lw_realloc(so -> afterbytes, so -> aftersize + 1); |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
317 so -> afterbytes[so -> aftersize] = v; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
318 so -> aftersize++; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
319 ptr3 = ptr4; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
320 while (*ptr3 && isspace(*ptr3)) |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
321 ptr3++; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
322 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
323 if (*ptr3 != ',') |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
324 break; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
325 |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
326 ptr3++; |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
327 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
328 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
329 else |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
330 { |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
331 fprintf(stderr, "%s: bad script line: %s %s\n", scriptfile, line, ptr2); |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
332 exit(1); |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
333 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
334 } |
ce1fdc8d6568
Added ability to add padding after a section when linking.
William Astle <lost@l-w.ca>
parents:
234
diff
changeset
|
335 else if (!strcmp(line, "define")) |
234
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
336 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
337 // parse out the definition type |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
338 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
339 /* do nothing */ ; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
340 |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
341 if (*ptr2) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
342 *ptr2++ = '\0'; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
343 |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
344 while (*ptr2 && isspace(*ptr2)) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
345 ptr2++; |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
346 |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
347 // now ptr points to the define type |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
348 if (!strcmp(ptr, "basesympat")) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
349 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
350 /* section base symbol pattern */ |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
351 lw_free(linkscript.basesympat); |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
352 linkscript.basesympat = lw_strdup(ptr2); |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
353 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
354 else if (!strcmp(ptr, "lensympat")) |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
355 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
356 /* section length symbol pattern */ |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
357 lw_free(linkscript.lensympat); |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
358 linkscript.lensympat = lw_strdup(ptr2); |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
359 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
360 else |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
361 { |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
362 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
363 } |
d389adbcc4ab
Added section base and length symbols to lwlink
William Astle <lost@l-w.ca>
parents:
183
diff
changeset
|
364 else if (!strcmp(line, "pad")) |
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
|
365 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
366 // padding |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
367 // parse the hex number and stow 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
|
368 linkscript.padsize = strtol(ptr, NULL, 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
|
369 if (linkscript.padsize < 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
|
370 linkscript.padsize = 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
|
371 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
372 else if (!strcmp(line, "stacksize")) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
373 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
374 // stack size for targets that support 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
|
375 // parse the hex number and stow 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
|
376 linkscript.padsize = strtol(ptr, NULL, 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
|
377 if (linkscript.stacksize < 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
|
378 linkscript.stacksize = 0x100; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
379 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
380 else if (!strcmp(line, "entry")) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
381 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
382 int eaddr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
383 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
384 eaddr = strtol(ptr, &ptr2, 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
|
385 if (*ptr2) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
386 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
387 linkscript.execaddr = -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
|
388 linkscript.execsym = lw_strdup(ptr); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
389 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
390 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
|
391 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
392 linkscript.execaddr = eaddr; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
393 linkscript.execsym = 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
|
394 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
395 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
396 else if (!strcmp(line, "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
|
397 { |
315
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
398 int growsdown = 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
|
399 // 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
|
400 // parse out the section name and 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
|
401 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
402 /* do nothing */ ; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
403 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
404 if (*ptr2) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
405 *ptr2++ = '\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
|
406 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
407 while (*ptr2 && isspace(*ptr2)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
408 ptr2++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
409 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
410 // ptr now points to the section name and flags and ptr2 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
411 // to the first non-space character following |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
412 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
413 // then look for "load <addr>" clause |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
414 if (*ptr2) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
415 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
416 if (!strncmp(ptr2, "load", 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
|
417 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
418 ptr2 += 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
|
419 while (*ptr2 && isspace(*ptr2)) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
420 ptr2++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
421 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
422 } |
315
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
423 else if (!strncmp(ptr2, "high", 4)) |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
424 { |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
425 ptr2 += 4; |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
426 while (*ptr2 && isspace(*ptr2)) |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
427 ptr2++; |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
428 growsdown = 1; |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
429 } |
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
|
430 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
|
431 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
432 fprintf(stderr, "%s: bad script\n", scriptfile); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
433 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
|
434 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
435 } |
315
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
436 else |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
437 { |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
438 if (linkscript.nlines > 0) |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
439 growsdown = linkscript.lines[linkscript.nlines - 1].growsdown; |
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
440 } |
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
|
441 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
442 // now ptr2 points to the load address if there is one |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
443 // or NUL if not |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
444 linkscript.lines = lw_realloc(linkscript.lines, sizeof(struct scriptline_s) * (linkscript.nlines + 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
|
445 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
446 linkscript.lines[linkscript.nlines].noflags = 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
|
447 linkscript.lines[linkscript.nlines].yesflags = 0; |
315
fcd103148aa6
Add ability to load sections downward instead of upward
William Astle <lost@l-w.ca>
parents:
310
diff
changeset
|
448 linkscript.lines[linkscript.nlines].growsdown = growsdown; |
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
|
449 if (*ptr2) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
450 linkscript.lines[linkscript.nlines].loadat = strtol(ptr2, NULL, 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
|
451 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
|
452 linkscript.lines[linkscript.nlines].loadat = -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
|
453 for (ptr2 = ptr; *ptr2 && *ptr2 != ','; ptr2++) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
454 /* do nothing */ ; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
455 if (*ptr2) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
456 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
457 *ptr2++ = '\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
|
458 if (!strcmp(ptr2, "!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
|
459 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
460 linkscript.lines[linkscript.nlines].noflags = 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
|
461 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
462 else if (!strcmp(ptr2, "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
|
463 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
464 linkscript.lines[linkscript.nlines].yesflags = 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
|
465 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
466 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
|
467 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
468 fprintf(stderr, "%s: bad script\n", scriptfile); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
469 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
|
470 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
471 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
472 if (ptr[0] == '*' && ptr[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
|
473 linkscript.lines[linkscript.nlines].sectname = 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
|
474 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
|
475 linkscript.lines[linkscript.nlines].sectname = lw_strdup(ptr); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
476 linkscript.nlines++; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
477 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
478 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
|
479 { |
67
554831f03338
Make lwlink more verbose about unrecognized linkscript lines
lost@l-w.ca
parents:
8
diff
changeset
|
480 fprintf(stderr, "%s: bad script line: %s\n", scriptfile, line); |
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
|
481 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
|
482 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
483 lw_free(line); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
484 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
485 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
486 if (scriptfile || nscriptls) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
487 lw_free(oscript); |
183 | 488 |
489 if (entrysym) | |
490 { | |
491 int eaddr; | |
492 char *ptr2; | |
493 | |
494 lw_free(linkscript.execsym); | |
495 | |
496 eaddr = strtol(entrysym, &ptr2, 0); | |
497 if (*ptr2) | |
498 { | |
499 linkscript.execaddr = -1; | |
500 linkscript.execsym = lw_strdup(entrysym); | |
501 } | |
502 else | |
503 { | |
504 linkscript.execaddr = eaddr; | |
505 linkscript.execsym = NULL; | |
506 } | |
507 | |
508 } | |
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
|
509 } |