aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>1997-12-04 02:04:42 +0000
committerDoug Evans <dje@google.com>1997-12-04 02:04:42 +0000
commit22469a10e8be365c0c85af41370cf5aa8e33bb51 (patch)
treedf706e34cfa28efe48b78f89020e079b0f68ac2f
parentb65b4d8b06ade312280a913279d5501180c70992 (diff)
downloadgdb-22469a10e8be365c0c85af41370cf5aa8e33bb51.zip
gdb-22469a10e8be365c0c85af41370cf5aa8e33bb51.tar.gz
gdb-22469a10e8be365c0c85af41370cf5aa8e33bb51.tar.bz2
* Make-common.in (SIM_ENVIRONMENT): New variable.
(CONFIG_CFLAGS): Add it. * aclocal.m4 (SIM_AC_OPTION_ENVIRONMENT): Handle --enable-sim-environment option. * configure: Regenerated. * sim-config.h (environment support): Rewrite. * sim-config.c (current_environment): Define as enum, unconditionally. (current_alignment): Define unconditionally. (config_environment_to_a): Update. (config_alignment_to_a): Fix type of argument. Define unconditionally. (sim_config): Handle environment and alignment determination unconditionally. Delete sanity checks of current_environment, unnecessary. (print_sim_config): Update. * sim-options.c (STANDARD_OPTIONS enum): Add OPTION_ENVIRONMENT. (standard_options): Add --environment. (standard_option_handler): Likewise.
-rw-r--r--sim/common/ChangeLog38
-rw-r--r--sim/common/Make-common.in22
-rw-r--r--sim/common/sim-config.c73
-rw-r--r--sim/common/sim-config.h45
-rw-r--r--sim/common/sim-options.c154
5 files changed, 222 insertions, 110 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index de941d4..90ce9da 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,41 @@
+Wed Dec 3 17:56:02 1997 Doug Evans <devans@canuck.cygnus.com>
+
+ * Make-common.in (SIM_ENVIRONMENT): New variable.
+ (CONFIG_CFLAGS): Add it.
+ * aclocal.m4 (SIM_AC_OPTION_ENVIRONMENT): Handle
+ --enable-sim-environment option.
+ * configure: Regenerated.
+ * sim-config.h (environment support): Rewrite.
+ * sim-config.c (current_environment): Define as enum, unconditionally.
+ (current_alignment): Define unconditionally.
+ (config_environment_to_a): Update.
+ (config_alignment_to_a): Fix type of argument. Define unconditionally.
+ (sim_config): Handle environment and alignment determination
+ unconditionally. Delete sanity checks of current_environment,
+ unnecessary.
+ (print_sim_config): Update.
+ * sim-options.c (STANDARD_OPTIONS enum): Add OPTION_ENVIRONMENT.
+ (standard_options): Add --environment.
+ (standard_option_handler): Likewise.
+
+Fri Nov 28 12:21:25 1997 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * sim-alu.h: Add notes on carry vs borrow for subtraction.
+ (ALU{,8,16,32,64}ADD): Redefine ADD macro as add overflowing.
+ (ALU{,8,16,32,64}ADDC): Define - add carrying.
+ (ALU{,8,16,32,64}SUB): Redefine SUB macro as subtract overflowing.
+ (ALU{,8,16,32,64}SUBB): Define - subtract borrowing.
+ (ALU{,8,16,32,64}SUBC): Define - tract carrying.
+ (ALU{,8,16,32,64}ADD_CA, ALU{,8,16,32,64}ADDC_C): Replace single
+ argument ADD_CA macro with two argument ADDC_C - add carrying with
+ carry in.
+ (ALU{,8,16,32,64}SUB_CA, ALU{,8,16,32,64}SUBC_X): Replace single
+ argument SUB_CA macro with two argument SUBC_X - subtract
+ carrying, extended.
+ (ALU{,8,16,32,64}SUBB_B): Define - subtract borrowing with
+ borrow-in.
+ (ALU{,8,16,32,64}NEGC, ALU{,8,16,32,64}NEGB): Define.
+
Sun Nov 30 17:40:57 1997 Michael Meissner <meissner@cygnus.com>
* sim-io.c (sim_io_{syscalls,getstring}): Delete. No longer used.
diff --git a/sim/common/Make-common.in b/sim/common/Make-common.in
index c359bac..fb1cf8f 100644
--- a/sim/common/Make-common.in
+++ b/sim/common/Make-common.in
@@ -77,6 +77,7 @@ SIM_ALIGNMENT = @sim_alignment@
SIM_BITSIZE = @sim_bitsize@
SIM_DEFAULT_MODEL = @sim_default_model@
SIM_ENDIAN = @sim_endian@
+SIM_ENVIRONMENT = @sim_environment@
SIM_FLOAT = @sim_float@
SIM_HARDWARE = @sim_hardware@
SIM_HOSTENDIAN = @sim_hostendian@
@@ -168,6 +169,7 @@ CONFIG_CFLAGS = @DEFS@ \
$(SIM_ALIGNMENT) \
$(SIM_BITSIZE) \
$(SIM_ENDIAN) \
+ $(SIM_ENVIRONMENT) \
$(SIM_FLOAT) \
$(SIM_HARDWARE) \
$(SIM_HOSTENDIAN) \
@@ -202,7 +204,7 @@ EXTRA_LIBS = $(BFD_LIB) $(OPCODES_LIB) $(LIBIBERTY_LIB) \
LIB_OBJS = callback.o syscall.o targ-map.o $(SIM_OBJS)
-all: $(SIM_EXTRA_ALL) libsim.a run
+all: $(SIM_EXTRA_ALL) libsim.a run .gdbinit
libsim.a: $(LIB_OBJS)
rm -f libsim.a
@@ -214,7 +216,7 @@ run: $(SIM_RUN_OBJS) libsim.a $(LIBDEPS)
$(SIM_RUN_OBJS) libsim.a $(EXTRA_LIBS)
run.o: $(srccom)/run.c config.h tconfig.h \
- $(srcroot)/include/callback.h
+ $(srcroot)/include/remote-sim.h $(srcroot)/include/callback.h
$(CC) -c $(srccom)/run.c $(ALL_CFLAGS)
# FIXME: Ideally, callback.o and friends live in a library outside of
@@ -321,10 +323,12 @@ sim-fpu.o: $(srccom)/sim-fpu.c $(sim-fpu_h) \
$(CC) -c $(srccom)/sim-fpu.c $(ALL_CFLAGS)
sim-hload.o: $(srccom)/sim-hload.c $(sim-assert_h) \
+ $(srcroot)/include/remote-sim.h \
$(SIM_EXTRA_DEPS)
$(CC) -c $(srccom)/sim-hload.c $(ALL_CFLAGS)
-sim-hrw.o: $(srccom)/sim-hrw.c $(sim-assert_h) \
+sim-hrw.o: $(srccom)/sim-hrw.c $(sim-assert_h) $(sim_core_h) \
+ $(srcroot)/include/remote-sim.h \
$(SIM_EXTRA_DEPS)
$(CC) -c $(srccom)/sim-hrw.c $(ALL_CFLAGS)
@@ -334,7 +338,8 @@ sim-inline.c: $(srccom)/sim-inline.c
cat $(srccom)/$@ >> tmp-$@
$(srcdir)/../../move-if-change tmp-$@ $@
-sim-io.o: $(srccom)/sim-io.c $(sim_main_headers) $(sim-io_h)
+sim-io.o: $(srccom)/sim-io.c $(sim_main_headers) $(sim-io_h) \
+ $(srcroot)/include/remote-sim.h
$(CC) -c $(srccom)/sim-io.c $(ALL_CFLAGS)
sim-memopt.o: $(srccom)/sim-memopt.c $(sim_main_headers) \
@@ -349,10 +354,12 @@ sim-options.o: $(srccom)/sim-options.c $(sim_main_headers) \
$(sim-options_h) $(sim-io_h)
$(CC) -c $(srccom)/sim-options.c $(ALL_CFLAGS)
-sim-reason.o: $(srccom)/sim-reason.c $(sim_main_headers)
+sim-reason.o: $(srccom)/sim-reason.c $(sim_main_headers) \
+ $(srcroot)/include/remote-sim.h
$(CC) -c $(srccom)/sim-reason.c $(ALL_CFLAGS)
-sim-resume.o: $(srccom)/sim-resume.c $(sim_main_headers)
+sim-resume.o: $(srccom)/sim-resume.c $(sim_main_headers) \
+ $(srcroot)/include/remote-sim.h
$(CC) -c $(srccom)/sim-resume.c $(ALL_CFLAGS)
sim-run.o: $(srccom)/sim-run.c $(sim_main_headers)
@@ -390,7 +397,8 @@ sim-break.o: $(srccom)/sim-break.c $(sim_main_headers) \
$(CC) -c $(srccom)/sim-break.c $(ALL_CFLAGS)
nrun.o: $(srccom)/nrun.c config.h tconfig.h \
- $(srcroot)/include/callback.h $(sim_main_headers)
+ $(srcroot)/include/remote-sim.h $(srcroot)/include/callback.h \
+ $(sim_main_headers)
$(CC) -c $(srccom)/nrun.c $(ALL_CFLAGS)
# CGEN support.
diff --git a/sim/common/sim-config.c b/sim/common/sim-config.c
index 14236f3..b7913e4 100644
--- a/sim/common/sim-config.c
+++ b/sim/common/sim-config.c
@@ -28,13 +28,14 @@ int current_host_byte_order;
int current_target_byte_order;
int current_stdio;
-#if defined (WITH_ENVIRONMENT)
-int current_environment;
-#endif
+/* The currently selected environment.
+ This isn't used unless the choice is runtime selectable.
+ The proper way to determine the currently selected environment
+ is with the CURRENT_ENVIRONMENT macro.
+ This is set to ALL_ENVIRONMENT to indicate none has been selected yet. */
+enum sim_environment current_environment = ALL_ENVIRONMENT;
-#if defined (WITH_ALIGNMENT)
enum sim_alignments current_alignment;
-#endif
#if defined (WITH_FLOATING_POINT)
int current_floating_point;
@@ -76,28 +77,26 @@ config_stdio_to_a (int stdio)
}
-#if defined (WITH_ENVIRONMENT)
static const char *
-config_environment_to_a (int environment)
+config_environment_to_a (enum sim_environment environment)
{
switch (environment)
{
+ case ALL_ENVIRONMENT:
+ return "ALL_ENVIRONMENT";
case USER_ENVIRONMENT:
return "USER_ENVIRONMENT";
case VIRTUAL_ENVIRONMENT:
return "VIRTUAL_ENVIRONMENT";
case OPERATING_ENVIRONMENT:
return "OPERATING_ENVIRONMENT";
- case 0:
- return "0";
}
return "UNKNOWN";
}
-#endif
static const char *
-config_alignment_to_a (int alignment)
+config_alignment_to_a (enum sim_alignments alignment)
{
switch (alignment)
{
@@ -227,11 +226,9 @@ sim_config (SIM_DESC sd)
}
-#if defined (WITH_ENVIRONMENT)
-
/* set the environment */
#if (WITH_DEVICES)
- if (current_environment == 0)
+ if (current_environment == ALL_ENVIRONMENT)
{
const char *env =
tree_find_string_property(root, "/openprom/options/env");
@@ -244,30 +241,13 @@ sim_config (SIM_DESC sd)
: (strcmp(env, "operating") == 0
|| strcmp(env, "oea") == 0)
? OPERATING_ENVIRONMENT
- : 0);
- }
-#endif
- if (current_environment == 0)
- current_environment = WITH_ENVIRONMENT;
-
- /* verify the environment */
- if (CURRENT_ENVIRONMENT == 0)
- {
- sim_io_eprintf (sd, "Target environment unspecified\n");
- return SIM_RC_FAIL;
- }
- if (CURRENT_ENVIRONMENT != current_environment)
- {
- sim_io_eprintf (sd, "Target (%s) and configured (%s) environment in conflict\n",
- config_environment_to_a (CURRENT_ENVIRONMENT),
- config_environment_to_a (current_environment));
- return SIM_RC_FAIL;
+ : ALL_ENVIRONMENT);
}
#endif
+ if (current_environment == ALL_ENVIRONMENT)
+ current_environment = DEFAULT_ENVIRONMENT;
-#if defined (WITH_ALIGNMENT)
-
/* set the alignment */
#if defined (WITH_DEVICES)
if (current_alignment == 0)
@@ -278,6 +258,8 @@ sim_config (SIM_DESC sd)
#endif
if (current_alignment == 0)
current_alignment = WITH_ALIGNMENT;
+ if (current_alignment == 0)
+ current_alignment = WITH_DEFAULT_ALIGNMENT;
/* verify the alignment */
if (CURRENT_ALIGNMENT == 0)
@@ -292,10 +274,8 @@ sim_config (SIM_DESC sd)
config_alignment_to_a (current_alignment));
return SIM_RC_FAIL;
}
-#endif
-
-#if defined (WITH_FLOAING_POINT)
+#if defined (WITH_FLOATING_POINT)
/* set the floating point */
if (current_floating_point == 0)
@@ -348,18 +328,19 @@ print_sim_config (SIM_DESC sd)
sim_io_printf (sd, "WITH_TARGET_WORD_MSB = %d\n",
WITH_TARGET_WORD_MSB);
-#if defined (WITH_XOR_ENDIAN)
- sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN);
-#endif
-
-#if defined (WITH_ENVIRONMENT)
sim_io_printf (sd, "WITH_ENVIRONMENT = %s\n",
config_environment_to_a (WITH_ENVIRONMENT));
-#endif
-#if defined (WITH_ALIGNMENT)
sim_io_printf (sd, "WITH_ALIGNMENT = %s\n",
config_alignment_to_a (WITH_ALIGNMENT));
+
+#if defined (WITH_DEFAULT_ALIGNMENT)
+ sim_io_printf (sd, "WITH_DEFAULT_ALIGNMENT = %s\n",
+ config_alignment_to_a (WITH_DEFAULT_ALIGNMENT));
+#endif
+
+#if defined (WITH_XOR_ENDIAN)
+ sim_io_printf (sd, "WITH_XOR_ENDIAN = %d\n", WITH_XOR_ENDIAN);
#endif
#if defined (WITH_FLOATING_POINT)
@@ -375,4 +356,8 @@ print_sim_config (SIM_DESC sd)
sim_io_printf (sd, "WITH_RESERVED_BITS = %d\n", WITH_RESERVED_BITS);
#endif
+#if defined (WITH_PROFILE)
+ sim_io_printf (sd, "WITH_PROFILE = %d\n", WITH_PROFILE);
+#endif
+
}
diff --git a/sim/common/sim-config.h b/sim/common/sim-config.h
index cea3101..f09eb98 100644
--- a/sim/common/sim-config.h
+++ b/sim/common/sim-config.h
@@ -319,24 +319,45 @@ extern int current_target_byte_order;
expect to see (VEA includes things like coherency and the time
base) while OEA is what an operating system expects to see. By
setting these to specific values, the build process is able to
- eliminate non relevent environment code
+ eliminate non relevent environment code.
CURRENT_ENVIRONMENT specifies which of vea or oea is required for
- the current runtime. */
+ the current runtime.
+
+ ALL_ENVIRONMENT is used during configuration as a value for
+ WITH_ENVIRONMENT to indicate the choice is runtime selectable.
+ The default is then USER_ENVIRONMENT [since allowing the user to choose
+ the default at configure time seems like featuritis and since people using
+ OPERATING_ENVIRONMENT have more to worry about than selecting the default].
+ ALL_ENVIRONMENT is also used to set `current_environment' to the
+ "unknown" state. */
+
+enum sim_environment {
+ ALL_ENVIRONMENT,
+ USER_ENVIRONMENT,
+ VIRTUAL_ENVIRONMENT,
+ OPERATING_ENVIRONMENT
+};
-#if defined (WITH_ENVIRONMENT)
+/* If the simulator specified SIM_AC_OPTION_ENVIRONMENT, indicate so. */
+#ifdef WITH_ENVIRONMENT
+#define SIM_HAVE_ENVIRONMENT
+#endif
-#define USER_ENVIRONMENT 1
-#define VIRTUAL_ENVIRONMENT 2
-#define OPERATING_ENVIRONMENT 3
+/* If the simulator doesn't specify SIM_AC_OPTION_ENVIRONMENT in its
+ configure.in, the only supported environment is the user environment. */
+#ifndef WITH_ENVIRONMENT
+#define WITH_ENVIRONMENT USER_ENVIRONMENT
+#endif
-extern int current_environment;
-#define CURRENT_ENVIRONMENT (WITH_ENVIRONMENT \
+#define DEFAULT_ENVIRONMENT (WITH_ENVIRONMENT != ALL_ENVIRONMENT \
? WITH_ENVIRONMENT \
- : current_environment)
-
-#endif
+ : USER_ENVIRONMENT)
+extern enum sim_environment current_environment;
+#define CURRENT_ENVIRONMENT (WITH_ENVIRONMENT != ALL_ENVIRONMENT \
+ ? WITH_ENVIRONMENT \
+ : current_environment)
/* Callback & Modulo Memory.
@@ -394,7 +415,7 @@ enum sim_alignments {
extern enum sim_alignments current_alignment;
#if !defined (WITH_ALIGNMENT)
-#define WITH_ALIGNMENT NONSTRICT_ALIGNMENT
+#define WITH_ALIGNMENT 0
#endif
#if !defined (WITH_DEFAULT_ALIGNMENT)
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index 6d4f3da..9f86d7e 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -31,7 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
#include <ctype.h>
#include "libiberty.h"
-#include "../libiberty/alloca-conf.h"
#include "sim-options.h"
#include "sim-io.h"
#include "sim-assert.h"
@@ -83,31 +82,55 @@ static DECLARE_OPTION_HANDLER (standard_option_handler);
If you decide to conditionally compile them out as well, delete this
comment and add a comment saying that that is the rule. */
-#define OPTION_DEBUG_INSN (OPTION_START + 0)
-#define OPTION_DEBUG_FILE (OPTION_START + 1)
-#define OPTION_DO_COMMAND (OPTION_START + 2)
-#define OPTION_ARCHITECTURE (OPTION_START + 3)
-#define OPTION_TARGET (OPTION_START + 4)
-#define OPTION_ARCHITECTURE_INFO (OPTION_START + 5)
-#define OPTION_ALIGNMENT (OPTION_START + 6)
+typedef enum {
+ OPTION_DEBUG_INSN = OPTION_START,
+ OPTION_DEBUG_FILE,
+ OPTION_DO_COMMAND,
+ OPTION_ARCHITECTURE,
+ OPTION_TARGET,
+ OPTION_ARCHITECTURE_INFO,
+ OPTION_ENVIRONMENT,
+ OPTION_ALIGNMENT,
+ OPTION_VERBOSE,
+#if defined (SIM_HAVE_BIENDIAN)
+ OPTION_ENDIAN,
+#endif
+ OPTION_DEBUG,
+#ifdef SIM_HAVE_FLATMEM
+ OPTION_MEM_SIZE,
+#endif
+ OPTION_HELP,
+#ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir. */
+ OPTION_H8300,
+#endif
+} STANDARD_OPTIONS;
static const OPTION standard_options[] =
{
- { {"verbose", no_argument, NULL, 'v'},
+ { {"verbose", no_argument, NULL, OPTION_VERBOSE},
'v', NULL, "Verbose output",
standard_option_handler },
#if defined (SIM_HAVE_BIENDIAN) /* ??? && WITH_TARGET_BYTE_ORDER == 0 */
- { {"endian", required_argument, NULL, 'E'},
+ { {"endian", required_argument, NULL, OPTION_ENDIAN},
'E', "big|little", "Set endianness",
standard_option_handler },
#endif
+#ifdef SIM_HAVE_ENVIRONMENT
+ /* This option isn't supported unless all choices are supported in keeping
+ with the goal of not printing in --help output things the simulator can't
+ do [as opposed to things that just haven't been configured in]. */
+ { {"environment", required_argument, NULL, OPTION_ENVIRONMENT},
+ '\0', "user|virtual|operating", "Set running environment",
+ standard_option_handler },
+#endif
+
{ {"alignment", required_argument, NULL, OPTION_ALIGNMENT},
'\0', "strict|nonstrict|forced", "Set memory access alignment",
standard_option_handler },
- { {"debug", no_argument, NULL, 'D'},
+ { {"debug", no_argument, NULL, OPTION_DEBUG},
'D', NULL, "Print debugging messages",
standard_option_handler },
{ {"debug-insn", no_argument, NULL, OPTION_DEBUG_INSN},
@@ -118,13 +141,13 @@ static const OPTION standard_options[] =
standard_option_handler },
#ifdef SIM_H8300 /* FIXME: Should be movable to h8300 dir. */
- { {"h8300h", no_argument, NULL, 'h'},
+ { {"h8300h", no_argument, NULL, OPTION_H8300},
'h', NULL, "Indicate the CPU is h8/300h or h8/300s",
standard_option_handler },
#endif
#ifdef SIM_HAVE_FLATMEM
- { {"mem-size", required_argument, NULL, 'm'},
+ { {"mem-size", required_argument, NULL, OPTION_MEM_SIZE},
'm', "MEMORY SIZE", "Specify memory size",
standard_option_handler },
#endif
@@ -133,7 +156,7 @@ static const OPTION standard_options[] =
'\0', "COMMAND", ""/*undocumented*/,
standard_option_handler },
- { {"help", no_argument, NULL, 'H'},
+ { {"help", no_argument, NULL, OPTION_HELP},
'H', NULL, "Print help information",
standard_option_handler },
@@ -163,14 +186,14 @@ standard_option_handler (sd, opt, arg, is_command)
{
int i,n;
- switch (opt)
+ switch ((STANDARD_OPTIONS) opt)
{
- case 'v' :
+ case OPTION_VERBOSE:
STATE_VERBOSE_P (sd) = 1;
break;
#ifdef SIM_HAVE_BIENDIAN
- case 'E' :
+ case OPTION_ENDIAN:
if (strcmp (arg, "big") == 0)
{
if (WITH_TARGET_BYTE_ORDER == LITTLE_ENDIAN)
@@ -199,6 +222,34 @@ standard_option_handler (sd, opt, arg, is_command)
break;
#endif
+ case OPTION_ENVIRONMENT:
+ if (strcmp (arg, "user") == 0)
+ current_environment = USER_ENVIRONMENT;
+ else if (strcmp (arg, "virtual") == 0)
+ current_environment = VIRTUAL_ENVIRONMENT;
+ else if (strcmp (arg, "operating") == 0)
+ current_environment = 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)
+ {
+ char *type;
+ switch (WITH_ENVIRONMENT)
+ {
+ case USER_ENVIRONMENT: type = "user"; break;
+ case VIRTUAL_ENVIRONMENT: type = "virtual"; break;
+ case OPERATING_ENVIRONMENT: type = "operating"; break;
+ }
+ sim_io_eprintf (sd, "Simulator compiled for the %s environment only.\n",
+ type);
+ return SIM_RC_FAIL;
+ }
+ break;
+
case OPTION_ALIGNMENT:
if (strcmp (arg, "strict") == 0)
{
@@ -235,7 +286,7 @@ standard_option_handler (sd, opt, arg, is_command)
sim_io_eprintf (sd, "Simulator compiled for strict alignment only.\n");
break;
case NONSTRICT_ALIGNMENT:
- sim_io_eprintf (sd, "Simulator compiled for nonsitrct alignment only.\n");
+ sim_io_eprintf (sd, "Simulator compiled for nonstrict alignment only.\n");
break;
case FORCED_ALIGNMENT:
sim_io_eprintf (sd, "Simulator compiled for forced alignment only.\n");
@@ -243,7 +294,7 @@ standard_option_handler (sd, opt, arg, is_command)
}
return SIM_RC_FAIL;
- case 'D' :
+ case OPTION_DEBUG:
if (! WITH_DEBUG)
sim_io_eprintf (sd, "Debugging not compiled in, `-D' ignored\n");
else
@@ -282,13 +333,13 @@ standard_option_handler (sd, opt, arg, is_command)
break;
#ifdef SIM_H8300 /* FIXME: Can be moved to h8300 dir. */
- case 'h' :
+ case OPTION_H8300:
set_h8300h (1);
break;
#endif
#ifdef SIM_HAVE_FLATMEM
- case 'm':
+ case OPTION_MEM_SIZE:
{
unsigned long ul = strtol (arg, NULL, 0);
/* 16384: some minimal amount */
@@ -338,7 +389,7 @@ standard_option_handler (sd, opt, arg, is_command)
break;
}
- case 'H':
+ case OPTION_HELP:
sim_print_help (sd, is_command);
if (STATE_OPEN_KIND (sd) == SIM_OPEN_STANDALONE)
exit (0);
@@ -407,7 +458,7 @@ sim_parse_args (sd, argv)
/* The `val' option struct entry is dynamically assigned for options that
only come in the long form. ORIG_VAL is used to get the original value
back. */
- unsigned char *orig_val;
+ int *orig_val;
struct option *lp, *long_options;
const struct option_list *ol;
const OPTION *opt;
@@ -420,28 +471,26 @@ sim_parse_args (sd, argv)
/* Count the number of options. */
num_opts = 0;
for (ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
- for (opt = ol->options; opt->opt.name != NULL; ++opt)
+ for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
++num_opts;
/* Initialize duplicate argument checker. */
(void) dup_arg_p (NULL);
/* Build the option table for getopt. */
- long_options = (struct option *) alloca ((num_opts + 1) * sizeof (struct option));
+ long_options = NZALLOC (struct option, num_opts + 1);
lp = long_options;
- short_options = (char *) alloca (num_opts * 3 + 1);
+ short_options = NZALLOC (char, num_opts * 3 + 1);
p = short_options;
-#if 0 /* ??? necessary anymore? */
- /* Set '+' as first char so argument permutation isn't done. This is done
- to workaround a problem with invoking getopt_long in run.c.: optind gets
- decremented when the program name is reached. */
+ handlers = NZALLOC (OPTION_HANDLER *, OPTION_START + num_opts);
+ orig_val = NZALLOC (int, OPTION_START + num_opts);
+ /* Set '+' as first char so argument permutation isn't done. This
+ is done to stop getopt_long returning options that appear after
+ the target program. Such options should be passed unchanged into
+ the program image. */
*p++ = '+';
-#endif
- handlers = (OPTION_HANDLER **) alloca (256 * sizeof (OPTION_HANDLER *));
- memset (handlers, 0, 256 * sizeof (OPTION_HANDLER *));
- orig_val = (unsigned char *) alloca (256);
for (i = OPTION_START, ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
- for (opt = ol->options; opt->opt.name != NULL; ++opt)
+ for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
{
if (dup_arg_p (opt->opt.name))
continue;
@@ -452,15 +501,21 @@ sim_parse_args (sd, argv)
*p++ = ':';
else if (opt->opt.has_arg == optional_argument)
{ *p++ = ':'; *p++ = ':'; }
+ handlers[(unsigned char) opt->shortopt] = opt->handler;
+ if (opt->opt.val != 0)
+ orig_val[(unsigned char) opt->shortopt] = opt->opt.val;
+ else
+ orig_val[(unsigned char) opt->shortopt] = opt->shortopt;
+ }
+ if (opt->opt.name != NULL)
+ {
+ *lp = opt->opt;
+ /* Dynamically assign `val' numbers for long options. */
+ lp->val = i++;
+ handlers[lp->val] = opt->handler;
+ orig_val[lp->val] = opt->opt.val;
+ ++lp;
}
- *lp = opt->opt;
- /* Dynamically assign `val' numbers for long options that don't have
- a short option equivalent. */
- if (OPTION_LONG_ONLY_P (opt->opt.val))
- lp->val = i++;
- handlers[(unsigned char) lp->val] = opt->handler;
- orig_val[(unsigned char) lp->val] = opt->opt.val;
- ++lp;
}
*p = 0;
lp->name = NULL;
@@ -511,7 +566,7 @@ sim_print_help (sd, is_command)
sim_io_printf (sd, "Commands:\n");
for (ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
- for (opt = ol->options; opt->opt.name != NULL; ++opt)
+ for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
{
const int indent = 30;
int comma, len;
@@ -531,6 +586,7 @@ sim_print_help (sd, is_command)
comma = 0;
len = 2;
+ /* list any short options (aliases) for the current OPT */
if (!is_command)
{
o = opt;
@@ -557,9 +613,10 @@ sim_print_help (sd, is_command)
}
++o;
}
- while (o->opt.name != NULL && o->doc == NULL);
+ while (OPTION_VALID_P (o) && o->doc == NULL);
}
+ /* list any long options (aliases) for the current OPT */
o = opt;
do
{
@@ -594,7 +651,7 @@ sim_print_help (sd, is_command)
}
++o;
}
- while (o->opt.name != NULL && o->doc == NULL);
+ while (OPTION_VALID_P (o) && o->doc == NULL);
if (len >= indent)
{
@@ -603,6 +660,7 @@ sim_print_help (sd, is_command)
else
sim_io_printf (sd, "%*s", indent - len, "");
+ /* print the description, word wrap long lines */
{
const char *chp = opt->doc;
unsigned doc_width = 80 - indent;
@@ -666,10 +724,12 @@ sim_args_command (sd, cmd)
int matching_argi = -1;
if (argv [0] != NULL)
for (ol = STATE_OPTIONS (sd); ol != NULL; ol = ol->next)
- for (opt = ol->options; opt->opt.name != NULL; ++opt)
+ for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
{
int argi = 0;
const char *name = opt->opt.name;
+ if (name == NULL)
+ continue;
while (strncmp (name, argv [argi], strlen (argv [argi])) == 0)
{
name = &name [strlen (argv[argi])];