mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-12-22 15:29:58 +00:00
Clean up memaccess header.
This commit is contained in:
parent
094d9a9c2f
commit
4f3dd797be
69
memaccess.h
69
memaccess.h
@ -1,4 +1,4 @@
|
|||||||
/** @file Set of macros for accessing host memory units of various sizes
|
/** @file Set of macros for accessing host memory in units of various sizes
|
||||||
and endianness.
|
and endianness.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -31,7 +31,8 @@
|
|||||||
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
||||||
|
|
||||||
/* read an unaligned big-endian DWORD (32bit) */
|
/* read an unaligned big-endian DWORD (32bit) */
|
||||||
#define READ_DWORD_BE_U(addr) (((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
|
#define READ_DWORD_BE_U(addr) \
|
||||||
|
(((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
|
||||||
|
|
||||||
/* read an unaligned big-endian QWORD (32bit) */
|
/* read an unaligned big-endian QWORD (32bit) */
|
||||||
#define READ_QWORD_BE_U(addr) \
|
#define READ_QWORD_BE_U(addr) \
|
||||||
@ -43,14 +44,15 @@
|
|||||||
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (addr)[0])
|
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (addr)[0])
|
||||||
|
|
||||||
/* read an unaligned little-endian DWORD (32bit) */
|
/* read an unaligned little-endian DWORD (32bit) */
|
||||||
#define READ_DWORD_LE_U(addr) (((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
#define READ_DWORD_LE_U(addr) \
|
||||||
|
(((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||||
|
|
||||||
/* read an unaligned little-endian DWORD (32bit) */
|
/* read an unaligned little-endian DWORD (64bit) */
|
||||||
#define READ_QWORD_LE_U(addr) \
|
#define READ_QWORD_LE_U(addr) \
|
||||||
(((addr)[7] << 56) | ((addr)[6] << 48) | ((addr)[5] << 40) | ((addr)[4] << 32) | \
|
((uint64_t((addr)[7]) << 56) | (uint64_t((addr)[6]) << 48) | \
|
||||||
|
(uint64_t((addr)[5]) << 40) | (uint64_t((addr)[4]) << 32) | \
|
||||||
((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||||
|
|
||||||
|
|
||||||
/* write an aligned big-endian WORD (16bit) */
|
/* write an aligned big-endian WORD (16bit) */
|
||||||
#define WRITE_WORD_BE_A(addr, val) (*((uint16_t*)((addr))) = BYTESWAP_16(val))
|
#define WRITE_WORD_BE_A(addr, val) (*((uint16_t*)((addr))) = BYTESWAP_16(val))
|
||||||
|
|
||||||
@ -61,19 +63,32 @@
|
|||||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)((addr))) = BYTESWAP_64(val))
|
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)((addr))) = BYTESWAP_64(val))
|
||||||
|
|
||||||
/* write an unaligned big-endian WORD (16bit) */
|
/* write an unaligned big-endian WORD (16bit) */
|
||||||
#define WRITE_WORD_BE_U(addr, val) \
|
#define WRITE_WORD_BE_U(addr, val) \
|
||||||
do { \
|
do { \
|
||||||
(addr)[0] = ((val) >> 8) & 0xFF; \
|
(addr)[0] = ((val) >> 8) & 0xFF; \
|
||||||
(addr)[1] = (val)&0xFF; \
|
(addr)[1] = (val) & 0xFF; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* write an unaligned big-endian DWORD (32bit) */
|
/* write an unaligned big-endian DWORD (32bit) */
|
||||||
#define WRITE_DWORD_BE_U(addr, val) \
|
#define WRITE_DWORD_BE_U(addr, val) \
|
||||||
do { \
|
do { \
|
||||||
(addr)[0] = ((val) >> 24) & 0xFF; \
|
(addr)[0] = ((val) >> 24) & 0xFF; \
|
||||||
(addr)[1] = ((val) >> 16) & 0xFF; \
|
(addr)[1] = ((val) >> 16) & 0xFF; \
|
||||||
(addr)[2] = ((val) >> 8) & 0xFF; \
|
(addr)[2] = ((val) >> 8) & 0xFF; \
|
||||||
(addr)[3] = (val)&0xFF; \
|
(addr)[3] = (val) & 0xFF; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* write an unaligned big-endian DWORD (64bit) */
|
||||||
|
#define WRITE_QWORD_BE_U(addr, val) \
|
||||||
|
do { \
|
||||||
|
(addr)[0] = ((uint64_t)(val) >> 56) & 0xFF; \
|
||||||
|
(addr)[1] = ((uint64_t)(val) >> 48) & 0xFF; \
|
||||||
|
(addr)[2] = ((uint64_t)(val) >> 40) & 0xFF; \
|
||||||
|
(addr)[3] = ((uint64_t)(val) >> 32) & 0xFF; \
|
||||||
|
(addr)[4] = ((val) >> 24) & 0xFF; \
|
||||||
|
(addr)[5] = ((val) >> 16) & 0xFF; \
|
||||||
|
(addr)[6] = ((val) >> 8) & 0xFF; \
|
||||||
|
(addr)[7] = (val) & 0xFF; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* write an aligned little-endian WORD (16bit) */
|
/* write an aligned little-endian WORD (16bit) */
|
||||||
@ -86,19 +101,19 @@
|
|||||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)((addr))) = (val))
|
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)((addr))) = (val))
|
||||||
|
|
||||||
/* write an unaligned little-endian WORD (16bit) */
|
/* write an unaligned little-endian WORD (16bit) */
|
||||||
#define WRITE_WORD_LE_U(addr, val) \
|
#define WRITE_WORD_LE_U(addr, val) \
|
||||||
do { \
|
do { \
|
||||||
(addr)[0] = (val)&0xFF; \
|
(addr)[0] = (val)&0xFF; \
|
||||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* write an unaligned little-endian DWORD (32bit) */
|
/* write an unaligned little-endian DWORD (32bit) */
|
||||||
#define WRITE_DWORD_LE_U(addr, val) \
|
#define WRITE_DWORD_LE_U(addr, val) \
|
||||||
do { \
|
do { \
|
||||||
(addr)[0] = (val)&0xFF; \
|
(addr)[0] = (val)&0xFF; \
|
||||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||||
(addr)[2] = ((val) >> 16) & 0xFF; \
|
(addr)[2] = ((val) >> 16) & 0xFF; \
|
||||||
(addr)[3] = ((val) >> 24) & 0xFF; \
|
(addr)[3] = ((val) >> 24) & 0xFF; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* read value of the specified size from memory starting at addr,
|
/* read value of the specified size from memory starting at addr,
|
||||||
|
Loading…
Reference in New Issue
Block a user