This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA:] Minor sim callback endian cleanup.
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 12 Dec 2004 06:22:32 +0100
- Subject: [RFA:] Minor sim callback endian cleanup.
The supposedly-sim-independent sim/common/callback.c and syscall.c
(from sim/common/syscall.c:
/* This interface isn't intended to be specific to any particular kind
of remote (hardware, simulator, whatever). As such, support for it
(e.g. sim/common/callback.c) should *not* live in the simulator source
tree, nor should it live in the gdb source tree. K&R C must be
supported. */
)
have no idea what the endian of the target is, and still are
supposed to store multi-byte values correctly without access to
proper multibyte-value-store functions. Currently,
little-endian is assumed when storing struct stat members, which
of course is just broken. This patch introduces a member of
host_callback to hold the endianness of the target. Because of
sim-independentness those files must not include sim-config.h to
access CURRENT_TARGET_BYTE_ORDER. Oh well. I blissfully ignore
the possibility of different endian types (16-bit within 32-bit
different to 8-bit within 16-bit) but so does the rest of sim/.
Tested together with other dependent stuff using the CRIS sim.
Test-built on m32r-sim, arm-sim and frv-sim with this patch
only.
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.
Only in .: .xdiff-directory
diff -rup /n/slask/hp_tmp/gdb-6.3.50_20041211/./include/gdb/callback.h ./include/gdb/callback.h
--- /n/slask/hp_tmp/gdb-6.3.50_20041211/./include/gdb/callback.h Fri Jun 25 18:48:01 2004
+++ ./include/gdb/callback.h Sun Dec 12 06:06:29 2004
@@ -150,6 +150,9 @@ struct host_callback_struct
Example: "st_dev,4:st_ino,4:st_mode,4:..." */
const char *stat_map;
+ /* Nonzero for a big-endian target. */
+ int target_big_endian;
+
/* Marker for those wanting to do sanity checks.
This should remain the last member of this struct to help catch
miscompilation errors. */
@@ -272,6 +275,9 @@ int cb_host_to_target_signal PARAMS ((ho
If stat struct ptr is NULL, just compute target stat struct size.
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 *));
Only in ./include/gdb: callback.h~
Only in ./sim/common: ChangeLog.hp
diff -rup /n/slask/hp_tmp/gdb-6.3.50_20041211/./sim/common/callback.c ./sim/common/callback.c
--- /n/slask/hp_tmp/gdb-6.3.50_20041211/./sim/common/callback.c Sat Dec 4 00:34:55 2004
+++ ./sim/common/callback.c Sun Dec 12 05:17:26 2004
@@ -615,6 +615,9 @@ host_callback default_callback =
0, /* signal_map */
0, /* stat_map */
+ /* Defaults expected to be overridden at initialization, where needed. */
+ 0, /* target_big_endian */
+
HOST_CALLBACK_MAGIC,
};
@@ -746,17 +749,17 @@ cb_target_to_host_open (cb, target_val)
return host_val;
}
-/* Utility for cb_host_to_target_stat to store values in the target's
+/* Utility for e.g. cb_host_to_target_stat to store values in the target's
stat struct. */
-static void
-store (p, size, val, big_p)
+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 */
- int big_p;
{
- if (big_p)
+ if (cb->target_big_endian)
{
p += size;
while (size-- > 0)
@@ -790,7 +793,6 @@ cb_host_to_target_stat (cb, hs, ts)
{
const char *m = cb->stat_map;
char *p;
- int big_p = 0;
if (hs == NULL)
ts = NULL;
@@ -822,7 +824,7 @@ cb_host_to_target_stat (cb, hs, ts)
#undef ST_x
#define ST_x(FLD) \
else if (strncmp (m, #FLD, q - m) == 0) \
- store (p, size, hs->FLD, big_p)
+ cb_store_target_endian (cb, p, size, hs->FLD)
#ifdef HAVE_STRUCT_STAT_ST_DEV
ST_x (st_dev);
@@ -866,7 +868,8 @@ cb_host_to_target_stat (cb, hs, ts)
#undef ST_x
/* FIXME:wip */
else
- store (p, size, 0, big_p); /* unsupported field, store 0 */
+ /* Unsupported field, store 0. */
+ cb_store_target_endian (cb, p, size, 0);
}
p += size;
Only in ./sim/common: callback.c.orig
Only in ./sim/common: callback.c~
diff -rup /n/slask/hp_tmp/gdb-6.3.50_20041211/./sim/common/nrun.c ./sim/common/nrun.c
--- /n/slask/hp_tmp/gdb-6.3.50_20041211/./sim/common/nrun.c Wed Dec 8 01:40:30 2004
+++ ./sim/common/nrun.c Sun Dec 12 05:17:26 2004
@@ -82,6 +82,11 @@ main (int argc, char **argv)
abort ();
}
+ /* We can't set the endianness in the callback structure until
+ sim_config is called, which happens in sim_open. */
+ default_callback.target_big_endian
+ = CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN;
+
/* Was there a program to run? */
prog_argv = STATE_PROG_ARGV (sd);
prog_bfd = STATE_PROG_BFD (sd);
brgds, H-P