X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCglue.c;h=28edf1be8501c612d3d6842f49844a59e6877495;hb=a9f3838bdbedc49bb24f63070e0bef2e6fb5edea;hp=fabe997584aa4f804d71c4fbe1cfce393341c48b;hpb=4c527a8dc0a11d9bb33bebfe2fafa42e34b2895b;p=fw%2Fsdcc diff --git a/src/SDCCglue.c b/src/SDCCglue.c index fabe9975..28edf1be 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -117,7 +117,7 @@ aopLiteralLong (value * val, int offset, int size) /* if it is a float then it gets tricky */ /* otherwise it is fairly simple */ if (!IS_FLOAT (val->type)) { - unsigned long v = (unsigned long) floatFromVal (val); + unsigned long v = ulFromVal (val); v >>= (offset * 8); switch (size) { @@ -698,7 +698,7 @@ void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf) size = ((SPEC_BLEN (lsym->etype) / 8) + (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0)); } - i = (unsigned long)floatFromVal(val); + i = ulFromVal(val); i <<= SPEC_BSTR (lsym->etype); ival |= i; if (! ( lsym->next && @@ -747,7 +747,7 @@ printIvalStruct (symbol * sym, sym_link * type, if (SPEC_STRUCT (type)->type == UNION) { printIval (sym, sflds->type, iloop, oBuf); - iloop = iloop->next; + iloop = iloop ? iloop->next : NULL; } else { for (; sflds; sflds = sflds->next, iloop = (iloop ? iloop->next : NULL)) { if (IS_BITFIELD(sflds->type)) { @@ -935,7 +935,7 @@ printIvalCharPtr (symbol * sym, sym_link * type, value * val, struct dbuf_s * oB /* PENDING: this is _very_ mcs51 specific, including a magic number... - It's also endin specific. + It's also endian specific. */ size = getSize (type); @@ -1083,7 +1083,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, struct dbuf_s * o switch (getSize (type)) { case 1: - dbuf_tprintf (oBuf, "\t!db !constbyte\n", (unsigned int) floatFromVal (val) & 0xff); + dbuf_tprintf (oBuf, "\t!db !constbyte\n", (unsigned int) ulFromVal (val) & 0xff); break; case 2: if (port->use_dw_for_init) @@ -1322,6 +1322,7 @@ emitMaps (void) emitRegularMap (bit, TRUE, TRUE); emitRegularMap (pdata, TRUE, TRUE); emitRegularMap (xdata, TRUE, TRUE); + emitRegularMap (x_abs, TRUE, TRUE); if (port->genXINIT) { emitRegularMap (xidata, TRUE, TRUE); } @@ -1394,7 +1395,7 @@ createInterruptVect (struct dbuf_s *vBuf) char *iComments1 = { ";--------------------------------------------------------\n" - "; File Created by SDCC : FreeWare ANSI-C Compiler\n"}; + "; File Created by SDCC : free open source ANSI-C Compiler\n"}; char *iComments2 = { @@ -1410,8 +1411,9 @@ initialComments (FILE * afile) time_t t; time (&t); fprintf (afile, "%s", iComments1); - fprintf (afile, "; Version " SDCC_VERSION_STR " #%s (%s)\n", getBuildNumber(), __DATE__); - fprintf (afile, "; This file generated %s", asctime (localtime (&t))); + fprintf (afile, "; Version " SDCC_VERSION_STR " #%s (%s) (%s)\n", + getBuildNumber(), __DATE__, getBuildEnvironment()); + fprintf (afile, "; This file was generated %s", asctime (localtime (&t))); fprintf (afile, "%s", iComments2); } @@ -1589,13 +1591,13 @@ glue (void) if(port->general.glue_up_main && (TARGET_IS_MCS51 || TARGET_IS_DS390 || TARGET_IS_XA51 || TARGET_IS_DS400)) - { + { mcs51_like=1; /*So it has bits, sfr, sbits, data, idata, etc...*/ - } + } else - { + { mcs51_like=0; - } + } /* print the global struct definitions */ if (options.debug) @@ -1642,11 +1644,11 @@ glue (void) tfprintf (asmFile, "\t!module\n", spacesToUnderscores (moduleBuf, moduleName, sizeof moduleBuf)); if(mcs51_like) - { - fprintf (asmFile, "\t.optsdcc -m%s", port->target); - - switch(options.model) { + fprintf (asmFile, "\t.optsdcc -m%s", port->target); + + switch(options.model) + { case MODEL_SMALL: fprintf (asmFile, " --model-small"); break; case MODEL_COMPACT: fprintf (asmFile, " --model-compact"); break; case MODEL_MEDIUM: fprintf (asmFile, " --model-medium"); break; @@ -1654,19 +1656,19 @@ glue (void) case MODEL_FLAT24: fprintf (asmFile, " --model-flat24"); break; case MODEL_PAGE0: fprintf (asmFile, " --model-page0"); break; default: break; + } + /*if(options.stackAuto) fprintf (asmFile, " --stack-auto");*/ + if(options.useXstack) fprintf (asmFile, " --xstack"); + /*if(options.intlong_rent) fprintf (asmFile, " --int-long-rent");*/ + /*if(options.float_rent) fprintf (asmFile, " --float-rent");*/ + if(options.noRegParams) fprintf (asmFile, " --no-reg-params"); + if(options.parms_in_bank1) fprintf (asmFile, " --parms-in-bank1"); + fprintf (asmFile, "\n"); + } + else if(TARGET_Z80_LIKE || TARGET_IS_HC08) + { + fprintf (asmFile, "\t.optsdcc -m%s\n", port->target); } - /*if(options.stackAuto) fprintf (asmFile, " --stack-auto");*/ - if(options.useXstack) fprintf (asmFile, " --xstack"); - /*if(options.intlong_rent) fprintf (asmFile, " --int-long-rent");*/ - /*if(options.float_rent) fprintf (asmFile, " --float-rent");*/ - if(options.noRegParams) fprintf (asmFile, " --no-reg-params"); - if(options.parms_in_bank1) fprintf (asmFile, " --parms-in-bank1"); - fprintf (asmFile, "\n"); - } - else if(TARGET_IS_Z80 || TARGET_IS_GBZ80 || TARGET_IS_HC08) - { - fprintf (asmFile, "\t.optsdcc -m%s\n", port->target); - } tfprintf (asmFile, "\t!fileprelude\n"); @@ -1682,14 +1684,14 @@ glue (void) printExterns (asmFile); if(( mcs51_like ) - ||( TARGET_IS_Z80 )) /*.p.t.20030924 need to output SFR table for Z80 as well */ - { + ||( TARGET_IS_Z80 )) /*.p.t.20030924 need to output SFR table for Z80 as well */ + { /* copy the sfr segment */ fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; special function registers\n"); fprintf (asmFile, "%s", iComments2); dbuf_write_and_destroy (&sfr->oBuf, asmFile); - } + } if(mcs51_like) { @@ -1701,35 +1703,35 @@ glue (void) /*JCF: Create the areas for the register banks*/ if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3]) - { - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; overlayable register banks\n"); - fprintf (asmFile, "%s", iComments2); - if(RegBankUsed[0]) - fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n"); - if(RegBankUsed[1]||options.parms_in_bank1) - fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n"); - if(RegBankUsed[2]) - fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n"); - if(RegBankUsed[3]) - fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n"); - } + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; overlayable register banks\n"); + fprintf (asmFile, "%s", iComments2); + if(RegBankUsed[0]) + fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n"); + if(RegBankUsed[1]||options.parms_in_bank1) + fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n"); + if(RegBankUsed[2]) + fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n"); + if(RegBankUsed[3]) + fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n"); + } if(BitBankUsed) - { - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; overlayable bit register bank\n"); - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "\t.area BIT_BANK\t(REL,OVR,DATA)\n"); - fprintf (asmFile, "bits:\n\t.ds 1\n"); - fprintf (asmFile, "\tb0 = bits[0]\n"); - fprintf (asmFile, "\tb1 = bits[1]\n"); - fprintf (asmFile, "\tb2 = bits[2]\n"); - fprintf (asmFile, "\tb3 = bits[3]\n"); - fprintf (asmFile, "\tb4 = bits[4]\n"); - fprintf (asmFile, "\tb5 = bits[5]\n"); - fprintf (asmFile, "\tb6 = bits[6]\n"); - fprintf (asmFile, "\tb7 = bits[7]\n"); - } + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; overlayable bit register bank\n"); + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "\t.area BIT_BANK\t(REL,OVR,DATA)\n"); + fprintf (asmFile, "bits:\n\t.ds 1\n"); + fprintf (asmFile, "\tb0 = bits[0]\n"); + fprintf (asmFile, "\tb1 = bits[1]\n"); + fprintf (asmFile, "\tb2 = bits[2]\n"); + fprintf (asmFile, "\tb3 = bits[3]\n"); + fprintf (asmFile, "\tb4 = bits[4]\n"); + fprintf (asmFile, "\tb5 = bits[5]\n"); + fprintf (asmFile, "\tb6 = bits[6]\n"); + fprintf (asmFile, "\tb7 = bits[7]\n"); + } } /* copy the data segment */ @@ -1740,12 +1742,13 @@ glue (void) /* create the overlay segments */ - if (overlay) { - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; overlayable items in %s ram \n", mcs51_like?"internal":""); - fprintf (asmFile, "%s", iComments2); - dbuf_write_and_destroy (&ovrBuf, asmFile); - } + if (overlay) + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; overlayable items in %s ram \n", mcs51_like?"internal":""); + fprintf (asmFile, "%s", iComments2); + dbuf_write_and_destroy (&ovrBuf, asmFile); + } /* create the stack segment MOF */ if (mainf && IFFUNC_HASBODY(mainf->type)) @@ -1758,29 +1761,32 @@ glue (void) } /* create the idata segment */ - if ( (idata) && (mcs51_like) ) { - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; indirectly addressable internal ram data\n"); - fprintf (asmFile, "%s", iComments2); - dbuf_write_and_destroy (&idata->oBuf, asmFile); - } + if ( (idata) && (mcs51_like) ) + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; indirectly addressable internal ram data\n"); + fprintf (asmFile, "%s", iComments2); + dbuf_write_and_destroy (&idata->oBuf, asmFile); + } /* create the absolute idata/data segment */ - if ( (i_abs) && (mcs51_like) ) { - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; absolute internal ram data\n"); - fprintf (asmFile, "%s", iComments2); - dbuf_write_and_destroy (&d_abs->oBuf, asmFile); - dbuf_write_and_destroy (&i_abs->oBuf, asmFile); - } + if ( (i_abs) && (mcs51_like) ) + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; absolute internal ram data\n"); + fprintf (asmFile, "%s", iComments2); + dbuf_write_and_destroy (&d_abs->oBuf, asmFile); + dbuf_write_and_destroy (&i_abs->oBuf, asmFile); + } /* copy the bit segment */ - if (mcs51_like) { - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; bit data\n"); - fprintf (asmFile, "%s", iComments2); - dbuf_write_and_destroy (&bit->oBuf, asmFile); - } + if (mcs51_like) + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; bit data\n"); + fprintf (asmFile, "%s", iComments2); + dbuf_write_and_destroy (&bit->oBuf, asmFile); + } /* copy paged external ram data */ if (mcs51_like) @@ -1802,12 +1808,22 @@ glue (void) } /* copy external ram data */ - if (mcs51_like) { - fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; external ram data\n"); - fprintf (asmFile, "%s", iComments2); - dbuf_write_and_destroy (&xdata->oBuf, asmFile); - } + if (mcs51_like) + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; external ram data\n"); + fprintf (asmFile, "%s", iComments2); + dbuf_write_and_destroy (&xdata->oBuf, asmFile); + } + + /* create the absolute xdata segment */ + if (mcs51_like || TARGET_IS_HC08) + { + fprintf (asmFile, "%s", iComments2); + fprintf (asmFile, "; absolute external ram data\n"); + fprintf (asmFile, "%s", iComments2); + dbuf_write_and_destroy (&x_abs->oBuf, asmFile); + } /* copy external initialized ram data */ fprintf (asmFile, "%s", iComments2); @@ -1817,10 +1833,10 @@ glue (void) /* If the port wants to generate any extra areas, let it do so. */ if (port->extraAreas.genExtraAreaDeclaration) - { + { port->extraAreas.genExtraAreaDeclaration(asmFile, mainf && IFFUNC_HASBODY(mainf->type)); - } + } /* copy the interrupt vector table */ if (mainf && IFFUNC_HASBODY(mainf->type)) @@ -1855,6 +1871,7 @@ glue (void) } else { + assert (mcs51_like); fprintf (asmFile, "__sdcc_gsinit_startup:\n"); /* if external stack is specified then the higher order byte of the xdatalocation is @@ -1877,10 +1894,10 @@ glue (void) fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n"); /* MOF */ } - fprintf (asmFile, "\tlcall\t__sdcc_external_startup\n"); + fprintf (asmFile, "\t%ccall\t__sdcc_external_startup\n", options.acall_ajmp?'a':'l'); fprintf (asmFile, "\tmov\ta,dpl\n"); fprintf (asmFile, "\tjz\t__sdcc_init_data\n"); - fprintf (asmFile, "\tljmp\t__sdcc_program_startup\n"); + fprintf (asmFile, "\t%cjmp\t__sdcc_program_startup\n", options.acall_ajmp?'a':'l'); fprintf (asmFile, "__sdcc_init_data:\n"); // if the port can copy the XINIT segment to XISEG @@ -1889,7 +1906,6 @@ glue (void) port->genXINIT(asmFile); } } - } dbuf_write_and_destroy (&statsg->oBuf, asmFile); @@ -1900,7 +1916,7 @@ glue (void) * by the ugly shucking and jiving about 20 lines ago. */ tfprintf (asmFile, "\t!area\n", port->mem.post_static_name); - fprintf (asmFile, "\tljmp\t__sdcc_program_startup\n"); + fprintf (asmFile, "\t%cjmp\t__sdcc_program_startup\n", options.acall_ajmp?'a':'l'); } fprintf (asmFile, @@ -1918,12 +1934,12 @@ glue (void) /* put in jump or call to main */ if (options.mainreturn) { - fprintf (asmFile, "\tljmp\t_main\n"); /* needed? */ + fprintf (asmFile, "\t%cjmp\t_main\n", options.acall_ajmp?'a':'l'); /* needed? */ fprintf (asmFile, ";\treturn from main will return to caller\n"); } else { - fprintf (asmFile, "\tlcall\t_main\n"); + fprintf (asmFile, "\t%ccall\t_main\n", options.acall_ajmp?'a':'l'); fprintf (asmFile, ";\treturn from main will lock up\n"); fprintf (asmFile, "\tsjmp .\n"); } @@ -1935,8 +1951,9 @@ glue (void) tfprintf (asmFile, "\t!areacode\n", options.code_seg); dbuf_write_and_destroy (&code->oBuf, asmFile); - if (port->genAssemblerEnd) { + if (port->genAssemblerEnd) + { port->genAssemblerEnd(asmFile); - } + } fclose (asmFile); }