Patchwork [32/34] vga: make byte swapping selectable

login
register
mail settings
Submitter Blue Swirl
Date July 22, 2010, 10:03 p.m.
Message ID <AANLkTikRzMBnA9YYYOhINWDqlgDMw-wXFb45_r2wbUu4@mail.gmail.com>
Download mbox | patch
Permalink /patch/59654/
State New
Headers show

Comments

Blue Swirl - July 22, 2010, 10:03 p.m.
Make byte swapping in VGA selectable.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/mips_jazz.c  |    6 +++++-
 hw/pc.h         |    2 +-
 hw/vga-isa-mm.c |    9 ++++++---
 hw/vga-isa.c    |    3 ++-
 hw/vga-pci.c    |    2 +-
 hw/vga.c        |   38 +++++++++++++-------------------------
 hw/vga_int.h    |    2 +-
 hw/vmware_vga.c |    3 ++-
 8 files changed, 31 insertions(+), 34 deletions(-)

     vga_init_vbe(&s->vga);

Patch

diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 71b05a2..3a3635d 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -217,7 +217,11 @@  void mips_jazz_init (ram_addr_t ram_size,
         g364fb_mm_init(0x40000000, 0x60000000, 0, rc4030[3]);
         break;
     case JAZZ_PICA61:
-        isa_vga_mm_init(0x40000000, 0x60000000, 0);
+#ifdef TARGET_WORDS_BIGENDIAN
+        isa_vga_mm_init(0x40000000, 0x60000000, 0, 1);
+#else
+        isa_vga_mm_init(0x40000000, 0x60000000, 0, 0);
+#endif
         break;
     default:
         break;
diff --git a/hw/pc.h b/hw/pc.h
index 63b0249..9ab2695 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -157,7 +157,7 @@  int isa_vga_init(void);
 int pci_vga_init(PCIBus *bus,
                  unsigned long vga_bios_offset, int vga_bios_size);
 int isa_vga_mm_init(target_phys_addr_t vram_base,
-                    target_phys_addr_t ctrl_base, int it_shift);
+                    target_phys_addr_t ctrl_base, int it_shift, int be);

 /* cirrus_vga.c */
 void pci_cirrus_vga_init(PCIBus *bus);
diff --git a/hw/vga-isa-mm.c b/hw/vga-isa-mm.c
index d4b1e95..1840c3e 100644
--- a/hw/vga-isa-mm.c
+++ b/hw/vga-isa-mm.c
@@ -92,13 +92,16 @@  static CPUWriteMemoryFunc * const vga_mm_write_ctrl[] = {
 };

 static void vga_mm_init(ISAVGAMMState *s, target_phys_addr_t vram_base,
-                        target_phys_addr_t ctrl_base, int it_shift)
+                        target_phys_addr_t ctrl_base, int it_shift, int be)
 {
     int s_ioport_ctrl, vga_io_memory;

     s->it_shift = it_shift;
     s_ioport_ctrl = cpu_register_io_memory(vga_mm_read_ctrl,
vga_mm_write_ctrl, s);
     vga_io_memory = cpu_register_io_memory(vga_mem_read, vga_mem_write, s);
+    if (be) {
+        vga_io_memory = cpu_physical_memory_toggle_bswap(vga_io_memory);
+    }

     vmstate_register(NULL, 0, &vmstate_vga_common, s);

@@ -108,14 +111,14 @@  static void vga_mm_init(ISAVGAMMState *s,
target_phys_addr_t vram_base,
 }

 int isa_vga_mm_init(target_phys_addr_t vram_base,
-                    target_phys_addr_t ctrl_base, int it_shift)
+                    target_phys_addr_t ctrl_base, int it_shift, int be)
 {
     ISAVGAMMState *s;

     s = qemu_mallocz(sizeof(*s));

     vga_common_init(&s->vga, VGA_RAM_SIZE);
-    vga_mm_init(s, vram_base, ctrl_base, it_shift);
+    vga_mm_init(s, vram_base, ctrl_base, it_shift, be);

     s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
                                      s->vga.screen_dump,
s->vga.text_update, s);
diff --git a/hw/vga-isa.c b/hw/vga-isa.c
index 3046054..cc99cdf 100644
--- a/hw/vga-isa.c
+++ b/hw/vga-isa.c
@@ -36,7 +36,8 @@  int isa_vga_init(void)
     s = qemu_mallocz(sizeof(*s));

     vga_common_init(s, VGA_RAM_SIZE);
