From 241031dfe74cbe1268846a5ed7f4a38a2fc66016 Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Fri, 3 Jan 2020 16:08:00 +0100 Subject: [PATCH] Move big-endian memory access to memreadwrite.h. --- cpu/ppc/ppcmmu.cpp | 6 +++--- devices/mmiodevice.h | 4 ---- devices/mpc106.cpp | 1 + memreadwrite.h | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 memreadwrite.h diff --git a/cpu/ppc/ppcmmu.cpp b/cpu/ppc/ppcmmu.cpp index 9c585bf..1fcf7f6 100644 --- a/cpu/ppc/ppcmmu.cpp +++ b/cpu/ppc/ppcmmu.cpp @@ -14,6 +14,7 @@ #include #include #include +#include "memreadwrite.h" #include "ppcemu.h" #include "ppcmmu.h" #include "devices/memctrlbase.h" @@ -65,10 +66,9 @@ void msr_status_update(){ msr_dr_test = (ppc_state.ppc_msr >> 4) & 1; } -static inline void ppc_set_cur_instruction(unsigned char *ptr, uint32_t offset) +static inline void ppc_set_cur_instruction(const uint8_t *ptr) { - ppc_cur_instruction = (ptr[offset] << 24) | (ptr[offset+1] << 16) | - (ptr[offset+2] << 8) | ptr[offset+3]; + ppc_cur_instruction = READ_DWORD_BE(ptr); } static inline void ppc_set_return_val(unsigned char *ptr, uint32_t offset, diff --git a/devices/mmiodevice.h b/devices/mmiodevice.h index adc6140..9cc48e4 100644 --- a/devices/mmiodevice.h +++ b/devices/mmiodevice.h @@ -4,10 +4,6 @@ #include #include -#define READ_WORD_BE(addr) ((addr)[0] << 16) | (addr)[1] -#define READ_DWORD_BE(addr) ((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3] -#define READ_DWORD_LE(addr) ((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0] - /** Abstract class representing a simple, memory-mapped I/O device */ class MMIODevice { public: diff --git a/devices/mpc106.cpp b/devices/mpc106.cpp index 2527b06..858d8f7 100644 --- a/devices/mpc106.cpp +++ b/devices/mpc106.cpp @@ -14,6 +14,7 @@ #include #include +#include "memreadwrite.h" #include "memctrlbase.h" #include "mmiodevice.h" #include "mpc106.h" diff --git a/memreadwrite.h b/memreadwrite.h new file mode 100644 index 0000000..f6357df --- /dev/null +++ b/memreadwrite.h @@ -0,0 +1,19 @@ +#ifndef MEM_READ_WRITE_H +#define MEM_READ_WRITE_H + +/** @file Set of macros for accessing integers of various sizes and endianness + in host memory. + */ + +/* read a unaligned big-endian WORD (16bit) */ +#define READ_WORD_BE(addr) (((addr)[0] << 16) | (addr)[1]) + +/* read a unaligned big-endian DWORD (32bit) */ +#define READ_DWORD_BE(addr) (((addr)[0] << 24) | ((addr)[1] << 16) | \ + ((addr)[2] << 8) | (addr)[3]) + +/* read a unaligned little-endian DWORD (32bit) */ +#define READ_DWORD_LE(addr) (((addr)[3] << 24) | ((addr)[2] << 16) | \ + ((addr)[1] << 8) | (addr)[0]) + +#endif /* MEM_READ_WRITE_H */