Most of the way to far fun support
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 20 Jul 2000 04:18:51 +0000 (04:18 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 20 Jul 2000 04:18:51 +0000 (04:18 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@305 4a8a32a2-be11-0410-ad9d-d568d2c75423

12 files changed:
src/SDCCglue.c
src/SDCCglue.h
src/SDCCmem.c
src/SDCCmem.h
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

index 0e1c7ed2bbde901b9ac83f302bf3e5e8d54719f2..e22c0910810360791d6a8a183aaaaabfe95c2fec 100644 (file)
@@ -144,8 +144,12 @@ static void emitRegularMap (memmap * map, bool addPublics, bool arFlag)
     
     if (addPublics) {
        /* PENDING: special case here - should remove */
-       if (!strcmp(map->sname, DATA_NAME))
+       if (!strcmp(map->sname, CODE_NAME))
+           tfprintf(map->oFile, "\t!areacode\n", map->sname);
+       else if (!strcmp(map->sname, DATA_NAME)) 
            tfprintf(map->oFile, "\t!areadata\n", map->sname);
+       else if (!strcmp(map->sname, HOME_NAME)) 
+           tfprintf(map->oFile, "\t!areahome\n", map->sname);
        else
            tfprintf(map->oFile, "\t!area\n", map->sname);
     }
@@ -390,7 +394,10 @@ void printIvalType (link * type, initList * ilist, FILE * oFile)
        break;
 
     case 2:
-       fprintf(oFile, "\t.byte %s,%s\n", aopLiteral(val, 0),aopLiteral(val, 1));
+       if (port->use_dw_for_init)
+           tfprintf(oFile, "\t!dws\n", aopLiteralLong(val, 0, 2));
+       else
+           fprintf(oFile, "\t.byte %s,%s\n", aopLiteral(val, 0),aopLiteral(val, 1));
        break;
     case 4:
        if (!val) {
@@ -587,8 +594,11 @@ int printIvalCharPtr (symbol * sym, link * type, value * val, FILE * oFile)
            tfprintf(oFile, "\t!dbs\n", aopLiteral(val, 0));
            break;
        case 2:
-           tfprintf(oFile, "\t.byte %s,%s\n", 
-                   aopLiteral(val, 0),aopLiteral(val, 1));
+           if (port->use_dw_for_init)
+               tfprintf(oFile, "\t!dws\n", aopLiteralLong(val, 0, size));
+           else 
+               tfprintf(oFile, "\t.byte %s,%s\n", 
+                        aopLiteral(val, 0),aopLiteral(val, 1));
            break;
        case 3:
            /* PENDING: 0x02 or 0x%02x, CDATA? */
@@ -643,7 +653,10 @@ void printIvalPtr (symbol * sym, link * type, initList * ilist, FILE * oFile)
            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));
+           if (port->use_dw_for_init)
+               tfprintf(oFile, "\t!dws\n", aopLiteralLong(val, 0, 2));
+           else
+               tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral(val, 0),aopLiteral(val, 1));
            break;
        case 3:
            fprintf (oFile, "\t.byte %s,%s,#0x02\n",
@@ -711,7 +724,9 @@ void emitStaticSeg (memmap * map)
     
     /*     fprintf(map->oFile,"\t.area\t%s\n",map->sname); */
     
-    
+    if (!codeOutFile)
+       codeOutFile = code->oFile;
+
     /* for all variables in this segment do */
     for (sym = setFirstItem (map->syms); sym;
         sym = setNextItem (map->syms)) {
@@ -732,49 +747,49 @@ void emitStaticSeg (memmap * map)
 
            if (!sym->level) { /* global */
                if (IS_STATIC(sym->etype))
-                   fprintf(code->oFile,"F%s$",moduleName); /* scope is file */
+                   fprintf(codeOutFile,"F%s$",moduleName); /* scope is file */
                else
-                   fprintf(code->oFile,"G$"); /* scope is global */
+                   fprintf(codeOutFile,"G$"); /* scope is global */
            }
            else
                /* symbol is local */
-               fprintf(code->oFile,"L%s$",
+               fprintf(codeOutFile,"L%s$",
                        (sym->localof ? sym->localof->name : "-null-"));
-           fprintf(code->oFile,"%s$%d$%d",sym->name,sym->level,sym->block);
+           fprintf(codeOutFile,"%s$%d$%d",sym->name,sym->level,sym->block);
        }
        
        /* if it has an absolute address */
        if (SPEC_ABSA (sym->etype)) {
            if ((options.debug || sym->level == 0) && !options.nodebug)
-               fprintf(code->oFile," == 0x%04x\n", SPEC_ADDR (sym->etype));
+               fprintf(codeOutFile," == 0x%04x\n", SPEC_ADDR (sym->etype));
 
-           fprintf (code->oFile, "%s\t=\t0x%04x\n",
+           fprintf (codeOutFile, "%s\t=\t0x%04x\n",
                     sym->rname,
                     SPEC_ADDR (sym->etype));
        }
        else {
            if ((options.debug || sym->level == 0) && !options.nodebug)
-               fprintf(code->oFile," == .\n"); 
+               fprintf(codeOutFile," == .\n"); 
 
            /* if it has an initial value */
            if (sym->ival) {
-               fprintf (code->oFile, "%s:\n", sym->rname);
+               fprintf (codeOutFile, "%s:\n", sym->rname);
                noAlloc++;
                resolveIvalSym (sym->ival);
-               printIval (sym, sym->type, sym->ival, code->oFile);
+               printIval (sym, sym->type, sym->ival, codeOutFile);
                noAlloc--;
            }
            else {
                /* allocate space */
-               fprintf (code->oFile, "%s:\n", sym->rname);
+               fprintf (codeOutFile, "%s:\n", sym->rname);
                /* special case for character strings */
                if (IS_ARRAY (sym->type) && IS_CHAR (sym->type->next) &&
                    SPEC_CVAL (sym->etype).v_char)
-                   printChar (code->oFile,
+                   printChar (codeOutFile,
                               SPEC_CVAL (sym->etype).v_char,
                               strlen(SPEC_CVAL (sym->etype).v_char)+1);
                else 
-                   tfprintf(code->oFile, "\t!ds\n", (unsigned int)getSize (sym->type)& 0xffff);
+                   tfprintf(codeOutFile, "\t!ds\n", (unsigned int)getSize (sym->type)& 0xffff);
            }
        }
     }
@@ -793,10 +808,21 @@ void emitMaps ()
     emitRegularMap (xdata, TRUE,TRUE);
     emitRegularMap (sfr, FALSE,FALSE);
     emitRegularMap (sfrbit, FALSE,FALSE);
+    emitRegularMap (home, TRUE,FALSE);
     emitRegularMap (code, TRUE,FALSE);
     emitStaticSeg (statsg);
 }
 
+/*-----------------------------------------------------------------*/
+/* flushStatics - flush all currently defined statics out to file  */
+/*  and delete.  Temporary function                                */
+/*-----------------------------------------------------------------*/
+void flushStatics(void)
+{
+    emitStaticSeg(statsg);
+    statsg->syms = NULL;
+}
+
 /*-----------------------------------------------------------------*/
 /* createInterruptVect - creates the interrupt vector              */
 /*-----------------------------------------------------------------*/
@@ -1182,7 +1208,14 @@ void glue ()
        tfprintf(asmFile, "\t!area\n", port->mem.post_static_name);
        fprintf (asmFile,"\tljmp\t__sdcc_program_startup\n");
     }
-       
+
+    fprintf (asmFile,
+            "%s"
+            "; Home\n"
+            "%s", iComments2, iComments2);
+    tfprintf(asmFile, "\t!areahome\n", HOME_NAME);
+    copyFile (asmFile, home->oFile);
+
     /* copy over code */
     fprintf (asmFile, "%s", iComments2);
     fprintf (asmFile, "; code\n");
index 5150428fb7d618d9cbb9cb852ccf3d14db0f8f57..0205dd55a59ca48825814f7a31ea313267af43ba 100644 (file)
@@ -31,5 +31,6 @@ void glue();
 /* drdani Jan 30 2000
  This is needed in gen.c of z80 port */
 char *aopLiteral (value *, int);
+void flushStatics(void);
 
 #endif
index 3d19be244f0e23d8c18e2a7e1259a142f10d4d11..662f04bbe91c9d9debe2b3d1a38f033b44b5d95d 100644 (file)
@@ -19,6 +19,7 @@ memmap  *sfrbit= NULL;   /* sfr bit space               */
 memmap  *generic=NULL;   /* is a generic pointer        */
 memmap  *overlay=NULL;   /* overlay segment             */
 memmap  *eeprom =NULL;   /* eeprom location             */
+memmap *home   =NULL;   /* Unswitchable code bank      */
 
 /* this is a set of sets each set containing
    symbols in a single overlay */
@@ -114,6 +115,18 @@ void initMem ()
        */
        code      = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME,'C',CPOINTER);
 
