X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fz80%2Fmain.c;h=aa8d569c15f16641d644652b6912a8138f2068db;hb=a5fa21b3861557338d6c86d37992b018c582b449;hp=45ebf1a67badb25958b7e4aa7028d6a513c0c5a2;hpb=b4d69dfd516f175255aa87b18b59dcf309d98b46;p=fw%2Fsdcc diff --git a/src/z80/main.c b/src/z80/main.c index 45ebf1a6..aa8d569c 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -1,4 +1,6 @@ #include "z80.h" +#include "MySystem.h" +#include "BuildCmd.h" static char _z80_defaultRules[] = { @@ -66,11 +68,22 @@ _reset_regparm () static int _reg_parm (sym_link * l) { - if (regParmFlg == 2) - return 0; - - regParmFlg++; - return 1; + if (options.noRegParams) + { + return FALSE; + } + else + { + if (regParmFlg == 2) + { + return FALSE; + } + else + { + regParmFlg++; + return TRUE; + } + } } static bool @@ -149,7 +162,6 @@ _gbz80_rgblink (void) { FILE *lnkfile; const char *sz; - char *argv[128]; int i; sz = srcFileName; @@ -157,10 +169,10 @@ _gbz80_rgblink (void) sz = "a"; /* first we need to create the .lnk file */ - sprintf (buffer, "%s.lnk", sz); - if (!(lnkfile = fopen (buffer, "w"))) + sprintf (scratchFileName, "%s.lnk", sz); + if (!(lnkfile = fopen (scratchFileName, "w"))) { - werror (E_FILE_OPEN_ERR, buffer); + werror (E_FILE_OPEN_ERR, scratchFileName); exit (1); } @@ -182,9 +194,9 @@ _gbz80_rgblink (void) fclose (lnkfile); - buildCmdLine (buffer, argv, port->linker.cmd, sz, NULL, NULL, NULL); + buildCmdLine (buffer,port->linker.cmd, sz, NULL, NULL, NULL); /* call the linker */ - if (my_system (argv[0], argv)) + if (my_system (buffer)) { perror ("Cannot exec linker"); exit (1); @@ -259,10 +271,12 @@ _setDefaultOptions (void) options.nopeep = 0; options.stackAuto = 1; options.mainreturn = 1; - options.noregparms = 1; - options.nodebug = 1; /* first the options part */ options.intlong_rent = 1; + options.noRegParams = 1; + /* Default code and data locations. */ + options.code_loc = 0x200; + options.data_loc = 0x8000; optimize.global_cse = 1; optimize.label1 = 1; @@ -273,6 +287,49 @@ _setDefaultOptions (void) optimize.loopInduction = 0; } +/* Mangaling format: + _fun_policy_params + where: + policy is the function policy + params is the parameter format + + policy format: + rs + where: + r is 'r' for reentrant, 's' for static functions + s is 'c' for callee saves, 'r' for caller saves + examples: + rr - reentrant, caller saves + params format: + A combination of register short names and s to signify stack variables. + examples: + bds - first two args appear in BC and DE, the rest on the stack + s - all arguments are on the stack. +*/ +static char * +_mangleSupportFunctionName(char *original) +{ + char buffer[128]; + + if (TARGET_IS_Z80) + { + if (options.noRegParams) + { + sprintf(buffer, "%s_rr_s", original); + } + else + { + sprintf(buffer, "%s_rr_bds", original); + } + } + else + { + strcpy(buffer, original); + } + + return gc_strdup(buffer); +} + static const char * _getRegName (struct regs *reg) { @@ -290,12 +347,99 @@ _getRegName (struct regs *reg) */ static const char *_z80_linkCmd[] = { - "link-z80", "-nf", "$1", NULL + "link-z80", + "-n", // Don't echo output + "-c", // Command line input + "--", // Again, command line input... + "-b_CODE=0x200", // Code starts at 0x200 + "-b_DATA=0x8000", // RAM starts at 0x8000 + "-j", // Output a symbol file as well + "-k" SDCC_LIB_DIR "/z80", // Library path + "-lz80.lib", // Library to use + "-i", // Output Intel IHX + "$1.ihx", // Output to + SDCC_LIB_DIR "/z80/crt0.o", // Link in crt0 first + "$1.o", // Actual code + NULL }; +/* sprintf that appends to the string. */ +static void +_saprintf(char *pinto, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + + vsprintf(pinto + strlen(pinto), format, ap); + va_end(ap); +} + +static void +_z80_link(void) +{ + int i; + // PENDING + char buffer[2048]; + + sprintf(buffer, + "link-z80 " + "-n " // Don't echo output + "-c " // Command line input + "-- " // Again, command line input... + "-b_CODE=0x%04X " // Code starts at 0x200 + "-b_DATA=0x%04X " // RAM starts at 0x8000 + "-j ", // Output a symbol file as well + options.code_loc, + options.data_loc + ); + + // Add the standard lib in. + if (options.nostdlib == FALSE) { + _saprintf(buffer, + "-k" SDCC_LIB_DIR "/z80 " // Library path + "-lz80.lib " // Library to use + ); + } + + // Add in the library paths and libraries + for (i = 0; i < nlibFiles; i++) { + _saprintf(buffer, "-k%s ", libFiles[i]); + } + for (i = 0; i < nlibPaths; i++) { + _saprintf(buffer, "-l%s ", libPaths[i]); + } + + _saprintf(buffer, + "-i " // Output Intel IHX + "%s.ihx ", // Output to + srcFileName + ); + + if (options.nostdlib == FALSE) { + _saprintf(buffer, + SDCC_LIB_DIR "/z80/crt0.o " // Link in crt0 first + ); + } + + _saprintf(buffer, + "%s.o ", // Actual code + srcFileName + ); + + // Append all the other targets + for (i = 0; i < nrelFiles; i++) { + _saprintf(buffer, "%s ", relFiles[i]); + } + + // Do it. + if (my_system (buffer)) { + exit(1); + } +} + static const char *_z80_asmCmd[] = { - "as-z80", "-plosgff", "$1.o", "$1.asm", NULL + "as-z80", "-plosgff", "$1.o", "$1.asm", NULL }; /** $1 is always the basename. @@ -306,17 +450,19 @@ static const char *_z80_asmCmd[] = */ static const char *_gbz80_linkCmd[] = { - "link-gbz80", "-nf", "$1", NULL + // PENDING + "link-gbz80", "-nf", "$1", NULL }; static const char *_gbz80_asmCmd[] = { - "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL + "as-gbz80", "-plosgff", "$1.o", "$1.asm", NULL }; /* Globals */ PORT z80_port = { + TARGET_ID_Z80, "z80", "Zilog Z80", /* Target name */ { @@ -328,10 +474,12 @@ PORT z80_port = _z80_asmCmd, "-plosgff", /* Options with debug */ "-plosgff", /* Options without debug */ + 0, + ".asm" }, { _z80_linkCmd, - NULL, + _z80_link, ".o" }, { @@ -339,7 +487,7 @@ PORT z80_port = }, { /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */ - 1, 1, 2, 4, 2, 2, 2, 1, 4, 4 + 1, 2, 2, 4, 2, 2, 2, 1, 4, 4 }, { "XSEG", @@ -363,7 +511,7 @@ PORT z80_port = }, /* Z80 has no native mul/div commands */ { - 0, 2 + 0, 0 }, "_", _z80_init, @@ -378,6 +526,7 @@ PORT z80_port = _reset_regparm, _reg_parm, _process_pragma, + _mangleSupportFunctionName, TRUE, 0, /* leave lt */ 0, /* leave gt */ @@ -391,6 +540,7 @@ PORT z80_port = /* Globals */ PORT gbz80_port = { + TARGET_ID_GBZ80, "gbz80", "Gameboy Z80-like", /* Target name */ { @@ -402,7 +552,8 @@ PORT gbz80_port = _gbz80_asmCmd, "-plosgff", /* Options with debug */ "-plosgff", /* Options without debug */ - 1 + 1, + ".asm" }, { _gbz80_linkCmd, @@ -453,6 +604,7 @@ PORT gbz80_port = _reset_regparm, _reg_parm, _process_pragma, + NULL, TRUE, 0, /* leave lt */ 0, /* leave gt */