Skip to contentSkip to conversation

target/ppc: Correct Freescale Book E CPU models

PATCH Superseded Bin Meng 4 participants 25 messages Oct 7 – Oct 22 Arm/Amlogic Meson SoC support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

cover target/ppc: Correct Freescale Book E CPU models

This series corrects SPR access, cache configuration and instruction availability in the Freescale Book E CPU models. It also adds system TCG tests for e500mc, e5500 and e6500.

The patches are grouped as follows:

- patch #1-#4, bug fixes to PIR write access, the MAS5 SPR number and cache block/line sizes (qemu-stable cc'ed)
- patch #5-#6, complete e500mc/e5500 L1 cache configuration and remove redundant e6500 cache geometry bits
- patch #7-#11, register the missing cache, MMU-assist and sevearl control SPRs
- patch #12-#14, split the PowerISA 2.05 instructions to several sub-flags controlled groups, due to differences seen on the e500 series cores
- patch #15-#17: Add TCG tests for illegal-instruction exceptions, byte comparison and parity results, and FPSCR field-mask handling

Bin Meng (17):
target/ppc: Correct PIR write access on e500 cores target/ppc: Correct the MAS5 SPR number
target/ppc: Correct the e500mc and e5500 cache block size fields target/ppc: Correct cache line size for e6500 target/ppc: Complete e500mc and e5500 L1 cache configuration target/ppc: Drop redundant e6500 L1 cache geometry bits target/ppc: Register L1CSR2 on e500mc/e5500/e6500 cores target/ppc: Register L2CFG0 and L2CSR1 on e500mc and e5500 target/ppc: Register MAS5 and MAS8 on e500mc/e5500/e6500 target/ppc: Register PWRMGTCR0 on e6500
target/ppc: Register IVOR42 on e6500
target/ppc: Split the ISA 2.05 instruction feature group target/ppc: Enable byte comparison and parity on e5500 and e6500 target/ppc: Ignore FPSCR W/L fields on e500mc, e5500 and e6500 tests/tcg/ppc: Add Book E illegal instruction tests tests/tcg/ppc: Test byte comparison and parity on e5500/e6500 tests/tcg/ppc: Test FPSCR W/L handling on e500mc/e5500/e6500

 target/ppc/cpu.h                           | 31 ++++++--
 target/ppc/cpu_init.h                      |  5 +-
 target/ppc/cpu_init.c                      | 72 +++++++++++++----
 target/ppc/translate.c                     | 10 ++-
 target/ppc/translate/fixedpoint-impl.c.inc |  6 +-
 target/ppc/translate/fp-impl.c.inc         | 14 +++-
 target/ppc/translate/fp-ops.c.inc          |  9 ++-
 meson_options.txt                          |  4 +
 scripts/meson-buildoptions.sh              |  2 +
 tests/tcg/meson.build                      |  1 +
 tests/tcg/ppc/meson.build                  |  5 ++
 tests/tcg/ppc/system/README                | 22 ++++++
 tests/tcg/ppc/system/boot.S                | 92 ++++++++++++++++++++++
 tests/tcg/ppc/system/byte-parity.S         | 33 ++++++++
 tests/tcg/ppc/system/fpscr.S               | 75 ++++++++++++++++++
 tests/tcg/ppc/system/isa.out               |  1 +
 tests/tcg/ppc/system/kernel.ld             | 18 +++++
 tests/tcg/ppc/system/macros.inc            | 56 +++++++++++++
 tests/tcg/ppc/system/meson.build           | 39 +++++++++
 tests/tcg/ppc/system/unsupported.S         | 31 ++++++++
 tests/tcg/ppc64/meson.build                |  2 +
 tests/tcg/ppc64/system/meson.build         | 33 ++++++++
 22 files changed, 525 insertions(+), 36 deletions(-)
 create mode 100644 tests/tcg/ppc/meson.build
 create mode 100644 tests/tcg/ppc/system/README
 create mode 100644 tests/tcg/ppc/system/boot.S
 create mode 100644 tests/tcg/ppc/system/byte-parity.S
 create mode 100644 tests/tcg/ppc/system/fpscr.S
 create mode 100644 tests/tcg/ppc/system/isa.out
 create mode 100644 tests/tcg/ppc/system/kernel.ld
 create mode 100644 tests/tcg/ppc/system/macros.inc
 create mode 100644 tests/tcg/ppc/system/meson.build
 create mode 100644 tests/tcg/ppc/system/unsupported.S
 create mode 100644 tests/tcg/ppc64/system/meson.build

---
base-commit: 2a0ac9c8ac2d303ca515dc819043409aef18cab5
branch: ppc-fsl-booke

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/17 target/ppc: Correct PIR write access on e500 cores

The BookE PIR registration reuses the classic PowerPC 604 write callback, which writes SPR 1023 and masks the value to four bits. BookE PIR is SPR 286; on e500, SPR 1023 is SVR, so a PIR write can corrupt SVR while leaving PIR unchanged.

The e500v1/e500v2 manual defines PIR as read-only. The e500mc, e5500 and e6500 manuals allow hypervisor software to write PIR after reset. Reject writes on e500v1/e500v2 and use the generic 32-bit SPR write callback on the other three cores to update the correct register without the four-bit restriction.

Reference:
- E500CORERM (Rev.1), section 2.5.2
https://www.nxp.com/docs/en/reference-manual/E500CORERM.pdf
- E500MCRM (Rev.3), section 2.9.7
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.9.7
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 2.9.8
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

Fixes 76a66253e5e4 ("Great PowerPC emulation code resynchronisation and improvments")

---

 target/ppc/cpu_init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
target/ppc/cpu_init.c +3 -1
index b711f9c0a8..96bae6a6d1 100644
@@ -2837,7 +2837,9 @@ static void init_proc_e500(CPUPPCState *env, int version)
     /* Processor identification */
     spr_register(env, SPR_BOOKE_PIR, "PIR",
                  SPR_NOACCESS, SPR_NOACCESS,
-                 &spr_read_generic, &spr_write_pir,
+                 &spr_read_generic,
+                 (version == fsl_e500v1 || version == fsl_e500v2) ?
+                     SPR_NOACCESS : &spr_write_generic32,
                  0x00000000);
 
     spr_register(env, SPR_BOOKE_SPEFSCR, "SPEFSCR",
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 01/17] target/ppc: Correct PIR write access on e500 cores

Quoted 11 lines · Bin Meng

The BookE PIR registration reuses the classic PowerPC 604 write callback, which writes SPR 1023 and masks the value to four bits. BookE PIR is SPR 286; on e500, SPR 1023 is SVR, so a PIR write can corrupt SVR while leaving PIR unchanged.

The e500v1/e500v2 manual defines PIR as read-only. The e500mc, e5500 and e6500 manuals allow hypervisor software to write PIR after reset. Reject writes on e500v1/e500v2 and use the generic 32-bit SPR write callback on the other three cores to update the correct register without the four-bit restriction.

Quoted 9 lines

Reference:
- E500CORERM (Rev.1), section 2.5.2
https://www.nxp.com/docs/en/reference-manual/E500CORERM.pdf
- E500MCRM (Rev.3), section 2.9.7
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.9.7
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 2.9.8
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

I'm not sure about URLs in commit messages which might go stale. I think the reference to title and section is enough without the URL but whatever others prefer is fine with me too.

Regards,
BALATON Zoltan

author
#3 lore raw

PATCH 2/17 target/ppc: Correct the MAS5 SPR number

In reply to Bin Meng

The e500mc, e5500 and e6500 core manuals define MAS5 as SPR 339 (0x153), but the existing definition assigns it number 629 (0x275). Correct the number and place the definition in its numeric group.

While we are here, adjust the order of SPR_HEIR so that it is inserted in ascending order.

Reference: EREF_RM (Rev.1), section 4.2.2 and 4.12.10.6
https://www.nxp.com/webapp/Download?colCode=EREF_RM

Fixes 80d11f4467c4 ("Add definitions for Freescale PowerPC implementations")

---

 target/ppc/cpu.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/ppc/cpu.h +2 -2
index 3fb51bbeb8..abcbcf3c18 100644
@@ -1926,8 +1926,9 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_HMER              (0x150)
 #define SPR_HMEER             (0x151)
 #define SPR_PCR               (0x152)
-#define SPR_HEIR              (0x153)
 #define SPR_BOOKE_LPIDR       (0x152)
+#define SPR_HEIR              (0x153)
+#define SPR_BOOKE_MAS5        (0x153)
 #define SPR_BOOKE_TCR         (0x154)
 #define SPR_PPE42_TCR         (0x154)
 #define SPR_BOOKE_TLB0PS      (0x158)
@@ -2042,7 +2043,6 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_BOOKE_MAS2        (0x272)
 #define SPR_BOOKE_MAS3        (0x273)
 #define SPR_BOOKE_MAS4        (0x274)
-#define SPR_BOOKE_MAS5        (0x275)
 #define SPR_BOOKE_MAS6        (0x276)
 #define SPR_BOOKE_PID1        (0x279)
 #define SPR_BOOKE_PID2        (0x27A)
Signature · 1 line
2.53.0
author
#4 lore raw

PATCH 3/17 target/ppc: Correct the e500mc and e5500 cache block size fields

In reply to Bin Meng

The L1 configuration registers encode a 64-byte cache block with CBSIZE=1. The models instead set CBSIZE=2, advertising 128 bytes despite using 64 bytes for cache operations.

Use the correct field value for both caches.

Reference:
- E500MCRM (Rev.3), sections 2.14.4 and 2.14.5
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), sections 2.14.4 and 2.14.5
https://www.nxp.com/webapp/Download?colCode=E5500RM

Fixes a496e8eeba51 ("PPC: E500: Populate L1CFG0 SPR")
Fixes d2ea2bf740c5 ("PPC: Add L1CFG1 SPR emulation")

---

 target/ppc/cpu_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/ppc/cpu_init.c +2 -2
index 96bae6a6d1..db807f64c2 100644
@@ -2886,8 +2886,8 @@ static void init_proc_e500(CPUPPCState *env, int version)
     case fsl_e5500:
         env->dcache_line_size = 64;
         env->icache_line_size = 64;
-        l1cfg0 |= 0x1000000; /* 64 byte cache block size */
-        l1cfg1 |= 0x1000000; /* 64 byte cache block size */
+        l1cfg0 |= 0x00800000; /* 64 byte cache block size */
+        l1cfg1 |= 0x00800000; /* 64 byte cache block size */
         break;
     case fsl_e6500:
         env->dcache_line_size = 32;
Signature · 1 line
2.53.0
author
#5 lore raw

PATCH 4/17 target/ppc: Correct cache line size for e6500

In reply to Bin Meng

