Signed comparisons are now working (except for signed longs)
[fw/sdcc] / src / pic / glue.c
index 77f6cc68591e7ba1f91148f514096a8abcd15c55..81c86b3665c9ae2b01e5d6ef59ca8afdff66e210 100644 (file)
@@ -33,7 +33,7 @@ extern symbol *interrupts[256];
 void printIval (symbol *, sym_link *, initList *, FILE *);
 extern int noAlloc;
 extern set *publics;
-extern int maxInterrupts;
+extern unsigned maxInterrupts;
 extern int maxRegBank;
 extern symbol *mainf;
 extern char *VersionString;
@@ -105,7 +105,7 @@ int pic14aopLiteral (value *val, int offset)
   /* if it is a float then it gets tricky */
   /* otherwise it is fairly simple */
   if (!IS_FLOAT(val->type)) {
-    unsigned long v = floatFromVal(val);
+    unsigned long v = (unsigned long) floatFromVal(val);
 
     //v >>= (offset * 8);
     return ( (v >> (offset * 8)) & 0xff);
@@ -806,7 +806,7 @@ pic14emitMaps ()
 static void
 pic14createInterruptVect (FILE * vFile)
 {
-  int i = 0;
+  unsigned i = 0;
   mainf = newSymbol ("main", 0);
   mainf->block = 0;
 
@@ -992,7 +992,7 @@ pic14emitOverlay (FILE * afile)
 /* glue - the final glue that hold the whole thing together        */
 /*-----------------------------------------------------------------*/
 void
-pic14glue ()
+picglue ()
 {
 
   FILE *vFile;
@@ -1001,6 +1001,49 @@ pic14glue ()
   int i;
 
   addSetHead(&tmpfileSet,ovrFile);
+
+
+  if (mainf && mainf->fbody) {
+
+    pBlock *pb = newpCodeChain(NULL,'X',newpCodeCharP("; Starting pCode block"));
+    addpBlock(pb);
+
+    /* entry point @ start of CSEG */
+    addpCode2pBlock(pb,newpCodeLabelStr("__sdcc_program_startup"));
+    /* put in the call to main */
+    addpCode2pBlock(pb,newpCode(POC_CALL,newpCodeOp("_main",PO_STR)));
+
+    if (options.mainreturn) {
+
+      addpCode2pBlock(pb,newpCodeCharP(";\treturn from main will return to caller\n"));
+      addpCode2pBlock(pb,newpCode(POC_RETURN,NULL));
+
+    } else {
+
+      addpCode2pBlock(pb,newpCodeCharP(";\treturn from main will lock up\n"));
+      addpCode2pBlock(pb,newpCode(POC_GOTO,newpCodeOp("$",PO_STR)));
+
+    }
+  }
+
+
+  /* At this point we've got all the code in the form of pCode structures */
+  /* Now it needs to be rearranged into the order it should be placed in the */
+  /* code space */
+
+  movepBlock2Head(code->dbName);     // Last
+  movepBlock2Head('X');
+  movepBlock2Head(statsg->dbName);   // First
+
+
+  AnalyzepCode('*'); //code->dbName);
+  printCallTree(stderr);
+
+  pCodePeepInit();
+
+  OptimizepCode(code->dbName);
+
+
   /* print the global struct definitions */
   if (options.debug)
     cdbStructBlock (0,cdbFile);
@@ -1063,14 +1106,13 @@ pic14glue ()
     
 
   /* Put all variables into a cblock */
-  fprintf (asmFile, "\n\n\tcblock  0x13\n\n");
+  fprintf (asmFile, "\n\n\tcblock  0x20\n\n");
 
   for(i=0; i<pic14_nRegs; i++) {
     if(regspic14[i].wasUsed && (regspic14[i].offset>=0x0c) )
       fprintf (asmFile, "\t%s\n",regspic14[i].name);
   }
-  //fprintf (asmFile, "\tr0x0C\n");
-  //fprintf (asmFile, "\tr0x0D\n");
+
 
   /* For now, create a "dpl" and a "dph" in the register space */
   /* of the pic so that we can use the same calling mechanism */
@@ -1182,26 +1224,7 @@ pic14glue ()
              (unsigned int)options.xdata_loc & 0xff);
     }
 
-    /* initialise the stack pointer */
-    /* if the user specified a value then use it */
-    if (options.stack_loc) 
-      fprintf(asmFile,";\tmov\tsp,#%d\n",options.stack_loc);
-    else 
-      /* no: we have to compute it */
-      if (!options.stackOnData && maxRegBank <= 3)
-       fprintf(asmFile,";\tmov\tsp,#%d\n",((maxRegBank + 1) * 8) -1); 
-      else
-       fprintf(asmFile,";\tmov\tsp,#__start__stack\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");
-       
   }
-  //copyFile (asmFile, statsg->oFile);
-  copypCode(asmFile, statsg->dbName);
 
   if (port->general.glue_up_main && mainf && mainf->fbody)
     {
@@ -1218,33 +1241,13 @@ pic14glue ()
   fprintf (asmFile, "; code\n");
   fprintf (asmFile, "%s", iComments2);
   fprintf (asmFile, ";\t.area %s\n", port->mem.code_name);
-  if (mainf && mainf->fbody) {
-       
-    /* entry point @ start of CSEG */
-    fprintf (asmFile,"__sdcc_program_startup:\n");
-       
-    /* put in the call to main */
-    fprintf(asmFile,"\tcall\t_main\n");
-    if (options.mainreturn) {
-
-      fprintf(asmFile,";\treturn from main ; will return to caller\n");
-      fprintf(asmFile,"\treturn\n");
-
-    } else {
-                  
-      fprintf(asmFile,";\treturn from main will lock up\n");
-      fprintf(asmFile,"\tgoto\t$\n");
-    }
-  }
 
-  AnalyzepCode(code->dbName);
-  pCodePeepInit();
-
-  OptimizepCode(code->dbName);
   //copyFile (asmFile, code->oFile);
+
+  copypCode(asmFile, statsg->dbName);
+  copypCode(asmFile, 'X');
   copypCode(asmFile, code->dbName);
 
-  printCallTree(stderr);
 
   fprintf (asmFile,"\tend\n");