Skip to contentSkip to conversation

Various fixes for hppa architecture

PATCH Superseded Helge Deller 3 participants 10 messages Jul 27, 2020 – Aug 1, 2020

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Various fixes for hppa architecture

This patch series fixes a few issues with the hppa emulation:

* The artist framebuffer emulation reports:
"write outside bounds: wants 1256x1023, max size 1280x1024" This is fixed by a patch from Sven Schnelle.

* Fix a SeaBIOS hppa compilation issue with gcc-10.

* Implement a proper SeaBIOS firmware version check to prevent incompatibility issues between emulation and firmware.

* The hppa_hardware.h file is shared with SeaBIOS. Sync it.

The series can be pulled from the fw_cfg-3 branch at:
https://github.com/hdeller/qemu-hppa.git fw_cfg-3

Helge

Helge Deller (3):
hw/hppa: Sync hppa_hardware.h file with SeaBIOS sources
seabios-hppa: Update to SeaBIOS hppa version 1 hw/hppa: Implement proper SeaBIOS version check

Sven Schnelle (1):
hw/display/artist.c: fix out of bounds check

 hw/display/artist.c       |  18 ++++++------------
 hw/hppa/hppa_hardware.h   |   6 ++++++
 hw/hppa/lasi.c            |   2 --
 hw/hppa/machine.c         |  22 ++++++++++++++++++++++
 pc-bios/hppa-firmware.img | Bin 766136 -> 783144 bytes
 roms/seabios-hppa         |   2 +-
 6 files changed, 35 insertions(+), 15 deletions(-)

--
2.21.3

#1 lore raw

PATCH 1/4 hw/hppa: Sync hppa_hardware.h file with SeaBIOS sources

The hppa_hardware.h file is shared with SeaBIOS. Sync it.

---
 hw/hppa/hppa_hardware.h | 6 ++++++
 hw/hppa/lasi.c          | 2 --
 2 files changed, 6 insertions(+), 2 deletions(-)
hw/hppa/hppa_hardware.h +6 -0
index 4a2fe2df60..cdb7fa6240 100644
@@ -17,6 +17,7 @@
 #define LASI_UART_HPA   0xffd05000
 #define LASI_SCSI_HPA   0xffd06000
 #define LASI_LAN_HPA    0xffd07000
+#define LASI_RTC_HPA    0xffd09000
 #define LASI_LPT_HPA    0xffd02000
 #define LASI_AUDIO_HPA  0xffd04000
 #define LASI_PS2KBD_HPA 0xffd08000
@@ -37,10 +38,15 @@
 #define PORT_PCI_CMD    (PCI_HPA + DINO_PCI_ADDR)
 #define PORT_PCI_DATA   (PCI_HPA + DINO_CONFIG_DATA)
 
+/* QEMU fw_cfg interface port */
+#define QEMU_FW_CFG_IO_BASE     (MEMORY_HPA + 0x80)
+
 #define PORT_SERIAL1    (DINO_UART_HPA + 0x800)
 #define PORT_SERIAL2    (LASI_UART_HPA + 0x800)
 
 #define HPPA_MAX_CPUS   8       /* max. number of SMP CPUs */
 #define CPU_CLOCK_MHZ   250     /* emulate a 250 MHz CPU */
 
+#define CPU_HPA_CR_REG  7       /* store CPU HPA in cr7 (SeaBIOS internal) */
+
 #endif
hw/hppa/lasi.c +0 -2
index 19974034f3..ffcbb988b8 100644
@@ -54,8 +54,6 @@
 #define LASI_CHIP(obj) \
     OBJECT_CHECK(LasiState, (obj), TYPE_LASI_CHIP)
 