+       /* home  segment ;   
+                  SFRSPACE       -   NO
+                  FAR-SPACE      -   YES
+                  PAGED          -   NO
+                  DIRECT-ACCESS  -   NO
+                  BIT-ACCESS     -   NO
+                  CODE-ACESS     -   YES 
+                  DEBUG-NAME     -   'C'
+                  POINTER-TYPE   -   CPOINTER
+       */
+       home      = allocMap (0, 1, 0, 0, 0, 1, options.code_loc, CODE_NAME,'C',CPOINTER);
+
        /* Static segment (code for variables );
                   SFRSPACE       -   NO
                   FAR-SPACE      -   YES
index b52eb9a332ab20d400818206d7c26671834c8d56..7a1009d10c5ddab5573b00c716d404e594b58cfb 100644 (file)
@@ -36,6 +36,7 @@ extern FILE   *junkFile ;
 #define  BIT_NAME      port->mem.bit_name
 #define  REG_NAME      port->mem.reg_name
 #define  STATIC_NAME   port->mem.static_name
+#define         HOME_NAME     port->mem.home_name
  
 /* forward definition for variables */
 extern   memmap  *xstack;    /* xternal stack data         */
@@ -53,6 +54,8 @@ extern   memmap  *_const;    /* constant segment           */
 extern   memmap  *generic;   /* unknown                    */
 extern   memmap  *overlay;   /* the overlay segment        */
 extern   memmap  *eeprom;    /* eepromp space              */
