}
}
+static void memory_region_read_accessor(void *opaque,
+ target_phys_addr_t addr,
+ uint64_t *value,
+ unsigned size,
+ unsigned shift,
+ uint64_t mask)
+{
+ MemoryRegion *mr = opaque;
+ uint64_t tmp;
+
+ tmp = mr->ops->read(mr->opaque, addr, size);
+ *value |= (tmp & mask) << shift;
+}
+
+static void memory_region_write_accessor(void *opaque,
+ target_phys_addr_t addr,
+ uint64_t *value,
+ unsigned size,
+ unsigned shift,
+ uint64_t mask)
+{
+ MemoryRegion *mr = opaque;
+ uint64_t tmp;
+
+ tmp = (*value >> shift) & mask;
+ mr->ops->write(mr->opaque, addr, tmp, size);
+}
+
+static void access_with_adjusted_size(target_phys_addr_t addr,
+ uint64_t *value,
+ unsigned size,
+ unsigned access_size_min,
+ unsigned access_size_max,
+ void (*access)(void *opaque,
+ target_phys_addr_t addr,
+ uint64_t *value,
+ unsigned size,
+ unsigned shift,
+ uint64_t mask),
+ void *opaque)
+{
+ uint64_t access_mask;
+ unsigned access_size;
+ unsigned i;
+
+ if (!access_size_min) {
+ access_size_min = 1;
+ }
+ if (!access_size_max) {
+ access_size_max = 4;
+ }
+ access_size = MAX(MIN(size, access_size_max), access_size_min);
+ access_mask = -1ULL >> (64 - access_size * 8);
+ for (i = 0; i < size; i += access_size) {
+ /* FIXME: big-endian support */
+ access(opaque, addr + i, value, access_size, i * 8, access_mask);
+ }
+}
+
static void memory_region_prepare_ram_addr(MemoryRegion *mr);
static void as_memory_range_add(AddressSpace *as, FlatRange *fr)
unsigned size)
{
MemoryRegion *mr = _mr;
- unsigned access_size, access_size_min, access_size_max;
- uint64_t access_mask;
- uint32_t data = 0, tmp;
- unsigned i;
+ uint64_t data = 0;
if (!memory_region_access_valid(mr, addr, size)) {
return -1U; /* FIXME: better signalling */
}
/* FIXME: support unaligned access */
-
- access_size_min = mr->ops->impl.min_access_size;
- if (!access_size_min) {
- access_size_min = 1;
- }
- access_size_max = mr->ops->impl.max_access_size;
- if (!access_size_max) {
- access_size_max = 4;
- }
- access_size = MAX(MIN(size, access_size_max), access_size_min);
- access_mask = -1ULL >> (64 - access_size * 8);
- addr += mr->offset;
- for (i = 0; i < size; i += access_size) {
- /* FIXME: big-endian support */
- tmp = mr->ops->read(mr->opaque, addr + i, access_size);
- data |= (tmp & access_mask) << (i * 8);
- }
+ access_with_adjusted_size(addr + mr->offset, &data, size,
+ mr->ops->impl.min_access_size,
+ mr->ops->impl.max_access_size,
+ memory_region_read_accessor, mr);
return data;
}
uint64_t data)
{
MemoryRegion *mr = _mr;
- unsigned access_size, access_size_min, access_size_max;
- uint64_t access_mask;
- unsigned i;
if (!memory_region_access_valid(mr, addr, size)) {
return; /* FIXME: better signalling */
}
/* FIXME: support unaligned access */
-
- access_size_min = mr->ops->impl.min_access_size;
- if (!access_size_min) {
- access_size_min = 1;
- }
- access_size_max = mr->ops->impl.max_access_size;
- if (!access_size_max) {
- access_size_max = 4;
- }
- access_size = MAX(MIN(size, access_size_max), access_size_min);
- access_mask = -1ULL >> (64 - access_size * 8);
- addr += mr->offset;
- for (i = 0; i < size; i += access_size) {
- /* FIXME: big-endian support */
- mr->ops->write(mr->opaque, addr + i, (data >> (i * 8)) & access_mask,
- access_size);
- }
+ access_with_adjusted_size(addr + mr->offset, &data, size,
+ mr->ops->impl.min_access_size,
+ mr->ops->impl.max_access_size,
+ memory_region_write_accessor, mr);
}
static uint32_t memory_region_read_thunk_b(void *mr, target_phys_addr_t addr)