Skip to contentSkip to conversation

MIPS & Co. patches for 2025-07-15

GIT PULL Applied Philippe Mathieu-Daudé 4 participants 23 messages Jul 15, 2025 – Jul 17, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

The following changes since commit 9a4e273ddec3927920c5958d2226c6b38b543336:

Merge tag 'pull-tcg-20250711' of https://gitlab.com/rth7680/qemu into staging (2025-07-13 01:46:04 -0400)

are available in the Git repository at:

https://github.com/philmd/qemu.git tags/mips-20250715

for you to fetch changes up to 6f8ce26bb00db66e6cec632f16df3cd13e4df934:

esp.c: only allow ESP commands permitted in the current asc_mode (2025-07-15 00:25:21 +0200)

----------------------------------------------------------------
MIPS patches queue

- Implement CRC32[c] (Release 6) instructions
- Convert Octeon LX instructions to decodetree
- Restrict ITU to TCG
- Fix ESP issue affecting WinNT (INACCESSIBLE_BOOT_DEVICE BSOD)
- Add missing FDT dependency for some MicroBlaze machines
- Remove execute bit on hppa-firmware blobs

----------------------------------------------------------------

Aleksandar Rakic (1):
tests/tcg/mips: Add tests for MIPS CRC32[c] instructions

Bernhard Beschow (1):
hw/microblaze: Add missing FDT dependency

Cole Robinson (1):
roms: re-remove execute bit from hppa-firmware*

Mark Cave-Ayland (7):
esp.c: only raise IRQ in esp_transfer_data() for CMD_SEL, CMD_SELATN
and CMD_TI commands
esp.c: improve comment in esp_transfer_data()
esp.h: remove separate ESPState typedef
esp.c: only call dma_memory_read function if transfer length is
non-zero
esp.c: only call dma_memory_write function if transfer length is
non-zero
esp.c: add asc_mode property to indicate the current ESP mode esp.c: only allow ESP commands permitted in the current asc_mode

Philippe Mathieu-Daudé (6):
target/mips: Extract gen_base_index_addr() helper target/mips: Extract generic gen_lx() helper
target/mips: Convert Octeon LX instructions to decodetree target/mips: Have gen_[d]lsa() callers add 1 to shift amount argument hw/mips: Restrict ITU to TCG
hw/intc/loongarch_extioi: Remove unnecessary 'qemu/typedefs.h' include

Yongbok Kim (1):
target/mips: Add support for emulation of CRC32 instructions

 include/hw/scsi/esp.h                         |  15 +-
 target/mips/helper.h                          |   2 +
 target/mips/tcg/translate.h                   |   4 +
 tests/tcg/mips/include/wrappers_mips64r6.h    |  32 ++++
 target/mips/tcg/octeon.decode                 |   8 +
 target/mips/tcg/rel6.decode                   |   5 +
 hw/intc/loongarch_extioi_kvm.c                |   1 -
 hw/mips/cps.c                                 |   4 +-
 hw/scsi/esp.c                                 |  94 ++++++++++--
 target/mips/tcg/msa_translate.c               |   4 +-
 target/mips/tcg/octeon_translate.c            |  12 ++
 target/mips/tcg/op_helper.c                   |  26 ++++
 target/mips/tcg/rel6_translate.c              |  16 +-
 target/mips/tcg/translate.c                   | 102 +++++++------
 target/mips/tcg/translate_addr_const.c        |   4 +-
 .../isa/mips64r6/crc/test_mips64r6_crc32b.c   | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32cb.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32cd.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32ch.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32cw.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32d.c   | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32h.c   | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32w.c   | 142 ++++++++++++++++++
 target/mips/cpu-defs.c.inc                    |  10 +-
 target/mips/tcg/micromips_translate.c.inc     |   2 +-
 target/mips/tcg/nanomips_translate.c.inc      |   7 +-
 hw/microblaze/Kconfig                         |   4 +-
 hw/mips/Kconfig                               |   2 +-
 hw/misc/Kconfig                               |   1 +
 hw/scsi/trace-events                          |   1 +
 pc-bios/hppa-firmware.img                     | Bin
 pc-bios/hppa-firmware64.img                   | Bin
 target/mips/meson.build                       |   1 +
 tests/tcg/mips/user/isa/mips64r6/crc/Makefile |  40 +++++
 34 files changed, 1447 insertions(+), 86 deletions(-)
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32b.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cb.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cd.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32ch.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cw.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32d.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32h.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32w.c
 mode change 100755 => 100644 pc-bios/hppa-firmware.img
 mode change 100755 => 100644 pc-bios/hppa-firmware64.img
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/Makefile
Signature · 1 line
2.49.0
#1 lore raw

[PULL 02/17] target/mips: Extract gen_base_index_addr() helper

Factor out gen_base_index_addr() which is used twice but we'll use it more.

Message-Id: <[email protected]>

---
 target/mips/tcg/translate.h |  1 +
 target/mips/tcg/translate.c | 27 +++++++++++++--------------
 2 files changed, 14 insertions(+), 14 deletions(-)
target/mips/tcg/translate.h +1 -0
index 428b53a0dac..e65593815e6 100644
@@ -154,6 +154,7 @@ void check_cp1_registers(DisasContext *ctx, int regs);
 void check_cop1x(DisasContext *ctx);
 
 void gen_base_offset_addr(DisasContext *ctx, TCGv addr, int base, int offset);
+void gen_base_index_addr(DisasContext *ctx, TCGv addr, int base, int index);
 void gen_move_low32(TCGv ret, TCGv_i64 arg);
 void gen_move_high32(TCGv ret, TCGv_i64 arg);
 void gen_load_gpr(TCGv t, int reg);
target/mips/tcg/translate.c +13 -14
index 5c80b030329..8816237e929 100644
@@ -1957,6 +1957,17 @@ void gen_base_offset_addr(DisasContext *ctx, TCGv addr, int base, int offset)
     }
 }
 