+extern   memmap  *eeprom;    /* eepromp space              */
+extern  memmap  *home;      /* Non-banked home space      */
 
 extern   struct  set     *ovrSetSets;
 
index b8ee1189d47f1b03db06b3199e8f8fd3c0d9024c..c2addb57f466675e2c6b031b355edf08b780475d 100644 (file)
@@ -1974,6 +1974,7 @@ void initCSupport ()
                        ssu[su],
                        sbwd[bwd]);
                __muldiv[muldivmod][bwd][su] = funcOfType(buffer, __multypes[bwd][su], __multypes[bwd][su], 2, options.intlong_rent);
+               SPEC_NONBANKED(__muldiv[muldivmod][bwd][su]->etype) = 1;
 #if ENABLE_MICHAELH_REGPARM_HACK
                if (bwd < 2) 
                    _makeRegParam(__muldiv[muldivmod][bwd][su]);
index 733e338396933b0d62536329a1c7320efe3410e9..3d2195a7c7f64358d8fc6867b51fef889389c071 100644 (file)
--- a/src/asm.c
+++ b/src/asm.c
@@ -155,6 +155,7 @@ static const ASM_MAPPING _asxxxx_mapping[] = {
     { "area", ".area %s" },
     { "areacode", ".area %s" },
     { "areadata", ".area %s" },
+    { "areahome", ".area %s" },
     { "ascii", ".ascii \"%s\"" },
     { "ds", ".ds %d" },
     { "db", ".db" },
index 98c6a7d47262c220e65c06705f7a59a46268417e..57c0aece2eb5b324a40d9c96edda3f82ca66a57e 100644 (file)
@@ -171,6 +171,7 @@ PORT avr_port = {
        "GSINIT  (CODE)",
        "OSEG    (OVR,DATA)",
        "GSFINAL (CODE)",
+       "HOME    (CODE)",
        NULL,
        NULL,
        0,
index 8dfa443922f2444357640860bf18fd7fbaa809e7..9bfed563e79b08fa59f08b35417fac614c519852 100644 (file)
@@ -228,6 +228,7 @@ PORT mcs51_port = {
        "GSINIT  (CODE)",
        "OSEG    (OVR,DATA)",
        "GSFINAL (CODE)",
+       "HOME    (CODE)",
        NULL,
        NULL,
        1
index aa71608d2095ab67f45b905ed4453a803d445888..0b142f871615bdcc50fe07341a12563b32497b46 100644 (file)
@@ -76,6 +76,7 @@ typedef struct {
        const char *static_name;
        const char *overlay_name;
        const char *post_static_name;
+       const char *home_name;
        struct memmap *default_local_map ; /* default location for auto vars */
        struct memmap *default_globl_map ; /* default location for globl vars*/
        int         code_ro;               /* code space read-only 1=yes */
index c22a8105f8c7c76fc9d8448b4cd8addbd3a85310..2a31a4cde93f92fab7165819b73c8d9db4631961 100644 (file)
@@ -148,6 +148,8 @@ static struct {
        int pushed_de;
     } stack;
     int frameId;
+    bool flush_statics;
+    bool in_home;
 } _G;
 
 static char *aopGet(asmop *aop, int offset, bool bit16);
@@ -804,7 +806,7 @@ static void fetchLitPair(PAIR_ID pairId, asmop *left, int offset)
 {
     const char *l;
     const char *pair = _pairs[pairId].name;
-    l = aopGetLitWordLong(left, offset, FALSE);
+    l = aopGetLitWordLong(left, 0, FALSE);
     wassert(l && pair);
 
     if (isPtr(pair)) {
@@ -825,13 +827,21 @@ static void fetchLitPair(PAIR_ID pairId, asmop *left, int offset)
        _G.pairs[pairId].lit = gc_strdup(l);
        _G.pairs[pairId].offset = offset;
     }
+    if (IS_GB && pairId == PAIR_DE) {
+       if (_G.pairs[pairId].lit && !strcmp(_G.pairs[pairId].lit, l)) {
+           if (abs(_G.pairs[pairId].offset - offset) < 3) {
+               adjustPair(pair, &_G.pairs[pairId].offset, offset);
+               return;
+           }
+       }
+       _G.pairs[pairId].last_type = left->type;
+       _G.pairs[pairId].lit = gc_strdup(l);
+       _G.pairs[pairId].offset = offset;
+    }
     /* Both a lit on the right and a true symbol on the left */
-    /* PENDING: for re-target */
-#if 0
     if (offset)
-       emit2("ld %s,!hashedstr + %d", pair, l, offset);
-    else 
-#endif
+       emit2("ld %s,!hashedstr + %u", pair, l, offset);
+    else
        emit2("ld %s,!hashedstr", pair, l);
 }
 
@@ -1643,8 +1653,9 @@ static int _opUsesPair(operand *op, iCode *ic, PAIR_ID pairId)
 static void setArea(int inHome)
 {
     static int lastArea = 0;
-    
-    if (lastArea != inHome) {
+
+    /*    
+    if (_G.in_home != inHome) {
        if (inHome) {
            const char *sz = port->mem.code_name;
            port->mem.code_name = "HOME";
@@ -1652,9 +1663,14 @@ static void setArea(int inHome)
            port->mem.code_name = sz;
        }
        else
-           emit2("!area", CODE_NAME);
-       lastArea = inHome;
-    }
+       emit2("!area", CODE_NAME);*/
+       _G.in_home = inHome;
+       //    }
+}
+
+static bool isInHome(void)
+{
+    return _G.in_home;
 }
 
 /** Emit the code for a call statement 
@@ -1968,6 +1984,7 @@ static void genEndFunction (iCode *ic)
        /* PENDING: portability. */
        emit2("__%s_end:", sym->rname);
     }
+    _G.flush_statics = 1;
     _G.stack.pushed = 0;
     _G.stack.offset = 0;
 }
@@ -4126,6 +4143,7 @@ static void genGenPointerGet (operand *left,
            }
            if (size) {
                emit2("inc %s", _pairs[pair].name);
+               _G.pairs[pair].offset++;
            }
         }
     }
