aboutsummaryrefslogtreecommitdiff
path: root/sim/common/sim-config.c
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-08-25 23:14:25 +0000
committerAndrew Cagney <cagney@redhat.com>1997-08-25 23:14:25 +0000
commit247fccdeb54a09a14287b2e829511803ad9d7cc1 (patch)
treec992df7132ca0c315cbcfd5ad81bbc4f16675936 /sim/common/sim-config.c
parent04f295b64859a6c6b01739fc4dd7fddce42db8d9 (diff)
downloadgdb-247fccdeb54a09a14287b2e829511803ad9d7cc1.zip
gdb-247fccdeb54a09a14287b2e829511803ad9d7cc1.tar.gz
gdb-247fccdeb54a09a14287b2e829511803ad9d7cc1.tar.bz2
Add ABFD argument to sim_open call. Pass through to sim_config so
that image properties such as endianness can be checked. More strongly document the expected behavour of each of the sim_* interfaces. Add default endian argument to simulator config macro SIM_AC_OPTION_ENDIAN. Use in sim_config.
Diffstat (limited to 'sim/common/sim-config.c')
-rw-r--r--sim/common/sim-config.c187
1 files changed, 138 insertions, 49 deletions
diff --git a/sim/common/sim-config.c b/sim/common/sim-config.c
index c6ee907..5f2efc3 100644
--- a/sim/common/sim-config.c
+++ b/sim/common/sim-config.c
@@ -19,7 +19,8 @@
*/
-#include "sim-state.h"
+#include "sim-main.h"
+#include "bfd.h"
int current_host_byte_order;
@@ -31,7 +32,7 @@ int current_environment;
#endif
#if defined (WITH_ALIGNMENT)
-int current_alignment;
+enum sim_alignments current_alignment;
#endif
#if defined (WITH_FLOATING_POINT)
@@ -94,22 +95,22 @@ config_environment_to_a (int environment)
#endif
-#if defined (WITH_ALIGNMENT)
static const char *
config_alignment_to_a (int alignment)
{
switch (alignment)
{
+ case MIXED_ALIGNMENT:
+ return "MIXED_ALIGNMENT";
case NONSTRICT_ALIGNMENT:
return "NONSTRICT_ALIGNMENT";
case STRICT_ALIGNMENT:
return "STRICT_ALIGNMENT";
- case 0:
- return "0";
+ case FORCED_ALIGNMENT:
+ return "FORCED_ALIGNMENT";
}
return "UNKNOWN";
}
-#endif
#if defined (WITH_FLOATING_POINT)
@@ -130,10 +131,48 @@ config_floating_point_to_a (int floating_point)
#endif
-void
+SIM_RC
sim_config (SIM_DESC sd,
- int prefered_target_byte_order)
+ struct _bfd *abfd)
{
+ int prefered_target_byte_order;
+
+ /* clone the bfd struct (or open prog_name directly) */
+ {
+ const char *prog_name;
+ if (STATE_PROG_ARGV (sd) == NULL)
+ {
+ if (abfd != NULL)
+ prog_name = bfd_get_filename (abfd);
+ else
+ prog_name = NULL;
+ }
+ else
+ prog_name = *STATE_PROG_ARGV (sd);
+ if (prog_name != NULL)
+ {
+ abfd = bfd_openr (prog_name, 0);
+ if (abfd == NULL)
+ {
+ sim_io_eprintf (sd, "%s: can't open \"%s\": %s\n",
+ STATE_MY_NAME (sd),
+ prog_name,
+ bfd_errmsg (bfd_get_error ()));
+ return SIM_RC_FAIL;
+ }
+ STATE_PROG_BFD (sd) = abfd;
+ }
+ else
+ STATE_PROG_BFD (sd) = NULL;
+ }
+
+ /* extract all relevant information */
+ if (abfd == NULL)
+ prefered_target_byte_order = 0;
+ else
+ prefered_target_byte_order = (bfd_little_endian(abfd)
+ ? LITTLE_ENDIAN
+ : BIG_ENDIAN);
/* set the host byte order */
current_host_byte_order = 1;
@@ -144,16 +183,19 @@ sim_config (SIM_DESC sd,
/* verify the host byte order */
if (CURRENT_HOST_BYTE_ORDER != current_host_byte_order)
- sim_io_error (sd, "host (%s) and configured (%s) byte order in conflict",
- config_byte_order_to_a (current_host_byte_order),
- config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER));
+ {
+ sim_io_eprintf (sd, "host (%s) and configured (%s) byte order in conflict",
+ config_byte_order_to_a (current_host_byte_order),
+ config_byte_order_to_a (CURRENT_HOST_BYTE_ORDER));
+ return SIM_RC_FAIL;
+ }
/* set the target byte order */
#if (WITH_DEVICES)
if (current_target_byte_order == 0)
current_target_byte_order
- = (tree_find_boolean_property(root, "/options/little-endian?")
+ = (tree_find_boolean_property (root, "/options/little-endian?")
? LITTLE_ENDIAN
: BIG_ENDIAN);
#endif
@@ -162,17 +204,22 @@ sim_config (SIM_DESC sd,
current_target_byte_order = prefered_target_byte_order;
if (current_target_byte_order == 0)
current_target_byte_order = WITH_TARGET_BYTE_ORDER;
+ if (current_target_byte_order == 0)
+ current_target_byte_order = WITH_DEFAULT_TARGET_BYTE_ORDER;
/* verify the target byte order */
if (CURRENT_TARGET_BYTE_ORDER == 0)
- sim_io_error (sd, "target byte order unspecified");
+ {
+ sim_io_eprintf (sd, "target byte order unspecified");
+ return SIM_RC_FAIL;
+ }
if (CURRENT_TARGET_BYTE_ORDER != current_target_byte_order)
- sim_io_error (sd, "target (%s) and configured (%s) byte order in conflict",
+ sim_io_eprintf (sd, "target (%s) and configured (%s) byte order in conflict",
config_byte_order_to_a (current_target_byte_order),
config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER));
if (prefered_target_byte_order != 0
&& CURRENT_TARGET_BYTE_ORDER != prefered_target_byte_order)
- sim_io_error (sd, "target (%s) and specified (%s) byte order in conflict",
+ sim_io_eprintf (sd, "target (%s) and specified (%s) byte order in conflict",
config_byte_order_to_a (CURRENT_TARGET_BYTE_ORDER),
config_byte_order_to_a (prefered_target_byte_order));
@@ -185,15 +232,31 @@ sim_config (SIM_DESC sd,
/* verify the stdio */
if (CURRENT_STDIO == 0)
- sim_io_error (sd, "target standard IO unspecified");
+ {
+ sim_io_eprintf (sd, "target standard IO unspecified");
+ return SIM_RC_FAIL;
+ }
if (CURRENT_STDIO != current_stdio)
- sim_io_error (sd, "target (%s) and configured (%s) standard IO in conflict",
- config_stdio_to_a (CURRENT_STDIO),
- config_stdio_to_a (current_stdio));
-
-
+ {
+ sim_io_eprintf (sd, "target (%s) and configured (%s) standard IO in conflict",
+ config_stdio_to_a (CURRENT_STDIO),
+ config_stdio_to_a (current_stdio));
+ return SIM_RC_FAIL;
+ }
+
+
+ /* check the value of MSB */
+ if (WITH_TARGET_WORD_MSB != 0
+ && WITH_TARGET_WORD_MSB != (WITH_TARGET_WORD_BITSIZE - 1))
+ {
+ sim_io_eprintf (sd, "target bitsize (%d) contradicts target most significant bit (%d)",
+ WITH_TARGET_WORD_BITSIZE, WITH_TARGET_WORD_MSB);
+ return SIM_RC_FAIL;
+ }
+
+
#if defined (WITH_ENVIRONMENT)
-
+
/* set the environment */
#if (WITH_DEVICES)
if (current_environment == 0)
@@ -214,19 +277,25 @@ sim_config (SIM_DESC sd,
#endif
if (current_environment == 0)
current_environment = WITH_ENVIRONMENT;
-
+
/* verify the environment */
if (CURRENT_ENVIRONMENT == 0)
- sim_io_error (sd, "target environment unspecified");
+ {
+ sim_io_eprintf (sd, "target environment unspecified");
+ return SIM_RC_FAIL;
+ }
if (CURRENT_ENVIRONMENT != current_environment)
- sim_io_error (sd, "target (%s) and configured (%s) environment in conflict",
- config_environment_to_a (CURRENT_ENVIRONMENT),
- config_environment_to_a (current_environment));
+ {
+ sim_io_eprintf (sd, "target (%s) and configured (%s) environment in conflict",
+ config_environment_to_a (CURRENT_ENVIRONMENT),
+ config_environment_to_a (current_environment));
+ return SIM_RC_FAIL;
+ }
#endif
-
-
+
+
#if defined (WITH_ALIGNMENT)
-
+
/* set the alignment */
#if defined (WITH_DEVICES)
if (current_alignment == 0)
@@ -237,34 +306,45 @@ sim_config (SIM_DESC sd,
#endif
if (current_alignment == 0)
current_alignment = WITH_ALIGNMENT;
-
+
/* verify the alignment */
if (CURRENT_ALIGNMENT == 0)
- sim_io_error (sd, "target alignment unspecified");
+ {
+ sim_io_eprintf (sd, "target alignment unspecified");
+ return SIM_RC_FAIL;
+ }
if (CURRENT_ALIGNMENT != current_alignment)
- sim_io_error (sd, "target (%s) and configured (%s) alignment in conflict",
- config_alignment_to_a (CURRENT_ALIGNMENT),
- config_alignment_to_a (current_alignment));
+ {
+ sim_io_eprintf (sd, "target (%s) and configured (%s) alignment in conflict",
+ config_alignment_to_a (CURRENT_ALIGNMENT),
+ config_alignment_to_a (current_alignment));
+ return SIM_RC_FAIL;
+ }
#endif
-
-
+
+
#if defined (WITH_FLOAING_POINT)
-
+
/* set the floating point */
if (current_floating_point == 0)
current_floating_point = WITH_FLOATING_POINT;
-
+
/* verify the floating point */
if (CURRENT_FLOATING_POINT == 0)
- sim_io_error (sd, "target floating-point unspecified");
+ {
+ sim_io_eprintf (sd, "target floating-point unspecified");
+ return SIM_RC_FAIL;
+ }
if (CURRENT_FLOATING_POINT != current_floating_point)
- sim_io_error (sd, "target (%s) and configured (%s) floating-point in conflict",
- config_alignment_to_a (CURRENT_FLOATING_POINT),
- config_alignment_to_a (current_floating_point));
-
+ {
+ sim_io_eprintf (sd, "target (%s) and configured (%s) floating-point in conflict",
+ config_alignment_to_a (CURRENT_FLOATING_POINT),
+ config_alignment_to_a (current_floating_point));
+ return SIM_RC_FAIL;
+ }
+
#endif
-
-
+ return SIM_RC_OK;
}
@@ -278,15 +358,24 @@ print_sim_config (SIM_DESC sd)
sim_io_printf (sd, "Compiled on %s %s\n", __DATE__, __TIME__);
#endif
- sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n",
+ sim_io_printf (sd, "WITH_TARGET_BYTE_ORDER = %s\n",
config_byte_order_to_a (WITH_TARGET_BYTE_ORDER));
- sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n",
+ sim_io_printf (sd, "WITH_DEFAULT_TARGET_BYTE_ORDER = %s\n",
+ config_byte_order_to_a (WITH_DEFAULT_TARGET_BYTE_ORDER));
+
+ sim_io_printf (sd, "WITH_HOST_BYTE_ORDER = %s\n",
config_byte_order_to_a (WITH_HOST_BYTE_ORDER));
- sim_io_printf (sd, "WITH_STDIO = %s\n",
+ sim_io_printf (sd, "WITH_STDIO = %s\n",
config_stdio_to_a (WITH_STDIO));
+ sim_io_printf (sd, "WITH_TARGET_WORD_BITSIZE = %d\n",
+ WITH_TARGET_WORD_BITSIZE);
+
+ 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