+void gen_base_index_addr(DisasContext *ctx, TCGv addr, int base, int index)
+{
+    if (base == 0) {
+        gen_load_gpr(addr, index);
+    } else if (index == 0) {
+        gen_load_gpr(addr, base);
+    } else {
+        gen_op_addr_add(ctx, addr, cpu_gpr[base], cpu_gpr[index]);
+    }
+}
+
 static target_ulong pc_relative_pc(DisasContext *ctx)
 {
     target_ulong pc = ctx->base.pc_next;
@@ -10546,13 +10557,7 @@ static void gen_flt3_ldst(DisasContext *ctx, uint32_t opc,
 {
     TCGv t0 = tcg_temp_new();
 
-    if (base == 0) {
-        gen_load_gpr(t0, index);
-    } else if (index == 0) {
-        gen_load_gpr(t0, base);
-    } else {
-        gen_op_addr_add(ctx, t0, cpu_gpr[base], cpu_gpr[index]);
-    }
+    gen_base_index_addr(ctx, t0, base, index);
     /*
      * Don't do NOP if destination is zero: we must perform the actual
      * memory access.
@@ -11334,13 +11339,7 @@ static void gen_mips_lx(DisasContext *ctx, uint32_t opc,
     }
     t0 = tcg_temp_new();
 
-    if (base == 0) {
-        gen_load_gpr(t0, offset);
-    } else if (offset == 0) {
-        gen_load_gpr(t0, base);
-    } else {
-        gen_op_addr_add(ctx, t0, cpu_gpr[base], cpu_gpr[offset]);
-    }
+    gen_base_index_addr(ctx, t0, base, offset);
 
     switch (opc) {
     case OPC_LBUX:
Signature · 1 line
2.49.0
#2 lore raw

[PULL 04/17] target/mips: Convert Octeon LX instructions to decodetree

In reply to Philippe Mathieu-Daudé

Use Octeon decodetree to call gen_lx() for the LX instructions.

Message-Id: <[email protected]>

---
 target/mips/tcg/octeon.decode      |  8 ++++++++
 target/mips/tcg/octeon_translate.c | 12 ++++++++++++
 target/mips/tcg/translate.c        |  4 +---
 3 files changed, 21 insertions(+), 3 deletions(-)
target/mips/tcg/octeon.decode +8 -0
index 0c787cb498c..102a05860df 100644
@@ -1,6 +1,7 @@
 # Octeon Architecture Module instruction set
 #
 # Copyright (C) 2022 Pavel Dovgalyuk
+# Copyright (C) 2024 Philippe Mathieu-Daudé
 #
 # SPDX-License-Identifier: LGPL-2.1-or-later
 #
@@ -39,3 +40,10 @@ CINS         011100 ..... ..... ..... ..... 11001 . @bitfield
 POP          011100 rs:5 00000 rd:5 00000 10110 dw:1
 SEQNE        011100 rs:5 rt:5 rd:5 00000 10101 ne:1
 SEQNEI       011100 rs:5 rt:5 imm:s10 10111 ne:1
+
+&lx          base index rd
+@lx          ...... base:5 index:5 rd:5 ...... ..... &lx
+LWX          011111 ..... ..... ..... 00000 001010 @lx
+LHX          011111 ..... ..... ..... 00100 001010 @lx
+LBUX         011111 ..... ..... ..... 00110 001010 @lx
+LDX          011111 ..... ..... ..... 01000 001010 @lx
target/mips/tcg/octeon_translate.c +12 -0
index d9eb43716e2..b2eca29e06c 100644
@@ -174,3 +174,15 @@ static bool trans_SEQNEI(DisasContext *ctx, arg_SEQNEI *a)
     }
     return true;
 }
+
+static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)
+{
+    gen_lx(ctx, a->rd, a->base, a->index, mop);
+
+    return true;
+}
+
+TRANS(LBUX, trans_lx, MO_UB);
+TRANS(LHX,  trans_lx, MO_SW);
+TRANS(LWX,  trans_lx, MO_SL);
+TRANS(LDX,  trans_lx, MO_UQ);
target/mips/tcg/translate.c +1 -3
index b9b2d8bb7e1..d91d6efe02c 100644
@@ -13607,9 +13607,7 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx)
         }
         break;
     case OPC_LX_DSP:
-        if (!(ctx->insn_flags & INSN_OCTEON)) {
-            check_dsp(ctx);
-        }
+        check_dsp(ctx);
         op2 = MASK_LX(ctx->opcode);
         switch (op2) {
 #if defined(TARGET_MIPS64)
Signature · 1 line
2.49.0
#3 lore raw

[PULL 03/17] target/mips: Extract generic gen_lx() helper

In reply to Philippe Mathieu-Daudé

Extract gen_lx() from gen_mips_lx(); inline the Octeon check in decode_opc_special3_legacy().

Message-Id: <[email protected]>

---
 target/mips/tcg/translate.h |  1 +
 target/mips/tcg/translate.c | 55 +++++++++++++------------------------
 2 files changed, 20 insertions(+), 36 deletions(-)
target/mips/tcg/translate.h +1 -0
index e65593815e6..89dde1e7124 100644
@@ -169,6 +169,7 @@ void gen_store_fpr32(DisasContext *ctx, TCGv_i32 t, int reg);
 void gen_store_fpr64(DisasContext *ctx, TCGv_i64 t, int reg);
 int get_fp_bit(int cc);
 
+void gen_lx(DisasContext *ctx, int rd, int base, int index, MemOp mop);
 void gen_ldxs(DisasContext *ctx, int base, int index, int rd);
 void gen_align(DisasContext *ctx, int wordsz, int rd, int rs, int rt, int bp);
 void gen_addiupc(DisasContext *ctx, int rx, int imm,
target/mips/tcg/translate.c +19 -36

81 lines not on this page · raw message

Signature · 1 line
2.49.0
#4 lore raw

[PULL 10/17] hw/microblaze: Add missing FDT dependency

In reply to Philippe Mathieu-Daudé

From: Bernhard Beschow <[email protected]>

These boards ship with a bundled DTB, and dtc will be required for generating these from device tree sources. Prepare for that by adding an FDT dependency.

Message-ID: <[email protected]>

---
 hw/microblaze/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/microblaze/Kconfig +2 -2
index b0214b2c8b2..72d8072f764 100644
@@ -1,7 +1,7 @@
 config PETALOGIX_S3ADSP1800
     bool
     default y
-    depends on MICROBLAZE
+    depends on MICROBLAZE && FDT
     select PFLASH_CFI01
     select XILINX
     select XILINX_AXI
@@ -11,7 +11,7 @@ config PETALOGIX_S3ADSP1800
 config PETALOGIX_ML605
     bool
     default y
-    depends on MICROBLAZE
+    depends on MICROBLAZE && FDT
     select PFLASH_CFI01
     select SERIAL_MM
     select SSI_M25P80
Signature · 1 line
2.49.0
#5 lore raw

[PULL 06/17] tests/tcg/mips: Add tests for MIPS CRC32[c] instructions

In reply to Philippe Mathieu-Daudé

From: Aleksandar Rakic <[email protected]>

Message-ID: <[email protected]>

---
 tests/tcg/mips/include/wrappers_mips64r6.h    |  32 ++++
 .../isa/mips64r6/crc/test_mips64r6_crc32b.c   | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32cb.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32cd.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32ch.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32cw.c  | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32d.c   | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32h.c   | 142 ++++++++++++++++++
 .../isa/mips64r6/crc/test_mips64r6_crc32w.c   | 142 ++++++++++++++++++
 tests/tcg/mips/user/isa/mips64r6/crc/Makefile |  40 +++++
 10 files changed, 1208 insertions(+)
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32b.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cb.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cd.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32ch.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cw.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32d.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32h.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32w.c
 create mode 100644 tests/tcg/mips/user/isa/mips64r6/crc/Makefile
tests/tcg/mips/include/wrappers_mips64r6.h +32 -0
index d1e5edb632e..33d03de50b2 100644
@@ -23,6 +23,7 @@
 #ifndef WRAPPERS_MIPS64R6_H
 #define WRAPPERS_MIPS64R6_H
 
+#include <string.h>
 
 #define DO_MIPS64R6__RD__RS(suffix, mnemonic)                          \
 static inline void do_mips64r6_##suffix(const void *input,             \
@@ -80,4 +81,35 @@ DO_MIPS64R6__RD__RS_RT(DMULU, dmulu)
 DO_MIPS64R6__RD__RS_RT(DMUHU, dmuhu)
 
 
+#define DO_MIPS64R6__RT__RS_RT(suffix, mnemonic)                       \
+static inline void do_mips64r6_##suffix(const void *input1,            \
+                                        const void *input2,            \
+                                        void *output)                  \
+{                                                                      \
+    if (strncmp(#mnemonic, "crc32", 5) == 0)                           \
+        __asm__ volatile (                                             \
+           ".set crc\n\t"                                              \
+        );                                                             \
+                                                                       \
+   __asm__ volatile (                                                  \
+      "ld $t1, 0(%0)\n\t"                                              \
+      "ld $t2, 0(%1)\n\t"                                              \
+      #mnemonic " $t2, $t1, $t2\n\t"                                   \
+      "sd $t2, 0(%2)\n\t"                                              \
+      :                                                                \
+      : "r" (input1), "r" (input2), "r" (output)                       \
+      : "t0", "t1", "t2", "memory"                                     \
+   );                                                                  \
+}
+
+DO_MIPS64R6__RT__RS_RT(CRC32B, crc32b)
+DO_MIPS64R6__RT__RS_RT(CRC32H, crc32h)
+DO_MIPS64R6__RT__RS_RT(CRC32W, crc32w)
+DO_MIPS64R6__RT__RS_RT(CRC32D, crc32d)
+
+DO_MIPS64R6__RT__RS_RT(CRC32CB, crc32cb)
+DO_MIPS64R6__RT__RS_RT(CRC32CH, crc32ch)
+DO_MIPS64R6__RT__RS_RT(CRC32CW, crc32cw)
+DO_MIPS64R6__RT__RS_RT(CRC32CD, crc32cd)
+
 #endif
tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32b.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cb.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cd.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32ch.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cw.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32d.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32h.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32w.c new file +142 -0

142 lines not on this page · raw message

tests/tcg/mips/user/isa/mips64r6/crc/Makefile new file +40 -0
new file mode 100644
index 00000000000..b7f5811a5e9
@@ -0,0 +1,40 @@
+#
+#  Test program for MIPS64R6 CRC32 instructions
+#
+#  Copyright (C) 2025  Aleksandar Rakic <[email protected]>
+#
+#  SPDX-License-Identifier: GPL-2.0-or-later
+#
+
+ifndef PREFIX
+  $(error "PREFIX not set, please export GNU Toolchain install directory.")
+endif
+
+ifndef SYSROOT
+  $(error "SYSROOT not set, please export GNU Toolchain system root directory.")
+endif
+
+SIM = ../../../../../../../build/qemu-mips64
+SIM_FLAGS = -L $(SYSROOT)
+
+CC      =  $(PREFIX)/bin/mips64-r6-linux-gnu-gcc
+
+TESTCASES  = test_mips64r6_crc32b.tst
+TESTCASES += test_mips64r6_crc32h.tst
+TESTCASES += test_mips64r6_crc32w.tst
+TESTCASES += test_mips64r6_crc32d.tst
+TESTCASES += test_mips64r6_crc32cb.tst
+TESTCASES += test_mips64r6_crc32ch.tst
+TESTCASES += test_mips64r6_crc32cw.tst
+TESTCASES += test_mips64r6_crc32cd.tst
+
+all: $(TESTCASES)
+	@for case in $(TESTCASES); do \
+            echo $(SIM) $(SIM_FLAGS) ./$$case; \
+            $(SIM) $(SIM_FLAGS) ./$$case; \
+            echo $(RM) -rf ./$$case; \
+            $(RM) -rf ./$$case; \
+	done
+
+%.tst: %.c
+	$(CC) $< -o $@
Signature · 1 line
2.49.0
#6 lore raw

[PULL 13/17] esp.h: remove separate ESPState typedef

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

This is not needed as it is now handled by the OBJECT_DECLARE_SIMPLE_TYPE() macro.

Message-ID: <[email protected]>

---
 include/hw/scsi/esp.h | 2 --
 1 file changed, 2 deletions(-)
include/hw/scsi/esp.h +0 -2
index 533d856aa34..c9afcb7cac0 100644
@@ -14,8 +14,6 @@ typedef void (*ESPDMAMemoryReadWriteFunc)(void *opaque, uint8_t *buf, int len);
 #define ESP_FIFO_SZ 16
 #define ESP_CMDFIFO_SZ 32
 
-typedef struct ESPState ESPState;
-
 #define TYPE_ESP "esp"
 OBJECT_DECLARE_SIMPLE_TYPE(ESPState, ESP)
 
Signature · 1 line
2.49.0
#7 lore raw

[PULL 09/17] hw/intc/loongarch_extioi: Remove unnecessary 'qemu/typedefs.h' include

In reply to Philippe Mathieu-Daudé

"qemu/typedefs.h" is already included by "qemu/osdep.h".

Message-Id: <[email protected]>

---
 hw/intc/loongarch_extioi_kvm.c | 1 -
 1 file changed, 1 deletion(-)
hw/intc/loongarch_extioi_kvm.c +0 -1
index 0133540c45d..aa2e8c753fb 100644
@@ -6,7 +6,6 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/typedefs.h"
 #include "hw/intc/loongarch_extioi.h"
 #include "linux/kvm.h"
 #include "qapi/error.h"
Signature · 1 line
2.49.0
#8 lore raw

[PULL 08/17] hw/mips: Restrict ITU to TCG

In reply to Philippe Mathieu-Daudé

MIPS Inter-Thread Communication Unit is implemented using TCG. Check for TCG both in Kconfig and CPS source.

Fixes 2321d971b6f ("hw/mips: Add dependency MIPS_CPS -> MIPS_ITU")

Message-Id: <[email protected]>

---
 hw/mips/cps.c   | 4 ++--
 hw/mips/Kconfig | 2 +-
 hw/misc/Kconfig | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)
hw/mips/cps.c +2 -2
index 2a3ba3f58d2..e47695e2b0a 100644
@@ -24,7 +24,7 @@
 #include "hw/mips/mips.h"
 #include "hw/qdev-clock.h"
 #include "hw/qdev-properties.h"
-#include "system/kvm.h"
+#include "system/tcg.h"
 #include "system/reset.h"
 
 qemu_irq get_cps_irq(MIPSCPSState *s, int pin_number)
@@ -59,7 +59,7 @@ static bool cpu_mips_itu_supported(CPUMIPSState *env)
 {
     bool is_mt = (env->CP0_Config5 & (1 << CP0C5_VP)) || ase_mt_available(env);
 
-    return is_mt && !kvm_enabled();
+    return is_mt && tcg_enabled();
 }
 
 static void mips_cps_realize(DeviceState *dev, Error **errp)
hw/mips/Kconfig +1 -1
index b09c89a0175..f84fffcd323 100644
@@ -76,7 +76,7 @@ config LOONGSON3V
 
 config MIPS_CPS
     bool
-    select MIPS_ITU
+    select MIPS_ITU if TCG
 
 config MIPS_BOSTON
     bool
hw/misc/Kconfig +1 -0
index c27285b47ab..4e35657468b 100644
@@ -119,6 +119,7 @@ config STM32L4X5_RCC
 
 config MIPS_ITU
     bool
+    depends on TCG
 
 config MPS2_FPGAIO
     bool
Signature · 1 line
2.49.0
#9 lore raw

[PULL 01/17] target/mips: Add support for emulation of CRC32 instructions

In reply to Philippe Mathieu-Daudé

From: Yongbok Kim <[email protected]>

Add emulation of MIPS' CRC32 (Cyclic Redundancy Check) instructions. Reuse zlib crc32() and Linux crc32c().

Corresponding disassembly has been added in commit 99029be1c28 ("target/mips: Add implementation of GINVT instruction").

Message-ID: <PA4PR09MB486489692D843DDFC25F3CF1846B2@PA4PR09MB4864.eurprd09.prod.outlook.com>

---
 target/mips/helper.h             |  2 ++
 target/mips/tcg/translate.h      |  2 ++
 target/mips/tcg/rel6.decode      |  5 +++++
 target/mips/tcg/op_helper.c      | 26 ++++++++++++++++++++++++++
 target/mips/tcg/rel6_translate.c | 12 ++++++++++++
 target/mips/tcg/translate.c      | 24 ++++++++++++++++++++++++
 target/mips/cpu-defs.c.inc       | 10 ++++++----
 target/mips/meson.build          |  1 +
 8 files changed, 78 insertions(+), 4 deletions(-)
target/mips/helper.h +2 -0
index 7e400418281..b6cd53c8538 100644
@@ -21,6 +21,8 @@ DEF_HELPER_FLAGS_1(bitswap, TCG_CALL_NO_RWG_SE, tl, tl)
 DEF_HELPER_FLAGS_1(dbitswap, TCG_CALL_NO_RWG_SE, tl, tl)
 #endif
 
+DEF_HELPER_3(crc32, tl, tl, tl, i32)
+DEF_HELPER_3(crc32c, tl, tl, tl, i32)
 DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32)
 
 /* microMIPS functions */
target/mips/tcg/translate.h +2 -0
index 1bf153d1838..428b53a0dac 100644
@@ -51,6 +51,7 @@ typedef struct DisasContext {
     bool abs2008;
     bool mi;
     int gi;
+    bool crcp;
 } DisasContext;
 
 #define DISAS_STOP       DISAS_TARGET_0
@@ -181,6 +182,7 @@ bool gen_lsa(DisasContext *ctx, int rd, int rt, int rs, int sa);
 bool gen_dlsa(DisasContext *ctx, int rd, int rt, int rs, int sa);
 
 void gen_rdhwr(DisasContext *ctx, int rt, int rd, int sel);
+void gen_crc32(DisasContext *ctx, int rd, int rs, int rt, int sz, int crc32c);
 
 extern TCGv cpu_gpr[32], cpu_PC;
 #if defined(TARGET_MIPS64)
target/mips/tcg/rel6.decode +5 -0
index d6989cf56e8..7fbcb109b4e 100644
@@ -16,11 +16,16 @@
 
 &r                  rs rt rd sa
 
+&special3_crc       rs rt c sz
+
 @lsa                ...... rs:5 rt:5 rd:5 ... sa:2 ......   &r
+@crc32              ...... rs:5 rt:5 ..... c:3 sz:2 ......  &special3_crc
 
 LSA                 000000 ..... ..... ..... 000 .. 000101  @lsa
 DLSA                000000 ..... ..... ..... 000 .. 010101  @lsa
 
+CRC32               011111 ..... ..... 00000 ... .. 001111  @crc32
+
 REMOVED             010011 ----- ----- ----- ----- ------   # COP1X (COP3)
 
 REMOVED             011100 ----- ----- ----- ----- ------   # SPECIAL2
target/mips/tcg/op_helper.c +26 -0
index b906d10204b..4502ae2b5be 100644
@@ -24,6 +24,8 @@
 #include "exec/helper-proto.h"
 #include "exec/memop.h"
 #include "fpu_helper.h"
+#include "qemu/crc32c.h"
+#include <zlib.h>
 
 static inline target_ulong bitswap(target_ulong v)
 {
@@ -142,6 +144,30 @@ target_ulong helper_rotx(target_ulong rs, uint32_t shift, uint32_t shiftx,
     return (int64_t)(int32_t)(uint32_t)tmp5;
 }
 
+/* these crc32 functions are based on target/loongarch/tcg/op_helper.c */
+target_ulong helper_crc32(target_ulong val, target_ulong m, uint32_t sz)
+{
+    uint8_t buf[8];
+    target_ulong mask = ((sz * 8) == 64) ?
+                        (target_ulong) -1ULL :
+                        ((1ULL << (sz * 8)) - 1);
+
+    m &= mask;
+    stq_le_p(buf, m);
+    return (int32_t) (crc32(val ^ 0xffffffff, buf, sz) ^ 0xffffffff);
+}
+
+target_ulong helper_crc32c(target_ulong val, target_ulong m, uint32_t sz)
+{
+    uint8_t buf[8];
+    target_ulong mask = ((sz * 8) == 64) ?
+                        (target_ulong) -1ULL :
+                        ((1ULL << (sz * 8)) - 1);
+    m &= mask;
+    stq_le_p(buf, m);
+    return (int32_t) (crc32c(val, buf, sz) ^ 0xffffffff);
+}
+
 void helper_fork(target_ulong arg1, target_ulong arg2)
 {
     /*
target/mips/tcg/rel6_translate.c +12 -0
index 59f237ba3ba..89335063977 100644
@@ -33,3 +33,15 @@ static bool trans_DLSA(DisasContext *ctx, arg_r *a)
     }
     return gen_dlsa(ctx, a->rd, a->rt, a->rs, a->sa);
 }
+
+static bool trans_CRC32(DisasContext *ctx, arg_special3_crc *a)
+{
+    if (unlikely(!ctx->crcp)
+        || unlikely((a->sz == 3) && (!(ctx->hflags & MIPS_HFLAG_64)))
+        || unlikely((a->c >= 2))) {
+        gen_reserved_instruction(ctx);
+        return true;
+    }
+    gen_crc32(ctx, a->rt, a->rs, a->rt, a->sz, a->c);
+    return true;
+}
target/mips/tcg/translate.c +24 -0
index 8658315f938..5c80b030329 100644
@@ -13449,6 +13449,29 @@ static void decode_opc_special2_legacy(CPUMIPSState *env, DisasContext *ctx)
     }
 }
 
+void gen_crc32(DisasContext *ctx, int rd, int rs, int rt, int sz,
+               int crc32c)
+{
+    TCGv t0;
+    TCGv t1;
+    TCGv_i32 tsz = tcg_constant_i32(1 << sz);
+    if (rd == 0) {
+        /* Treat as NOP. */
+        return;
+    }
+    t0 = tcg_temp_new();
+    t1 = tcg_temp_new();
+
+    gen_load_gpr(t0, rt);
+    gen_load_gpr(t1, rs);
+
+    if (crc32c) {
+        gen_helper_crc32c(cpu_gpr[rd], t0, t1, tsz);
+    } else {
+        gen_helper_crc32(cpu_gpr[rd], t0, t1, tsz);
+    }
+}
+
 static void decode_opc_special3_r6(CPUMIPSState *env, DisasContext *ctx)
 {
     int rs, rt, rd, sa;
@@ -15095,6 +15118,7 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
     ctx->abs2008 = (env->active_fpu.fcr31 >> FCR31_ABS2008) & 1;
     ctx->mi = (env->CP0_Config5 >> CP0C5_MI) & 1;
     ctx->gi = (env->CP0_Config5 >> CP0C5_GI) & 3;
+    ctx->crcp = (env->CP0_Config5 >> CP0C5_CRCP) & 1;
     restore_cpu_state(env, ctx);
 #ifdef CONFIG_USER_ONLY
         ctx->mem_idx = MIPS_HFLAG_UM;
target/mips/cpu-defs.c.inc +6 -4
index 922fc39138d..d93b9d341ac 100644
@@ -756,8 +756,9 @@ const mips_def_t mips_defs[] =
                        (1 << CP0C3_RXI) | (1 << CP0C3_LPA) | (1 << CP0C3_VInt),
         .CP0_Config4 = MIPS_CONFIG4 | (1U << CP0C4_M) | (3 << CP0C4_IE) |
                        (1 << CP0C4_AE) | (0xfc << CP0C4_KScrExist),
-        .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_XNP) | (1 << CP0C5_VP) |
-                       (1 << CP0C5_LLB) | (1 << CP0C5_MRP) | (3 << CP0C5_GI),
+        .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_CRCP) | (1 << CP0C5_XNP) |
+                       (1 << CP0C5_VP) | (1 << CP0C5_LLB) | (1 << CP0C5_MRP) |
+                       (3 << CP0C5_GI),
         .CP0_Config5_rw_bitmask = (1 << CP0C5_MSAEn) | (1 << CP0C5_SBRI) |
                                   (1 << CP0C5_FRE) | (1 << CP0C5_UFE),
         .CP0_LLAddr_rw_bitmask = 0,
@@ -796,8 +797,9 @@ const mips_def_t mips_defs[] =
                        (1 << CP0C3_RXI) | (1 << CP0C3_LPA) | (1 << CP0C3_VInt),
         .CP0_Config4 = MIPS_CONFIG4 | (1U << CP0C4_M) | (3 << CP0C4_IE) |
                        (1 << CP0C4_AE) | (0xfc << CP0C4_KScrExist),
-        .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_XNP) | (1 << CP0C5_VP) |
-                       (1 << CP0C5_LLB) | (1 << CP0C5_MRP) | (3 << CP0C5_GI),
+        .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_CRCP) | (1 << CP0C5_XNP) |
+                       (1 << CP0C5_VP) | (1 << CP0C5_LLB) | (1 << CP0C5_MRP) |
+                       (3 << CP0C5_GI),
         .CP0_Config5_rw_bitmask = (1 << CP0C5_MSAEn) | (1 << CP0C5_SBRI) |
                                   (1 << CP0C5_FRE) | (1 << CP0C5_UFE),
         .CP0_LLAddr_rw_bitmask = 0,
