summaryrefslogtreecommitdiff
path: root/gdb/rdi-share
diff options
context:
space:
mode:
authorJason Molenda <jsm@bugshack.cygnus.com>1999-11-02 04:44:27 +0000
committerJason Molenda <jsm@bugshack.cygnus.com>1999-11-02 04:44:27 +0000
commit1f80975aceb82ecd4fc9bf4e988e6d1b7c7bbca1 (patch)
tree89b91ca4bdc6d7fa4fc721e8bb68d90484cc5358 /gdb/rdi-share
parent2c74239c50b6b7f9e08083a8692621d4d314d011 (diff)
downloadgdb-1f80975aceb82ecd4fc9bf4e988e6d1b7c7bbca1.tar.gz
Initial revision
Diffstat (limited to 'gdb/rdi-share')
-rw-r--r--gdb/rdi-share/angel_bytesex.c57
-rw-r--r--gdb/rdi-share/angel_bytesex.h42
-rw-r--r--gdb/rdi-share/angel_endian.h125
3 files changed, 224 insertions, 0 deletions
diff --git a/gdb/rdi-share/angel_bytesex.c b/gdb/rdi-share/angel_bytesex.c
new file mode 100644
index 00000000000..b98c971708e
--- /dev/null
+++ b/gdb/rdi-share/angel_bytesex.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
+ *
+ * This software may be freely used, copied, modified, and distributed
+ * provided that the above copyright notice is preserved in all copies of the
+ * software.
+ */
+
+/*
+ * angel_bytesex.c - Code to support byte-sex independence
+ * Copyright: (C) 1991, Advanced RISC Machines Ltd., Cambridge, England.
+ */
+
+/*
+ * RCS $Revision: 1.1 $
+ * Checkin $Date: 1999/11/01 15:29:57 $
+ */
+
+#include "angel_bytesex.h"
+
+static int reversing_bytes = 0;
+
+void bytesex_reverse(yes_or_no)
+int yes_or_no;
+{ reversing_bytes = yes_or_no;
+}
+
+int bytesex_reversing()
+{
+ return reversing_bytes;
+}
+
+int32 bytesex_hostval(v)
+int32 v;
+{ /* Return v with the same endian-ness as the host */
+ /* This mess generates better ARM code than the more obvious mess */
+ /* and may eventually peephole to optimal code... */
+ if (reversing_bytes)
+ { unsigned32 t;
+ /* t = v ^ (v ror 16) */
+ t = v ^ ((v << 16) | (((unsigned32)v) >> 16));
+ t &= ~0xff0000;
+ /* v = v ror 8 */
+ v = (v << 24) | (((unsigned32)v) >> 8);
+ v = v ^ (t >> 8);
+ }
+ return v;
+}
+
+int32 bytesex_hostval_16(v)
+int32 v;
+{
+ if (reversing_bytes) {
+ v = ((v >> 8) & 0xff) | ((v << 8) & 0xff00);
+ }
+ return v;
+}
diff --git a/gdb/rdi-share/angel_bytesex.h b/gdb/rdi-share/angel_bytesex.h
new file mode 100644
index 00000000000..40786ed2ba9
--- /dev/null
+++ b/gdb/rdi-share/angel_bytesex.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
+ *
+ * This software may be freely used, copied, modified, and distributed
+ * provided that the above copyright notice is preserved in all copies of the
+ * software.
+ */
+
+/*
+ Title: Code to support byte-sex independence
+ Copyright: (C) 1991, Advanced RISC Machines Ltd., Cambridge, England.
+*/
+/*
+ * RCS $Revision: 1.1 $
+ * Checkin $Date: 1999/11/01 15:29:57 $
+ */
+
+#ifndef angel_bytesex_h
+#define angel_bytesex_h
+
+#include "host.h"
+
+void bytesex_reverse(int yes_or_no);
+/*
+ * Turn sex-reversal on or off - 0 means off, non-0 means on.
+ */
+
+int bytesex_reversing(void);
+/*
+ * Return non-0 if reversing the byte sex, else 0.
+ */
+
+int32 bytesex_hostval(int32 v);
+/*
+ * Return v or byte-reversed v, according to whether sex-reversval
+ * is on or off.
+ */
+
+int32 bytesex_hostval_16(int32 v);
+/* Return v or byte-reversed v for a 16 bit value */
+
+#endif
diff --git a/gdb/rdi-share/angel_endian.h b/gdb/rdi-share/angel_endian.h
new file mode 100644
index 00000000000..6e871397041
--- /dev/null
+++ b/gdb/rdi-share/angel_endian.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
+ *
+ * This software may be freely used, copied, modified, and distributed
+ * provided that the above copyright notice is preserved in all copies of the
+ * software.
+ */
+
+/* -*-C-*-
+ *
+ * $Revision: 1.1 $
+ * $Date: 1999/11/01 13:31:32 $
+ *
+ *
+ * angel_endian.h - target endianness independent read/write primitives.
+ */
+
+#ifndef angel_endian_h
+#define angel_endian_h
+
+/*
+ * The endianness of the data being processed needs to be known, but
+ * the host endianness is not required (since the data is constructed
+ * using bytes). At the moment these are provided as macros. This
+ * gives the compiler freedom in optimising individual calls. However,
+ * if space is at a premium then functions should be provided.
+ *
+ * NOTE: These macros assume that the data has been packed in the same format
+ * as the packing on the build host. If this is not the case then
+ * the wrong addresses could be used when dealing with structures.
+ *
+ */
+
+/*
+ * For all the following routines the target endianness is defined by the
+ * following boolean definitions.
+ */
+#define BE (1 == 1) /* TRUE : big-endian */
+#define LE (1 == 0) /* FALSE : little-endian */
+
+/*
+ * The following type definitions are used by the endianness converting
+ * macros.
+ */
+typedef unsigned char U8;
+typedef U8 *P_U8;
+typedef const U8 *CP_U8;
+
+typedef unsigned short U16;
+typedef U16 *P_U16;
+
+typedef unsigned int U32;
+typedef U32 *P_U32;
+
+/*
+ * If the endianness of the host and target are known (fixed) and the same
+ * then the following macro definitions can be used. These just directly copy
+ * the data.
+ *
+ * #define READ(e,a) (a)
+ * #define WRITE(e,a,v) ((a) = (v))
+ * #define PREAD(e,a) (a)
+ * #define PWRITE(e,a,v) (*(a) = (v))
+ */
+
+/*
+ * These macros assume that a byte (char) is 8bits in size, and that the
+ * endianness is not important when reading or writing bytes.
+ */
+#define PUT8(a,v) (*((P_U8)(a)) = (U8)(v))
+#define PUT16LE(a,v) (PUT8(a,((v) & 0xFF)), \
+ PUT8((((P_U8)(a)) + sizeof(char)),((v) >> 8)))
+#define PUT16BE(a,v) (PUT8(a,((v) >> 8)), \
+ PUT8((((P_U8)(a)) + sizeof(char)),((v) & 0xFF)))
+#define PUT32LE(a,v) (PUT16LE(a,v), \
+ PUT16LE((((P_U8)(a)) + sizeof(short)),((v) >> 16)))
+#define PUT32BE(a,v) (PUT16BE(a,((v) >> 16)), \
+ PUT16BE((((P_U8)(a)) + sizeof(short)),v))
+
+#define GET8(a) (*((CP_U8)(a)))
+#define GET16LE(a) (GET8(a) | (((U16)GET8(((CP_U8)(a)) + sizeof(char))) << 8))
+#define GET16BE(a) ((((U16)GET8(a)) << 8) | GET8(((CP_U8)(a)) + sizeof(char)))
+#define GET32LE(a) (GET16LE(a) | \
+ (((U32)GET16LE(((CP_U8)(a)) + sizeof(short))) << 16))
+#define GET32BE(a) ((((U32)GET16BE(a)) << 16) | \
+ GET16BE(((CP_U8)(a)) + sizeof(short)))
+
+/*
+ * These macros simplify the code in respect to reading and writing the
+ * correct size data when dealing with endianness. "e" is TRUE if we are
+ * dealing with big-endian data, FALSE if we are dealing with little-endian.
+ */
+
+/* void WRITE(int endianness, void *address, unsigned value); */
+
+#define WRITE16(e,a,v) ((e) ? PUT16BE(&(a),v) : PUT16LE(&(a),v))
+#define WRITE32(e,a,v) ((e) ? PUT32BE(&(a),v) : PUT32LE(&(a),v))
+#define WRITE(e,a,v) ((sizeof(v) == sizeof(char)) ? \
+ PUT8(&(a),v) : ((sizeof(v) == sizeof(short)) ? \
+ WRITE16(e,a,v) : WRITE32(e,a,v)))
+
+/* unsigned READ(int endianness, void *address) */
+#define READ16(e,a) ((e) ? GET16BE(&(a)) : GET16LE(&(a)))
+#define READ32(e,a) ((e) ? GET32BE(&(a)) : GET32LE(&(a)))
+#define READ(e,a) ((sizeof(a) == sizeof(char)) ? \
+ GET8((CP_U8)&(a)) : ((sizeof(a) == sizeof(short)) ? \
+ READ16(e,a) : READ32(e,a)))
+
+/* void PWRITE(int endianness, void *address, unsigned value); */
+#define PWRITE16(e,a,v) ((e) ? PUT16BE(a,v) : PUT16LE(a,v))
+#define PWRITE32(e,a,v) ((e) ? PUT32BE(a,v) : PUT32LE(a,v))
+#define PWRITE(e,a,v) ((sizeof(v) == sizeof(char)) ? \
+ PUT8(a,v) : ((sizeof(v) == sizeof(short)) ? \
+ PWRITE16(e,a,v) : PWRITE32(e,a,v)))
+
+/* unsigned PREAD(int endianness, void *address) */
+#define PREAD16(e,a) ((e) ? GET16BE(a) : GET16LE(a))
+#define PREAD32(e,a) ((e) ? GET32BE(a) : GET32LE(a))
+#define PREAD(e,a) ((sizeof(*(a)) == sizeof(char)) ? \
+ GET8((CP_U8)a) : ((sizeof(*(a)) == sizeof(short)) ? \
+ PREAD16(e,a) : PREAD32(e,a)))
+
+#endif /* !defined(angel_endian_h) */
+
+/* EOF angel_endian.h */