* src/SDCCglue.c (emitMaps): allow public sfr variables
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 17 Mar 2004 23:33:26 +0000 (23:33 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 17 Mar 2004 23:33:26 +0000 (23:33 +0000)
* 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

25 files changed:
ChangeLog
device/lib/clean.mk
device/lib/large/Makefile
device/lib/mcs51/Makefile [new file with mode: 0644]
device/lib/mcs51/crtclear.asm [new file with mode: 0644]
device/lib/mcs51/crtpagesfr.asm [new file with mode: 0644]
device/lib/mcs51/crtstart.asm [new file with mode: 0644]
device/lib/mcs51/crtxclear.asm [new file with mode: 0644]
device/lib/mcs51/crtxinit.asm [new file with mode: 0644]
device/lib/mcs51/crtxstack.asm [new file with mode: 0644]
device/lib/small/Makefile
doc/sdccman.lyx
src/SDCCglue.c
src/SDCCmain.c
src/avr/main.c
src/ds390/main.c
src/hc08/main.c
src/mcs51/main.c
src/pic/main.c
src/pic16/main.c
src/port.h
src/xa51/main.c
src/z80/main.c
support/regression/ports/mcs51-stack-auto/spec.mk
support/regression/tests/longlit.c

index 0b9f426042c015ffec61f7500e6a4ff49fc45142..89eb7ed38daf6cdb9d8123b7a36c254d7cd0e6a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+2004-03-17 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * 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 <epetrich AT ivorytower.norman.ok.us>
 
        * device/include/mc68hc908qy.h: corrected declarations of FLBPR and
index e4b0a401820b8076f96133a703cbddab07fcfaa8..f1fa504c286706289d0167bf96db511e0c103734 100644 (file)
@@ -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
index 2e05df18d085d5071e08990b31fd5a35d0326e8b..c132ed9caf424c1ee3bd26b6dd70be0c0c4d317b 100644 (file)
@@ -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 (file)
index 0000000..9476653
--- /dev/null
@@ -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 (file)
index 0000000..3ccaca8
--- /dev/null
@@ -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 (file)
index 0000000..ae799a5
--- /dev/null
@@ -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 (file)
index 0000000..37978ed
--- /dev/null
@@ -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 (file)
index 0000000..819c111
--- /dev/null
@@ -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 (file)
index 0000000..b1e2f2f
--- /dev/null
@@ -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 (file)
index 0000000..83790f7
--- /dev/null
@@ -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
index 2e05df18d085d5071e08990b31fd5a35d0326e8b..c132ed9caf424c1ee3bd26b6dd70be0c0c4d317b 100644 (file)
@@ -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
index 8b6f8ed12c22e92cf6f27d65ab4e5cb67bb3eb58..21b011f5c8c86d4a6450116e82796097704ca541 100644 (file)
@@ -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
index 9f7c4806707de3a4d438ffe20bf637192841dcae..5ba2b3670c109593da6d25f2dd4a672bb03811af 100644 (file)
@@ -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);
index 5c6bddaf72f9a6d895edd85ae069b1b434c2eef9..e781993fb638dc81e1918f9ef39e13762fc17e16 100644 (file)
@@ -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);
index 25cbdb0ff7019643b7f468baf9a1a5d361f77d34..8b98bae14cfd5777e1fea032d01db35ecdc3ea7a 100644 (file)
@@ -240,6 +240,7 @@ PORT avr_port = {
        NULL,                           /* no genAssemblerEnd */
        _avr_genIVT,
        NULL, // _avr_genXINIT
+       NULL,                   /* genInitStartup */
        _avr_reset_regparm,
        _avr_regparm,
         NULL,
index 2aacc1b311bc0311c324018c2077a8d5f76851bf..211e9dc180239627d96e1b8227fb1b48fe5e8c89 100644 (file)
@@ -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,
index c60408fc959a4857fb90964e1a2e3f33bdeb2443..a513f7ac12023503ba87651721d8d4c505b0f248 100644 (file)
@@ -412,6 +412,7 @@ PORT hc08_port =
   NULL,                                /* no genAssemblerEnd */
   _hc08_genIVT,
   _hc08_genXINIT,
+  NULL,                        /* genInitStartup */
   _hc08_reset_regparm,
   _hc08_regparm,
   NULL,                                /* process_pragma */
index 55aa324054943c83e9e1d6362e0edb99bc9ecd59..c0a49d15374834a5916c68c38d6d42fe79f467e1 100644 (file)
@@ -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,
index 86d29fe8bb52c3e8140535aa9f600d4517d58421..a84d1bc8050122c8419d470bd3226677f16db153 100644 (file)
@@ -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 */
index 5685d878bf4398c209bb479cffaeafa547ea2e84..6c98fb22d3934f1f8f29ed09807fe2f92936e905 100644 (file)
@@ -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 */
index 010a3efde29e7f529c1c4ef4dbffc192229ba00a..e3c08ae7287575aa952b27fa88a435174039d08c 100644 (file)
@@ -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 */
index 4a6ffc8183c9c6826f11a4b9b4e2be5a3aa3209e..51bc27f574d05d898cc0da77a6aaac30e6ff97c8 100755 (executable)
@@ -314,6 +314,7 @@ PORT xa51_port =
   _xa51_genAssemblerEnd,
   _xa51_genIVT,
   _xa51_genXINIT,
+  NULL,                        /* genInitStartup */
   _xa51_reset_regparm,
   _xa51_regparm,
   NULL, // process_pragma()
index 44cd21e372a12822924cf40b903877e9b6ea2c31..d2a21845b73279fa445bc33b892412ccb5141529 100644 (file)
@@ -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,
index 38d21984b7db07624ad2e78837bec11fada24960..c0e396965d5c019a4ef548c9a289471f079b7bc6 100644 (file)
@@ -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
index 033a731400976946808566b1d33037ffff6e1cf4..c8e7fcf65bd9e3e1edb85b27e922dde30b6e74f7 100644 (file)
@@ -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);