daily update
[deliverable/binutils-gdb.git] / sim / common / sim-options.c
index 01d1a7e5b900361f88d46e35aba69b2021c7431b..2c19f43646741c8f5e51cee1f103347d61dfd794 100644 (file)
@@ -1,22 +1,21 @@
 /* Simulator option handling.
-   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 2004, 2007, 2008 Free Software Foundation, Inc.
    Contributed by Cygnus Support.
 
 This file is part of GDB, the GNU debugger.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
-with this program; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "sim-main.h"
 #ifdef HAVE_STRING_H
@@ -109,8 +108,13 @@ typedef enum {
 #endif
   OPTION_HELP,
 #ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir.  */
-  OPTION_H8300,
+  OPTION_H8300H,
+  OPTION_H8300S,
+  OPTION_H8300SX,
 #endif
+  OPTION_LOAD_LMA,
+  OPTION_LOAD_VMA,
+  OPTION_SYSROOT
 } STANDARD_OPTIONS;
 
 static const OPTION standard_options[] =
@@ -149,15 +153,21 @@ static const OPTION standard_options[] =
       standard_option_handler },
 
 #ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir.  */
-  { {"h8300h", no_argument, NULL, OPTION_H8300},
-      'h', NULL, "Indicate the CPU is h8/300h or h8/300s",
+  { {"h8300h", no_argument, NULL, OPTION_H8300H},
+      'h', NULL, "Indicate the CPU is H8/300H",
+      standard_option_handler },
+  { {"h8300s", no_argument, NULL, OPTION_H8300S},
+      'S', NULL, "Indicate the CPU is H8S",
+      standard_option_handler },
+  { {"h8300sx", no_argument, NULL, OPTION_H8300SX},
+      'x', NULL, "Indicate the CPU is H8SX",
       standard_option_handler },
 #endif
 
 #ifdef SIM_HAVE_FLATMEM
   { {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},
-      'm', "MEMORY SIZE", "Specify memory size",
-      standard_option_handler },
+     'm', "<size>[in bytes, Kb (k suffix), Mb (m suffix) or Gb (g suffix)]",
+     "Specify memory size", standard_option_handler },
 #endif
 
   { {"do-command", required_argument, NULL, OPTION_DO_COMMAND},
@@ -182,6 +192,24 @@ static const OPTION standard_options[] =
       '\0', "BFDNAME", "Specify the object-code format for the object files",
       standard_option_handler },
 
+#ifdef SIM_HANDLES_LMA
+  { {"load-lma", no_argument, NULL, OPTION_LOAD_LMA},
+      '\0', NULL,
+#if SIM_HANDLES_LMA
+    "Use VMA or LMA addresses when loading image (default LMA)",
+#else
+    "Use VMA or LMA addresses when loading image (default VMA)",
+#endif
+      standard_option_handler, "load-{lma,vma}" },
+  { {"load-vma", no_argument, NULL, OPTION_LOAD_VMA},
+      '\0', NULL, "", standard_option_handler,  "" },
+#endif
+
+  { {"sysroot", required_argument, NULL, OPTION_SYSROOT},
+      '\0', "SYSROOT",
+    "Root for system calls with absolute file-names and cwd at start",
+      standard_option_handler },
+
   { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
 };
 
@@ -229,18 +257,18 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
 
     case OPTION_ENVIRONMENT:
       if (strcmp (arg, "user") == 0)
-       current_environment = USER_ENVIRONMENT;
+       STATE_ENVIRONMENT (sd) = USER_ENVIRONMENT;
       else if (strcmp (arg, "virtual") == 0)
-       current_environment = VIRTUAL_ENVIRONMENT;
+       STATE_ENVIRONMENT (sd) = VIRTUAL_ENVIRONMENT;
       else if (strcmp (arg, "operating") == 0)
