target/mips: add missing Octeon user-mode support
v3 cover target/mips: add missing Octeon user-mode support
This series updates MIPS linux-user unaligned-access behavior and fills in missing Octeon user-mode instruction support used by existing Octeon binaries.
The first patches model the Linux/MIPS sysmips ABI pieces needed by linux-user, including MIPS_FLUSH_CACHE, MIPS_ATOMIC_SET, and the MIPS_FIXADE policy used to control unaligned scalar access fixups. User-mode unaligned scalar accesses default to software fixups and sysmips(MIPS_FIXADE) can toggle SIGBUS/BUS_ADRALN behavior.
The Octeon patches add integer, indexed memory, atomic, multiplier, COP2 crypto, CHORD, and LLM support. The series also adds a small mips64/mips64el TCG guest test covering representative Octeon integer, multiplier, and COP2 selector paths. The final patch corrects the Octeon68XX CP1 feature bits and FCR defaults.
Changes since v1:
- Split BADDU/DMUL destination fixes into a preliminary patch.
- Split the SEQ/SNE decode refactoring into a preliminary patch.
- Moved Octeon multiplier state to uint64_t arrays and updated VMState.
- Switched Octeon helper ABIs to i64/uint64_t where applicable.
- Moved COP2 selector decode/support logic into octeon_translate.c.
- Added in-tree TCG tests for mips64 and mips64el linux-user.
- Used switch ranges and g_assert_not_reached() for SHA3/ZUC shared selector handling.
- Dropped Octeon prefixes from generic Camellia helper routines.
- Replaced the reflected GFM 64-bit carryless multiply loop with crypto/clmul.h.
- Moved the Octeon68XX CP1 CPU-model correction to the end of the series.
- Added migration coverage for Octeon COP2 crypto and LLM sparse state.
---
Changes in v3:
- Rebased on current qemu.git master.
- Split sysmips support into separate MIPS_FLUSH_CACHE, MIPS_ATOMIC_SET,
and MIPS_FIXADE patches.
- Made MIPS_ATOMIC_SET always use the MIPS separate error-result register
path for successful returns.
- Removed redundant Octeon MIPS64 checks and target-long guards from the
translator paths.
- Removed zero-register fast paths where gen_store_gpr() already handles
discarded writes.
- Reworked SEQ/SNE decode and LA* translator helpers as requested.
- Split the Octeon arithmetic/memory patch into narrower state, indexed
load, SAA/SAAD, ZCB, multiplier, and test patches.
- Switched Octeon multiplier limb accumulation to uadd64_overflow().
- Link to v2: https://lore.kernel.org/qemu-devel/20260421-mips-octeon-missing-insns-v2-v2-0-a0791df188c9@gmail.com
To: [email protected]
Cc: Laurent Vivier <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: Pierrick Bouvier <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Cc: Jiaxun Yang <[email protected]>
Cc: Aurelien Jarno <[email protected]>
Cc: Aleksandar Rikalo <[email protected]>
Cc: Huacai Chen <[email protected]>
---
James Hilliard (32):
linux-user/mips: implement sysmips(MIPS_FLUSH_CACHE) linux-user/mips: implement sysmips(MIPS_ATOMIC_SET) linux-user/mips, target/mips: honor MIPS_FIXADE for unaligned accesses target/mips: fix Octeon arithmetic destination handling target/mips: split Octeon SEQ/SNE decode
target/mips: drop Octeon zero-register fast paths target/mips: add Octeon multiplier state
target/mips: add Octeon LBX instruction
target/mips: add Octeon LHUX instruction
target/mips: add Octeon LWUX instruction
target/mips: add Octeon SAA instruction
target/mips: add Octeon SAAD instruction
target/mips: add Octeon ZCB instruction
target/mips: add Octeon ZCBT instruction
target/mips: add Octeon MTM0 instruction
target/mips: add Octeon MTP0 instruction
target/mips: add Octeon MTP1 instruction
target/mips: add Octeon MTP2 instruction
target/mips: add Octeon MTM1 instruction
target/mips: add Octeon MTM2 instruction
target/mips: add Octeon VMULU instruction
target/mips: add Octeon VMM0 instruction
target/mips: add Octeon V3MULU instruction
tests/tcg/mips: add Octeon instruction smoke test target/mips: add Octeon LA* atomic instructions target/mips: add Octeon COP2 crypto core support target/mips: add Octeon SMS4 crypto support
target/mips: add Octeon SHA3 crypto support
target/mips: add Octeon ZUC crypto support
target/mips: add Octeon Camellia crypto support target/mips: add Octeon CHORD and LLM COP2 support target/mips: expose Octeon68XX floating-point support
MAINTAINERS | 2 + linux-user/mips/cpu_loop.c | 5 + linux-user/mips/target_syscall.h | 3 + linux-user/mips64/target_syscall.h | 3 + linux-user/syscall.c | 56 + target/mips/cpu-defs.c.inc | 10 +- target/mips/cpu.c | 75 +- target/mips/cpu.h | 249 +++ target/mips/helper.h | 6 + target/mips/internal.h | 3 + target/mips/system/machine.c | 142 ++ target/mips/tcg/meson.build | 1 + target/mips/tcg/octeon.decode | 46 +- target/mips/tcg/octeon_crypto.c | 2479 +++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 595 +++++- target/mips/tcg/op_helper.c | 100 + target/mips/tcg/translate.c | 23 +- target/mips/tcg/translate.h | 1 + tests/tcg/mips/Makefile.target | 11 + tests/tcg/mips/user/isa/octeon/octeon-insns.c | 216 +++ tests/tcg/mips64/Makefile.target | 20 + tests/tcg/mips64el/Makefile.target | 8 + 22 files changed, 3997 insertions(+), 57 deletions(-)
---
base-commit: ee7eb612be8f8886d48c1d0c1f1c65e495138f83
change-id: 20260420-mips-octeon-missing-insns-v2-5e693770cf2c
Best regards,
Signature · 1 line
James Hilliard <[email protected]>
PATCH v3 1/32 linux-user/mips: implement sysmips(MIPS_FLUSH_CACHE)
Add the target sysmips dispatcher and implement MIPS_FLUSH_CACHE as a successful no-op for linux-user.
Self-modifying code is handled by QEMU's normal user-mode translation invalidation machinery, so the target ABI only needs the syscall command to be accepted.
---
Changes v2 -> v3:
- Split MIPS_FLUSH_CACHE out of the combined sysmips/MIPS_FIXADE patch. (suggested by Richard Henderson)
--- linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+)
linux-user/mips/target_syscall.h +1 -0
@@ -10,6 +10,7 @@#define TARGET_MCL_ONFAULT 4#define TARGET_FORCE_SHMLBA +#define TARGET_SYSMIPS_FLUSH_CACHE 3static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/mips64/target_syscall.h +1 -0
@@ -10,6 +10,7 @@#define TARGET_MCL_ONFAULT 4#define TARGET_FORCE_SHMLBA +#define TARGET_SYSMIPS_FLUSH_CACHE 3static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/syscall.c +17 -0
@@ -6630,6 +6630,19 @@ static abi_long do_prctl_syscall_user_dispatch(CPUArchState *env, } } +#ifdef TARGET_NR_sysmips +static abi_long do_sysmips (CPUArchState *env,abi_long cmd,abi_long arg1, +abi_long arg2) +{ +switch (cmd) { +case TARGET_SYSMIPS_FLUSH_CACHE : +return 0 ; +default : +return -TARGET_EINVAL ; + } +} +#endif +static abi_long do_prctl (CPUArchState *env,abi_long option,abi_long arg2,abi_long arg3,abi_long arg4,abi_long arg5) {
@@ -12102,6 +12115,10 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,case TARGET_NR_prctl:return do_prctl (cpu_env, arg1, arg2, arg3, arg4, arg5);break ; +#ifdef TARGET_NR_sysmips +case TARGET_NR_sysmips: +return do_sysmips (cpu_env, arg1, arg2, arg3); +#endif #ifdef TARGET_NR_arch_prctlcase TARGET_NR_arch_prctl:return do_arch_prctl (cpu_env, arg1, arg2);
Signature · 1 line
2.54.0
Re: [PATCH v3 01/32] linux-user/mips: implement sysmips(MIPS_FLUSH_CACHE)
Quoted 12 lines · James Hilliard
Add the target sysmips dispatcher and implement
MIPS_FLUSH_CACHEas a successful no-op for linux-user.Self-modifying code is handled by QEMU's normal user-mode translation invalidation machinery, so the target ABI only needs the syscall command to be accepted.
Signed-off-by James Hilliard<[email protected]>---
Changes v2 -> v3:
- SplitMIPS_FLUSH_CACHEout of the combined sysmips/MIPS_FIXADE patch. (suggested by Richard Henderson)
Quoted 5 lines
--- linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+)
r~
PATCH v3 2/32 linux-user/mips: implement sysmips(MIPS_ATOMIC_SET)
In reply to James HilliardImplement the MIPS_ATOMIC_SET sysmips command as an aligned 32-bit atomic exchange in target memory.
MIPS reports syscall errors through a separate register, so successful old values can overlap the errno range. Write the return value and error flag directly and return -QEMU_ESIGRETURN so the common syscall path leaves the registers unchanged.
---
Changes v2 -> v3:
- Split MIPS_ATOMIC_SET out of the combined sysmips/MIPS_FIXADE patch. (suggested by Richard Henderson)
- Always use the explicit MIPS return-register path for successful atomic_set results. (suggested by Richard Henderson)
--- linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+)
linux-user/mips/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/mips64/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/syscall.c +31 -0
@@ -6631,10 +6631,41 @@ static abi_long do_prctl_syscall_user_dispatch(CPUArchState *env, }#ifdef TARGET_NR_sysmips +static abi_long do_sysmips_atomic_set (CPUArchState *env,abi_ulong addr, +abi_long value) +{ +uint32_t *ptr; +abi_long old; + +if (addr &3 ) { +return -TARGET_EINVAL ; + } + + ptr =lock_user (VERIFY_WRITE , addr,sizeof (*ptr), true); +if (!ptr) { +return -TARGET_EINVAL ; + } + + old =tswap32 (qatomic_xchg (ptr,tswap32 ((uint32_t )value))); +unlock_user (ptr, addr,sizeof (*ptr)); + +/* +* MIPS uses a separate error flag, but the common linux-user syscall +* path infers that flag from the return value. Successful atomic_set +* results can overlap the target errno range, so write the result +* registers here and ask the CPU loop to leave them alone. +*/ + env->active_tc.gpr[2 ] = old; + env->active_tc.gpr[7 ] =0 ; +return -QEMU_ESIGRETURN ; +} +static abi_long do_sysmips (CPUArchState *env,abi_long cmd,abi_long arg1,abi_long arg2) {switch (cmd) { +case TARGET_SYSMIPS_ATOMIC_SET : +return do_sysmips_atomic_set (env, arg1, arg2);case TARGET_SYSMIPS_FLUSH_CACHE :return 0 ;default :
Signature · 1 line
2.54.0
Re: [PATCH v3 02/32] linux-user/mips: implement sysmips(MIPS_ATOMIC_SET)
Quoted 15 lines · James Hilliard
Implement the
MIPS_ATOMIC_SETsysmips command as an aligned 32-bit atomic exchange in target memory.MIPS reports syscall errors through a separate register, so successful old values can overlap the errno range. Write the return value and error flag directly and return -QEMU_ESIGRETURN so the common syscall path leaves the registers unchanged.
Signed-off-by James Hilliard<[email protected]>---
Changes v2 -> v3:
- SplitMIPS_ATOMIC_SETout of the combined sysmips/MIPS_FIXADE patch. (suggested by Richard Henderson)
- Always use the explicit MIPS return-register path for successfulatomic_setresults. (suggested by Richard Henderson)
Quoted 5 lines
--- linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+)
r~
PATCH v3 3/32 linux-user/mips, target/mips: honor MIPS_FIXADE for unaligned accesses
In reply to James HilliardLinux/MIPS enables software fixups for user-mode unaligned scalar accesses by default through MIPS_FIXADE/TIF_FIXADE. QEMU linux-user did not model that ABI, so MIPS guests took fatal AdEL/AdES exceptions unless translation was forced to use unaligned host accesses.
Key MIPS translation blocks on the linux-user unaligned policy, implement sysmips(MIPS_FIXADE) to toggle that policy, and raise SIGBUS/BUS_ADRALN when fixups are disabled.
---
Changes v2 -> v3:
- Split MIPS_FLUSH_CACHE and MIPS_ATOMIC_SET into preparatory sysmips patches. (suggested by Richard Henderson)
--- linux-user/mips/cpu_loop.c | 5 +++++ linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 8 ++++++++ target/mips/cpu.c | 8 ++++++-- target/mips/cpu.h | 4 ++++ target/mips/tcg/translate.c | 6 +++++- 7 files changed, 30 insertions(+), 3 deletions(-)
linux-user/mips/cpu_loop.c +5 -0
@@ -161,6 +161,11 @@ done_syscall:case EXCP_DSPDIS :force_sig (TARGET_SIGILL );break ; +case EXCP_AdEL: +case EXCP_AdES: +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , + env->CP0_BadVAddr); +break ;case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */ break ;
linux-user/mips/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_FIXADE 7#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env)
linux-user/mips64/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_FIXADE 7#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env)
linux-user/syscall.c +8 -0
@@ -6663,9 +6663,17 @@ static abi_long do_sysmips_atomic_set(CPUArchState *env, abi_ulong addr,static abi_long do_sysmips (CPUArchState *env,abi_long cmd,abi_long arg1,abi_long arg2) { +CPUState *cs =env_cpu (env); +switch (cmd) {case TARGET_SYSMIPS_ATOMIC_SET :return do_sysmips_atomic_set (env, arg1, arg2); +case TARGET_SYSMIPS_FIXADE : +if (arg1 & ~3 ) { +return -TARGET_EINVAL ; + } + cs->prctl_unalign_sigbus = !(arg1 &1 ); +return 0 ;case TARGET_SYSMIPS_FLUSH_CACHE :return 0 ;default :
target/mips/cpu.c +6 -2
@@ -565,11 +565,15 @@ static int mips_cpu_mmu_index(CPUState *cs, bool ifunc)static TCGTBCPUState mips_get_tb_cpu_state (CPUState *cs) {CPUMIPSState *env =cpu_env (cs); +uint32_t flags = env->hflags &MIPS_HFLAG_TB_MASK ; + +#ifdef CONFIG_USER_ONLY + flags |=TB_FLAG_UNALIGN * !cs->prctl_unalign_sigbus; +#endif return (TCGTBCPUState ){ .pc = env->active_tc.PC, - .flags = env->hflags & (MIPS_HFLAG_TMASK |MIPS_HFLAG_BMASK | -MIPS_HFLAG_HWRENA_ULR ), + .flags = flags, }; }
target/mips/cpu.h +4 -0
@@ -1161,6 +1161,10 @@ typedef struct CPUArchState {#define MIPS_HFLAG_ELPA 0x4000000#define MIPS_HFLAG_ITC_CACHE 0x8000000/* CACHE instr. operates on ITC tag */ #define MIPS_HFLAG_ERL 0x10000000/* error level flag */ +#define MIPS_HFLAG_TB_MASK (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK | \ + MIPS_HFLAG_HWRENA_ULR) + +#define TB_FLAG_UNALIGN 0x40000000target_ulong btarget;/* Jump / branch target */ target_ulong bcond;/* Branch condition (if needed) */
target/mips/tcg/translate.c +5 -1
@@ -15070,6 +15070,7 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) {DisasContext *ctx =container_of (dcbase, DisasContext, base);CPUMIPSState *env =cpu_env (cs); +uint32_t tb_flags = ctx->base.tb->flags; ctx->page_start = ctx->base.pc_first &TARGET_PAGE_MASK ; ctx->saved_pc =-1 ;
@@ -15092,7 +15093,7 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->CP0_LLAddr_shift = env->CP0_LLAddr_shift; ctx->cmgcr = (env->CP0_Config3 >>CP0C3_CMGCR ) &1 ;/* Restore delay slot state from the tb context. */ - ctx->hflags = (uint32_t )ctx->base.tb->flags;/* FIXME: maybe use 64 bits? */ + ctx->hflags = tb_flags &MIPS_HFLAG_TB_MASK ; ctx->ulri = (env->CP0_Config3 >>CP0C3_ULRI ) &1 ; ctx->ps = ((env->active_fpu.fcr0 >>FCR0_PS ) &1 ) || (env->insn_flags & (INSN_LOONGSON2E |INSN_LOONGSON2F ));
@@ -15112,6 +15113,9 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->default_tcg_memop_mask = (!(ctx->insn_flags &ISA_NANOMIPS32 ) && (ctx->insn_flags & (ISA_MIPS_R6 |INSN_LOONGSON3A ))) ?MO_UNALN :MO_ALIGN ; +if (tb_flags &TB_FLAG_UNALIGN ) { + ctx->default_tcg_memop_mask =MO_UNALN ; + }/* * Execute a branch and its delay slot as a single instruction.
Signature · 1 line
2.54.0
Re: [PATCH v3 03/32] linux-user/mips, target/mips: honor MIPS_FIXADE for unaligned accesses
Quoted 14 lines · James Hilliard
Linux/MIPS enables software fixups for user-mode unaligned scalar accesses by default through MIPS_FIXADE/TIF_FIXADE. QEMU linux-user did not model that ABI, so MIPS guests took fatal AdEL/AdES exceptions unless translation was forced to use unaligned host accesses.
Key MIPS translation blocks on the linux-user unaligned policy, implement
sysmips(MIPS_FIXADE)to toggle that policy, and raise SIGBUS/BUS_ADRALN when fixups are disabled.Signed-off-by James Hilliard<[email protected]>---
Changes v2 -> v3:
- SplitMIPS_FLUSH_CACHEandMIPS_ATOMIC_SETinto preparatory sysmips patches. (suggested by Richard Henderson)
Quoted 9 lines
--- linux-user/mips/cpu_loop.c | 5 +++++ linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 8 ++++++++ target/mips/cpu.c | 8 ++++++-- target/mips/cpu.h | 4 ++++ target/mips/tcg/translate.c | 6 +++++- 7 files changed, 30 insertions(+), 3 deletions(-)
r~
PATCH v3 4/32 target/mips: fix Octeon arithmetic destination handling
In reply to James HilliardBADDU and DMUL write their results to rd, not rt. Route writes through gen_store_gpr() so rd == $zero is handled consistently.
---
Changes v1 -> v2:
- Split the BADDU/DMUL destination handling fix out of the Octeon arithmetic instruction patch. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Remove the rd == $zero fast paths and let gen_store_gpr() discard writes to $zero. (suggested by Richard Henderson)
--- target/mips/tcg/octeon_translate.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
target/mips/tcg/octeon_translate.c +4 -12
@@ -45,18 +45,14 @@ static bool trans_BADDU(DisasContext *ctx, arg_BADDU *a) {TCGv_i64 t0, t1; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 (); t1 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);gen_load_gpr (t1, a->rt);tcg_gen_add_i64 (t0, t0, t1); -tcg_gen_andi_i64 (cpu_gpr[a->rd], t0,0xff ); +tcg_gen_andi_i64 (t0, t0,0xff ); +gen_store_gpr (t0, a->rd);return true; }
@@ -64,17 +60,13 @@ static bool trans_DMUL(DisasContext *ctx, arg_DMUL *a) {TCGv_i64 t0, t1; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 (); t1 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);gen_load_gpr (t1, a->rt); -tcg_gen_mul_i64 (cpu_gpr[a->rd], t0, t1); +tcg_gen_mul_i64 (t0, t0, t1); +gen_store_gpr (t0, a->rd);return true; }
Signature · 1 line
2.54.0
Re: [PATCH v3 04/32] target/mips: fix Octeon arithmetic destination handling
Quoted 9 lines · James Hilliard
BADDU and DMUL write their results to rd, not rt. Route writes through
gen_store_gpr()so rd == $zero is handled consistently.Signed-off-by James Hilliard<[email protected]>---
Changes v1 -> v2:
- Split the BADDU/DMUL destination handling fix out of the Octeon arithmetic instruction patch. (suggested by Philippe Mathieu-Daudé)
Quoted 6 lines
Changes v2 -> v3:
- Remove the rd == $zero fast paths and letgen_store_gpr()discard writes to $zero. (suggested by Richard Henderson)--- target/mips/tcg/octeon_translate.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
r~
PATCH v3 5/32 target/mips: split Octeon SEQ/SNE decode
In reply to James HilliardDecode the equality and inequality forms as explicit SEQ/SNE and SEQI/SNEI instructions rather than using shared generated SEQNE/SEQNEI entries.
The explicit decoder names match the architectural mnemonics, which makes the translator entry points and trace/debug output easier to correlate with the instruction set.
---
Changes v1 -> v2:
- Split the SEQ/SNE decode cleanup out of the Octeon arithmetic instruction patch. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Remove the decoded ne field now that the instructions are split.
- Reuse @r3 for SEQ/SNE and pass the TCG condition into a shared translator helper. (suggested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 7 +++-- target/mips/tcg/octeon_translate.c | 52 ++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 27 deletions(-)
target/mips/tcg/octeon.decode +5 -2
@@ -30,6 +30,7 @@ BBIT 11 set:1 . 10 rs:5 ..... offset:s16 p=%bbit_p # SNEI rt, rs, immediate @r3 ...... rs:5 rt:5 rd:5 ..... ...... +&cmpi rs rt imm %bitfield_p 0:1 6:5 @bitfield ...... rs:5 rt:5 lenm1:5 ..... ..... . p=%bitfield_p
@@ -38,8 +39,10 @@ DMUL 011100 ..... ..... ..... 00000 000011 @r3 EXTS 011100 ..... ..... ..... ..... 11101 . @bitfield CINS 011100 ..... ..... ..... ..... 11001 . @bitfield POP 011100 rs:5 00000 rd:5 00000 10110 dw:1 -SEQNE 011100 rs:5 rt:5 rd:5 00000 10101 ne:1 -SEQNEI 011100 rs:5 rt:5 imm:s10 10111 ne:1 +SEQ 011100 ..... ..... ..... 00000 101010 @r3 +SNE 011100 ..... ..... ..... 00000 101011 @r3 +SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi +SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx
target/mips/tcg/octeon_translate.c +27 -25
79 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v3 05/32] target/mips: split Octeon SEQ/SNE decode
Quoted 14 lines · James Hilliard
Decode the equality and inequality forms as explicit SEQ/SNE and SEQI/SNEI instructions rather than using shared generated SEQNE/SEQNEI entries.
The explicit decoder names match the architectural mnemonics, which makes the translator entry points and trace/debug output easier to correlate with the instruction set.
Signed-off-by James Hilliard<[email protected]>---
Changes v1 -> v2:
- Split the SEQ/SNE decode cleanup out of the Octeon arithmetic instruction patch. (suggested by Philippe Mathieu-Daudé)
Quoted 8 lines
Changes v2 -> v3:
- Remove the decoded ne field now that the instructions are split.
- Reuse @r3 for SEQ/SNE and pass the TCG condition into a shared translator helper. (suggested by Richard Henderson)--- target/mips/tcg/octeon.decode | 7 +++-- target/mips/tcg/octeon_translate.c | 52 ++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 27 deletions(-)
r~
PATCH v3 6/32 target/mips: drop Octeon zero-register fast paths
In reply to James HilliardEXTS, CINS, and POP route their destination writes through gen_store_gpr(), which already discards writes to $zero. Remove the remaining translator fast paths for destination $zero so these Octeon instructions follow the same shape as BADDU/DMUL and the generic MIPS translator helpers.
---
Changes v2 -> v3:
- Remove the remaining destination $zero fast paths and let gen_store_gpr() discard writes to $zero. (suggested by Richard Henderson)
--- target/mips/tcg/octeon_translate.c | 15 --------------- 1 file changed, 15 deletions(-)
target/mips/tcg/octeon_translate.c +0 -15
@@ -74,11 +74,6 @@ static bool trans_EXTS(DisasContext *ctx, arg_EXTS *a) {TCGv_i64 t0; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);tcg_gen_sextract_i64 (t0, t0, a->p, a->lenm1 +1 );
@@ -90,11 +85,6 @@ static bool trans_CINS(DisasContext *ctx, arg_CINS *a) {TCGv_i64 t0; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);tcg_gen_deposit_z_i64 (t0, t0, a->p, a->lenm1 +1 );
@@ -106,11 +96,6 @@ static bool trans_POP(DisasContext *ctx, arg_POP *a) {TCGv_i64 t0; -if (a->rd ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);if (!a->dw) {
Signature · 1 line
2.54.0
Re: [PATCH v3 06/32] target/mips: drop Octeon zero-register fast paths
Quoted 7 lines · James Hilliard
EXTS, CINS, and POP route their destination writes through
gen_store_gpr(), which already discards writes to $zero. Remove the remaining translator fast paths for destination $zero so these Octeon instructions follow the same shape as BADDU/DMUL and the generic MIPS translator helpers.Signed-off-by James Hilliard <[email protected]>
Quoted 8 lines
---
Changes v2 -> v3:
- Remove the remaining destination $zero fast paths and letgen_store_gpr()discard writes to $zero. (suggested by Richard Henderson)--- target/mips/tcg/octeon_translate.c | 15 --------------- 1 file changed, 15 deletions(-)
r~
PATCH v3 7/32 target/mips: add Octeon multiplier state
In reply to James HilliardAdd per-thread Octeon multiplier state for the MPL and P limb banks used by the VMULU/VMM0/V3MULU instruction family.
Keep the storage in uint64_t arrays and migrate it as an Octeon-only subsection, so later instruction patches can update the architectural multiplier state without mixing state layout changes with decode support.
---
Changes v2 -> v3:
- Split the multiplier state out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/cpu.h | 4 ++++ target/mips/system/machine.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
target/mips/cpu.h +4 -0
@@ -497,6 +497,10 @@ struct TCState {target_ulong CP0_TCScheFBack;int32_t CP0_Debug_tcstatus;target_ulong CP0_UserLocal; +struct { +uint64_t MPL[2 *3 ]; +uint64_t P[2 *3 ]; + } octeon;int32_t msacsr;
target/mips/system/machine.c +33 -0
@@ -120,6 +120,17 @@ static const VMStateDescription vmstate_inactive_tc = { .fields = vmstate_tc_fields }; +static const VMStateDescription vmstate_octeon_multiplier_tc = { + .name ="cpu/tc/octeon_multiplier" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (const VMStateField []) { +VMSTATE_UINT64_ARRAY (octeon.MPL, TCState,2 *3 ), +VMSTATE_UINT64_ARRAY (octeon.P, TCState,2 *3 ), +VMSTATE_END_OF_LIST () + } +}; +/* MVP state */ static const VMStateDescription vmstate_mvp = {
@@ -247,6 +258,27 @@ static const VMStateDescription mips_vmstate_timer = { } }; +static bool mips_octeon_needed (void *opaque) +{ +MIPSCPU *cpu = opaque; + +return cpu->env.insn_flags &INSN_OCTEON ; +} + +static const VMStateDescription mips_vmstate_octeon_multiplier = { + .name ="cpu/octeon_multiplier" , + .version_id =1 , + .minimum_version_id =1 , + .needed = mips_octeon_needed, + .fields = (const VMStateField []) { +VMSTATE_STRUCT (env.active_tc,MIPSCPU ,1 , + vmstate_octeon_multiplier_tc, TCState), +VMSTATE_STRUCT_ARRAY (env.tcs,MIPSCPU ,MIPS_SHADOW_SET_MAX ,1 , + vmstate_octeon_multiplier_tc, TCState), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_mips_cpu = { .name ="cpu" , .version_id =21 ,
@@ -363,6 +395,7 @@ const VMStateDescription vmstate_mips_cpu = { }, .subsections = (const VMStateDescription * const []) { &mips_vmstate_timer, + &mips_vmstate_octeon_multiplier,NULL } };
Signature · 1 line
2.54.0
Re: [PATCH v3 07/32] target/mips: add Octeon multiplier state
Quoted 8 lines · James Hilliard
Add per-thread Octeon multiplier state for the MPL and P limb banks used by the VMULU/VMM0/V3MULU instruction family.
Keep the storage in
uint64_tarrays and migrate it as an Octeon-only subsection, so later instruction patches can update the architectural multiplier state without mixing state layout changes with decode support.Signed-off-by James Hilliard<[email protected]>
Quoted 8 lines
---
Changes v2 -> v3:
- Split the multiplier state out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)--- target/mips/cpu.h | 4 ++++ target/mips/system/machine.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
r~
Re: [PATCH v3 07/32] target/mips: add Octeon multiplier state
In reply to James HilliardQuoted 22 lines · James Hilliard
Add per-thread Octeon multiplier state for the MPL and P limb banks used by the VMULU/VMM0/V3MULU instruction family.
Keep the storage in
uint64_tarrays and migrate it as an Octeon-only subsection, so later instruction patches can update the architectural multiplier state without mixing state layout changes with decode support.Signed-off-by James Hilliard <[email protected]>---
Changes v2 -> v3:
- Split the multiplier state out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)--- target/mips/cpu.h | 4 ++++ target/mips/system/machine.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)target/mips/cpu.h +0
-0
target/mips/cpu.h struct TCState { · line 503
Quoted 7 lines
target/mips/cpu.h +4
-0@@ -497,6 +497,10 @@ struct TCState {target_ulong CP0_TCScheFBack;int32_t CP0_Debug_tcstatus;target_ulong CP0_UserLocal; +struct { +uint64_t MPL[2 *3 ]; +uint64_t P[2 *3 ]; + } octeon;
Why are there 6 elements here?
My octeon documentation only says
P0-P2 are 64-bit product registers. MPL0-MPL2 are 64-bit multiplier registers. Which makes sense in the context of v3mulu "192-bit x 64-bit unsigned multiply and add yielding a 256-bit result".
Did this get copied from something that used uint32_t?
r~
PATCH v3 8/32 target/mips: add Octeon LBX instruction
In reply to James HilliardLBX performs an indexed signed byte load from base + index and writes the sign-extended result to rd.
Wire the existing indexed-load helper to MO_SB so Octeon user-mode binaries can use the signed byte variant alongside the existing LBUX path.
---
Changes v2 -> v3:
- Split LBX out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -49,4 +49,5 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi LWX 011111 ..... ..... ..... 00000 001010 @lx LHX 011111 ..... ..... ..... 00100 001010 @lx LBUX 011111 ..... ..... ..... 00110 001010 @lx +LBX 011111 ..... ..... ..... 10110 001010 @lx LDX 011111 ..... ..... ..... 01000 001010 @lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -161,6 +161,7 @@ static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)return true; } +TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );TRANS (LWX , trans_lx,MO_SL );
Signature · 1 line
2.54.0
PATCH v3 9/32 target/mips: add Octeon LHUX instruction
In reply to James HilliardLHUX performs an indexed unsigned halfword load from base + index and zero-extends the result into rd.
Add the decode entry and reuse the common indexed-load translator with MO_UW.
---
Changes v2 -> v3:
- Split LHUX out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -48,6 +48,7 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi @lx ...... base:5 index:5 rd:5 ...... ..... &lx LWX 011111 ..... ..... ..... 00000 001010 @lx LHX 011111 ..... ..... ..... 00100 001010 @lx +LHUX 011111 ..... ..... ..... 10100 001010 @lx LBUX 011111 ..... ..... ..... 00110 001010 @lx LBX 011111 ..... ..... ..... 10110 001010 @lx LDX 011111 ..... ..... ..... 01000 001010 @lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -164,5 +164,6 @@ static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW ); +TRANS (LHUX , trans_lx,MO_UW );TRANS (LWX , trans_lx,MO_SL );TRANS (LDX , trans_lx,MO_UQ );
Signature · 1 line
2.54.0
PATCH v3 10/32 target/mips: add Octeon LWUX instruction
In reply to James HilliardLWUX performs an indexed unsigned word load from base + index and zero-extends the result into rd.
Add the decode entry and route it through the common indexed-load translator with MO_UL.
---
Changes v2 -> v3:
- Split LWUX out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -50,5 +50,6 @@ LWX 011111 ..... ..... ..... 00000 001010 @lx LHX 011111 ..... ..... ..... 00100 001010 @lx LHUX 011111 ..... ..... ..... 10100 001010 @lx LBUX 011111 ..... ..... ..... 00110 001010 @lx +LWUX 011111 ..... ..... ..... 10000 001010 @lx LBX 011111 ..... ..... ..... 10110 001010 @lx LDX 011111 ..... ..... ..... 01000 001010 @lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -166,4 +166,5 @@ TRANS(LBUX, trans_lx, MO_UB);TRANS (LHX , trans_lx,MO_SW );TRANS (LHUX , trans_lx,MO_UW );TRANS (LWX , trans_lx,MO_SL ); +TRANS (LWUX , trans_lx,MO_UL );TRANS (LDX , trans_lx,MO_UQ );
Signature · 1 line
2.54.0
PATCH v3 11/32 target/mips: add Octeon SAA instruction
In reply to James HilliardSAA atomically adds rt to the naturally aligned 32-bit word at base and discards the old memory value.
Implement it with TCG atomic_fetch_add_i32 using Octeon L2 transaction alignment semantics.
---
Changes v2 -> v3:
- Split SAA out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
target/mips/tcg/octeon.decode +4 -0
@@ -44,6 +44,10 @@ SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +&saa base rt +@saa ...... base:5 rt:5 ................ &saa +SAA 011100 ..... ..... 00000 00000 011000 @saa + &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx LWX 011111 ..... ..... ..... 00000 001010 @lx
target/mips/tcg/octeon_translate.c +27 -0
@@ -161,6 +161,33 @@ static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)return true; } +static bool trans_saa (DisasContext *ctx,arg_saa *a,MemOp mop) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); +MemOp amo =mo_endian (ctx) | mop |MO_ALIGN ; + +gen_base_offset_addr (ctx, addr, a->base,0 ); + +if (mop ==MO_UQ ) { +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i64 old =tcg_temp_new_i64 (); + +gen_load_gpr (value, a->rt); +tcg_gen_atomic_fetch_add_i64 (old, addr, value, ctx->mem_idx, amo); + }else { +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i32 value32 =tcg_temp_new_i32 (); +TCGv_i32 old =tcg_temp_new_i32 (); + +gen_load_gpr (value, a->rt); +tcg_gen_extrl_i64_i32 (value32, value); +tcg_gen_atomic_fetch_add_i32 (old, addr, value32, ctx->mem_idx, amo); + } + +return true; +} + +TRANS (SAA , trans_saa,MO_UL );TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
Signature · 1 line
2.54.0
Re: [PATCH v3 11/32] target/mips: add Octeon SAA instruction
Quoted 54 lines · James Hilliard
SAA atomically adds rt to the naturally aligned 32-bit word at base and discards the old memory value.
Implement it with TCG
atomic_fetch_add_i32using Octeon L2 transaction alignment semantics.Signed-off-by James Hilliard <[email protected]>---
Changes v2 -> v3:
- Split SAA out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)target/mips/tcg/octeon.decode +4
-0@@ -44,6 +44,10 @@ SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +&saa base rt +@saa ...... base:5 rt:5 ................ &saa +SAA 011100 ..... ..... 00000 00000 011000 @saa + &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx LWX 011111 ..... ..... ..... 00000 001010 @lxtarget/mips/tcg/octeon_translate.c +15
-0@@ -161,6 +161,33 @@ static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)return true; } +static bool trans_saa (DisasContext *ctx,arg_saa *a,MemOp mop) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); +MemOp amo =mo_endian (ctx) | mop |MO_ALIGN ; + +gen_base_offset_addr (ctx, addr, a->base,0 ); + +if (mop ==MO_UQ ) { +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i64 old =tcg_temp_new_i64 (); + +gen_load_gpr (value, a->rt); +tcg_gen_atomic_fetch_add_i64 (old, addr, value, ctx->mem_idx, amo); + }else { +TCGv_i64 value =tcg_temp_new_i64 ();
target/mips/tcg/octeon_translate.c static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop) · line 188
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+TCGv_i32 value32 =tcg_temp_new_i32 (); +TCGv_i32 old =tcg_temp_new_i32 (); + +gen_load_gpr (value, a->rt); +tcg_gen_extrl_i64_i32 (value32, value); +tcg_gen_atomic_fetch_add_i32 (old, addr, value32, ctx->mem_idx, amo); + } + +return true; +}
No need to special-case UQ. You can always use tcg_gen_atomic_fetch_add_i64, which will do the right thing based on mop.
r~
Re: [PATCH v3 11/32] target/mips: add Octeon SAA instruction
In reply to James HilliardQuoted 7 lines · James Hilliard
SAA atomically adds rt to the naturally aligned 32-bit word at base and discards the old memory value.
Implement it with TCG
atomic_fetch_add_i32using Octeon L2 transaction alignment semantics.Signed-off-by James Hilliard <[email protected]>
Quoted 8 lines
---
Changes v2 -> v3:
- Split SAA out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
According to binutils, saa and saad are octeon+ instructions. Which makes sense, because they aren't in my octeon docs.
r~
PATCH v3 12/32 target/mips: add Octeon SAAD instruction
In reply to James HilliardSAAD is the doubleword form of SAA: it atomically adds rt to the naturally aligned 64-bit doubleword at base and discards the old memory value.
Implement it with TCG atomic_fetch_add_i64 and the same aligned transaction semantics as SAA.
---
Changes v2 -> v3:
- Split SAAD out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -47,6 +47,7 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi &saa base rt @saa ...... base:5 rt:5 ................ &saa SAA 011100 ..... ..... 00000 00000 011000 @saa +SAAD 011100 ..... ..... 00000 00000 011001 @saa &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -188,6 +188,7 @@ static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop) }TRANS (SAA , trans_saa,MO_UL ); +TRANS (SAAD , trans_saa,MO_UQ );TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
Signature · 1 line
2.54.0
PATCH v3 13/32 target/mips: add Octeon ZCB instruction
In reply to James HilliardZCB zeros the 128-byte cache block containing the base address.
Model the user-mode-visible effect by aligning the address down to a 128-byte line and storing sixteen zero doublewords to guest memory.
---
Changes v2 -> v3:
- Split ZCB out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 3 +++ target/mips/tcg/octeon_translate.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
target/mips/tcg/octeon.decode +3 -0
@@ -49,6 +49,9 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi SAA 011100 ..... ..... 00000 00000 011000 @saa SAAD 011100 ..... ..... 00000 00000 011001 @saa +&zcb base +ZCB 011100 base:5 00000 00000 11100 011111 &zcb + &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx LWX 011111 ..... ..... ..... 00000 001010 @lx
target/mips/tcg/octeon_translate.c +24 -0
@@ -187,6 +187,30 @@ static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop)return true; } +static bool trans_ZCB (DisasContext *ctx,arg_zcb *a) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); +TCGv_i64 line =tcg_temp_new_i64 (); +TCGv_i64 zero =tcg_constant_i64 (0 ); + +gen_base_offset_addr (ctx, addr, a->base,0 ); + +/* +* QEMU models ZCB/ZCBT as zeroing the containing 128-byte cache line +* in guest memory. +*/ +tcg_gen_andi_i64 (line, addr, ~0x7fULL ); + +for (int i =0 ; i <16 ; i++) { +TCGv_i64 slot =tcg_temp_new_i64 (); + +tcg_gen_addi_i64 (slot, line, i *8 ); +tcg_gen_qemu_st_i64 (zero, slot, ctx->mem_idx,mo_endian (ctx) |MO_UQ ); + } + +return true; +} +TRANS (SAA , trans_saa,MO_UL );TRANS (SAAD , trans_saa,MO_UQ );TRANS (LBX , trans_lx,MO_SB );
Signature · 1 line
2.54.0
PATCH v3 14/32 target/mips: add Octeon ZCBT instruction
In reply to James HilliardZCBT has the same user-mode memory effect as ZCB for QEMU's purposes.
Reuse the ZCB translator so both cache-block-zero forms clear the containing 128-byte line.
---
Changes v2 -> v3:
- Split ZCBT out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 5 +++++ 2 files changed, 6 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -51,6 +51,7 @@ SAAD 011100 ..... ..... 00000 00000 011001 @saa &zcb base ZCB 011100 base:5 00000 00000 11100 011111 &zcb +ZCBT 011100 base:5 00000 00000 11101 011111 &zcb &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx
target/mips/tcg/octeon_translate.c +5 -0
@@ -211,6 +211,11 @@ static bool trans_ZCB(DisasContext *ctx, arg_zcb *a)return true; } +static bool trans_ZCBT (DisasContext *ctx,arg_zcb *a) +{ +return trans_ZCB (ctx, a); +} +TRANS (SAA , trans_saa,MO_UL );TRANS (SAAD , trans_saa,MO_UQ );TRANS (LBX , trans_lx,MO_SB );
Signature · 1 line
2.54.0
PATCH v3 15/32 target/mips: add Octeon MTM0 instruction
In reply to James HilliardMTM0 loads the low multiplier operand pair from rs/rt, starts a new multiplier chain, clears the upper multiplier limbs, and resets partial products.
Add the decode and translator path that writes MPL[0] and MPL[3].
---
Changes v2 -> v3:
- Split MTM0 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 2 ++ target/mips/tcg/octeon_translate.c | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)
target/mips/tcg/octeon.decode +2 -0
@@ -43,6 +43,8 @@ SEQ 011100 ..... ..... ..... 00000 101010 @r3 SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +&r2 rs rt +MTM0 011100 rs:5 rt:5 00000 00000 001000 &r2 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +55 -0
64 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v3 15/32] target/mips: add Octeon MTM0 instruction
Quoted 41 lines · James Hilliard
MTM0 loads the low multiplier operand pair from rs/rt, starts a new multiplier chain, clears the upper multiplier limbs, and resets partial products.
Add the decode and translator path that writes MPL[0] and MPL[3].
Signed-off-by James Hilliard <[email protected]>---
Changes v2 -> v3:
- Split MTM0 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)--- target/mips/tcg/octeon.decode | 2 ++ target/mips/tcg/octeon_translate.c | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+)target/mips/tcg/octeon.decode +2
-0@@ -43,6 +43,8 @@ SEQ 011100 ..... ..... ..... 00000 101010 @r3 SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +&r2 rs rt +MTM0 011100 rs:5 rt:5 00000 00000 001000 &r2 &saa base rt @saa ...... base:5 rt:5 ................ &saatarget/mips/tcg/octeon_translate.c +4
-0@@ -216,6 +216,60 @@ static bool trans_ZCBT(DisasContext *ctx, arg_zcb *a)return trans_ZCB (ctx, a); } +static ptrdiff_t octeon_tc_mpl_offset (unsigned int index) +{ + return offsetof(CPUMIPSState, active_tc.octeon.MPL[index]); +}
target/mips/tcg/octeon_translate.c static bool trans_ZCBT(DisasContext *ctx, arg_zcb *a) · line 232
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+ +static ptrdiff_t octeon_tc_p_offset (unsigned int index) +{ + return offsetof(CPUMIPSState, active_tc.octeon.P[index]); +} + +static void octeon_store_tc_field (ptrdiff_t offset,TCGv_i64 value) +{ +tcg_gen_st_i64 (value, tcg_env, offset); +}
Are these really helpful?
target/mips/tcg/octeon_translate.c static bool trans_ZCBT(DisasContext *ctx, arg_zcb *a) · line 241
Quoted 8 lines
target/mips/tcg/octeon_translate.c +8
-0+static void octeon_zero_partial_product_state (void ) +{ +TCGv_i64 zero =tcg_constant_i64 (0 ); + +for (int i =0 ; i <2 *3 ; i++) { +octeon_store_tc_field (octeon_tc_p_offset (i), zero); + } +}
You probably want to use ARRAY_SIZE instead of "2 * 3".
target/mips/tcg/octeon_translate.c static bool trans_ZCBT(DisasContext *ctx, arg_zcb *a) · line 268
Quoted 11 lines
target/mips/tcg/octeon_translate.c +11
-0+static bool trans_mtm (DisasContext *ctx,arg_r2 *a,unsigned int index) +{ +TCGv_i64 value =tcg_temp_new_i64 (); + +gen_load_gpr (value, a->rs); +octeon_store_tc_field (octeon_tc_mpl_offset (index), value); +gen_load_gpr (value, a->rt); +octeon_store_tc_field (octeon_tc_mpl_offset (index +3 ), value); +if (index ==0 ) { +octeon_clear_upper_multiplier_state (); + }
This does not correspond to my documentation.
MPL0<63:0> = GPR[rs]
P0 = 0
P1 = 0
P2 = 0So: where's that + 3 copy come from, and where does the clear come from?
r~
PATCH v3 16/32 target/mips: add Octeon MTP0 instruction
In reply to James HilliardMTP0 loads the low partial-product pair from rs/rt into P[0] and P[3].
Add the translator storage path so subsequent VMULU/VMM0/V3MULU operations can consume guest-managed partial products.
---
Changes v2 -> v3:
- Split MTP0 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 12 ++++++++++++ 2 files changed, 13 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -45,6 +45,7 @@ SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi &r2 rs rt MTM0 011100 rs:5 rt:5 00000 00000 001000 &r2 +MTP0 011100 rs:5 rt:5 00000 00000 001001 &r2 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +12 -0
@@ -270,6 +270,17 @@ static bool trans_mtm(DisasContext *ctx, arg_r2 *a, unsigned int index)return true; } +static bool trans_mtp (DisasContext *ctx,arg_r2 *a,unsigned int index) +{ +TCGv_i64 value =tcg_temp_new_i64 (); + +gen_load_gpr (value, a->rs); +octeon_store_tc_field (octeon_tc_p_offset (index), value); +gen_load_gpr (value, a->rt); +octeon_store_tc_field (octeon_tc_p_offset (index +3 ), value); +return true; +} +TRANS (SAA , trans_saa,MO_UL );TRANS (SAAD , trans_saa,MO_UQ );TRANS (LBX , trans_lx,MO_SB );
@@ -280,3 +291,4 @@ TRANS(LWX, trans_lx, MO_SL);TRANS (LWUX , trans_lx,MO_UL );TRANS (LDX , trans_lx,MO_UQ );TRANS (MTM0 , trans_mtm,0 ); +TRANS (MTP0 , trans_mtp,0 );
Signature · 1 line
2.54.0
PATCH v3 17/32 target/mips: add Octeon MTP1 instruction
In reply to James HilliardMTP1 loads the middle partial-product pair from rs/rt into P[1] and P[4].
This completes the second guest-visible partial-product slot used by the Octeon multiplier helpers.
---
Changes v2 -> v3:
- Split MTP1 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -46,6 +46,7 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi &r2 rs rt MTM0 011100 rs:5 rt:5 00000 00000 001000 &r2 MTP0 011100 rs:5 rt:5 00000 00000 001001 &r2 +MTP1 011100 rs:5 rt:5 00000 00000 001010 &r2 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +1 -0
@@ -292,3 +292,4 @@ TRANS(LWUX, trans_lx, MO_UL);TRANS (LDX , trans_lx,MO_UQ );TRANS (MTM0 , trans_mtm,0 );TRANS (MTP0 , trans_mtp,0 ); +TRANS (MTP1 , trans_mtp,1 );
Signature · 1 line
2.54.0
PATCH v3 18/32 target/mips: add Octeon MTP2 instruction
In reply to James HilliardMTP2 loads the high partial-product pair from rs/rt into P[2] and P[5].
This exposes the final guest-managed partial-product slot for the three-limb Octeon multiplier operations.
---
Changes v2 -> v3:
- Split MTP2 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -47,6 +47,7 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi MTM0 011100 rs:5 rt:5 00000 00000 001000 &r2 MTP0 011100 rs:5 rt:5 00000 00000 001001 &r2 MTP1 011100 rs:5 rt:5 00000 00000 001010 &r2 +MTP2 011100 rs:5 rt:5 00000 00000 001011 &r2 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +1 -0
@@ -293,3 +293,4 @@ TRANS(LDX, trans_lx, MO_UQ);TRANS (MTM0 , trans_mtm,0 );TRANS (MTP0 , trans_mtp,0 );TRANS (MTP1 , trans_mtp,1 ); +TRANS (MTP2 , trans_mtp,2 );
Signature · 1 line
2.54.0
PATCH v3 19/32 target/mips: add Octeon MTM1 instruction
In reply to James HilliardMTM1 loads the middle multiplier operand pair from rs/rt into MPL[1] and MPL[4].
Like the other MTM writes, it resets partial products so the following multiplier operation starts from the newly programmed operand state.
---
Changes v2 -> v3:
- Split MTM1 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -48,6 +48,7 @@ MTM0 011100 rs:5 rt:5 00000 00000 001000 &r2 MTP0 011100 rs:5 rt:5 00000 00000 001001 &r2 MTP1 011100 rs:5 rt:5 00000 00000 001010 &r2 MTP2 011100 rs:5 rt:5 00000 00000 001011 &r2 +MTM1 011100 rs:5 rt:5 00000 00000 001100 &r2 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +1 -0
@@ -291,6 +291,7 @@ TRANS(LWX, trans_lx, MO_SL);TRANS (LWUX , trans_lx,MO_UL );TRANS (LDX , trans_lx,MO_UQ );TRANS (MTM0 , trans_mtm,0 ); +TRANS (MTM1 , trans_mtm,1 );TRANS (MTP0 , trans_mtp,0 );TRANS (MTP1 , trans_mtp,1 );TRANS (MTP2 , trans_mtp,2 );
Signature · 1 line
2.54.0
PATCH v3 20/32 target/mips: add Octeon MTM2 instruction
In reply to James HilliardMTM2 loads the high multiplier operand pair from rs/rt into MPL[2] and MPL[5].
This supplies the final operand pair consumed by the V3MULU three-limb multiplier helper.
---
Changes v2 -> v3:
- Split MTM2 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -49,6 +49,7 @@ MTP0 011100 rs:5 rt:5 00000 00000 001001 &r2 MTP1 011100 rs:5 rt:5 00000 00000 001010 &r2 MTP2 011100 rs:5 rt:5 00000 00000 001011 &r2 MTM1 011100 rs:5 rt:5 00000 00000 001100 &r2 +MTM2 011100 rs:5 rt:5 00000 00000 001101 &r2 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +1 -0
@@ -292,6 +292,7 @@ TRANS(LWUX, trans_lx, MO_UL);TRANS (LDX , trans_lx,MO_UQ );TRANS (MTM0 , trans_mtm,0 );TRANS (MTM1 , trans_mtm,1 ); +TRANS (MTM2 , trans_mtm,2 );TRANS (MTP0 , trans_mtp,0 );TRANS (MTP1 , trans_mtp,1 );TRANS (MTP2 , trans_mtp,2 );
Signature · 1 line
2.54.0
PATCH v3 21/32 target/mips: add Octeon VMULU instruction
In reply to James HilliardVMULU multiplies the active Octeon multiplier state by rs, adds rt and queued partial products, returns the low result, and advances P[0]/P[1] with carry limbs.
Add helper and translator support for the two-limb accumulator operation.
---
Changes v2 -> v3:
- Split VMULU out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
- Use uadd64_overflow() for multiplier limb carry accumulation. (suggested by Richard Henderson)
--- target/mips/helper.h | 1 + target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 17 +++++++++++++++++ target/mips/tcg/op_helper.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+)
target/mips/helper.h +1 -0
@@ -24,6 +24,7 @@ DEF_HELPER_FLAGS_1(dbitswap, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_3(crc32, tl, tl, tl, i32) DEF_HELPER_3(crc32c, tl, tl, tl, i32) DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32) +DEF_HELPER_3 (octeon_vmulu, i64, env, i64, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon.decode +1 -0
@@ -50,6 +50,7 @@ MTP1 011100 rs:5 rt:5 00000 00000 001010 &r2 MTP2 011100 rs:5 rt:5 00000 00000 001011 &r2 MTM1 011100 rs:5 rt:5 00000 00000 001100 &r2 MTM2 011100 rs:5 rt:5 00000 00000 001101 &r2 +VMULU 011100 ..... ..... ..... 00000 001111 @r3 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +17 -0
@@ -13,6 +13,8 @@/* Include the auto-generated decoder. */ #include "decode-octeon.c.inc" +typedef void gen_helper_lmi (TCGv_i64 ,TCGv_ptr ,TCGv_i64 ,TCGv_i64 ); +static bool trans_BBIT (DisasContext *ctx,arg_BBIT *a) {TCGv_i64 p;
@@ -281,6 +283,20 @@ static bool trans_mtp(DisasContext *ctx, arg_r2 *a, unsigned int index)return true; } +static bool trans_vmul (DisasContext *ctx,arg_decode_ext_octeon1 *a, +gen_helper_lmi *helper) +{ +TCGv_i64 rs =tcg_temp_new_i64 (); +TCGv_i64 rt =tcg_temp_new_i64 (); +TCGv_i64 rd =tcg_temp_new_i64 (); + +gen_load_gpr (rs, a->rs); +gen_load_gpr (rt, a->rt); +helper (rd, tcg_env, rs, rt); +gen_store_gpr (rd, a->rd); +return true; +} +TRANS (SAA , trans_saa,MO_UL );TRANS (SAAD , trans_saa,MO_UQ );TRANS (LBX , trans_lx,MO_SB );
@@ -296,3 +312,4 @@ TRANS(MTM2, trans_mtm, 2);TRANS (MTP0 , trans_mtp,0 );TRANS (MTP1 , trans_mtp,1 );TRANS (MTP2 , trans_mtp,2 ); +TRANS (VMULU , trans_vmul, gen_helper_octeon_vmulu);
target/mips/tcg/op_helper.c +32 -0
@@ -144,6 +144,38 @@ target_ulong helper_rotx(target_ulong rs, uint32_t shift, uint32_t shiftx,return (int64_t )(int32_t )(uint32_t )tmp5; } +static void octeon_add_limb (uint64_t *sum,int limb_count, +uint64_t value,int limb) +{ +while (limb < limb_count && +uadd64_overflow (sum[limb], value, &sum[limb])) { + value =1 ; + limb++; + } +} + +uint64_t helper_octeon_vmulu (CPUMIPSState *env,uint64_t rs,uint64_t rt) +{ +uint64_t lo, hi; +uint64_t sum[3 ] = {}; + +mulu64 (&lo, &hi, env->active_tc.octeon.MPL[0 ], rs); + sum[0 ] = lo; + sum[1 ] = hi; + +mulu64 (&lo, &hi, env->active_tc.octeon.MPL[1 ], rs); +octeon_add_limb (sum,3 , lo,1 ); +octeon_add_limb (sum,3 , hi,2 ); + +octeon_add_limb (sum,3 , rt,0 ); +octeon_add_limb (sum,3 , env->active_tc.octeon.P[0 ],0 ); +octeon_add_limb (sum,3 , env->active_tc.octeon.P[1 ],1 ); + + env->active_tc.octeon.P[0 ] = sum[1 ]; + env->active_tc.octeon.P[1 ] = sum[2 ]; +return sum[0 ]; +} +/* these crc32 functions are based on target/loongarch/tcg/op_helper.c */ target_ulong helper_crc32 (target_ulong val,target_ulong m,uint32_t sz) {
Signature · 1 line
2.54.0
PATCH v3 22/32 target/mips: add Octeon VMM0 instruction
In reply to James HilliardVMM0 performs the VMULU accumulation, returns the low result, then feeds that result back into the MTM0 multiplier state with a zero high operand and clears partial products.
Add helper and translator support for this multiplier chain-update operation.
---
Changes v2 -> v3:
- Split VMM0 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/helper.h | 1 + target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + target/mips/tcg/op_helper.c | 16 ++++++++++++++++ 4 files changed, 19 insertions(+)
target/mips/helper.h +1 -0
@@ -25,6 +25,7 @@ DEF_HELPER_3(crc32, tl, tl, tl, i32) DEF_HELPER_3(crc32c, tl, tl, tl, i32) DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32) DEF_HELPER_3(octeon_vmulu, i64, env, i64, i64) +DEF_HELPER_3 (octeon_vmm0, i64, env, i64, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon.decode +1 -0
@@ -51,6 +51,7 @@ MTP2 011100 rs:5 rt:5 00000 00000 001011 &r2 MTM1 011100 rs:5 rt:5 00000 00000 001100 &r2 MTM2 011100 rs:5 rt:5 00000 00000 001101 &r2 VMULU 011100 ..... ..... ..... 00000 001111 @r3 +VMM0 011100 ..... ..... ..... 00000 010000 @r3 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +1 -0
@@ -313,3 +313,4 @@ TRANS(MTP0, trans_mtp, 0);TRANS (MTP1 , trans_mtp,1 );TRANS (MTP2 , trans_mtp,2 );TRANS (VMULU , trans_vmul, gen_helper_octeon_vmulu); +TRANS (VMM0 , trans_vmul, gen_helper_octeon_vmm0);
target/mips/tcg/op_helper.c +16 -0
@@ -176,6 +176,22 @@ uint64_t helper_octeon_vmulu(CPUMIPSState *env, uint64_t rs, uint64_t rt)return sum[0 ]; } +uint64_t helper_octeon_vmm0 (CPUMIPSState *env,uint64_t rs,uint64_t rt) +{ +uint64_t lo =helper_octeon_vmulu (env, rs, rt); + +/* +* Complete the VMULU accumulation, then apply the MTM0-style state +* update with the low result and a zero high operand. +*/ + env->active_tc.octeon.MPL[0 ] = lo; + env->active_tc.octeon.MPL[3 ] =0 ; +for (int i =0 ; i <2 *3 ; i++) { + env->active_tc.octeon.P[i] =0 ; + } +return lo; +} +/* these crc32 functions are based on target/loongarch/tcg/op_helper.c */ target_ulong helper_crc32 (target_ulong val,target_ulong m,uint32_t sz) {
Signature · 1 line
2.54.0
PATCH v3 23/32 target/mips: add Octeon V3MULU instruction
In reply to James HilliardV3MULU extends VMULU across all three multiplier operand pairs, adding rt and the six partial-product limbs.
Return the low result while shifting the remaining accumulated limbs back into P[0] through P[5].
---
Changes v2 -> v3:
- Split V3MULU out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- target/mips/helper.h | 1 + target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + target/mips/tcg/op_helper.c | 46 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+)
target/mips/helper.h +1 -0
@@ -26,6 +26,7 @@ DEF_HELPER_3(crc32c, tl, tl, tl, i32) DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32) DEF_HELPER_3(octeon_vmulu, i64, env, i64, i64) DEF_HELPER_3(octeon_vmm0, i64, env, i64, i64) +DEF_HELPER_3 (octeon_v3mulu, i64, env, i64, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon.decode +1 -0
@@ -52,6 +52,7 @@ MTM1 011100 rs:5 rt:5 00000 00000 001100 &r2 MTM2 011100 rs:5 rt:5 00000 00000 001101 &r2 VMULU 011100 ..... ..... ..... 00000 001111 @r3 VMM0 011100 ..... ..... ..... 00000 010000 @r3 +V3MULU 011100 ..... ..... ..... 00000 010001 @r3 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +1 -0
@@ -314,3 +314,4 @@ TRANS(MTP1, trans_mtp, 1);TRANS (MTP2 , trans_mtp,2 );TRANS (VMULU , trans_vmul, gen_helper_octeon_vmulu);TRANS (VMM0 , trans_vmul, gen_helper_octeon_vmm0); +TRANS (V3MULU , trans_vmul, gen_helper_octeon_v3mulu);
target/mips/tcg/op_helper.c +46 -0
52 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v3 24/32 tests/tcg/mips: add Octeon instruction smoke test
In reply to James HilliardAdd a mips64/mips64el linux-user TCG smoke test for representative Octeon integer, comparison, population count, and multiplier instruction paths.
Run the test with -cpu Octeon68XX and share the source between the mips64 and mips64el target directories.
---
Changes v2 -> v3:
- Split the smoke test out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- MAINTAINERS | 2 + tests/tcg/mips/Makefile.target | 11 ++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 145 ++++++++++++++++++++++++++ tests/tcg/mips64/Makefile.target | 20 ++++ tests/tcg/mips64el/Makefile.target | 8 ++ 5 files changed, 186 insertions(+)
MAINTAINERS +2 -0
@@ -311,6 +311,8 @@ F: target/mips/ F: disas/*mips.c F: docs/system/cpu-models-mips.rst.inc F: tests/tcg/mips/ +F: tests/tcg/mips64/ +F: tests/tcg/mips64el/ OpenRISC TCG CPUs M: Stafford Horne <[email protected]>
tests/tcg/mips/Makefile.target +11 -0
@@ -8,6 +8,17 @@ MIPS_SRC=$(SRC_PATH)/tests/tcg/mips # Set search path for all sources VPATH += $(MIPS_SRC) +ifneq ($(findstring 64,$(TARGET_NAME)),) +VPATH += $(MIPS_SRC)/user/isa/octeon + +MIPS64_TESTS=octeon-insns + +TESTS += $(MIPS64_TESTS) + +octeon-insns: CFLAGS+=-mabi=64 +run-octeon-insns: QEMU_OPTS+=-cpu Octeon68XX +endif + # hello-mips is 32 bit only ifeq ($(findstring 64,$(TARGET_NAME)),) MIPS_TESTS=hello-mips
tests/tcg/mips/user/isa/octeon/octeon-insns.c new file +145 -0
145 lines not on this page · raw message
tests/tcg/mips64/Makefile.target new file +20 -0
@@ -0,0 +1,20 @@ +# -*- Mode: makefile -*- +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# MIPS64 - included from tests/tcg/Makefile.target +# + +MIPS64_SRC=$(SRC_PATH)/tests/tcg/mips64 +MIPS_OCTEON_SRC=$(SRC_PATH)/tests/tcg/mips/user/isa/octeon + +# Set search path for all sources +VPATH += $(MIPS64_SRC) $(MIPS_OCTEON_SRC) + +MIPS64_TESTS=octeon-insns + +TESTS += $(MIPS64_TESTS) + +$(MIPS64_TESTS): CFLAGS+=-mabi=64 + +run-octeon-insns: QEMU_OPTS+=-cpu Octeon68XX
tests/tcg/mips64el/Makefile.target new file +8 -0
@@ -0,0 +1,8 @@ +# -*- Mode: makefile -*- +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# MIPS64 little-endian - included from tests/tcg/Makefile.target +# + +include $(SRC_PATH)/tests/tcg/mips64/Makefile.target
Signature · 1 line
2.54.0
PATCH v3 25/32 target/mips: add Octeon LA* atomic instructions
In reply to James HilliardImplement the Octeon LA* read-modify-write atomic instruction family:
LAI/LAID, LAD/LADD, LAA/LAAD, LAS/LASD, LAC/LACD, and LAW/LAWD.
These operations are architecturally distinct from SAA/SAAD and are used by existing Octeon user-mode code for atomic counters, bit operations, and exchange-style updates.
---
Changes v1 -> v2:
- Keep LA* atomics naturally aligned per Octeon L2 transaction semantics.
- Use explicit i64 TCG ops in the LA* translator paths. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Drop redundant TARGET_LONG_BITS guards from doubleword atomic paths. (suggested by Richard Henderson)
- Group LA* translator wrappers by argument shape instead of adding one wrapper per instruction. (suggested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 17 ++++++ target/mips/tcg/octeon_translate.c | 118 +++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+)
target/mips/tcg/octeon.decode +17 -0
@@ -59,6 +59,23 @@ V3MULU 011100 ..... ..... ..... 00000 010001 @r3 SAA 011100 ..... ..... 00000 00000 011000 @saa SAAD 011100 ..... ..... 00000 00000 011001 @saa +&la base rd +&laa base add rd +@la ...... base:5 ..... rd:5 ........... &la +@laa ...... base:5 add:5 rd:5 ........... &laa +LAI 011100 ..... 00000 ..... 00010 011111 @la +LAID 011100 ..... 00000 ..... 00011 011111 @la +LAD 011100 ..... 00000 ..... 00110 011111 @la +LADD 011100 ..... 00000 ..... 00111 011111 @la +LAA 011100 ..... ..... ..... 10010 011111 @laa +LAAD 011100 ..... ..... ..... 10011 011111 @laa +LAS 011100 ..... 00000 ..... 01010 011111 @la +LASD 011100 ..... 00000 ..... 01011 011111 @la +LAC 011100 ..... 00000 ..... 01110 011111 @la +LACD 011100 ..... 00000 ..... 01111 011111 @la +LAW 011100 ..... ..... ..... 10110 011111 @laa +LAWD 011100 ..... ..... ..... 10111 011111 @laa + &zcb base ZCB 011100 base:5 00000 00000 11100 011111 &zcb ZCBT 011100 base:5 00000 00000 11101 011111 &zcb
target/mips/tcg/octeon_translate.c +118 -0
130 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v3 25/32] target/mips: add Octeon LA* atomic instructions
Quoted 90 lines · James Hilliard
Implement the Octeon LA* read-modify-write atomic instruction family:
LAI/LAID, LAD/LADD, LAA/LAAD, LAS/LASD, LAC/LACD, and LAW/LAWD.These operations are architecturally distinct from SAA/SAAD and are used by existing Octeon user-mode code for atomic counters, bit operations, and exchange-style updates.
Signed-off-by James Hilliard <[email protected]>---
Changes v1 -> v2:
- Keep LA* atomics naturally aligned per Octeon L2 transaction semantics.
- Use explicit i64 TCG ops in the LA* translator paths. (suggested by Philippe Mathieu-Daudé)Changes v2 -> v3:
- Drop redundantTARGET_LONG_BITSguards from doubleword atomic paths. (suggested by Richard Henderson)
- Group LA* translator wrappers by argument shape instead of adding one wrapper per instruction. (suggested by Richard Henderson)--- target/mips/tcg/octeon.decode | 17 ++++++ target/mips/tcg/octeon_translate.c | 118 +++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+)target/mips/tcg/octeon.decode +17
-0@@ -59,6 +59,23 @@ V3MULU 011100 ..... ..... ..... 00000 010001 @r3 SAA 011100 ..... ..... 00000 00000 011000 @saa SAAD 011100 ..... ..... 00000 00000 011001 @saa +&la base rd +&laa base add rd +@la ...... base:5 ..... rd:5 ........... &la +@laa ...... base:5 add:5 rd:5 ........... &laa +LAI 011100 ..... 00000 ..... 00010 011111 @la +LAID 011100 ..... 00000 ..... 00011 011111 @la +LAD 011100 ..... 00000 ..... 00110 011111 @la +LADD 011100 ..... 00000 ..... 00111 011111 @la +LAA 011100 ..... ..... ..... 10010 011111 @laa +LAAD 011100 ..... ..... ..... 10011 011111 @laa +LAS 011100 ..... 00000 ..... 01010 011111 @la +LASD 011100 ..... 00000 ..... 01011 011111 @la +LAC 011100 ..... 00000 ..... 01110 011111 @la +LACD 011100 ..... 00000 ..... 01111 011111 @la +LAW 011100 ..... ..... ..... 10110 011111 @laa +LAWD 011100 ..... ..... ..... 10111 011111 @laa + &zcb base ZCB 011100 base:5 00000 00000 11100 011111 &zcb ZCBT 011100 base:5 00000 00000 11101 011111 &zcbtarget/mips/tcg/octeon_translate.c +29
-0@@ -189,6 +189,112 @@ static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop)return true; } +static bool trans_la_common (DisasContext *ctx,int base,int add_reg,int rd, +int64_t imm,bool dw) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); + +gen_base_offset_addr (ctx, addr, base,0 ); + +if (dw) { +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i64 old =tcg_temp_new_i64 (); +MemOp amo =mo_endian (ctx) |MO_UQ |MO_ALIGN ; + +if (add_reg >=0 ) { +gen_load_gpr (value, add_reg); + }else { +tcg_gen_movi_i64 (value, imm); + } + +tcg_gen_atomic_fetch_add_i64 (old, addr, value, ctx->mem_idx, amo); +gen_store_gpr (old, rd); + }else { +TCGv_i64 old =tcg_temp_new_i64 (); +TCGv_i32 value32 =tcg_temp_new_i32 (); +TCGv_i32 old32 =tcg_temp_new_i32 (); +MemOp amo =mo_endian (ctx) |MO_UL |MO_ALIGN ; + +if (add_reg <0 ) { +tcg_gen_movi_i32 (value32, imm); + }else {
target/mips/tcg/octeon_translate.c static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop) · line 230
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+TCGv_i64 value =tcg_temp_new_i64 (); + +gen_load_gpr (value, add_reg); +tcg_gen_extrl_i64_i32 (value32, value); + } + +tcg_gen_atomic_fetch_add_i32 (old32, addr, value32, ctx->mem_idx, amo); +tcg_gen_ext_i32_i64 (old, old32); +gen_store_gpr (old, rd); + }
Always use tcg_gen_atomic_fetch_add_i64.
The correct memop for 32-bit is MO_SL, so that you automatically get the sign-extension for the 32-bit operation.
Which means that it'd be cleaner to replace the 'bool dw' parameter with 'MemOp mop'.
Quoted 29 lines
target/mips/tcg/octeon_translate.c +29
-0+static bool trans_law_common (DisasContext *ctx,int base,int add_reg,int rd, +int64_t imm,bool dw) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); + +gen_base_offset_addr (ctx, addr, base,0 ); + +if (dw) { +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i64 old =tcg_temp_new_i64 (); +MemOp amo =mo_endian (ctx) |MO_UQ |MO_ALIGN ; + +if (add_reg >=0 ) { +gen_load_gpr (value, add_reg); + }else { +tcg_gen_movi_i64 (value, imm); + } + +tcg_gen_atomic_xchg_i64 (old, addr, value, ctx->mem_idx, amo); +gen_store_gpr (old, rd); + }else { +TCGv_i64 old =tcg_temp_new_i64 (); +TCGv_i32 value32 =tcg_temp_new_i32 (); +TCGv_i32 old32 =tcg_temp_new_i32 (); +MemOp amo =mo_endian (ctx) |MO_UL |MO_ALIGN ; + +if (add_reg >=0 ) { +TCGv_i64 value =tcg_temp_new_i64 (); +
target/mips/tcg/octeon_translate.c static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop) · line 273
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+gen_load_gpr (value, add_reg); +tcg_gen_extrl_i64_i32 (value32, value); + }else { +tcg_gen_movi_i32 (value32, imm); + } + +tcg_gen_atomic_xchg_i32 (old32, addr, value32, ctx->mem_idx, amo); +tcg_gen_ext_i32_i64 (old, old32); +gen_store_gpr (old, rd); + }
Similarly.
r~
PATCH v3 26/32 target/mips: add Octeon COP2 crypto core support
In reply to James HilliardOcteon processors expose their crypto engines through selector-driven DMFC2/DMTC2 accesses rather than architected standalone opcodes. Add the common COP2 state, selector decode, and helper plumbing for the base engine set.
This covers the hash, AES, CRC, GFM, 3DES, KASUMI, and SNOW3G engines and moves the implementation into octeon_crypto.c to keep the MIPS helper layer manageable.
Model the AES result/input selector bank as writable as well as readable. Octeon COP2 engines use these slots as result-input staging registers, so the shared bank belongs with the base selector support.
Extend the TCG smoke test with AES key-register readback checks for the selector window introduced here.
---
Changes v1 -> v2:
- Fold the AES COP2 selector readback smoke coverage into this patch.
- Move Octeon COP2 decode plumbing into octeon_translate.c. (suggested by Philippe Mathieu-Daudé)
- Use uint64_t/i64 helper types for Octeon COP2 state transfers. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Remove redundant MIPS64 checks from Octeon COP2 translation; the opcode path is already restricted to TARGET_MIPS64 Octeon CPUs. (suggested by Richard Henderson)
--- target/mips/cpu.h | 165 +++ target/mips/helper.h | 2 + target/mips/system/machine.c | 37 + target/mips/tcg/meson.build | 1 + target/mips/tcg/octeon_crypto.c | 1654 +++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 204 +++ target/mips/tcg/translate.c | 9 + target/mips/tcg/translate.h | 1 + tests/tcg/mips/user/isa/octeon/octeon-insns.c | 71 ++ 9 files changed, 2144 insertions(+)
target/mips/cpu.h +165 -0
@@ -529,6 +529,169 @@ struct TCState { };struct MIPSITUState ; +typedef enum MIPSOcteonSharedMode { +OCTEON_SHARED_MODE_NONE =0 , +OCTEON_SHARED_MODE_SHA512 , +OCTEON_SHARED_MODE_SNOW3G , +}MIPSOcteonSharedMode ; + +typedef enum MIPSOcteonCop2Sel { +OCTEON_COP2_SEL_HSH_DAT0 =0x0040 , +OCTEON_COP2_SEL_HSH_DAT1 , +OCTEON_COP2_SEL_HSH_DAT2 , +OCTEON_COP2_SEL_HSH_DAT3 , +OCTEON_COP2_SEL_HSH_DAT4 , +OCTEON_COP2_SEL_HSH_DAT5 , +OCTEON_COP2_SEL_HSH_DAT6 , +OCTEON_COP2_SEL_HSH_IV0 =0x0048 , +OCTEON_COP2_SEL_HSH_IV1 , +OCTEON_COP2_SEL_HSH_IV2 , +OCTEON_COP2_SEL_HSH_IV3 , +OCTEON_COP2_SEL_SHA3_DAT24 =0x0050 , +OCTEON_COP2_SEL_SHA3_DAT15_WRITE =0x0051 , +OCTEON_COP2_SEL_HSH_STARTSHA1_COMPAT =0x0057 , +OCTEON_COP2_SEL_GFM_MUL_REFLECT0 =0x0058 , +OCTEON_COP2_SEL_GFM_MUL_REFLECT1 , +OCTEON_COP2_SEL_GFM_RESINP_REFLECT0 =0x005a , +OCTEON_COP2_SEL_GFM_RESINP_REFLECT1 , +OCTEON_COP2_SEL_GFM_XOR0_REFLECT =0x005c , +OCTEON_COP2_SEL_3DES_KEY0 =0x0080 , +OCTEON_COP2_SEL_3DES_KEY1 , +OCTEON_COP2_SEL_3DES_KEY2 , +OCTEON_COP2_SEL_3DES_IV =0x0084 , +OCTEON_COP2_SEL_3DES_RESULT =0x0088 , +OCTEON_COP2_SEL_3DES_RESULT_IN =0x0098 , +OCTEON_COP2_SEL_3DES_ENC_CBC =0x4088 , +/* +* Octeon reuses the 3DES key/result bank for KASUMI and only adds +* KASUMI-specific operation selectors. +*/ +OCTEON_COP2_SEL_KAS_ENC_CBC =0x4089 , +OCTEON_COP2_SEL_3DES_ENC =0x408a , +OCTEON_COP2_SEL_KAS_ENC =0x408b , +OCTEON_COP2_SEL_3DES_DEC_CBC =0x408c , +OCTEON_COP2_SEL_3DES_DEC =0x408e , +OCTEON_COP2_SEL_AES_RESULT0 =0x0100 , +OCTEON_COP2_SEL_AES_RESULT1 , +OCTEON_COP2_SEL_AES_IV0 , +OCTEON_COP2_SEL_AES_IV1 , +OCTEON_COP2_SEL_AES_KEY0 , +OCTEON_COP2_SEL_AES_KEY1 , +OCTEON_COP2_SEL_AES_KEY2 , +OCTEON_COP2_SEL_AES_KEY3 , +OCTEON_COP2_SEL_AES_ENC_CBC0 =0x0108 , +OCTEON_COP2_SEL_AES_ENC0 =0x010a , +OCTEON_COP2_SEL_AES_DEC_CBC0 =0x010c , +OCTEON_COP2_SEL_AES_DEC0 =0x010e , +OCTEON_COP2_SEL_AES_KEYLENGTH =0x0110 , +OCTEON_COP2_SEL_AES_DAT0 =0x0111 , +OCTEON_COP2_SEL_CRC_POLYNOMIAL =0x0200 , +OCTEON_COP2_SEL_CRC_IV =0x0201 , +OCTEON_COP2_SEL_CRC_LEN =0x0202 , +OCTEON_COP2_SEL_CRC_IV_REFLECT =0x0203 , +OCTEON_COP2_SEL_CRC_WRITE_BYTE =0x0204 , +OCTEON_COP2_SEL_CRC_WRITE_HALF =0x0205 , +OCTEON_COP2_SEL_CRC_WRITE_WORD =0x0206 , +OCTEON_COP2_SEL_CRC_WRITE_POLYNOMIAL =0x4200 , +OCTEON_COP2_SEL_CRC_WRITE_LEN =0x1202 , +OCTEON_COP2_SEL_CRC_WRITE_IV_REFLECT =0x0211 , +OCTEON_COP2_SEL_CRC_WRITE_BYTE_REFLECT =0x0214 , +OCTEON_COP2_SEL_CRC_WRITE_HALF_REFLECT =0x0215 , +OCTEON_COP2_SEL_CRC_WRITE_WORD_REFLECT =0x0216 , +OCTEON_COP2_SEL_CRC_WRITE_DWORD =0x1207 , +OCTEON_COP2_SEL_CRC_WRITE_VAR =0x1208 , +OCTEON_COP2_SEL_CRC_WRITE_POLYNOMIAL_REFLECT =0x4210 , +OCTEON_COP2_SEL_CRC_WRITE_DWORD_REFLECT =0x1217 , +OCTEON_COP2_SEL_CRC_WRITE_VAR_REFLECT =0x1218 , +/* +* Octeon shares 0x0240..0x0257 between SHA512 state/data and the SNOW3G +* RESULT/FSM/LFSR window. +*/ +OCTEON_COP2_SEL_HSH_DATW0 =0x0240 , +OCTEON_COP2_SEL_HSH_DATW1 , +OCTEON_COP2_SEL_HSH_DATW2 , +OCTEON_COP2_SEL_HSH_DATW3 , +OCTEON_COP2_SEL_HSH_DATW4 , +OCTEON_COP2_SEL_HSH_DATW5 , +OCTEON_COP2_SEL_HSH_DATW6 , +OCTEON_COP2_SEL_HSH_DATW7 , +OCTEON_COP2_SEL_HSH_DATW8 , +OCTEON_COP2_SEL_HSH_DATW9 , +OCTEON_COP2_SEL_HSH_DATW10 , +OCTEON_COP2_SEL_HSH_DATW11 , +OCTEON_COP2_SEL_HSH_DATW12 , +OCTEON_COP2_SEL_HSH_DATW13 , +OCTEON_COP2_SEL_HSH_DATW14 , +OCTEON_COP2_SEL_HSH_DATW15 , +OCTEON_COP2_SEL_HSH_IVW0 =0x0250 , +OCTEON_COP2_SEL_HSH_IVW1 , +OCTEON_COP2_SEL_HSH_IVW2 , +OCTEON_COP2_SEL_HSH_IVW3 , +OCTEON_COP2_SEL_HSH_IVW4 , +OCTEON_COP2_SEL_HSH_IVW5 , +OCTEON_COP2_SEL_HSH_IVW6 , +OCTEON_COP2_SEL_HSH_IVW7 , +OCTEON_COP2_SEL_SNOW3G_LFSR0 =0x0240 , +OCTEON_COP2_SEL_SNOW3G_LFSR1 , +OCTEON_COP2_SEL_SNOW3G_LFSR2 , +OCTEON_COP2_SEL_SNOW3G_LFSR3 , +OCTEON_COP2_SEL_SNOW3G_LFSR4 , +OCTEON_COP2_SEL_SNOW3G_LFSR5 , +OCTEON_COP2_SEL_SNOW3G_LFSR6 , +OCTEON_COP2_SEL_SNOW3G_LFSR7 , +OCTEON_COP2_SEL_SNOW3G_RESULT =0x0250 , +OCTEON_COP2_SEL_SNOW3G_FSM0 , +OCTEON_COP2_SEL_SNOW3G_FSM1 , +OCTEON_COP2_SEL_SNOW3G_FSM2 , +OCTEON_COP2_SEL_GFM_MUL0 =0x0258 , +OCTEON_COP2_SEL_GFM_MUL1 , +OCTEON_COP2_SEL_GFM_RESINP0 , +OCTEON_COP2_SEL_GFM_RESINP1 , +OCTEON_COP2_SEL_GFM_XOR0 , +OCTEON_COP2_SEL_GFM_POLY =0x025e , +OCTEON_COP2_SEL_AES_ENC_CBC1 =0x3109 , +OCTEON_COP2_SEL_AES_ENC1 =0x310b , +OCTEON_COP2_SEL_AES_DEC_CBC1 =0x310d , +OCTEON_COP2_SEL_AES_DEC1 =0x310f , +OCTEON_COP2_SEL_HSH_STARTMD5 =0x4047 , +OCTEON_COP2_SEL_SNOW3G_START =0x404d , +OCTEON_COP2_SEL_SNOW3G_MORE =0x404e , +OCTEON_COP2_SEL_HSH_STARTSHA256 =0x404f , +OCTEON_COP2_SEL_GFM_XORMUL1_REFLECT =0x405d , +OCTEON_COP2_SEL_HSH_STARTSHA1 =0x4057 , +OCTEON_COP2_SEL_HSH_STARTSHA512 =0x424f , +OCTEON_COP2_SEL_GFM_XORMUL1 =0x425d , +}MIPSOcteonCop2Sel ; + +typedef struct MIPSOcteonCryptoState { +uint64_t des3_key[3 ]; +uint64_t des3_iv; +uint64_t des3_result; +uint64_t hash_state[4 ]; +uint64_t hash_block[8 ]; +uint64_t sha512_state[8 ]; +uint64_t sha512_block[16 ]; +uint64_t aes_iv[2 ]; +uint64_t aes_key[4 ]; +uint64_t aes_result[2 ]; +uint64_t aes_input[2 ]; +uint64_t gfm_mul[2 ]; +uint64_t gfm_result[2 ]; +uint64_t gfm_xor0; +uint64_t gfm_reflect_mul[2 ]; +uint64_t gfm_reflect_result[2 ]; +uint64_t gfm_reflect_xor0; +uint16_t gfm_poly; +uint8_t aes_keylen; +uint32_t shared_mode; +uint32_t crc_poly; +uint32_t crc_iv; +uint32_t crc_len; +uint32_t snow3g_fsm[3 ]; +uint32_t snow3g_lfsr[16 ]; +uint64_t snow3g_result; +}MIPSOcteonCryptoState ; + typedef struct CPUArchState { TCState active_tc; CPUMIPSFPUContext active_fpu;
@@ -550,6 +713,8 @@ typedef struct CPUArchState {#define MSAIR_ProcID 8#define MSAIR_Rev 0 +MIPSOcteonCryptoState octeon_crypto; +/* * CP0 Register 0 */
target/mips/helper.h +2 -0
@@ -27,6 +27,8 @@ DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32) DEF_HELPER_3(octeon_vmulu, i64, env, i64, i64) DEF_HELPER_3(octeon_vmm0, i64, env, i64, i64) DEF_HELPER_3(octeon_v3mulu, i64, env, i64, i64) +DEF_HELPER_2(octeon_cop2_dmfc2, i64, env, i32) +DEF_HELPER_3 (octeon_cop2_dmtc2, void, env, i64, i32) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/system/machine.c +37 -0
@@ -279,6 +279,42 @@ static const VMStateDescription mips_vmstate_octeon_multiplier = { } }; +static const VMStateDescription mips_vmstate_octeon_crypto = { + .name ="cpu/octeon_crypto" , + .version_id =1 , + .minimum_version_id =1 , + .needed = mips_octeon_needed, + .fields = (const VMStateField []) { +VMSTATE_UINT64_ARRAY (env.octeon_crypto.des3_key,MIPSCPU ,3 ), +VMSTATE_UINT64 (env.octeon_crypto.des3_iv,MIPSCPU ), +VMSTATE_UINT64 (env.octeon_crypto.des3_result,MIPSCPU ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.hash_state,MIPSCPU ,4 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.hash_block,MIPSCPU ,8 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.sha512_state,MIPSCPU ,8 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.sha512_block,MIPSCPU ,16 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_iv,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_key,MIPSCPU ,4 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_result,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_input,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_mul,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_result,MIPSCPU ,2 ), +VMSTATE_UINT64 (env.octeon_crypto.gfm_xor0,MIPSCPU ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_reflect_mul,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_reflect_result,MIPSCPU ,2 ), +VMSTATE_UINT64 (env.octeon_crypto.gfm_reflect_xor0,MIPSCPU ), +VMSTATE_UINT16 (env.octeon_crypto.gfm_poly,MIPSCPU ), +VMSTATE_UINT8 (env.octeon_crypto.aes_keylen,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.shared_mode,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.crc_poly,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.crc_iv,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.crc_len,MIPSCPU ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_fsm,MIPSCPU ,3 ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_lfsr,MIPSCPU ,16 ), +VMSTATE_UINT64 (env.octeon_crypto.snow3g_result,MIPSCPU ), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_mips_cpu = { .name ="cpu" , .version_id =21 ,
@@ -396,6 +432,7 @@ const VMStateDescription vmstate_mips_cpu = { .subsections = (const VMStateDescription * const []) { &mips_vmstate_timer, &mips_vmstate_octeon_multiplier, + &mips_vmstate_octeon_crypto,NULL } };
target/mips/tcg/meson.build +1 -0
@@ -18,6 +18,7 @@ mips_ss.add(files( 'lmmi_helper.c', 'msa_helper.c', 'msa_translate.c', + 'octeon_crypto.c', 'op_helper.c', 'rel6_translate.c', 'translate.c',
target/mips/tcg/octeon_crypto.c new file +1654 -0
1,654 lines not on this page · raw message
target/mips/tcg/octeon_translate.c +204 -0
210 lines not on this page · raw message
target/mips/tcg/translate.c +9 -0
@@ -14863,6 +14863,15 @@ static bool decode_opc_legacy(CPUMIPSState *env, DisasContext *ctx) }break ;case OPC_CP2 : +#if defined(TARGET_MIPS64 ) +if (ctx->insn_flags &INSN_OCTEON ) { +if (gen_octeon_cop2 (ctx)) { +break ; + } +generate_exception_err (ctx, EXCP_CpU,2 ); +break ; + } +#endif check_insn (ctx,ASE_LMMI );/* Note that these instructions use different fields. */ gen_loongson_multimedia (ctx, sa, rd, rt);
target/mips/tcg/translate.h +1 -0
@@ -232,6 +232,7 @@ bool decode_ext_loongson(DisasContext *ctx, uint32_t insn);bool decode_ase_lcsr (DisasContext *ctx,uint32_t insn);bool decode_ext_tx79 (DisasContext *ctx,uint32_t insn);bool decode_ext_octeon (DisasContext *ctx,uint32_t insn); +bool gen_octeon_cop2 (DisasContext *ctx);#endif bool decode_ext_vr54xx (DisasContext *ctx,uint32_t insn);
tests/tcg/mips/user/isa/octeon/octeon-insns.c +71 -0
83 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v3 27/32 target/mips: add Octeon SMS4 crypto support
In reply to James HilliardOn Octeon, the SMS4 engine is exposed through selectors that alias the AES register bank. Add the missing selectors and model the shared RESULT, IV, and key state so the hardware interface matches the processor behaviour.
Use the in-tree SM4 tables to implement the block operation without adding a host crypto dependency.
---
Changes v1 -> v2:
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
--- target/mips/cpu.h | 18 ++++++ target/mips/tcg/octeon_crypto.c | 109 +++++++++++++++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 4 ++ 3 files changed, 131 insertions(+)
target/mips/cpu.h +18 -0
@@ -585,6 +585,20 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_AES_DEC0 =0x010e ,OCTEON_COP2_SEL_AES_KEYLENGTH =0x0110 ,OCTEON_COP2_SEL_AES_DAT0 =0x0111 , +/* +* SMS4 reuses the AES result/input, IV, and key banks and only adds +* operation selectors for ECB/CBC encrypt/decrypt. +*/ +OCTEON_COP2_SEL_SMS4_RESINP0 =OCTEON_COP2_SEL_AES_RESULT0 , +OCTEON_COP2_SEL_SMS4_RESINP1 =OCTEON_COP2_SEL_AES_RESULT1 , +OCTEON_COP2_SEL_SMS4_IV0 =OCTEON_COP2_SEL_AES_IV0 , +OCTEON_COP2_SEL_SMS4_IV1 =OCTEON_COP2_SEL_AES_IV1 , +OCTEON_COP2_SEL_SMS4_KEY0 =OCTEON_COP2_SEL_AES_KEY0 , +OCTEON_COP2_SEL_SMS4_KEY1 =OCTEON_COP2_SEL_AES_KEY1 , +OCTEON_COP2_SEL_SMS4_ENC_CBC0 =OCTEON_COP2_SEL_AES_ENC_CBC0 , +OCTEON_COP2_SEL_SMS4_ENC0 =OCTEON_COP2_SEL_AES_ENC0 , +OCTEON_COP2_SEL_SMS4_DEC_CBC0 =OCTEON_COP2_SEL_AES_DEC_CBC0 , +OCTEON_COP2_SEL_SMS4_DEC0 =OCTEON_COP2_SEL_AES_DEC0 ,OCTEON_COP2_SEL_CRC_POLYNOMIAL =0x0200 ,OCTEON_COP2_SEL_CRC_IV =0x0201 , OCTEON_COP2_SEL_CRC_LEN = 0x0202,
@@ -653,6 +667,10 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_AES_ENC1 =0x310b ,OCTEON_COP2_SEL_AES_DEC_CBC1 =0x310d ,OCTEON_COP2_SEL_AES_DEC1 =0x310f , +OCTEON_COP2_SEL_SMS4_ENC_CBC1 =0x3119 , +OCTEON_COP2_SEL_SMS4_ENC1 =0x311b , +OCTEON_COP2_SEL_SMS4_DEC_CBC1 =0x311d , +OCTEON_COP2_SEL_SMS4_DEC1 =0x311f ,OCTEON_COP2_SEL_HSH_STARTMD5 =0x4047 ,OCTEON_COP2_SEL_SNOW3G_START =0x404d , OCTEON_COP2_SEL_SNOW3G_MORE = 0x404e,
target/mips/tcg/octeon_crypto.c +109 -0
133 lines not on this page · raw message
target/mips/tcg/octeon_translate.c +4 -0
@@ -180,6 +180,10 @@ static bool octeon_cop2_is_supported_dmtc2(uint16_t sel)case OCTEON_COP2_SEL_AES_ENC1 :case OCTEON_COP2_SEL_AES_DEC_CBC1 :case OCTEON_COP2_SEL_AES_DEC1 : +case OCTEON_COP2_SEL_SMS4_ENC_CBC1 : +case OCTEON_COP2_SEL_SMS4_ENC1 : +case OCTEON_COP2_SEL_SMS4_DEC_CBC1 : +case OCTEON_COP2_SEL_SMS4_DEC1 :return true;default :return false;
Signature · 1 line
2.54.0
PATCH v3 28/32 target/mips: add Octeon SHA3 crypto support
In reply to James HilliardAdd the Octeon SHA3 register window and STARTOP selector.
Keep the shared HSH/SHA3/SHA512 write path coherent, then model the dedicated 25-lane Keccak state and the Keccak-f[1600] permutation so the COP2 SHA3 interface follows the hardware behaviour.
---
Changes v1 -> v2:
- Use switch ranges and g_assert_not_reached() for SHA3 selector position decoding. (suggested by Philippe Mathieu-Daudé)
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
--- target/mips/cpu.h | 22 +++++ target/mips/system/machine.c | 1 + target/mips/tcg/octeon_crypto.c | 171 +++++++++++++++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 22 +++++ 4 files changed, 216 insertions(+)
target/mips/cpu.h +22 -0
@@ -533,6 +533,7 @@ typedef enum MIPSOcteonSharedMode {OCTEON_SHARED_MODE_NONE =0 ,OCTEON_SHARED_MODE_SHA512 ,OCTEON_SHARED_MODE_SNOW3G , +OCTEON_SHARED_MODE_SHA3 , } MIPSOcteonSharedMode; typedef enum MIPSOcteonCop2Sel {
@@ -637,6 +638,7 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_HSH_DATW13 ,OCTEON_COP2_SEL_HSH_DATW14 ,OCTEON_COP2_SEL_HSH_DATW15 , +OCTEON_COP2_SEL_SHA3_DAT15_READ =0x024f ,OCTEON_COP2_SEL_HSH_IVW0 =0x0250 ,OCTEON_COP2_SEL_HSH_IVW1 , OCTEON_COP2_SEL_HSH_IVW2,
@@ -663,6 +665,24 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_GFM_RESINP1 ,OCTEON_COP2_SEL_GFM_XOR0 ,OCTEON_COP2_SEL_GFM_POLY =0x025e , +OCTEON_COP2_SEL_SHA3_XORDAT0 =0x02c0 , +OCTEON_COP2_SEL_SHA3_XORDAT1 , +OCTEON_COP2_SEL_SHA3_XORDAT2 , +OCTEON_COP2_SEL_SHA3_XORDAT3 , +OCTEON_COP2_SEL_SHA3_XORDAT4 , +OCTEON_COP2_SEL_SHA3_XORDAT5 , +OCTEON_COP2_SEL_SHA3_XORDAT6 , +OCTEON_COP2_SEL_SHA3_XORDAT7 , +OCTEON_COP2_SEL_SHA3_XORDAT8 , +OCTEON_COP2_SEL_SHA3_XORDAT9 , +OCTEON_COP2_SEL_SHA3_XORDAT10 , +OCTEON_COP2_SEL_SHA3_XORDAT11 , +OCTEON_COP2_SEL_SHA3_XORDAT12 , +OCTEON_COP2_SEL_SHA3_XORDAT13 , +OCTEON_COP2_SEL_SHA3_XORDAT14 , +OCTEON_COP2_SEL_SHA3_XORDAT15 , +OCTEON_COP2_SEL_SHA3_XORDAT16 , +OCTEON_COP2_SEL_SHA3_XORDAT17 ,OCTEON_COP2_SEL_AES_ENC_CBC1 =0x3109 ,OCTEON_COP2_SEL_AES_ENC1 =0x310b , OCTEON_COP2_SEL_AES_DEC_CBC1 = 0x310d,
@@ -675,6 +695,7 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_SNOW3G_START =0x404d ,OCTEON_COP2_SEL_SNOW3G_MORE =0x404e ,OCTEON_COP2_SEL_HSH_STARTSHA256 =0x404f , +OCTEON_COP2_SEL_SHA3_STARTOP =0x4052 ,OCTEON_COP2_SEL_GFM_XORMUL1_REFLECT =0x405d ,OCTEON_COP2_SEL_HSH_STARTSHA1 =0x4057 , OCTEON_COP2_SEL_HSH_STARTSHA512 = 0x424f,
@@ -689,6 +710,7 @@ typedef struct MIPSOcteonCryptoState {uint64_t hash_block[8 ];uint64_t sha512_state[8 ];uint64_t sha512_block[16 ]; +uint64_t sha3_state[25 ];uint64_t aes_iv[2 ];uint64_t aes_key[4 ];uint64_t aes_result[2 ];
target/mips/system/machine.c +1 -0
@@ -292,6 +292,7 @@ static const VMStateDescription mips_vmstate_octeon_crypto = {VMSTATE_UINT64_ARRAY (env.octeon_crypto.hash_block,MIPSCPU ,8 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.sha512_state,MIPSCPU ,8 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.sha512_block,MIPSCPU ,16 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.sha3_state,MIPSCPU ,25 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_iv,MIPSCPU ,2 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_key,MIPSCPU ,4 ), VMSTATE_UINT64_ARRAY(env.octeon_crypto.aes_result, MIPSCPU, 2),
target/mips/tcg/octeon_crypto.c +171 -0
222 lines not on this page · raw message
target/mips/tcg/octeon_translate.c +22 -0
@@ -66,6 +66,7 @@ static bool octeon_cop2_is_supported_dmfc2(uint16_t sel)case OCTEON_COP2_SEL_HSH_IVW6 :case OCTEON_COP2_SEL_HSH_IVW7 :case OCTEON_COP2_SEL_AES_DAT0 : +case OCTEON_COP2_SEL_SHA3_DAT24 :case OCTEON_COP2_SEL_GFM_MUL_REFLECT0 :case OCTEON_COP2_SEL_GFM_MUL_REFLECT1 :case OCTEON_COP2_SEL_GFM_RESINP_REFLECT0 :
@@ -150,6 +151,8 @@ static bool octeon_cop2_is_supported_dmtc2(uint16_t sel)case OCTEON_COP2_SEL_HSH_DATW13 :case OCTEON_COP2_SEL_HSH_DATW14 :case OCTEON_COP2_SEL_HSH_DATW15 : +case OCTEON_COP2_SEL_SHA3_DAT24 : +case OCTEON_COP2_SEL_SHA3_DAT15_WRITE :case OCTEON_COP2_SEL_HSH_IVW0 :case OCTEON_COP2_SEL_HSH_IVW1 :case OCTEON_COP2_SEL_HSH_IVW2 :
@@ -167,11 +170,30 @@ static bool octeon_cop2_is_supported_dmtc2(uint16_t sel)case OCTEON_COP2_SEL_GFM_RESINP1 :case OCTEON_COP2_SEL_GFM_XOR0 :case OCTEON_COP2_SEL_GFM_POLY : +case OCTEON_COP2_SEL_SHA3_XORDAT0 : +case OCTEON_COP2_SEL_SHA3_XORDAT1 : +case OCTEON_COP2_SEL_SHA3_XORDAT2 : +case OCTEON_COP2_SEL_SHA3_XORDAT3 : +case OCTEON_COP2_SEL_SHA3_XORDAT4 : +case OCTEON_COP2_SEL_SHA3_XORDAT5 : +case OCTEON_COP2_SEL_SHA3_XORDAT6 : +case OCTEON_COP2_SEL_SHA3_XORDAT7 : +case OCTEON_COP2_SEL_SHA3_XORDAT8 : +case OCTEON_COP2_SEL_SHA3_XORDAT9 : +case OCTEON_COP2_SEL_SHA3_XORDAT10 : +case OCTEON_COP2_SEL_SHA3_XORDAT11 : +case OCTEON_COP2_SEL_SHA3_XORDAT12 : +case OCTEON_COP2_SEL_SHA3_XORDAT13 : +case OCTEON_COP2_SEL_SHA3_XORDAT14 : +case OCTEON_COP2_SEL_SHA3_XORDAT15 : +case OCTEON_COP2_SEL_SHA3_XORDAT16 : +case OCTEON_COP2_SEL_SHA3_XORDAT17 :case OCTEON_COP2_SEL_HSH_STARTSHA1_COMPAT :case OCTEON_COP2_SEL_HSH_STARTMD5 :case OCTEON_COP2_SEL_SNOW3G_START :case OCTEON_COP2_SEL_SNOW3G_MORE :case OCTEON_COP2_SEL_HSH_STARTSHA256 : +case OCTEON_COP2_SEL_SHA3_STARTOP :case OCTEON_COP2_SEL_HSH_STARTSHA1 :case OCTEON_COP2_SEL_GFM_XORMUL1_REFLECT :case OCTEON_COP2_SEL_HSH_STARTSHA512 :
Signature · 1 line
2.54.0
PATCH v3 29/32 target/mips: add Octeon ZUC crypto support
In reply to James HilliardAdd the Octeon ZUC START and MORE selectors and model the shared state window used by the hardware interface.
This covers the keystream and MAC engine state, including the save-and-restore view that overlaps the HSH/SHA3 bank. Shared-window writes also update the SHA512/SHA3 backing state so guests can switch between engines without stale register contents.
---
Changes v1 -> v2:
- Add shared-window selector predicates and assert on unreachable ZUC selector switches. (suggested by Philippe Mathieu-Daudé)
- Preserve aliased HSH/SHA3/SHA512 backing state during ZUC shared-window writes.
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
--- target/mips/cpu.h | 7 + target/mips/system/machine.c | 4 + target/mips/tcg/octeon_crypto.c | 353 +++++++++++++++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 2 + 4 files changed, 366 insertions(+)
target/mips/cpu.h +7 -0
@@ -533,6 +533,7 @@ typedef enum MIPSOcteonSharedMode {OCTEON_SHARED_MODE_NONE =0 ,OCTEON_SHARED_MODE_SHA512 ,OCTEON_SHARED_MODE_SNOW3G , +OCTEON_SHARED_MODE_ZUC ,OCTEON_SHARED_MODE_SHA3 , } MIPSOcteonSharedMode;
@@ -696,6 +697,8 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_SNOW3G_MORE =0x404e ,OCTEON_COP2_SEL_HSH_STARTSHA256 =0x404f ,OCTEON_COP2_SEL_SHA3_STARTOP =0x4052 , +OCTEON_COP2_SEL_ZUC_START =0x4055 , +OCTEON_COP2_SEL_ZUC_MORE =0x4056 ,OCTEON_COP2_SEL_GFM_XORMUL1_REFLECT =0x405d ,OCTEON_COP2_SEL_HSH_STARTSHA1 =0x4057 , OCTEON_COP2_SEL_HSH_STARTSHA512 = 0x424f,
@@ -730,6 +733,10 @@ typedef struct MIPSOcteonCryptoState {uint32_t snow3g_fsm[3 ];uint32_t snow3g_lfsr[16 ];uint64_t snow3g_result; +uint32_t zuc_fsm[2 ]; +uint32_t zuc_lfsr[16 ]; +uint32_t zuc_window[3 ]; +uint32_t zuc_tresult; } MIPSOcteonCryptoState; typedef struct CPUArchState {
target/mips/system/machine.c +4 -0
@@ -312,6 +312,10 @@ static const VMStateDescription mips_vmstate_octeon_crypto = {VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_fsm,MIPSCPU ,3 ),VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_lfsr,MIPSCPU ,16 ),VMSTATE_UINT64 (env.octeon_crypto.snow3g_result,MIPSCPU ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.zuc_fsm,MIPSCPU ,2 ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.zuc_lfsr,MIPSCPU ,16 ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.zuc_window,MIPSCPU ,3 ), +VMSTATE_UINT32 (env.octeon_crypto.zuc_tresult,MIPSCPU ), VMSTATE_END_OF_LIST() } };
target/mips/tcg/octeon_crypto.c +353 -0
377 lines not on this page · raw message
target/mips/tcg/octeon_translate.c +2 -0
@@ -194,6 +194,8 @@ static bool octeon_cop2_is_supported_dmtc2(uint16_t sel)case OCTEON_COP2_SEL_SNOW3G_MORE :case OCTEON_COP2_SEL_HSH_STARTSHA256 :case OCTEON_COP2_SEL_SHA3_STARTOP : +case OCTEON_COP2_SEL_ZUC_START : +case OCTEON_COP2_SEL_ZUC_MORE :case OCTEON_COP2_SEL_HSH_STARTSHA1 :case OCTEON_COP2_SEL_GFM_XORMUL1_REFLECT :case OCTEON_COP2_SEL_HSH_STARTSHA512 :
Signature · 1 line
2.54.0
PATCH v3 30/32 target/mips: add Octeon Camellia crypto support
In reply to James HilliardAdd the Octeon Camellia ROUND, FL, and FLINV selectors and model the round engine that reuses the AES RESULT/RESINP bank.
Implement the Camellia F-function and FL layers directly from RFC 3713 so guest-managed key schedules can drive the engine through the hardware interface.
---
Changes v1 -> v2:
- Drop the Octeon prefix from generic Camellia helper routines. (suggested by Philippe Mathieu-Daudé)
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
--- target/mips/cpu.h | 9 +++ target/mips/tcg/octeon_crypto.c | 120 +++++++++++++++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 3 + 3 files changed, 132 insertions(+)
target/mips/cpu.h +9 -0
@@ -587,6 +587,14 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_AES_DEC0 =0x010e ,OCTEON_COP2_SEL_AES_KEYLENGTH =0x0110 ,OCTEON_COP2_SEL_AES_DAT0 =0x0111 , +/* +* Camellia reuses the AES RESULT/RESINP bank and adds per-round and +* diffusion-layer selectors for the guest-managed key schedule. +*/ +OCTEON_COP2_SEL_CAMELLIA_RESINP0 =OCTEON_COP2_SEL_AES_RESULT0 , +OCTEON_COP2_SEL_CAMELLIA_RESINP1 =OCTEON_COP2_SEL_AES_RESULT1 , +OCTEON_COP2_SEL_CAMELLIA_FL =0x0115 , +OCTEON_COP2_SEL_CAMELLIA_FLINV =0x0116 ,/* * SMS4 reuses the AES result/input, IV, and key banks and only adds * operation selectors for ECB/CBC encrypt/decrypt.
@@ -688,6 +696,7 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_AES_ENC1 =0x310b ,OCTEON_COP2_SEL_AES_DEC_CBC1 =0x310d ,OCTEON_COP2_SEL_AES_DEC1 =0x310f , +OCTEON_COP2_SEL_CAMELLIA_ROUND =0x3114 ,OCTEON_COP2_SEL_SMS4_ENC_CBC1 =0x3119 ,OCTEON_COP2_SEL_SMS4_ENC1 =0x311b , OCTEON_COP2_SEL_SMS4_DEC_CBC1 = 0x311d,
target/mips/tcg/octeon_crypto.c +120 -0
138 lines not on this page · raw message
target/mips/tcg/octeon_translate.c +3 -0
@@ -109,6 +109,8 @@ static bool octeon_cop2_is_supported_dmtc2(uint16_t sel)case OCTEON_COP2_SEL_AES_DEC_CBC0 :case OCTEON_COP2_SEL_AES_DEC0 :case OCTEON_COP2_SEL_AES_KEYLENGTH : +case OCTEON_COP2_SEL_CAMELLIA_FL : +case OCTEON_COP2_SEL_CAMELLIA_FLINV :case OCTEON_COP2_SEL_CRC_WRITE_POLYNOMIAL :case OCTEON_COP2_SEL_CRC_IV :case OCTEON_COP2_SEL_CRC_WRITE_LEN :
@@ -204,6 +206,7 @@ static bool octeon_cop2_is_supported_dmtc2(uint16_t sel)case OCTEON_COP2_SEL_AES_ENC1 :case OCTEON_COP2_SEL_AES_DEC_CBC1 :case OCTEON_COP2_SEL_AES_DEC1 : +case OCTEON_COP2_SEL_CAMELLIA_ROUND :case OCTEON_COP2_SEL_SMS4_ENC_CBC1 :case OCTEON_COP2_SEL_SMS4_ENC1 :case OCTEON_COP2_SEL_SMS4_DEC_CBC1 :
Signature · 1 line
2.54.0
PATCH v3 31/32 target/mips: add Octeon CHORD and LLM COP2 support
In reply to James HilliardAdd the Octeon CHORD hardware register access path and the LLM narrow/wide read and write windows.
Model both CHORD access forms, including the rdhwr $30 path and the legacy dmfc2 alias, and implement sparse backing storage for the two LLM sets so user-mode code can save, restore, and probe the architectural state.
---
Changes v1 -> v2:
- Use neutral selector-slot wording for the LLM/CHORD alias comment.
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
--- target/mips/cpu.c | 67 +++++++++++++++++++++++++++++++++++ target/mips/cpu.h | 20 +++++++++++ target/mips/helper.h | 1 + target/mips/internal.h | 3 ++ target/mips/system/machine.c | 67 +++++++++++++++++++++++++++++++++++ target/mips/tcg/octeon_crypto.c | 72 ++++++++++++++++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 13 +++++++ target/mips/tcg/op_helper.c | 6 ++++ target/mips/tcg/translate.c | 8 +++++ 9 files changed, 257 insertions(+)
target/mips/cpu.c +67 -0
@@ -27,6 +27,7 @@#include "internal.h" #include "kvm_mips.h" #include "qemu/module.h" +#include "qemu/qtree.h" #include "system/kvm.h" #include "system/qtest.h" #include "hw/core/qdev-properties.h"
@@ -183,6 +184,57 @@ static bool mips_cpu_has_work(CPUState *cs)#include "cpu-defs.c.inc" +static gint mips_octeon_u64_tree_compare (gconstpointer a,gconstpointer b, +gpointer user_data) +{ +uint64_t av = *(const uint64_t *)a; +uint64_t bv = *(const uint64_t *)b; + +return (av > bv) - (av < bv); +} + +QTree *mips_octeon_llm_tree_new (void ) +{ +return q_tree_new_full (mips_octeon_u64_tree_compare, +NULL , g_free, g_free); +} + +uint64_t mips_octeon_llm_load (QTree *tree,uint64_t addr) +{ +uint64_t key = addr; +uint64_t *value = tree ?q_tree_lookup (tree, &key) :NULL ; + +return value ? *value :0 ; +} + +void mips_octeon_llm_store (QTree **treep,uint64_t addr,uint64_t value) +{ +uint64_t *key; +uint64_t *stored; + +if (!*treep) { + *treep =mips_octeon_llm_tree_new (); + } + + key =g_new (uint64_t,1 ); + stored =g_new (uint64_t,1 ); + *key = addr; + *stored = value; +q_tree_replace (*treep, key, stored); +} + +static void mips_octeon_destroy_llm_state (MIPSOcteonCryptoState *crypto) +{ +if (crypto->llm_narrow) { +q_tree_destroy (crypto->llm_narrow); + crypto->llm_narrow =NULL ; + } +if (crypto->llm_wide) { +q_tree_destroy (crypto->llm_wide); + crypto->llm_wide =NULL ; + } +} +static void mips_cpu_reset_hold (Object *obj,ResetType type) {CPUState *cs =CPU (obj);
@@ -194,6 +246,7 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type) mcc->parent_phases.hold (obj, type); } +mips_octeon_destroy_llm_state (&env->octeon_crypto);memset (env,0 , offsetof(CPUMIPSState , end_reset_fields));/* Reset registers to their default values */
@@ -248,6 +301,9 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type) env->active_fpu.fcr31 = env->cpu_model->CP1_fcr31; env->msair = env->cpu_model->MSAIR; env->insn_flags = env->cpu_model->insn_flags; +if (env->insn_flags &INSN_OCTEON ) { + env->octeon_crypto.chord =1 ; + }#if defined(CONFIG_USER_ONLY ) env->CP0_Status = (MIPS_HFLAG_UM << CP0St_KSU);
@@ -264,6 +320,9 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)* hardware registers. */ env->CP0_HWREna |=0x0000000F ; +if (env->insn_flags &INSN_OCTEON ) { + env->CP0_HWREna |=0x40000000u ; + }if (env->CP0_Config1 & (1 <<CP0C1_FP )) { env->CP0_Status |= (1 << CP0St_CU1); }
@@ -422,6 +481,13 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)#endif } +static void mips_cpu_finalize (Object *obj) +{ +MIPSCPU *cpu =MIPS_CPU (obj); + +mips_octeon_destroy_llm_state (&cpu->env.octeon_crypto); +} +static void mips_cpu_disas_set_info (const CPUState *cs,disassemble_info *info) {const MIPSCPU *cpu =MIPS_CPU (cs);
@@ -648,6 +714,7 @@ static const TypeInfo mips_cpu_type_info = { .instance_size = sizeof(MIPSCPU), .instance_align = __alignof(MIPSCPU), .instance_init = mips_cpu_initfn, + .instance_finalize = mips_cpu_finalize, .abstract = true, .class_size = sizeof(MIPSCPUClass), .class_init = mips_cpu_class_init,
target/mips/cpu.h +20 -0
@@ -11,6 +11,7 @@#include "fpu/softfloat-types.h" #include "hw/core/clock.h" #include "mips-defs.h" +#include "qemu/qtree.h" typedef struct CPUMIPSTLBContext CPUMIPSTLBContext ;
@@ -609,6 +610,21 @@ typedef enum MIPSOcteonCop2Sel {OCTEON_COP2_SEL_SMS4_ENC0 =OCTEON_COP2_SEL_AES_ENC0 ,OCTEON_COP2_SEL_SMS4_DEC_CBC0 =OCTEON_COP2_SEL_AES_DEC_CBC0 ,OCTEON_COP2_SEL_SMS4_DEC0 =OCTEON_COP2_SEL_AES_DEC0 , +/* +* Selector 0x0400 is the narrow LLM read selector and is also used as a +* DMFC2 alias for the CHORD POW tag-switch completion bit. +*/ +OCTEON_COP2_SEL_LLM_READ_ADDR0 =0x0400 , +OCTEON_COP2_SEL_CHORD =OCTEON_COP2_SEL_LLM_READ_ADDR0 , +OCTEON_COP2_SEL_LLM_WRITE_ADDR_INTERNAL0 =0x0401 , +OCTEON_COP2_SEL_LLM_DATA0 =0x0402 , +OCTEON_COP2_SEL_LLM_READ64_ADDR0 =0x0404 , +OCTEON_COP2_SEL_LLM_WRITE64_ADDR_INTERNAL0 =0x0405 , +OCTEON_COP2_SEL_LLM_READ_ADDR1 =0x0408 , +OCTEON_COP2_SEL_LLM_WRITE_ADDR_INTERNAL1 =0x0409 , +OCTEON_COP2_SEL_LLM_DATA1 =0x040a , +OCTEON_COP2_SEL_LLM_READ64_ADDR1 =0x040c , +OCTEON_COP2_SEL_LLM_WRITE64_ADDR_INTERNAL1 =0x040d ,OCTEON_COP2_SEL_CRC_POLYNOMIAL =0x0200 ,OCTEON_COP2_SEL_CRC_IV =0x0201 , OCTEON_COP2_SEL_CRC_LEN = 0x0202,
@@ -746,6 +762,10 @@ typedef struct MIPSOcteonCryptoState {uint32_t zuc_lfsr[16 ];uint32_t zuc_window[3 ];uint32_t zuc_tresult; +uint64_t llm_data[2 ]; +uint64_t chord; +QTree *llm_narrow; +QTree *llm_wide; } MIPSOcteonCryptoState; typedef struct CPUArchState {
target/mips/helper.h +1 -0
@@ -200,6 +200,7 @@ DEF_HELPER_1(rdhwr_cc, tl, env) DEF_HELPER_1(rdhwr_ccres, tl, env) DEF_HELPER_1(rdhwr_performance, tl, env) DEF_HELPER_1(rdhwr_xnp, tl, env) +DEF_HELPER_1(rdhwr_chord, tl, env) DEF_HELPER_2(pmon, void, env, int)DEF_HELPER_1 (wait, void, env)
target/mips/internal.h +3 -0
@@ -93,6 +93,9 @@ extern const int mips_defs_number;int mips_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int mips_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); +QTree *mips_octeon_llm_tree_new (void ); +uint64_t mips_octeon_llm_load (QTree *tree,uint64_t addr); +void mips_octeon_llm_store (QTree **treep,uint64_t addr,uint64_t value);#define USEG_LIMIT ((target_ulong)(int32_t)0x7FFFFFFFUL)#define KSEG0_BASE ((target_ulong)(int32_t)0x80000000UL)
target/mips/system/machine.c +67 -0
79 lines not on this page · raw message
target/mips/tcg/octeon_crypto.c +72 -0
90 lines not on this page · raw message
target/mips/tcg/octeon_translate.c +13 -0
@@ -76,6 +76,9 @@ static bool octeon_cop2_is_supported_dmfc2(uint16_t sel)case OCTEON_COP2_SEL_GFM_RESINP0 :case OCTEON_COP2_SEL_GFM_RESINP1 :case OCTEON_COP2_SEL_GFM_POLY : +case OCTEON_COP2_SEL_CHORD : +case OCTEON_COP2_SEL_LLM_DATA0 : +case OCTEON_COP2_SEL_LLM_DATA1 :return true;default :return false;
@@ -111,6 +114,16 @@ static bool octeon_cop2_is_supported_dmtc2(uint16_t sel)case OCTEON_COP2_SEL_AES_KEYLENGTH :case OCTEON_COP2_SEL_CAMELLIA_FL :case OCTEON_COP2_SEL_CAMELLIA_FLINV : +case OCTEON_COP2_SEL_LLM_READ_ADDR0 : +case OCTEON_COP2_SEL_LLM_WRITE_ADDR_INTERNAL0 : +case OCTEON_COP2_SEL_LLM_DATA0 : +case OCTEON_COP2_SEL_LLM_READ64_ADDR0 : +case OCTEON_COP2_SEL_LLM_WRITE64_ADDR_INTERNAL0 : +case OCTEON_COP2_SEL_LLM_READ_ADDR1 : +case OCTEON_COP2_SEL_LLM_WRITE_ADDR_INTERNAL1 : +case OCTEON_COP2_SEL_LLM_DATA1 : +case OCTEON_COP2_SEL_LLM_READ64_ADDR1 : +case OCTEON_COP2_SEL_LLM_WRITE64_ADDR_INTERNAL1 :case OCTEON_COP2_SEL_CRC_WRITE_POLYNOMIAL :case OCTEON_COP2_SEL_CRC_IV :case OCTEON_COP2_SEL_CRC_WRITE_LEN :
target/mips/tcg/op_helper.c +6 -0
@@ -349,6 +349,12 @@ target_ulong helper_rdhwr_xnp(CPUMIPSState *env)return (env->CP0_Config5 >>CP0C5_XNP ) &1 ; } +target_ulong helper_rdhwr_chord (CPUMIPSState *env) +{ +check_hwrena (env,30 ,GETPC ()); +return env->octeon_crypto.chord; +} +void helper_pmon (CPUMIPSState *env,int function) { function /=2 ;
target/mips/tcg/translate.c +8 -0
@@ -10923,6 +10923,14 @@ void gen_rdhwr(DisasContext *ctx, int rt, int rd, int sel) }break ;#endif +case 30 : +if (!(ctx->insn_flags &INSN_OCTEON )) { +gen_reserved_instruction (ctx); +break ; + } +gen_helper_rdhwr_chord (t0, tcg_env); +gen_store_gpr (t0, rt); +break ;default :/* Invalid */ MIPS_INVAL ("rdhwr" );gen_reserved_instruction (ctx);
Signature · 1 line
2.54.0
PATCH v3 32/32 target/mips: expose Octeon68XX floating-point support
In reply to James HilliardOcteon68XX cores implement CP1. Advertise that in the CPU definition by setting Config1.FP, enabling the writable Status bits, and providing the FCR0/FCR31 defaults used by this CPU model.
This lets guests observe the expected floating-point feature bits and use CP1 with -cpu Octeon68XX.
---
Changes v1 -> v2:
- Move this CPU-model correction into a separate final patch. (suggested by Philippe Mathieu-Daudé)
--- target/mips/cpu-defs.c.inc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
target/mips/cpu-defs.c.inc +8 -2
@@ -997,7 +997,8 @@ const mips_def_t mips_defs[] = .CP0_PRid = 0x000D9100, .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) | (MMU_TYPE_R4000 << CP0C0_MT), - .CP0_Config1 = MIPS_CONFIG1 | (0x3F << CP0C1_MMU) | + .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | + (0x3F << CP0C1_MMU) | (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) | (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) | (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
@@ -1011,7 +1012,12 @@ const mips_def_t mips_defs[] = .CP0_PageGrain = (1 << CP0PG_ELPA), .SYNCI_Step = 32, .CCRes = 2, - .CP0_Status_rw_bitmask = 0x12F8FFFF, + .CP0_Status_rw_bitmask = 0x36F8FFFF, + .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) | + (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) | + (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV), + .CP1_fcr31 = 0, + .CP1_fcr31_rw_bitmask = 0xFF83FFFF, .SEGBITS = 42, .PABITS = 49, .insn_flags = CPU_MIPS64R2 | INSN_OCTEON,
Signature · 1 line
2.54.0