* src/SDCCicode.c (operandOperation): fixed bug #874819
[fw/sdcc] / src / pic / glue.c
index 6f54ed1d7100a477e3d5de757cb0c0deaf4d081f..c007753353c15070c71159495b0287a43ffedf62 100644 (file)
@@ -68,6 +68,8 @@ extern void printChar (FILE * ofile, char *s, int plen);
 void  pCodeInitRegisters(void);
 int getConfigWord(int address);
 
+char *udata_section_name="udata";              // FIXME Temporary fix to change udata section name -- VR
+
 /*-----------------------------------------------------------------*/
 /* aopLiteral - string from a literal value                        */
 /*-----------------------------------------------------------------*/
@@ -106,14 +108,14 @@ pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
   symbol *sym;
   int bitvars = 0;;
 
+  /* print the area name */
   if (addPublics)
     fprintf (map->oFile, ";\t.area\t%s\n", map->sname);
 
-  /* print the area name */
   for (sym = setFirstItem (map->syms); sym;
        sym = setNextItem (map->syms)) {
 
-    printf("%s\n",sym->name);
+    //printf("%s\n",sym->name);
 
     /* if extern then add it into the extern list */
     if (IS_EXTERN (sym->etype)) {
@@ -280,7 +282,7 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
   if(!pb)
     return 0;
 
-  fprintf(stderr, "%s\n",__FUNCTION__);
+  //fprintf(stderr, "%s\n",__FUNCTION__);
   if (!s)
     {
 
@@ -307,7 +309,7 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
   else {
     //printChar (oFile, s, strlen (s) + 1);
 
-    for(remain=0; remain<strlen(s); remain++) {
+    for(remain=0; remain<(int)strlen(s); remain++) {
       addpCode2pBlock(pb,newpCode(POC_RETLW,newpCodeOpLit(s[remain])));
       //fprintf(stderr,"0x%02x ",s[remain]);
     }
@@ -572,14 +574,15 @@ pic14createInterruptVect (FILE * vFile)
   fprintf (vFile, "\t__config 0x%x\n", getConfigWord(0x2007));
 
   fprintf (vFile, "%s", iComments2);
-  fprintf (vFile, "; reset and interrupt vectors \n");
+  fprintf (vFile, "; reset vector \n");
   fprintf (vFile, "%s", iComments2);
   fprintf (vFile, "STARTUP\t%s\n", CODE_NAME);
+  fprintf (vFile, "\tnop\n"); /* first location used by incircuit debugger */
   fprintf (vFile, "\tgoto\t__sdcc_gsinit_startup\n");
-  fprintf (vFile, "\tnop\n");
+/* during an interrupt PCLATH must be cleared before a goto  - delete me
   fprintf (vFile, "\tnop\n");
   fprintf (vFile, "\tgoto\t__sdcc_interrupt\n");
-
+*/
 }
 
 
@@ -626,9 +629,10 @@ pic14printPublics (FILE * afile)
 
   for (sym = setFirstItem (publics); sym;
        sym = setNextItem (publics)) {
-    if(!IS_BITFIELD(sym->type) && ((IS_FUNC(sym->type) || sym->allocreq)))
-      fprintf (afile, "\tglobal %s\n", sym->rname);
-    else
+    if(!IS_BITFIELD(sym->type) && ((IS_FUNC(sym->type) || sym->allocreq))) {
+      if (!IS_BITVAR(sym->type))
+        fprintf (afile, "\tglobal %s\n", sym->rname);
+    } else
       fprintf (afile, ";\tglobal %s\n", sym->rname);
   }
 }
@@ -641,8 +645,13 @@ pic14emitOverlay (FILE * afile)
 {
   set *ovrset;
 
-  if (!elementsInSet (ovrSetSets))
-    fprintf (afile, "\t%s\n", port->mem.overlay_name);
+/*  if (!elementsInSet (ovrSetSets))*/
+
+  /* the hack below, fixes translates for devices which
+   * only have udata_shr memory */
+  fprintf (afile, "%s\t%s\n",
+       (elementsInSet(ovrSetSets)?"":";"),
+       port->mem.overlay_name);
 
   /* for each of the sets in the overlay segment do */
   for (ovrset = setFirstItem (ovrSetSets); ovrset;
@@ -789,11 +798,6 @@ picglue ()
     cdbStructBlock (0);
 
   vFile = tempfile();
-  /* PENDING: this isnt the best place but it will do */
-  if (port->general.glue_up_main) {
-    /* create the interrupt vector table */
-    pic14createInterruptVect (vFile);
-  }
 
   addSetHead(&tmpfileSet,vFile);
     
@@ -802,6 +806,11 @@ picglue ()
   /* do the overlay segments */
   pic14emitOverlay(ovrFile);
 
+  /* PENDING: this isnt the best place but it will do */
+  if (port->general.glue_up_main) {
+    /* create the interrupt vector table */
+    pic14createInterruptVect (vFile);
+  }
 
   AnalyzepCode('*');
 
@@ -859,9 +868,9 @@ picglue ()
   copyFile (asmFile, sfr->oFile);
 
   fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "; udata\n");
+  fprintf (asmFile, "; %s\n", udata_section_name);
   fprintf (asmFile, "%s", iComments2);
-  fprintf (asmFile, "\tudata\n");
+  fprintf (asmFile, "\t%s\n", udata_section_name);
   copyFile (asmFile, data->oFile);
 
   /* Put all variables into a cblock */
@@ -919,11 +928,15 @@ picglue ()
     copyFile (asmFile, vFile);
     
     fprintf (asmFile, "%s", iComments2);
-    fprintf (asmFile, "; initialization and interrupt code \n");
+    fprintf (asmFile, "; interrupt and initialization code\n");
     fprintf (asmFile, "%s", iComments2);
+    fprintf (asmFile, "code_init\t%s\t0x4\n", CODE_NAME);
+
+    /* interrupt service routine */
+    fprintf (asmFile, "__sdcc_interrupt:\n");
+    copypCode(asmFile, 'I');
 
     /* initialize data memory */
-    fprintf (asmFile, "code_init\t%s\t0x10\n", CODE_NAME);
     fprintf (asmFile,"__sdcc_gsinit_startup:\n");
     /* FIXME: This is temporary.  The idata section should be used.  If 
        not, we could add a special feature to the linker.  This will 
@@ -931,11 +944,6 @@ picglue ()
     copypCode(asmFile, statsg->dbName);
     fprintf (asmFile,"\tpagesel _main\n");
     fprintf (asmFile,"\tgoto _main\n");
-
-    /* interrupt service routine */
-    fprintf (asmFile, "__sdcc_interrupt:\n");
-    copypCode(asmFile, 'I');
-    fprintf (asmFile,"\tgoto $\n");
   }
 
 #if 0