Move big-endian memory access to memreadwrite.h.

This commit is contained in:
Maxim Poliakovski 2020-01-03 16:08:00 +01:00
parent 14e203f528
commit 241031dfe7
4 changed files with 23 additions and 7 deletions

View File

@ -14,6 +14,7 @@
#include <array> #include <array>
#include <thread> #include <thread>
#include <atomic> #include <atomic>
#include "memreadwrite.h"
#include "ppcemu.h" #include "ppcemu.h"
#include "ppcmmu.h" #include "ppcmmu.h"
#include "devices/memctrlbase.h" #include "devices/memctrlbase.h"
@ -65,10 +66,9 @@ void msr_status_update(){
msr_dr_test = (ppc_state.ppc_msr >> 4) & 1; 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) | ppc_cur_instruction = READ_DWORD_BE(ptr);
(ptr[offset+2] << 8) | ptr[offset+3];
} }
static inline void ppc_set_return_val(unsigned char *ptr, uint32_t offset, static inline void ppc_set_return_val(unsigned char *ptr, uint32_t offset,

View File

@ -4,10 +4,6 @@
#include <cinttypes> #include <cinttypes>
#include <string> #include <string>
#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 */ /** Abstract class representing a simple, memory-mapped I/O device */
class MMIODevice { class MMIODevice {
public: public:

View File

@ -14,6 +14,7 @@
#include <cstring> #include <cstring>
#include <cinttypes> #include <cinttypes>
#include "memreadwrite.h"
#include "memctrlbase.h" #include "memctrlbase.h"
#include "mmiodevice.h" #include "mmiodevice.h"
#include "mpc106.h" #include "mpc106.h"

19
memreadwrite.h Normal file
View File

@ -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 */