@@ -4218,6 +4236,7 @@ static void genGenPointerSet (operand *right,
            }
            if (size) {
                emitcode("inc", _pairs[pairId].name);
+               _G.pairs[pairId].offset++;
            }
            offset++;
         }
@@ -4855,7 +4874,17 @@ void genZ80Code (iCode *lic)
     if (!options.nopeep)
        peepHole (&lineHead);
 
+    /* This is unfortunate */
     /* now do the actual printing */
-    printLine (lineHead, codeOutFile);
-    return;
+    {
+       FILE *fp = codeOutFile;
+       if (isInHome() && codeOutFile == code->oFile)
+           codeOutFile = home->oFile;
+       printLine (lineHead, codeOutFile);
+       if (_G.flush_statics) {
+           flushStatics();
+           _G.flush_statics = 0;
+       }
+       codeOutFile = fp;
+    }
 }
index c4981344d6ef5dbf04c72546ba8864d3eff9a197..8254ac8cbd7d95c15dda020aaf52cf27c36a28da 100644 (file)
@@ -312,6 +312,7 @@ PORT z80_port = {
        "GSINIT",
        "OVERLAY",
        "GSFINAL",
+       "HOME",
        NULL,
        NULL,
        1
@@ -376,6 +377,7 @@ PORT gbz80_port = {
        "GSINIT",
        "OVERLAY",
        "GSFINAL",
+       "HOME",
        NULL,
        NULL,
        1
index 987d4e6077d99ee0ce95dfdc376cb5bad614bacc..f8bc23864643a0e093f2580fcf2cdbccabe3c24f 100644 (file)
@@ -3,6 +3,7 @@ static const ASM_MAPPING _asxxxx_gb_mapping[] = {
     { "area", ".area _%s" },
     { "areacode", ".area _%s" },
     { "areadata", ".area _%s" },
+    { "areahome", ".area _%s" },
     { "functionlabeldef", "%s:" },
     { "*hl", "(hl)" },
     { "di", "di" },
@@ -34,6 +35,7 @@ static const ASM_MAPPING _asxxxx_z80_mapping[] = {
     { "area", ".area _%s" },
     { "areacode", ".area _%s" },
     { "areadata", ".area _%s" },
+    { "areahome", ".area _%s" },
     { "*ixx", "%d(ix)" },
     { "*iyx", "%d(iy)" },
     { "*hl", "(hl)" },
@@ -113,9 +115,10 @@ static const ASM_MAPPING _rgbds_mapping[] = {
     { "functionlabeldef", "%s:" },
     { "zero", "$00" },
     { "one", "$01" },
-    { "area", "SECTION \"%s_%F_%I\",%C" },
-    { "areacode", "SECTION \"CODE\",%C" },
-    { "areadata", "SECTION \"DATA\",BSS" },
+    { "area", "SECTION \"%s\",CODE" },
+    { "areadata", "SECTION \"%F_%s\",BSS" },
+    { "areacode", "SECTION \"%F_CODE\",%s" }, 
+    { "areahome", "SECTION \"%F_HOME\",HOME" },
     { "ascii", "DB \"%s\"" },
     { "ds", "DS %d" },
     { "db", "DB" },
@@ -200,6 +203,7 @@ static const ASM_MAPPING _isas_mapping[] = {
     { "area", "%s\tGROUP" },
     { "areacode", "_CODE\tGROUP" },
     { "areadata", "_DATA\tGROUP" },
+    { "areahome", "_CODE\tGROUP" },
     { "ascii", "DB \"%s\"" },
     { "ds", "DS %d" },
     { "db", "DB" },