From: michaelh Date: Thu, 20 Jul 2000 04:18:51 +0000 (+0000) Subject: Most of the way to far fun support X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c19e63c811b568ecd13a231f78cc69a01bacfa1e;p=fw%2Fsdcc Most of the way to far fun support git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@305 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 0e1c7ed2..e22c0910 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -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"); diff --git a/src/SDCCglue.h b/src/SDCCglue.h index 5150428f..0205dd55 100644 --- a/src/SDCCglue.h +++ b/src/SDCCglue.h @@ -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 diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 3d19be24..662f04bb 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -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 diff --git a/src/SDCCmem.h b/src/SDCCmem.h index b52eb9a3..7a1009d1 100644 --- a/src/SDCCmem.h +++ b/src/SDCCmem.h @@ -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; diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index b8ee1189..c2addb57 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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]); diff --git a/src/asm.c b/src/asm.c index 733e3383..3d2195a7 100644 --- 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" }, diff --git a/src/avr/main.c b/src/avr/main.c index 98c6a7d4..57c0aece 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -171,6 +171,7 @@ PORT avr_port = { "GSINIT (CODE)", "OSEG (OVR,DATA)", "GSFINAL (CODE)", + "HOME (CODE)", NULL, NULL, 0, diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 8dfa4439..9bfed563 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -228,6 +228,7 @@ PORT mcs51_port = { "GSINIT (CODE)", "OSEG (OVR,DATA)", "GSFINAL (CODE)", + "HOME (CODE)", NULL, NULL, 1 diff --git a/src/port.h b/src/port.h index aa71608d..0b142f87 100644 --- a/src/port.h +++ b/src/port.h @@ -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 */ diff --git a/src/z80/gen.c b/src/z80/gen.c index c22a8105..2a31a4cd 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -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; + } } diff --git a/src/z80/main.c b/src/z80/main.c index c4981344..8254ac8c 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -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 diff --git a/src/z80/mappings.i b/src/z80/mappings.i index 987d4e60..f8bc2386 100644 --- a/src/z80/mappings.i +++ b/src/z80/mappings.i @@ -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" },