This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA:] Minor sim callback endian cleanup.
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: cagney at gnu dot org
- Cc: hans-peter dot nilsson at axis dot com, gdb-patches at sources dot redhat dot com
- Date: Fri, 28 Jan 2005 04:37:03 +0100
- Subject: Re: [RFA:] Minor sim callback endian cleanup.
> Date: Tue, 11 Jan 2005 10:02:05 -0500
> From: Andrew Cagney <cagney@gnu.org>
> Hans-Peter Nilsson wrote:
> > include/gdb:
> > * callback.h (struct host_callback_struct): New member
> > target_big_endian.
> > (cb_store_target_endian): Prototype.
> >
> > sim/common:
> > * callback.c (default_callback): Initialize target_big_endian.
> > (cb_store_target_endian): Renamed from store, new first parameter
> > host_callback *cb, drop last parameter big_p. Take endianness
> > from cb.
> > (cb_host_to_target_stat): Change to use cb_store_target_endian.
> > Remove variable big_p.
> > * nrun.c (main): Initialize default_callback.target_big_endian.
>
> [draining my backlog, sorry]
Me too!
> Almost. Can you just modify it so that the field's type is bfd_endian
> instead of an int. If this means #including "bfd.h" explicitly, so be
> it (having a common, but not in bfd.h, type system is only a nice-to-have).
I did the explicit include; seems less error-prone than to put
the burden on the includer. The sim/common dependencies already
apparently deliberately miss dependencies on bfd.h; nothing to
do there.
> (Also, feel free to treat as obvious the ripping out any K&Risms you
> stumble across, or fixing of the definition of SIM_ADDR (it should be
> bfd's largest int).
Hopefully later, as different priorities allow. Have to get
everything working first.
> this, and fallout pre-approved,
Test-built all-sim for: arm-elf frv-elf m32r-elf m68hc11-elf
mips-elf mn10300-elf powerpc-elf h8300-elf mcore-elf. No
fallout there. d10v-elf and v850-elf seem broken for other
reasons; sim for d10v-elf seems to miss common=yes in
sim/configure.ac, and sim for v850-elf wants to "cd ../igen"
(but no such ...)
This is what I committed:
include/gdb:
2005-01-28 Hans-Peter Nilsson <hp@axis.com>
* callback.h: Include "bfd.h".
(struct host_callback_struct): New member target_endian.
(cb_store_target_endian): Declare.
sim/common:
2005-01-28 Hans-Peter Nilsson <hp@axis.com>
* callback.c (default_callback): Initialize target_endian.
(cb_store_target_endian): Renamed from store, new first parameter
host_callback *cb, drop last parameter big_p. Take endianness
from cb.
(cb_host_to_target_stat): Change to use cb_store_target_endian.
Remove variable big_p.
* nrun.c (main): Initialize default_callback.target_endian.
Index: include/gdb/callback.h
===================================================================
RCS file: /cvs/src/src/include/gdb/callback.h,v
retrieving revision 1.6
diff -p -c -r1.6 callback.h
*** include/gdb/callback.h 15 Dec 2004 01:24:15 -0000 1.6
--- include/gdb/callback.h 28 Jan 2005 00:45:49 -0000
*************** Foundation, Inc., 59 Temple Place - Suit
*** 56,61 ****
--- 56,63 ----
#include <varargs.h>
#endif
#endif
+ /* Needed for enum bfd_endian. */
+ #include "bfd.h"
/* Mapping of host/target values. */
/* ??? For debugging purposes, one might want to add a string of the
*************** struct host_callback_struct
*** 151,156 ****
--- 153,160 ----
Example: "st_dev,4:st_ino,4:st_mode,4:..." */
const char *stat_map;
+ enum bfd_endian target_endian;
+
/* Marker for those wanting to do sanity checks.
This should remain the last member of this struct to help catch
miscompilation errors. */
*************** int cb_host_to_target_signal PARAMS ((ho
*** 280,285 ****
--- 284,292 ----
Result is size of target stat struct or 0 if error. */
int cb_host_to_target_stat PARAMS ((host_callback *, const struct stat *, PTR));
+ /* Translate a value to target endian. */
+ void cb_store_target_endian PARAMS ((host_callback *, char *, int, long));
+
/* Perform a system call. */
CB_RC cb_syscall PARAMS ((host_callback *, CB_SYSCALL *));
Index: sim/common/callback.c
===================================================================
RCS file: /cvs/src/src/sim/common/callback.c,v
retrieving revision 1.13
diff -p -c -r1.13 callback.c
*** sim/common/callback.c 13 Dec 2004 00:38:38 -0000 1.13
--- sim/common/callback.c 28 Jan 2005 00:45:50 -0000
*************** host_callback default_callback =
*** 626,631 ****
--- 626,634 ----
0, /* signal_map */
0, /* stat_map */
+ /* Defaults expected to be overridden at initialization, where needed. */
+ BFD_ENDIAN_UNKNOWN, /* target_endian */
+
HOST_CALLBACK_MAGIC,
};
*************** cb_target_to_host_open (cb, target_val)
*** 757,773 ****
return host_val;
}
! /* Utility for cb_host_to_target_stat to store values in the target's
stat struct. */
! static void
! store (p, size, val, big_p)
char *p;
int size;
long val; /* ??? must be as big as target word size */
- int big_p;
{
! if (big_p)
{
p += size;
while (size-- > 0)
--- 760,776 ----
return host_val;
}
! /* Utility for e.g. cb_host_to_target_stat to store values in the target's
stat struct. */
! void
! cb_store_target_endian (cb, p, size, val)
! host_callback *cb;
char *p;
int size;
long val; /* ??? must be as big as target word size */
{
! if (cb->target_endian == BFD_ENDIAN_BIG)
{
p += size;
while (size-- > 0)
*************** cb_host_to_target_stat (cb, hs, ts)
*** 801,807 ****
{
const char *m = cb->stat_map;
char *p;
- int big_p = 0;
if (hs == NULL)
ts = NULL;
--- 804,809 ----
*************** cb_host_to_target_stat (cb, hs, ts)
*** 833,839 ****
#undef ST_x
#define ST_x(FLD) \
else if (strncmp (m, #FLD, q - m) == 0) \
! store (p, size, hs->FLD, big_p)
#ifdef HAVE_STRUCT_STAT_ST_DEV
ST_x (st_dev);
--- 835,841 ----
#undef ST_x
#define ST_x(FLD) \
else if (strncmp (m, #FLD, q - m) == 0) \
! cb_store_target_endian (cb, p, size, hs->FLD)
#ifdef HAVE_STRUCT_STAT_ST_DEV
ST_x (st_dev);
*************** cb_host_to_target_stat (cb, hs, ts)
*** 877,883 ****
#undef ST_x
/* FIXME:wip */
else
! store (p, size, 0, big_p); /* unsupported field, store 0 */
}
p += size;
--- 879,886 ----
#undef ST_x
/* FIXME:wip */
else
! /* Unsupported field, store 0. */
! cb_store_target_endian (cb, p, size, 0);
}
p += size;
Index: sim/common/nrun.c
===================================================================
RCS file: /cvs/src/src/sim/common/nrun.c,v
retrieving revision 1.5
diff -p -c -r1.5 nrun.c
*** sim/common/nrun.c 8 Dec 2004 00:40:30 -0000 1.5
--- sim/common/nrun.c 28 Jan 2005 00:26:44 -0000
*************** main (int argc, char **argv)
*** 82,87 ****
--- 82,93 ----
abort ();
}
+ /* We can't set the endianness in the callback structure until
+ sim_config is called, which happens in sim_open. */
+ default_callback.target_endian
+ = (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN
+ ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
+
/* Was there a program to run? */
prog_argv = STATE_PROG_ARGV (sd);
prog_bfd = STATE_PROG_BFD (sd);
brgds, H-P