From 7e85609884eda439265cfc7f140fe9e8303892d5 Mon Sep 17 00:00:00 2001 From: michaelh Date: Wed, 12 Jul 2000 02:04:31 +0000 Subject: [PATCH] Merge out from the z80 far branch git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@294 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- link/z80/aslink.h | 30 +++++++-------- link/z80/lklist.c | 10 +++-- link/z80/lkmain.c | 1 - src/SDCCerr.c | 3 +- src/SDCCerr.h | 2 + src/SDCCglobl.h | 11 ++++++ src/SDCCglue.c | 18 ++++----- src/SDCCmain.c | 23 ++++++++---- src/SDCCmem.c | 6 ++- src/SDCCsymt.c | 4 +- src/asm.c | 5 ++- src/avr/main.c | 6 ++- src/mcs51/main.c | 6 ++- src/port.h | 7 ++++ src/z80/gen.c | 91 +++++++++++++++++++++++++++++++++++++++++----- src/z80/main.c | 72 +++++++++++++++++++++++++++++++++--- src/z80/mappings.i | 81 +++++++++++++++-------------------------- src/z80/ralloc.c | 10 ++--- src/z80/z80.h | 2 +- 19 files changed, 271 insertions(+), 117 deletions(-) diff --git a/link/z80/aslink.h b/link/z80/aslink.h index c241194d..04ddecbe 100644 --- a/link/z80/aslink.h +++ b/link/z80/aslink.h @@ -105,30 +105,30 @@ * +-----+-----+-----+-----+-----+-----+-----+-----+ */ -#define R_WORD 0000 /* 16 bit */ -#define R_BYTE 0001 /* 8 bit */ +#define R_WORD 0x00 /* 16 bit */ +#define R_BYTE 0x01 /* 8 bit */ -#define R_AREA 0000 /* Base type */ -#define R_SYM 0002 +#define R_AREA 0x00 /* Base type */ +#define R_SYM 0x02 -#define R_NORM 0000 /* PC adjust */ -#define R_PCR 0004 +#define R_NORM 0x00 /* PC adjust */ +#define R_PCR 0x04 -#define R_BYT1 0000 /* Byte count for R_BYTE = 1 */ -#define R_BYT2 0010 /* Byte count for R_BYTE = 2 */ +#define R_BYT1 0x00 /* Byte count for R_BYTE = 1 */ +#define R_BYT2 0x08 /* Byte count for R_BYTE = 2 */ -#define R_SGND 0000 /* Signed value */ -#define R_USGN 0020 /* Unsigned value */ +#define R_SGND 0x00 /* Signed value */ +#define R_USGN 0x10 /* Unsigned value */ -#define R_NOPAG 0000 /* Page Mode */ -#define R_PAG0 0040 /* Page '0' */ -#define R_PAG 0100 /* Page 'nnn' */ +#define R_NOPAG 0x00 /* Page Mode */ +#define R_PAG0 0x20 /* Page '0' */ +#define R_PAG 0x40 /* Page 'nnn' */ /* * Valid for R_BYT2: */ -#define R_LSB 0000 /* output low byte */ -#define R_MSB 0200 /* output high byte */ +#define R_LSB 0x00 /* output low byte */ +#define R_MSB 0x80 /* output high byte */ /* * Global symbol types. diff --git a/link/z80/lklist.c b/link/z80/lklist.c index 46ac9199..4f907ff7 100644 --- a/link/z80/lklist.c +++ b/link/z80/lklist.c @@ -753,14 +753,18 @@ VOID lstareatosym(struct area *xp) } i = 0; while (i < nmsym) { - if ((strncmp("l__", p[i]->s_id, 3)!=0)&&(strchr(p[i]->s_id,' ')==NULL)) { + /* no$gmb requires the symbol names to be less than 32 chars long. Truncate. */ + char name[32]; + strncpy(name, p[i]->s_id, 31); + name[31] = '\0'; + if ((strncmp("l__", name, 3)!=0)&&(strchr(name,' ')==NULL)) { a0=p[i]->s_addr + p[i]->s_axp->a_addr; if (a0>0x7FFFU) { /* Not inside the ROM, so treat as being in bank zero */ - fprintf(mfp, "00:%04X %s\n", a0, p[i]->s_id); + fprintf(mfp, "00:%04X %s\n", a0, name); } else { - fprintf(mfp, "%02X:%04X %s\n", a0/16384, a0, p[i]->s_id ); + fprintf(mfp, "%02X:%04X %s\n", a0/16384, a0, name); } } i++; diff --git a/link/z80/lkmain.c b/link/z80/lkmain.c index c2294e08..e92f5994 100644 --- a/link/z80/lkmain.c +++ b/link/z80/lkmain.c @@ -1,5 +1,4 @@ /* lkmain.c */ - /* * (C) Copyright 1989-1995 * All Rights Reserved diff --git a/src/SDCCerr.c b/src/SDCCerr.c index 143ae821..9bd37c6b 100644 --- a/src/SDCCerr.c +++ b/src/SDCCerr.c @@ -144,7 +144,8 @@ struct { { WARNING,"warning *** possible code generation error at line %d,\n send source to sandeep.dutta@usa.net\n"}, { WARNING,"warning *** pointer types incompatible \n" }, { WARNING,"warning *** unknown memory model at %s : %d\n" }, -{ ERROR ,"error *** cannot generate code for target '%s'\n"} +{ ERROR ,"error *** cannot generate code for target '%s'\n"}, +{ WARNING,"warning *** Indirect call to a banked function not implemented.\n"}, }; /****************************************************************************/ diff --git a/src/SDCCerr.h b/src/SDCCerr.h index e3ac831a..d5d82190 100644 --- a/src/SDCCerr.h +++ b/src/SDCCerr.h @@ -132,4 +132,6 @@ #define W_PTR_ASSIGN 129 /* incampatible pointer assignment */ #define W_UNKNOWN_MODEL 130 /* Unknown memory model */ #define E_UNKNOWN_TARGET 131 /* target not defined */ +#define W_INDIR_BANKED 132 /* Indirect call to a banked fun */ + void werror(int, ...); diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index 8be1ab06..000722ff 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -241,6 +241,17 @@ extern int currBlockno; /* sequentail block number */ extern struct optimize optimize ; extern struct options options; extern int maxInterrupts; + +/* Visible from SDCCmain.c */ +extern int nrelFiles; +extern char *relFiles[128]; +extern char *libFiles[128] ; +extern int nlibFiles; +void buildCmdLine(char *into, char **args, const char **cmds, + const char *p1, const char *p2, + const char *p3, const char **list); +int my_system (const char *cmd, char **cmd_argv); + void parseWithComma (char **,char *) ; /** Creates a temporary file a'la tmpfile which avoids the bugs diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 1a3c5158..0e1c7ed2 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -343,7 +343,7 @@ void printChar (FILE * ofile, char *s, int plen) *p = '\0'; if (p != buf) tfprintf(ofile, "\t!ascii\n", buf); - tfprintf(ofile, "\t!db\n", *s); + tfprintf(ofile, "\t!db !constbyte\n", *s); p = buf; } else { @@ -365,7 +365,7 @@ void printChar (FILE * ofile, char *s, int plen) else len = 0; } - tfprintf(ofile, "\t!db\n", 0); + tfprintf(ofile, "\t!db !constbyte\n", 0); } /*-----------------------------------------------------------------*/ @@ -383,7 +383,7 @@ void printIvalType (link * type, initList * ilist, FILE * oFile) switch (getSize (type)) { case 1: if (!val) - tfprintf(oFile, "\t!db\n", 0); + tfprintf(oFile, "\t!db !constbyte\n", 0); else tfprintf(oFile, "\t!dbs\n", aopLiteral (val, 0)); @@ -394,8 +394,8 @@ void printIvalType (link * type, initList * ilist, FILE * oFile) break; case 4: if (!val) { - tfprintf (oFile, "\t!dw\n", 0); - tfprintf (oFile, "\t!dw\n", 0); + tfprintf (oFile, "\t!dw !constword\n", 0); + tfprintf (oFile, "\t!dw !constword\n", 0); } else { fprintf (oFile, "\t.byte %s,%s,%s,%s\n", @@ -453,7 +453,7 @@ int printIvalChar (link * type, initList * ilist, FILE * oFile, char *s) if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) -1))>0) while (remain--) - tfprintf (oFile, "\t!db\n", 0); + tfprintf (oFile, "\t!db !constbyte\n", 0); return 1; } @@ -527,14 +527,14 @@ void printIvalFuncPtr (link * type, initList * ilist, FILE * oFile) val = list2val (ilist); /* check the types */ if ((dLvl = checkType (val->type, type->next)) <= 0) { - tfprintf(oFile, "\t!dw\n", 0); + tfprintf(oFile, "\t!dw !constword\n", 0); return; } /* now generate the name */ if (!val->sym) { if (port->use_dw_for_init) - tfprintf(oFile, "\t!dw %s\n", val->name); + tfprintf(oFile, "\t!dws\n", val->name); else fprintf(oFile, "\t.byte %s,(%s >> 8)\n", val->name,val->name); } @@ -640,7 +640,7 @@ void printIvalPtr (symbol * sym, link * type, initList * ilist, FILE * oFile) if (IS_LITERAL (val->etype)) { switch (getSize (type)) { case 1: - tfprintf(oFile, "\t!db\n", (unsigned int)floatFromVal(val) & 0xff); + tfprintf(oFile, "\t!db !constbyte\n", (unsigned int)floatFromVal(val) & 0xff); break; case 2: tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral(val, 0),aopLiteral(val, 1)); diff --git a/src/SDCCmain.c b/src/SDCCmain.c index d2173138..7adc16ae 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -178,7 +178,7 @@ static int _setPort(const char *name) exit(1); } -static void _buildCmdLine(char *into, char **args, const char **cmds, +void buildCmdLine(char *into, char **args, const char **cmds, const char *p1, const char *p2, const char *p3, const char **list) { @@ -195,6 +195,8 @@ static void _buildCmdLine(char *into, char **args, const char **cmds, /* See if it has a '$' anywhere - if not, just copy */ if ((p = strchr(from, '$'))) { strncpy(into, from, p - from); + /* NULL terminate it */ + into[p-from] = '\0'; from = p+2; p++; switch (*p) { @@ -412,8 +414,9 @@ static void processFile (char *s) /* if the extention is type .rel or .r or .REL or .R addtional object file will be passed to the linker */ if (strcmp(fext,".r") == 0 || strcmp(fext,".rel") == 0 || - strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0) { - + strcmp(fext,".R") == 0 || strcmp(fext,".REL") == 0 || + strcmp(fext, port->linker.rel_ext) == 0) + { relFiles[nrelFiles++] = s; return ; } @@ -1163,7 +1166,7 @@ static void linkEdit (char **envp) fprintf (lnkfile,"\n-e\n"); fclose(lnkfile); - _buildCmdLine(buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL); + buildCmdLine(buffer, argv, port->linker.cmd, srcFileName, NULL, NULL, NULL); /* call the linker */ if (my_system(argv[0], argv)) { @@ -1187,7 +1190,7 @@ static void assemble (char **envp) { char *argv[128]; /* assembler arguments */ - _buildCmdLine(buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions); + buildCmdLine(buffer, argv, port->assembler.cmd, srcFileName, NULL, NULL, asmOptions); if (my_system(argv[0], argv)) { perror("Cannot exec assember"); @@ -1245,7 +1248,7 @@ static int preProcess (char **envp) if (!preProcOnly) preOutName = strdup(tmpnam(NULL)); - _buildCmdLine(buffer, argv, _preCmd, fullSrcFileName, + buildCmdLine(buffer, argv, _preCmd, fullSrcFileName, preOutName, srcFileName, preArgv); if (my_system(argv[0], argv)) { @@ -1343,8 +1346,12 @@ int main ( int argc, char **argv , char **envp) !fatalError && !noAssemble && !options.c1mode && - (srcFileName || nrelFiles)) - linkEdit (envp); + (srcFileName || nrelFiles)) { + if (port->linker.do_link) + port->linker.do_link(); + else + linkEdit (envp); + } if (yyin && yyin != stdin) fclose(yyin); diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 3ad2d92d..e19ed96f 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -429,7 +429,11 @@ void allocParms ( value *val ) else { /* This looks like the wrong order but it turns out OK... */ /* PENDING: isr, bank overhead, ... */ - SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack = stackPtr; + SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack = + stackPtr + + (IS_BANKED(currFunc->etype) ? port->stack.banked_overhead : 0) + + (IS_ISR(currFunc->etype) ? port->stack.isr_overhead : 0) + + 0; stackPtr += getSize (lval->type); } } diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 0c666cba..06683574 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -23,7 +23,7 @@ #include "common.h" -#define ENABLE_MICHAELH_REGPARM_HACK 0 +#define ENABLE_MICHAELH_REGPARM_HACK 0 bucket *SymbolTab [256] ; /* the symbol table */ bucket *StructTab [256] ; /* the structure table */ @@ -1884,6 +1884,7 @@ symbol *__conv[2][3][2]; link *floatType; +#if ENABLE_MICHAELH_REGPARM_HACK static void _makeRegParam(symbol *sym) { value *val ; @@ -1898,6 +1899,7 @@ static void _makeRegParam(symbol *sym) val = val->next ; } } +#endif /*-----------------------------------------------------------------*/ /* initCSupport - create functions for C support routines */ diff --git a/src/asm.c b/src/asm.c index e1b3a0b1..2766b987 100644 --- a/src/asm.c +++ b/src/asm.c @@ -146,9 +146,9 @@ static const ASM_MAPPING _asxxxx_mapping[] = { { "areadata", ".area %s" }, { "ascii", ".ascii \"%s\"" }, { "ds", ".ds %d" }, - { "db", ".db %d" }, + { "db", ".db" }, { "dbs", ".db %s" }, - { "dw", ".dw %d" }, + { "dw", ".dw" }, { "dws", ".dw %s" }, { "constbyte", "0x%02X" }, { "constword", "0x%04X" }, @@ -166,6 +166,7 @@ static const ASM_MAPPING _asxxxx_mapping[] = { "; ---------------------------------" }, { "functionlabeldef", "%s:" }, + { "bankimmeds", "0 ; PENDING: bank support" }, { NULL, NULL } }; diff --git a/src/avr/main.c b/src/avr/main.c index c0f05c38..98c6a7d4 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -148,7 +148,9 @@ PORT avr_port = { 0 }, { - _linkCmd + _linkCmd, + NULL, + ".rel" }, { _defaultRules @@ -174,7 +176,7 @@ PORT avr_port = { 0, }, { - -1, 1, 4, 1, 1 + -1, 1, 4, 1, 1, 0 }, /* avr has an 8 bit mul */ { diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 2a2b8fc0..8dfa4439 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -205,7 +205,9 @@ PORT mcs51_port = { 0 }, { - _linkCmd + _linkCmd, + NULL, + ".rel" }, { _defaultRules @@ -231,7 +233,7 @@ PORT mcs51_port = { 1 }, { - +1, 1, 4, 1, 1 + +1, 1, 4, 1, 1, 0 }, /* mcs51 has an 8 bit mul */ { diff --git a/src/port.h b/src/port.h index 081e26db..aa71608d 100644 --- a/src/port.h +++ b/src/port.h @@ -38,6 +38,10 @@ typedef struct { struct { /** Command to run (eg link-z80) */ const char **cmd; + /** If non-null will be used to execute the link. */ + void (*do_link)(void); + /** Extention for object files (.rel, .obj, ...) */ + const char *rel_ext; } linker; struct { @@ -89,6 +93,9 @@ typedef struct { int call_overhead; /** Re-enterant space */ int reent_overhead; + /** 'banked' call overhead. + Mild overlap with bank_overhead */ + int banked_overhead; } stack; struct { diff --git a/src/z80/gen.c b/src/z80/gen.c index c0701734..b5004ed6 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -142,7 +142,10 @@ static struct { struct { int last; int pushed; + int param_offset; int offset; + int pushed_bc; + int pushed_de; } stack; int frameId; } _G; @@ -887,13 +890,16 @@ static void setupPair(PAIR_ID pairId, asmop *aop, int offset) case AOP_STK: { /* Doesnt include _G.stack.pushed */ int abso = aop->aopu.aop_stk + offset + _G.stack.offset; + if (aop->aopu.aop_stk > 0) { + abso += _G.stack.param_offset; + } assert(pairId == PAIR_HL); /* In some cases we can still inc or dec hl */ if (_G.pairs[pairId].last_type == AOP_STK && abs(_G.pairs[pairId].offset - abso) < 3) { adjustPair(_pairs[pairId].name, &_G.pairs[pairId].offset, abso); } else { - emit2("!ldahlsp", aop->aopu.aop_stk+offset + _G.stack.pushed + _G.stack.offset); + emit2("!ldahlsp", abso +_G.stack.pushed); } _G.pairs[pairId].offset = abso; break; @@ -931,12 +937,19 @@ static char *aopGet(asmop *aop, int offset, bool bit16) if (bit16) tsprintf (s,"!immedwords", aop->aopu.aop_immd); else - if (offset) { - wassert(offset == 1); + switch (offset) { + case 2: + tsprintf(s, "!bankimmeds", aop->aopu.aop_immd); + break; + case 1: + tsprintf(s, "!msbimmeds", aop->aopu.aop_immd); + break; + case 0: tsprintf(s, "!lsbimmeds", aop->aopu.aop_immd); + break; + default: + wassert(0); } - else - tsprintf(s, "!msbimmeds", aop->aopu.aop_immd); ALLOC_ATOMIC(rs,strlen(s)+1); strcpy(rs,s); return rs; @@ -1607,6 +1620,10 @@ static int _opUsesPair(operand *op, iCode *ic, PAIR_ID pairId) static void emitCall(iCode *ic, bool ispcall) { int pushed_de = 0; + link *detype = getSpec(operandType(IC_LEFT(ic))); + + if (IS_BANKED(detype)) + emit2("; call to a banked function"); /* if caller saves & we have not saved then */ if (!ic->regsSaved) { @@ -1678,6 +1695,9 @@ static void emitCall(iCode *ic, bool ispcall) } if (ispcall) { + if (IS_BANKED(detype)) { + werror(W_INDIR_BANKED); + } aopOp(IC_LEFT(ic),ic,FALSE, FALSE); if (isLitWord(AOP(IC_LEFT(ic)))) { @@ -1687,7 +1707,7 @@ static void emitCall(iCode *ic, bool ispcall) else { symbol *rlbl = newiTempLabel(NULL); spillPair(PAIR_HL); - emit2("ld hl,#!tlabel", (rlbl->key+100)); + emit2("ld hl,!immed!tlabel", (rlbl->key+100)); emitcode("push", "hl"); _G.stack.pushed += 2; @@ -1699,11 +1719,18 @@ static void emitCall(iCode *ic, bool ispcall) freeAsmop(IC_LEFT(ic),NULL,ic); } else { - /* make the call */ char *name = OP_SYMBOL(IC_LEFT(ic))->rname[0] ? OP_SYMBOL(IC_LEFT(ic))->rname : OP_SYMBOL(IC_LEFT(ic))->name; - emitcode("call", "%s", name); + if (IS_BANKED(detype)) { + emit2("call banked_call"); + emit2("!dws", name); + emit2("!dw !bankimmeds", name); + } + else { + /* make the call */ + emit2("call %s", name); + } } spillCached(); @@ -1815,6 +1842,37 @@ static void genFunction (iCode *ic) } /* PENDING: callee-save etc */ + /* If BC or DE are used, then push */ + _G.stack.pushed_bc = 0; + _G.stack.pushed_de = 0; + _G.stack.param_offset = 0; + if (sym->regsUsed) { + int i; + for ( i = 0 ; i < sym->regsUsed->size ; i++) { + if (bitVectBitValue(sym->regsUsed, i)) { + switch (i) { + case C_IDX: + case B_IDX: + _G.stack.pushed_bc = 1; + break; + case D_IDX: + case E_IDX: + if (IS_Z80) + _G.stack.pushed_de = 1; + break; + } + } + } + if (_G.stack.pushed_bc) { + emit2("push bc"); + _G.stack.param_offset += 2; + } + if (_G.stack.pushed_de) { + emit2("push de"); + _G.stack.param_offset += 2; + } + } + /* adjust the stack for the function */ _G.stack.last = sym->stack; @@ -1857,6 +1915,14 @@ static void genEndFunction (iCode *ic) emit2("!leavex", _G.stack.offset); else emit2("!leave"); + + if (_G.stack.pushed_de) + emit2("pop de"); + if (_G.stack.pushed_bc) + emit2("pop bc"); + /* Both baned and non-banked just ret */ + emit2("ret"); + /* PENDING: portability. */ emit2("__%s_end:", sym->rname); } @@ -4097,12 +4163,17 @@ static void genAddrOf (iCode *ic) if (IS_GB) { if (sym->onStack) { spillCached(); - emit2("!ldahlsp", sym->stack + _G.stack.pushed + _G.stack.offset); + if (sym->stack <= 0) { + emit2("!ldahlsp", sym->stack + _G.stack.pushed + _G.stack.offset); + } + else { + emit2("!ldahlsp", sym->stack + _G.stack.pushed + _G.stack.offset + _G.stack.param_offset); + } emitcode("ld", "d,h"); emitcode("ld", "e,l"); } else { - emitcode("ld", "de,#%s", sym->rname); + emit2("ld de,!hashedstr", sym->rname); } aopPut(AOP(IC_RESULT(ic)), "e", 0); aopPut(AOP(IC_RESULT(ic)), "d", 1); diff --git a/src/z80/main.c b/src/z80/main.c index 24f8b2b9..935e1f07 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -74,6 +74,9 @@ static int _process_pragma(const char *sz) char buffer[128]; sprintf(buffer, "%s", sz+5); _chomp(buffer); + if (!strcmp(buffer, "BASE")) { + strcpy(buffer, "HOME"); + } gbz80_port.mem.code_name = gc_strdup(buffer); code->sname = gbz80_port.mem.code_name; return 0; @@ -81,6 +84,58 @@ static int _process_pragma(const char *sz) return 1; } +static const char *_gbz80_rgbasmCmd[] = { + "rgbasm", "-o$1.o", "$1.asm", NULL +}; + +static const char *_gbz80_rgblinkCmd[] = { + "xlink", "-tg", "-n$1.sym", "-m$1.map", "-zFF", "$1.lnk", NULL +}; + +static void _gbz80_rgblink(void) +{ + FILE *lnkfile; + const char *sz; + char *argv[128]; + + int i; + sz = srcFileName; + if (!sz) + sz = "a"; + + /* first we need to create the .lnk file */ + sprintf(buffer,"%s.lnk", sz); + if (!(lnkfile = fopen(buffer,"w"))) { + werror(E_FILE_OPEN_ERR, buffer); + exit(1); + } + + fprintf(lnkfile, "[Objects]\n"); + + if (srcFileName) + fprintf(lnkfile, "%s.o\n", sz); + + for (i = 0 ; i < nrelFiles ; i++ ) + fprintf (lnkfile,"%s\n",relFiles[i]); + + fprintf(lnkfile, "\n[Libraries]\n"); + /* additional libraries if any */ + for (i = 0 ; i < nlibFiles; i++) + fprintf (lnkfile,"%s\n",libFiles[i]); + + + fprintf(lnkfile,"\n[Output]\n" "%s.gb",sz); + + fclose(lnkfile); + + buildCmdLine(buffer, argv, port->linker.cmd, sz, NULL, NULL, NULL); + /* call the linker */ + if (my_system(argv[0], argv)) { + perror("Cannot exec linker"); + exit(1); + } +} + static bool _parseOptions(int *pargc, char **argv, int *i) { if (argv[*i][0] == '-') { @@ -103,6 +158,9 @@ static bool _parseOptions(int *pargc, char **argv, int *i) else if (!strncmp(argv[*i], "--asm=", 6)) { if (!strcmp(argv[*i], "--asm=rgbds")) { asm_addTree(&_rgbds_gb); + gbz80_port.assembler.cmd = _gbz80_rgbasmCmd; + gbz80_port.linker.cmd = _gbz80_rgblinkCmd; + gbz80_port.linker.do_link = _gbz80_rgblink; _G.fsetAsmType = TRUE; return TRUE; } @@ -170,7 +228,7 @@ static const char *_z80_linkCmd[] = { }; static const char *_z80_asmCmd[] = { - "as-z80", "-plosgff", "$1.o", "$1.asm", NULL + "as-z80", "-plosgff", "$1.asm", NULL }; /** $1 is always the basename. @@ -200,7 +258,9 @@ PORT z80_port = { "-plosgff", /* Options without debug */ }, { - _z80_linkCmd + _z80_linkCmd, + NULL, + ".o" }, { _z80_defaultRules @@ -226,7 +286,7 @@ PORT z80_port = { 1 }, { - -1, 0, 0, 8, 0 + -1, 0, 0, 4, 0, 2 }, /* Z80 has no native mul/div commands */ { @@ -262,7 +322,9 @@ PORT gbz80_port = { 1 }, { - _gbz80_linkCmd + _gbz80_linkCmd, + NULL, + ".o" }, { _gbz80_defaultRules @@ -288,7 +350,7 @@ PORT gbz80_port = { 1 }, { - -1, 0, 0, 4, 0 + -1, 0, 0, 2, 0, 4 }, /* gbZ80 has no native mul/div commands */ { diff --git a/src/z80/mappings.i b/src/z80/mappings.i index 92eacf59..8a507fdd 100644 --- a/src/z80/mappings.i +++ b/src/z80/mappings.i @@ -11,18 +11,12 @@ static const ASM_MAPPING _asxxxx_gb_mapping[] = { { "ldaspsp", "lda sp,%d(sp)" }, { "*pair", "(%s)" }, { "shortjp", "jr" }, - { "enter", "push bc" }, + { "enter", "" }, { "enterx", - "push bc\n" - "\tlda sp,-%d(sp)" }, - { "leave", - "pop bc\n" - "\tret" + "lda sp,-%d(sp)" }, + { "leave", "" }, - { "leavex", - "lda sp,%d(sp)\n" - "\tpop bc\n" - "\tret" + { "leavex", "lda sp,%d(sp)" }, { "pusha", "push af\n" @@ -31,6 +25,7 @@ static const ASM_MAPPING _asxxxx_gb_mapping[] = { "\tpush hl" }, { "adjustsp", "lda sp,-%d(sp)" }, + { "fileprelude", "" }, { NULL, NULL } }; @@ -56,15 +51,11 @@ static const ASM_MAPPING _asxxxx_z80_mapping[] = { { "*pair", "(%s)" }, { "shortjp", "jp" }, { "enter", - "push bc\n" - "\tpush\tde\n" - "\tpush\tix\n" + "push\tix\n" "\tld\tix,#0\n" "\tadd\tix,sp" }, { "enterx", - "push bc\n" - "\tpush\tde\n" - "\tpush\tix\n" + "push\tix\n" "\tld\tix,#0\n" "\tadd\tix,sp\n" "\tld\thl,#-%d\n" @@ -72,16 +63,10 @@ static const ASM_MAPPING _asxxxx_z80_mapping[] = { "\tld\tsp,hl" }, { "leave", "pop\tix\n" - "\tpop\tde\n" - "\tpop\tbc\n" - "\tret" }, { "leavex", "ld sp,ix\n" "\tpop\tix\n" - "\tpop\tde\n" - "\tpop\tbc\n" - "\tret" }, { "pusha", "push af\n" @@ -113,7 +98,12 @@ static const ASM_MAPPING _rgbds_mapping[] = { "\tGLOBAL __modschar\n" "\tGLOBAL __moduchar\n" "\tGLOBAL __modsint\n" - "\tGLOBAL __moduint" + "\tGLOBAL __moduint\n" + "\tGLOBAL __mulslong\n" + "\tGLOBAL __modslong\n" + "\tGLOBAL __divslong\n" + "\tGLOBAL banked_call\n" + "\tGLOBAL banked_ret\n" }, { "functionheader", "; ---------------------------------\n" @@ -128,9 +118,9 @@ static const ASM_MAPPING _rgbds_mapping[] = { { "areadata", "SECTION \"DATA\",BSS" }, { "ascii", "DB \"%s\"" }, { "ds", "DS %d" }, - { "db", "DB %d" }, + { "db", "DB" }, { "dbs", "DB %s" }, - { "dw", "DW %d" }, + { "dw", "DW" }, { "dws", "DW %s" }, { "immed", "" }, { "constbyte", "$%02X" }, @@ -140,6 +130,7 @@ static const ASM_MAPPING _rgbds_mapping[] = { { "hashedstr", "%s" }, { "lsbimmeds", "%s & $FF" }, { "msbimmeds", "%s >> 8" }, + { "bankimmeds", "BANK(%s)" }, { "module", "; MODULE %s" }, { NULL, NULL } }; @@ -153,19 +144,12 @@ static const ASM_MAPPING _rgbds_gb_mapping[] = { }, { "di", "di" }, { "adjustsp", "add sp,-%d" }, - { "enter", "push bc" }, - { "enterx", - "push bc\n" - "\tadd sp,-%d" + { "enter", "" }, + { "enterx", "add sp,-%d" }, - { "leave", - "pop bc\n" - "\tret" + { "leave", "" }, - { "leavex", - "add sp,%d\n" - "\tpop bc\n" - "\tret" + { "leavex", "add sp,%d" }, { "ldahli", "ld a,[hl+]" }, { "*hl", "[hl]" }, @@ -201,7 +185,9 @@ static const ASM_MAPPING _isas_mapping[] = { "\tGLOBAL __modschar\n" "\tGLOBAL __moduchar\n" "\tGLOBAL __modsint\n" - "\tGLOBAL __moduint" + "\tGLOBAL __moduint\n" + "\tGLOBAL banked_call\n" + "\tGLOBAL banked_ret\n" }, { "functionheader", "; ---------------------------------\n" @@ -216,9 +202,9 @@ static const ASM_MAPPING _isas_mapping[] = { { "areadata", "_DATA\tGROUP" }, { "ascii", "DB \"%s\"" }, { "ds", "DS %d" }, - { "db", "DB %d" }, + { "db", "DB" }, { "dbs", "DB %s" }, - { "dw", "DW %d" }, + { "dw", "DW" }, { "dws", "DW %s" }, { "immed", "" }, { "constbyte", "0x%02X" }, @@ -228,6 +214,7 @@ static const ASM_MAPPING _isas_mapping[] = { { "hashedstr", "%s" }, { "lsbimmeds", "%s & 0xFF" }, { "msbimmeds", "%s >> 8" }, + { "bankimmeds", "!%s" }, { "module", "; MODULE %s" }, { NULL, NULL } }; @@ -241,20 +228,12 @@ static const ASM_MAPPING _isas_gb_mapping[] = { }, { "di", "di" }, { "adjustsp", "add sp,-%d" }, - { "enter", "push bc" }, - { "enterx", - "push bc\n" - "\tadd sp,-%d" - }, - { "leave", - "pop bc\n" - "\tret" + { "enter", "" }, + { "enterx", "add sp,-%d" }, - { "leavex", - "add sp,%d\n" - "\tpop bc\n" - "\tret" + { "leave", "" }, + { "leavex", "add sp,%d\n" }, { "ldahli", "ld a,(hli)" }, { "*hl", "(hl)" }, { "ldahlsp", "ldhl sp,%d" }, diff --git a/src/z80/ralloc.c b/src/z80/ralloc.c index db0153b1..90d6f6fb 100644 --- a/src/z80/ralloc.c +++ b/src/z80/ralloc.c @@ -1268,7 +1268,7 @@ static void regTypeNum (void) /* for the first run we don't provide */ /* registers for true symbols we will */ /* see how things go */ - D(D_ALLOC, ("regTypeNum: #2 setting num of %p to 0\n", sym, 0)); + D(D_ALLOC, ("regTypeNum: #2 setting num of %p to 0\n", sym)); sym->nRegs = 0; } } @@ -1792,7 +1792,7 @@ static void packRegsForAccUse (iCode *ic) /* if one of them is a literal then we can */ if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) || (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) { - OP_SYMBOL(IC_RESULT(ic))->accuse = 1; + goto accuse; return ; } @@ -1984,7 +1984,7 @@ static void packRegsForAccUse2(iCode *ic) return; } } while (!bitVectIsZero(uses)); - OP_SYMBOL(IC_RESULT(ic))->accuse = 1; + OP_SYMBOL(IC_RESULT(ic))->accuse = ACCUSE_A; return; } @@ -2070,7 +2070,7 @@ static void packRegsForAccUse2(iCode *ic) /* if one of them is a literal then we can */ if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) || (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) { - OP_SYMBOL(IC_RESULT(ic))->accuse = 1; + goto accuse; return ; } @@ -2087,7 +2087,7 @@ static void packRegsForAccUse2(iCode *ic) return ; accuse: printf("acc ok!\n"); - OP_SYMBOL(IC_RESULT(ic))->accuse = 1; + OP_SYMBOL(IC_RESULT(ic))->accuse = ACCUSE_A; } /** Does some transformations to reduce register pressure. diff --git a/src/z80/z80.h b/src/z80/z80.h index d51ec916..1bd54404 100644 --- a/src/z80/z80.h +++ b/src/z80/z80.h @@ -20,6 +20,6 @@ extern Z80_OPTS z80_opts; #define IS_Z80 (z80_opts.sub == SUB_Z80) enum { - ACCUSE_A, + ACCUSE_A = 1, ACCUSE_HL }; -- 2.30.2