fixed check_syntax(), "break xram r 0x7654" did not work.
[fw/sdcc] / src / SDCCmain.c
index c1510d14e16761f8a13c1e3e22a45e8e29046aa4..5c3e0e2782cc8f0662ccf41009e642ac1650d6c6 100644 (file)
@@ -56,6 +56,7 @@ char *srcFileName;            /* source file name with the .c stripped */
 char *moduleName;              /* module name is srcFilename stripped of any path */
 const char *preArgv[128];      /* pre-processor arguments  */
 int currRegBank = 0;
+int RegBankUsed[4]={1, 0, 0, 0};       /*JCF: Reg Bank 0 used by default*/
 struct optimize optimize;
 struct options options;
 char *VersionString = SDCC_VERSION_STR;
@@ -71,6 +72,7 @@ char *relFiles[128];
 int nrelFiles = 0;
 bool verboseExec = FALSE;
 char *preOutName;
+bool noXinitOpt = FALSE;
 
 /* uncomment JAMIN_DS390 to always override and use ds390 port
   for mcs51 work.  This is temporary, for compatibility testing. */
@@ -115,6 +117,7 @@ char DefaultExePath[128];
 #define OPTION_NO_GCSE         "--nogcse"
 #define OPTION_SHORT_IS_8BITS  "--short-is-8bits"
 #define OPTION_TINI_LIBID      "--tini-libid"
+#define OPTION_NO_XINIT_OPT     "--no-xinit-opt"
 
 static const OPTION 
 optionsTable[] = {
@@ -196,6 +199,7 @@ optionsTable[] = {
     { 0,    "--tini-libid",        NULL,"<nnnn> LibraryID used in -mTININative"},
     { 0,    "--protect-sp-update",  &options.protect_sp_update,"DS390 - will disable interrupts during ESP:SP updates"},
     { 0,    "--parms-in-bank1",            &options.parms_in_bank1,"MCS51/DS390 - use Bank1 for parameter passing"},
+    { 0,    OPTION_NO_XINIT_OPT,    &noXinitOpt, "don't memcpy initialized xram from code"},
     /* End of options */
     { 0,    NULL }
 };
@@ -294,6 +298,15 @@ _setPort (const char *name)
   exit (1);
 }
 
+/* Override the default processor with the one specified 
+ * on the command line */
+static void
+_setProcessor (char *_processor)
+{
+  port->processor = _processor;
+  fprintf(stderr,"Processor: %s\n",_processor);
+}
+
 static void
 _validatePorts (void)
 {
@@ -330,6 +343,23 @@ _findPort (int argc, char **argv)
   port = _ports[0];
 }
 
+/* search through the command line options for the processor */
+static void
+_findProcessor (int argc, char **argv)
+{
+  while (argc--)
+    {
+      if (!strncmp (*argv, "-p", 2))
+       {
+         _setProcessor (*argv + 2);
+         return;
+       }
+      argv++;
+    }
+
+  /* no error if processor was not specified. */
+}
+
 /*-----------------------------------------------------------------*/
 /* printVersionInfo - prints the version info        */
 /*-----------------------------------------------------------------*/
@@ -452,7 +482,7 @@ setDefaultOptions ()
   options.stack_loc = 0;       /* stack pointer initialised to 0 */
   options.xstack_loc = 0;      /* xternal stack starts at 0 */
   options.code_loc = 0;                /* code starts at 0 */
-  options.data_loc = 0x0030;   /* data starts at 0x0030 */
+  options.data_loc = 0;                /* JCF: By default let the linker locate data */
   options.xdata_loc = 0;
   options.idata_loc = 0x80;
   options.genericPtr = 1;      /* default on */
@@ -597,13 +627,6 @@ _setModel (int model, const char *sz)
     werror (W_UNSUPPORTED_MODEL, sz, port->target);
 }
 
-static void
-_setProcessor (char *_processor)
-{
-  port->processor = _processor;
-  fprintf(stderr,"Processor: %s\n",_processor);
-}
-
 /** Gets the string argument to this option.  If the option is '--opt'
     then for input of '--optxyz' or '--opt xyz' returns xyz.
 */
@@ -966,13 +989,12 @@ parseCmdLine (int argc, char **argv)
              break;
 
            case 'm':
-             /* Used to select the port */
-             _setPort (argv[i] + 2);
+             /* Used to select the port. But this has already been done. */
              break;
 
            case 'p':
-             /* Used to select the processor in port */
-             _setProcessor (getStringArg("-p", argv, &i, argc));
+             /* Used to select the processor in port. But this has
+              * already been done. */
              break;
 
            case 'c':
@@ -1088,7 +1110,7 @@ parseCmdLine (int argc, char **argv)
   /* if debug option is set the open the cdbFile */
   if (options.debug && srcFileName)
     {
-      sprintf (scratchFileName, "%s.cdb", srcFileName);
+      sprintf (scratchFileName, "%s.adb", srcFileName); //JCF: Nov 30, 2002
       if ((cdbFile = fopen (scratchFileName, "w")) == NULL)
        werror (E_FILE_OPEN_ERR, scratchFileName);
       else
@@ -1121,8 +1143,8 @@ linkEdit (char **envp)
       exit (1);
     }
 