-#define LASI_RTC_HPA    (LASI_HPA + 0x9000)
-
 typedef struct LasiState {
     PCIHostState parent_obj;
 

--
2.21.3

#3 lore raw

Re: [PATCH 1/4] hw/hppa: Sync hppa_hardware.h file with SeaBIOS sources

In reply to Helge Deller
Quoted 13 lines · Helge Deller

The hppa_hardware.h file is shared with SeaBIOS. Sync it.

---
 hw/hppa/hppa_hardware.h | 6 ++++++
 hw/hppa/lasi.c          | 2 --
 2 files changed, 6 insertions(+), 2 deletions(-)
hw/hppa/hppa_hardware.h +0 -0
index 4a2fe2df60..cdb7fa6240 100644

hw/hppa/hppa_hardware.h line 20

Quoted 4 lines
hw/hppa/hppa_hardware.h +1 -0
@@ -17,6 +17,7 @@
 #define LASI_UART_HPA   0xffd05000
 #define LASI_SCSI_HPA   0xffd06000
 #define LASI_LAN_HPA    0xffd07000
+#define LASI_RTC_HPA    0xffd09000

I find the line you are removing cleaner:

-#define LASI_RTC_HPA (LASI_HPA + 0x9000)

"Offset in the LASI memory region".

Anyway not a blocker.

Having these values sorted would help.

Quoted 36 lines
hw/hppa/hppa_hardware.h +5 -0
 #define LASI_LPT_HPA    0xffd02000
 #define LASI_AUDIO_HPA  0xffd04000
 #define LASI_PS2KBD_HPA 0xffd08000
@@ -37,10 +38,15 @@
 #define PORT_PCI_CMD    (PCI_HPA + DINO_PCI_ADDR)
 #define PORT_PCI_DATA   (PCI_HPA + DINO_CONFIG_DATA)
 
+/* QEMU fw_cfg interface port */
+#define QEMU_FW_CFG_IO_BASE     (MEMORY_HPA + 0x80)
+
 #define PORT_SERIAL1    (DINO_UART_HPA + 0x800)
 #define PORT_SERIAL2    (LASI_UART_HPA + 0x800)
 
 #define HPPA_MAX_CPUS   8       /* max. number of SMP CPUs */
 #define CPU_CLOCK_MHZ   250     /* emulate a 250 MHz CPU */
 
+#define CPU_HPA_CR_REG  7       /* store CPU HPA in cr7 (SeaBIOS internal) */
+
 #endif
hw/hppa/lasi.c +0 -3
index 19974034f3..ffcbb988b8 100644
@@ -54,8 +54,6 @@
 #define LASI_CHIP(obj) \
     OBJECT_CHECK(LasiState, (obj), TYPE_LASI_CHIP)
 
-#define LASI_RTC_HPA    (LASI_HPA + 0x9000)
-
 typedef struct LasiState {
     PCIHostState parent_obj;
 
--

2.21.3

#4 lore raw

Re: [PATCH 1/4] hw/hppa: Sync hppa_hardware.h file with SeaBIOS sources

Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Helge Deller

The hppa_hardware.h file is shared with SeaBIOS. Sync it.

---
 hw/hppa/hppa_hardware.h | 6 ++++++
 hw/hppa/lasi.c          | 2 --
 2 files changed, 6 insertions(+), 2 deletions(-)
Quoted 12 lines

hw/hppa/hppa_hardware.h line 20

Quoted 9 lines
hw/hppa/hppa_hardware.h +1 -0
index 4a2fe2df60..cdb7fa6240 100644
@@ -17,6 +17,7 @@
 #define LASI_UART_HPA   0xffd05000
 #define LASI_SCSI_HPA   0xffd06000
 #define LASI_LAN_HPA    0xffd07000
+#define LASI_RTC_HPA    0xffd09000

I find the line you are removing cleaner:
-#define LASI_RTC_HPA (LASI_HPA + 0x9000)

Yes, but at least temporarily it should be consistent inside the header file.

Quoted 3 lines

"Offset in the LASI memory region".

Anyway not a blocker.

Ok, thanks!

Helge

Quoted 39 lines

Having these values sorted would help.

Quoted 36 lines
hw/hppa/hppa_hardware.h +5 -0
 #define LASI_LPT_HPA    0xffd02000
 #define LASI_AUDIO_HPA  0xffd04000
 #define LASI_PS2KBD_HPA 0xffd08000
@@ -37,10 +38,15 @@
 #define PORT_PCI_CMD    (PCI_HPA + DINO_PCI_ADDR)
 #define PORT_PCI_DATA   (PCI_HPA + DINO_CONFIG_DATA)
 
+/* QEMU fw_cfg interface port */
+#define QEMU_FW_CFG_IO_BASE     (MEMORY_HPA + 0x80)
+
 #define PORT_SERIAL1    (DINO_UART_HPA + 0x800)
 #define PORT_SERIAL2    (LASI_UART_HPA + 0x800)
 
 #define HPPA_MAX_CPUS   8       /* max. number of SMP CPUs */
 #define CPU_CLOCK_MHZ   250     /* emulate a 250 MHz CPU */
 
+#define CPU_HPA_CR_REG  7       /* store CPU HPA in cr7 (SeaBIOS internal) */
+
 #endif
hw/hppa/lasi.c +0 -3
index 19974034f3..ffcbb988b8 100644
@@ -54,8 +54,6 @@
 #define LASI_CHIP(obj) \
     OBJECT_CHECK(LasiState, (obj), TYPE_LASI_CHIP)
 
-#define LASI_RTC_HPA    (LASI_HPA + 0x9000)
-
 typedef struct LasiState {
     PCIHostState parent_obj;
 
--

2.21.3

#5 lore raw

PATCH 2/4 seabios-hppa: Update to SeaBIOS hppa version 1

In reply to Helge Deller

Changes include:
* Introduce SeaBIOS firmware version check
* Implement QEMU fw_cfg interface support
* Fix endian bug in romfile_loadint()
* gcc-10 compile fix

Required for proper version checking and gcc-10 update on Debian.

---
 pc-bios/hppa-firmware.img | Bin 766136 -> 783144 bytes
 roms/seabios-hppa         |   2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
pc-bios/hppa-firmware.img binary +0 -0
index 82d98b13536cdc9830edfec5caa33bc5b09ca912..eb11ca12f60453c3b43562853a8a19ca9a30dfcb 100644
GIT binary patch
roms/seabios-hppa +1 -1
index 1630ac7d65..004258352c 160000
@@ -1 +1 @@
-Subproject commit 1630ac7d65c4a09218cc677f1fa56cd5b3140447
+Subproject commit 004258352cd89a30367ccc97f8a0a30f92e42717

--
2.21.3

#6 lore raw

PATCH 3/4 hw/hppa: Implement proper SeaBIOS version check

In reply to Helge Deller

It's important that the SeaBIOS hppa firmware is at least at a minimal level to ensure proper interaction between qemu and firmware.

Implement a proper firmware version check by telling SeaBIOS via the fw_cfg interface which minimal SeaBIOS version is required by this running qemu instance. If the firmware detects that it's too old, it will stop.

---
 hw/hppa/machine.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
hw/hppa/machine.c +22 -0
index 49155537cd..90aeefe2a4 100644
@@ -25,6 +25,8 @@
 
 #define MAX_IDE_BUS 2
 
+#define MIN_SEABIOS_HPPA_VERSION 1 /* require at least this fw version */
+
 static ISABus *hppa_isa_bus(void)
 {
     ISABus *isa_bus;
@@ -56,6 +58,23 @@ static uint64_t cpu_hppa_to_phys(void *opaque, uint64_t addr)
 static HPPACPU *cpu[HPPA_MAX_CPUS];
 static uint64_t firmware_entry;
 
+static FWCfgState *create_fw_cfg(MachineState *ms)
+{
+    FWCfgState *fw_cfg;
+    uint64_t val;
+
+    fw_cfg = fw_cfg_init_mem(QEMU_FW_CFG_IO_BASE, QEMU_FW_CFG_IO_BASE + 4);
+    fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, ms->smp.cpus);
+    fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, HPPA_MAX_CPUS);
+    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, ram_size);
+
+    val = cpu_to_le64(MIN_SEABIOS_HPPA_VERSION);
+    fw_cfg_add_file(fw_cfg, "/etc/firmware-min-version",
+                    g_memdup(&val, sizeof(val)), sizeof(val));
+
+    return fw_cfg;
+}
+
 static void machine_hppa_init(MachineState *machine)
 {
     const char *kernel_filename = machine->kernel_filename;
@@ -118,6 +137,9 @@ static void machine_hppa_init(MachineState *machine)
                        115200, serial_hd(0), DEVICE_BIG_ENDIAN);
     }
 