The e6500 L1 instruction and data caches use 64-byte cache lines. The cache configuration registers already describe this geometry, but the translator used 32-byte lines for cache operations.

Match the line sizes to the hardware so that guest cache management and dcbz agree with the reported configuration.

Reference: E6500RM (Rev.0), section 2.11.4 and 2.11.5
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

Fixes 54a50dae93fa ("ppc64: introduce e6500")

---

 target/ppc/cpu_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/ppc/cpu_init.c +2 -2
index db807f64c2..29f28be7e0 100644
@@ -2890,8 +2890,8 @@ static void init_proc_e500(CPUPPCState *env, int version)
         l1cfg1 |= 0x00800000; /* 64 byte cache block size */
         break;
     case fsl_e6500:
-        env->dcache_line_size = 32;
-        env->icache_line_size = 32;
+        env->dcache_line_size = 64;
+        env->icache_line_size = 64;
         l1cfg0 |= 0x0F83820;
         l1cfg1 |= 0x0B83820;
         break;
Signature · 1 line
2.53.0
author
#6 lore raw

PATCH 5/17 target/ppc: Complete e500mc and e5500 L1 cache configuration

In reply to Bin Meng

The e500mc and e5500 manuals specify pseudo-LRU replacement, cache locking and parity detection for both L1 caches. The reset values describe the block size, associativity and capacity, but leave CREPL/ICREPL, CLA/ICLA and CPA/ICPA clear.

Set those fields to their documented values so both L1CFG0 and L1CFG1 reset to 0x00B83820, including the shared eight-way, 32 KiB cache geometry.

Reference:
- E500MCRM (Rev.3), section 2.14.4 and 2.14.5
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.14.4 and 2.14.5
https://www.nxp.com/webapp/Download?colCode=E5500RM

---

 target/ppc/cpu_init.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/cpu_init.c +3 -2
index 29f28be7e0..fec672a8a6 100644
@@ -2886,8 +2886,9 @@ static void init_proc_e500(CPUPPCState *env, int version)
     case fsl_e5500:
         env->dcache_line_size = 64;
         env->icache_line_size = 64;
-        l1cfg0 |= 0x00800000; /* 64 byte cache block size */
-        l1cfg1 |= 0x00800000; /* 64 byte cache block size */
+        /* 64 byte blocks, pseudo-LRU replacement, cache locking and parity */
+        l1cfg0 |= 0x00B80000;
+        l1cfg1 |= 0x00B80000;
         break;
     case fsl_e6500:
         env->dcache_line_size = 64;
Signature · 1 line
2.53.0
author
#7 lore raw

PATCH 6/17 target/ppc: Drop redundant e6500 L1 cache geometry bits

In reply to Bin Meng

The shared L1CFG0 and L1CFG1 initializers already set 0x3820 for eight ways and 32 KiB. The e6500 masks repeat those same bits. Keep only the e6500-specific upper fields in the masks.

Reference: E6500RM (Rev.0), section 2.11.4 and 2.11.5
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/ppc/cpu_init.c +2 -2
index fec672a8a6..23f25a56c0 100644
@@ -2893,8 +2893,8 @@ static void init_proc_e500(CPUPPCState *env, int version)
     case fsl_e6500:
         env->dcache_line_size = 64;
         env->icache_line_size = 64;
