5 static char _z80_defaultRules[] =
8 #include "peeph-z80.rul"
11 static char _gbz80_defaultRules[] =
14 #include "peeph-gbz80.rul"
34 static char *_keywords[] =
42 extern PORT gbz80_port;
50 z80_opts.sub = SUB_Z80;
51 asm_addTree (&_asxxxx_z80);
57 z80_opts.sub = SUB_GBZ80;
60 static int regParmFlg = 0; /* determine if we can register a parameter */
69 _reg_parm (sym_link * l)
71 if (options.noRegParams)
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;
279 options.data_loc = 0x8000;
281 optimize.global_cse = 1;
286 optimize.loopInvariant = 1;
287 optimize.loopInduction = 0;
293 policy is the function policy
294 params is the parameter format
299 r is 'r' for reentrant, 's' for static functions
300 s is 'c' for callee saves, 'r' for caller saves
302 rr - reentrant, caller saves
304 A combination of register short names and s to signify stack variables.
306 bds - first two args appear in BC and DE, the rest on the stack
307 s - all arguments are on the stack.
310 _mangleSupportFunctionName(char *original)
316 if (options.noRegParams)
318 sprintf(buffer, "%s_rr_s", original);
322 sprintf(buffer, "%s_rr_bds", original);
327 strcpy(buffer, original);
330 return gc_strdup(buffer);
334 _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_linkCmd[] =
351 "-n", // Don't echo output
352 "-c", // Command line input
353 "--", // Again, command line input...
354 "-b_CODE=0x200", // Code starts at 0x200
355 "-b_DATA=0x8000", // RAM starts at 0x8000
356 "-j", // Output a symbol file as well
357 "-k" SDCC_LIB_DIR "/z80", // Library path
358 "-lz80.lib", // Library to use
359 "-i", // Output Intel IHX
360 "$1.ihx", // Output to
361 SDCC_LIB_DIR "/z80/crt0.o", // Link in crt0 first
362 "$1.o", // Actual code
366 /* sprintf that appends to the string. */
368 _saprintf(char *pinto, const char *format, ...)
371 va_start(ap, format);
373 vsprintf(pinto + strlen(pinto), format, ap);
386 "-n " // Don't echo output
387 "-c " // Command line input
388 "-- " // Again, command line input...
389 "-b_CODE=0x%04X " // Code starts at 0x200
390 "-b_DATA=0x%04X " // RAM starts at 0x8000
391 "-j ", // Output a symbol file as well
396 // Add the standard lib in.
397 if (options.nostdlib == FALSE) {
399 "-k" SDCC_LIB_DIR "/z80 " // Library path
400 "-lz80.lib " // Library to use
404 // Add in the library paths and libraries
405 for (i = 0; i < nlibFiles; i++) {
406 _saprintf(buffer, "-k%s ", libFiles[i]);
408 for (i = 0; i < nlibPaths; i++) {
409 _saprintf(buffer, "-l%s ", libPaths[i]);
413 "-i " // Output Intel IHX
414 "%s.ihx ", // Output to
418 if (options.nostdlib == FALSE) {
420 SDCC_LIB_DIR "/z80/crt0.o " // Link in crt0 first
425 "%s.o ", // Actual code
429 // Append all the other targets
430 for (i = 0; i < nrelFiles; i++) {
431 _saprintf(buffer, "%s ", relFiles[i]);
435 if (my_system (buffer)) {
440 static const char *_z80_asmCmd[] =
442 "as-z80", "-plosgff", "$1.o", "$1.asm", NULL
445 /** $1 is always the basename.
446 $2 is always the output file.
448 $l is the list of extra options that should be there somewhere...
449 MUST be terminated with a NULL.
451 static const char *_gbz80_linkCmd[] =
454 "link-gbz80", "-nf", "$1", NULL
457 static const char *_gbz80_asmCmd[] =
459 "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL
467 "Zilog Z80", /* Target name */
470 MODEL_MEDIUM | MODEL_SMALL,
475 "-plosgff", /* Options with debug */
476 "-plosgff", /* Options without debug */
489 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
490 1, 2, 2, 4, 2, 2, 2, 1, 4, 4
512 /* Z80 has no native mul/div commands */
524 0, /* no assembler preamble */
525 0, /* no local IVT generation code */
529 _mangleSupportFunctionName,
533 1, /* transform <= to ! > */
534 1, /* transform >= to ! < */
535 1, /* transform != to !(a == b) */
545 "Gameboy Z80-like", /* Target name */
548 MODEL_MEDIUM | MODEL_SMALL,
553 "-plosgff", /* Options with debug */
554 "-plosgff", /* Options without debug */
567 /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
568 1, 1, 2, 4, 2, 2, 2, 1, 4, 4
590 /* gbZ80 has no native mul/div commands */
602 0, /* no assembler preamble */
603 0, /* no local IVT generation code */
611 1, /* transform <= to ! > */
612 1, /* transform >= to ! < */
613 1, /* transform != to !(a == b) */