X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fz80%2Fmain.c;h=8fb6b0a2d18ef96d13784d134f62ddb09dbb1e97;hb=d2da99feec099aa224e1db53bc5a1ed42ed51ec9;hp=233574c1d9fcc312101d54ea2f67c654ac8db815;hpb=1e54c930f2ad6e63663ca207e1b410b442c10bd9;p=fw%2Fsdcc diff --git a/src/z80/main.c b/src/z80/main.c index 233574c1..8fb6b0a2 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -22,10 +22,12 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ +#include #include "z80.h" #include "MySystem.h" #include "BuildCmd.h" #include "SDCCutil.h" +#include "dbuf.h" static char _z80_defaultRules[] = { @@ -43,8 +45,15 @@ Z80_OPTS z80_opts; static OPTION _z80_options[] = { - { 0, "--callee-saves-bc", &z80_opts.calleeSavesBC, "Force a called function to always save BC" }, - { 0, NULL } + { 0, "--callee-saves-bc", &z80_opts.calleeSavesBC, "Force a called function to always save BC" }, + { 0, "--portmode=", NULL, "Determine PORT I/O mode (z80/z180)" }, + { 0, NULL } + }; + +static OPTION _gbz80_options[] = + { + { 0, "--callee-saves-bc", &z80_opts.calleeSavesBC, "Force a called function to always save BC" }, + { 0, NULL } }; typedef enum @@ -70,6 +79,9 @@ static char *_keywords[] = "sfr", "nonbanked", "banked", + "at", //.p.t.20030714 adding support for 'sfr at ADDR' construct + "_naked", //.p.t.20030714 adding support for '_naked' functions + "critical", NULL }; @@ -100,7 +112,7 @@ _gbz80_init (void) } static void -_reset_regparm () +_reset_regparm (void) { _G.regParams = 0; } @@ -125,33 +137,38 @@ _reg_parm (sym_link * l) } } } - static int _process_pragma (const char *sz) { - if (startsWith (sz, "bank=")) + if( startsWith( sz, "bank=" ) || startsWith( sz, "bank " )) + { + char buffer[128]; + + if (sz[4]=='=') + werror(W_DEPRECATED_PRAGMA, "bank="); + + strncpy (buffer, sz + 5, sizeof (buffer)); + buffer[sizeof (buffer) - 1 ] = '\0'; + chomp (buffer); + if (isdigit (buffer[0])) { - char buffer[128]; - strcpy (buffer, sz + 5); - chomp (buffer); - if (isdigit (buffer[0])) - { - } - else if (!strcmp (buffer, "BASE")) - { - strcpy (buffer, "HOME"); - } - if (isdigit (buffer[0])) - { + } + else if (!strcmp (buffer, "BASE")) + { + strcpy (buffer, "HOME"); + } + if (isdigit (buffer[0])) + { /* Arg was a bank number. Handle in an ASM independent way. */ - char num[128]; - strcpy (num, sz + 5); - chomp (num); + char num[128]; + strncpy (num, sz + 5, sizeof (num)); + num[sizeof (num) -1] = '\0'; + chomp (num); - switch (_G.asmType) - { + switch (_G.asmType) + { case ASM_TYPE_ASXXXX: sprintf (buffer, "CODE_%s", num); break; @@ -164,12 +181,32 @@ _process_pragma (const char *sz) break; default: wassert (0); - } - } - gbz80_port.mem.code_name = Safe_strdup (buffer); - code->sname = gbz80_port.mem.code_name; - return 0; + } } + gbz80_port.mem.code_name = Safe_strdup (buffer); + code->sname = gbz80_port.mem.code_name; + return 0; + } + else if( startsWith( sz, "portmode=" ) || startsWith( sz, "portmode " )) + { /*.p.t.20030716 - adding pragma to manipulate z80 i/o port addressing modes */ + char bfr[128]; + + if (sz[8]=='=') + werror(W_DEPRECATED_PRAGMA, "portmode="); + + strncpy( bfr, sz + 9, sizeof (bfr)); + bfr[sizeof (bfr) - 1] = '\0'; + chomp( bfr ); + + if ( !strcmp( bfr, "z80" )){ z80_opts.port_mode = 80; } + else if( !strcmp( bfr, "z180" )){ z80_opts.port_mode = 180; } + else if( !strcmp( bfr, "save" )){ z80_opts.port_back = z80_opts.port_mode; } + else if( !strcmp( bfr, "restore" )){ z80_opts.port_mode = z80_opts.port_back; } + else return( 1 ); + + return( 0 ); + } + return 1; } @@ -274,6 +311,19 @@ _parseOptions (int *pargc, char **argv, int *i) return TRUE; } } + else if (!strncmp (argv[*i], "--portmode=", 11)) + { + if (!strcmp (argv[*i], "--portmode=z80")) + { + z80_opts.port_mode = 80; + return TRUE; + } + else if (!strcmp (argv[*i], "--portmode=z180")) + { + z80_opts.port_mode = 180; + return TRUE; + } + } } return FALSE; } @@ -285,8 +335,44 @@ _setValues(void) if (options.nostdlib == FALSE) { - setMainValue ("z80libspec", "-l\"{port}.lib\""); - setMainValue ("z80crt0", "\"crt0{objext}\""); + const char *s; + char path[PATH_MAX]; + struct dbuf_s dbuf; + + dbuf_init(&dbuf, PATH_MAX); + + for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet)) + { + buildCmdLine2(path, sizeof path, "-k\"%s" DIR_SEPARATOR_STRING "{port}\" ", s); + dbuf_append(&dbuf, path, strlen(path)); + } + buildCmdLine2(path, sizeof path, "-l\"{port}.lib\"", s); + dbuf_append(&dbuf, path, strlen(path)); + + setMainValue ("z80libspec", dbuf_c_str(&dbuf)); + dbuf_destroy(&dbuf); + + for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet)) + { + struct stat stat_buf; + + buildCmdLine2(path, sizeof path, "%s" DIR_SEPARATOR_STRING "{port}" DIR_SEPARATOR_STRING "crt0{objext}", s); + if (stat(path, &stat_buf) == 0) + break; + } + + if (s == NULL) + setMainValue ("z80crt0", "\"crt0{objext}\""); + else + { + char *buf; + size_t len = strlen(path) + 3; + + buf = Safe_alloc(len); + SNPRINTF(buf, len, "\"%s\"", path); + setMainValue("z80crt0", buf); + Safe_free(buf); + } } else { @@ -440,6 +526,29 @@ _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right) return FALSE; } +/* Indicate which extended bit operations this port supports */ +static bool +hasExtBitOp (int op, int size) +{ + if (op == GETHBIT) + return TRUE; + else + return FALSE; +} + +/* Indicate the expense of an access to an output storage class */ +static int +oclsExpense (struct memmap *oclass) +{ + if (IN_FARSPACE(oclass)) + return 1; + + return 0; +} + + +#define LINKCMD "link-{port} -nf {dstfilename}" +/* #define LINKCMD \ "link-{port} -n -c -- {z80bases} -m -j" \ " {z80libspec}" \ @@ -448,6 +557,7 @@ _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right) " {z80crt0}" \ " \"{dstfilename}{objext}\"" \ " {z80extraobj}" +*/ #define ASMCMD \ "as-{port} -plosgff \"{objdstfilename}\" \"{dstfilename}{asmext}\"" @@ -460,6 +570,7 @@ PORT z80_port = "Zilog Z80", /* Target name */ NULL, /* Processor name */ { + glue, FALSE, MODEL_MEDIUM | MODEL_SMALL, MODEL_SMALL @@ -476,7 +587,8 @@ PORT z80_port = NULL, LINKCMD, NULL, - ".o" + ".o", + 1 }, { _z80_defaultRules @@ -491,6 +603,7 @@ PORT z80_port = "CODE", "DATA", "ISEG", + NULL, /* pdata */ "XSEG", "BSEG", "RSEG", @@ -504,6 +617,7 @@ PORT z80_port = NULL, 1 }, + { NULL, NULL }, { -1, 0, 0, 4, 0, 2 }, @@ -511,10 +625,24 @@ PORT z80_port = { 0, 2 }, + { + z80_emitDebuggerSymbol + }, + { + 255, /* maxCount */ + 3, /* sizeofElement */ + /* The rest of these costs are bogus. They approximate */ + /* the behavior of src/SDCCicode.c 1.207 and earlier. */ + {4,4,4}, /* sizeofMatchJump[] */ + {0,0,0}, /* sizeofRangeCompare[] */ + 0, /* sizeofSubtract */ + 3, /* sizeofDispatch */ + }, "_", _z80_init, _parseOptions, _z80_options, + NULL, _finaliseOptions, _setDefaultOptions, z80_assignRegisters, @@ -524,12 +652,16 @@ PORT z80_port = NULL, /* no genAssemblerEnd */ 0, /* no local IVT generation code */ 0, /* no genXINIT code */ + NULL, /* genInitStartup */ _reset_regparm, _reg_parm, _process_pragma, _mangleSupportFunctionName, _hasNativeMulFor, + hasExtBitOp, /* hasExtBitOp */ + oclsExpense, /* oclsExpense */ TRUE, + TRUE, /* little endian */ 0, /* leave lt */ 0, /* leave gt */ 1, /* transform <= to ! > */ @@ -553,6 +685,7 @@ PORT gbz80_port = "Gameboy Z80-like", /* Target name */ NULL, { + glue, FALSE, MODEL_MEDIUM | MODEL_SMALL, MODEL_SMALL @@ -570,7 +703,8 @@ PORT gbz80_port = NULL, LINKCMD, NULL, - ".o" + ".o", + 1 }, { _gbz80_defaultRules @@ -585,6 +719,7 @@ PORT gbz80_port = "CODE", "DATA", "ISEG", + NULL, /* pdata */ "XSEG", "BSEG", "RSEG", @@ -598,6 +733,7 @@ PORT gbz80_port = NULL, 1 }, + { NULL, NULL }, { -1, 0, 0, 2, 0, 4 }, @@ -605,10 +741,24 @@ PORT gbz80_port = { 0, 2 }, + { + z80_emitDebuggerSymbol + }, + { + 255, /* maxCount */ + 3, /* sizeofElement */ + /* The rest of these costs are bogus. They approximate */ + /* the behavior of src/SDCCicode.c 1.207 and earlier. */ + {4,4,4}, /* sizeofMatchJump[] */ + {0,0,0}, /* sizeofRangeCompare[] */ + 0, /* sizeofSubtract */ + 3, /* sizeofDispatch */ + }, "_", _gbz80_init, _parseOptions, - _z80_options, + _gbz80_options, + NULL, _finaliseOptions, _setDefaultOptions, z80_assignRegisters, @@ -618,12 +768,16 @@ PORT gbz80_port = NULL, /* no genAssemblerEnd */ 0, /* no local IVT generation code */ 0, /* no genXINIT code */ + NULL, /* genInitStartup */ _reset_regparm, _reg_parm, _process_pragma, _mangleSupportFunctionName, _hasNativeMulFor, + hasExtBitOp, /* hasExtBitOp */ + oclsExpense, /* oclsExpense */ TRUE, + TRUE, /* little endian */ 0, /* leave lt */ 0, /* leave gt */ 1, /* transform <= to ! > */