-        l1cfg0 |= 0x0F83820;
-        l1cfg1 |= 0x0B83820;
+        l1cfg0 |= 0x00F80000;
+        l1cfg1 |= 0x00B80000;
         break;
     default:
         cpu_abort(env_cpu(env), "Unknown CPU: " TARGET_FMT_lx "\n",
Signature · 1 line
2.53.0
author
#8 lore raw

PATCH 7/17 target/ppc: Register L1CSR2 on e500mc/e5500/e6500 cores

In reply to Bin Meng

U-Boot programs the L1 data cache stash identifier before entering its C initialization code. The e500mc, e5500 and e6500 core manuals define L1CSR2 as a 32-bit SPR with number 606 (0x25e) and reset value zero.

Expose the register on all three cores, excluding e500v1 and e500v2.

Reference:
- E500MCRM (Rev.3), section 2.14.3
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.14.3
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 2.11.3
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu.h      | 1 +
 target/ppc/cpu_init.c | 4 ++++
 2 files changed, 5 insertions(+)
target/ppc/cpu.h +1 -0
index abcbcf3c18..d3f1c82730 100644
@@ -2038,6 +2038,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_BOOKE_DSRR1       (0x23F)
 #define SPR_BOOKE_SPRG8       (0x25C)
 #define SPR_BOOKE_SPRG9       (0x25D)
+#define SPR_Exxx_L1CSR2       (0x25E)
 #define SPR_BOOKE_MAS0        (0x270)
 #define SPR_BOOKE_MAS1        (0x271)
 #define SPR_BOOKE_MAS2        (0x272)
target/ppc/cpu_init.c +4 -0
index 23f25a56c0..e5856b5b1d 100644
@@ -2965,6 +2965,10 @@ static void init_proc_e500(CPUPPCState *env, int version)
                  &spr_read_generic, &spr_write_e500_l1csr1,
                  0x00000000);
     if (version != fsl_e500v1 && version != fsl_e500v2) {
+        spr_register(env, SPR_Exxx_L1CSR2, "L1CSR2",
+                     SPR_NOACCESS, SPR_NOACCESS,
+                     &spr_read_generic, &spr_write_generic32,
+                     0x00000000);
         spr_register(env, SPR_Exxx_L2CSR0, "L2CSR0",
                      SPR_NOACCESS, SPR_NOACCESS,
                      &spr_read_generic, &spr_write_e500_l2csr0,
Signature · 1 line
2.53.0
#9 lore raw

Re: [PATCH 07/17] target/ppc: Register L1CSR2 on e500mc/e5500/e6500 cores

Quoted 27 lines · Bin Meng

U-Boot programs the L1 data cache stash identifier before entering its C initialization code. The e500mc, e5500 and e6500 core manuals define L1CSR2 as a 32-bit SPR with number 606 (0x25e) and reset value zero.

Expose the register on all three cores, excluding e500v1 and e500v2.

Reference:
- E500MCRM (Rev.3), section 2.14.3
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.14.3
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 2.11.3
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

target/ppc/cpu.h | 1 +
target/ppc/cpu_init.c | 4 ++++

2 files changed, 5 insertions(+)
target/ppc/cpu.h +0 -0
index abcbcf3c18..d3f1c82730 100644

target/ppc/cpu.h void ppc_compat_add_property(Object *obj, const char *name, · line 2041

Quoted 4 lines
target/ppc/cpu.h +1 -0
@@ -2038,6 +2038,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_BOOKE_DSRR1       (0x23F)
 #define SPR_BOOKE_SPRG8       (0x25C)
 #define SPR_BOOKE_SPRG9       (0x25D)
+#define SPR_Exxx_L1CSR2       (0x25E)

This name is too unspecific. Did you mean E5xx or something similar? Or could just be E500MC with 5500 and 6500 being derivative of that.

Regards,
BALATON Zoltan

Quoted 19 lines
target/ppc/cpu.h +0 -0
 #define SPR_BOOKE_MAS0        (0x270)
 #define SPR_BOOKE_MAS1        (0x271)
 #define SPR_BOOKE_MAS2        (0x272)
target/ppc/cpu_init.c +4 -0
index 23f25a56c0..e5856b5b1d 100644
@@ -2965,6 +2965,10 @@ static void init_proc_e500(CPUPPCState *env, int version)
                 &spr_read_generic, &spr_write_e500_l1csr1,
                 0x00000000);
    if (version != fsl_e500v1 && version != fsl_e500v2) {
+        spr_register(env, SPR_Exxx_L1CSR2, "L1CSR2",
+                     SPR_NOACCESS, SPR_NOACCESS,
+                     &spr_read_generic, &spr_write_generic32,
+                     0x00000000);
        spr_register(env, SPR_Exxx_L2CSR0, "L2CSR0",
                     SPR_NOACCESS, SPR_NOACCESS,
                     &spr_read_generic, &spr_write_e500_l2csr0,
author
#10 lore raw

PATCH 8/17 target/ppc: Register L2CFG0 and L2CSR1 on e500mc and e5500

In reply to Bin Meng

The e500mc and e5500 core manuals define L2CFG0 as read-only SPR 519 (0x207) and L2CSR1 as writable SPR 1018 (0x3fa). U-Boot reads the former to discover the private L2 cache and programs the latter to select its stash ID. Missing registrations leave cache discovery and stash setup incomplete.

Expose both registers on e500mc and e5500. Use the 128 KiB L2 geometry specified by the e500mc manual and a 256 KiB default for e5500, matching T1040/T1024. Other SoC integrations can override the capacity.

Note the e6500 shared L2 uses memory-mapped registers, hence we do not add these SPRs to that core.

Reference:
- E500MCRM (Rev.3), section 2.15.1 and 2.15.3
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.15.1 and 2.15.3
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 2.12.1 and 2.12.3
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu.h      |  2 ++
 target/ppc/cpu_init.c | 14 ++++++++++++++
 2 files changed, 16 insertions(+)
target/ppc/cpu.h +2 -0
index d3f1c82730..498b505a96 100644
@@ -1976,6 +1976,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_Exxx_L1CFG0       (0x203)
 #define SPR_Exxx_L1CFG1       (0x204)
 #define SPR_Exxx_NPIDR        (0x205)
+#define SPR_Exxx_L2CFG0       (0x207)
 #define SPR_ATBL              (0x20E)
 #define SPR_ATBU              (0x20F)
 #define SPR_IBAT0U            (0x210)
@@ -2341,6 +2342,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_750_TDCH          (0x3FA)
 #define SPR_IABR2             (0x3FA)
 #define SPR_40x_DCCR          (0x3FA)
+#define SPR_Exxx_L2CSR1       (0x3FA)
 #define SPR_ICTC              (0x3FB)
 #define SPR_40x_ICCR          (0x3FB)
 #define SPR_THRM1             (0x3FC)
target/ppc/cpu_init.c +14 -0
index e5856b5b1d..21c6012fa1 100644
@@ -2974,6 +2974,20 @@ static void init_proc_e500(CPUPPCState *env, int version)
                      &spr_read_generic, &spr_write_e500_l2csr0,
                      0x00000000);
     }
+    if (version == fsl_e500mc || version == fsl_e5500) {
+        /*
+         * L2CSIZE is in 64 KiB units. Use 128 KiB for e500mc and a
+         * 256 KiB default for e5500, matching the T1040/T1024 SoCs.
+         * Other SoC models can override the e5500 capacity.
+         */
+        spr_register(env, SPR_Exxx_L2CFG0, "L2CFG0",
+                     &spr_read_generic, SPR_NOACCESS,
+                     &spr_read_generic, SPR_NOACCESS,
+                     version == fsl_e500mc ? 0x3cb1c002 : 0x3cb1c004);
+        spr_register(env, SPR_Exxx_L2CSR1, "L2CSR1",
+                     SPR_NOACCESS, SPR_NOACCESS,
+                     &spr_read_generic, &spr_write_generic32, 0);
+    }
     spr_register(env, SPR_BOOKE_MCSRR0, "MCSRR0",
                  SPR_NOACCESS, SPR_NOACCESS,
                  &spr_read_generic, &spr_write_generic,
Signature · 1 line
2.53.0
#11 lore raw

Re: [PATCH 08/17] target/ppc: Register L2CFG0 and L2CSR1 on e500mc and e5500

Quoted 33 lines · Bin Meng

The e500mc and e5500 core manuals define L2CFG0 as read-only SPR 519 (0x207) and L2CSR1 as writable SPR 1018 (0x3fa). U-Boot reads the former to discover the private L2 cache and programs the latter to select its stash ID. Missing registrations leave cache discovery and stash setup incomplete.

Expose both registers on e500mc and e5500. Use the 128 KiB L2 geometry specified by the e500mc manual and a 256 KiB default for e5500, matching T1040/T1024. Other SoC integrations can override the capacity.

Note the e6500 shared L2 uses memory-mapped registers, hence we do not add these SPRs to that core.

Reference:
- E500MCRM (Rev.3), section 2.15.1 and 2.15.3
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.15.1 and 2.15.3
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 2.12.1 and 2.12.3
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

target/ppc/cpu.h | 2 ++
target/ppc/cpu_init.c | 14 ++++++++++++++

2 files changed, 16 insertions(+)
target/ppc/cpu.h +0 -0
index d3f1c82730..498b505a96 100644

target/ppc/cpu.h void ppc_compat_add_property(Object *obj, const char *name, · line 1979

Quoted 4 lines
target/ppc/cpu.h +1 -0
@@ -1976,6 +1976,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_Exxx_L1CFG0       (0x203)
 #define SPR_Exxx_L1CFG1       (0x204)
 #define SPR_Exxx_NPIDR        (0x205)
+#define SPR_Exxx_L2CFG0       (0x207)

I see there are more of these already. Disregard previous comment in that case.

Regards,
BALATON Zoltan

Quoted 37 lines
target/ppc/cpu.h +1 -0
 #define SPR_ATBL              (0x20E)
 #define SPR_ATBU              (0x20F)
 #define SPR_IBAT0U            (0x210)
@@ -2341,6 +2342,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_750_TDCH          (0x3FA)
 #define SPR_IABR2             (0x3FA)
 #define SPR_40x_DCCR          (0x3FA)
+#define SPR_Exxx_L2CSR1       (0x3FA)
 #define SPR_ICTC              (0x3FB)
 #define SPR_40x_ICCR          (0x3FB)
 #define SPR_THRM1             (0x3FC)
target/ppc/cpu_init.c +14 -0
index e5856b5b1d..21c6012fa1 100644
@@ -2974,6 +2974,20 @@ static void init_proc_e500(CPUPPCState *env, int version)
                     &spr_read_generic, &spr_write_e500_l2csr0,
                     0x00000000);
    }
+    if (version == fsl_e500mc || version == fsl_e5500) {
+        /*
+         * L2CSIZE is in 64 KiB units. Use 128 KiB for e500mc and a
+         * 256 KiB default for e5500, matching the T1040/T1024 SoCs.
+         * Other SoC models can override the e5500 capacity.
+         */
+        spr_register(env, SPR_Exxx_L2CFG0, "L2CFG0",
+                     &spr_read_generic, SPR_NOACCESS,
+                     &spr_read_generic, SPR_NOACCESS,
+                     version == fsl_e500mc ? 0x3cb1c002 : 0x3cb1c004);
+        spr_register(env, SPR_Exxx_L2CSR1, "L2CSR1",
+                     SPR_NOACCESS, SPR_NOACCESS,
+                     &spr_read_generic, &spr_write_generic32, 0);
+    }
    spr_register(env, SPR_BOOKE_MCSRR0, "MCSRR0",
                 SPR_NOACCESS, SPR_NOACCESS,
                 &spr_read_generic, &spr_write_generic,
author
#12 lore raw

PATCH 9/17 target/ppc: Register MAS5 and MAS8 on e500mc/e5500/e6500

In reply to Bin Meng

The e500mc, e5500 and e6500 core manuals define MAS5 and MAS8 as SPRs 339 (0x153) and 341 (0x155). MAS5 supplies GS and LPID values for TLB searches and invalidations, while MAS8 holds guest-space and LPID context for TLB entries.

Register both alongside the other BookE MMU assist registers using the existing 32-bit SPR storage. Exclude e500v1 and e500v2, which do not implement MAS5 or MAS8.

Reference:
- E500MCRM (Rev.3), section 2.16.6.6 and 2.16.6.9
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 2.16.6.6 and 2.16.6.9
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 2.13.10.6 and 2.13.10.9
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu.h      | 1 +
 target/ppc/cpu_init.c | 8 ++++++++
 2 files changed, 9 insertions(+)
target/ppc/cpu.h +1 -0
index 498b505a96..9d3d27be91 100644
@@ -1931,6 +1931,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_BOOKE_MAS5        (0x153)
 #define SPR_BOOKE_TCR         (0x154)
 #define SPR_PPE42_TCR         (0x154)
+#define SPR_BOOKE_MAS8        (0x155)
 #define SPR_BOOKE_TLB0PS      (0x158)
 #define SPR_BOOKE_TLB1PS      (0x159)
 #define SPR_BOOKE_TLB2PS      (0x15A)
target/ppc/cpu_init.c +8 -0
index 21c6012fa1..032b8b606e 100644
@@ -2901,6 +2901,14 @@ static void init_proc_e500(CPUPPCState *env, int version)
                   env->spr[SPR_PVR]);
     }
     register_BookE206_sprs(env, 0x000000DF, tlbncfg, mmucfg);
+    if (version != fsl_e500v1 && version != fsl_e500v2) {
+        spr_register(env, SPR_BOOKE_MAS5, "MAS5",
+                     SPR_NOACCESS, SPR_NOACCESS,
+                     &spr_read_generic, &spr_write_generic32, 0);
+        spr_register(env, SPR_BOOKE_MAS8, "MAS8",
+                     SPR_NOACCESS, SPR_NOACCESS,
+                     &spr_read_generic, &spr_write_generic32, 0);
+    }
     register_usprgh_sprs(env);
 
     if (version != fsl_e500v1) {
Signature · 1 line
2.53.0
author
#13 lore raw

PATCH 10/17 target/ppc: Register PWRMGTCR0 on e6500

In reply to Bin Meng

The e6500 core manual defines PWRMGTCR0 as SPR 1019 (0x3fb). QorIQ U-Boot and kernel access its fields during processor power setup.

Define and register PWRMGTCR0 using the existing 32-bit SPR storage to retain the programmed control fields.

Reference: E6500RM (Rev.0), section 2.7.7
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu.h      | 1 +
 target/ppc/cpu_init.c | 3 +++
 2 files changed, 4 insertions(+)
target/ppc/cpu.h +1 -0
index 9d3d27be91..b716ccf540 100644
@@ -2346,6 +2346,7 @@ void ppc_compat_add_property(Object *obj, const char *name,
 #define SPR_Exxx_L2CSR1       (0x3FA)
 #define SPR_ICTC              (0x3FB)
 #define SPR_40x_ICCR          (0x3FB)
+#define SPR_Exxx_PWRMGTCR0    (0x3FB)
 #define SPR_THRM1             (0x3FC)
 #define SPR_403_PBL1          (0x3FC)
 #define SPR_SP                (0x3FD)
target/ppc/cpu_init.c +3 -0
index 032b8b606e..4d12152659 100644
@@ -3026,6 +3026,9 @@ static void init_proc_e500(CPUPPCState *env, int version)
     }
 
     if (version == fsl_e6500) {
+        spr_register(env, SPR_Exxx_PWRMGTCR0, "PWRMGTCR0",
+                     SPR_NOACCESS, SPR_NOACCESS,
+                     &spr_read_generic, &spr_write_generic32, 0);
         /* Thread identification */
         spr_register(env, SPR_TIR, "TIR",
                      SPR_NOACCESS, SPR_NOACCESS,
Signature · 1 line
2.53.0
author
#14 lore raw

PATCH 11/17 target/ppc: Register IVOR42 on e6500

In reply to Bin Meng

The e6500 core manual defines IVOR42 as the LRAT error interrupt offset register. U-Boot programs it during interrupt setup, but currently the QEMU e6500 IVOR mask currently excludes bit 42.

Include IVOR42 in the mask so the existing BookE SPR registration exposes its offset. This permits the register accesses without implementing LRAT translation or LRAT exception delivery.

Reference: E6500RM (Rev.0), section 2.9.5 and 4.9.22
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/cpu_init.c +1 -1
index 4d12152659..5077f3300e 100644
@@ -2824,7 +2824,7 @@ static void init_proc_e500(CPUPPCState *env, int version)
         ivor_mask = 0x000003FE0000FFFFULL;
         break;
     case fsl_e6500:
-        ivor_mask = 0x000003FF0000FFFFULL;
+        ivor_mask = 0x000007FF0000FFFFULL;
         break;
     }
     register_BookE_sprs(env, ivor_mask);
Signature · 1 line
2.53.0
author
#15 lore raw

PATCH 12/17 target/ppc: Split the ISA 2.05 instruction feature group

In reply to Bin Meng

The ISA 2.05 flag couples integer instructions to floating-point instructions and extended FPSCR access. The e5500 and e6500 implement cmpb and parity instructions but lack these floating-point features, so enabling the entire group cannot describe their hardware.

Give byte comparison, parity, copy sign, integer word loads, paired floating-point transfers and extended FPSCR access separate flags. Keep the existing capabilities of POWER7 and later models, and include all new flags in the TCG supported instruction mask.

---

 target/ppc/cpu.h                           | 20 ++++++++++++++++----
 target/ppc/cpu_init.h                      |  5 ++++-
 target/ppc/cpu_init.c                      | 10 ++++++++--
 target/ppc/translate.c                     | 10 ++++++----
 target/ppc/translate/fixedpoint-impl.c.inc |  6 +++---
 target/ppc/translate/fp-impl.c.inc         |  8 ++++----
 target/ppc/translate/fp-ops.c.inc          |  9 ++++++---
 7 files changed, 47 insertions(+), 21 deletions(-)
target/ppc/cpu.h +16 -4
index b716ccf540..78fa4653fb 100644
@@ -2568,8 +2568,8 @@ enum {
     PPC2_PRCNTL        = 0x0000000000000008ULL,
     /* Byte-reversed, indexed, double-word load and store                    */
     PPC2_DBRX          = 0x0000000000000010ULL,
-    /* Book I 2.05 PowerPC specification                                     */
-    PPC2_ISA205        = 0x0000000000000020ULL,
+    /* ISA 2.05 cmpb */
+    PPC2_CMPB_ISA205   = 0x0000000000000020ULL,
     /* POWER ISA 2.07                                                        */
     PPC2_ISA207        = 0x0000000000000040ULL,
     /* ISA 2.06B bpermd                                                      */
@@ -2602,15 +2602,27 @@ enum {
     PPC2_PPE42X        = 0x0000000000100000ULL,
     /* PPE42XM instructions                                                  */
     PPC2_PPE42XM       = 0x0000000000200000ULL,
+    /* ISA 2.05 prtyw and prtyd */
+    PPC2_PRTY_ISA205   = 0x0000000000800000ULL,
+    /* ISA 2.05 fcpsgn */
+    PPC2_FCPSGN_ISA205 = 0x0000000001000000ULL,
+    /* ISA 2.05 lfiwax */
+    PPC2_LFIWAX_ISA205 = 0x0000000002000000ULL,
+    /* ISA 2.05 floating-point pair loads and stores */
+    PPC2_FP_PAIR_ISA205 = 0x0000000004000000ULL,
+    /* ISA 2.05 FPSCR access through the W and L fields */
+    PPC2_FPSCR_EXT_ISA205 = 0x0000000008000000ULL,
 
 #define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_VSX | PPC2_PRCNTL | PPC2_DBRX | \
-                        PPC2_ISA205 | PPC2_ISA207 | PPC2_PERM_ISA206 | \
+                        PPC2_CMPB_ISA205 | PPC2_ISA207 | PPC2_PERM_ISA206 | \
                         PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 | \
                         PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206 | PPC2_DFP | \
                         PPC2_FP_CVT_S64 | PPC2_TM | PPC2_PM_ISA206 | \
                         PPC2_ISA300 | PPC2_ISA310 | PPC2_MEM_LWSYNC | \
                         PPC2_BCDA_ISA206 | PPC2_PPE42 | PPC2_PPE42X | \
-                        PPC2_PPE42XM)
+                        PPC2_PPE42XM | PPC2_PRTY_ISA205 | \
+                        PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 | \
+                        PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205)
 };
 
 /*****************************************************************************/
target/ppc/cpu_init.h +4 -1
index 4ba559d8af..e70f1baa74 100644
@@ -17,7 +17,10 @@
 #define PPC_INSNS_FLAGS2_POWER_COMMON                                \
     (PPC2_VSX | PPC2_ISA207 | PPC2_DFP | PPC2_DBRX |                 \
      PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 |      \
-     PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206 | PPC2_ISA205 |         \
+     PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206 |                       \
+     PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205 |                          \
+     PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 |                      \
+     PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205 |                   \
      PPC2_FP_CVT_S64 | PPC2_ISA300 | PPC2_PRCNTL |                   \
      PPC2_MEM_LWSYNC | PPC2_BCDA_ISA206)
 
target/ppc/cpu_init.c +8 -2
index 5077f3300e..f2a342b076 100644
@@ -6220,7 +6220,10 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, const void *data)
                        PPC_SEGMENT_64B | PPC_SLBI |
                        PPC_POPCNTB | PPC_POPCNTWD |
                        PPC_CILDST;
-    pcc->insns_flags2 = PPC2_VSX | PPC2_DFP | PPC2_DBRX | PPC2_ISA205 |
+    pcc->insns_flags2 = PPC2_VSX | PPC2_DFP | PPC2_DBRX |
+                        PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205 |
+                        PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 |
+                        PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205 |
                         PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
                         PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
                         PPC2_FP_TST_ISA206 | PPC2_FP_CVT_S64 |
@@ -6381,7 +6384,10 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, const void *data)
     pcc->insns_flags2 = PPC2_VSX | PPC2_ISA207 | PPC2_DFP | PPC2_DBRX |
                         PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
                         PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