target/mips/meson.build +1 -0
index 247979a2cfc..abf0ce3e8b9 100644
@@ -7,6 +7,7 @@ mips_ss.add(files(
   'gdbstub.c',
   'msa.c',
 ))
+mips_ss.add(zlib)
 
 if have_system
   subdir('system')
Signature · 1 line
2.49.0
#10 lore raw

[PULL 07/17] roms: re-remove execute bit from hppa-firmware*

In reply to Philippe Mathieu-Daudé

From: Cole Robinson <[email protected]>

This was fixed in c9d77526bddba0803a1fa982fb59ec98057150f9 for 9.2.0 but regressed in db34be329162cf6b06192703065e6c1010dbe3c5 in 10.0.0

When the bit is present, rpmbuild complains about missing ELF build-id

Message-ID: <52d0edfbb9b2f63a866f0065a721f3a95da6f8ba.1747590860.git.crobinso@redhat.com>

---
 pc-bios/hppa-firmware.img   | Bin
 pc-bios/hppa-firmware64.img | Bin
 2 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100755 => 100644 pc-bios/hppa-firmware.img
 mode change 100755 => 100644 pc-bios/hppa-firmware64.img
pc-bios/hppa-firmware.img +0 -0
old mode 100755
new mode 100644
pc-bios/hppa-firmware64.img +0 -0
old mode 100755
new mode 100644
Signature · 1 line
2.49.0
#11 lore raw

