Merge out from the z80 far branch
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 12 Jul 2000 02:04:31 +0000 (02:04 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 12 Jul 2000 02:04:31 +0000 (02:04 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@294 4a8a32a2-be11-0410-ad9d-d568d2c75423

19 files changed:
link/z80/aslink.h
link/z80/lklist.c
link/z80/lkmain.c
src/SDCCerr.c
src/SDCCerr.h
src/SDCCglobl.h
src/SDCCglue.c
src/SDCCmain.c
src/SDCCmem.c
src/SDCCsymt.c
src/asm.c
src/avr/main.c
src/mcs51/main.c
src/port.h
src/z80/gen.c
src/z80/main.c
src/z80/mappings.i
src/z80/ralloc.c
src/z80/z80.h

index c241194da4a82bac993a831c28408d70ab274085..04ddecbedd311cc3c56eff04036cf0e4fa5c20e5 100644 (file)
  *         +-----+-----+-----+-----+-----+-----+-----+-----+
  */
 
-#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.
index 46ac9199b47d59e2189b1ab831199d0bd06339d2..4f907ff72d84981d7e80d5770cddda6a1413dcad 100644 (file)
@@ -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++;
index c2294e08a64726654a4c82503d1a2252c60f3ac4..e92f59943dc7d8d1b95de6f5602684fc041828fb 100644 (file)
@@ -1,5 +1,4 @@
 /* lkmain.c */
-
 /*
  * (C) Copyright 1989-1995
  * All Rights Reserved
index 143ae8219a5f7bcf27951e732b7464e4531cde11..9bd37c6b2895d5e9796fd52bfcb5c98f81836494 100644 (file)
@@ -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"},
 };
 
 /****************************************************************************/
index e3ac831a38aba587a9df8c0cf94d46b71a507a13..d5d82190170d01e15d150d2a40152d2d3aa65c42 100644 (file)
 #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, ...);
index 8be1ab06afcd6da688d1a15330c44881f40d11e4..000722ffc8a16c158404bcc2c079679e58b08231 100644 (file)
@@ -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
index 1a3c51584b852c777dcf462cdc5b3a2404a5d3a0..0e1c7ed2bbde901b9ac83f302bf3e5e8d54719f2 100644 (file)
@@ -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));
index d217313827d256186837f8706b1590f1df122e2f..7adc16aeb66b16cff3e6181ca4e9ac873b77320e 100644 (file)
@@ -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);
index 3ad2d92df4f7b834dab6af7587681367c676db09..e19ed96f11695b5a4a6276aa6c09b5280fcdc833 100644 (file)
@@ -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);
                }                   
            }
index 0c666cbaa219480cffcd73eda8ec10a78b0d9a5b..0668357471091591094009f357f3dd20dc568226 100644 (file)
@@ -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          */
index e1b3a0b13e112878bb3082c3596b69ae3e3ad44a..2766b9875aee9da29897f9122084cb5e949ab407 100644 (file)
--- 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 }
 };
 
index c0f05c38ea8d6e4d58580988f5f7626372316c78..98c6a7d47262c220e65c06705f7a59a46268417e 100644 (file)
@@ -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 */
     {
index 2a2b8fc085153c1c135e5827778ccf1d45ec2cc6..8dfa443922f2444357640860bf18fd7fbaa809e7 100644 (file)
@@ -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 */
     {
index 081e26db06f2010008fe04ea183d191d709c95ec..aa71608d2095ab67f45b905ed4453a803d445888 100644 (file)
@@ -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 {
index c0701734d11cc298faab3bde348cd23546538751..b5004ed6e8025bfbc75f8f590a540e69a8c587f5 100644 (file)
@@ -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);
index 24f8b2b93e84afc993d75360e6f4cb91c972b675..935e1f07e642725b7a7282f45f5de20d780d426f 100644 (file)
@@ -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 <filename>.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 */
     {  
index 92eacf591d9ee9c4e0dd9f7e343667f0c55d0fd1..8a507fddb200427033ccf7cd20426dd7a18e7643 100644 (file)
@@ -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" },
index db0153b14e40891ed1e629f04c537d8181f194c2..90d6f6fbeea25756904d1ae7683bb36579255d69 100644 (file)
@@ -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.
index d51ec9161ada7d081bc4206db05601aa0affc40d..1bd544049ec84accfb0061ced7bef09b96bed0d1 100644 (file)
@@ -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
 };