1 /*****************************************************************************/
5 /* Target system support for the ld65 linker */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
50 /*****************************************************************************/
51 /* Target configurations */
52 /*****************************************************************************/
56 static const char CfgNone [] =
58 "RAM: start = %S, size = $10000, file = %O;"
61 "CODE: load = RAM, type = rw;"
62 "RODATA: load = RAM, type = rw;"
63 "DATA: load = RAM, type = rw;"
64 "BSS: load = RAM, type = bss, define = yes;"
67 static const char CfgAtari [] =
69 "HEADER: start = $0000, size = $6, file = %O;"
70 "RAM: start = $1F00, size = $9D1F, file = %O;" /* 9D1F: matches upper bound BC1F */
73 "EXEHDR: load = HEADER, type = wprot;"
74 "CODE: load = RAM, type = wprot, define = yes;"
75 "RODATA: load = RAM, type = wprot;"
76 "DATA: load = RAM, type = rw;"
77 "BSS: load = RAM, type = bss, define = yes;"
78 "AUTOSTRT: load = RAM, type = wprot;"
81 static const char CfgC64 [] =
83 "RAM: start = $7FF, size = $c801, file = %O;"
86 "CODE: load = RAM, type = wprot;"
87 "RODATA: load = RAM, type = wprot;"
88 "DATA: load = RAM, type = rw;"
89 "BSS: load = RAM, type = bss, define = yes;"
92 static const char CfgC128 [] =
94 "RAM: start = $1bff, size = $a401, file = %O;"
97 "CODE: load = RAM, type = wprot;"
98 "RODATA: load = RAM, type = wprot;"
99 "DATA: load = RAM, type = rw;"
100 "BSS: load = RAM, type = bss, define = yes;"
103 static const char CfgAce [] =
106 static const char CfgPlus4 [] =
108 "RAM: start = $0fff, size = $7001, file = %O;"
111 "CODE: load = RAM, type = wprot;"
112 "RODATA: load = RAM, type = wprot;"
113 "DATA: load = RAM, type = rw;"
114 "BSS: load = RAM, type = bss, define = yes;"
117 static const char CfgCBM610 [] =
119 "RAM: start = $0001, size = $FFF0, file = %O;"
122 "CODE: load = RAM, type = wprot;"
123 "RODATA: load = RAM, type = wprot;"
124 "DATA: load = RAM, type = rw;"
125 "BSS: load = RAM, type = bss, define = yes;"
128 static const char CfgPET [] =
130 "RAM: start = $03FF, size = $7BFF, file = %O;"
133 "CODE: load = RAM, type = wprot;"
134 "RODATA: load = RAM, type = wprot;"
135 "DATA: load = RAM, type = rw;"
136 "BSS: load = RAM, type = bss, define = yes;"
139 static const char CfgNES [] =
141 "RAM: start = $0200, size = $0600, file = \"\";"
142 "ROM: start = $8000, size = $8000, file = %O;"
145 "CODE: load = ROM, type = ro;"
146 "RODATA: load = ROM, type = ro;"
147 "DATA: load = ROM, run = RAM, type = rw, define = yes;"
148 "BSS: load = RAM, type = bss, define = yes;"
149 "VECTORS: load = ROM, type = ro, start = $FFFA;"
152 static const char CfgLunix [] =
154 "COMBINED: start = $0000, size = $FFFF, file = %O;"
155 "ZEROPAGE: start = $0000, size = $0100, file = %O;"
158 "CODE: load = COMBINED, type = wprot;"
159 "RODATA: load = COMBINED, type = wprot;"
160 "DATA: load = COMBINED, type = rw, define = yes;"
161 "BSS: load = COMBINED, type = bss, define = yes;"
162 "ZEROPAGE: load = ZEROPAGE, type = zp;"
168 "o65: os = lunix, type = small,"
169 "extsym = \"LUNIXKERNAL\", extsym = \"LIB6502\";"
172 static const char CfgOSA65 [] =
174 "COMBINED: start = $0000, size = $FFFF, file = %O;"
175 "ZEROPAGE: start = $0000, size = $0100, file = %O;"
178 "CODE: load = COMBINED, type = wprot;"
179 "RODATA: load = COMBINED, type = wprot;"
180 "DATA: load = COMBINED, type = rw, define = yes;"
181 "BSS: load = COMBINED, type = bss, define = yes;"
182 "ZEROPAGE: load = ZEROPAGE, type = zp;"
188 "o65: os = osa65, type = small,"
189 "extsym = \"OSA2KERNAL\", extsym = \"LIB6502\";"
192 static const char CfgApple2 [] =
194 "RAM: start = $800, size = $8E00, file = %O;"
197 "CODE: load = RAM, type = ro;"
198 "RODATA: load = RAM, type = ro;"
199 "DATA: load = RAM, type = rw;"
200 "BSS: load = RAM, type = bss, define = yes;"
203 static const char CfgGeos [] =
205 "HEADER: start = $204, size = 508, file = %O;"
206 "RAM: start = $400, size = $7C00, file = %O;"
209 "HEADER: load = HEADER, type = ro;"
210 "CODE: load = RAM, type = ro;"
211 "RODATA: load = RAM, type = ro;"
212 "DATA: load = RAM, type = rw;"
213 "BSS: load = RAM, type = bss, define = yes;"
218 /*****************************************************************************/
220 /*****************************************************************************/
224 /* Supported systems */
226 #define TGT_ATARI 1 /* Atari 8 bit machines */
231 #define TGT_CBM610 6 /* CBM 600/700 family */
232 #define TGT_PET 7 /* CBM PET family */
233 #define TGT_NES 8 /* Nintendo Entertainment System */
236 #define TGT_APPLE2 11
238 #define TGT_COUNT 13 /* Count of supported systems */
242 /* Structure describing a target */
243 typedef struct TargetCfg_ TargetCfg;
245 const char* Name; /* Name of the system */
246 unsigned char BinFmt; /* Default binary format for the target */
247 const char* Cfg; /* Pointer to configuration */
250 static const TargetCfg Targets [TGT_COUNT] = {
251 { "none", BINFMT_BINARY, CfgNone },
252 { "atari", BINFMT_BINARY, CfgAtari },
253 { "c64", BINFMT_BINARY, CfgC64 },
254 { "c128", BINFMT_BINARY, CfgC128 },
255 { "ace", BINFMT_BINARY, CfgAce },
256 { "plus4", BINFMT_BINARY, CfgPlus4 },
257 { "cbm610", BINFMT_BINARY, CfgCBM610 },
258 { "pet", BINFMT_BINARY, CfgPET },
259 { "nes", BINFMT_BINARY, CfgNES },
260 { "lunix", BINFMT_O65, CfgLunix },
261 { "osa65", BINFMT_O65, CfgOSA65 },
262 { "apple2", BINFMT_BINARY, CfgApple2 },
263 { "geos", BINFMT_BINARY, CfgGeos },
266 /* Selected target system type */
267 static const TargetCfg* Target;
271 /*****************************************************************************/
273 /*****************************************************************************/
277 static int StrICmp (const char* S1, const char* S2)
278 /* Compare two strings case insensitive */
282 Diff = tolower (*S1) - tolower (*S2);
283 if (Diff != 0 || *S1 == '\0') {
293 static int TgtMap (const char* Name)
294 /* Map a target name to a system code. Return -1 in case of an error */
298 /* Check for a numeric target */
299 if (isdigit (*Name)) {
300 int Target = atoi (Name);
301 if (Target >= 0 && Target < TGT_COUNT) {
306 /* Check for a target string */
307 for (I = 0; I < TGT_COUNT; ++I) {
308 if (StrICmp (Targets [I].Name, Name) == 0) {
319 void TgtSet (const char* T)
320 /* Set the target system, initialize internal stuff for this target */
322 /* Map the target to a number */
323 int TgtNum = TgtMap (T);
325 Error ("Invalid target system: %s", T);
327 Target = &Targets [TgtNum];
329 /* Set the target data */
330 DefaultBinFmt = Target->BinFmt;
331 CfgSetBuf (Target->Cfg);
336 void TgtPrintList (FILE* F)
337 /* Print a list of the available target systems */
342 fprintf (F, "Available targets:\n");
344 /* Print a list of the target systems */
345 for (I = 0; I < TGT_COUNT; ++I) {
346 fprintf (F, " %s\n", Targets [I].Name);