-                        PPC2_FP_TST_ISA206 | PPC2_ISA205 | PPC2_FP_CVT_S64 |
+                        PPC2_FP_TST_ISA206 | PPC2_FP_CVT_S64 |
+                        PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205 |
+                        PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 |
+                        PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205 |
                         PPC2_TM | PPC2_PM_ISA206 | PPC2_MEM_LWSYNC |
                         PPC2_BCDA_ISA206;
     pcc->msr_mask = (1ull << MSR_SF) |
target/ppc/translate.c +6 -4
index 467b8f3d4e..c00581fc36 100644
@@ -4403,7 +4403,7 @@ static bool trans_ICBIEP(DisasContext *ctx, arg_X_ea *a)
 static void gen_dform39(DisasContext *ctx)
 {
     if ((ctx->opcode & 0x3) == 0) {
-        if (ctx->insns_flags2 & PPC2_ISA205) {
+        if (ctx->insns_flags2 & PPC2_FP_PAIR_ISA205) {
             return gen_lfdp(ctx);
         }
     }
@@ -4415,7 +4415,7 @@ static void gen_dform3D(DisasContext *ctx)
 {
     if ((ctx->opcode & 3) == 0) { /* DS-FORM */
         /* stfdp */
-        if (ctx->insns_flags2 & PPC2_ISA205) {
+        if (ctx->insns_flags2 & PPC2_FP_PAIR_ISA205) {
             return gen_stfdp(ctx);
         }
     }
@@ -4429,9 +4429,11 @@ GEN_HANDLER_E(cp_abort, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER_E(paste, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE, PPC2_ISA300),
 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
 /* handles lfdp, lxsd, lxssp */
-GEN_HANDLER_E(dform39, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(dform39, 0x39, 0xFF, 0xFF, 0x00000000,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
 /* handles stfdp, stxsd, stxssp */
-GEN_HANDLER_E(dform3D, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(dform3D, 0x3D, 0xFF, 0xFF, 0x00000000,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
target/ppc/translate/fixedpoint-impl.c.inc +3 -3
index c3d8bbf267..0c6ec91400 100644
@@ -1545,7 +1545,7 @@ static bool trans_XOR(DisasContext *ctx, arg_XOR *a)
 
 static bool trans_CMPB(DisasContext *ctx, arg_CMPB *a)
 {
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, CMPB_ISA205);
     gen_helper_CMPB(cpu_gpr[a->ra], cpu_gpr[a->rt], cpu_gpr[a->rb]);
     return true;
 }
@@ -1636,7 +1636,7 @@ static bool trans_PRTYW(DisasContext *ctx, arg_PRTYW *a)
     TCGv rs = cpu_gpr[a->rs];
     TCGv t0 = tcg_temp_new();
 
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, PRTY_ISA205);
     tcg_gen_shri_tl(t0, rs, 16);
     tcg_gen_xor_tl(ra, rs, t0);
     tcg_gen_shri_tl(t0, ra, 8);
@@ -1652,7 +1652,7 @@ static bool trans_PRTYD(DisasContext *ctx, arg_PRTYD *a)
     TCGv t0 = tcg_temp_new();
 
     REQUIRE_64BIT(ctx);
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, PRTY_ISA205);
     tcg_gen_shri_tl(t0, rs, 32);
     tcg_gen_xor_tl(ra, rs, t0);
     tcg_gen_shri_tl(t0, ra, 16);
target/ppc/translate/fp-impl.c.inc +4 -4
index e0d9fa2e24..fef770368a 100644
@@ -324,7 +324,7 @@ TRANS(FNABS, do_move_b, 1ULL << 63, tcg_gen_ori_i64);
 static bool trans_FCPSGN(DisasContext *ctx, arg_FCPSGN *a)
 {
     TCGv_i64 t0, t1, t2;
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, FCPSGN_ISA205);
     REQUIRE_FPU(ctx);
     t0 = tcg_temp_new_i64();
     t1 = tcg_temp_new_i64();
@@ -592,13 +592,13 @@ static void gen_mtfsf(DisasContext *ctx)
     flm = FPFLM(ctx->opcode);
     l = FPL(ctx->opcode);
     w = FPW(ctx->opcode);
-    if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
+    if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
         gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         return;
     }
     if (!l) {
         t0 = tcg_constant_i32(flm << (w * 8));
-    } else if (ctx->insns_flags2 & PPC2_ISA205) {
+    } else if (ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205) {
         t0 = tcg_constant_i32(0xffff);
     } else {
         t0 = tcg_constant_i32(0xff);
@@ -627,7 +627,7 @@ static void gen_mtfsfi(DisasContext *ctx)
     }
     w = FPW(ctx->opcode);
     bf = FPBF(ctx->opcode);
-    if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
+    if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
         gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         return;
     }
target/ppc/translate/fp-ops.c.inc +6 -3
index 9bc9c3a3c3..e6a0d88dd4 100644
@@ -1,14 +1,17 @@
 GEN_HANDLER_E(lfdepx, 0x1F, 0x1F, 0x12, 0x00000001, PPC_NONE, PPC2_BOOKE206),
-GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001,
+              PPC_NONE, PPC2_LFIWAX_ISA205),
 GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
-GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
 
 #define GEN_STXF(name, stop, opc2, opc3, type)                                \
 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
 
 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
 GEN_HANDLER_E(stfdepx, 0x1F, 0x1F, 0x16, 0x00000001, PPC_NONE, PPC2_BOOKE206),
-GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
 
 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
Signature · 1 line
2.53.0
#16 lore raw

Re: [PATCH 12/17] target/ppc: Split the ISA 2.05 instruction feature group

Quoted 38 lines · Bin Meng

The ISA 2.05 flag couples integer instructions to floating-point instructions and extended FPSCR access. The e5500 and e6500 implement cmpb and parity instructions but lack these floating-point features, so enabling the entire group cannot describe their hardware.

Give byte comparison, parity, copy sign, integer word loads, paired floating-point transfers and extended FPSCR access separate flags. Keep the existing capabilities of POWER7 and later models, and include all new flags in the TCG supported instruction mask.

---

  target/ppc/cpu.h                           | 20 ++++++++++++++++----
  target/ppc/cpu_init.h                      |  5 ++++-
  target/ppc/cpu_init.c                      | 10 ++++++++--
  target/ppc/translate.c                     | 10 ++++++----
  target/ppc/translate/fixedpoint-impl.c.inc |  6 +++---
  target/ppc/translate/fp-impl.c.inc         |  8 ++++----
  target/ppc/translate/fp-ops.c.inc          |  9 ++++++---
  7 files changed, 47 insertions(+), 21 deletions(-)
target/ppc/cpu.h +2 -2
index b716ccf540..78fa4653fb 100644
@@ -2568,8 +2568,8 @@ enum {
      PPC2_PRCNTL        = 0x0000000000000008ULL,
      /* Byte-reversed, indexed, double-word load and store                    */
      PPC2_DBRX          = 0x0000000000000010ULL,
-    /* Book I 2.05 PowerPC specification                                     */
-    PPC2_ISA205        = 0x0000000000000020ULL,
+    /* ISA 2.05 cmpb */
+    PPC2_CMPB_ISA205   = 0x0000000000000020ULL,
      /* POWER ISA 2.07                                                        */
      PPC2_ISA207        = 0x0000000000000040ULL,
      /* ISA 2.06B bpermd                                                      */

target/ppc/cpu.h enum { · line 2606

Quoted 5 lines
target/ppc/cpu.h +2 -0
@@ -2602,15 +2602,27 @@ enum {
      PPC2_PPE42X        = 0x0000000000100000ULL,
      /* PPE42XM instructions                                                  */
      PPC2_PPE42XM       = 0x0000000000200000ULL,
+    /* ISA 2.05 prtyw and prtyd */
+    PPC2_PRTY_ISA205   = 0x0000000000800000ULL,

Hey,
You have skipped a bit in the flag here. PPC2_PRTY_ISA205 flag should be  0x0000000000400000ULL instead of 0x0000000000800000ULL.

target/ppc/cpu.h enum { · line 2614

Quoted 8 lines
target/ppc/cpu.h +8 -0
+    /* ISA 2.05 fcpsgn */
+    PPC2_FCPSGN_ISA205 = 0x0000000001000000ULL,
+    /* ISA 2.05 lfiwax */
+    PPC2_LFIWAX_ISA205 = 0x0000000002000000ULL,
+    /* ISA 2.05 floating-point pair loads and stores */
+    PPC2_FP_PAIR_ISA205 = 0x0000000004000000ULL,
+    /* ISA 2.05 FPSCR access through the W and L fields */
+    PPC2_FPSCR_EXT_ISA205 = 0x0000000008000000ULL,

Please keep the '=' sign in the flag definitions aligned so as to help prevent error as the one pointed out above. While we are at it, please keep the comment end '*/' aligned as well.

Thanks,
Chinmay

Quoted 190 lines
target/ppc/cpu.h +4 -2
  #define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_VSX | PPC2_PRCNTL | PPC2_DBRX | \
-                        PPC2_ISA205 | PPC2_ISA207 | PPC2_PERM_ISA206 | \
+                        PPC2_CMPB_ISA205 | PPC2_ISA207 | PPC2_PERM_ISA206 | \
                          PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 | \
                          PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206 | PPC2_DFP | \
                          PPC2_FP_CVT_S64 | PPC2_TM | PPC2_PM_ISA206 | \
                          PPC2_ISA300 | PPC2_ISA310 | PPC2_MEM_LWSYNC | \
                          PPC2_BCDA_ISA206 | PPC2_PPE42 | PPC2_PPE42X | \
-                        PPC2_PPE42XM)
+                        PPC2_PPE42XM | PPC2_PRTY_ISA205 | \
+                        PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 | \
+                        PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205)
  };
 
  /*****************************************************************************/
target/ppc/cpu_init.h +4 -1
index 4ba559d8af..e70f1baa74 100644
@@ -17,7 +17,10 @@
  #define PPC_INSNS_FLAGS2_POWER_COMMON                                \
      (PPC2_VSX | PPC2_ISA207 | PPC2_DFP | PPC2_DBRX |                 \
       PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 |      \
-     PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206 | PPC2_ISA205 |         \
+     PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206 |                       \
+     PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205 |                          \
+     PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 |                      \
+     PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205 |                   \
       PPC2_FP_CVT_S64 | PPC2_ISA300 | PPC2_PRCNTL |                   \
       PPC2_MEM_LWSYNC | PPC2_BCDA_ISA206)
 
target/ppc/cpu_init.c +8 -2
index 5077f3300e..f2a342b076 100644
@@ -6220,7 +6220,10 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, const void *data)
                         PPC_SEGMENT_64B | PPC_SLBI |
                         PPC_POPCNTB | PPC_POPCNTWD |
                         PPC_CILDST;
-    pcc->insns_flags2 = PPC2_VSX | PPC2_DFP | PPC2_DBRX | PPC2_ISA205 |
+    pcc->insns_flags2 = PPC2_VSX | PPC2_DFP | PPC2_DBRX |
+                        PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205 |
+                        PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 |
+                        PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205 |
                          PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
                          PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
                          PPC2_FP_TST_ISA206 | PPC2_FP_CVT_S64 |
@@ -6381,7 +6384,10 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, const void *data)
      pcc->insns_flags2 = PPC2_VSX | PPC2_ISA207 | PPC2_DFP | PPC2_DBRX |
                          PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 |
                          PPC2_ATOMIC_ISA206 | PPC2_FP_CVT_ISA206 |
-                        PPC2_FP_TST_ISA206 | PPC2_ISA205 | PPC2_FP_CVT_S64 |
+                        PPC2_FP_TST_ISA206 | PPC2_FP_CVT_S64 |
+                        PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205 |
+                        PPC2_FCPSGN_ISA205 | PPC2_LFIWAX_ISA205 |
+                        PPC2_FP_PAIR_ISA205 | PPC2_FPSCR_EXT_ISA205 |
                          PPC2_TM | PPC2_PM_ISA206 | PPC2_MEM_LWSYNC |
                          PPC2_BCDA_ISA206;
      pcc->msr_mask = (1ull << MSR_SF) |
target/ppc/translate.c +6 -4
index 467b8f3d4e..c00581fc36 100644
@@ -4403,7 +4403,7 @@ static bool trans_ICBIEP(DisasContext *ctx, arg_X_ea *a)
  static void gen_dform39(DisasContext *ctx)
  {
      if ((ctx->opcode & 0x3) == 0) {
-        if (ctx->insns_flags2 & PPC2_ISA205) {
+        if (ctx->insns_flags2 & PPC2_FP_PAIR_ISA205) {
              return gen_lfdp(ctx);
          }
      }
@@ -4415,7 +4415,7 @@ static void gen_dform3D(DisasContext *ctx)
  {
      if ((ctx->opcode & 3) == 0) { /* DS-FORM */
          /* stfdp */
-        if (ctx->insns_flags2 & PPC2_ISA205) {
+        if (ctx->insns_flags2 & PPC2_FP_PAIR_ISA205) {
              return gen_stfdp(ctx);
          }
      }
@@ -4429,9 +4429,11 @@ GEN_HANDLER_E(cp_abort, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE, PPC2_ISA300),
  GEN_HANDLER_E(paste, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE, PPC2_ISA300),
  GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
  /* handles lfdp, lxsd, lxssp */
-GEN_HANDLER_E(dform39, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(dform39, 0x39, 0xFF, 0xFF, 0x00000000,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
  /* handles stfdp, stxsd, stxssp */
-GEN_HANDLER_E(dform3D, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(dform3D, 0x3D, 0xFF, 0xFF, 0x00000000,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
  GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
  GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
  GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
target/ppc/translate/fixedpoint-impl.c.inc +3 -3
index c3d8bbf267..0c6ec91400 100644
@@ -1545,7 +1545,7 @@ static bool trans_XOR(DisasContext *ctx, arg_XOR *a)
 
  static bool trans_CMPB(DisasContext *ctx, arg_CMPB *a)
  {
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, CMPB_ISA205);
      gen_helper_CMPB(cpu_gpr[a->ra], cpu_gpr[a->rt], cpu_gpr[a->rb]);
      return true;
  }
@@ -1636,7 +1636,7 @@ static bool trans_PRTYW(DisasContext *ctx, arg_PRTYW *a)
      TCGv rs = cpu_gpr[a->rs];
      TCGv t0 = tcg_temp_new();
 
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, PRTY_ISA205);
      tcg_gen_shri_tl(t0, rs, 16);
      tcg_gen_xor_tl(ra, rs, t0);
      tcg_gen_shri_tl(t0, ra, 8);
@@ -1652,7 +1652,7 @@ static bool trans_PRTYD(DisasContext *ctx, arg_PRTYD *a)
      TCGv t0 = tcg_temp_new();
 
      REQUIRE_64BIT(ctx);
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, PRTY_ISA205);
      tcg_gen_shri_tl(t0, rs, 32);
      tcg_gen_xor_tl(ra, rs, t0);
      tcg_gen_shri_tl(t0, ra, 16);
target/ppc/translate/fp-impl.c.inc +4 -4
index e0d9fa2e24..fef770368a 100644
@@ -324,7 +324,7 @@ TRANS(FNABS, do_move_b, 1ULL << 63, tcg_gen_ori_i64);
  static bool trans_FCPSGN(DisasContext *ctx, arg_FCPSGN *a)
  {
      TCGv_i64 t0, t1, t2;
-    REQUIRE_INSNS_FLAGS2(ctx, ISA205);
+    REQUIRE_INSNS_FLAGS2(ctx, FCPSGN_ISA205);
      REQUIRE_FPU(ctx);
      t0 = tcg_temp_new_i64();
      t1 = tcg_temp_new_i64();
@@ -592,13 +592,13 @@ static void gen_mtfsf(DisasContext *ctx)
      flm = FPFLM(ctx->opcode);
      l = FPL(ctx->opcode);
      w = FPW(ctx->opcode);
-    if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
+    if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
          gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
          return;
      }
      if (!l) {
          t0 = tcg_constant_i32(flm << (w * 8));
-    } else if (ctx->insns_flags2 & PPC2_ISA205) {
+    } else if (ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205) {
          t0 = tcg_constant_i32(0xffff);
      } else {
          t0 = tcg_constant_i32(0xff);
@@ -627,7 +627,7 @@ static void gen_mtfsfi(DisasContext *ctx)
      }
      w = FPW(ctx->opcode);
      bf = FPBF(ctx->opcode);
-    if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
+    if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
          gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
          return;
      }
target/ppc/translate/fp-ops.c.inc +6 -3
index 9bc9c3a3c3..e6a0d88dd4 100644
@@ -1,14 +1,17 @@
  GEN_HANDLER_E(lfdepx, 0x1F, 0x1F, 0x12, 0x00000001, PPC_NONE, PPC2_BOOKE206),
-GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001,
+              PPC_NONE, PPC2_LFIWAX_ISA205),
  GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
-GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
 
  #define GEN_STXF(name, stop, opc2, opc3, type)                                \
  GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
 
  GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
  GEN_HANDLER_E(stfdepx, 0x1F, 0x1F, 0x16, 0x00000001, PPC_NONE, PPC2_BOOKE206),
-GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
+GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001,
+              PPC_NONE, PPC2_FP_PAIR_ISA205),
 
  GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
  GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
author
#17 lore raw

PATCH 13/17 target/ppc: Enable byte comparison and parity on e5500 and e6500

In reply to Bin Meng

The e5500 and e6500 implement cmpb, prtyw and prtyd, as listed in table 3-7 of their reference manuals.

Enable only the byte comparison and parity feature flags on these cores. The e500mc explicitly excludes cmpb and prtyw in table 3-1, so keep these features disabled there. Unsupported floating-point instructions and extended FPSCR access remain disabled.

Reference:
- E500MCRM (Rev.3), section 3.1.1
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 3.1.1 and 3.4.3.1.3
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 3.1.1 and 3.4.3.1.3
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu_init.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/cpu_init.c +3 -2
index f2a342b076..1c02354e11 100644
@@ -3216,7 +3216,7 @@ POWERPC_FAMILY(e5500)(ObjectClass *oc, const void *data)
                        PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC |
                        PPC_64B | PPC_POPCNTB | PPC_POPCNTWD;
     pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_PERM_ISA206 |
-                        PPC2_FP_CVT_S64;
+                        PPC2_FP_CVT_S64 | PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205;
     pcc->msr_mask = (1ull << MSR_CM) |
                     (1ull << MSR_GS) |
                     (1ull << MSR_UCLE) |
@@ -3265,7 +3265,8 @@ POWERPC_FAMILY(e6500)(ObjectClass *oc, const void *data)
                        PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC |
                        PPC_64B | PPC_POPCNTB | PPC_POPCNTWD | PPC_ALTIVEC;
     pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_PERM_ISA206 |
-                        PPC2_FP_CVT_S64 | PPC2_ATOMIC_ISA206;
+                        PPC2_FP_CVT_S64 | PPC2_ATOMIC_ISA206 |
+                        PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205;
     pcc->msr_mask = (1ull << MSR_CM) |
                     (1ull << MSR_GS) |
                     (1ull << MSR_UCLE) |
Signature · 1 line
2.53.0
#18 lore raw

Re: [PATCH 13/17] target/ppc: Enable byte comparison and parity on e5500 and e6500

Quoted 7 lines · Bin Meng

The e5500 and e6500 implement cmpb, prtyw and prtyd, as listed in table 3-7 of their reference manuals.

Enable only the byte comparison and parity feature flags on these cores. The e500mc explicitly excludes cmpb and prtyw in table 3-1, so keep these features disabled there. Unsupported floating-point instructions and extended FPSCR access remain disabled.

Hey,
With this change, I observe 2 distinct sets of the new ISA205 flags introduced in this series :
1. PPC2_CMPB_ISA205 and PPC2_PRTY_ISA205, used always together with each other in cpu initialization, for e5500 and e6500. and
2. The other 4 PPC2_xxx_ISA205 flags, which are always used together in cpu initialization of various CPUs.

This makes me wonder, why not just have 2 PPC2_xxx_ISA205 flags, one for each of these sets instead of 6 ? The said proposed 2 flags will accurately capture the behavior needed by the series since no machine during its initialization uses a subset of the above mentioned 2 sets. This leaves room for future flag bits.

Thoughts ?

Thanks,
Chinmay

Quoted 38 lines

Reference:
- E500MCRM (Rev.3), section 3.1.1
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 3.1.1 and 3.4.3.1.3
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 3.1.1 and 3.4.3.1.3
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

  target/ppc/cpu_init.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/cpu_init.c +3 -2
index f2a342b076..1c02354e11 100644
@@ -3216,7 +3216,7 @@ POWERPC_FAMILY(e5500)(ObjectClass *oc, const void *data)
                         PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC |
                         PPC_64B | PPC_POPCNTB | PPC_POPCNTWD;
      pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_PERM_ISA206 |
-                        PPC2_FP_CVT_S64;
+                        PPC2_FP_CVT_S64 | PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205;
      pcc->msr_mask = (1ull << MSR_CM) |
                      (1ull << MSR_GS) |
                      (1ull << MSR_UCLE) |
@@ -3265,7 +3265,8 @@ POWERPC_FAMILY(e6500)(ObjectClass *oc, const void *data)
                         PPC_MEM_TLBSYNC | PPC_TLBIVAX | PPC_MEM_SYNC |
                         PPC_64B | PPC_POPCNTB | PPC_POPCNTWD | PPC_ALTIVEC;
      pcc->insns_flags2 = PPC2_BOOKE206 | PPC2_PRCNTL | PPC2_PERM_ISA206 |
-                        PPC2_FP_CVT_S64 | PPC2_ATOMIC_ISA206;
+                        PPC2_FP_CVT_S64 | PPC2_ATOMIC_ISA206 |
+                        PPC2_CMPB_ISA205 | PPC2_PRTY_ISA205;
      pcc->msr_mask = (1ull << MSR_CM) |
                      (1ull << MSR_GS) |
                      (1ull << MSR_UCLE) |
author
#19 lore raw

PATCH 14/17 target/ppc: Ignore FPSCR W/L fields on e500mc, e5500 and e6500

In reply to Bin Meng

Table 3-1 of the e500mc, e5500 and e6500 reference manuals specifies that mtfsfi ignores W and mtfsf ignores W and L, behaving as if these fields were zero. The existing translation rejects W=1 without extended FPSCR support and honors L=1, which does not match these cores.

Add a processor behavior flag to ignore these fields without advertising extended FPSCR support. Keep the ordinary field mask and rounding-mode updates effective.

Reference:
- E500MCRM (Rev.3), section 3.1.1
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 3.1.1
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 3.1.1
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

 target/ppc/cpu.h                   | 2 ++
 target/ppc/cpu_init.c              | 9 ++++++---
 target/ppc/translate/fp-impl.c.inc | 6 ++++++
 3 files changed, 14 insertions(+), 3 deletions(-)
target/ppc/cpu.h +2 -0
index 78fa4653fb..edcb2ac5c7 100644
@@ -844,6 +844,8 @@ enum {
     POWERPC_FLAG_BHRB      = 0x01000000,
     /* Use PPE42-specific behavior                                           */
     POWERPC_FLAG_PPE42     = 0x02000000,
+    /* Treat FPSCR instruction W and L fields as zero */
+    POWERPC_FLAG_FPSCR_IGNORE_WL = 0x04000000,
 };
 
 /*
target/ppc/cpu_init.c +6 -3
index 1c02354e11..f38a67208d 100644
@@ -3188,7 +3188,8 @@ POWERPC_FAMILY(e500mc)(ObjectClass *oc, const void *data)
     /* FIXME: figure out the correct flag for e500mc */
     pcc->bfd_mach = bfd_mach_ppc_e500;
     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
-                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
+                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK |
+                 POWERPC_FLAG_FPSCR_IGNORE_WL;
 }
 
 #ifdef TARGET_PPC64
@@ -3238,7 +3239,8 @@ POWERPC_FAMILY(e5500)(ObjectClass *oc, const void *data)
     /* FIXME: figure out the correct flag for e5500 */
     pcc->bfd_mach = bfd_mach_ppc_e500;
     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
-                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
+                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK |
+                 POWERPC_FLAG_FPSCR_IGNORE_WL;
 }
 
 static void init_proc_e6500(CPUPPCState *env)
@@ -3288,7 +3290,8 @@ POWERPC_FAMILY(e6500)(ObjectClass *oc, const void *data)
     pcc->bus_model = PPC_FLAGS_INPUT_BookE;
     pcc->bfd_mach = bfd_mach_ppc_e500;
     pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
-                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_VRE;
+                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_VRE |
+                 POWERPC_FLAG_FPSCR_IGNORE_WL;
 }
 
 #endif
target/ppc/translate/fp-impl.c.inc +6 -0
index fef770368a..9937b2db50 100644
@@ -592,6 +592,9 @@ static void gen_mtfsf(DisasContext *ctx)
     flm = FPFLM(ctx->opcode);
     l = FPL(ctx->opcode);
     w = FPW(ctx->opcode);
+    if (ctx->flags & POWERPC_FLAG_FPSCR_IGNORE_WL) {
+        l = w = 0;
+    }
     if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
         gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         return;
@@ -627,6 +630,9 @@ static void gen_mtfsfi(DisasContext *ctx)
     }
     w = FPW(ctx->opcode);
     bf = FPBF(ctx->opcode);
