提交 54f7b4a3 编写于 作者: S Stefan Weil 提交者: Aurelien Jarno

Replace cpu_physical_memory_rw were possible

Using cpu_physical_memory_read, cpu_physical_memory_write and ldub_phys
improves readability and allows removing some type casts.

lduw_phys and ldl_phys were not used because both require aligned
addresses. Therefore it is not possible to simply replace existing
calls by one of these functions.
Signed-off-by: NStefan Weil <weil@mail.berlios.de>
Signed-off-by: NAurelien Jarno <aurelien@aurel32.net>
上级 b8b79323
...@@ -345,7 +345,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length, ...@@ -345,7 +345,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int length,
struct disassemble_info *info) struct disassemble_info *info)
{ {
if (monitor_disas_is_physical) { if (monitor_disas_is_physical) {
cpu_physical_memory_rw(memaddr, myaddr, length, 0); cpu_physical_memory_read(memaddr, myaddr, length);
} else { } else {
cpu_memory_rw_debug(monitor_disas_env, memaddr,myaddr, length, 0); cpu_memory_rw_debug(monitor_disas_env, memaddr,myaddr, length, 0);
} }
......
...@@ -3932,7 +3932,7 @@ void *cpu_physical_memory_map(target_phys_addr_t addr, ...@@ -3932,7 +3932,7 @@ void *cpu_physical_memory_map(target_phys_addr_t addr,
bounce.addr = addr; bounce.addr = addr;
bounce.len = l; bounce.len = l;
if (!is_write) { if (!is_write) {
cpu_physical_memory_rw(addr, bounce.buffer, l, 0); cpu_physical_memory_read(addr, bounce.buffer, l);
} }
ptr = bounce.buffer; ptr = bounce.buffer;
} else { } else {
......
...@@ -307,7 +307,7 @@ static void rc4030_writel(void *opaque, target_phys_addr_t addr, uint32_t val) ...@@ -307,7 +307,7 @@ static void rc4030_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
if (s->cache_ltag == 0x80000001 && s->cache_bmask == 0xf0f0f0f) { if (s->cache_ltag == 0x80000001 && s->cache_bmask == 0xf0f0f0f) {
target_phys_addr_t dest = s->cache_ptag & ~0x1; target_phys_addr_t dest = s->cache_ptag & ~0x1;
dest += (s->cache_maint & 0x3) << 3; dest += (s->cache_maint & 0x3) << 3;
cpu_physical_memory_rw(dest, (uint8_t*)&val, 4, 1); cpu_physical_memory_write(dest, &val, 4);
} }
break; break;
/* Remote Speed Registers */ /* Remote Speed Registers */
...@@ -704,7 +704,7 @@ void rc4030_dma_memory_rw(void *opaque, target_phys_addr_t addr, uint8_t *buf, i ...@@ -704,7 +704,7 @@ void rc4030_dma_memory_rw(void *opaque, target_phys_addr_t addr, uint8_t *buf, i
entry_addr = s->dma_tl_base + index * sizeof(dma_pagetable_entry); entry_addr = s->dma_tl_base + index * sizeof(dma_pagetable_entry);
/* XXX: not sure. should we really use only lowest bits? */ /* XXX: not sure. should we really use only lowest bits? */
entry_addr &= 0x7fffffff; entry_addr &= 0x7fffffff;
cpu_physical_memory_rw(entry_addr, (uint8_t *)&entry, sizeof(entry), 0); cpu_physical_memory_read(entry_addr, &entry, sizeof(entry));
/* Read/write data at right place */ /* Read/write data at right place */
phys_addr = entry.frame + (addr & (DMA_PAGESIZE - 1)); phys_addr = entry.frame + (addr & (DMA_PAGESIZE - 1));
......
...@@ -233,7 +233,8 @@ void s390_virtio_device_sync(VirtIOS390Device *dev) ...@@ -233,7 +233,8 @@ void s390_virtio_device_sync(VirtIOS390Device *dev)
dev->vdev->get_config(dev->vdev, dev->vdev->config); dev->vdev->get_config(dev->vdev, dev->vdev->config);
} }
cpu_physical_memory_rw(cur_offs, dev->vdev->config, dev->vdev->config_len, 1); cpu_physical_memory_write(cur_offs,
dev->vdev->config, dev->vdev->config_len);
cur_offs += dev->vdev->config_len; cur_offs += dev->vdev->config_len;
} }
......
...@@ -230,8 +230,8 @@ static void s390_init(ram_addr_t ram_size, ...@@ -230,8 +230,8 @@ static void s390_init(ram_addr_t ram_size,
} }
if (kernel_cmdline) { if (kernel_cmdline) {
cpu_physical_memory_rw(KERN_PARM_AREA, (uint8_t *)kernel_cmdline, cpu_physical_memory_write(KERN_PARM_AREA, kernel_cmdline,
strlen(kernel_cmdline), 1); strlen(kernel_cmdline));
} }
/* Create VirtIO network adapters */ /* Create VirtIO network adapters */
......
...@@ -120,7 +120,7 @@ static void glue(draw_hwc_line_, PIXEL_NAME)(SM501State * s, int crt, ...@@ -120,7 +120,7 @@ static void glue(draw_hwc_line_, PIXEL_NAME)(SM501State * s, int crt,
/* get pixel value */ /* get pixel value */
if (i % 4 == 0) { if (i % 4 == 0) {
cpu_physical_memory_rw(cursor_addr, &bitset, 1, 0); bitset = ldub_phys(cursor_addr);
cursor_addr++; cursor_addr++;
} }
v = bitset & 3; v = bitset & 3;
......
...@@ -427,7 +427,7 @@ static inline int get_dwords(OHCIState *ohci, ...@@ -427,7 +427,7 @@ static inline int get_dwords(OHCIState *ohci,
addr += ohci->localmem_base; addr += ohci->localmem_base;
for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0); cpu_physical_memory_read(addr, buf, sizeof(*buf));
*buf = le32_to_cpu(*buf); *buf = le32_to_cpu(*buf);
} }
...@@ -444,7 +444,7 @@ static inline int put_dwords(OHCIState *ohci, ...@@ -444,7 +444,7 @@ static inline int put_dwords(OHCIState *ohci,
for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
uint32_t tmp = cpu_to_le32(*buf); uint32_t tmp = cpu_to_le32(*buf);
cpu_physical_memory_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1); cpu_physical_memory_write(addr, &tmp, sizeof(tmp));
} }
return 1; return 1;
...@@ -459,7 +459,7 @@ static inline int get_words(OHCIState *ohci, ...@@ -459,7 +459,7 @@ static inline int get_words(OHCIState *ohci,
addr += ohci->localmem_base; addr += ohci->localmem_base;
for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
cpu_physical_memory_rw(addr, (uint8_t *)buf, sizeof(*buf), 0); cpu_physical_memory_read(addr, buf, sizeof(*buf));
*buf = le16_to_cpu(*buf); *buf = le16_to_cpu(*buf);
} }
...@@ -476,7 +476,7 @@ static inline int put_words(OHCIState *ohci, ...@@ -476,7 +476,7 @@ static inline int put_words(OHCIState *ohci,
for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) { for (i = 0; i < num; i++, buf++, addr += sizeof(*buf)) {
uint16_t tmp = cpu_to_le16(*buf); uint16_t tmp = cpu_to_le16(*buf);
cpu_physical_memory_rw(addr, (uint8_t *)&tmp, sizeof(tmp), 1); cpu_physical_memory_write(addr, &tmp, sizeof(tmp));
} }
return 1; return 1;
...@@ -504,8 +504,7 @@ static inline int ohci_read_iso_td(OHCIState *ohci, ...@@ -504,8 +504,7 @@ static inline int ohci_read_iso_td(OHCIState *ohci,
static inline int ohci_read_hcca(OHCIState *ohci, static inline int ohci_read_hcca(OHCIState *ohci,
uint32_t addr, struct ohci_hcca *hcca) uint32_t addr, struct ohci_hcca *hcca)
{ {
cpu_physical_memory_rw(addr + ohci->localmem_base, cpu_physical_memory_read(addr + ohci->localmem_base, hcca, sizeof(*hcca));
(uint8_t *)hcca, sizeof(*hcca), 0);
return 1; return 1;
} }
...@@ -531,8 +530,7 @@ static inline int ohci_put_iso_td(OHCIState *ohci, ...@@ -531,8 +530,7 @@ static inline int ohci_put_iso_td(OHCIState *ohci,
static inline int ohci_put_hcca(OHCIState *ohci, static inline int ohci_put_hcca(OHCIState *ohci,
uint32_t addr, struct ohci_hcca *hcca) uint32_t addr, struct ohci_hcca *hcca)
{ {
cpu_physical_memory_rw(addr + ohci->localmem_base, cpu_physical_memory_write(addr + ohci->localmem_base, hcca, sizeof(*hcca));
(uint8_t *)hcca, sizeof(*hcca), 1);
return 1; return 1;
} }
......
...@@ -1429,7 +1429,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, ...@@ -1429,7 +1429,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
if (l > line_size) if (l > line_size)
l = line_size; l = line_size;
if (is_physical) { if (is_physical) {
cpu_physical_memory_rw(addr, buf, l, 0); cpu_physical_memory_read(addr, buf, l);
} else { } else {
env = mon_get_cpu(); env = mon_get_cpu();
if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) { if (cpu_memory_rw_debug(env, addr, buf, l, 0) < 0) {
...@@ -1605,7 +1605,7 @@ static int do_physical_memory_save(Monitor *mon, const QDict *qdict, ...@@ -1605,7 +1605,7 @@ static int do_physical_memory_save(Monitor *mon, const QDict *qdict,
l = sizeof(buf); l = sizeof(buf);
if (l > size) if (l > size)
l = size; l = size;
cpu_physical_memory_rw(addr, buf, l, 0); cpu_physical_memory_read(addr, buf, l);
if (fwrite(buf, 1, l, f) != l) { if (fwrite(buf, 1, l, f) != l) {
monitor_printf(mon, "fwrite() error in do_physical_memory_save\n"); monitor_printf(mon, "fwrite() error in do_physical_memory_save\n");
goto exit; goto exit;
...@@ -1625,17 +1625,16 @@ exit: ...@@ -1625,17 +1625,16 @@ exit:
static void do_sum(Monitor *mon, const QDict *qdict) static void do_sum(Monitor *mon, const QDict *qdict)
{ {
uint32_t addr; uint32_t addr;
uint8_t buf[1];
uint16_t sum; uint16_t sum;
uint32_t start = qdict_get_int(qdict, "start"); uint32_t start = qdict_get_int(qdict, "start");
uint32_t size = qdict_get_int(qdict, "size"); uint32_t size = qdict_get_int(qdict, "size");
sum = 0; sum = 0;
for(addr = start; addr < (start + size); addr++) { for(addr = start; addr < (start + size); addr++) {
cpu_physical_memory_rw(addr, buf, 1, 0); uint8_t val = ldub_phys(addr);
/* BSD sum algorithm ('sum' Unix command) */ /* BSD sum algorithm ('sum' Unix command) */
sum = (sum >> 1) | (sum << 15); sum = (sum >> 1) | (sum << 15);
sum += buf[0]; sum += val;
} }
monitor_printf(mon, "%05d\n", sum); monitor_printf(mon, "%05d\n", sum);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册