diff --git a/devices/common/pci/bandit.cpp b/devices/common/pci/bandit.cpp index 4ed2697..3c2c0e9 100644 --- a/devices/common/pci/bandit.cpp +++ b/devices/common/pci/bandit.cpp @@ -196,7 +196,8 @@ 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, flip_sized(value, size) + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + size * 2, BYTESWAP_SIZED(value, size) ); return; } @@ -208,7 +209,8 @@ 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, flip_sized(value, size) + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + size * 2, BYTESWAP_SIZED(value, size) ); return; } @@ -225,7 +227,8 @@ 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, flip_sized(value, size) + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + size * 2, BYTESWAP_SIZED(value, size) ); } } else { @@ -358,7 +361,8 @@ 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, flip_sized(value, size) + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + size * 2, BYTESWAP_SIZED(value, size) ); return; } @@ -370,7 +374,8 @@ 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, flip_sized(value, size) + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + size * 2, BYTESWAP_SIZED(value, size) ); return; } @@ -382,7 +387,8 @@ 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, flip_sized(value, size) + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + size * 2, BYTESWAP_SIZED(value, size) ); } } else { diff --git a/devices/common/pci/pcidevice.cpp b/devices/common/pci/pcidevice.cpp index 9148e6a..0570dbe 100644 --- a/devices/common/pci/pcidevice.cpp +++ b/devices/common/pci/pcidevice.cpp @@ -156,7 +156,8 @@ 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, flip_sized(value, size) + size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, + size * 2, BYTESWAP_SIZED(value, size) ); } } @@ -216,10 +217,12 @@ int PCIDevice::attach_exp_rom_image(const std::string img_path) memset(&this->exp_rom_data[exp_rom_image_size], 0xff, this->exp_rom_size - exp_rom_image_size); if (exp_rom_image_size == this->exp_rom_size) { - LOG_F(INFO, "%s: loaded expansion rom (%d bytes).", this->pci_name.c_str(), this->exp_rom_size); + LOG_F(INFO, "%s: loaded expansion rom (%d bytes).", + this->pci_name.c_str(), this->exp_rom_size); } else { - LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).", this->pci_name.c_str(), exp_rom_image_size, this->exp_rom_size); + LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).", + this->pci_name.c_str(), exp_rom_image_size, this->exp_rom_size); } this->exp_bar_cfg = ~(this->exp_rom_size - 1); diff --git a/devices/memctrl/mpc106.cpp b/devices/memctrl/mpc106.cpp index 3c85aef..dc9eb89 100644 --- a/devices/memctrl/mpc106.cpp +++ b/devices/memctrl/mpc106.cpp @@ -169,7 +169,7 @@ 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, flip_sized(value, size) + size * 2, BYTESWAP_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, flip_sized(value, size) + size * 2, BYTESWAP_SIZED(value, size) ); } } diff --git a/endianswap.h b/endianswap.h index 1f3e1d7..024ec1d 100644 --- a/endianswap.h +++ b/endianswap.h @@ -69,4 +69,7 @@ along with this program. If not, see . #endif +#define BYTESWAP_SIZED(val, size) \ + (size) == 2 ? BYTESWAP_16((val)) : ((size) == 4 ? BYTESWAP_32((val)) : (val)) + #endif /* ENDIAN_SWAP_H */ diff --git a/memaccess.h b/memaccess.h index 9f2d81b..46bc60c 100644 --- a/memaccess.h +++ b/memaccess.h @@ -177,15 +177,6 @@ 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. */