diff --git a/devices/common/pci/bandit.cpp b/devices/common/pci/bandit.cpp index 6ebd6a1..4ed2697 100644 --- a/devices/common/pci/bandit.cpp +++ b/devices/common/pci/bandit.cpp @@ -196,7 +196,7 @@ void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size LOG_F( WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -208,7 +208,7 @@ void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x", this->name.c_str(), idsel, this->config_addr, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -225,7 +225,7 @@ void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size LOG_F( ERROR, "%s err: write attempt to non-existing PCI device ??:%02x.%x @%02x.%c = %0*x", this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); } } else { @@ -358,7 +358,7 @@ void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) LOG_F( WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -370,7 +370,7 @@ void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x", this->name.c_str(), idsel, this->config_addr, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); return; } @@ -382,7 +382,7 @@ void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) LOG_F( ERROR, "%s err: write attempt to non-existing VCI device ??:%02x.%x @%02x.%c = %0*x", this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3), - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); } } else { diff --git a/devices/common/pci/pcidevice.cpp b/devices/common/pci/pcidevice.cpp index ea060b0..9148e6a 100644 --- a/devices/common/pci/pcidevice.cpp +++ b/devices/common/pci/pcidevice.cpp @@ -156,7 +156,7 @@ void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) LOG_F( WARNING, "%s: attempt to write to reserved/unimplemented register @%02x.%c = %0*x", this->pci_name.c_str(), reg_offs, - size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, flip_sized(value, size) ); } } diff --git a/devices/memctrl/mpc106.cpp b/devices/memctrl/mpc106.cpp index 7ca2ab4..3c85aef 100644 --- a/devices/memctrl/mpc106.cpp +++ b/devices/memctrl/mpc106.cpp @@ -169,8 +169,8 @@ void MPC106::pci_write(uint32_t value, uint32_t size) { "%s err: write attempt to non-local PCI bus, config_addr = %x %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), this->config_addr, bus_num, dev_num, fun_num, reg_offs, size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, - size * 2, value - ); + size * 2, flip_sized(value, size) + ); return; } @@ -185,7 +185,7 @@ void MPC106::pci_write(uint32_t value, uint32_t size) { "%s err: write attempt to non-existing PCI device %02x:%02x.%x @%02x.%c = %0*x", this->name.c_str(), bus_num, dev_num, fun_num, reg_offs, size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, - size * 2, value + size * 2, flip_sized(value, size) ); } } diff --git a/memaccess.h b/memaccess.h index 46bc60c..9f2d81b 100644 --- a/memaccess.h +++ b/memaccess.h @@ -177,6 +177,15 @@ inline uint32_t read_mem_rev(const uint8_t* buf, uint32_t size) { } } +inline uint32_t flip_sized(uint32_t value, uint32_t size) { + switch (size) { + case 1: return value; + case 2: return BYTESWAP_16(value); + case 4: return BYTESWAP_32(value); + default: LOG_F(ERROR, "flip_sized: invalid size %d!", size); return 0xffffffff; + } +} + /* write the specified value of the specified size to memory pointed to by addr, perform necessary byte swapping so that the byte order of the destination remains unchanged. */