[PULL 17/17] esp.c: only allow ESP commands permitted in the current asc_mode

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

If an ESP command is issued in an incorrect mode then an illegal command interrupt should be generated. Add a new esp_cmd_is_valid() function to indicate whether the ESP command is valid for the current mode, and if not then raise the illegal command interrupt.

This fixes WinNT MIPS which issues ICCS after a Chip Reset which is not permitted, but will fail with an INACCESSIBLE_BOOT_DEVICE error unless an interrupt is generated.

Fixes 83428f7a97 ("esp.c: move write_response() non-DMA logic to esp_do_nodma()")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2464

Message-ID: <[email protected]>

---
 include/hw/scsi/esp.h |  8 ++++++++
 hw/scsi/esp.c         | 37 +++++++++++++++++++++++++++++++++++++
 hw/scsi/trace-events  |  1 +
 3 files changed, 46 insertions(+)
include/hw/scsi/esp.h +8 -0
index 6327060c7c7..3526bad7464 100644
@@ -111,6 +111,13 @@ struct SysBusESPState {
 #define CMD_DMA 0x80
 #define CMD_CMD 0x7f
 
+#define CMD_GRP_MASK 0x70
+
+#define CMD_GRP_MISC 0x00
+#define CMD_GRP_INIT 0x01
+#define CMD_GRP_TRGT 0x02
+#define CMD_GRP_DISC 0x04
+
 #define CMD_NOP      0x00
 #define CMD_FLUSH    0x01
 #define CMD_RESET    0x02
@@ -145,6 +152,7 @@ struct SysBusESPState {
 #define INTR_FC 0x08
 #define INTR_BS 0x10
 #define INTR_DC 0x20
+#define INTR_IL 0x40
 #define INTR_RST 0x80
 
 #define SEQ_0 0x0
hw/scsi/esp.c +37 -0
index 4aa58f9e485..1d264c40e57 100644
@@ -1129,6 +1129,38 @@ static void parent_esp_reset(ESPState *s, int irq, int level)
     }
 }
 