+    if (ctx->flags & POWERPC_FLAG_FPSCR_IGNORE_WL) {
+        w = 0;
+    }
     if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
         gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
         return;
Signature · 1 line
2.53.0
#20 lore raw

Re: [PATCH 14/17] target/ppc: Ignore FPSCR W/L fields on e500mc, e5500 and e6500

Quoted 31 lines · Bin Meng

Table 3-1 of the e500mc, e5500 and e6500 reference manuals specifies that mtfsfi ignores W and mtfsf ignores W and L, behaving as if these fields were zero. The existing translation rejects W=1 without extended FPSCR support and honors L=1, which does not match these cores.

Add a processor behavior flag to ignore these fields without advertising extended FPSCR support. Keep the ordinary field mask and rounding-mode updates effective.

Reference:
- E500MCRM (Rev.3), section 3.1.1
https://www.nxp.com/docs/en/reference-manual/E500MCRM.pdf
- E5500RM (Rev.4), section 3.1.1
https://www.nxp.com/webapp/Download?colCode=E5500RM
- E6500RM (Rev.0), section 3.1.1
https://www.nxp.com/docs/en/reference-manual/E6500RM.pdf

---

  target/ppc/cpu.h                   | 2 ++
  target/ppc/cpu_init.c              | 9 ++++++---
  target/ppc/translate/fp-impl.c.inc | 6 ++++++
  3 files changed, 14 insertions(+), 3 deletions(-)
