fixed bug #655842
[fw/sdcc] / src / SDCCglue.c
index 75c40870403e09a3b6afb4ada19a4d72ef3579b4..59f82998c0ae74494db1f6ab87f58f442fff2a36 100644 (file)
@@ -1229,7 +1229,7 @@ createInterruptVect (FILE * vFile)
   /* only if the main function exists */
   if (!(mainf = findSymWithLevel (SymbolTab, mainf)))
     {
-      if (!options.cc_only && !noAssemble)
+      if (!options.cc_only && !noAssemble && !options.c1mode)
        werror (E_NO_MAIN);
       return;
     }
@@ -1458,22 +1458,15 @@ glue (void)
   /* now put it all together into the assembler file */
   /* create the assembler file name */
 
-  if (!options.c1mode)
+  /* -o option overrides default name? */
+  if ((noAssemble || options.c1mode) && fullDstFileName)
     {
-      /* -o option overrides default name? */
-      if (noAssemble && fullDstFileName)
-        {
-          strcpy (scratchFileName, fullDstFileName);
-        }
-      else
-        {
-          strcpy (scratchFileName, dstFileName);
-      strcat (scratchFileName, port->assembler.file_ext);
-        }
+      strcpy (scratchFileName, fullDstFileName);
     }
   else
     {
-      strcpy (scratchFileName, options.out_name);
+      strcpy (scratchFileName, dstFileName);
+      strcat (scratchFileName, port->assembler.file_ext);
     }
 
   if (!(asmFile = fopen (scratchFileName, "w")))
@@ -1513,7 +1506,8 @@ glue (void)
   copyFile (asmFile, sfrbit->oFile);
   
   /*JCF: Create the areas for the register banks*/
-  if( TARGET_IS_MCS51 || TARGET_IS_DS390 || TARGET_IS_XA51 )
+  if(port->general.glue_up_main &&
+     (TARGET_IS_MCS51 || TARGET_IS_DS390 || TARGET_IS_XA51))
   {
          if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3])
          {
@@ -1633,7 +1627,7 @@ glue (void)
        }
 
       /* initialise the stack pointer.  JCF: aslink takes care of the location */
-       fprintf (asmFile, "\tmov\tsp,#__start__stack\n");       /* MOF */
+       fprintf (asmFile, "\tmov\tsp,#__start__stack - 1\n");   /* MOF */
 
       fprintf (asmFile, "\tlcall\t__sdcc_external_startup\n");
       fprintf (asmFile, "\tmov\ta,dpl\n");