+static bool esp_cmd_is_valid(ESPState *s, uint8_t cmd)
+{
+    uint8_t cmd_group = (cmd & CMD_GRP_MASK) >> 4;
+
+    /* Always allow misc commands */
+    if (cmd_group == CMD_GRP_MISC) {
+        return true;
+    }
+
+    switch (s->asc_mode) {
+    case ESP_ASC_MODE_DIS:
+        /* Disconnected mode: only allow disconnected commands */
+        if (cmd_group == CMD_GRP_DISC) {
+            return true;
+        }
+        break;
+
+    case ESP_ASC_MODE_INI:
+        /* Initiator mode: allow initiator commands */
+        if (cmd_group == CMD_GRP_INIT) {
+            return true;
+        }
+        break;
+
+    default:
+        g_assert_not_reached();
+    }
+
+    trace_esp_invalid_cmd(cmd, s->asc_mode);
+    return false;
+}
+
 static void esp_run_cmd(ESPState *s)
 {
     uint8_t cmd = s->rregs[ESP_CMD];
@@ -1285,6 +1317,11 @@ void esp_reg_write(ESPState *s, uint32_t saddr, uint64_t val)
         break;
     case ESP_CMD:
         s->rregs[saddr] = val;
+        if (!esp_cmd_is_valid(s, s->rregs[saddr])) {
+            s->rregs[ESP_RSTAT] |= INTR_IL;
+            esp_raise_irq(s);
+            break;
+        }
         esp_run_cmd(s);
         break;
     case ESP_WBUSID ... ESP_WSYNO:
hw/scsi/trace-events +1 -0
index f0f2a98c2ee..6c2788e2026 100644
@@ -198,6 +198,7 @@ esp_mem_writeb_cmd_ensel(uint32_t val) "Enable selection (0x%2.2x)"
 esp_mem_writeb_cmd_dissel(uint32_t val) "Disable selection (0x%2.2x)"
 esp_mem_writeb_cmd_ti(uint32_t val) "Transfer Information (0x%2.2x)"
 esp_set_phase(const char *phase) "setting bus phase to %s"
+esp_invalid_cmd(uint8_t cmd, uint8_t asc_mode) "command 0x%x asc_mode 0x%x"
 
 # esp-pci.c
 esp_pci_error_invalid_dma_direction(void) "invalid DMA transfer direction"
Signature · 1 line
2.49.0
#12 lore raw

[PULL 16/17] esp.c: add asc_mode property to indicate the current ESP mode

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Add a new asc_mode property to ESPState which indicates the current mode of the ESP and update the ESP state machine accordingly.

Bump the vmstate version and include migration logic to ensure that asc_mode is set to initiator mode such that any commands in progress will always continue.

Message-ID: <[email protected]>

---
 include/hw/scsi/esp.h |  7 +++++++
 hw/scsi/esp.c         | 21 ++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
include/hw/scsi/esp.h +7 -0
index c9afcb7cac0..6327060c7c7 100644
@@ -14,6 +14,12 @@ typedef void (*ESPDMAMemoryReadWriteFunc)(void *opaque, uint8_t *buf, int len);
 #define ESP_FIFO_SZ 16
 #define ESP_CMDFIFO_SZ 32
 
+enum ESPASCMode {
+    ESP_ASC_MODE_DIS = 0,    /* Disconnected */
+    ESP_ASC_MODE_INI = 1,    /* Initiator */
+    ESP_ASC_MODE_TGT = 2     /* Target */
+};
+
 #define TYPE_ESP "esp"
 OBJECT_DECLARE_SIMPLE_TYPE(ESPState, ESP)
 
@@ -38,6 +44,7 @@ struct ESPState {
     uint8_t cmdfifo_cdb_offset;
     uint8_t lun;
     uint32_t do_cmd;
+    uint8_t asc_mode;
 
     bool data_ready;
     int dma_enabled;
hw/scsi/esp.c +20 -1
index 1c7bad8fc02..4aa58f9e485 100644
@@ -275,6 +275,7 @@ static int esp_select(ESPState *s)
     if (!s->current_dev) {
         /* No such drive */
         s->rregs[ESP_RSTAT] = 0;
+        s->asc_mode = ESP_ASC_MODE_DIS;
         s->rregs[ESP_RINTR] = INTR_DC;
         esp_raise_irq(s);
         return -1;
@@ -284,6 +285,7 @@ static int esp_select(ESPState *s)
      * Note that we deliberately don't raise the IRQ here: this will be done
      * either in esp_transfer_data() or esp_command_complete()
      */
+    s->asc_mode = ESP_ASC_MODE_INI;
     return 0;
 }
 
@@ -308,6 +310,7 @@ static void do_command_phase(ESPState *s)
     if (!current_lun) {
         /* No such drive */
         s->rregs[ESP_RSTAT] = 0;
+        s->asc_mode = ESP_ASC_MODE_DIS;
         s->rregs[ESP_RINTR] = INTR_DC;
         s->rregs[ESP_RSEQ] = SEQ_0;
         esp_raise_irq(s);
@@ -1102,6 +1105,7 @@ void esp_hard_reset(ESPState *s)
     fifo8_reset(&s->cmdfifo);
     s->dma = 0;
     s->dma_cb = NULL;
+    s->asc_mode = ESP_ASC_MODE_DIS;
 
     s->rregs[ESP_CFG1] = 7;
 }
@@ -1170,6 +1174,7 @@ static void esp_run_cmd(ESPState *s)
         break;
     case CMD_MSGACC:
         trace_esp_mem_writeb_cmd_msgacc(cmd);
+        s->asc_mode = ESP_ASC_MODE_DIS;
         s->rregs[ESP_RINTR] |= INTR_DC;
         s->rregs[ESP_RSEQ] = 0;
         s->rregs[ESP_RFLAGS] = 0;
@@ -1337,6 +1342,14 @@ static bool esp_is_between_version_5_and_6(void *opaque, int version_id)
     return version_id >= 5 && version_id <= 6;
 }
 
+static bool esp_is_version_8(void *opaque, int version_id)
+{
+    ESPState *s = ESP(opaque);
+
+    version_id = MIN(version_id, s->mig_version_id);
+    return version_id >= 8;
+}
+
 int esp_pre_save(void *opaque)
 {
     ESPState *s = ESP(object_resolve_path_component(
@@ -1368,13 +1381,18 @@ static int esp_post_load(void *opaque, int version_id)
         }
     }
 
+    if (version_id < 8) {
+        /* Assume initiator mode to allow all commands to continue */
+        s->asc_mode = ESP_ASC_MODE_INI;
+    }
+
     s->mig_version_id = vmstate_esp.version_id;
     return 0;
 }
 
 const VMStateDescription vmstate_esp = {
     .name = "esp",
-    .version_id = 7,
+    .version_id = 8,
     .minimum_version_id = 3,
     .post_load = esp_post_load,
     .fields = (const VMStateField[]) {
@@ -1406,6 +1424,7 @@ const VMStateDescription vmstate_esp = {
                            esp_is_between_version_5_and_6),
         VMSTATE_UINT8_TEST(lun, ESPState, esp_is_version_6),
         VMSTATE_BOOL(drq_state, ESPState),
+        VMSTATE_UINT8_TEST(asc_mode, ESPState, esp_is_version_8),
         VMSTATE_END_OF_LIST()
     },
 };
Signature · 1 line
2.49.0
#13 lore raw

[PULL 14/17] esp.c: only call dma_memory_read function if transfer length is non-zero

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

In the cases where mixed DMA/non-DMA transfers are used or no data is available, it is possible for the calculated transfer length to be zero. Only call the dma_memory_read function where the transfer length is non-zero to avoid invoking the DMA engine for a zero length transfer which can have side-effects (along with generating additional tracing noise).

Message-ID: <[email protected]>

---
 hw/scsi/esp.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
hw/scsi/esp.c +13 -7
index 62ba4061492..ec9fcbeddf4 100644
@@ -487,8 +487,10 @@ static void esp_do_dma(ESPState *s)
     case STAT_MO:
         if (s->dma_memory_read) {
             len = MIN(len, fifo8_num_free(&s->cmdfifo));
-            s->dma_memory_read(s->dma_opaque, buf, len);
-            esp_set_tc(s, esp_get_tc(s) - len);
+            if (len) {
+                s->dma_memory_read(s->dma_opaque, buf, len);
+                esp_set_tc(s, esp_get_tc(s) - len);
+            }
         } else {
             len = esp_fifo_pop_buf(s, buf, fifo8_num_used(&s->fifo));
             len = MIN(fifo8_num_free(&s->cmdfifo), len);
@@ -541,9 +543,11 @@ static void esp_do_dma(ESPState *s)
         trace_esp_do_dma(cmdlen, len);
         if (s->dma_memory_read) {
             len = MIN(len, fifo8_num_free(&s->cmdfifo));
-            s->dma_memory_read(s->dma_opaque, buf, len);
-            fifo8_push_all(&s->cmdfifo, buf, len);
-            esp_set_tc(s, esp_get_tc(s) - len);
+            if (len) {
+                s->dma_memory_read(s->dma_opaque, buf, len);
+                fifo8_push_all(&s->cmdfifo, buf, len);
+                esp_set_tc(s, esp_get_tc(s) - len);
+            }
         } else {
             len = esp_fifo_pop_buf(s, buf, fifo8_num_used(&s->fifo));
             len = MIN(fifo8_num_free(&s->cmdfifo), len);
@@ -572,8 +576,10 @@ static void esp_do_dma(ESPState *s)
         switch (s->rregs[ESP_CMD]) {
         case CMD_TI | CMD_DMA:
             if (s->dma_memory_read) {
-                s->dma_memory_read(s->dma_opaque, s->async_buf, len);
-                esp_set_tc(s, esp_get_tc(s) - len);
+                if (len) {
+                    s->dma_memory_read(s->dma_opaque, s->async_buf, len);
+                    esp_set_tc(s, esp_get_tc(s) - len);
+                }
             } else {
                 /* Copy FIFO data to device */
                 len = MIN(s->async_len, ESP_FIFO_SZ);
Signature · 1 line
2.49.0
#14 lore raw

Re: [PULL 14/17] esp.c: only call dma_memory_read function if transfer length is non-zero

Hi Mark,

Quoted 25 lines · Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

In the cases where mixed DMA/non-DMA transfers are used or no data is available, it is possible for the calculated transfer length to be zero. Only call the dma_memory_read function where the transfer length is non-zero to avoid invoking the DMA engine for a zero length transfer which can have side-effects (along with generating additional tracing noise).

Message-ID: <[email protected]>

---
  hw/scsi/esp.c | 20 +++++++++++++-------
  1 file changed, 13 insertions(+), 7 deletions(-)
hw/scsi/esp.c +0 -0
index 62ba4061492..ec9fcbeddf4 100644
@@ -487,8 +487,10 @@ static void esp_do_dma(ESPState *s)
      case STAT_MO:
          if (s->dma_memory_read) {

hw/scsi/esp.c static void esp_do_dma(ESPState *s) · line 496

Quoted 10 lines
hw/scsi/esp.c +4 -2
              len = MIN(len, fifo8_num_free(&s->cmdfifo));
-            s->dma_memory_read(s->dma_opaque, buf, len);
-            esp_set_tc(s, esp_get_tc(s) - len);
+            if (len) {
+                s->dma_memory_read(s->dma_opaque, buf, len);
+                esp_set_tc(s, esp_get_tc(s) - len);
+            }
          } else {
              len = esp_fifo_pop_buf(s, buf, fifo8_num_used(&s->fifo));
              len = MIN(fifo8_num_free(&s->cmdfifo), len);
            }
            fifo8_push_all(&s->cmdfifo, buf, len);

Coverity reported access to uninitialized buf[]:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1612373: Uninitialized variables (UNINIT)
Using uninitialized value "*buf" when calling "fifo8_push_all".

Do you mind having a look?

Thanks,

Phil.

#15 lore raw

Re: [PULL 14/17] esp.c: only call dma_memory_read function if transfer length is non-zero

Quoted 42 lines · Philippe Mathieu-Daudé

Hi Mark,

Quoted 25 lines · Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

In the cases where mixed DMA/non-DMA transfers are used or no data is available, it is possible for the calculated transfer length to be zero. Only call the dma_memory_read function where the transfer length is non-zero to avoid invoking the DMA engine for a zero length transfer which can have side-effects (along with generating additional tracing noise).

Message-ID: <[email protected]>

---
  hw/scsi/esp.c | 20 +++++++++++++-------
  1 file changed, 13 insertions(+), 7 deletions(-)
hw/scsi/esp.c +0 -0
index 62ba4061492..ec9fcbeddf4 100644
@@ -487,8 +487,10 @@ static void esp_do_dma(ESPState *s)
      case STAT_MO:
          if (s->dma_memory_read) {

hw/scsi/esp.c static void esp_do_dma(ESPState *s) · line 496

Quoted 10 lines
hw/scsi/esp.c +4 -2
              len = MIN(len, fifo8_num_free(&s->cmdfifo));
-            s->dma_memory_read(s->dma_opaque, buf, len);
-            esp_set_tc(s, esp_get_tc(s) - len);
+            if (len) {
+                s->dma_memory_read(s->dma_opaque, buf, len);
+                esp_set_tc(s, esp_get_tc(s) - len);
+            }
          } else {
              len = esp_fifo_pop_buf(s, buf, fifo8_num_used(&s->fifo));
              len = MIN(fifo8_num_free(&s->cmdfifo), len);
             }
             fifo8_push_all(&s->cmdfifo, buf, len);
Quoted 6 lines

Coverity reported access to uninitialized buf[]:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1612373: Uninitialized variables (UNINIT)
Using uninitialized value "*buf" when calling "fifo8_push_all".

Do you mind having a look?

I think this is a false positive (and marked it that way in the Coverity Scan UI). Coverity is complaining that
we might access buf[] uninitialized, but in the code path it is complaining about we know that len is zero. The fifo8_push_all() does a "memcpy(&fifo->data[start], data, num)" and if num is 0 that is valid and won't access anything in buf[].

We could I suppose make fifo8_push_all() return early for the num == 0 case, just to make it clearer that it's supposed to work.

thanks
-- PMM

#16 lore raw

Re: [PULL 14/17] esp.c: only call dma_memory_read function if transfer length is non-zero

Quoted 57 lines · Peter Maydell
Quoted 42 lines · Philippe Mathieu-Daudé

Hi Mark,

Quoted 25 lines · Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

In the cases where mixed DMA/non-DMA transfers are used or no data is available, it is possible for the calculated transfer length to be zero. Only call the dma_memory_read function where the transfer length is non-zero to avoid invoking the DMA engine for a zero length transfer which can have side-effects (along with generating additional tracing noise).

Message-ID: <[email protected]>

---
   hw/scsi/esp.c | 20 +++++++++++++-------
   1 file changed, 13 insertions(+), 7 deletions(-)
hw/scsi/esp.c +0 -0
index 62ba4061492..ec9fcbeddf4 100644
@@ -487,8 +487,10 @@ static void esp_do_dma(ESPState *s)
       case STAT_MO:
           if (s->dma_memory_read) {

hw/scsi/esp.c static void esp_do_dma(ESPState *s) · line 496

Quoted 10 lines
hw/scsi/esp.c +4 -2
               len = MIN(len, fifo8_num_free(&s->cmdfifo));
-            s->dma_memory_read(s->dma_opaque, buf, len);
-            esp_set_tc(s, esp_get_tc(s) - len);
+            if (len) {
+                s->dma_memory_read(s->dma_opaque, buf, len);
+                esp_set_tc(s, esp_get_tc(s) - len);
+            }
           } else {
               len = esp_fifo_pop_buf(s, buf, fifo8_num_used(&s->fifo));
               len = MIN(fifo8_num_free(&s->cmdfifo), len);
              }
              fifo8_push_all(&s->cmdfifo, buf, len);
Quoted 6 lines

Coverity reported access to uninitialized buf[]:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1612373: Uninitialized variables (UNINIT)
Using uninitialized value "*buf" when calling "fifo8_push_all".

Do you mind having a look?

I think this is a false positive (and marked it that way in the Coverity Scan UI). Coverity is complaining that
we might access buf[] uninitialized, but in the code path it is complaining about we know that len is zero. The fifo8_push_all() does a "memcpy(&fifo->data[start], data, num)" and if num is 0 that is valid and won't access anything in buf[].

Quoted 2 lines

We could I suppose make fifo8_push_all() return early for the num == 0 case, just to make it clearer that it's supposed to work.

Thanks both!

I can certainly look to update fifo8_push_all() if you think it would be a better solution?

ATB,

Mark.

#17 lore raw

[PULL 12/17] esp.c: improve comment in esp_transfer_data()

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Whilst working on the previous patch, the existing comment was not enough to document when the TI command codepath was being used. Update and improve the comment accordingly.

Message-ID: <[email protected]>

---
 hw/scsi/esp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/scsi/esp.c +3 -2
index 9181c8810fb..62ba4061492 100644
@@ -1029,8 +1029,9 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len)
         case CMD_TI | CMD_DMA:
         case CMD_TI:
             /*
-             * Bus service interrupt raised because of initial change to
-             * DATA phase
+             * If the final COMMAND phase data was transferred using a TI
+             * command, clear ESP_CMD to terminate the TI command and raise
+             * the completion interrupt
              */
             s->rregs[ESP_CMD] = 0;
             s->rregs[ESP_RINTR] |= INTR_BS;
Signature · 1 line
2.49.0
#18 lore raw

[PULL 15/17] esp.c: only call dma_memory_write function if transfer length is non-zero

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

In the cases where mixed DMA/non-DMA transfers are used or no data is available, it is possible for the calculated transfer length to be zero. Only call the dma_memory_write function where the transfer length is non-zero to avoid invoking the DMA engine for a zero length transfer which can have side-effects (along with generating additional tracing noise).

Message-ID: <[email protected]>

---
 hw/scsi/esp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/scsi/esp.c +5 -1
index ec9fcbeddf4..1c7bad8fc02 100644
@@ -631,7 +631,9 @@ static void esp_do_dma(ESPState *s)
         switch (s->rregs[ESP_CMD]) {
         case CMD_TI | CMD_DMA:
             if (s->dma_memory_write) {
-                s->dma_memory_write(s->dma_opaque, s->async_buf, len);
+                if (len) {
+                    s->dma_memory_write(s->dma_opaque, s->async_buf, len);
+                }
             } else {
                 /* Copy device data to FIFO */
                 len = MIN(len, fifo8_num_free(&s->fifo));
@@ -681,6 +683,7 @@ static void esp_do_dma(ESPState *s)
                 buf[0] = s->status;
 
                 if (s->dma_memory_write) {
+                    /* Length already non-zero */
                     s->dma_memory_write(s->dma_opaque, buf, len);
                 } else {
                     esp_fifo_push_buf(s, buf, len);
@@ -715,6 +718,7 @@ static void esp_do_dma(ESPState *s)
                 buf[0] = 0;
 
                 if (s->dma_memory_write) {
+                    /* Length already non-zero */
                     s->dma_memory_write(s->dma_opaque, buf, len);
                 } else {
                     esp_fifo_push_buf(s, buf, len);
Signature · 1 line
2.49.0
#19 lore raw

[PULL 05/17] target/mips: Have gen_[d]lsa() callers add 1 to shift amount argument

In reply to Philippe Mathieu-Daudé

Having the callee add 1 to shift amount is misleading (see the NM_LSA case in decode_nanomips_32_48_opc() where we have to manually substract 1). Rather have the callers pass a modified $sa.

Message-Id: <[email protected]>

---
 target/mips/tcg/msa_translate.c           | 4 ++--
 target/mips/tcg/rel6_translate.c          | 4 ++--
 target/mips/tcg/translate_addr_const.c    | 4 ++--
 target/mips/tcg/micromips_translate.c.inc | 2 +-
 target/mips/tcg/nanomips_translate.c.inc  | 7 +------
 5 files changed, 8 insertions(+), 13 deletions(-)
target/mips/tcg/msa_translate.c +2 -2
index 75cf80a20ed..82b149922fa 100644
@@ -780,7 +780,7 @@ TRANS_DF_iv(ST, trans_msa_ldst, gen_helper_msa_st);
 
 static bool trans_LSA(DisasContext *ctx, arg_r *a)
 {
-    return gen_lsa(ctx, a->rd, a->rt, a->rs, a->sa);
+    return gen_lsa(ctx, a->rd, a->rt, a->rs, a->sa + 1);
 }
 
 static bool trans_DLSA(DisasContext *ctx, arg_r *a)
@@ -788,5 +788,5 @@ static bool trans_DLSA(DisasContext *ctx, arg_r *a)
     if (TARGET_LONG_BITS != 64) {
         return false;
     }
-    return gen_dlsa(ctx, a->rd, a->rt, a->rs, a->sa);
+    return gen_dlsa(ctx, a->rd, a->rt, a->rs, a->sa + 1);
 }
target/mips/tcg/rel6_translate.c +2 -2
index 89335063977..4c056621c97 100644
@@ -23,7 +23,7 @@ bool trans_REMOVED(DisasContext *ctx, arg_REMOVED *a)
 
 static bool trans_LSA(DisasContext *ctx, arg_r *a)
 {
-    return gen_lsa(ctx, a->rd, a->rt, a->rs, a->sa);
+    return gen_lsa(ctx, a->rd, a->rt, a->rs, a->sa + 1);
 }
 
 static bool trans_DLSA(DisasContext *ctx, arg_r *a)
@@ -31,7 +31,7 @@ static bool trans_DLSA(DisasContext *ctx, arg_r *a)
     if (TARGET_LONG_BITS != 64) {
         return false;
     }
-    return gen_dlsa(ctx, a->rd, a->rt, a->rs, a->sa);
+    return gen_dlsa(ctx, a->rd, a->rt, a->rs, a->sa + 1);
 }
 
 static bool trans_CRC32(DisasContext *ctx, arg_special3_crc *a)
target/mips/tcg/translate_addr_const.c +2 -2
index 6f4b39f715b..1d140e918da 100644
@@ -26,7 +26,7 @@ bool gen_lsa(DisasContext *ctx, int rd, int rt, int rs, int sa)
     t1 = tcg_temp_new();
     gen_load_gpr(t0, rs);
     gen_load_gpr(t1, rt);
-    tcg_gen_shli_tl(t0, t0, sa + 1);
+    tcg_gen_shli_tl(t0, t0, sa);
     tcg_gen_add_tl(cpu_gpr[rd], t0, t1);
     tcg_gen_ext32s_tl(cpu_gpr[rd], cpu_gpr[rd]);
     return true;
@@ -47,7 +47,7 @@ bool gen_dlsa(DisasContext *ctx, int rd, int rt, int rs, int sa)
     t1 = tcg_temp_new();
     gen_load_gpr(t0, rs);
     gen_load_gpr(t1, rt);
-    tcg_gen_shli_tl(t0, t0, sa + 1);
+    tcg_gen_shli_tl(t0, t0, sa);
     tcg_gen_add_tl(cpu_gpr[rd], t0, t1);
     return true;
 }
target/mips/tcg/micromips_translate.c.inc +1 -1
index c479bec1081..8fda7c8a214 100644
@@ -1795,7 +1795,7 @@ static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx)
             return;
         case LSA:
             check_insn(ctx, ISA_MIPS_R6);
-            gen_lsa(ctx, rd, rt, rs, extract32(ctx->opcode, 9, 2));
+            gen_lsa(ctx, rd, rt, rs, extract32(ctx->opcode, 9, 2) + 1);
             break;
         case ALIGN:
             check_insn(ctx, ISA_MIPS_R6);
target/mips/tcg/nanomips_translate.c.inc +1 -6
index 1e274143bbd..9d4e0bee81f 100644
@@ -3626,12 +3626,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
                 gen_p_lsx(ctx, rd, rs, rt);
                 break;
             case NM_LSA:
-                /*
-                 * In nanoMIPS, the shift field directly encodes the shift
-                 * amount, meaning that the supported shift values are in
-                 * the range 0 to 3 (instead of 1 to 4 in MIPSR6).
-                 */
-                gen_lsa(ctx, rd, rt, rs, extract32(ctx->opcode, 9, 2) - 1);
+                gen_lsa(ctx, rd, rt, rs, extract32(ctx->opcode, 9, 2));
                 break;
             case NM_EXTW:
                 gen_ext(ctx, 32, rd, rs, rt, extract32(ctx->opcode, 6, 5));
Signature · 1 line
2.49.0
#20 lore raw

[PULL 11/17] esp.c: only raise IRQ in esp_transfer_data() for CMD_SEL, CMD_SELATN and CMD_TI commands

In reply to Philippe Mathieu-Daudé

From: Mark Cave-Ayland <[email protected]>

Clarify the logic in esp_transfer_data() to ensure that the deferred interrupt code can only be triggered for CMD_SEL, CMD_SELATN and CMD_TI commands. This should already be the case, but make it explicit to ensure the logic isn't triggered unexpectedly.

Message-ID: <[email protected]>

---
 hw/scsi/esp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/scsi/esp.c +3 -2
index f24991fd16d..9181c8810fb 100644
@@ -1012,6 +1012,7 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len)
              */
              s->rregs[ESP_RINTR] |= INTR_BS | INTR_FC;
              s->rregs[ESP_RSEQ] = SEQ_CD;
+             esp_raise_irq(s);
              break;
 
         case CMD_SELATNS | CMD_DMA:
@@ -1022,6 +1023,7 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len)
              */
              s->rregs[ESP_RINTR] |= INTR_BS;
              s->rregs[ESP_RSEQ] = SEQ_MO;
+             esp_raise_irq(s);
              break;
 
         case CMD_TI | CMD_DMA:
@@ -1032,10 +1034,9 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len)
              */
             s->rregs[ESP_CMD] = 0;
             s->rregs[ESP_RINTR] |= INTR_BS;
+            esp_raise_irq(s);
             break;
         }