target/ppc/cpu.h +0 -0
index 78fa4653fb..edcb2ac5c7 100644

target/ppc/cpu.h enum { · line 847

Quoted 4 lines
target/ppc/cpu.h +1 -0
@@ -844,6 +844,8 @@ enum {
      POWERPC_FLAG_BHRB      = 0x01000000,
      /* Use PPE42-specific behavior                                           */
      POWERPC_FLAG_PPE42     = 0x02000000,
+    /* Treat FPSCR instruction W and L fields as zero */

^ nit : '*/' to be aligned.

Regards,
Chinmay

Quoted 62 lines
target/ppc/cpu.h +1 -0
+    POWERPC_FLAG_FPSCR_IGNORE_WL = 0x04000000,
  };
 
  /*
target/ppc/cpu_init.c +6 -3
index 1c02354e11..f38a67208d 100644
@@ -3188,7 +3188,8 @@ POWERPC_FAMILY(e500mc)(ObjectClass *oc, const void *data)
      /* FIXME: figure out the correct flag for e500mc */
      pcc->bfd_mach = bfd_mach_ppc_e500;
      pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
-                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
+                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK |
+                 POWERPC_FLAG_FPSCR_IGNORE_WL;
  }
 
  #ifdef TARGET_PPC64
@@ -3238,7 +3239,8 @@ POWERPC_FAMILY(e5500)(ObjectClass *oc, const void *data)
      /* FIXME: figure out the correct flag for e5500 */
      pcc->bfd_mach = bfd_mach_ppc_e500;
      pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
