aboutsummaryrefslogtreecommitdiff
path: root/lib/dis.h
diff options
context:
space:
mode:
authorcomex2015-02-24 20:57:12 -0500
committercomex2015-02-24 20:57:12 -0500
commit11d6f5764e35bdddae7a4aaf23fd859eecb48c8f (patch)
tree59d1be8a346c15c2e1287d31ce04eabd58eb3104 /lib/dis.h
parentfix armv7 syscall registers :o (diff)
downloadsubstitute-11d6f5764e35bdddae7a4aaf23fd859eecb48c8f.tar.gz
Add unaligned read/write functions.
I thought I could get away without since I wasn't (presently) targeting systems without hardware support for unaligned accesses, but on armv7 clang insists on optimizing into the one ARM instruction that requires alignment anyway - LDM/STM. Oops. Damnit, clang.
Diffstat (limited to 'lib/dis.h')
-rw-r--r--lib/dis.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/dis.h b/lib/dis.h
index ed3690f..99f3a7c 100644
--- a/lib/dis.h
+++ b/lib/dis.h
@@ -9,6 +9,31 @@
#define INLINE __attribute__((always_inline))
#define NOINLINE __attribute__((noinline))
+static INLINE inline void unaligned_w64(void *ptr, uint64_t val) {
+ __builtin_memcpy(ptr, &val, 8);
+}
+static INLINE inline void unaligned_w32(void *ptr, uint32_t val) {
+ __builtin_memcpy(ptr, &val, 4);
+}
+static INLINE inline void unaligned_w16(void *ptr, uint16_t val) {
+ __builtin_memcpy(ptr, &val, 2);
+}
+static INLINE inline uint64_t unaligned_r64(const void *ptr) {
+ uint64_t val;
+ __builtin_memcpy(&val, ptr, 8);
+ return val;
+}
+static INLINE inline uint32_t unaligned_r32(const void *ptr) {
+ uint32_t val;
+ __builtin_memcpy(&val, ptr, 4);
+ return val;
+}
+static INLINE inline uint16_t unaligned_r16(const void *ptr) {
+ uint16_t val;
+ __builtin_memcpy(&val, ptr, 2);
+ return val;
+}
+
struct bitslice_run {
int inpos, outpos, len;
};
@@ -113,17 +138,17 @@ static const unsigned null_op = -0x100;
#endif
static inline void op64(void **codep, uint64_t op) {
- *(uint64_t *) *codep = op;
+ unaligned_w64(*codep, op);
*codep += 8;
}
static inline void op32(void **codep, uint32_t op) {
- *(uint32_t *) *codep = op;
+ unaligned_w32(*codep, op);
*codep += 4;
}
static inline void op16(void **codep, uint16_t op) {
- *(uint16_t *) *codep = op;
+ unaligned_w16(*codep, op);
*codep += 2;
}