-
-        esp_raise_irq(s);
     }
 
     /*
Signature · 1 line
2.49.0
#21 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 15 lines · Philippe Mathieu-Daudé

The following changes since commit 9a4e273ddec3927920c5958d2226c6b38b543336:

   Merge tag 'pull-tcg-20250711' of https://gitlab.com/rth7680/qemu into staging (2025-07-13 01:46:04 -0400)

are available in the Git repository at:

   https://github.com/philmd/qemu.git tags/mips-20250715

for you to fetch changes up to 6f8ce26bb00db66e6cec632f16df3cd13e4df934:

esp.c: only allow ESP commands permitted in the current asc_mode (2025-07-15 00:25:21 +0200)

----------------------------------------------------------------
MIPS patches queue

Quoted 8 lines

- Implement CRC32[c] (Release 6) instructions
- Convert Octeon LX instructions to decodetree
- Restrict ITU to TCG
- Fix ESP issue affecting WinNT (INACCESSIBLE_BOOT_DEVICE BSOD)
- Add missing FDT dependency for some MicroBlaze machines
- Remove execute bit on hppa-firmware blobs

----------------------------------------------------------------

BTW the 2 checkpatch errors are spurious:

4/17 Checking commit 23ecff81ac88 (target/mips: Convert Octeon LX instructions to decodetree)
WARNING: Saw acceptable license 'LGPL-2.1-or-later' but note 'GPL-2.0-or-later' is preferred for new files unless the code is derived from a source file with an existing declared license that must be retained. Please explain the license choice in the commit message.
total: 0 errors, 1 warnings, 42 lines checked

-> no license change / addition.

6/17 Checking commit c083f1f3de93 (tests/tcg/mips: Add tests for MIPS CRC32[c] instructions)
WARNING: added, moved or deleted file(s):

tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32b.c tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cb.c tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cd.c tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32ch.c tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32cw.c tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32d.c tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32h.c tests/tcg/mips/user/isa/mips64r6/crc/test_mips64r6_crc32w.c tests/tcg/mips/user/isa/mips64r6/crc/Makefile

Does MAINTAINERS need updating?

->

$ ./scripts/get_maintainer.pl -f tests/tcg/mips/user/isa/mips64r6/crc/Makefile
"Philippe Mathieu-Daudé" <[email protected]> (odd fixer:MIPS TCG CPUs)
Aurelien Jarno <[email protected]> (reviewer:MIPS TCG CPUs)
Jiaxun Yang <[email protected]> (reviewer:MIPS TCG CPUs)
Aleksandar Rikalo <[email protected]> (reviewer:MIPS TCG CPUs)
[email protected] (open list:All patches CC here)