* src/pic/pcode.c (register_reassign): do not crash on recursive code
[fw/sdcc] / src / pic / glue.c
index c5f491e146b54c2eec075a1ab1550aa00124ac62..b075cdb99d6a92dfc38a8fee37ff88744fb4b4c4 100644 (file)
@@ -73,8 +73,6 @@ extern void printChar (FILE * ofile, char *s, int plen);
 void  pCodeInitRegisters(void);
 int getConfigWord(int address);
 int getHasSecondConfigReg(void);
-int pic14_getSharebankSize(void);
-int pic14_getSharebankAddress(void);
 
 char *udata_section_name=0;            // FIXME Temporary fix to change udata section name -- VR
 int pic14_hasInterrupt = 0;            // Indicates whether to emit interrupt handler or not
@@ -107,22 +105,6 @@ unsigned int pic14aopLiteral (value *val, int offset)
        
 }
 
-/* Check whether the given reg is shared amongst all .o files of a project.
- * This is true for the pseudo stack and WSAVE, SSAVE and PSAVE. */
-static int
-is_shared_address (int addr)
-{
-  return ((addr > Gstack_base_addr - 18)
-       && (addr <= Gstack_base_addr));
-}
-
-int
-pic14_is_shared (regs *reg)
-{
-       if (!reg) return 0;
-       return is_shared_address (reg->address);
-}
-
 static int
 is_valid_identifier( const char *name )
 {
@@ -238,6 +220,8 @@ pic14_constructAbsMap (FILE *ofile)
   set *aliases;
   int addr, min=-1, max=-1;
   int size;
+  PIC_device *pic;
+  int low, high, shared;
 
   for (i=0; maps[i] != NULL; i++)
   {
@@ -301,6 +285,8 @@ pic14_constructAbsMap (FILE *ofile)
        if (getSize(sym->type) > size) {
          size = getSize(sym->type);
        }
+       addSet (&symbolsEmitted, (void *) sym->name);
+       addSet (&symbolsEmitted, (void *) sym->rname);
       } // for
       fprintf (ofile, "\tres\t%d\n", size);
     } // if
@@ -312,21 +298,32 @@ pic14_constructAbsMap (FILE *ofile)
    *      required by larger devices but only up to STK03 might
    *      be defined using smaller devices. */
   fprintf (ofile, "\n");
+  shared = pic14_getSharedStack(&low, &high, &size);
   if (!pic14_options.isLibrarySource)
   {
+    pic = pic14_getPIC();
+
     fprintf (ofile, "\tglobal PSAVE\n");
     fprintf (ofile, "\tglobal SSAVE\n");
     fprintf (ofile, "\tglobal WSAVE\n");
-    for (i=pic14_getSharebankSize()-4; i >= 0; i--) {
+    for (i = size - 4; i >= 0; i--) {
       fprintf (ofile, "\tglobal STK%02d\n", i);
     } // for i
-    fprintf (ofile, "sharebank udata_ovr 0x%04x\n",
-         pic14_getSharebankAddress() - pic14_getSharebankSize() + 1);
+
+    // 16f84 has no SHAREBANK (in linkerscript) but memory aliased in two
+    // banks, sigh...
+    if (1 || !shared) {
+       // for single banked devices: use normal, "banked" RAM
+       fprintf (ofile, "sharebank udata_ovr 0x%04X\n", low);
+    } else {
+       // for devices with at least two banks, require a sharebank section
+       fprintf (ofile, "sharebank udata_shr\n");
+    }
     fprintf (ofile, "PSAVE\tres 1\n");
     fprintf (ofile, "SSAVE\tres 1\n");
-    fprintf (ofile, "WSAVE\tres 1\n");
+    fprintf (ofile, "WSAVE\tres 1\n"); // WSAVE *must* be in sharebank (IRQ handlers)
     /* fill rest of sharebank with stack STKxx .. STK00 */
-    for (i=pic14_getSharebankSize()-4; i >= 0; i--) {
+    for (i = size - 4; i >= 0; i--) {
       fprintf (ofile, "STK%02d\tres 1\n", i);
     } // for i
   } else {
@@ -335,8 +332,11 @@ pic14_constructAbsMap (FILE *ofile)
     fprintf (ofile, "\textern PSAVE\n");
     fprintf (ofile, "\textern SSAVE\n");
     fprintf (ofile, "\textern WSAVE\n");
-    for (i=pic14_getSharebankSize()-4; i >= 0; i--) {
-      fprintf (ofile, "\textern STK%02d\n", i);
+    for (i = size - 4; i >= 0; i--) {
+       char buffer[128];
+       SNPRINTF(&buffer[0], 127, "STK%02d", i);
+       fprintf (ofile, "\textern %s\n", &buffer[0]);
+       addSet (&symbolsEmitted, (void *) &buffer[0]);
     } // for i
   }
 }
@@ -974,6 +974,7 @@ pic14emitMaps ()
        pic14emitRegularMap (sfrbit, FALSE, FALSE);
        pic14emitRegularMap (code, TRUE, FALSE);
        pic14emitStaticSeg (statsg);
+       pic14emitStaticSeg (c_abs);
 }
 
 /*-----------------------------------------------------------------*/
@@ -1010,6 +1011,7 @@ pic14createInterruptVect (FILE * vFile)
        fprintf (vFile, "%s", iComments2);
        fprintf (vFile, "STARTUP\t%s\n", CODE_NAME); // Lkr file should place section STARTUP at address 0x0
        fprintf (vFile, "\tnop\n"); /* first location for used by incircuit debugger */
+       fprintf( vFile, "\tpagesel __sdcc_gsinit_startup\n");
        fprintf (vFile, "\tgoto\t__sdcc_gsinit_startup\n");
 }
 
@@ -1086,7 +1088,7 @@ pic14printPublics (FILE * afile)
   symbol *sym;
 
   fprintf (afile, "%s", iComments2);
-  fprintf (afile, "; publics variables in this module\n");
+  fprintf (afile, "; public variables in this module\n");
   fprintf (afile, "%s", iComments2);
 
   for (sym = setFirstItem (publics); sym;