-       current_environment = OPERATING_ENVIRONMENT;
+       STATE_ENVIRONMENT (sd) = OPERATING_ENVIRONMENT;
       else
        {
          sim_io_eprintf (sd, "Invalid environment specification `%s'\n", arg);
          return SIM_RC_FAIL;
        }
       if (WITH_ENVIRONMENT != ALL_ENVIRONMENT
-         && WITH_ENVIRONMENT != current_environment)
+         && WITH_ENVIRONMENT != STATE_ENVIRONMENT (sd))
        {
          char *type;
          switch (WITH_ENVIRONMENT)
@@ -338,15 +366,35 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
       break;
 
 #ifdef SIM_H8300 /* FIXME: Can be moved to h8300 dir.  */
-    case OPTION_H8300:
-      set_h8300h (1);
+    case OPTION_H8300H:
+      set_h8300h (bfd_mach_h8300h);
+      break;
+    case OPTION_H8300S:
+      set_h8300h (bfd_mach_h8300s);
+      break;
+    case OPTION_H8300SX:
+      set_h8300h (bfd_mach_h8300sx);
       break;
 #endif
 
 #ifdef SIM_HAVE_FLATMEM
     case OPTION_MEM_SIZE:
       {
-       unsigned long ul = strtol (arg, NULL, 0);
+       char * endp;
+       unsigned long ul = strtol (arg, &endp, 0);
+
+       switch (* endp)
+         {
+         case 'k': case 'K': size <<= 10; break;
+         case 'm': case 'M': size <<= 20; break;
+         case 'g': case 'G': size <<= 30; break;
+         case ' ': case '\0': case '\t':  break;
+         default:
+           if (ul > 0)
+             sim_io_eprintf (sd, "Ignoring strange character at end of memory size: %c\n", * endp);
+           break;
+         }
+
        /* 16384: some minimal amount */
        if (! isdigit (arg[0]) || ul < 16384)
          {
@@ -394,12 +442,32 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
        break;
       }
 
+    case OPTION_LOAD_LMA:
+      {
+       STATE_LOAD_AT_LMA_P (sd) = 1;
+       break;
+      }
+
+    case OPTION_LOAD_VMA:
+      {
+       STATE_LOAD_AT_LMA_P (sd) = 0;
+       break;
+      }
+
     case OPTION_HELP:
       sim_print_help (sd, is_command);
       if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
        exit (0);
       /* FIXME: 'twould be nice to do something similar if gdb.  */
       break;
+
+    case OPTION_SYSROOT:
+      /* Don't leak memory in the odd event that there's lots of
+        --sysroot=... options.  */
+      if (simulator_sysroot[0] != '\0' && arg[0] != '\0')
+       free (simulator_sysroot);
+      simulator_sysroot = xstrdup (arg);
+      break;
     }
 
   return SIM_RC_OK;
@@ -413,6 +481,9 @@ standard_install (SIM_DESC sd)
   SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
   if (sim_add_option_table (sd, NULL, standard_options) != SIM_RC_OK)
     return SIM_RC_FAIL;
+#ifdef SIM_HANDLES_LMA
+  STATE_LOAD_AT_LMA_P (sd) = SIM_HANDLES_LMA;
+#endif
   return SIM_RC_OK;
 }
 
@@ -469,6 +540,7 @@ sim_parse_args (sd, argv)
   const OPTION *opt;
   OPTION_HANDLER **handlers;
   sim_cpu **opt_cpu;
+  SIM_RC result = SIM_RC_OK;
 
   /* Count the number of arguments.  */
   for (argc = 0; argv[argc] != NULL; ++argc)
@@ -549,7 +621,8 @@ sim_parse_args (sd, argv)
            if (opt->shortopt != 0)
              {
                sim_io_eprintf (sd, "internal error, short cpu specific option");
-               return SIM_RC_FAIL;
+               result = SIM_RC_FAIL;
+               break;
              }
            if (opt->opt.name != NULL)
              {
@@ -587,13 +660,24 @@ sim_parse_args (sd, argv)
          break;
        }
       if (optc == '?')
-       return SIM_RC_FAIL;
+       {
+         result = SIM_RC_FAIL;
+         break;
+       }
 
       if ((*handlers[optc]) (sd, opt_cpu[optc], orig_val[optc], optarg, 0/*!is_command*/) == SIM_RC_FAIL)
-       return SIM_RC_FAIL;
+       {
+         result = SIM_RC_FAIL;
+         break;
+       }
     }
 
-  return SIM_RC_OK;
+  zfree (long_options);
+  zfree (short_options);
+  zfree (handlers);
+  zfree (opt_cpu);
+  zfree (orig_val);
+  return result;
 }
 
 /* Utility of sim_print_help to print a list of option tables.  */
@@ -679,7 +763,7 @@ print_help (SIM_DESC sd, sim_cpu *cpu, const struct option_list *ol, int is_comm
                  {
                    if (o->opt.has_arg == optional_argument)
                      {
-                       sim_io_printf (sd, " [%s]", o->arg);
+                       sim_io_printf (sd, "[=%s]", o->arg);
                        len += 2 + strlen (o->arg) + 1;
                      }
                    else
@@ -712,7 +796,10 @@ print_help (SIM_DESC sd, sim_cpu *cpu, const struct option_list *ol, int is_comm
                end --;
              if (end == chp)
                end = chp + doc_width - 1;
-             sim_io_printf (sd, "%.*s\n%*s", end - chp, chp, indent, "");
+             /* The cast should be ok - its distances between to
+                 points in a string.  */
+             sim_io_printf (sd, "%.*s\n%*s", (int) (end - chp), chp, indent,
+                            "");
              chp = end;
              while (isspace (*chp) && *chp != '\0')
                chp++;
@@ -838,7 +925,7 @@ sim_args_command (SIM_DESC sd, char *cmd)
 {
   /* something to do? */
   if (cmd == NULL)
-    return SIM_RC_OK; /* FIXME - perhaphs help would be better */
+    return SIM_RC_OK; /* FIXME - perhaps help would be better */
   
   if (cmd [0] == '-')
     {
@@ -856,7 +943,7 @@ sim_args_command (SIM_DESC sd, char *cmd)
       sim_cpu *cpu;
 
       if (argv [0] == NULL)
-       return SIM_RC_OK; /* FIXME - perhaphs help would be better */
+       return SIM_RC_OK; /* FIXME - perhaps help would be better */
 
       /* First check for a cpu selector.  */
       {
This page took 0.027058 seconds and 4 git commands to generate.