From: epetrich Date: Wed, 17 Mar 2004 23:33:26 +0000 (+0000) Subject: * src/SDCCglue.c (emitMaps): allow public sfr variables X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=8c9c17bede2d442a7690c614260ee38e6b40b39a;p=fw%2Fsdcc * src/SDCCglue.c (emitMaps): allow public sfr variables * src/SDCCglue.c (initialComments): include compiler build date with compiler version and put the timestamp of the generated assembly file on a serperate line to be less confusing. * src/port.h: added genInitStartup hook * src/avr/main.c, * src/ds390/main.c, * src/hc08/main.c, * src/pic/main.c, * src/pic16/main.c, * src/xa51/main.c, * src/z80/main.c: genInitStartup initialize as NULL (default to historical behaviour) * src/SDCCglue.c (glue): _sdcc_gsinit_startup is now port specific. * src/mcs51/main.c: (_mcs51_genInitStartup, _mcs51_genExtraAreas, _mcs51_genXINIT, _mcs51_genRAMCLEAR): link initialization code from the library instead of hard coding it into the compiler. * support/regression/ports/mcs51-stack-auto/spec.mk, * src/SDCCmain.c (linkEdit): added mcs51.lib to the link libraries * device/lib/mcs51/Makefile, * device/lib/small/Makefile, * device/lib/large/Makefile, * device/lib/mcs51/crtpagesfr.asm, * device/lib/mcs51/crtstart.asm, * device/lib/mcs51/crtxclear.asm, * device/lib/mcs51/crtxinit.asm, * device/lib/mcs51/crtclear.asm, * device/lib/mcs51/crtxstack.asm: move most of the mcs51 C runtime startup/initialization out of src/SDCCglue.c and src/mcs51/main.c and into user configurable files. * device/lib/clean.mk: clean mcs51 directory too * support/regression/tests/longlit.c: added static to T1 declaration * doc/sdccman.lyx: documented _PAGESFR sfr for customizing pdata accesses in the initialization code git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3267 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 0b9f4260..89eb7ed3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,40 @@ +2004-03-17 Erik Petrich + + * src/SDCCglue.c (emitMaps): allow public sfr variables + * src/SDCCglue.c (initialComments): include compiler build date + with compiler version and put the timestamp of the generated + assembly file on a serperate line to be less confusing. + * src/port.h: added genInitStartup hook + * src/avr/main.c, + * src/ds390/main.c, + * src/hc08/main.c, + * src/pic/main.c, + * src/pic16/main.c, + * src/xa51/main.c, + * src/z80/main.c: genInitStartup initialize as NULL (default to + historical behaviour) + * src/SDCCglue.c (glue): _sdcc_gsinit_startup is now port specific. + * src/mcs51/main.c: (_mcs51_genInitStartup, _mcs51_genExtraAreas, + _mcs51_genXINIT, _mcs51_genRAMCLEAR): link initialization code from the + library instead of hard coding it into the compiler. + * support/regression/ports/mcs51-stack-auto/spec.mk, + * src/SDCCmain.c (linkEdit): added mcs51.lib to the link libraries + * device/lib/mcs51/Makefile, + * device/lib/small/Makefile, + * device/lib/large/Makefile, + * device/lib/mcs51/crtpagesfr.asm, + * device/lib/mcs51/crtstart.asm, + * device/lib/mcs51/crtxclear.asm, + * device/lib/mcs51/crtxinit.asm, + * device/lib/mcs51/crtclear.asm, + * device/lib/mcs51/crtxstack.asm: move most of the mcs51 C runtime + startup/initialization out of src/SDCCglue.c and src/mcs51/main.c + and into user configurable files. + * device/lib/clean.mk: clean mcs51 directory too + * support/regression/tests/longlit.c: added static to T1 declaration + * doc/sdccman.lyx: documented _PAGESFR sfr for customizing pdata + accesses in the initialization code + 2004-03-14 Erik Petrich * device/include/mc68hc908qy.h: corrected declarations of FLBPR and diff --git a/device/lib/clean.mk b/device/lib/clean.mk index e4b0a401..f1fa504c 100644 --- a/device/lib/clean.mk +++ b/device/lib/clean.mk @@ -10,6 +10,7 @@ clean: for model in $(MODELS); do \ find $$model -maxdepth 1 -type f ! -name Makefile -exec rm {} \; ; \ done + make -C mcs51 clean make -C ds390 clean make -C z80 clean make -C gbz80 clean diff --git a/device/lib/large/Makefile b/device/lib/large/Makefile index 2e05df18..c132ed9c 100644 --- a/device/lib/large/Makefile +++ b/device/lib/large/Makefile @@ -1,6 +1,9 @@ # Dummy Makefile to get around CVS all: + make -C ../mcs51 all + cp ../mcs51/*.rel ../mcs51/*.lib . touch dummy.lib touch dummy.rel clean: + rm *.rel *.lib diff --git a/device/lib/mcs51/Makefile b/device/lib/mcs51/Makefile new file mode 100644 index 00000000..9476653f --- /dev/null +++ b/device/lib/mcs51/Makefile @@ -0,0 +1,31 @@ + +TOPDIR = ../../.. + +SAS = $(TOPDIR)/bin/asx8051 +SCC = $(TOPDIR)/bin/sdcc + +OBJ = crtstart.rel crtxinit.rel crtxclear.rel crtclear.rel crtxstack.rel \ + crtpagesfr.rel + +LIB = mcs51.lib + +CC = $(SCC) +AS = $(SAS) +ASFLAGS = -plosgff + +CFLAGS = -I../../include -I. + +all: $(LIB) + +$(LIB): $(OBJ) Makefile + rm -f $(LIB) + for i in $(OBJ); do echo $$i >> $(LIB); done + +%.rel: %.c + $(CC) $(CFLAGS) -c $< + +%.rel: %.asm + $(AS) $(ASFLAGS) $< + +clean: + rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.lib diff --git a/device/lib/mcs51/crtclear.asm b/device/lib/mcs51/crtclear.asm new file mode 100644 index 00000000..3ccaca84 --- /dev/null +++ b/device/lib/mcs51/crtclear.asm @@ -0,0 +1,41 @@ +; /*------------------------------------------------------------------------- +; +; crtclear.asm :- C run-time: clear DATA/IDATA +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU Library General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU Library General Public License for more details. +; +; You should have received a copy of the GNU Library General Public License +; along with this program; if not, write to the Free Software +; Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +; +; In other words, you are welcome to use, share and improve this program. +; You are forbidden to forbid anyone else to use, share and improve +; what you give them. Help stamp out software-hoarding! +; -------------------------------------------------------------------------*/ + + .area CSEG (CODE) + .area GSINIT0 (CODE) + .area GSINIT1 (CODE) + .area GSINIT2 (CODE) + .area GSINIT3 (CODE) + .area GSINIT4 (CODE) + .area GSINIT5 (CODE) + .area GSINIT (CODE) + .area GSFINAL (CODE) + + .area GSINIT4 (CODE) + +__mcs51_genRAMCLEAR:: + clr a + mov r0,a +00005$: mov @r0,a + djnz r0,00005$ +; _mcs51_genRAMCLEAR() end diff --git a/device/lib/mcs51/crtpagesfr.asm b/device/lib/mcs51/crtpagesfr.asm new file mode 100644 index 00000000..ae799a54 --- /dev/null +++ b/device/lib/mcs51/crtpagesfr.asm @@ -0,0 +1,24 @@ +; /*------------------------------------------------------------------------- +; +; crtpagesfr.asm :- C run-time: define page sfr for movx @r0/r1 instructions +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU Library General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU Library General Public License for more details. +; +; You should have received a copy of the GNU Library General Public License +; along with this program; if not, write to the Free Software +; Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +; +; In other words, you are welcome to use, share and improve this program. +; You are forbidden to forbid anyone else to use, share and improve +; what you give them. Help stamp out software-hoarding! +; -------------------------------------------------------------------------*/ + +__PAGESFR == 0xa0 ; 0xa0 is P2 on the original 8051 diff --git a/device/lib/mcs51/crtstart.asm b/device/lib/mcs51/crtstart.asm new file mode 100644 index 00000000..37978edf --- /dev/null +++ b/device/lib/mcs51/crtstart.asm @@ -0,0 +1,47 @@ +; /*------------------------------------------------------------------------- +; +; crtstart.asm :- C run-time: startup +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU Library General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU Library General Public License for more details. +; +; You should have received a copy of the GNU Library General Public License +; along with this program; if not, write to the Free Software +; Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +; +; In other words, you are welcome to use, share and improve this program. +; You are forbidden to forbid anyone else to use, share and improve +; what you give them. Help stamp out software-hoarding! +; -------------------------------------------------------------------------*/ + + .area CSEG (CODE) + .area GSINIT0 (CODE) + .area GSINIT1 (CODE) + .area GSINIT2 (CODE) + .area GSINIT3 (CODE) + .area GSINIT4 (CODE) + .area GSINIT5 (CODE) + .area GSINIT (CODE) + .area GSFINAL (CODE) + + .globl __start__stack + + .area GSINIT0 (CODE) + +__sdcc_gsinit_startup:: + mov sp,#__start__stack - 1 + + .area GSINIT2 (CODE) + + lcall __sdcc_external_startup + mov a,dpl + jz __sdcc_init_data + ljmp __sdcc_program_startup +__sdcc_init_data: diff --git a/device/lib/mcs51/crtxclear.asm b/device/lib/mcs51/crtxclear.asm new file mode 100644 index 00000000..819c111b --- /dev/null +++ b/device/lib/mcs51/crtxclear.asm @@ -0,0 +1,49 @@ +; /*------------------------------------------------------------------------- +; +; crtxclear.asm :- C run-time: clear XSEG +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU Library General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU Library General Public License for more details. +; +; You should have received a copy of the GNU Library General Public License +; along with this program; if not, write to the Free Software +; Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +; +; In other words, you are welcome to use, share and improve this program. +; You are forbidden to forbid anyone else to use, share and improve +; what you give them. Help stamp out software-hoarding! +; -------------------------------------------------------------------------*/ + + .area CSEG (CODE) + .area GSINIT0 (CODE) + .area GSINIT1 (CODE) + .area GSINIT2 (CODE) + .area GSINIT3 (CODE) + .area GSINIT4 (CODE) + .area GSINIT5 (CODE) + .area GSINIT (CODE) + .area GSFINAL (CODE) + + .area GSINIT4 (CODE) + +__mcs51_genXRAMCLEAR:: + mov r0,#l_XSEG + mov a,r0 + orl a,#(l_XSEG >> 8) + jz 00005$ + mov r1,#((l_XSEG + 255) >> 8) + mov dptr,#s_XSEG + clr a +00004$: movx @dptr,a + inc dptr + djnz r0,00004$ + djnz r1,00004$ +00005$: + diff --git a/device/lib/mcs51/crtxinit.asm b/device/lib/mcs51/crtxinit.asm new file mode 100644 index 00000000..b1e2f2fe --- /dev/null +++ b/device/lib/mcs51/crtxinit.asm @@ -0,0 +1,56 @@ +; /*------------------------------------------------------------------------- +; +; crtxinit.asm :- C run-time: copy XINIT to XISEG +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU Library General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU Library General Public License for more details. +; +; You should have received a copy of the GNU Library General Public License +; along with this program; if not, write to the Free Software +; Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +; +; In other words, you are welcome to use, share and improve this program. +; You are forbidden to forbid anyone else to use, share and improve +; what you give them. Help stamp out software-hoarding! +; -------------------------------------------------------------------------*/ + + .area CSEG (CODE) + .area GSINIT0 (CODE) + .area GSINIT1 (CODE) + .area GSINIT2 (CODE) + .area GSINIT3 (CODE) + .area GSINIT4 (CODE) + .area GSINIT5 (CODE) + .area GSINIT (CODE) + .area GSFINAL (CODE) + + .area GSINIT3 (CODE) + +__mcs51_genXINIT:: + mov r1,#l_XINIT + mov a,r1 + orl a,#(l_XINIT >> 8) + jz 00003$ + mov r2,#((l_XINIT+255) >> 8) + mov dptr,#s_XINIT + mov r0,#s_XISEG + mov __PAGESFR,#(s_XISEG >> 8) +00001$: clr a + movc a,@a+dptr + movx @r0,a + inc dptr + inc r0 + cjne r0,#0,00002$ + inc __PAGESFR +00002$: djnz r1,00001$ + djnz r2,00001$ + mov __PAGESFR,#0xFF +00003$: + \ No newline at end of file diff --git a/device/lib/mcs51/crtxstack.asm b/device/lib/mcs51/crtxstack.asm new file mode 100644 index 00000000..83790f7a --- /dev/null +++ b/device/lib/mcs51/crtxstack.asm @@ -0,0 +1,53 @@ +; /*------------------------------------------------------------------------- +; +; crtxstack.asm :- C run-time: setup xstack +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU Library General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU Library General Public License for more details. +; +; You should have received a copy of the GNU Library General Public License +; along with this program; if not, write to the Free Software +; Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +; +; In other words, you are welcome to use, share and improve this program. +; You are forbidden to forbid anyone else to use, share and improve +; what you give them. Help stamp out software-hoarding! +; -------------------------------------------------------------------------*/ + + .area CSEG (CODE) + .area GSINIT0 (CODE) + .area GSINIT1 (CODE) + .area GSINIT2 (CODE) + .area GSINIT3 (CODE) + .area GSINIT4 (CODE) + .area GSINIT5 (CODE) + .area GSINIT (CODE) + .area GSFINAL (CODE) + + .globl __start__xstack + .globl __PAGESFR + + .area GSINIT1 (CODE) + +__sdcc_init_xstack:: + +; Need to initialize in GSINIT1 in case the user's __sdcc_external_startup +; uses the xstack. + + mov __PAGESFR,#(__start__xstack >> 8) + mov _spx,#__start__xstack + + .area GSINIT5 (CODE) + +; Need to initialize in GSINIT5 because __mcs51_genXINIT modifies __PAGESFR +; and __mcs51_genRAMCLEAR modifies _spx. + + mov __PAGESFR,#(__start__xstack >> 8) + mov _spx,#__start__xstack diff --git a/device/lib/small/Makefile b/device/lib/small/Makefile index 2e05df18..c132ed9c 100644 --- a/device/lib/small/Makefile +++ b/device/lib/small/Makefile @@ -1,6 +1,9 @@ # Dummy Makefile to get around CVS all: + make -C ../mcs51 all + cp ../mcs51/*.rel ../mcs51/*.lib . touch dummy.lib touch dummy.rel clean: + rm *.rel *.lib diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 8b6f8ed1..21b011f5 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -14274,14 +14274,34 @@ sfr \emph default is where the chip designers decided to put it. Needless to say that they didn't agree on a common name either. - As pdata addressing is used in the startup code for the initialization - of xdata variables a separate startup code should be used as described - in section + So that the startup code can correctly initialize xdata variables, you + should define an sfr with the name _PAGESFR at the appropriate location + if the default, port P2, is not used for this. + Some examples are: +\layout Verse + + +\family typewriter +sfr at 0x92 _PAGESFR; /* Cypress EZ-USB family */ +\layout Verse + + +\family typewriter +sfr at 0xaf _PAGESFR; /* some Silicon Labs (Cygnal) chips */ +\layout Verse + + +\family typewriter +sfr at 0xaa _PAGESFR; /* some Silicon Labs (Cygnal) chips */ +\layout Standard + +For more exotic implementations further customizations may be needed. + See section \begin_inset LatexCommand \ref{sub:Startup-Code} \end_inset -. + for other possibilities. \layout Subsection Other Features available by SFR diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 9f7c4806..5ba2b367 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -1076,16 +1076,23 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile) tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0)); break; case 3: // how about '390?? + fprintf (oFile, "; generic printIvalPtr\n"); if (port->little_endian) { - fprintf (oFile, "\t.byte %s,%s,%s\n", - aopLiteral (val, 0), aopLiteral (val, 1), aopLiteral (val, 2)); + fprintf (oFile, "\t.byte %s,%s", + aopLiteral (val, 0), aopLiteral (val, 1)); } else { - fprintf (oFile, "\t.byte %s,%s,%s\n", - aopLiteral (val, 2), aopLiteral (val, 1), aopLiteral (val, 0)); + fprintf (oFile, "\t.byte %s,%s", + aopLiteral (val, 1), aopLiteral (val, 0)); } + if (IS_GENPTR (val->type)) + fprintf (oFile, ",%s\n", aopLiteral (val, 2)); + else if (IS_PTR (val->type)) + fprintf (oFile, ",#%x\n", pointerTypeToGPByte (DCL_TYPE (val->type), NULL, NULL)); + else + fprintf (oFile, ",%s\n", aopLiteral (val, 2)); } return; } @@ -1281,6 +1288,9 @@ emitStaticSeg (memmap * map, FILE * out) void emitMaps (void) { + int publicsfr = TARGET_IS_MCS51; /* Ideally, this should be true for all */ + /* ports but let's be conservative - EEP */ + inInitMode++; /* no special considerations for the following data, idata & bit & xdata */ @@ -1291,8 +1301,8 @@ emitMaps (void) if (port->genXINIT) { emitRegularMap (xidata, TRUE, TRUE); } - emitRegularMap (sfr, FALSE, FALSE); - emitRegularMap (sfrbit, FALSE, FALSE); + emitRegularMap (sfr, publicsfr, FALSE); + emitRegularMap (sfrbit, publicsfr, FALSE); emitRegularMap (home, TRUE, FALSE); emitRegularMap (code, TRUE, FALSE); @@ -1392,7 +1402,8 @@ initialComments (FILE * afile) time_t t; time (&t); fprintf (afile, "%s", iComments1); - fprintf (afile, "; Version " SDCC_VERSION_STR " %s\n", asctime (localtime (&t))); + fprintf (afile, "; Version " SDCC_VERSION_STR " (%s)\n", __DATE__); + fprintf (afile, "; This file generated %s", asctime (localtime (&t))); fprintf (afile, "%s", iComments2); } @@ -1797,38 +1808,46 @@ glue (void) if (mainf && IFFUNC_HASBODY(mainf->type)) { - fprintf (asmFile, "__sdcc_gsinit_startup:\n"); - /* if external stack is specified then the - higher order byte of the xdatalocation is - going into P2 and the lower order going into - spx */ - if (options.useXstack) - { - fprintf (asmFile, "\tmov\tP2,#0x%02x\n", - (((unsigned int) options.xdata_loc) >> 8) & 0xff); - fprintf (asmFile, "\tmov\t_spx,#0x%02x\n", - (unsigned int) options.xdata_loc & 0xff); + if (port->genInitStartup) + { + port->genInitStartup(asmFile); } + else + { + fprintf (asmFile, "__sdcc_gsinit_startup:\n"); + /* if external stack is specified then the + higher order byte of the xdatalocation is + going into P2 and the lower order going into + spx */ + if (options.useXstack) + { + fprintf (asmFile, "\tmov\tP2,#0x%02x\n", + (((unsigned int) options.xdata_loc) >> 8) & 0xff); + fprintf (asmFile, "\tmov\t_spx,#0x%02x\n", + (unsigned int) options.xdata_loc & 0xff); + } - // This should probably be a port option, but I'm being lazy. - // on the 400, the firmware boot loader gives us a valid stack - // (see '400 data sheet pg. 85 (TINI400 ROM Initialization code) - if (!TARGET_IS_DS400) - { - /* initialise the stack pointer. JCF: aslink takes care of the location */ - fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n"); /* MOF */ - } + // This should probably be a port option, but I'm being lazy. + // on the 400, the firmware boot loader gives us a valid stack + // (see '400 data sheet pg. 85 (TINI400 ROM Initialization code) + if (!TARGET_IS_DS400) + { + /* initialise the stack pointer. JCF: aslink takes care of the location */ + fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n"); /* MOF */ + } - fprintf (asmFile, "\tlcall\t__sdcc_external_startup\n"); - fprintf (asmFile, "\tmov\ta,dpl\n"); - fprintf (asmFile, "\tjz\t__sdcc_init_data\n"); - fprintf (asmFile, "\tljmp\t__sdcc_program_startup\n"); - fprintf (asmFile, "__sdcc_init_data:\n"); + fprintf (asmFile, "\tlcall\t__sdcc_external_startup\n"); + fprintf (asmFile, "\tmov\ta,dpl\n"); + fprintf (asmFile, "\tjz\t__sdcc_init_data\n"); + fprintf (asmFile, "\tljmp\t__sdcc_program_startup\n"); + fprintf (asmFile, "__sdcc_init_data:\n"); - // if the port can copy the XINIT segment to XISEG - if (port->genXINIT) { - port->genXINIT(asmFile); - } + // if the port can copy the XINIT segment to XISEG + if (port->genXINIT) + { + port->genXINIT(asmFile); + } + } } copyFile (asmFile, statsg->oFile); diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 5c6bddaf..e781993f 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -1488,7 +1488,11 @@ linkEdit (char **envp) } #endif #endif - if (!(TARGET_IS_Z80 || TARGET_IS_GBZ80 + if (TARGET_IS_MCS51) + { + fprintf (lnkfile, "-l mcs51\n"); + } + if (!(TARGET_IS_Z80 || TARGET_IS_GBZ80 || TARGET_IS_HC08)) /*Not for the z80, gbz80*/ { /*Why the z80 port is not using the standard libraries?*/ fprintf (lnkfile, "-l %s\n", STD_LIB); diff --git a/src/avr/main.c b/src/avr/main.c index 25cbdb0f..8b98bae1 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -240,6 +240,7 @@ PORT avr_port = { NULL, /* no genAssemblerEnd */ _avr_genIVT, NULL, // _avr_genXINIT + NULL, /* genInitStartup */ _avr_reset_regparm, _avr_regparm, NULL, diff --git a/src/ds390/main.c b/src/ds390/main.c index 2aacc1b3..211e9dc1 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -880,6 +880,7 @@ PORT ds390_port = NULL, /* no genAssemblerEnd */ _ds390_genIVT, _ds390_genXINIT, + NULL, /* genInitStartup */ _ds390_reset_regparm, _ds390_regparm, NULL, @@ -1178,6 +1179,7 @@ PORT tininative_port = _tininative_genAssemblerEnd, _tininative_genIVT, NULL, + NULL, /* genInitStartup */ _ds390_reset_regparm, _ds390_regparm, NULL, @@ -1391,6 +1393,7 @@ PORT ds400_port = NULL, /* no genAssemblerEnd */ _ds400_genIVT, _ds390_genXINIT, + NULL, /* genInitStartup */ _ds390_reset_regparm, _ds390_regparm, NULL, diff --git a/src/hc08/main.c b/src/hc08/main.c index c60408fc..a513f7ac 100644 --- a/src/hc08/main.c +++ b/src/hc08/main.c @@ -412,6 +412,7 @@ PORT hc08_port = NULL, /* no genAssemblerEnd */ _hc08_genIVT, _hc08_genXINIT, + NULL, /* genInitStartup */ _hc08_reset_regparm, _hc08_regparm, NULL, /* process_pragma */ diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 55aa3240..c0a49d15 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -145,6 +145,7 @@ _mcs51_genAssemblerPreamble (FILE * of) for (i=0; i < 8 ; i++ ) fprintf (of,"b1_%d = 0x%x \n",i,8+i); } + } /* Generate interrupt vector table. */ @@ -154,52 +155,49 @@ _mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) return FALSE; } -/* Generate code to clear XSEG and idata memory. - This clears XSEG, DSEG, BSEG, OSEG, SSEG */ -static void _mcs51_genRAMCLEAR (FILE * of) { - fprintf (of, "; _mcs51_genRAMCLEAR() start\n"); - fprintf (of, " mov r0,#l_XSEG\n"); - fprintf (of, " mov a,r0\n"); - fprintf (of, " orl a,#(l_XSEG >> 8)\n"); - fprintf (of, " jz 00005$\n"); - fprintf (of, " mov r1,#((l_XSEG + 255) >> 8)\n"); - fprintf (of, " mov dptr,#s_XSEG\n"); - fprintf (of, " clr a\n"); - fprintf (of, "00004$: movx @dptr,a\n"); - fprintf (of, " inc dptr\n"); - fprintf (of, " djnz r0,00004$\n"); - fprintf (of, " djnz r1,00004$\n"); - /* r0 is zero now. Clearing 256 byte assuming 128 byte devices don't mind */ - fprintf (of, "00005$: mov @r0,a\n"); - fprintf (of, " djnz r0,00005$\n"); - fprintf (of, "; _mcs51_genRAMCLEAR() end\n"); +static void +_mcs51_genExtraAreas(FILE *of, bool hasMain) +{ + tfprintf (of, "\t!area\n", port->mem.code_name); + tfprintf (of, "\t!area\n", "GSINIT0 (CODE)"); + tfprintf (of, "\t!area\n", "GSINIT1 (CODE)"); + tfprintf (of, "\t!area\n", "GSINIT2 (CODE)"); + tfprintf (of, "\t!area\n", "GSINIT3 (CODE)"); + tfprintf (of, "\t!area\n", "GSINIT4 (CODE)"); + tfprintf (of, "\t!area\n", "GSINIT5 (CODE)"); +} + +static void +_mcs51_genInitStartup (FILE *of) +{ + tfprintf (of, "\t!global\n", "__sdcc_gsinit_startup"); + tfprintf (of, "\t!global\n", "__sdcc_program_startup"); + tfprintf (of, "\t!global\n", "__start__stack"); + + if (options.useXstack) + { + tfprintf (of, "\t!global\n", "__sdcc_init_xstack"); + tfprintf (of, "\t!global\n", "__start__xstack"); + fprintf (of, "__start__xstack = 0x%04x", options.xdata_loc); + } + + // if the port can copy the XINIT segment to XISEG + if (port->genXINIT) + { + port->genXINIT(of); + } + + if (!getenv("SDCC_NOGENRAMCLEAR")) + tfprintf (of, "\t!global\n", "__mcs51_genRAMCLEAR"); } + /* Generate code to copy XINIT to XISEG */ static void _mcs51_genXINIT (FILE * of) { - fprintf (of, "; _mcs51_genXINIT() start\n"); - fprintf (of, " mov r1,#l_XINIT\n"); - fprintf (of, " mov a,r1\n"); - fprintf (of, " orl a,#(l_XINIT >> 8)\n"); - fprintf (of, " jz 00003$\n"); - fprintf (of, " mov r2,#((l_XINIT+255) >> 8)\n"); - fprintf (of, " mov dptr,#s_XINIT\n"); - fprintf (of, " mov r0,#s_XISEG\n"); - fprintf (of, " mov p2,#(s_XISEG >> 8)\n"); - fprintf (of, "00001$: clr a\n"); - fprintf (of, " movc a,@a+dptr\n"); - fprintf (of, " movx @r0,a\n"); - fprintf (of, " inc dptr\n"); - fprintf (of, " inc r0\n"); - fprintf (of, " cjne r0,#0,00002$\n"); - fprintf (of, " inc p2\n"); - fprintf (of, "00002$: djnz r1,00001$\n"); - fprintf (of, " djnz r2,00001$\n"); - fprintf (of, " mov p2,#0xFF\n"); - fprintf (of, "00003$:\n"); - fprintf (of, "; _mcs51_genXINIT() end\n"); + tfprintf (of, "\t!global\n", "__mcs51_genXINIT"); - if (!getenv("SDCC_NOGENRAMCLEAR")) _mcs51_genRAMCLEAR (of); + if (!getenv("SDCC_NOGENRAMCLEAR")) + tfprintf (of, "\t!global\n", "__mcs51_genXRAMCLEAR"); } @@ -706,7 +704,7 @@ PORT mcs51_port = NULL, 1 }, - { NULL, NULL }, + { _mcs51_genExtraAreas, NULL }, { +1, 0, 4, 1, 1, 0 }, @@ -727,6 +725,7 @@ PORT mcs51_port = NULL, /* no genAssemblerEnd */ _mcs51_genIVT, _mcs51_genXINIT, + _mcs51_genInitStartup, _mcs51_reset_regparm, _mcs51_regparm, NULL, diff --git a/src/pic/main.c b/src/pic/main.c index 86d29fe8..a84d1bc8 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -466,6 +466,7 @@ PORT pic_port = NULL, /* no genAssemblerEnd */ _pic14_genIVT, NULL, // _pic14_genXINIT + NULL, /* genInitStartup */ _pic14_reset_regparm, _pic14_regparm, _process_pragma, /* process a pragma */ diff --git a/src/pic16/main.c b/src/pic16/main.c index 5685d878..6c98fb22 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -819,6 +819,7 @@ PORT pic16_port = NULL, /* no genAssemblerEnd */ _pic16_genIVT, NULL, // _pic16_genXINIT + NULL, /* genInitStartup */ _pic16_reset_regparm, _pic16_regparm, _process_pragma, /* process a pragma */ diff --git a/src/port.h b/src/port.h index 010a3efd..e3c08ae7 100644 --- a/src/port.h +++ b/src/port.h @@ -236,6 +236,9 @@ typedef struct int (*genIVT) (FILE * of, symbol ** intTable, int intCount); void (*genXINIT) (FILE * of); + + /* Write port specific startup code */ + void (*genInitStartup) (FILE * of); /* parameter passing in register related functions */ void (*reset_regparms) (); /* reset the register count */ diff --git a/src/xa51/main.c b/src/xa51/main.c index 4a6ffc81..51bc27f5 100755 --- a/src/xa51/main.c +++ b/src/xa51/main.c @@ -314,6 +314,7 @@ PORT xa51_port = _xa51_genAssemblerEnd, _xa51_genIVT, _xa51_genXINIT, + NULL, /* genInitStartup */ _xa51_reset_regparm, _xa51_regparm, NULL, // process_pragma() diff --git a/src/z80/main.c b/src/z80/main.c index 44cd21e3..d2a21845 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -636,6 +636,7 @@ PORT z80_port = NULL, /* no genAssemblerEnd */ 0, /* no local IVT generation code */ 0, /* no genXINIT code */ + NULL, /* genInitStartup */ _reset_regparm, _reg_parm, _process_pragma, @@ -736,6 +737,7 @@ PORT gbz80_port = NULL, /* no genAssemblerEnd */ 0, /* no local IVT generation code */ 0, /* no genXINIT code */ + NULL, /* genInitStartup */ _reset_regparm, _reg_parm, _process_pragma, diff --git a/support/regression/ports/mcs51-stack-auto/spec.mk b/support/regression/ports/mcs51-stack-auto/spec.mk index 38d21984..c0e39696 100644 --- a/support/regression/ports/mcs51-stack-auto/spec.mk +++ b/support/regression/ports/mcs51-stack-auto/spec.mk @@ -6,7 +6,8 @@ LIBSRCDIR = ../../device/lib LIBDIR = gen/$(PORT)/lib LIBSDCCFLAGS+=--stack-auto --int-long-reent --float-reent -SDCCFLAGS +=$(LIBSDCCFLAGS) --nostdlib -L$(LIBDIR) -llibsdcc -llibint -lliblong -llibfloat +SDCCFLAGS +=$(LIBSDCCFLAGS) --nostdlib -L$(LIBDIR) -llibsdcc -llibint \ + -lliblong -llibfloat -lmcs51 # copy support.c $(PORTS_DIR)/$(PORT)/%.c: $(PORTS_DIR)/mcs51/%.c @@ -51,5 +52,7 @@ $(LIBDIR)/%.rel: $(LIBSRCDIR)/%.c .PHONY: lib-files lib-files: + make -C $(LIBSRCDIR)/mcs51 all + cp $(LIBSRCDIR)/mcs51/*.rel $(LIBSRCDIR)/mcs51/mcs51.lib $(LIBDIR) echo $(MODULES) | tr ' ' '\n' > $(LIBDIR)/libsdcc.lib touch $(LIBDIR)/libfloat.lib $(LIBDIR)/libint.lib $(LIBDIR)/liblong.lib diff --git a/support/regression/tests/longlit.c b/support/regression/tests/longlit.c index 033a7314..c8e7fcf6 100644 --- a/support/regression/tests/longlit.c +++ b/support/regression/tests/longlit.c @@ -8,7 +8,7 @@ #define T1_RELOAD_VALUE -(2*OSCILLATOR)/(32*12*BAUD) -unsigned char T1=T1_RELOAD_VALUE; +static unsigned char T1=T1_RELOAD_VALUE; void test (void) { ASSERT(T1==0xfd);