-    vga_init(s);
+    vga_init(s, -1);
+
     vmstate_register(NULL, 0, &vmstate_vga_common, s);

     s->ds = graphic_console_init(s->update, s->invalidate,
diff --git a/hw/vga-pci.c b/hw/vga-pci.c
index 94e3ee0..68fbe36 100644
--- a/hw/vga-pci.c
+++ b/hw/vga-pci.c
@@ -79,7 +79,7 @@  static int pci_vga_initfn(PCIDevice *dev)

      // vga + console init
      vga_common_init(s, VGA_RAM_SIZE);
-     vga_init(s);
+     vga_init(s, -1);

      s->ds = graphic_console_init(s->update, s->invalidate,
                                   s->screen_dump, s->text_update, s);
diff --git a/hw/vga.c b/hw/vga.c
index b612529..d85ccd2 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -767,30 +767,22 @@  uint32_t vga_mem_readb(void *opaque,
target_phys_addr_t addr)
 static uint32_t vga_mem_readw(void *opaque, target_phys_addr_t addr)
 {
     uint32_t v;
-#ifdef TARGET_WORDS_BIGENDIAN
-    v = vga_mem_readb(opaque, addr) << 8;
-    v |= vga_mem_readb(opaque, addr + 1);
-#else
+
     v = vga_mem_readb(opaque, addr);
     v |= vga_mem_readb(opaque, addr + 1) << 8;
-#endif
+
     return v;
 }

 static uint32_t vga_mem_readl(void *opaque, target_phys_addr_t addr)
 {
     uint32_t v;
-#ifdef TARGET_WORDS_BIGENDIAN
-    v = vga_mem_readb(opaque, addr) << 24;
-    v |= vga_mem_readb(opaque, addr + 1) << 16;
-    v |= vga_mem_readb(opaque, addr + 2) << 8;
-    v |= vga_mem_readb(opaque, addr + 3);
-#else
+
     v = vga_mem_readb(opaque, addr);
     v |= vga_mem_readb(opaque, addr + 1) << 8;
     v |= vga_mem_readb(opaque, addr + 2) << 16;
     v |= vga_mem_readb(opaque, addr + 3) << 24;
-#endif
+
     return v;
 }

@@ -931,28 +923,16 @@  void vga_mem_writeb(void *opaque,
target_phys_addr_t addr, uint32_t val)

 static void vga_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
-#ifdef TARGET_WORDS_BIGENDIAN
-    vga_mem_writeb(opaque, addr, (val >> 8) & 0xff);
-    vga_mem_writeb(opaque, addr + 1, val & 0xff);
-#else
     vga_mem_writeb(opaque, addr, val & 0xff);
     vga_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff);
-#endif
 }

 static void vga_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
 {
-#ifdef TARGET_WORDS_BIGENDIAN
-    vga_mem_writeb(opaque, addr, (val >> 24) & 0xff);
-    vga_mem_writeb(opaque, addr + 1, (val >> 16) & 0xff);
-    vga_mem_writeb(opaque, addr + 2, (val >> 8) & 0xff);
-    vga_mem_writeb(opaque, addr + 3, val & 0xff);
-#else
     vga_mem_writeb(opaque, addr, val & 0xff);
     vga_mem_writeb(opaque, addr + 1, (val >> 8) & 0xff);
     vga_mem_writeb(opaque, addr + 2, (val >> 16) & 0xff);
     vga_mem_writeb(opaque, addr + 3, (val >> 24) & 0xff);
-#endif
 }

 typedef void vga_draw_glyph8_func(uint8_t *d, int linesize,
@@ -2287,7 +2267,7 @@  void vga_common_init(VGACommonState *s, int vga_ram_size)
 }

 /* used by both ISA and PCI */
-void vga_init(VGACommonState *s)
+void vga_init(VGACommonState *s, int do_bswap)
 {
     int vga_io_memory;

@@ -2329,6 +2309,14 @@  void vga_init(VGACommonState *s)
 #endif /* CONFIG_BOCHS_VBE */

     vga_io_memory = cpu_register_io_memory(vga_mem_read, vga_mem_write, s);
+
+    if (do_bswap == -1) {
+#ifdef TARGET_WORDS_BIGENDIAN
+        vga_io_memory = cpu_physical_memory_toggle_bswap(vga_io_memory);
+#endif
+    } else if (do_bswap == 1) {
+        vga_io_memory = cpu_physical_memory_toggle_bswap(vga_io_memory);
+    }
     cpu_register_physical_memory(isa_mem_base + 0x000a0000, 0x20000,
                                  vga_io_memory);
     qemu_register_coalesced_mmio(isa_mem_base + 0x000a0000, 0x20000);
diff --git a/hw/vga_int.h b/hw/vga_int.h
index 6a46a43..60af53f 100644
--- a/hw/vga_int.h
+++ b/hw/vga_int.h
@@ -192,7 +192,7 @@  static inline int c6_to_8(int v)
 }

 void vga_common_init(VGACommonState *s, int vga_ram_size);
-void vga_init(VGACommonState *s);
+void vga_init(VGACommonState *s, int do_bswap);
 void vga_common_reset(VGACommonState *s);

 void vga_dirty_log_start(VGACommonState *s);
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index a9ade91..f73f5fa 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1168,7 +1168,8 @@  static void vmsvga_init(struct vmsvga_state_s
*s, int vga_ram_size)
     s->fifo_ptr = qemu_get_ram_ptr(s->fifo_offset);

     vga_common_init(&s->vga, vga_ram_size);
-    vga_init(&s->vga);
+    vga_init(&s->vga, -1);
+
     vmstate_register(NULL, 0, &vmstate_vga_common, &s->vga);