-                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK;
+                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK |
+                 POWERPC_FLAG_FPSCR_IGNORE_WL;
  }
 
  static void init_proc_e6500(CPUPPCState *env)
@@ -3288,7 +3290,8 @@ POWERPC_FAMILY(e6500)(ObjectClass *oc, const void *data)
      pcc->bus_model = PPC_FLAGS_INPUT_BookE;
      pcc->bfd_mach = bfd_mach_ppc_e500;
      pcc->flags = POWERPC_FLAG_CE | POWERPC_FLAG_DE |
-                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_VRE;
+                 POWERPC_FLAG_PMM | POWERPC_FLAG_BUS_CLK | POWERPC_FLAG_VRE |
+                 POWERPC_FLAG_FPSCR_IGNORE_WL;
  }
 
  #endif
target/ppc/translate/fp-impl.c.inc +6 -0
index fef770368a..9937b2db50 100644
@@ -592,6 +592,9 @@ static void gen_mtfsf(DisasContext *ctx)
      flm = FPFLM(ctx->opcode);
      l = FPL(ctx->opcode);
      w = FPW(ctx->opcode);
+    if (ctx->flags & POWERPC_FLAG_FPSCR_IGNORE_WL) {
+        l = w = 0;
+    }
      if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
          gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
          return;
@@ -627,6 +630,9 @@ static void gen_mtfsfi(DisasContext *ctx)
      }
      w = FPW(ctx->opcode);
      bf = FPBF(ctx->opcode);
+    if (ctx->flags & POWERPC_FLAG_FPSCR_IGNORE_WL) {
+        w = 0;
+    }
      if (unlikely(w & !(ctx->insns_flags2 & PPC2_FPSCR_EXT_ISA205))) {
          gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
          return;
author
#21 lore raw

PATCH 15/17 tests/tcg/ppc: Add Book E illegal instruction tests

In reply to Bin Meng

Check the instruction subsets of e500mc, e5500 and e6500 through the existing TCG test framework. System emulation allows checking SRR0 and ESR on program exceptions. Run e500mc in 32-bit computation mode and e5500/e6500 in 64-bit computation mode.

Add shared ppce500 startup code, a linker script and assembly helpers. Use the existing UART and GPIO power-off devices to report results and terminate QEMU. Register the system targets in ppc/system and ppc64/system, sharing the assembly sources.

Test that unsupported floating-point instructions raise precise illegal instruction exceptions. Also check cmpb, prtyw and prtyd on e500mc.

---

 meson_options.txt                  |  4 ++
 scripts/meson-buildoptions.sh      |  2 +
 tests/tcg/meson.build              |  1 +
 tests/tcg/ppc/meson.build          |  5 ++
 tests/tcg/ppc/system/README        | 22 +++++++
 tests/tcg/ppc/system/boot.S        | 92 ++++++++++++++++++++++++++++++
 tests/tcg/ppc/system/isa.out       |  1 +
 tests/tcg/ppc/system/kernel.ld     | 18 ++++++
 tests/tcg/ppc/system/macros.inc    | 56 ++++++++++++++++++
 tests/tcg/ppc/system/meson.build   | 39 +++++++++++++
 tests/tcg/ppc/system/unsupported.S | 31 ++++++++++
 tests/tcg/ppc64/meson.build        |  2 +
 tests/tcg/ppc64/system/meson.build | 32 +++++++++++
 13 files changed, 305 insertions(+)
 create mode 100644 tests/tcg/ppc/meson.build
 create mode 100644 tests/tcg/ppc/system/README
 create mode 100644 tests/tcg/ppc/system/boot.S
 create mode 100644 tests/tcg/ppc/system/isa.out
 create mode 100644 tests/tcg/ppc/system/kernel.ld
 create mode 100644 tests/tcg/ppc/system/macros.inc
 create mode 100644 tests/tcg/ppc/system/meson.build
 create mode 100644 tests/tcg/ppc/system/unsupported.S
 create mode 100644 tests/tcg/ppc64/system/meson.build
meson_options.txt +4 -0
index c9247e9de1..c75c8d7db7 100644
@@ -465,6 +465,10 @@ option('tcg_tests_cross_cc_or1k', type: 'string',
        description: 'cc for or1k tcg tests')
 option('tcg_tests_cross_cflags_or1k', type: 'string',
        description: 'cflags for or1k tcg tests')
+option('tcg_tests_cross_cc_ppc', type: 'string',
+       description: 'cc for ppc tcg tests')
+option('tcg_tests_cross_cflags_ppc', type: 'string',
+       description: 'cflags for ppc tcg tests')
 option('tcg_tests_cross_cc_ppc64', type: 'string',
        description: 'cc for ppc64 tcg tests')
 option('tcg_tests_cross_cflags_ppc64', type: 'string',
scripts/meson-buildoptions.sh +2 -0
index 064e1429a4..5bac2bcf7c 100644
@@ -545,6 +545,7 @@ _meson_option_parse() {
     --tcg-tests-cross-cc-mips64r6el=*) quote_sh "-Dtcg_tests_cross_cc_mips64r6el=$2" ;;
     --tcg-tests-cross-cc-mipsel=*) quote_sh "-Dtcg_tests_cross_cc_mipsel=$2" ;;
     --tcg-tests-cross-cc-or1k=*) quote_sh "-Dtcg_tests_cross_cc_or1k=$2" ;;
+    --tcg-tests-cross-cc-ppc=*) quote_sh "-Dtcg_tests_cross_cc_ppc=$2" ;;
     --tcg-tests-cross-cc-ppc64=*) quote_sh "-Dtcg_tests_cross_cc_ppc64=$2" ;;
     --tcg-tests-cross-cc-ppc64le=*) quote_sh "-Dtcg_tests_cross_cc_ppc64le=$2" ;;
     --tcg-tests-cross-cc-riscv64=*) quote_sh "-Dtcg_tests_cross_cc_riscv64=$2" ;;
@@ -571,6 +572,7 @@ _meson_option_parse() {
     --tcg-tests-cross-cflags-mips64r6el=*) quote_sh "-Dtcg_tests_cross_cflags_mips64r6el=$2" ;;
     --tcg-tests-cross-cflags-mipsel=*) quote_sh "-Dtcg_tests_cross_cflags_mipsel=$2" ;;
     --tcg-tests-cross-cflags-or1k=*) quote_sh "-Dtcg_tests_cross_cflags_or1k=$2" ;;
+    --tcg-tests-cross-cflags-ppc=*) quote_sh "-Dtcg_tests_cross_cflags_ppc=$2" ;;
     --tcg-tests-cross-cflags-ppc64=*) quote_sh "-Dtcg_tests_cross_cflags_ppc64=$2" ;;
     --tcg-tests-cross-cflags-ppc64le=*) quote_sh "-Dtcg_tests_cross_cflags_ppc64le=$2" ;;
     --tcg-tests-cross-cflags-riscv64=*) quote_sh "-Dtcg_tests_cross_cflags_riscv64=$2" ;;
tests/tcg/meson.build +1 -0
index 4c0e30756d..5976540526 100644
@@ -184,6 +184,7 @@ subdir('mipsel')
 subdir('mips64')
 subdir('mips64el')
 subdir('or1k')
+subdir('ppc')
 subdir('ppc64')
 subdir('ppc64le')
 subdir('riscv64')
tests/tcg/ppc/meson.build new file +5 -0
new file mode 100644
index 0000000000..869b8906c5
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (c) 2026 Process Mission
+
+subdir('system')
tests/tcg/ppc/system/README new file +22 -0
new file mode 100644
index 0000000000..37a0fca951
@@ -0,0 +1,22 @@
+These Book E ISA tests use the generic tests/tcg build and test runner.
+They run on ppce500 with e500mc, e5500 and e6500 CPU models. System mode
+allows checking SRR0 and ESR on illegal instructions. The ppc target runs
+e500mc in 32-bit computation mode; ppc64 runs e5500/e6500 in 64-bit mode.
+
+The cross compiler builds freestanding ELF32 executables for ppc with
+-m32 and ELF64 executables for ppc64 with -m64. No target libc or
+multilib runtime is needed. The boot stub uses the initial RAM mapping
+provided by ppce500 -kernel, maps the CCSR area, and installs a program
+exception handler. Results go to UART0, and the existing GPIO power-off
+line terminates QEMU. The standard run_and_diff wrapper compares the
+output with isa.out.
+
+Configure QEMU with ppc-softmmu and/or ppc64-softmmu enabled. Compilers
+are found through the usual TCG cross-compiler detection or containers;
+--cross-cc-ppc and --cross-cc-ppc64 can select them explicitly. Run with:
+
+    make check-tcg-ppc-softmmu
+    make check-tcg-ppc64-softmmu
+
+These targets are generated only when configure finds a usable cross
+compiler or container. If missing, check the TCG tests configure summary.
tests/tcg/ppc/system/boot.S new file +92 -0

92 lines not on this page · raw message

tests/tcg/ppc/system/isa.out new file +1 -0
new file mode 100644
index 0000000000..34dabaf8bb
@@ -0,0 +1 @@
+ISA:PASS
tests/tcg/ppc/system/kernel.ld new file +18 -0
new file mode 100644
index 0000000000..3f18a3e087
@@ -0,0 +1,18 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 Process Mission
+ */
+
+ENTRY(_start)
+
+SECTIONS
+{
+    . = 0x100000;
+    .text : { *(.text.start) *(.text) }
+    . = ALIGN(0x10000);
+    .vectors : { *(.vectors) }
+    .rodata : { *(.rodata) }
+    .data : { *(.data) }
+    .bss : { *(.bss) }
+}
tests/tcg/ppc/system/macros.inc new file +56 -0

56 lines not on this page · raw message

