5 static char _z80_defaultRules[] =
8 #include "peeph-z80.rul"
11 static char _gbz80_defaultRules[] =
14 #include "peeph-gbz80.rul"
31 /* determine if we can register a parameter */
36 static char *_keywords[] =
44 extern PORT gbz80_port;
52 z80_opts.sub = SUB_Z80;
53 asm_addTree (&_asxxxx_z80);
59 z80_opts.sub = SUB_GBZ80;
69 _reg_parm (sym_link * l)
71 if (options.noRegParams)
77 if (_G.regParams == 2)
90 _startsWith (const char *sz, const char *key)
92 return !strncmp (sz, key, strlen (key));
99 while ((nl = strrchr (sz, '\n')))
104 _process_pragma (const char *sz)
106 if (_startsWith (sz, "bank="))
109 strcpy (buffer, sz + 5);
111 if (isdigit (buffer[0]))
115 else if (!strcmp (buffer, "BASE"))
117 strcpy (buffer, "HOME");
119 if (isdigit (buffer[0]))
121 /* Arg was a bank number. Handle in an ASM independent
124 strcpy (num, sz + 5);
129 case ASM_TYPE_ASXXXX:
130 sprintf (buffer, "CODE_%s", num);
133 sprintf (buffer, "CODE,BANK[%s]", num);
136 /* PENDING: what to use for ISAS? */
137 sprintf (buffer, "CODE,BANK(%s)", num);
143 gbz80_port.mem.code_name = gc_strdup (buffer);
144 code->sname = gbz80_port.mem.code_name;
150 static const char *_gbz80_rgbasmCmd[] =
152 "rgbasm", "-o$1.o", "$1.asm", NULL
155 static const char *_gbz80_rgblinkCmd[] =
157 "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL
161 _gbz80_rgblink (void)
171 /* first we need to create the <filename>.lnk file */
172 sprintf (scratchFileName, "%s.lnk", sz);
173 if (!(lnkfile = fopen (scratchFileName, "w")))
175 werror (E_FILE_OPEN_ERR, scratchFileName);
179 fprintf (lnkfile, "[Objects]\n");
182 fprintf (lnkfile, "%s.o\n", sz);
184 for (i = 0; i < nrelFiles; i++)
185 fprintf (lnkfile, "%s\n", relFiles[i]);
187 fprintf (lnkfile, "\n[Libraries]\n");
188 /* additional libraries if any */
189 for (i = 0; i < nlibFiles; i++)
190 fprintf (lnkfile, "%s\n", libFiles[i]);
193 fprintf (lnkfile, "\n[Output]\n" "%s.gb", sz);
197 buildCmdLine (buffer,port->linker.cmd, sz, NULL, NULL, NULL);
198 /* call the linker */
199 if (my_system (buffer))
201 perror ("Cannot exec linker");
207 _parseOptions (int *pargc, char **argv, int *i)
209 if (argv[*i][0] == '-')
211 if (argv[*i][1] == 'b' && IS_GB)
213 int bank = atoi (argv[*i] + 3);
219 sprintf (buffer, "CODE_%u", bank);
220 gbz80_port.mem.code_name = gc_strdup (buffer);
224 sprintf (buffer, "DATA_%u", bank);
225 gbz80_port.mem.data_name = gc_strdup (buffer);
229 else if (!strncmp (argv[*i], "--asm=", 6))
231 if (!strcmp (argv[*i], "--asm=rgbds"))
233 asm_addTree (&_rgbds_gb);
234 gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
235 gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
236 gbz80_port.linker.do_link = _gbz80_rgblink;
237 _G.asmType = ASM_TYPE_RGBDS;
240 else if (!strcmp (argv[*i], "--asm=asxxxx"))
242 _G.asmType = ASM_TYPE_ASXXXX;
245 else if (!strcmp (argv[*i], "--asm=isas"))
247 asm_addTree (&_isas_gb);
248 /* Munge the function prefix */
249 gbz80_port.fun_prefix = "";
250 _G.asmType = ASM_TYPE_ISAS;
259 _finaliseOptions (void)
261 port->mem.default_local_map = data;
262 port->mem.default_globl_map = data;
263 if (_G.asmType == ASM_TYPE_ASXXXX && IS_GB)
264 asm_addTree (&_asxxxx_gb);
268 _setDefaultOptions (void)
270 options.genericPtr = 1; /* default on */
272 options.stackAuto = 1;
273 options.mainreturn = 1;
274 /* first the options part */
275 options.intlong_rent = 1;
276 options.noRegParams = 1;
277 /* Default code and data locations. */
278 options.code_loc = 0x200;
282 options.data_loc = 0xC000;
286 options.data_loc = 0x8000;
289 optimize.global_cse = 1;
294 optimize.loopInvariant = 1;
295 optimize.loopInduction = 1;
301 policy is the function policy
302 params is the parameter format
307 r is 'r' for reentrant, 's' for static functions
308 s is 'c' for callee saves, 'r' for caller saves
309 p is 'p' for profiling on, 'x' for profiling off
311 rr - reentrant, caller saves
313 A combination of register short names and s to signify stack variables.
315 bds - first two args appear in BC and DE, the rest on the stack
316 s - all arguments are on the stack.
319 _mangleSupportFunctionName(char *original)
323 sprintf(buffer, "%s_rr%s_%s", original,
324 options.profile ? "f" : "x",
325 options.noRegParams ? "s" : "bds"
328 return gc_strdup(buffer);
332 _getRegName (struct regs *reg)
342 /** $1 is always the basename.
343 $2 is always the output file.
345 $l is the list of extra options that should be there somewhere...
346 MUST be terminated with a NULL.
348 static const char *_z80_asmCmd[] =
357 static const char *_z80_linkCmd[] =
360 "-n", // Don't echo output
361 "-c", // Command line input
362 "--", // Again, command line input...
363 "-b_CODE=0x200", // Code starts at 0x200
364 "-b_DATA=0x8000", // RAM starts at 0x8000
365 "-j", // Output a symbol file as well
366 "-k" SDCC_LIB_DIR "/z80", // Library path
367 "-lz80.lib", // Library to use
368 "-i", // Output Intel IHX
369 "$1.ihx", // Output to
370 SDCC_LIB_DIR "/z80/crt0.o", // Link in crt0 first
371 "$1.o", // Actual code
375 static const char *_gbz80_asmCmd[] =
384 static const char *_gbz80_linkCmd[] =
387 "-n", // Don't echo output
388 "-c", // Command line input
389 "--", // Again, command line input...
390 "-b_CODE=0x200", // Code starts at 0x200
391 "-b_DATA=0xC000", // RAM starts at 0xC000
392 "-j", // Output a symbol file as well
393 "-k" SDCC_LIB_DIR "/gbz80", // Library path
394 "-lgbz80.lib", // Library to use
395 "-z", // Output Gameboy image
396 "$1.gb", // Output to
397 SDCC_LIB_DIR "/gbz80/crt0.o",// Link in crt0 first
398 "$1.o", // Actual code
402 /* sprintf that appends to the string. */
404 _saprintf(char *pinto, const char *format, ...)
407 va_start(ap, format);
409 vsprintf(pinto + strlen(pinto), format, ap);
414 _link(const char *portName, const char *portExt, const char *portOutputType)
422 "-n " // Don't echo output
423 "-c " // Command line input
424 "-- " // Again, command line input...
425 "-b_CODE=0x%04X " // Code starts at 0x200
426 "-b_DATA=0x%04X " // RAM starts at 0x8000
427 "-j ", // Output a symbol file as well
433 // Add the standard lib in.
434 if (options.nostdlib == FALSE) {
436 "-k" SDCC_LIB_DIR "/%s " // Library path
437 "-l%s.lib ", // Library to use
442 // Add in the library paths and libraries
443 for (i = 0; i < nlibFiles; i++) {
444 _saprintf(buffer, "-k%s ", libFiles[i]);
446 for (i = 0; i < nlibPaths; i++) {
447 _saprintf(buffer, "-l%s ", libPaths[i]);
451 "-%s " // Output type
452 "%s.%s ", // Output to
453 portOutputType, srcFileName, portExt
456 if (options.nostdlib == FALSE) {
458 SDCC_LIB_DIR "/%s/crt0.o ", // Link in crt0 first
464 "%s.o ", // Actual code
468 // Append all the other targets
469 for (i = 0; i < nrelFiles; i++) {
470 _saprintf(buffer, "%s ", relFiles[i]);
474 if (my_system (buffer)) {
482 _link("z80", "ihx", "i");
488 _link("gbz80", "gb", "z");
496 "Zilog Z80", /* Target name */
499 MODEL_MEDIUM | MODEL_SMALL,
504 "-plosgff", /* Options with debug */
505 "-plosgff", /* Options without debug */
518 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
519 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
541 /* Z80 has no native mul/div commands */
553 0, /* no assembler preamble */
554 0, /* no local IVT generation code */
558 _mangleSupportFunctionName,
562 1, /* transform <= to ! > */
563 1, /* transform >= to ! < */
564 1, /* transform != to !(a == b) */
566 TRUE, /* Array initializer support. */
575 "Gameboy Z80-like", /* Target name */
578 MODEL_MEDIUM | MODEL_SMALL,
583 "-plosgff", /* Options with debug */
584 "-plosgff", /* Options without debug */
597 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
598 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
620 /* gbZ80 has no native mul/div commands */
632 0, /* no assembler preamble */
633 0, /* no local IVT generation code */
637 _mangleSupportFunctionName,
641 1, /* transform <= to ! > */
642 1, /* transform >= to ! < */
643 1, /* transform != to !(a == b) */
645 FALSE, /* No array initializer support. */