+    /* fw_cfg configuration interface */
+    create_fw_cfg(machine);
+
     /* SCSI disk setup. */
     dev = DEVICE(pci_create_simple(pci_bus, -1, "lsi53c895a"));
     lsi53c8xx_handle_legacy_cmdline(dev);

--
2.21.3

#7 lore raw

PATCH 4/4 hw/display/artist.c: fix out of bounds check

In reply to Helge Deller

From: Sven Schnelle <[email protected]>

---
 hw/display/artist.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
hw/display/artist.c +6 -12
index 6261bfe65b..46043ec895 100644
@@ -340,14 +340,13 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
 {
     struct vram_buffer *buf;
     uint32_t vram_bitmask = s->vram_bitmask;
-    int mask, i, pix_count, pix_length, offset, height, width;
+    int mask, i, pix_count, pix_length, offset, width;
     uint8_t *data8, *p;
 
     pix_count = vram_write_pix_per_transfer(s);
     pix_length = vram_pixel_length(s);
 
     buf = vram_write_buffer(s);
-    height = buf->height;
     width = buf->width;
 
     if (s->cmap_bm_access) {
@@ -367,20 +366,13 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
         pix_count = size * 8;
     }
 
-    if (posy * width + posx + pix_count > buf->size) {
-        qemu_log("write outside bounds: wants %dx%d, max size %dx%d\n",
-                 posx, posy, width, height);
-        return;
-    }
-
-
     switch (pix_length) {
     case 0:
         if (s->image_bitmap_op & 0x20000000) {
             data &= vram_bitmask;
         }
 
-        for (i = 0; i < pix_count; i++) {
+        for (i = 0; i < pix_count && offset + i < buf->size; i++) {
             artist_rop8(s, p + offset + pix_count - 1 - i,
                         (data & 1) ? (s->plane_mask >> 24) : 0);
             data >>= 1;
@@ -398,7 +390,9 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
         for (i = 3; i >= 0; i--) {
             if (!(s->image_bitmap_op & 0x20000000) ||
                 s->vram_bitmask & (1 << (28 + i))) {
-                artist_rop8(s, p + offset + 3 - i, data8[ROP8OFF(i)]);
+                if (offset + 3 - i < buf->size) {
+                    artist_rop8(s, p + offset + 3 - i, data8[ROP8OFF(i)]);
+                }
             }
         }
         memory_region_set_dirty(&buf->mr, offset, 3);
@@ -420,7 +414,7 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
             break;
         }
 
-        for (i = 0; i < pix_count; i++) {
+        for (i = 0; i < pix_count && offset + i < buf->size; i++) {
             mask = 1 << (pix_count - 1 - i);
 
             if (!(s->image_bitmap_op & 0x20000000) ||

--
2.21.3

#8 lore raw

Re: [PATCH 4/4] hw/display/artist.c: fix out of bounds check

hw/display/artist.c static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x, · line 378

Quoted 5 lines · Helge Deller
hw/display/artist.c +1 -1
-        for (i = 0; i < pix_count; i++) {
+        for (i = 0; i < pix_count && offset + i < buf->size; i++) {
             artist_rop8(s, p + offset + pix_count - 1 - i,
                         (data & 1) ? (s->plane_mask >> 24) : 0);
             data >>= 1;

This doesn't look right.

You're writing to "offset + pix_count - 1 - i" and yet you're checking bounds vs "offset + i".

This could be fixed by computing the complete offset into a local variable and then have an inner if to avoid the write, as you do for the second loop.

But it would be better to precompute the correct loop bounds.

r~

Quoted 20 lines
hw/display/artist.c +4 -2
@@ -398,7 +390,9 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
         for (i = 3; i >= 0; i--) {
             if (!(s->image_bitmap_op & 0x20000000) ||
                 s->vram_bitmask & (1 << (28 + i))) {
-                artist_rop8(s, p + offset + 3 - i, data8[ROP8OFF(i)]);
+                if (offset + 3 - i < buf->size) {
+                    artist_rop8(s, p + offset + 3 - i, data8[ROP8OFF(i)]);
+                }
             }
         }
         memory_region_set_dirty(&buf->mr, offset, 3);
@@ -420,7 +414,7 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
             break;
         }
 
-        for (i = 0; i < pix_count; i++) {
+        for (i = 0; i < pix_count && offset + i < buf->size; i++) {
             mask = 1 << (pix_count - 1 - i);
 
             if (!(s->image_bitmap_op & 0x20000000) ||
#9 lore raw

Re: [PATCH 4/4] hw/display/artist.c: fix out of bounds check

Quoted 9 lines · Richard Henderson

hw/display/artist.c static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x, · line 378

Quoted 5 lines · Helge Deller
hw/display/artist.c +1 -1
-        for (i = 0; i < pix_count; i++) {
+        for (i = 0; i < pix_count && offset + i < buf->size; i++) {
             artist_rop8(s, p + offset + pix_count - 1 - i,
                         (data & 1) ? (s->plane_mask >> 24) : 0);
             data >>= 1;

This doesn't look right.

Quoted 7 lines

You're writing to "offset + pix_count - 1 - i" and yet you're checking bounds vs "offset + i".

This could be fixed by computing the complete offset into a local variable and then have an inner if to avoid the write, as you do for the second loop.

But it would be better to precompute the correct loop bounds.

Thanks for the feedback.
Will send out a revised version soon.

Helge

Quoted 24 lines

r~

Quoted 20 lines
hw/display/artist.c +4 -2
@@ -398,7 +390,9 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
         for (i = 3; i >= 0; i--) {
             if (!(s->image_bitmap_op & 0x20000000) ||
                 s->vram_bitmask & (1 << (28 + i))) {
-                artist_rop8(s, p + offset + 3 - i, data8[ROP8OFF(i)]);
+                if (offset + 3 - i < buf->size) {
+                    artist_rop8(s, p + offset + 3 - i, data8[ROP8OFF(i)]);
+                }
             }
         }
         memory_region_set_dirty(&buf->mr, offset, 3);
@@ -420,7 +414,7 @@ static void vram_bit_write(ARTISTState *s, int posx, int posy, bool incr_x,
             break;
         }
 
-        for (i = 0; i < pix_count; i++) {
+        for (i = 0; i < pix_count && offset + i < buf->size; i++) {
             mask = 1 << (pix_count - 1 - i);
 
             if (!(s->image_bitmap_op & 0x20000000) ||