-  /* now write the options */
-  fprintf (lnkfile, "-mux%c\n", (options.out_fmt ? 's' : 'i'));
+  /* now write the options.  JCF: added option 'y' */
+  fprintf (lnkfile, "-myux%c\n", (options.out_fmt ? 's' : 'i'));
 
   /* if iram size specified */
   if (options.iram_size)
@@ -1141,7 +1163,9 @@ linkEdit (char **envp)
   WRITE_SEG_LOC (CODE_NAME, options.code_loc);
 
   /* data segment start */
-  WRITE_SEG_LOC (DATA_NAME, options.data_loc);
+  if(options.data_loc){ /*JCF: If zero, the linker chooses the best place for data*/
+         WRITE_SEG_LOC (DATA_NAME, options.data_loc);
+  }
 
   /* xdata start */
   WRITE_SEG_LOC (XDATA_NAME, options.xdata_loc);
@@ -1154,6 +1178,11 @@ linkEdit (char **envp)
   /* bit segment start */
   WRITE_SEG_LOC (BIT_NAME, 0);
 
+  /* JCF: stack start */
+  if(options.stack_loc) {
+       WRITE_SEG_LOC ("SSEG", options.stack_loc & 0xff);
+  }
+
   /* add the extra linker options */
   for (i = 0; linkOptions[i]; i++)
     fprintf (lnkfile, "%s\n", linkOptions[i]);
@@ -1345,7 +1374,7 @@ preProcess (char **envp)
 
       /* Have to set cppoutfilename to something, even if just pre-processing. */
       setMainValue ("cppoutfilename", preOutName ? preOutName : "");
-       
+
       if (options.verbose)
        printf ("sdcc: Calling preprocessor...\n");
 
@@ -1542,7 +1571,17 @@ main (int argc, char **argv, char **envp)
     exit (1);
   }
 
+  /* install atexit handler */
+  atexit(rm_tmpfiles);
+
+  /* Before parsing the command line options, do a 
+   * search for the port and processor and initialize
+   * them if they're found. (We can't gurantee that these
+   * will be the first options specified).
+   */
+
   _findPort (argc, argv);
+
 #ifdef JAMIN_DS390
   if (strcmp(port->target, "mcs51") == 0) {
     printf("DS390 jammed in A\n");
@@ -1550,6 +1589,9 @@ main (int argc, char **argv, char **envp)
     ds390_jammed = 1;
   }
 #endif
+
+  _findProcessor (argc, argv);
+
   /* Initalise the port. */
   if (port->init)
     port->init ();
@@ -1596,58 +1638,38 @@ main (int argc, char **argv, char **envp)
 
       yyparse ();
 
-      if (!fatalError)
-       {
-         if (TARGET_IS_PIC) {
-           /* TSD PIC port hack - if the PIC port option is enabled
-              and SDCC is used to generate PIC code, then we will
-              generate .asm files in gpasm's format instead of SDCC's
-              assembler's format
-           */
+      if (fatalError) {
+        // @FIX: Dario Vecchio 03-05-2001
+        if (preOutName) {
+          if (yyin && yyin != stdin)
+            fclose (yyin);
+          unlink (preOutName);
+          Safe_free (preOutName);
+        }
+        // EndFix
+        return 1;
+      }
+
+      if (TARGET_IS_PIC) {
+        /* TSD PIC port hack - if the PIC port option is enabled
+           and SDCC is used to generate PIC code, then we will
+           generate .asm files in gpasm's format instead of SDCC's
+           assembler's format
+        */
 #if !OPT_DISABLE_PIC
-           picglue ();
+        picglue ();
 #endif
-         } else {
-           glue ();
-         }
-
-         if (fatalError)
-           {
-              // @FIX: Dario Vecchio 03-05-2001
-              if (preOutName)
-                {
-                  if (yyin && yyin != stdin)
-                    fclose (yyin);
-                  unlink (preOutName);
-                  Safe_free (preOutName);
-                }
-              // EndFix
-             return 1;
-           }
-         if (!options.c1mode && !noAssemble)
-           {
-             if (options.verbose)
-               printf ("sdcc: Calling assembler...\n");
-             assemble (envp);
-           }
-       }
-      else
-       {
-          // @FIX: Dario Vecchio 03-05-2001
-          if (preOutName)
-            {
-              if (yyin && yyin != stdin)
-                fclose (yyin);
-              unlink (preOutName);
-              Safe_free (preOutName);
-            }
-          // EndFix
-          #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
-          rm_tmpfiles();
-          #endif
-         return 1;
-       }
+      }
+      else {
+        glue ();
+      }
 
+      if (!options.c1mode && !noAssemble)
+        {
+          if (options.verbose)
+            printf ("sdcc: Calling assembler...\n");
+          assemble (envp);
+        }
     }
 
   closeDumpFiles();
@@ -1655,6 +1677,9 @@ main (int argc, char **argv, char **envp)
   if (cdbFile)
     fclose (cdbFile);
 
+  if (yyin && yyin != stdin)
+    fclose (yyin);
+
   if (preOutName && !options.c1mode)
     {
       unlink (preOutName);
@@ -1673,9 +1698,5 @@ main (int argc, char **argv, char **envp)
        linkEdit (envp);
     }
 
-  if (yyin && yyin != stdin)
-    fclose (yyin);
-
   return 0;
-
 }