Add IBM PPE42 CPU support
v3 cover Add IBM PPE42 CPU support
v3:
- Split v2 patch 1 into smaller patches 1 through 5 (Cedric)
- Moved special PPE42 decrementer support into distinct patch (Cedric)
- Introduced a specific MachineState for the ppe42 Machine (Cedric)
- Use qdev_realize to create the machine (Cedric)
- Use valid_cpu_types to determine validity of CPU (Cedric)
- Changed machine ram limit from 2GB to 512KB (Cedric)
- Utilize the TRANS macro to reduce TCG code (Chinmay)
This patchset adds support for the IBM PPE42 processor, including a simple machine providing a platform for testing the PPE42 instructions.
The PPE42 processor is used as an embedded processor in the IBM Power9, Power10 and Power12 processors for various tasks. It is basically a stripped down version of the IBM PowerPC 405 processor, with some added instructions for handling 64-bit loads and stores and some 64-bit logical operations.
For more information on the PPE 42 processor please visit:
https://wiki.raptorcs.com/w/images/a/a3/PPE_42X_Core_Users_Manual.pdf
A functional test is included. This test downloads a prebuilt test image from:
https://github.com/milesg-github/ppe42-tests
Building the image rquires a forked version of an old version of GCC, which can be found here:
https://github.com/open-power/ppe42-gcc
Thanks,
Glenn
Glenn Miles (9):
target/ppc: IBM PPE42 general regs and flags target/ppc: Add IBM PPE42 family of processors target/ppc: IBM PPE42 exception flags and regs target/ppc: Add IBM PPE42 exception model target/ppc: Support for IBM PPE42 MMU target/ppc: Add IBM PPE42 special instructions hw/ppc: Support for an IBM PPE42 CPU decrementer hw/ppc: Add a test machine for the IBM PPE42 CPU tests/functional: Add test for IBM PPE42 instructions
MAINTAINERS | 7 + hw/ppc/Kconfig | 9 + hw/ppc/meson.build | 2 + hw/ppc/ppc_booke.c | 7 +- hw/ppc/ppe42_machine.c | 102 +++++ include/hw/ppc/ppc.h | 1 + target/ppc/cpu-models.c | 7 + target/ppc/cpu-models.h | 4 + target/ppc/cpu.h | 76 +++- target/ppc/cpu_init.c | 241 ++++++++-- target/ppc/excp_helper.c | 163 +++++++ target/ppc/helper_regs.c | 45 +- target/ppc/insn32.decode | 66 ++- target/ppc/tcg-excp_helper.c | 12 + target/ppc/translate.c | 35 +- target/ppc/translate/ppe-impl.c.inc | 663 ++++++++++++++++++++++++++++ tests/functional/meson.build | 1 + tests/functional/test_ppc_ppe42.py | 79 ++++ 18 files changed, 1453 insertions(+), 67 deletions(-) create mode 100644 hw/ppc/ppe42_machine.c create mode 100644 target/ppc/translate/ppe-impl.c.inc create mode 100644 tests/functional/test_ppc_ppe42.py
Signature · 1 line
2.43.0
PATCH v3 5/9 target/ppc: Support for IBM PPE42 MMU
The IBM PPE42 processor only supports real mode addressing and does not distinguish between problem and supervisor states. It also uses the IR and DR MSR bits for other purposes. Therefore, add a check for PPE42 when we update hflags and cause it to ignore the IR and DR bits when calculating MMU indexes.
---
Changes from v2:
- Split MMU changes from v2 patch 1
target/ppc/helper_regs.c | 4 ++++ 1 file changed, 4 insertions(+)
target/ppc/helper_regs.c +4 -0
@@ -186,6 +186,10 @@ static uint32_t hreg_compute_hflags_value(CPUPPCState *env)if (env->spr[SPR_LPCR ] &LPCR_HR ) { hflags |=1 <<HFLAGS_HR ; } +if (unlikely (ppc_flags &POWERPC_FLAG_PPE42 )) { +/* PPE42 has a single address space and no problem state */ + msr =0 ; + }#ifndef CONFIG_USER_ONLY if (!env->has_hv_mode || (msr & (1ull <<MSR_HV ))) {
Signature · 1 line
2.43.0
PATCH v3 2/9 target/ppc: Add IBM PPE42 family of processors
In reply to Glenn MilesAdds the IBM PPE42 family of 32-bit processors supporting the PPE42, PPE42X and PPE42XM processor versions. These processors are used as embedded processors in the IBM Power9, Power10 and Power12 processors for various tasks. It is basically a stripped down version of the IBM PowerPC 405 processor, with some added instructions for handling 64-bit loads and stores.
For more information on the PPE 42 processor please visit:
https://wiki.raptorcs.com/w/images/a/a3/PPE_42X_Core_Users_Manual.pdf
Supports PPE42 SPR's (Including the MSR).
Does not yet support exceptions, new PPE42 instructions and does not prevent access to some invalid instructions and registers (currently allows access to invalid GPR's and CR fields).
---
Changes from v2:
- Split general CPU changes from v2 patch 1
target/ppc/cpu-models.c | 7 ++ target/ppc/cpu_init.c | 204 ++++++++++++++++++++++++++++++++------- target/ppc/helper_regs.c | 41 +++++--- target/ppc/translate.c | 6 +- 4 files changed, 203 insertions(+), 55 deletions(-)
target/ppc/cpu-models.c +7 -0
@@ -116,6 +116,13 @@ NULL) POWERPC_DEF("x2vp20", CPU_POWERPC_X2VP20, 405, NULL) +/* PPE42 Embedded Controllers */ +POWERPC_DEF ("PPE42" ,CPU_POWERPC_PPE42 , ppe42, + "Generic PPE 42") +POWERPC_DEF ("PPE42X" ,CPU_POWERPC_PPE42X , ppe42x, + "Generic PPE 42X") +POWERPC_DEF ("PPE42XM" ,CPU_POWERPC_PPE42XM , ppe42xm, +"Generic PPE 42XM" ) /* PowerPC 440 family */#if defined(TODO_USER_ONLY ) POWERPC_DEF("440", CPU_POWERPC_440, 440GP,
target/ppc/cpu_init.c +167 -37
289 lines not on this page · raw message
target/ppc/helper_regs.c +25 -16
65 lines not on this page · raw message
target/ppc/translate.c +4 -2
@@ -4264,8 +4264,10 @@ static void gen_mtmsr(DisasContext *ctx)/* L=1 form only updates EE and RI */ mask &= (1ULL <<MSR_RI ) | (1ULL <<MSR_EE ); }else { -/* mtmsr does not alter S, ME, or LE */ - mask &= ~((1ULL <<MSR_LE ) | (1ULL <<MSR_ME ) | (1ULL <<MSR_S )); +if (likely (!(ctx->insns_flags2 &PPC2_PPE42 ))) { +/* mtmsr does not alter S, ME, or LE */ + mask &= ~((1ULL <<MSR_LE ) | (1ULL <<MSR_ME ) | (1ULL <<MSR_S )); + }/* * XXX: we need to update nip before the store if we enter
Signature · 1 line
2.43.0
PATCH v3 7/9 hw/ppc: Support for an IBM PPE42 CPU decrementer
In reply to Glenn MilesThe IBM PPE42 processors support a 32-bit decrementer that can raise an external interrupt when DEC[0] transitions from a 0 to a 1 (a non-negative value to a negative value). It also continues decrementing even after this condition is met.
The BookE timer is slightly different in that it raises an interrupt when the DEC value reaches 0 and stops decrementing at that point.
Support a PPE42 version of the BookE timer by adding a new PPC_TIMER_PPE flag that has the timer code look for the transition from a non-negative value to a negative value and allows the value to continue decrementing.
---
Changes from v2:
- Split out PPE42 decrementer support from v2 patch 3
hw/ppc/ppc_booke.c | 7 ++++++- include/hw/ppc/ppc.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)
hw/ppc/ppc_booke.c +6 -1
@@ -352,7 +352,12 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t freq, uint32_t flags) booke_timer =g_new0 (booke_timer_t,1 ); cpu->env.tb_env = tb_env; - tb_env->flags = flags |PPC_TIMER_BOOKE |PPC_DECR_ZERO_TRIGGERED ; +if (flags &PPC_TIMER_PPE ) { +/* PPE's use a modified version of the booke behavior */ + tb_env->flags = flags |PPC_DECR_UNDERFLOW_TRIGGERED ; + }else { + tb_env->flags = flags |PPC_TIMER_BOOKE |PPC_DECR_ZERO_TRIGGERED ; + } tb_env->tb_freq = freq; tb_env->decr_freq = freq;
include/hw/ppc/ppc.h +1 -0
@@ -52,6 +52,7 @@ struct ppc_tb_t {#define PPC_DECR_UNDERFLOW_LEVEL (1 << 4)/* Decr interrupt active when * the most significant bit is 1. */ +#define PPC_TIMER_PPE (1 << 5)/* Enable PPE support */ uint64_t cpu_ppc_get_tb (ppc_tb_t *tb_env,uint64_t vmclk,int64_t tb_offset);void cpu_ppc_tb_init (CPUPPCState *env,uint32_t freq);
Signature · 1 line
2.43.0
PATCH v3 1/9 target/ppc: IBM PPE42 general regs and flags
In reply to Glenn MilesIntroduces general IBM PPE42 processor register definitions and flags.
---
Changes from v2:
- Split general registers and flags from v2 patch 1
target/ppc/cpu-models.h | 4 ++++ target/ppc/cpu.h | 49 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)
target/ppc/cpu-models.h +4 -0
@@ -69,6 +69,10 @@ enum {/* Xilinx cores */ CPU_POWERPC_X2VP4 =0x20010820 ,CPU_POWERPC_X2VP20 =0x20010860 , +/* IBM PPE42 Family */ +CPU_POWERPC_PPE42 =0x42000000 , +CPU_POWERPC_PPE42X =0x42100000 , +CPU_POWERPC_PPE42XM =0x42200000 ,/* PowerPC 440 family */ /* Generic PowerPC 440 */ #define CPU_POWERPC_440 CPU_POWERPC_440GXf
target/ppc/cpu.h +48 -1
157 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 9/9 tests/functional: Add test for IBM PPE42 instructions
In reply to Glenn MilesAdds a functional test for the IBM PPE42 instructions which downloads a test image from a public github repo and then loads and executes the image.
(see https://github.com/milesg-github/ppe42-tests for details)
Test status is checked by periodically issuing 'info register' commands and checking the NIP value. If the NIP is 0xFFF80200 then the test successfully executed to completion. If the machine stops before the test completes or if a 90 second timeout is reached, then the test is marked as having failed.
This test does not test any PowerPC instructions as it is expected that these instructions are well covered in other tests. Only instructions that are unique to the IBM PPE42 processor are tested.
---
No changes from v2 patch 4
MAINTAINERS | 1 + tests/functional/meson.build | 1 + tests/functional/test_ppc_ppe42.py | 79 ++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 tests/functional/test_ppc_ppe42.py
MAINTAINERS +1 -0
@@ -1536,6 +1536,7 @@ M: Glenn Miles <[email protected]> L: [email protected] S: Odd Fixes F: hw/ppc/ppe42_machine.c +F: tests/functional/test_ppc_ppe42.py PReP M: Hervé Poussineau <[email protected]>
tests/functional/meson.build +1 -0
@@ -233,6 +233,7 @@ tests_ppc_system_quick = [ ] tests_ppc_system_thorough = [ + 'ppc_ppe42', 'ppc_40p', 'ppc_amiga', 'ppc_bamboo',
tests/functional/test_ppc_ppe42.py new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 3/9 target/ppc: IBM PPE42 exception flags and regs
In reply to Glenn MilesIntroduces flags and register definitions needed
for the IBM PPE42 exception model.
---
Changes from v2:
- Split exception flags and registers from v2 patch 1
target/ppc/cpu.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
target/ppc/cpu.h +27 -0
@@ -220,6 +220,8 @@ typedef enum powerpc_excp_t {POWERPC_EXCP_POWER10 ,/* POWER11 exception model */ POWERPC_EXCP_POWER11 , +/* PPE42 exception model */ +POWERPC_EXCP_PPE42 , } powerpc_excp_t;/*****************************************************************************/
@@ -760,6 +762,31 @@ FIELD(MSR, SIBRCA, MSR_SIBRCA7, 8)#define ESR_VLEMI PPC_BIT(58)/* VLE operation */ #define ESR_MIF PPC_BIT(62)/* Misaligned instruction (VLE) */ +/* PPE42 Interrupt Status Register bits */ +#define PPE42_ISR_SRSMS0 PPC_BIT_NR(48)/* Sys Reset State Machine State 0 */ +#define PPE42_ISR_SRSMS1 PPC_BIT_NR(49)/* Sys Reset State Machine State 1 */ +#define PPE42_ISR_SRSMS2 PPC_BIT_NR(50)/* Sys Reset State Machine State 2 */ +#define PPE42_ISR_SRSMS3 PPC_BIT_NR(51)/* Sys Reset State Machine State 3 */ +#define PPE42_ISR_EP PPC_BIT_NR(53)/* MSR[EE] Maskable Event Pending */ +#define PPE42_ISR_PTR PPC_BIT_NR(56)/* Program Interrupt from trap */ +#define PPE42_ISR_ST PPC_BIT_NR(57)/* Data Interrupt caused by store */ +#define PPE42_ISR_MFE PPC_BIT_NR(60)/* Multiple Fault Error */ +#define PPE42_ISR_MCS0 PPC_BIT_NR(61)/* Machine Check Status bit0 */ +#define PPE42_ISR_MCS1 PPC_BIT_NR(62)/* Machine Check Status bit1 */ +#define PPE42_ISR_MCS2 PPC_BIT_NR(63)/* Machine Check Status bit2 */ +FIELD(PPE42_ISR, SRSMS, PPE42_ISR_SRSMS3, 4) +FIELD (PPE42_ISR ,MCS ,PPE42_ISR_MCS2 ,3 ) + +/* PPE42 Machine Check Status field values */ +#define PPE42_ISR_MCS_INSTRUCTION 0 +#define PPE42_ISR_MCS_DATA_LOAD 1 +#define PPE42_ISR_MCS_DATA_PRECISE_STORE 2 +#define PPE42_ISR_MCS_DATA_IMPRECISE_STORE 3 +#define PPE42_ISR_MCS_PROGRAM 4 +#define PPE42_ISR_MCS_ISI 5 +#define PPE42_ISR_MCS_ALIGNMENT 6 +#define PPE42_ISR_MCS_DSI 7 +/* Transaction EXception And Summary Register bits */ #define TEXASR_FAILURE_PERSISTENT (63 - 7)#define TEXASR_DISALLOWED (63 - 8)
Signature · 1 line
2.43.0
PATCH v3 8/9 hw/ppc: Add a test machine for the IBM PPE42 CPU
In reply to Glenn MilesAdds a test machine for the IBM PPE42 processor, including a DEC, FIT, WDT and 512 KiB of ram.
The purpose of this machine is only to provide a generic platform for testing instructions of the recently added PPE42 processor model which is used extensively in the IBM Power9, Power10 and future Power server processors.
---
Changes from v2:
- Moved decrementer changes to distinct commit
- Introduced a specific MachineState for the ppe42 Machine
- Use qdev_realize to create the machine
- Use valid_cpu_types to determine validity of CPU
- Changed machine ram limit from 2GB to 512KB
MAINTAINERS | 6 +++ hw/ppc/Kconfig | 9 ++++ hw/ppc/meson.build | 2 + hw/ppc/ppe42_machine.c | 102 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 hw/ppc/ppe42_machine.c
MAINTAINERS +6 -0
@@ -1531,6 +1531,12 @@ F: include/hw/pci-host/grackle.h F: pc-bios/qemu_vga.ndrv F: tests/functional/test_ppc_mac.py +PPE42 +M: Glenn Miles <[email protected]> +L: [email protected] +S: Odd Fixes +F: hw/ppc/ppe42_machine.c + PReP M: Hervé Poussineau <[email protected]> L: [email protected]
hw/ppc/Kconfig +9 -0
@@ -44,6 +44,15 @@ config POWERNV select SSI_M25P80 select PNV_SPI +config PPC405 + bool + default y + depends on PPC + select M48T59 + select PFLASH_CFI02 + select PPC4XX + select SERIAL + config PPC440 bool default y
hw/ppc/meson.build +2 -0
@@ -57,6 +57,8 @@ ppc_ss.add(when: 'CONFIG_POWERNV', if_true: files( 'pnv_n1_chiplet.c', )) # PowerPC 4xx boards +ppc_ss.add(when: 'CONFIG_PPC405', if_true: files( + 'ppe42_machine.c')) ppc_ss.add(when: 'CONFIG_PPC440', if_true: files( 'ppc440_bamboo.c', 'ppc440_uc.c'))
hw/ppc/ppe42_machine.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 6/9 target/ppc: Add IBM PPE42 special instructions
In reply to Glenn MilesAdds the following instructions exclusively for
IBM PPE42 processors:
LSKU
LCXU
STSKU
STCXU
LVD
LVDU
LVDX
STVD
STVDU
STVDX
SLVD
SRVD
CMPWBC
CMPLWBC
CMPWIBC
BNBWI
BNBW
CLRBWIBC
CLRWBC
DCBQ
RLDICL
RLDICR
RLDIMI
A PPE42 GCC compiler is available here:
https://github.com/open-power/ppe42-gcc
For more information on the PPE42 processors please visit:
https://wiki.raptorcs.com/w/images/a/a3/PPE_42X_Core_Users_Manual.pdf
---
Changes from v2:
- Utilized the TRANS macro to reduce code
target/ppc/insn32.decode | 66 ++- target/ppc/translate.c | 29 +- target/ppc/translate/ppe-impl.c.inc | 663 ++++++++++++++++++++++++++++ 3 files changed, 748 insertions(+), 10 deletions(-) create mode 100644 target/ppc/translate/ppe-impl.c.inc
target/ppc/insn32.decode +62 -4
@@ -58,6 +58,10 @@ %ds_rtp 22:4 !function=times_2 @DS_rtp ...... ....0 ra:5 .............. .. &D rt=%ds_rtp si=%ds_si +%dd_si 3:s13 +&DD rt ra si:int64_t +@DD ...... rt:5 ra:5 ............. . .. &DD si=%dd_si + &DX_b vrt b %dx_b 6:10 16:5 0:1 @DX_b ...... vrt:5 ..... .......... ..... . &DX_b b=%dx_b
@@ -66,6 +70,11 @@ %dx_d 6:s10 16:5 0:1 @DX ...... rt:5 ..... .......... ..... . &DX d=%dx_d +%md_sh 1:1 11:5 +%md_mb 5:1 6:5 +&MD rs ra sh mb rc +@MD ...... rs:5 ra:5 ..... ...... ... . rc:1 &MD sh=%md_sh mb=%md_mb + &VA vrt vra vrb rc @VA ...... vrt:5 vra:5 vrb:5 rc:5 ...... &VA
@@ -322,6 +331,13 @@ LDUX 011111 ..... ..... ..... 0000110101 - @X LQ 111000 ..... ..... ............ ---- @DQ_rtp +LVD 000101 ..... ..... ................ @D +LVDU 001001 ..... ..... ................ @D +LVDX 011111 ..... ..... ..... 0000010001 - @X +LSKU 111010 ..... ..... ............. 0 11 @DD +LCXU 111010 ..... ..... ............. 1 11 @DD + + ### Fixed-Point Store Instructions STB 100110 ..... ..... ................ @D
@@ -346,6 +362,11 @@ STDUX 011111 ..... ..... ..... 0010110101 - @X STQ 111110 ..... ..... ..............10 @DS_rtp +STVDU 010110 ..... ..... ................ @D +STVDX 011111 ..... ..... ..... 0010010001 - @X +STSKU 111110 ..... ..... ............. 0 11 @DD +STCXU 111110 ..... ..... ............. 1 11 @DD + ### Fixed-Point Compare Instructions CMP 011111 ... - . ..... ..... 0000000000 - @X_bfl
@@ -461,8 +482,14 @@ PRTYD 011111 ..... ..... ----- 0010111010 - @X_sa BPERMD 011111 ..... ..... ..... 0011111100 - @X CFUGED 011111 ..... ..... ..... 0011011100 - @X -CNTLZDM 011111 ..... ..... ..... 0000111011 - @X -CNTTZDM 011111 ..... ..... ..... 1000111011 - @X +{ + SLVD 011111 ..... ..... ..... 0000111011 . @X_rc + CNTLZDM 011111 ..... ..... ..... 0000111011 - @X +} +{ + SRVD 011111 ..... ..... ..... 1000111011 . @X_rc + CNTTZDM 011111 ..... ..... ..... 1000111011 - @X +} PDEPD 011111 ..... ..... ..... 0010011100 - @X PEXTD 011111 ..... ..... ..... 0010111100 - @X
@@ -981,8 +1008,16 @@ LXSSP 111001 ..... ..... .............. 11 @DS STXSSP 111101 ..... ..... .............. 11 @DS LXV 111101 ..... ..... ............ . 001 @DQ_TSX STXV 111101 ..... ..... ............ . 101 @DQ_TSX -LXVP 000110 ..... ..... ............ 0000 @DQ_TSXP -STXVP 000110 ..... ..... ............ 0001 @DQ_TSXP + +# STVD PPE instruction overlaps with the LXVP and STXVP instructions +{ + STVD 000110 ..... ..... ................ @D + [ + LXVP 000110 ..... ..... ............ 0000 @DQ_TSXP + STXVP 000110 ..... ..... ............ 0001 @DQ_TSXP + ] +} + LXVX 011111 ..... ..... ..... 0100 - 01100 . @X_TSX STXVX 011111 ..... ..... ..... 0110001100 . @X_TSX LXVPX 011111 ..... ..... ..... 0101001101 - @X_TSXP
@@ -1300,3 +1335,26 @@ CLRBHRB 011111 ----- ----- ----- 0110101110 - ## Misc POWER instructions ATTN 000000 00000 00000 00000 0100000000 0 + +# Fused compare-branch instructions for PPE only +%fcb_bdx 1:s10 !function=times_4 +&FCB px:bool ra rb:uint64_t bdx lk:bool +@FCB ...... .. px:1 .. ra:5 rb:5 .......... lk:1 &FCB bdx=%fcb_bdx +&FCB_bix px:bool bix ra rb:uint64_t bdx lk:bool +@FCB_bix ...... .. px:1 bix:2 ra:5 rb:5 .......... lk:1 &FCB_bix bdx=%fcb_bdx + +CMPWBC 000001 00 . .. ..... ..... .......... . @FCB_bix +CMPLWBC 000001 01 . .. ..... ..... .......... . @FCB_bix +CMPWIBC 000001 10 . .. ..... ..... .......... . @FCB_bix +BNBWI 000001 11 . 00 ..... ..... .......... . @FCB +BNBW 000001 11 . 01 ..... ..... .......... . @FCB +CLRBWIBC 000001 11 . 10 ..... ..... .......... . @FCB +CLRBWBC 000001 11 . 11 ..... ..... .......... . @FCB + +# Data Cache Block Query for PPE only +DCBQ 011111 ..... ..... ..... 0110010110 - @X + +# Rotate Doubleword Instructions for PPE only (if TARGET_PPC64 not defined) +RLDICL 011110 ..... ..... ..... ...... 000 . . @MD +RLDICR 011110 ..... ..... ..... ...... 001 . . @MD +RLDIMI 011110 ..... ..... ..... ...... 011 . . @MD
target/ppc/translate.c +23 -6
@@ -209,6 +209,11 @@ struct DisasContext {#define DISAS_CHAIN DISAS_TARGET_2/* lookup next tb, pc updated */ #define DISAS_CHAIN_UPDATE DISAS_TARGET_3/* lookup next tb, pc stale */ +static inline bool is_ppe (const DisasContext *ctx) +{ +return !!(ctx->flags &POWERPC_FLAG_PPE42 ); +} +/* Return true iff byteswap is needed in a scalar memop */ static inline bool need_byteswap (const DisasContext *ctx) {
@@ -556,11 +561,8 @@ void spr_access_nop(DisasContext *ctx, int sprn, int gprn)#endif -/* SPR common to all PowerPC */ -/* XER */ -void spr_read_xer (DisasContext *ctx,int gprn,int sprn) +static void gen_get_xer (DisasContext *ctx,TCGv dst) { -TCGv dst = cpu_gpr[gprn];TCGv t0 =tcg_temp_new ();TCGv t1 =tcg_temp_new ();TCGv t2 =tcg_temp_new ();
@@ -579,9 +581,16 @@ void spr_read_xer(DisasContext *ctx, int gprn, int sprn) } } -void spr_write_xer (DisasContext *ctx,int sprn,int gprn) +/* SPR common to all PowerPC */ +/* XER */ +void spr_read_xer (DisasContext *ctx,int gprn,int sprn) +{ +TCGv dst = cpu_gpr[gprn]; +gen_get_xer (ctx, dst); +} + +static void gen_set_xer (DisasContext *ctx,TCGv src) { -TCGv src = cpu_gpr[gprn];/* Write all flags, while reading back check for isa300 */ tcg_gen_andi_tl(cpu_xer, src, ~((1u << XER_SO) |
@@ -594,6 +603,12 @@ void spr_write_xer(DisasContext *ctx, int sprn, int gprn)tcg_gen_extract_tl (cpu_ca, src,XER_CA ,1 ); } +void spr_write_xer (DisasContext *ctx,int sprn,int gprn) +{ +TCGv src = cpu_gpr[gprn]; +gen_set_xer (ctx, src); +} +/* LR */ void spr_read_lr (DisasContext *ctx,int gprn,int sprn) {
@@ -5755,6 +5770,8 @@ static bool resolve_PLS_D(DisasContext *ctx, arg_D *d, arg_PLS_D *a)#include "translate/bhrb-impl.c.inc" +#include "translate/ppe-impl.c.inc" +/* Handles lfdp */ static void gen_dform39 (DisasContext *ctx) {
target/ppc/translate/ppe-impl.c.inc new file +663 -0
663 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 4/9 target/ppc: Add IBM PPE42 exception model
In reply to Glenn MilesAdd support for the IBM PPE42 exception model including new exception vectors, exception priorities and setting of PPE42 SPRs for determining the cause of an exception.
---
Changes from v2:
- Split exception changes from v2 patch 1
target/ppc/cpu_init.c | 39 ++++++++- target/ppc/excp_helper.c | 163 +++++++++++++++++++++++++++++++++++ target/ppc/tcg-excp_helper.c | 12 +++ 3 files changed, 213 insertions(+), 1 deletion(-)
target/ppc/cpu_init.c +38 -1
@@ -1720,6 +1720,30 @@ static void init_excp_4xx(CPUPPCState *env)#endif } +static void init_excp_ppe42 (CPUPPCState *env) +{ +#if !defined(CONFIG_USER_ONLY ) +/* Machine Check vector changed after version 0 */ +if (((env->spr[SPR_PVR ] &0xf00000ul ) >>20 ) ==0 ) { + env->excp_vectors[POWERPC_EXCP_MCHECK ] =0x00000000 ; + }else { + env->excp_vectors[POWERPC_EXCP_MCHECK ] =0x00000020 ; + } + env->excp_vectors[POWERPC_EXCP_RESET ] =0x00000040 ; + env->excp_vectors[POWERPC_EXCP_DSI ] =0x00000060 ; + env->excp_vectors[POWERPC_EXCP_ISI ] =0x00000080 ; + env->excp_vectors[POWERPC_EXCP_EXTERNAL ] =0x000000A0 ; + env->excp_vectors[POWERPC_EXCP_ALIGN ] =0x000000C0 ; + env->excp_vectors[POWERPC_EXCP_PROGRAM ] =0x000000E0 ; + env->excp_vectors[POWERPC_EXCP_DECR ] =0x00000100 ; + env->excp_vectors[POWERPC_EXCP_FIT ] =0x00000120 ; + env->excp_vectors[POWERPC_EXCP_WDT ] =0x00000140 ; + env->ivpr_mask =0xFFFFFE00UL ; +/* Hardware reset vector */ + env->hreset_vector =0x00000040UL ; +#endif +} +static void init_excp_MPC5xx (CPUPPCState *env) {#if !defined(CONFIG_USER_ONLY )
@@ -2245,6 +2269,7 @@ static void init_proc_ppe42(CPUPPCState *env) {register_ppe42_sprs (env); +init_excp_ppe42 (env); env->dcache_line_size =32 ; env->icache_line_size =32 ;/* Allocate hardware IRQ controller */
@@ -2278,7 +2303,7 @@ static void ppe42_class_common_init(PowerPCCPUClass *pcc) (1ull <<MSR_IPE ) |R_MSR_SIBRCA_MASK ; pcc->mmu_model =POWERPC_MMU_REAL ; - pcc->excp_model = POWERPC_EXCP_40x; + pcc->excp_model =POWERPC_EXCP_PPE42 ; pcc->bus_model =PPC_FLAGS_INPUT_PPE42 ; pcc->bfd_mach = bfd_mach_ppc_403; pcc->flags =POWERPC_FLAG_PPE42 |POWERPC_FLAG_BUS_CLK ;
@@ -7855,6 +7880,18 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, int flags)* they can be read with "p $ivor0", "p $ivor1", etc. */ break ; +case POWERPC_EXCP_PPE42 : +qemu_fprintf (f,"SRR0 " TARGET_FMT_lx" SRR1 " TARGET_FMT_lx"\n" , + env->spr[SPR_SRR0 ], env->spr[SPR_SRR1 ]); + +qemu_fprintf (f," TCR " TARGET_FMT_lx" TSR " TARGET_FMT_lx +" ISR " TARGET_FMT_lx" EDR " TARGET_FMT_lx"\n" , + env->spr[SPR_PPE42_TCR ], env->spr[SPR_PPE42_TSR ], + env->spr[SPR_PPE42_ISR ], env->spr[SPR_PPE42_EDR ]); + +qemu_fprintf (f," PIR " TARGET_FMT_lx" IVPR " TARGET_FMT_lx"\n" , + env->spr[SPR_PPE42_PIR ], env->spr[SPR_PPE42_IVPR ]); +break ;case POWERPC_EXCP_40x: qemu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
target/ppc/excp_helper.c +163 -0
187 lines not on this page · raw message
target/ppc/tcg-excp_helper.c +12 -0
@@ -229,6 +229,18 @@ void ppc_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,case POWERPC_MMU_BOOKE206 : env->spr[SPR_BOOKE_DEAR ] = vaddr;break ; +case POWERPC_MMU_REAL : +if (env->flags &POWERPC_FLAG_PPE42 ) { + env->spr[SPR_PPE42_EDR ] = vaddr; +if (access_type ==MMU_DATA_STORE ) { + env->spr[SPR_PPE42_ISR ] |=PPE42_ISR_ST ; + }else { + env->spr[SPR_PPE42_ISR ] &= ~PPE42_ISR_ST ; + } + }else { + env->spr[SPR_DAR ] = vaddr; + } +break ;default : env->spr[SPR_DAR ] = vaddr;break ;
Signature · 1 line
2.43.0
Re: [PATCH v3 9/9] tests/functional: Add test for IBM PPE42 instructions
In reply to Glenn MilesI noticed after sending this that it did not apply cleanly to the latest master branch. Looks like the tests/functional directory structure has been changed. Not sure how this situation is normally handled. I assume I can just send out a v4 patch that is rebased on the latest master branch once I get feeedback for v3.
-Glenn
Quoted 137 lines · Glenn Miles
Adds a functional test for the IBM PPE42 instructions which downloads a test image from a public github repo and then loads and executes the image.
(see https://github.com/milesg-github/ppe42-tests for details)Test status is checked by periodically issuing 'info register' commands and checking the NIP value. If the NIP is
0xFFF80200then the test successfully executed to completion. If the machine stops before the test completes or if a 90 second timeout is reached, then the test is marked as having failed.This test does not test any PowerPC instructions as it is expected that these instructions are well covered in other tests. Only instructions that are unique to the IBM PPE42 processor are tested.
Signed-off-by Glenn Miles <[email protected]>Reviewed-by Thomas Huth <[email protected]>---
No changes from v2 patch 4
MAINTAINERS | 1 + tests/functional/meson.build | 1 + tests/functional/test_ppc_ppe42.py | 79 ++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 tests/functional/test_ppc_ppe42.pyMAINTAINERS +1
-0@@ -1536,6 +1536,7 @@ M: Glenn Miles <[email protected]> L: [email protected] S: Odd Fixes F: hw/ppc/ppe42_machine.c +F: tests/functional/test_ppc_ppe42.py PReP M: Hervé Poussineau <[email protected]>tests/functional/meson.build +1
-0@@ -233,6 +233,7 @@ tests_ppc_system_quick = [ ] tests_ppc_system_thorough = [ + 'ppc_ppe42', 'ppc_40p', 'ppc_amiga', 'ppc_bamboo',tests/functional/test_ppc_ppe42.py new file +79
-0@@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +# +# Functional tests for the IBM PPE42 processor +# +# Copyright (c) 2025, IBM Corporation +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from qemu_test import QemuSystemTest, Asset +import asyncio + +class Ppe42Machine(QemuSystemTest): + + timeout = 90 + poll_period = 1.0 + + ASSET_PPE42_TEST_IMAGE = Asset( + ('https://github.com/milesg-github/ppe42-tests/raw/refs/heads/main/' + 'images/ppe42-test.out'), + '03c1ac0fb7f6c025102a02776a93b35101dae7c14b75e4eab36a337e39042ea8') + + def _test_completed(self): + self.log.info("Checking for test completion...") + try: + output = self.vm.cmd('human-monitor-command', + command_line='info registers') + except Exception as err: + self.log.debug(f"'info registers' cmd failed due to {err=}," + " {type(err)=}") + raise + + self.log.info(output) + if "NIP fff80200" in output: + self.log.info("<test completed>") + return True + else: + self.log.info("<test not completed>") + return False + + def _wait_pass_fail(self, timeout): + while not self._test_completed(): + if timeout >= self.poll_period: + timeout = timeout - self.poll_period + self.log.info(f"Waiting {self.poll_period} seconds for test" + " to complete...") + e = None + try: + e = self.vm.event_wait('STOP', self.poll_period) + + except asyncio.TimeoutError: + self.log.info("Poll period ended.") + pass + + except Exception as err: + self.log.debug(f"event_wait() failed due to {err=}," + " {type(err)=}") + raise + + if e != None: + self.log.debug(f"Execution stopped: {e}") + self.log.debug("Exiting due to test failure") + self.fail("Failure detected!") + break + else: + self.fail("Timed out waiting for test completion.") + + def test_ppe42_instructions(self): + self.set_machine('ppe42_machine') + self.require_accelerator("tcg") + image_path = self.ASSET_PPE42_TEST_IMAGE.fetch() + self.vm.add_args('-nographic') + self.vm.add_args('-device', f'loader,file={image_path}') + self.vm.add_args('-device', 'loader,addr=0xfff80040,cpu-num=0') + self.vm.add_args('-action', 'panic=pause') + self.vm.launch() + self._wait_pass_fail(self.timeout) + +if __name__ == '__main__': + QemuSystemTest.main()
Re: [PATCH v3 8/9] hw/ppc: Add a test machine for the IBM PPE42 CPU
In reply to Glenn MilesQuoted 48 lines · Glenn Miles
Adds a test machine for the IBM PPE42 processor, including a DEC, FIT, WDT and 512 KiB of ram.
The purpose of this machine is only to provide a generic platform for testing instructions of the recently added PPE42 processor model which is used extensively in the IBM Power9, Power10 and future Power server processors.
Signed-off-by Glenn Miles <[email protected]>---
Changes from v2:
- Moved decrementer changes to distinct commit
- Introduced a specific MachineState for the ppe42 Machine
- Useqdev_realizeto create the machine
- Usevalid_cpu_typesto determine validity of CPU
- Changed machine ram limit from 2GB to 512KBMAINTAINERS | 6 +++ hw/ppc/Kconfig | 9 ++++ hw/ppc/meson.build | 2 + hw/ppc/ppe42_machine.c | 102 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+)create mode 100644
hw/ppc/ppe42_machine.cMAINTAINERS +6
-0@@ -1531,6 +1531,12 @@ F: include/hw/pci-host/grackle.h F: pc-bios/qemu_vga.ndrv F: tests/functional/test_ppc_mac.py +PPE42 +M: Glenn Miles <[email protected]> +L: [email protected] +S: Odd Fixes +F: hw/ppc/ppe42_machine.c + PReP M: Hervé Poussineau <[email protected]> L: [email protected]hw/ppc/Kconfig +0
-0@@ -44,6 +44,15 @@ config POWERNV select SSI_M25P80
hw/ppc/Kconfig config POWERNV · line 54
Quoted 10 lines
hw/ppc/Kconfig +8
-0select PNV_SPI +config PPC405 + bool + default y + depends on PPC + select M48T59 + select PFLASH_CFI02 + select PPC4XX + select SERIAL
Does the machine need all the above support ?
Quoted 78 lines
hw/ppc/Kconfig +1
-0+ config PPC440 bool default yhw/ppc/meson.build +2
-0@@ -57,6 +57,8 @@ ppc_ss.add(when: 'CONFIG_POWERNV', if_true: files( 'pnv_n1_chiplet.c', )) # PowerPC 4xx boards +ppc_ss.add(when: 'CONFIG_PPC405', if_true: files( + 'ppe42_machine.c')) ppc_ss.add(when: 'CONFIG_PPC440', if_true: files( 'ppc440_bamboo.c', 'ppc440_uc.c'))hw/ppc/ppe42_machine.c new file +55
-0@@ -0,0 +1,102 @@ +/* +* Test Machine for the IBM PPE42 processor +* +* Copyright (c) 2025, IBM Corporation. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu/error-report.h" +#include "system/address-spaces.h" +#include "hw/boards.h" +#include "hw/ppc/ppc.h" +#include "system/system.h" +#include "system/reset.h" +#include "system/kvm.h" +#include "qapi/error.h" + +#define TYPE_PPE42_MACHINE MACHINE_TYPE_NAME("ppe42_machine") +typedef MachineClass Ppe42MachineClass ; +typedef struct Ppe42MachineState Ppe42MachineState ; +DECLARE_OBJ_CHECKERS (Ppe42MachineState, Ppe42MachineClass, + PPE42_MACHINE, TYPE_PPE42_MACHINE) + +struct Ppe42MachineState { +MachineState parent_obj; + +PowerPCCPU cpu; +}; + +static void main_cpu_reset (void *opaque) +{ +PowerPCCPU *cpu = opaque; + +cpu_reset (CPU (cpu)); +} + +static void ppe42_machine_init (MachineState *machine) +{ +Ppe42MachineState *pms =PPE42_MACHINE (machine); +PowerPCCPU *cpu = &pms->cpu; + +if (kvm_enabled ()) { +error_report ("machine %s does not support the KVM accelerator" , +MACHINE_GET_CLASS (machine)->name); +exit (EXIT_FAILURE ); + } + +/* init CPU */ +object_initialize_child (OBJECT (pms),"cpu" , cpu, machine->cpu_type); +if (!qdev_realize (DEVICE (cpu),NULL , &error_fatal)) { +return ; + } +
hw/ppc/ppe42_machine.c line 65
Quoted 10 lines
hw/ppc/ppe42_machine.c new file +10
-0+qemu_register_reset (main_cpu_reset, cpu); + +/* This sets the decrementer timebase */ +ppc_booke_timers_init (cpu,37500000 ,PPC_TIMER_PPE ); + +/* RAM */ +if (machine->ram_size >512 * KiB) { +error_report ("RAM size more than 512 KiB is not supported" ); +exit (1 ); + }
In case of resend, the RAM size could be tested sooner (after kvm_enabled()).
Quoted 27 lines
hw/ppc/ppe42_machine.c new file +27
-0+memory_region_add_subregion (get_system_memory (),0xfff80000 , machine->ram); +} + + +static void ppe42_machine_class_init (ObjectClass *oc,const void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +static const char *const valid_cpu_types[] = { +POWERPC_CPU_TYPE_NAME ("PPE42" ), +POWERPC_CPU_TYPE_NAME ("PPE42X" ), +POWERPC_CPU_TYPE_NAME ("PPE42XM" ), +NULL , + }; + + mc->desc ="PPE42 Test Machine" ; + mc->init = ppe42_machine_init; + mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("PPE42XM" ); + mc->valid_cpu_types = valid_cpu_types; + mc->default_ram_id ="ram" ; + mc->default_ram_size =512 * KiB; +} + +static const TypeInfo ppe42_machine_info = { + .name =TYPE_PPE42_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (Ppe42MachineState), + .class_init = ppe42_machine_class_init,
hw/ppc/ppe42_machine.c line 102
Quoted 10 lines
hw/ppc/ppe42_machine.c new file +10
-0+ .class_size = sizeof(Ppe42MachineClass), +}; + +static void ppe42_machine_register_types (void ) +{ +type_register_static (&ppe42_machine_info); +} + +type_init (ppe42_machine_register_types); +
Thanks,
C.
Re: [PATCH v3 8/9] hw/ppc: Add a test machine for the IBM PPE42 CPU
Quoted 51 lines · Cédric Le Goater
Quoted 50 lines · Glenn Miles
Adds a test machine for the IBM PPE42 processor, including a DEC, FIT, WDT and 512 KiB of ram.
The purpose of this machine is only to provide a generic platform for testing instructions of the recently added PPE42 processor model which is used extensively in the IBM Power9, Power10 and future Power server processors.
Signed-off-by Glenn Miles <[email protected]>---
Changes from v2:
- Moved decrementer changes to distinct commit
- Introduced a specific MachineState for the ppe42 Machine
- Useqdev_realizeto create the machine
- Usevalid_cpu_typesto determine validity of CPU
- Changed machine ram limit from 2GB to 512KBMAINTAINERS | 6 +++ hw/ppc/Kconfig | 9 ++++ hw/ppc/meson.build | 2 + hw/ppc/ppe42_machine.c | 102 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+)create mode 100644
hw/ppc/ppe42_machine.cMAINTAINERS +6
-0@@ -1531,6 +1531,12 @@ F: include/hw/pci-host/grackle.h F: pc-bios/qemu_vga.ndrv F: tests/functional/test_ppc_mac.py +PPE42 +M: Glenn Miles <[email protected]> +L: [email protected] +S: Odd Fixes +F: hw/ppc/ppe42_machine.c + PReP M: Hervé Poussineau <[email protected]> L: [email protected]hw/ppc/Kconfig +0
-0@@ -44,6 +44,15 @@ config POWERNV select SSI_M25P80 select PNV_SPI
Quoted 10 lines
hw/ppc/Kconfig config POWERNV · line 54
Quoted 8 lines
hw/ppc/Kconfig +8
-0+config PPC405 + bool + default y + depends on PPC + select M48T59 + select PFLASH_CFI02 + select PPC4XX + select SERIALDoes the machine need all the above support ?
No, it only needs PPC4XX. I'll remove the others.
Quoted 83 lines
Quoted 83 lines
hw/ppc/Kconfig +1
-0+ config PPC440 bool default yhw/ppc/meson.build +2
-0@@ -57,6 +57,8 @@ ppc_ss.add(when: 'CONFIG_POWERNV', if_true: files( 'pnv_n1_chiplet.c', )) # PowerPC 4xx boards +ppc_ss.add(when: 'CONFIG_PPC405', if_true: files( + 'ppe42_machine.c')) ppc_ss.add(when: 'CONFIG_PPC440', if_true: files( 'ppc440_bamboo.c', 'ppc440_uc.c'))hw/ppc/ppe42_machine.c new file +59
-0@@ -0,0 +1,102 @@ +/* +* Test Machine for the IBM PPE42 processor +* +* Copyright (c) 2025, IBM Corporation. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu/error-report.h" +#include "system/address-spaces.h" +#include "hw/boards.h" +#include "hw/ppc/ppc.h" +#include "system/system.h" +#include "system/reset.h" +#include "system/kvm.h" +#include "qapi/error.h" + +#define TYPE_PPE42_MACHINE MACHINE_TYPE_NAME("ppe42_machine") +typedef MachineClass Ppe42MachineClass ; +typedef struct Ppe42MachineState Ppe42MachineState ; +DECLARE_OBJ_CHECKERS (Ppe42MachineState, Ppe42MachineClass, + PPE42_MACHINE, TYPE_PPE42_MACHINE) + +struct Ppe42MachineState { +MachineState parent_obj; + +PowerPCCPU cpu; +}; + +static void main_cpu_reset (void *opaque) +{ +PowerPCCPU *cpu = opaque; + +cpu_reset (CPU (cpu)); +} + +static void ppe42_machine_init (MachineState *machine) +{ +Ppe42MachineState *pms =PPE42_MACHINE (machine); +PowerPCCPU *cpu = &pms->cpu; + +if (kvm_enabled ()) { +error_report ("machine %s does not support the KVM accelerator" , +MACHINE_GET_CLASS (machine)->name); +exit (EXIT_FAILURE ); + } + +/* init CPU */ +object_initialize_child (OBJECT (pms),"cpu" , cpu, machine->cpu_type); +if (!qdev_realize (DEVICE (cpu),NULL , &error_fatal)) { +return ; + } + +qemu_register_reset (main_cpu_reset, cpu); + +/* This sets the decrementer timebase */ +ppc_booke_timers_init (cpu,37500000 ,PPC_TIMER_PPE );
Quoted 9 lines
hw/ppc/ppe42_machine.c line 65
Quoted 6 lines
hw/ppc/ppe42_machine.c new file +6
-0+ +/* RAM */ +if (machine->ram_size >512 * KiB) { +error_report ("RAM size more than 512 KiB is not supported" ); +exit (1 ); + }In case of resend, the RAM size could be tested sooner (after
kvm_enabled()).
Sure, I'll move it up.
Quoted 40 lines
Quoted 27 lines
hw/ppc/ppe42_machine.c new file +27
-0+memory_region_add_subregion (get_system_memory (),0xfff80000 , machine->ram); +} + + +static void ppe42_machine_class_init (ObjectClass *oc,const void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +static const char *const valid_cpu_types[] = { +POWERPC_CPU_TYPE_NAME ("PPE42" ), +POWERPC_CPU_TYPE_NAME ("PPE42X" ), +POWERPC_CPU_TYPE_NAME ("PPE42XM" ), +NULL , + }; + + mc->desc ="PPE42 Test Machine" ; + mc->init = ppe42_machine_init; + mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("PPE42XM" ); + mc->valid_cpu_types = valid_cpu_types; + mc->default_ram_id ="ram" ; + mc->default_ram_size =512 * KiB; +} + +static const TypeInfo ppe42_machine_info = { + .name =TYPE_PPE42_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (Ppe42MachineState), + .class_init = ppe42_machine_class_init,hw/ppc/ppe42_machine.c line 102
Quoted 10 lines
hw/ppc/ppe42_machine.c new file +10
-0+ .class_size = sizeof(Ppe42MachineClass), +}; + +static void ppe42_machine_register_types (void ) +{ +type_register_static (&ppe42_machine_info); +} + +type_init (ppe42_machine_register_types); +Reviewed-by Cédric Le Goater <[email protected]>
Quoted 4 lines
Thanks,
C.
Thank you for your help!
Glenn
Re: [PATCH v3 6/9] target/ppc: Add IBM PPE42 special instructions
In reply to Glenn MilesQuoted 274 lines · Glenn Miles
Adds the following instructions exclusively for
IBM PPE42 processors:LSKU
LCXU
STSKU
STCXU
LVD
LVDU
LVDX
STVD
STVDU
STVDX
SLVD
SRVD
CMPWBC
CMPLWBC
CMPWIBC
BNBWI
BNBW
CLRBWIBC
CLRWBC
DCBQ
RLDICL
RLDICR
RLDIMIA PPE42 GCC compiler is available here:
https://github.com/open-power/ppe42-gccFor more information on the PPE42 processors please visit:
https://wiki.raptorcs.com/w/images/a/a3/PPE_42X_Core_Users_Manual.pdfSigned-off-by Glenn Miles <[email protected]>---
Changes from v2:
- Utilized the TRANS macro to reduce codetarget/ppc/insn32.decode | 66 ++- target/ppc/translate.c | 29 +- target/ppc/translate/ppe-impl.c.inc | 663 ++++++++++++++++++++++++++++ 3 files changed, 748 insertions(+), 10 deletions(-)create mode 100644 target/ppc/translate/ppe-impl.c.inc
target/ppc/insn32.decode +62
-4@@ -58,6 +58,10 @@ %ds_rtp 22:4 !function=times_2 @DS_rtp ...... ....0 ra:5 .............. .. &D rt=%ds_rtp si=%ds_si +%dd_si 3:s13 +&DD rt ra si:int64_t +@DD ...... rt:5 ra:5 ............. . .. &DD si=%dd_si + &DX_b vrt b %dx_b 6:10 16:5 0:1 @DX_b ...... vrt:5 ..... .......... ..... . &DX_b b=%dx_b@@ -66,6 +70,11 @@ %dx_d 6:s10 16:5 0:1 @DX ...... rt:5 ..... .......... ..... . &DX d=%dx_d +%md_sh 1:1 11:5 +%md_mb 5:1 6:5 +&MD rs ra sh mb rc +@MD ...... rs:5 ra:5 ..... ...... ... . rc:1 &MD sh=%md_sh mb=%md_mb + &VA vrt vra vrb rc @VA ...... vrt:5 vra:5 vrb:5 rc:5 ...... &VA@@ -322,6 +331,13 @@ LDUX 011111 ..... ..... ..... 0000110101 - @X LQ 111000 ..... ..... ............ ---- @DQ_rtp +LVD 000101 ..... ..... ................ @D +LVDU 001001 ..... ..... ................ @D +LVDX 011111 ..... ..... ..... 0000010001 - @X +LSKU 111010 ..... ..... ............. 0 11 @DD +LCXU 111010 ..... ..... ............. 1 11 @DD + + ### Fixed-Point Store Instructions STB 100110 ..... ..... ................ @D@@ -346,6 +362,11 @@ STDUX 011111 ..... ..... ..... 0010110101 - @X STQ 111110 ..... ..... ..............10 @DS_rtp +STVDU 010110 ..... ..... ................ @D +STVDX 011111 ..... ..... ..... 0010010001 - @X +STSKU 111110 ..... ..... ............. 0 11 @DD +STCXU 111110 ..... ..... ............. 1 11 @DD + ### Fixed-Point Compare Instructions CMP 011111 ... - . ..... ..... 0000000000 - @X_bfl@@ -461,8 +482,14 @@ PRTYD 011111 ..... ..... ----- 0010111010 - @X_sa BPERMD 011111 ..... ..... ..... 0011111100 - @X CFUGED 011111 ..... ..... ..... 0011011100 - @X -CNTLZDM 011111 ..... ..... ..... 0000111011 - @X -CNTTZDM 011111 ..... ..... ..... 1000111011 - @X +{ + SLVD 011111 ..... ..... ..... 0000111011 . @X_rc + CNTLZDM 011111 ..... ..... ..... 0000111011 - @X +} +{ + SRVD 011111 ..... ..... ..... 1000111011 . @X_rc + CNTTZDM 011111 ..... ..... ..... 1000111011 - @X +} PDEPD 011111 ..... ..... ..... 0010011100 - @X PEXTD 011111 ..... ..... ..... 0010111100 - @X@@ -981,8 +1008,16 @@ LXSSP 111001 ..... ..... .............. 11 @DS STXSSP 111101 ..... ..... .............. 11 @DS LXV 111101 ..... ..... ............ . 001 @DQ_TSX STXV 111101 ..... ..... ............ . 101 @DQ_TSX -LXVP 000110 ..... ..... ............ 0000 @DQ_TSXP -STXVP 000110 ..... ..... ............ 0001 @DQ_TSXP + +# STVD PPE instruction overlaps with the LXVP and STXVP instructions +{ + STVD 000110 ..... ..... ................ @D + [ + LXVP 000110 ..... ..... ............ 0000 @DQ_TSXP + STXVP 000110 ..... ..... ............ 0001 @DQ_TSXP + ] +} + LXVX 011111 ..... ..... ..... 0100 - 01100 . @X_TSX STXVX 011111 ..... ..... ..... 0110001100 . @X_TSX LXVPX 011111 ..... ..... ..... 0101001101 - @X_TSXP@@ -1300,3 +1335,26 @@ CLRBHRB 011111 ----- ----- ----- 0110101110 - ## Misc POWER instructions ATTN 000000 00000 00000 00000 0100000000 0 + +# Fused compare-branch instructions for PPE only +%fcb_bdx 1:s10 !function=times_4 +&FCB px:bool ra rb:uint64_t bdx lk:bool +@FCB ...... .. px:1 .. ra:5 rb:5 .......... lk:1 &FCB bdx=%fcb_bdx +&FCB_bix px:bool bix ra rb:uint64_t bdx lk:bool +@FCB_bix ...... .. px:1 bix:2 ra:5 rb:5 .......... lk:1 &FCB_bix bdx=%fcb_bdx + +CMPWBC 000001 00 . .. ..... ..... .......... . @FCB_bix +CMPLWBC 000001 01 . .. ..... ..... .......... . @FCB_bix +CMPWIBC 000001 10 . .. ..... ..... .......... . @FCB_bix +BNBWI 000001 11 . 00 ..... ..... .......... . @FCB +BNBW 000001 11 . 01 ..... ..... .......... . @FCB +CLRBWIBC 000001 11 . 10 ..... ..... .......... . @FCB +CLRBWBC 000001 11 . 11 ..... ..... .......... . @FCB + +# Data Cache Block Query for PPE only +DCBQ 011111 ..... ..... ..... 0110010110 - @X + +# Rotate Doubleword Instructions for PPE only (if TARGET_PPC64 not defined) +RLDICL 011110 ..... ..... ..... ...... 000 . . @MD +RLDICR 011110 ..... ..... ..... ...... 001 . . @MD +RLDIMI 011110 ..... ..... ..... ...... 011 . . @MDtarget/ppc/translate.c +23
-6@@ -209,6 +209,11 @@ struct DisasContext {#define DISAS_CHAIN DISAS_TARGET_2/* lookup next tb, pc updated */ #define DISAS_CHAIN_UPDATE DISAS_TARGET_3/* lookup next tb, pc stale */ +static inline bool is_ppe (const DisasContext *ctx) +{ +return !!(ctx->flags &POWERPC_FLAG_PPE42 ); +} +/* Return true iff byteswap is needed in a scalar memop */ static inline bool need_byteswap (const DisasContext *ctx) {@@ -556,11 +561,8 @@ void spr_access_nop(DisasContext *ctx, int sprn, int gprn)#endif -/* SPR common to all PowerPC */ -/* XER */ -void spr_read_xer (DisasContext *ctx,int gprn,int sprn) +static void gen_get_xer (DisasContext *ctx,TCGv dst) { -TCGv dst = cpu_gpr[gprn];TCGv t0 =tcg_temp_new ();TCGv t1 =tcg_temp_new ();TCGv t2 =tcg_temp_new ();@@ -579,9 +581,16 @@ void spr_read_xer(DisasContext *ctx, int gprn, int sprn) } } -void spr_write_xer (DisasContext *ctx,int sprn,int gprn) +/* SPR common to all PowerPC */ +/* XER */ +void spr_read_xer (DisasContext *ctx,int gprn,int sprn) +{ +TCGv dst = cpu_gpr[gprn]; +gen_get_xer (ctx, dst); +} + +static void gen_set_xer (DisasContext *ctx,TCGv src) { -TCGv src = cpu_gpr[gprn];/* Write all flags, while reading back check for isa300 */ tcg_gen_andi_tl(cpu_xer, src, ~((1u << XER_SO) |@@ -594,6 +603,12 @@ void spr_write_xer(DisasContext *ctx, int sprn, int gprn)tcg_gen_extract_tl (cpu_ca, src,XER_CA ,1 ); } +void spr_write_xer (DisasContext *ctx,int sprn,int gprn) +{ +TCGv src = cpu_gpr[gprn]; +gen_set_xer (ctx, src); +} +/* LR */ void spr_read_lr (DisasContext *ctx,int gprn,int sprn) {@@ -5755,6 +5770,8 @@ static bool resolve_PLS_D(DisasContext *ctx, arg_D *d, arg_PLS_D *a)#include "translate/bhrb-impl.c.inc" +#include "translate/ppe-impl.c.inc" +/* Handles lfdp */ static void gen_dform39 (DisasContext *ctx) {target/ppc/translate/ppe-impl.c.inc new file +37
-0@@ -0,0 +1,663 @@ +/* + * IBM PPE Instructions + * + * Copyright (c) 2025, IBM Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + + +#if !defined(TARGET_PPC64) +static bool vdr_is_valid(uint32_t vdr) +{ + const uint32_t valid_bitmap = 0xf00003ff; + return !!((1ul << (vdr & 0x1f)) & valid_bitmap); +} + +static bool ppe_gpr_is_valid(uint32_t reg) +{ + const uint32_t valid_bitmap = 0xf00027ff; + return !!((1ul << (reg & 0x1f)) & valid_bitmap); +} +#endif + +#define CHECK_VDR(CTX, VDR) \ + do { \ + if (unlikely(!vdr_is_valid(VDR))) { \ + gen_invalid(CTX); \ + return true; \ + } \ + } while (0) + +#define CHECK_PPE_GPR(CTX, REG) \ + do { \ + if (unlikely(!ppe_gpr_is_valid(REG))) { \ + gen_invalid(CTX); \ + return true; \ + } \
target/ppc/translate/ppe-impl.c.inc line 47
Quoted 10 lines
target/ppc/translate/ppe-impl.c.inc new file +10
-0+ } while (0) + +#define CHECK_VDR(CTX, VDR) \ + do { \ + if (unlikely(!vdr_is_valid(VDR))) { \ + gen_invalid(CTX); \ + return true; \ + } \ + } while (0) +
Hey Glenn,
Looks like this CHECK_VDR macro is defined twice with the same definition.
Quoted 314 lines
target/ppc/translate/ppe-impl.c.inc new file +314
-0+#define VDR_PAIR_REG(VDR) (((VDR) + 1) & 0x1f) + +#define CHECK_PPE_LEVEL(CTX, LVL) \ + do { \ + if (unlikely(!((CTX)->insns_flags2 & (LVL)))) { \ + gen_invalid(CTX); \ + return true; \ + } \ + } while (0) + +static bool trans_LCXU(DisasContext *ctx, arg_LCXU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + int i; + TCGv base, EA; + TCGv lo, hi; + TCGv_i64 t8; + const uint8_t vd_list[] = {9, 7, 5, 3, 0}; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || (a->si < 0xB))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + base = tcg_temp_new(); + + tcg_gen_addi_tl(base, cpu_gpr[a->ra], a->si * 8); + gen_store_spr(SPR_PPE42_EDR, base); + + t8 = tcg_temp_new_i64(); + + tcg_gen_addi_tl(EA, base, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(cpu_gpr[31], cpu_gpr[30], t8); + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(cpu_gpr[29], cpu_gpr[28], t8); + + lo = tcg_temp_new(); + hi = tcg_temp_new(); + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(lo, hi, t8); + gen_store_spr(SPR_SRR0, hi); + gen_store_spr(SPR_SRR1, lo); + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(lo, hi, t8); + gen_set_xer(ctx, hi); + tcg_gen_mov_tl(cpu_ctr, lo); + + for (i = 0; i < sizeof(vd_list); i++) { + int vd = vd_list[i]; + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(cpu_gpr[VDR_PAIR_REG(vd)], cpu_gpr[vd], t8); + } + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(lo, hi, t8); + tcg_gen_shri_tl(hi, hi, 28); + tcg_gen_trunc_tl_i32(cpu_crf[0], hi); + gen_store_spr(SPR_SPRG0, lo); + + tcg_gen_addi_tl(EA, base, 4); + tcg_gen_qemu_ld_tl(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], base); + return true; +#endif +} + +static bool trans_LSKU(DisasContext *ctx, arg_LSKU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + int64_t n; + TCGv base, EA; + TCGv_i32 lo, hi; + TCGv_i64 t8; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || + (a->si & PPC_BIT(0)) || (a->si == 0))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + base = tcg_temp_new(); + gen_addr_register(ctx, base); + + + tcg_gen_addi_tl(base, base, a->si * 8); + gen_store_spr(SPR_PPE42_EDR, base); + + n = a->si - 1; + t8 = tcg_temp_new_i64(); + if (n > 0) { + tcg_gen_addi_tl(EA, base, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + hi = cpu_gpr[30]; + lo = cpu_gpr[31]; + tcg_gen_extr_i64_i32(lo, hi, t8); + } + if (n > 1) { + tcg_gen_addi_tl(EA, base, -16); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + hi = cpu_gpr[28]; + lo = cpu_gpr[29]; + tcg_gen_extr_i64_i32(lo, hi, t8); + } + tcg_gen_addi_tl(EA, base, 4); + tcg_gen_qemu_ld_i32(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], base); + return true; +#endif +} + +static bool trans_STCXU(DisasContext *ctx, arg_STCXU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv EA; + TCGv lo, hi; + TCGv_i64 t8; + int i; + const uint8_t vd_list[] = {9, 7, 5, 3, 0}; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || !(a->si & PPC_BIT(0)))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + tcg_gen_addi_tl(EA, cpu_gpr[a->ra], 4); + tcg_gen_qemu_st_i32(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + + gen_store_spr(SPR_PPE42_EDR, cpu_gpr[a->ra]); + + t8 = tcg_temp_new_i64(); + + tcg_gen_concat_tl_i64(t8, cpu_gpr[31], cpu_gpr[30]); + tcg_gen_addi_tl(EA, cpu_gpr[a->ra], -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + tcg_gen_concat_tl_i64(t8, cpu_gpr[29], cpu_gpr[28]); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + lo = tcg_temp_new(); + hi = tcg_temp_new(); + + gen_load_spr(hi, SPR_SRR0); + gen_load_spr(lo, SPR_SRR1); + tcg_gen_concat_tl_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + gen_get_xer(ctx, hi); + tcg_gen_mov_tl(lo, cpu_ctr); + tcg_gen_concat_tl_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + for (i = 0; i < sizeof(vd_list); i++) { + int vd = vd_list[i]; + tcg_gen_concat_tl_i64(t8, cpu_gpr[VDR_PAIR_REG(vd)], cpu_gpr[vd]); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + } + + gen_load_spr(lo, SPR_SPRG0); + tcg_gen_extu_i32_tl(hi, cpu_crf[0]); + tcg_gen_shli_tl(hi, hi, 28); + tcg_gen_concat_tl_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + tcg_gen_addi_tl(EA, cpu_gpr[a->ra], a->si * 8); + tcg_gen_qemu_st_i32(cpu_gpr[a->rt], EA, ctx->mem_idx, DEF_MEMOP(MO_32) | + MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], EA); + return true; +#endif +} + +static bool trans_STSKU(DisasContext *ctx, arg_STSKU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + int64_t n; + TCGv base, EA; + TCGv_i32 lo, hi; + TCGv_i64 t8; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || !(a->si & PPC_BIT(0)))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + base = tcg_temp_new(); + gen_addr_register(ctx, base); + tcg_gen_addi_tl(EA, base, 4); + tcg_gen_qemu_st_i32(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + + gen_store_spr(SPR_PPE42_EDR, base); + + n = ~(a->si); + + t8 = tcg_temp_new_i64(); + if (n > 0) { + hi = cpu_gpr[30]; + lo = cpu_gpr[31]; + tcg_gen_concat_i32_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, base, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + } + if (n > 1) { + hi = cpu_gpr[28]; + lo = cpu_gpr[29]; + tcg_gen_concat_i32_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, base, -16); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + } + + tcg_gen_addi_tl(EA, base, a->si * 8); + tcg_gen_qemu_st_i32(cpu_gpr[a->rt], EA, ctx->mem_idx, DEF_MEMOP(MO_32) | + MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], EA); + return true; +#endif +} + +static bool do_ppe_ldst(DisasContext *ctx, void *a, int rt, int ra, + int rb_or_si, bool update, bool store, bool indexed) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv ea; + int rt_lo; + TCGv_i64 t8; + TCGv disp; + + /* Some PowerPC CPU's have a different meaning for this instruciton */ + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_VDR(ctx, rt); + CHECK_PPE_GPR(ctx, ra); + if (indexed) { + CHECK_PPE_GPR(ctx, rb_or_si); + disp = cpu_gpr[rb_or_si]; + } else { + disp = tcg_constant_tl(rb_or_si); + } + rt_lo = VDR_PAIR_REG(rt); + if (update && (ra == 0 || (!store && ((ra == rt) || (ra == rt_lo))))) { + gen_invalid(ctx); + return true; + } + gen_set_access_type(ctx, ACCESS_INT); + + ea = do_ea_calc(ctx, ra, disp); + t8 = tcg_temp_new_i64(); + if (store) { + tcg_gen_concat_i32_i64(t8, cpu_gpr[rt_lo], cpu_gpr[rt]); + tcg_gen_qemu_st_i64(t8, ea, ctx->mem_idx, DEF_MEMOP(MO_64)); + } else { + tcg_gen_qemu_ld_i64(t8, ea, ctx->mem_idx, DEF_MEMOP(MO_64)); + tcg_gen_extr_i64_i32(cpu_gpr[rt_lo], cpu_gpr[rt], t8); + } + if (update) { + tcg_gen_mov_tl(cpu_gpr[ra], ea); + } + return true;
target/ppc/translate/ppe-impl.c.inc line 371
Quoted 10 lines
target/ppc/translate/ppe-impl.c.inc new file +10
-0+#endif +} + +TRANS(LVD, do_ppe_ldst, a->rt, a->ra, a->si, false, false, false) +TRANS(LVDU, do_ppe_ldst, a->rt, a->ra, a->si, true, false, false) +TRANS(LVDX, do_ppe_ldst, a->rt, a->ra, a->rb, false, false, true) +TRANS(STVD, do_ppe_ldst, a->rt, a->ra, a->si, false, true, false) +TRANS(STVDU, do_ppe_ldst, a->rt, a->ra, a->si, true, true, false) +TRANS(STVDX, do_ppe_ldst, a->rt, a->ra, a->rb, false, true, true) +
Hey I think a->rt and a->ra need to not be passed as args to do_ppe_ldst since they are common for
all insns but it should be fine I guess if you have them for future insns that might that different value
for that arg.
Thanks,
Chinmay
Quoted 292 lines
target/ppc/translate/ppe-impl.c.inc new file +292
-0+ +#if !defined(TARGET_PPC64) +static bool do_fcb(DisasContext *ctx, TCGv ra_val, TCGv rb_val, int bix, + int32_t bdx, bool s, bool px, bool lk) +{ + TCGCond cond; + uint32_t mask; + TCGLabel *no_branch; + target_ulong dest; + + /* Update CR0 */ + gen_op_cmp32(ra_val, rb_val, s, 0); + + if (lk) { + gen_setlr(ctx, ctx->base.pc_next); + } + + + mask = PPC_BIT32(28 + bix); + cond = (px) ? TCG_COND_TSTEQ : TCG_COND_TSTNE; + no_branch = gen_new_label(); + dest = ctx->cia + bdx; + + /* Do the branch if CR0[bix] == PX */ + tcg_gen_brcondi_i32(cond, cpu_crf[0], mask, no_branch); + gen_goto_tb(ctx, 0, dest); + gen_set_label(no_branch); + gen_goto_tb(ctx, 1, ctx->base.pc_next); + ctx->base.is_jmp = DISAS_NORETURN; + return true; +} +#endif + +static bool do_cmp_branch(DisasContext *ctx, arg_FCB_bix *a, bool s, + bool rb_is_gpr) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv old_ra; + TCGv rb_val; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_GPR(ctx, a->ra); + if (rb_is_gpr) { + CHECK_PPE_GPR(ctx, a->rb); + rb_val = cpu_gpr[a->rb]; + } else { + rb_val = tcg_constant_tl(a->rb); + } + if (a->bix == 3) { + old_ra = tcg_temp_new(); + tcg_gen_mov_tl(old_ra, cpu_gpr[a->ra]); + tcg_gen_sub_tl(cpu_gpr[a->ra], cpu_gpr[a->ra], rb_val); + return do_fcb(ctx, old_ra, rb_val, 2, + a->bdx, s, a->px, a->lk); + } else { + return do_fcb(ctx, cpu_gpr[a->ra], rb_val, a->bix, + a->bdx, s, a->px, a->lk); + } +#endif +} + +TRANS(CMPWBC, do_cmp_branch, true, true) +TRANS(CMPLWBC, do_cmp_branch, false, true) +TRANS(CMPWIBC, do_cmp_branch, true, false) + +static bool do_mask_branch(DisasContext *ctx, arg_FCB * a, bool invert, + bool update, bool rb_is_gpr) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv r; + TCGv mask, shift; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_GPR(ctx, a->ra); + if (rb_is_gpr) { + CHECK_PPE_GPR(ctx, a->rb); + mask = tcg_temp_new(); + shift = tcg_temp_new(); + tcg_gen_andi_tl(shift, cpu_gpr[a->rb], 0x1f); + tcg_gen_shr_tl(mask, tcg_constant_tl(0x80000000), shift); + } else { + mask = tcg_constant_tl(PPC_BIT32(a->rb)); + } + if (invert) { + tcg_gen_not_tl(mask, mask); + } + + /* apply mask to ra */ + r = tcg_temp_new(); + tcg_gen_and_tl(r, cpu_gpr[a->ra], mask); + if (update) { + tcg_gen_mov_tl(cpu_gpr[a->ra], r); + } + return do_fcb(ctx, r, tcg_constant_tl(0), 2, + a->bdx, false, a->px, a->lk); +#endif +} + +TRANS(BNBWI, do_mask_branch, false, false, false) +TRANS(BNBW, do_mask_branch, false, false, true) +TRANS(CLRBWIBC, do_mask_branch, true, true, false) +TRANS(CLRBWBC, do_mask_branch, true, true, true) + +#if !defined(TARGET_PPC64) +static void gen_set_Rc0_i64(DisasContext *ctx, TCGv_i64 reg) +{ + TCGv_i64 t0 = tcg_temp_new_i64(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i32 t = tcg_temp_new_i32(); + + tcg_gen_movi_i64(t0, CRF_EQ); + tcg_gen_movi_i64(t1, CRF_LT); + tcg_gen_movcond_i64(TCG_COND_LT, t0, reg, tcg_constant_i64(0), t1, t0); + tcg_gen_movi_i64(t1, CRF_GT); + tcg_gen_movcond_i64(TCG_COND_GT, t0, reg, tcg_constant_i64(0), t1, t0); + tcg_gen_extrl_i64_i32(t, t0); + tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); + tcg_gen_or_i32(cpu_crf[0], cpu_crf[0], t); +} +#endif + +static bool do_shift64(DisasContext *ctx, arg_X_rc *a, bool left) +{ +#if defined(TARGET_PPC64) + return false; +#else + int rt_lo, ra_lo; + TCGv_i64 t0, t8; + + /* Check for PPE since opcode overlaps with CNTTZDM instruction */ + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_VDR(ctx, a->rt); + CHECK_VDR(ctx, a->ra); + CHECK_PPE_GPR(ctx, a->rb); + rt_lo = VDR_PAIR_REG(a->rt); + ra_lo = VDR_PAIR_REG(a->ra); + t8 = tcg_temp_new_i64(); + + /* AND rt with a mask that is 0 when rb >= 0x40 */ + t0 = tcg_temp_new_i64(); + tcg_gen_extu_tl_i64(t0, cpu_gpr[a->rb]); + tcg_gen_shli_i64(t0, t0, 0x39); + tcg_gen_sari_i64(t0, t0, 0x3f); + + /* form 64bit value from two 32bit regs */ + tcg_gen_concat_tl_i64(t8, cpu_gpr[rt_lo], cpu_gpr[a->rt]); + + /* apply mask */ + tcg_gen_andc_i64(t8, t8, t0); + + /* do the shift */ + tcg_gen_extu_tl_i64(t0, cpu_gpr[a->rb]); + tcg_gen_andi_i64(t0, t0, 0x3f); + if (left) { + tcg_gen_shl_i64(t8, t8, t0); + } else { + tcg_gen_shr_i64(t8, t8, t0); + } + + /* split the 64bit word back into two 32bit regs */ + tcg_gen_extr_i64_tl(cpu_gpr[ra_lo], cpu_gpr[a->ra], t8); + + /* update CR0 if requested */ + if (unlikely(a->rc != 0)) { + gen_set_Rc0_i64(ctx, t8); + } + return true; +#endif +} + +TRANS(SRVD, do_shift64, false) +TRANS(SLVD, do_shift64, true) + +static bool trans_DCBQ(DisasContext *ctx, arg_DCBQ * a) +{ +#if defined(TARGET_PPC64) + return false; +#else + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_GPR(ctx, a->rt); + CHECK_PPE_GPR(ctx, a->ra); + CHECK_PPE_GPR(ctx, a->rb); + + /* No cache exists, so just set RT to 0 */ + tcg_gen_movi_tl(cpu_gpr[a->rt], 0); + return true; +#endif +} + +static bool trans_RLDIMI(DisasContext *ctx, arg_RLDIMI *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv_i64 t_rs, t_ra; + int ra_lo, rs_lo; + uint32_t sh = a->sh; + uint32_t mb = a->mb; + uint32_t me = 63 - sh; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_VDR(ctx, a->rs); + CHECK_VDR(ctx, a->ra); + + rs_lo = VDR_PAIR_REG(a->rs); + ra_lo = VDR_PAIR_REG(a->ra); + + t_rs = tcg_temp_new_i64(); + t_ra = tcg_temp_new_i64(); + + tcg_gen_concat_tl_i64(t_rs, cpu_gpr[rs_lo], cpu_gpr[a->rs]); + tcg_gen_concat_tl_i64(t_ra, cpu_gpr[ra_lo], cpu_gpr[a->ra]); + + if (mb <= me) { + tcg_gen_deposit_i64(t_ra, t_ra, t_rs, sh, me - mb + 1); + } else { + uint64_t mask = mask_u64(mb, me); + TCGv_i64 t1 = tcg_temp_new_i64(); + + tcg_gen_rotli_i64(t1, t_rs, sh); + tcg_gen_andi_i64(t1, t1, mask); + tcg_gen_andi_i64(t_ra, t_ra, ~mask); + tcg_gen_or_i64(t_ra, t_ra, t1); + } + + tcg_gen_extr_i64_tl(cpu_gpr[ra_lo], cpu_gpr[a->ra], t_ra); + + if (unlikely(a->rc != 0)) { + gen_set_Rc0_i64(ctx, t_ra); + } + return true; +#endif +} + + +static bool gen_rldinm_i64(DisasContext *ctx, arg_MD *a, int mb, int me, int sh) +{ +#if defined(TARGET_PPC64) + return false; +#else + int len = me - mb + 1; + int rsh = (64 - sh) & 63; + int ra_lo, rs_lo; + TCGv_i64 t8; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_VDR(ctx, a->rs); + CHECK_VDR(ctx, a->ra); + + rs_lo = VDR_PAIR_REG(a->rs); + ra_lo = VDR_PAIR_REG(a->ra); + t8 = tcg_temp_new_i64(); + tcg_gen_concat_tl_i64(t8, cpu_gpr[rs_lo], cpu_gpr[a->rs]); + if (sh != 0 && len > 0 && me == (63 - sh)) { + tcg_gen_deposit_z_i64(t8, t8, sh, len); + } else if (me == 63 && rsh + len <= 64) { + tcg_gen_extract_i64(t8, t8, rsh, len); + } else { + tcg_gen_rotli_i64(t8, t8, sh); + tcg_gen_andi_i64(t8, t8, mask_u64(mb, me)); + } + tcg_gen_extr_i64_tl(cpu_gpr[ra_lo], cpu_gpr[a->ra], t8); + if (unlikely(a->rc != 0)) { + gen_set_Rc0_i64(ctx, t8); + } + return true; +#endif +} + +TRANS(RLDICL, gen_rldinm_i64, a->mb, 63, a->sh) +TRANS(RLDICR, gen_rldinm_i64, 0, a->mb, a->sh) +
Re: [PATCH v3 6/9] target/ppc: Add IBM PPE42 special instructions
Quoted 288 lines · Chinmay Rath
Quoted 274 lines · Glenn Miles
Adds the following instructions exclusively for
IBM PPE42 processors:LSKU
LCXU
STSKU
STCXU
LVD
LVDU
LVDX
STVD
STVDU
STVDX
SLVD
SRVD
CMPWBC
CMPLWBC
CMPWIBC
BNBWI
BNBW
CLRBWIBC
CLRWBC
DCBQ
RLDICL
RLDICR
RLDIMIA PPE42 GCC compiler is available here:
https://github.com/open-power/ppe42-gccFor more information on the PPE42 processors please visit:
https://wiki.raptorcs.com/w/images/a/a3/PPE_42X_Core_Users_Manual.pdfSigned-off-by Glenn Miles <[email protected]>---
Changes from v2:
- Utilized the TRANS macro to reduce codetarget/ppc/insn32.decode | 66 ++- target/ppc/translate.c | 29 +- target/ppc/translate/ppe-impl.c.inc | 663 ++++++++++++++++++++++++++++ 3 files changed, 748 insertions(+), 10 deletions(-)create mode 100644 target/ppc/translate/ppe-impl.c.inc
target/ppc/insn32.decode +62
-4@@ -58,6 +58,10 @@ %ds_rtp 22:4 !function=times_2 @DS_rtp ...... ....0 ra:5 .............. .. &D rt=%ds_rtp si=%ds_si +%dd_si 3:s13 +&DD rt ra si:int64_t +@DD ...... rt:5 ra:5 ............. . .. &DD si=%dd_si + &DX_b vrt b %dx_b 6:10 16:5 0:1 @DX_b ...... vrt:5 ..... .......... ..... . &DX_b b=%dx_b@@ -66,6 +70,11 @@ %dx_d 6:s10 16:5 0:1 @DX ...... rt:5 ..... .......... ..... . &DX d=%dx_d +%md_sh 1:1 11:5 +%md_mb 5:1 6:5 +&MD rs ra sh mb rc +@MD ...... rs:5 ra:5 ..... ...... ... . rc:1 &MD sh=%md_sh mb=%md_mb + &VA vrt vra vrb rc @VA ...... vrt:5 vra:5 vrb:5 rc:5 ...... &VA@@ -322,6 +331,13 @@ LDUX 011111 ..... ..... ..... 0000110101 - @X LQ 111000 ..... ..... ............ ---- @DQ_rtp +LVD 000101 ..... ..... ................ @D +LVDU 001001 ..... ..... ................ @D +LVDX 011111 ..... ..... ..... 0000010001 - @X +LSKU 111010 ..... ..... ............. 0 11 @DD +LCXU 111010 ..... ..... ............. 1 11 @DD + + ### Fixed-Point Store Instructions STB 100110 ..... ..... ................ @D@@ -346,6 +362,11 @@ STDUX 011111 ..... ..... ..... 0010110101 - @X STQ 111110 ..... ..... ..............10 @DS_rtp +STVDU 010110 ..... ..... ................ @D +STVDX 011111 ..... ..... ..... 0010010001 - @X +STSKU 111110 ..... ..... ............. 0 11 @DD +STCXU 111110 ..... ..... ............. 1 11 @DD + ### Fixed-Point Compare Instructions CMP 011111 ... - . ..... ..... 0000000000 - @X_bfl@@ -461,8 +482,14 @@ PRTYD 011111 ..... ..... ----- 0010111010 - @X_sa BPERMD 011111 ..... ..... ..... 0011111100 - @X CFUGED 011111 ..... ..... ..... 0011011100 - @X -CNTLZDM 011111 ..... ..... ..... 0000111011 - @X -CNTTZDM 011111 ..... ..... ..... 1000111011 - @X +{ + SLVD 011111 ..... ..... ..... 0000111011 . @X_rc + CNTLZDM 011111 ..... ..... ..... 0000111011 - @X +} +{ + SRVD 011111 ..... ..... ..... 1000111011 . @X_rc + CNTTZDM 011111 ..... ..... ..... 1000111011 - @X +} PDEPD 011111 ..... ..... ..... 0010011100 - @X PEXTD 011111 ..... ..... ..... 0010111100 - @X@@ -981,8 +1008,16 @@ LXSSP 111001 ..... ..... .............. 11 @DS STXSSP 111101 ..... ..... .............. 11 @DS LXV 111101 ..... ..... ............ . 001 @DQ_TSX STXV 111101 ..... ..... ............ . 101 @DQ_TSX -LXVP 000110 ..... ..... ............ 0000 @DQ_TSXP -STXVP 000110 ..... ..... ............ 0001 @DQ_TSXP + +# STVD PPE instruction overlaps with the LXVP and STXVP instructions +{ + STVD 000110 ..... ..... ................ @D + [ + LXVP 000110 ..... ..... ............ 0000 @DQ_TSXP + STXVP 000110 ..... ..... ............ 0001 @DQ_TSXP + ] +} + LXVX 011111 ..... ..... ..... 0100 - 01100 . @X_TSX STXVX 011111 ..... ..... ..... 0110001100 . @X_TSX LXVPX 011111 ..... ..... ..... 0101001101 - @X_TSXP@@ -1300,3 +1335,26 @@ CLRBHRB 011111 ----- ----- ----- 0110101110 - ## Misc POWER instructions ATTN 000000 00000 00000 00000 0100000000 0 + +# Fused compare-branch instructions for PPE only +%fcb_bdx 1:s10 !function=times_4 +&FCB px:bool ra rb:uint64_t bdx lk:bool +@FCB ...... .. px:1 .. ra:5 rb:5 .......... lk:1 &FCB bdx=%fcb_bdx +&FCB_bix px:bool bix ra rb:uint64_t bdx lk:bool +@FCB_bix ...... .. px:1 bix:2 ra:5 rb:5 .......... lk:1 &FCB_bix bdx=%fcb_bdx + +CMPWBC 000001 00 . .. ..... ..... .......... . @FCB_bix +CMPLWBC 000001 01 . .. ..... ..... .......... . @FCB_bix +CMPWIBC 000001 10 . .. ..... ..... .......... . @FCB_bix +BNBWI 000001 11 . 00 ..... ..... .......... . @FCB +BNBW 000001 11 . 01 ..... ..... .......... . @FCB +CLRBWIBC 000001 11 . 10 ..... ..... .......... . @FCB +CLRBWBC 000001 11 . 11 ..... ..... .......... . @FCB + +# Data Cache Block Query for PPE only +DCBQ 011111 ..... ..... ..... 0110010110 - @X + +# Rotate Doubleword Instructions for PPE only (if TARGET_PPC64 not defined) +RLDICL 011110 ..... ..... ..... ...... 000 . . @MD +RLDICR 011110 ..... ..... ..... ...... 001 . . @MD +RLDIMI 011110 ..... ..... ..... ...... 011 . . @MDtarget/ppc/translate.c +23
-6@@ -209,6 +209,11 @@ struct DisasContext {#define DISAS_CHAIN DISAS_TARGET_2/* lookup next tb, pc updated */ #define DISAS_CHAIN_UPDATE DISAS_TARGET_3/* lookup next tb, pc stale */ +static inline bool is_ppe (const DisasContext *ctx) +{ +return !!(ctx->flags &POWERPC_FLAG_PPE42 ); +} +/* Return true iff byteswap is needed in a scalar memop */ static inline bool need_byteswap (const DisasContext *ctx) {@@ -556,11 +561,8 @@ void spr_access_nop(DisasContext *ctx, int sprn, int gprn)#endif -/* SPR common to all PowerPC */ -/* XER */ -void spr_read_xer (DisasContext *ctx,int gprn,int sprn) +static void gen_get_xer (DisasContext *ctx,TCGv dst) { -TCGv dst = cpu_gpr[gprn];TCGv t0 =tcg_temp_new ();TCGv t1 =tcg_temp_new ();TCGv t2 =tcg_temp_new ();@@ -579,9 +581,16 @@ void spr_read_xer(DisasContext *ctx, int gprn, int sprn) } } -void spr_write_xer (DisasContext *ctx,int sprn,int gprn) +/* SPR common to all PowerPC */ +/* XER */ +void spr_read_xer (DisasContext *ctx,int gprn,int sprn) +{ +TCGv dst = cpu_gpr[gprn]; +gen_get_xer (ctx, dst); +} + +static void gen_set_xer (DisasContext *ctx,TCGv src) { -TCGv src = cpu_gpr[gprn];/* Write all flags, while reading back check for isa300 */ tcg_gen_andi_tl(cpu_xer, src, ~((1u << XER_SO) |@@ -594,6 +603,12 @@ void spr_write_xer(DisasContext *ctx, int sprn, int gprn)tcg_gen_extract_tl (cpu_ca, src,XER_CA ,1 ); } +void spr_write_xer (DisasContext *ctx,int sprn,int gprn) +{ +TCGv src = cpu_gpr[gprn]; +gen_set_xer (ctx, src); +} +/* LR */ void spr_read_lr (DisasContext *ctx,int gprn,int sprn) {@@ -5755,6 +5770,8 @@ static bool resolve_PLS_D(DisasContext *ctx, arg_D *d, arg_PLS_D *a)#include "translate/bhrb-impl.c.inc" +#include "translate/ppe-impl.c.inc" +/* Handles lfdp */ static void gen_dform39 (DisasContext *ctx) {target/ppc/translate/ppe-impl.c.inc new file +37
-0@@ -0,0 +1,663 @@ +/* + * IBM PPE Instructions + * + * Copyright (c) 2025, IBM Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + + +#if !defined(TARGET_PPC64) +static bool vdr_is_valid(uint32_t vdr) +{ + const uint32_t valid_bitmap = 0xf00003ff; + return !!((1ul << (vdr & 0x1f)) & valid_bitmap); +} + +static bool ppe_gpr_is_valid(uint32_t reg) +{ + const uint32_t valid_bitmap = 0xf00027ff; + return !!((1ul << (reg & 0x1f)) & valid_bitmap); +} +#endif + +#define CHECK_VDR(CTX, VDR) \ + do { \ + if (unlikely(!vdr_is_valid(VDR))) { \ + gen_invalid(CTX); \ + return true; \ + } \ + } while (0) + +#define CHECK_PPE_GPR(CTX, REG) \ + do { \ + if (unlikely(!ppe_gpr_is_valid(REG))) { \ + gen_invalid(CTX); \ + return true; \ + } \target/ppc/translate/ppe-impl.c.inc line 47
Quoted 10 lines
target/ppc/translate/ppe-impl.c.inc new file +10
-0+ } while (0) + +#define CHECK_VDR(CTX, VDR) \ + do { \ + if (unlikely(!vdr_is_valid(VDR))) { \ + gen_invalid(CTX); \ + return true; \ + } \ + } while (0) +Hey Glenn,
Quoted 2 lines
Looks like this
CHECK_VDRmacro is defined twice with the same definition.
Good catch! Will remove it.
Quoted 328 lines
Quoted 314 lines
target/ppc/translate/ppe-impl.c.inc new file +314
-0+#define VDR_PAIR_REG(VDR) (((VDR) + 1) & 0x1f) + +#define CHECK_PPE_LEVEL(CTX, LVL) \ + do { \ + if (unlikely(!((CTX)->insns_flags2 & (LVL)))) { \ + gen_invalid(CTX); \ + return true; \ + } \ + } while (0) + +static bool trans_LCXU(DisasContext *ctx, arg_LCXU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + int i; + TCGv base, EA; + TCGv lo, hi; + TCGv_i64 t8; + const uint8_t vd_list[] = {9, 7, 5, 3, 0}; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || (a->si < 0xB))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + base = tcg_temp_new(); + + tcg_gen_addi_tl(base, cpu_gpr[a->ra], a->si * 8); + gen_store_spr(SPR_PPE42_EDR, base); + + t8 = tcg_temp_new_i64(); + + tcg_gen_addi_tl(EA, base, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(cpu_gpr[31], cpu_gpr[30], t8); + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(cpu_gpr[29], cpu_gpr[28], t8); + + lo = tcg_temp_new(); + hi = tcg_temp_new(); + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(lo, hi, t8); + gen_store_spr(SPR_SRR0, hi); + gen_store_spr(SPR_SRR1, lo); + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(lo, hi, t8); + gen_set_xer(ctx, hi); + tcg_gen_mov_tl(cpu_ctr, lo); + + for (i = 0; i < sizeof(vd_list); i++) { + int vd = vd_list[i]; + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(cpu_gpr[VDR_PAIR_REG(vd)], cpu_gpr[vd], t8); + } + + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + tcg_gen_extr_i64_tl(lo, hi, t8); + tcg_gen_shri_tl(hi, hi, 28); + tcg_gen_trunc_tl_i32(cpu_crf[0], hi); + gen_store_spr(SPR_SPRG0, lo); + + tcg_gen_addi_tl(EA, base, 4); + tcg_gen_qemu_ld_tl(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], base); + return true; +#endif +} + +static bool trans_LSKU(DisasContext *ctx, arg_LSKU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + int64_t n; + TCGv base, EA; + TCGv_i32 lo, hi; + TCGv_i64 t8; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || + (a->si & PPC_BIT(0)) || (a->si == 0))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + base = tcg_temp_new(); + gen_addr_register(ctx, base); + + + tcg_gen_addi_tl(base, base, a->si * 8); + gen_store_spr(SPR_PPE42_EDR, base); + + n = a->si - 1; + t8 = tcg_temp_new_i64(); + if (n > 0) { + tcg_gen_addi_tl(EA, base, -8); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + hi = cpu_gpr[30]; + lo = cpu_gpr[31]; + tcg_gen_extr_i64_i32(lo, hi, t8); + } + if (n > 1) { + tcg_gen_addi_tl(EA, base, -16); + tcg_gen_qemu_ld_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + hi = cpu_gpr[28]; + lo = cpu_gpr[29]; + tcg_gen_extr_i64_i32(lo, hi, t8); + } + tcg_gen_addi_tl(EA, base, 4); + tcg_gen_qemu_ld_i32(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], base); + return true; +#endif +} + +static bool trans_STCXU(DisasContext *ctx, arg_STCXU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv EA; + TCGv lo, hi; + TCGv_i64 t8; + int i; + const uint8_t vd_list[] = {9, 7, 5, 3, 0}; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || !(a->si & PPC_BIT(0)))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + tcg_gen_addi_tl(EA, cpu_gpr[a->ra], 4); + tcg_gen_qemu_st_i32(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + + gen_store_spr(SPR_PPE42_EDR, cpu_gpr[a->ra]); + + t8 = tcg_temp_new_i64(); + + tcg_gen_concat_tl_i64(t8, cpu_gpr[31], cpu_gpr[30]); + tcg_gen_addi_tl(EA, cpu_gpr[a->ra], -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + tcg_gen_concat_tl_i64(t8, cpu_gpr[29], cpu_gpr[28]); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + lo = tcg_temp_new(); + hi = tcg_temp_new(); + + gen_load_spr(hi, SPR_SRR0); + gen_load_spr(lo, SPR_SRR1); + tcg_gen_concat_tl_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + gen_get_xer(ctx, hi); + tcg_gen_mov_tl(lo, cpu_ctr); + tcg_gen_concat_tl_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + for (i = 0; i < sizeof(vd_list); i++) { + int vd = vd_list[i]; + tcg_gen_concat_tl_i64(t8, cpu_gpr[VDR_PAIR_REG(vd)], cpu_gpr[vd]); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + } + + gen_load_spr(lo, SPR_SPRG0); + tcg_gen_extu_i32_tl(hi, cpu_crf[0]); + tcg_gen_shli_tl(hi, hi, 28); + tcg_gen_concat_tl_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, EA, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + + tcg_gen_addi_tl(EA, cpu_gpr[a->ra], a->si * 8); + tcg_gen_qemu_st_i32(cpu_gpr[a->rt], EA, ctx->mem_idx, DEF_MEMOP(MO_32) | + MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], EA); + return true; +#endif +} + +static bool trans_STSKU(DisasContext *ctx, arg_STSKU *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + int64_t n; + TCGv base, EA; + TCGv_i32 lo, hi; + TCGv_i64 t8; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_PPE_GPR(ctx, a->rt); + + if (unlikely((a->rt != a->ra) || (a->ra == 0) || !(a->si & PPC_BIT(0)))) { + gen_invalid(ctx); + return true; + } + + EA = tcg_temp_new(); + base = tcg_temp_new(); + gen_addr_register(ctx, base); + tcg_gen_addi_tl(EA, base, 4); + tcg_gen_qemu_st_i32(cpu_lr, EA, ctx->mem_idx, DEF_MEMOP(MO_32) | MO_ALIGN); + + gen_store_spr(SPR_PPE42_EDR, base); + + n = ~(a->si); + + t8 = tcg_temp_new_i64(); + if (n > 0) { + hi = cpu_gpr[30]; + lo = cpu_gpr[31]; + tcg_gen_concat_i32_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, base, -8); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + } + if (n > 1) { + hi = cpu_gpr[28]; + lo = cpu_gpr[29]; + tcg_gen_concat_i32_i64(t8, lo, hi); + tcg_gen_addi_tl(EA, base, -16); + tcg_gen_qemu_st_i64(t8, EA, ctx->mem_idx, DEF_MEMOP(MO_64) | MO_ALIGN); + } + + tcg_gen_addi_tl(EA, base, a->si * 8); + tcg_gen_qemu_st_i32(cpu_gpr[a->rt], EA, ctx->mem_idx, DEF_MEMOP(MO_32) | + MO_ALIGN); + tcg_gen_mov_tl(cpu_gpr[a->ra], EA); + return true; +#endif +} + +static bool do_ppe_ldst(DisasContext *ctx, void *a, int rt, int ra, + int rb_or_si, bool update, bool store, bool indexed) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv ea; + int rt_lo; + TCGv_i64 t8; + TCGv disp; + + /* Some PowerPC CPU's have a different meaning for this instruciton */ + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_VDR(ctx, rt); + CHECK_PPE_GPR(ctx, ra); + if (indexed) { + CHECK_PPE_GPR(ctx, rb_or_si); + disp = cpu_gpr[rb_or_si]; + } else { + disp = tcg_constant_tl(rb_or_si); + } + rt_lo = VDR_PAIR_REG(rt); + if (update && (ra == 0 || (!store && ((ra == rt) || (ra == rt_lo))))) { + gen_invalid(ctx); + return true; + } + gen_set_access_type(ctx, ACCESS_INT); + + ea = do_ea_calc(ctx, ra, disp); + t8 = tcg_temp_new_i64(); + if (store) { + tcg_gen_concat_i32_i64(t8, cpu_gpr[rt_lo], cpu_gpr[rt]); + tcg_gen_qemu_st_i64(t8, ea, ctx->mem_idx, DEF_MEMOP(MO_64)); + } else { + tcg_gen_qemu_ld_i64(t8, ea, ctx->mem_idx, DEF_MEMOP(MO_64)); + tcg_gen_extr_i64_i32(cpu_gpr[rt_lo], cpu_gpr[rt], t8); + } + if (update) { + tcg_gen_mov_tl(cpu_gpr[ra], ea); + } + return true;target/ppc/translate/ppe-impl.c.inc line 371
Quoted 10 lines
target/ppc/translate/ppe-impl.c.inc new file +10
-0+#endif +} + +TRANS(LVD, do_ppe_ldst, a->rt, a->ra, a->si, false, false, false) +TRANS(LVDU, do_ppe_ldst, a->rt, a->ra, a->si, true, false, false) +TRANS(LVDX, do_ppe_ldst, a->rt, a->ra, a->rb, false, false, true) +TRANS(STVD, do_ppe_ldst, a->rt, a->ra, a->si, false, true, false) +TRANS(STVDU, do_ppe_ldst, a->rt, a->ra, a->si, true, true, false) +TRANS(STVDX, do_ppe_ldst, a->rt, a->ra, a->rb, false, true, true) +Hey I think
a->rtanda->raneed to not be passed as args todo_ppe_ldstsince they are common for
Quoted 9 lines
all insns but it should be fine I guess if you have them for future insns that might that different value
for that arg.
Thanks,
Chinmay
The load/store instructions actually have two different argument formats. The indexed instructions (ending with X) use the X form while the others all use the D form. I was passing a->rt and a->ra for each instruction in order to get around the fact that the type of 'a' varied. However, upon review, I think a better way to do this is to have intermediate functions that handle the differing argument types. So, I will do that instead.
Thanks,
Glenn
Quoted 292 lines
Quoted 292 lines
target/ppc/translate/ppe-impl.c.inc new file +292
-0+ +#if !defined(TARGET_PPC64) +static bool do_fcb(DisasContext *ctx, TCGv ra_val, TCGv rb_val, int bix, + int32_t bdx, bool s, bool px, bool lk) +{ + TCGCond cond; + uint32_t mask; + TCGLabel *no_branch; + target_ulong dest; + + /* Update CR0 */ + gen_op_cmp32(ra_val, rb_val, s, 0); + + if (lk) { + gen_setlr(ctx, ctx->base.pc_next); + } + + + mask = PPC_BIT32(28 + bix); + cond = (px) ? TCG_COND_TSTEQ : TCG_COND_TSTNE; + no_branch = gen_new_label(); + dest = ctx->cia + bdx; + + /* Do the branch if CR0[bix] == PX */ + tcg_gen_brcondi_i32(cond, cpu_crf[0], mask, no_branch); + gen_goto_tb(ctx, 0, dest); + gen_set_label(no_branch); + gen_goto_tb(ctx, 1, ctx->base.pc_next); + ctx->base.is_jmp = DISAS_NORETURN; + return true; +} +#endif + +static bool do_cmp_branch(DisasContext *ctx, arg_FCB_bix *a, bool s, + bool rb_is_gpr) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv old_ra; + TCGv rb_val; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_GPR(ctx, a->ra); + if (rb_is_gpr) { + CHECK_PPE_GPR(ctx, a->rb); + rb_val = cpu_gpr[a->rb]; + } else { + rb_val = tcg_constant_tl(a->rb); + } + if (a->bix == 3) { + old_ra = tcg_temp_new(); + tcg_gen_mov_tl(old_ra, cpu_gpr[a->ra]); + tcg_gen_sub_tl(cpu_gpr[a->ra], cpu_gpr[a->ra], rb_val); + return do_fcb(ctx, old_ra, rb_val, 2, + a->bdx, s, a->px, a->lk); + } else { + return do_fcb(ctx, cpu_gpr[a->ra], rb_val, a->bix, + a->bdx, s, a->px, a->lk); + } +#endif +} + +TRANS(CMPWBC, do_cmp_branch, true, true) +TRANS(CMPLWBC, do_cmp_branch, false, true) +TRANS(CMPWIBC, do_cmp_branch, true, false) + +static bool do_mask_branch(DisasContext *ctx, arg_FCB * a, bool invert, + bool update, bool rb_is_gpr) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv r; + TCGv mask, shift; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_GPR(ctx, a->ra); + if (rb_is_gpr) { + CHECK_PPE_GPR(ctx, a->rb); + mask = tcg_temp_new(); + shift = tcg_temp_new(); + tcg_gen_andi_tl(shift, cpu_gpr[a->rb], 0x1f); + tcg_gen_shr_tl(mask, tcg_constant_tl(0x80000000), shift); + } else { + mask = tcg_constant_tl(PPC_BIT32(a->rb)); + } + if (invert) { + tcg_gen_not_tl(mask, mask); + } + + /* apply mask to ra */ + r = tcg_temp_new(); + tcg_gen_and_tl(r, cpu_gpr[a->ra], mask); + if (update) { + tcg_gen_mov_tl(cpu_gpr[a->ra], r); + } + return do_fcb(ctx, r, tcg_constant_tl(0), 2, + a->bdx, false, a->px, a->lk); +#endif +} + +TRANS(BNBWI, do_mask_branch, false, false, false) +TRANS(BNBW, do_mask_branch, false, false, true) +TRANS(CLRBWIBC, do_mask_branch, true, true, false) +TRANS(CLRBWBC, do_mask_branch, true, true, true) + +#if !defined(TARGET_PPC64) +static void gen_set_Rc0_i64(DisasContext *ctx, TCGv_i64 reg) +{ + TCGv_i64 t0 = tcg_temp_new_i64(); + TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i32 t = tcg_temp_new_i32(); + + tcg_gen_movi_i64(t0, CRF_EQ); + tcg_gen_movi_i64(t1, CRF_LT); + tcg_gen_movcond_i64(TCG_COND_LT, t0, reg, tcg_constant_i64(0), t1, t0); + tcg_gen_movi_i64(t1, CRF_GT); + tcg_gen_movcond_i64(TCG_COND_GT, t0, reg, tcg_constant_i64(0), t1, t0); + tcg_gen_extrl_i64_i32(t, t0); + tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); + tcg_gen_or_i32(cpu_crf[0], cpu_crf[0], t); +} +#endif + +static bool do_shift64(DisasContext *ctx, arg_X_rc *a, bool left) +{ +#if defined(TARGET_PPC64) + return false; +#else + int rt_lo, ra_lo; + TCGv_i64 t0, t8; + + /* Check for PPE since opcode overlaps with CNTTZDM instruction */ + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_VDR(ctx, a->rt); + CHECK_VDR(ctx, a->ra); + CHECK_PPE_GPR(ctx, a->rb); + rt_lo = VDR_PAIR_REG(a->rt); + ra_lo = VDR_PAIR_REG(a->ra); + t8 = tcg_temp_new_i64(); + + /* AND rt with a mask that is 0 when rb >= 0x40 */ + t0 = tcg_temp_new_i64(); + tcg_gen_extu_tl_i64(t0, cpu_gpr[a->rb]); + tcg_gen_shli_i64(t0, t0, 0x39); + tcg_gen_sari_i64(t0, t0, 0x3f); + + /* form 64bit value from two 32bit regs */ + tcg_gen_concat_tl_i64(t8, cpu_gpr[rt_lo], cpu_gpr[a->rt]); + + /* apply mask */ + tcg_gen_andc_i64(t8, t8, t0); + + /* do the shift */ + tcg_gen_extu_tl_i64(t0, cpu_gpr[a->rb]); + tcg_gen_andi_i64(t0, t0, 0x3f); + if (left) { + tcg_gen_shl_i64(t8, t8, t0); + } else { + tcg_gen_shr_i64(t8, t8, t0); + } + + /* split the 64bit word back into two 32bit regs */ + tcg_gen_extr_i64_tl(cpu_gpr[ra_lo], cpu_gpr[a->ra], t8); + + /* update CR0 if requested */ + if (unlikely(a->rc != 0)) { + gen_set_Rc0_i64(ctx, t8); + } + return true; +#endif +} + +TRANS(SRVD, do_shift64, false) +TRANS(SLVD, do_shift64, true) + +static bool trans_DCBQ(DisasContext *ctx, arg_DCBQ * a) +{ +#if defined(TARGET_PPC64) + return false; +#else + if (unlikely(!is_ppe(ctx))) { + return false; + } + + CHECK_PPE_GPR(ctx, a->rt); + CHECK_PPE_GPR(ctx, a->ra); + CHECK_PPE_GPR(ctx, a->rb); + + /* No cache exists, so just set RT to 0 */ + tcg_gen_movi_tl(cpu_gpr[a->rt], 0); + return true; +#endif +} + +static bool trans_RLDIMI(DisasContext *ctx, arg_RLDIMI *a) +{ +#if defined(TARGET_PPC64) + return false; +#else + TCGv_i64 t_rs, t_ra; + int ra_lo, rs_lo; + uint32_t sh = a->sh; + uint32_t mb = a->mb; + uint32_t me = 63 - sh; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_VDR(ctx, a->rs); + CHECK_VDR(ctx, a->ra); + + rs_lo = VDR_PAIR_REG(a->rs); + ra_lo = VDR_PAIR_REG(a->ra); + + t_rs = tcg_temp_new_i64(); + t_ra = tcg_temp_new_i64(); + + tcg_gen_concat_tl_i64(t_rs, cpu_gpr[rs_lo], cpu_gpr[a->rs]); + tcg_gen_concat_tl_i64(t_ra, cpu_gpr[ra_lo], cpu_gpr[a->ra]); + + if (mb <= me) { + tcg_gen_deposit_i64(t_ra, t_ra, t_rs, sh, me - mb + 1); + } else { + uint64_t mask = mask_u64(mb, me); + TCGv_i64 t1 = tcg_temp_new_i64(); + + tcg_gen_rotli_i64(t1, t_rs, sh); + tcg_gen_andi_i64(t1, t1, mask); + tcg_gen_andi_i64(t_ra, t_ra, ~mask); + tcg_gen_or_i64(t_ra, t_ra, t1); + } + + tcg_gen_extr_i64_tl(cpu_gpr[ra_lo], cpu_gpr[a->ra], t_ra); + + if (unlikely(a->rc != 0)) { + gen_set_Rc0_i64(ctx, t_ra); + } + return true; +#endif +} + + +static bool gen_rldinm_i64(DisasContext *ctx, arg_MD *a, int mb, int me, int sh) +{ +#if defined(TARGET_PPC64) + return false; +#else + int len = me - mb + 1; + int rsh = (64 - sh) & 63; + int ra_lo, rs_lo; + TCGv_i64 t8; + + if (unlikely(!is_ppe(ctx))) { + return false; + } + CHECK_PPE_LEVEL(ctx, PPC2_PPE42X); + CHECK_VDR(ctx, a->rs); + CHECK_VDR(ctx, a->ra); + + rs_lo = VDR_PAIR_REG(a->rs); + ra_lo = VDR_PAIR_REG(a->ra); + t8 = tcg_temp_new_i64(); + tcg_gen_concat_tl_i64(t8, cpu_gpr[rs_lo], cpu_gpr[a->rs]); + if (sh != 0 && len > 0 && me == (63 - sh)) { + tcg_gen_deposit_z_i64(t8, t8, sh, len); + } else if (me == 63 && rsh + len <= 64) { + tcg_gen_extract_i64(t8, t8, rsh, len); + } else { + tcg_gen_rotli_i64(t8, t8, sh); + tcg_gen_andi_i64(t8, t8, mask_u64(mb, me)); + } + tcg_gen_extr_i64_tl(cpu_gpr[ra_lo], cpu_gpr[a->ra], t8); + if (unlikely(a->rc != 0)) { + gen_set_Rc0_i64(ctx, t8); + } + return true; +#endif +} + +TRANS(RLDICL, gen_rldinm_i64, a->mb, 63, a->sh) +TRANS(RLDICR, gen_rldinm_i64, 0, a->mb, a->sh) +