Add aligned macros for reading ints from memory.
This commit is contained in:
parent
720b35aa26
commit
0b0c00b653
|
@ -35,7 +35,7 @@ PPC_BAT_entry dbat_array[4] = {{0}};
|
|||
|
||||
void ppc_set_cur_instruction(const uint8_t *ptr)
|
||||
{
|
||||
ppc_cur_instruction = READ_DWORD_BE(ptr);
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
static inline void ppc_set_return_val(const uint8_t *ptr, int num_size)
|
||||
|
@ -49,17 +49,17 @@ static inline void ppc_set_return_val(const uint8_t *ptr, int num_size)
|
|||
|
||||
if (ppc_state.ppc_msr & 1) { /* little-endian byte ordering */
|
||||
if (num_size == 2) { // WORD
|
||||
return_value = READ_WORD_LE(ptr);
|
||||
return_value = READ_WORD_LE_A(ptr);
|
||||
}
|
||||
else if (num_size == 4) { // DWORD
|
||||
return_value = READ_DWORD_LE(ptr);
|
||||
return_value = READ_DWORD_LE_A(ptr);
|
||||
}
|
||||
} else { /* big-endian byte ordering */
|
||||
if (num_size == 2) { // WORD
|
||||
return_value = READ_WORD_BE(ptr);
|
||||
return_value = READ_WORD_BE_A(ptr);
|
||||
}
|
||||
else if (num_size == 4) { // DWORD
|
||||
return_value = READ_DWORD_BE(ptr);
|
||||
return_value = READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,22 +183,22 @@ static bool search_pteg(uint8_t *pteg_addr, uint8_t **ret_pte_addr,
|
|||
bool match_found = false;
|
||||
|
||||
for (int i = 0; i < 8; i++, pteg_addr += 8) {
|
||||
if (pte_check == READ_DWORD_BE(pteg_addr)) {
|
||||
if (pte_check == READ_DWORD_BE_A(pteg_addr)) {
|
||||
if (match_found) {
|
||||
if ((READ_DWORD_BE(pteg_addr) & 0xFFFFF07B) != pte_word2_check) {
|
||||
if ((READ_DWORD_BE_A(pteg_addr) & 0xFFFFF07B) != pte_word2_check) {
|
||||
printf("Multiple PTEs with different RPN/WIMG/PP found!\n");
|
||||
exit(-1);
|
||||
}
|
||||
} else {
|
||||
/* isolate RPN, WIMG and PP fields */
|
||||
pte_word2_check = READ_DWORD_BE(pteg_addr) & 0xFFFFF07B;
|
||||
pte_word2_check = READ_DWORD_BE_A(pteg_addr) & 0xFFFFF07B;
|
||||
*ret_pte_addr = pteg_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < 8; i++, pteg_addr += 8) {
|
||||
if (pte_check == READ_DWORD_BE(pteg_addr)) {
|
||||
if (pte_check == READ_DWORD_BE_A(pteg_addr)) {
|
||||
*ret_pte_addr = pteg_addr;
|
||||
return true;
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ static uint32_t page_address_translate(uint32_t la, bool is_instr_fetch,
|
|||
}
|
||||
}
|
||||
|
||||
pte_word2 = READ_DWORD_BE(pte_addr + 4);
|
||||
pte_word2 = READ_DWORD_BE_A(pte_addr + 4);
|
||||
|
||||
key = (((sr_val >> 29) & 1) & msr_pr) | (((sr_val >> 30) & 1) & (msr_pr ^ 1));
|
||||
|
||||
|
|
|
@ -123,10 +123,10 @@ uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
|||
return this->my_pci_cfg_hdr[reg_offs];
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_BE(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
return READ_WORD_BE_A(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
break;
|
||||
case 4:
|
||||
return READ_DWORD_BE(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
return READ_DWORD_BE_A(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
break;
|
||||
default:
|
||||
std::cout << "MPC106 read error: invalid size parameter " << size
|
||||
|
@ -198,15 +198,15 @@ void MPC106::setup_ram()
|
|||
for (int bank = 0; bank < 8; bank++) {
|
||||
if (bank_en & (1 << bank)) {
|
||||
if (bank < 4) {
|
||||
mem_start = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x80]);
|
||||
ext_mem_start = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x88]);
|
||||
mem_end = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x90]);
|
||||
ext_mem_end = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x98]);
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x80]);
|
||||
ext_mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x88]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x90]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x98]);
|
||||
} else {
|
||||
mem_start = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x84]);
|
||||
ext_mem_start = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x8C]);
|
||||
mem_end = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x94]);
|
||||
ext_mem_end = READ_DWORD_LE(&this->my_pci_cfg_hdr[0x9C]);
|
||||
mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x84]);
|
||||
ext_mem_start = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x8C]);
|
||||
mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x94]);
|
||||
ext_mem_end = READ_DWORD_LE_A(&this->my_pci_cfg_hdr[0x9C]);
|
||||
}
|
||||
bank_start = (((ext_mem_start >> bank * 8) & 3) << 30) |
|
||||
(((mem_start >> bank * 8) & 0xFF) << 20);
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -305,7 +305,7 @@ int main(int argc, char **argv)
|
|||
romFile.seekg (configInfoAddr, ios::beg);
|
||||
romFile.read(memPPCBlock, 4);
|
||||
memPPCBlock[4] = 0;
|
||||
uint32_t rom_id = READ_DWORD_BE(memPPCBlock);
|
||||
uint32_t rom_id = READ_DWORD_BE_A(memPPCBlock);
|
||||
|
||||
std::string string_test = std::string(memPPCBlock);
|
||||
|
||||
|
|
|
@ -1,22 +1,38 @@
|
|||
#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] << 8) | (addr)[1])
|
||||
#ifndef MEM_READ_WRITE_H
|
||||
#define MEM_READ_WRITE_H
|
||||
|
||||
/* read a unaligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE(addr) (((addr)[0] << 24) | ((addr)[1] << 16) | \
|
||||
((addr)[2] << 8) | (addr)[3])
|
||||
#include <cinttypes>
|
||||
#include "endianswap.h"
|
||||
|
||||
/* read a unaligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE(addr) (((addr)[1] << 8) | (ptr)[0])
|
||||
/* read an aligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_A(addr) (BYTESWAP_16(*((uint16_t *)((addr)))))
|
||||
|
||||
/* read a unaligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE(addr) (((addr)[3] << 24) | ((addr)[2] << 16) | \
|
||||
((addr)[1] << 8) | (addr)[0])
|
||||
/* read an aligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t *)((addr)))))
|
||||
|
||||
/* read an aligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_A(addr) (*(uint16_t *)((addr)))
|
||||
|
||||
/* read an aligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_A(addr) (*(uint32_t *)((addr)))
|
||||
|
||||
|
||||
/* read an unaligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
||||
|
||||
/* read an unaligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_U(addr) (((addr)[0] << 24) | ((addr)[1] << 16) | \
|
||||
((addr)[2] << 8) | (addr)[3])
|
||||
|
||||
/* read an unaligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (ptr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_U(addr) (((addr)[3] << 24) | ((addr)[2] << 16) | \
|
||||
((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
#endif /* MEM_READ_WRITE_H */
|
||||
|
|
Loading…
Reference in New Issue