tests/tcg/ppc/system/meson.build new file +39 -0
new file mode 100644
index 0000000000..1598348656
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (c) 2026 Process Mission
+
+# Shared settings and sources for the ppc and ppc64 system targets
+ppc_system_link_script = files('kernel.ld')[0]
+ppc_system_boot = files('boot.S')[0]
+ppc_system_cflags = ['-nostdlib', '-ffreestanding', '-mcpu=power6',
+                     '-Wa,-mregnames', '-Wa,--noexecstack',
+                     '-Wl,--build-id=none',
+                     '-Wl,-T', ppc_system_link_script, ppc_system_boot]
+ppc_system_qemu_args = ['-M', 'ppce500', '-accel', 'tcg', '-display', 'none',
+                        '-serial', 'stdio', '-monitor', 'none', '-nic', 'none']
+ppc_system_sources = ['unsupported.S']
+
+tests = []
+foreach src: ppc_system_sources
+  tests += {
+    'system/' + src: {
+      'exe_name': fs.stem(src) + '-e500mc-32',
+      'cflags': ppc_system_cflags + ['-m32', '-DE500MC'],
+      'qemu_args': ppc_system_qemu_args + ['-cpu', 'e500mc', '-kernel'],
+      'expected_output': 'system/isa.out',
+    }
+  }
+endforeach
+
+if 'qemu-system-ppc' in emulators
+  tcg_tests += {
+    'ppc-softmmu': {
+      'cc': 'powerpc-linux-gnu-gcc',
+      'cc_dockerfile': 'debian-all-test-cross',
+      'folder': 'ppc',
+      'gdb_arch': 'ppc',
+      'qemu': emulators['qemu-system-ppc'],
+      'tests': tests,
+    }
+  }
+endif
tests/tcg/ppc/system/unsupported.S new file +31 -0
new file mode 100644
index 0000000000..1737646b35
@@ -0,0 +1,31 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 Process Mission
+ */
+
+#include "macros.inc"
+
+    .text
+    .globl test_main
+test_main:
+    /* Valid memory prevents address faults from hiding decode errors */
+    load_addr r4, scratch
+    check_illegal fcpsgn f0, f0, f0
+    check_illegal fcpsgn. f0, f0, f0
+    check_illegal lfiwax f0, 0, r4
+    check_illegal lfdp f0, 0(r4)
+    check_illegal lfdpx f0, 0, r4
+    check_illegal stfdp f0, 0(r4)
+    check_illegal stfdpx f0, 0, r4
+#ifdef E500MC
+    check_illegal cmpb r11, r9, r10
+    check_illegal prtyw r11, r9
+    check_illegal prtyd r11, r9
+#endif
+    b pass
+
+    .data
+    .balign 16
+scratch:
+    .space 16
tests/tcg/ppc64/meson.build +2 -0
index 8cca4d65a4..6aa79fff28 100644
@@ -3,6 +3,8 @@ cc_feat_cflags = {
   'power10': '-mcpu=power10',
 }
 
+subdir('system')
+
 tests = []
 
 # Multi arch tests
tests/tcg/ppc64/system/meson.build new file +32 -0
new file mode 100644
index 0000000000..ca398860e3
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (c) 2026 Process Mission
+
+ppc64_system_cflags = ppc_system_cflags + ['-m64']
+tests = []
+foreach cpu: ['e5500', 'e6500']
+  sources = ppc_system_sources
+  foreach src: sources
+    tests += {
+      '../ppc/system/' + src: {
+        'exe_name': fs.stem(src) + '-' + cpu + '-64',
+        'cflags': ppc64_system_cflags,
+        'qemu_args': ppc_system_qemu_args + ['-cpu', cpu, '-kernel'],
+        'expected_output': '../ppc/system/isa.out',
+      }
+    }
+  endforeach
+endforeach
+
+if 'qemu-system-ppc64' in emulators
+  tcg_tests += {
+    'ppc64-softmmu': {
+      'cc': 'powerpc64-linux-gnu-gcc',
+      'cc_dockerfile': 'debian-all-test-cross',
+      'folder': 'ppc64',
+      'gdb_arch': 'ppc64',
+      'qemu': emulators['qemu-system-ppc64'],
+      'tests': tests,
+    }
+  }
+endif
Signature · 1 line
2.53.0
author
#22 lore raw

PATCH 16/17 tests/tcg/ppc: Test byte comparison and parity on e5500/e6500

In reply to Bin Meng

The e5500 and e6500 implement cmpb, prtyw and prtyd. Check matching-byte masks and parity results, including the separate word results in a 64-bit register and parity based on the low bit of each byte.

Use inputs with odd parity in bits above each byte's low bit to reject implementations that compute parity over all bits.

Add the test to the existing Book E matrix for e5500 and e6500 in 64-bit mode.

---

 tests/tcg/ppc/system/byte-parity.S | 33 ++++++++++++++++++++++++++++++
 tests/tcg/ppc64/system/meson.build |  1 +
 2 files changed, 34 insertions(+)
 create mode 100644 tests/tcg/ppc/system/byte-parity.S
tests/tcg/ppc/system/byte-parity.S new file +33 -0
new file mode 100644
index 0000000000..f4d434c881
@@ -0,0 +1,33 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 Process Mission
+ */
+
+#include "macros.inc"
+
+    .text
+    .globl test_main
+test_main:
+    load_value r9, 0x1122334455667788
+    load_value r10, 0x1122994455660088
+    cmpb r11, r9, r10
+    check_value r11, 0xffff00ffffff00ff
+
+    .macro parity value, word, doubleword
+    load_value r9, \value
+    prtyw r11, r9
+    check_value r11, \word
+#ifdef _LP64
+    prtyd r11, r9
+    check_value r11, \doubleword
+#endif
+    .endm
+
+    /* Parity uses the least significant bit of each byte */
+    parity 0x0101010100010000, 1, 1
+    parity 0x0001010100010000, 0x100000001, 0
+    parity 0x8080808002020202, 0, 0
+    parity 0x0000000000000080, 0, 0
+    parity 0x8000000000000000, 0, 0
+    b pass
tests/tcg/ppc64/system/meson.build +1 -0
index ca398860e3..ffa3060f05 100644
@@ -6,6 +6,7 @@ ppc64_system_cflags = ppc_system_cflags + ['-m64']
 tests = []
 foreach cpu: ['e5500', 'e6500']
   sources = ppc_system_sources
+  sources += ['byte-parity.S']
   foreach src: sources
     tests += {
       '../ppc/system/' + src: {
Signature · 1 line
2.53.0
author
#23 lore raw

PATCH 17/17 tests/tcg/ppc: Test FPSCR W/L handling on e500mc/e5500/e6500

In reply to Bin Meng

The e500mc, e5500 and e6500 ignore W in mtfsfi and W/L in mtfsf. Check that these fields do not select extended FPSCR fields, cause illegal instruction exceptions or override the ordinary field mask.

Test both W values, all W/L combinations and the Rc variants. Seed ZE and RN before each instruction so partial and zero field masks verify that unaffected fields remain intact and selected fields receive the expected values. Ignore the undefined upper word returned by mffs.

Register the test for e500mc in 32-bit mode and for e5500/e6500 in 64-bit mode, using the shared Book E startup and result handling.

---

 tests/tcg/ppc/system/fpscr.S     | 75 ++++++++++++++++++++++++++++++++
 tests/tcg/ppc/system/meson.build |  2 +-
 2 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/ppc/system/fpscr.S
tests/tcg/ppc/system/fpscr.S new file +75 -0
new file mode 100644
index 0000000000..41e90b1076
@@ -0,0 +1,75 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 Process Mission
+ */
+
+#include "macros.inc"
+
+    .macro seed_fpscr
+    mtfsf 255, f2
+    mtfsfi 6, 1                 /* ZE */
+    mtfsfi 7, 2                 /* RN */
+    .endm
+
+    .macro check_fpscr expected
+    mffs f1
+    stfd f1, 8(r4)
+    lwz r11, 12(r4)
+    load32 r12, \expected
+    cmpw r11, r12
+    bne fail
+    .endm
+
+    .macro test_mtfsfi field, value, w, record, expected
+    seed_fpscr
+    .if \record
+    mtfsfi. \field, \value, \w
+    .else
+    mtfsfi \field, \value, \w
+    .endif
+    check_fpscr \expected
+    .endm
+
+    .macro test_mtfsf mask, w, l, record, expected
+    seed_fpscr
+    .if \record
+    mtfsf. \mask, f0, \l, \w
+    .else
+    mtfsf \mask, f0, \l, \w
+    .endif
+    check_fpscr \expected
+    .endm
+
+    .text
+    .globl test_main
+test_main:
+    load_addr r4, scratch
+    lfd f0, 0(r4)               /* Source: upper word 3, lower word 1 */
+    lfd f2, 16(r4)              /* Zero for a reproducible initial FPSCR */
+
+    .irp w, 0, 1
+    .irp record, 0, 1
+    test_mtfsfi 6, 4, \w, \record, 0x42
+    test_mtfsfi 7, 1, \w, \record, 0x11
+    .endr
+    .endr
+
+    .irp w, 0, 1
+    .irp l, 0, 1
+    .irp record, 0, 1
+    /* L must not override the ordinary field mask, and W is ignored */
+    test_mtfsf 0, \w, \l, \record, 0x12
+    test_mtfsf 1, \w, \l, \record, 0x11
+    test_mtfsf 2, \w, \l, \record, 0x02
+    test_mtfsf 255, \w, \l, \record, 0x01
+    .endr
+    .endr
+    .endr
+    b pass
+
+    .data
+    .balign 8
+scratch:
+    .long 3, 1
+    .space 16
tests/tcg/ppc/system/meson.build +1 -1
index 1598348656..ad4c257c9a 100644
@@ -11,7 +11,7 @@ ppc_system_cflags = ['-nostdlib', '-ffreestanding', '-mcpu=power6',
                      '-Wl,-T', ppc_system_link_script, ppc_system_boot]
 ppc_system_qemu_args = ['-M', 'ppce500', '-accel', 'tcg', '-display', 'none',
                         '-serial', 'stdio', '-monitor', 'none', '-nic', 'none']
-ppc_system_sources = ['unsupported.S']
+ppc_system_sources = ['unsupported.S', 'fpscr.S']
 
 tests = []
 foreach src: ppc_system_sources
Signature · 1 line
2.53.0
#24 lore raw
In reply to Bin Meng
Quoted 7 lines · Bin Meng

This series corrects SPR access, cache configuration and instruction availability in the Freescale Book E CPU models. It also adds system TCG tests for e500mc, e5500 and e6500.

The patches are grouped as follows:

Quoted 11 lines

- patch #1-#4, bug fixes to PIR write access, the MAS5 SPR number and cache block/line sizes (qemu-stable cc'ed)
- patch #5-#6, complete e500mc/e5500 L1 cache configuration and remove redundant e6500 cache geometry bits
- patch #7-#11, register the missing cache, MMU-assist and sevearl control SPRs
- patch #12-#14, split the PowerISA 2.05 instructions to several sub-flags controlled groups, due to differences seen on the e500 series cores
- patch #15-#17: Add TCG tests for illegal-instruction exceptions, byte comparison and parity results, and FPSCR field-mask handling

Ping for review?