target/mips: add missing Octeon user-mode support
v16 cover target/mips: add missing Octeon user-mode support
This series completes the remaining Octeon user-mode support work after v12 covered the sysmips/FIXADE pieces, Octeon integer/indexed memory/atomic instructions, multiplier/QMAC support, CP1 exposure, and per-instruction smoke tests.
This series carries the remaining Octeon COP2 crypto state and helpers, explicit COP2 selector decode, CHORD/LLM, CvmCount RDHWR support, and the extended Octeon smoke coverage. The COP2 work is
split into state, helper plumbing, per-engine helper patches, explicit selector decode by functional group, and smoke-test coverage so each functional block can be reviewed independently.
Changes since v1:
- Split BADDU/DMUL destination fixes into a separate patch.
- Split the SEQ/SNE decode refactoring into a separate 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.
- Reworked GFM helpers to keep the architectural 128-bit state and direct RESINP XOR paths.
- Moved the Octeon68XX CP1 CPU-model correction to the end of the series.
- Added migration coverage for Octeon COP2 crypto and LLM sparse state.
- Split COP2 helper implementation by functional subcategory and added helper.h declarations alongside the side-effecting selector operations.
- Removed the shared COP2 selector enum; selectors are now either decoded by decodetree or kept as helper-local constants for shared register-window arithmetic.
- Used signed 32-bit DMFC2 direct loads for 32-bit COP2 register readback.
---
Changes in v16:
- Rebased on current qemu.git master.
- Dropped the TCG mul[us]2 optimization patch, which is now upstream as
c9349965ce ("tcg: Optimize INDEX_op_mul[us]2 for 0 and 1").
- No changes to the remaining Octeon target patches since v15.
- Link to v15: https://lore.kernel.org/qemu-devel/20260522-mips-octeon-missing-insns-v2-v15-0-f8731a588dc2@gmail.com
Changes in v15:
- Addressed Richard Henderson's v14 GFM review by documenting the
validated reflected-polynomial reduction form and sharing the 64-bit
UIA2 shortcut for normal and reflected XORMUL1.
- Modeled SHA3 as a direct 25-lane architectural view, used direct TCG
moves and XORs for SHA3 DAT/XORDAT selectors, and removed the unused
STARTOP operand.
- Kept ZUC runtime state in the documented HASHIV window and generated the
third MAC lookahead word on demand instead of mirroring it through HSH
DAT aliases.
- Added Richard Henderson's Reviewed-by and Acked-by tags for the COP2
selector decode and QMAC test patches.
- Link to v14: https://lore.kernel.org/qemu-devel/20260521-mips-octeon-missing-insns-v2-v14-0-fbf08e164830@gmail.com
Changes in v14:
- Added Richard Henderson's Reviewed-by tags for the Octeon COP2 crypto
state and helper plumbing patches.
- Fixed HSH DAT/IV DMFC2/DMTC2 selector transfers to use paired low-32
architectural words.
- Added missing HSH DAT readback selectors and smoke coverage.
- Moved the Octeon COP2 undefined-selector fallback into the register
selector decode patch.
- Removed the redundant AES RESINP translator path.
- Link to v13: https://lore.kernel.org/qemu-devel/20260521-mips-octeon-missing-insns-v2-v13-0-5a4cb8ec9cd3@gmail.com
Changes in v13:
- Rebased the remaining TCG/COP2/CvmCount patches on current qemu.git staging after v12.
- Dropped patches already covered by v12.
- Kept the explicit Octeon COP2 selector decode split by register,
CRC/GFM, HSH/SHA3, stream-cipher, block-cipher, and CHORD/LLM groups.
- Folded the COP2 state/decode review fixes into the series, including architectural HSH shared-window state, direct reflected GFM register helpers, CRC/AES length masking, and corrected selector naming.
- Folded COP2 readback, reflected-selector, and CvmCount smoke coverage
into the related implementation commits.
- Added standalone QMAC/QMACS smoke coverage.
- Link to v12: https://lore.kernel.org/qemu-devel/[email protected]/
Changes in v12:
- Rebased v12 on rth/tcg-next.
- Addressed Richard's review comments, including comment rewording.
- Passed gen_atomic_*() through do_atomic_ld().
- Used tcg_zero_i128() for ZCB/ZCBT zero stores.
- Reordered the indexed-load TRANS() entries.
- Link to v11: https://lore.kernel.org/qemu-devel/[email protected]/
Changes in v11:
- Split the previously submitted v10 series for review.
- Added tests alongside each instruction patch instead of collecting all
instruction coverage at the end.
- Split SEQNE/SEQNEI into separate SEQ/SNE and SEQI/SNEI decode patches
to ease review.
- Link to v10: https://lore.kernel.org/qemu-devel/20260519-mips-octeon-missing-insns-v2-v10-0-306f9edfe15b@gmail.com
Changes in v10:
- Split the explicit Octeon COP2 selector decode patch into register,
CRC/GFM, HSH/SHA3, stream-cipher, block-cipher, and CHORD/LLM
patches.
- Added Philippe's Reviewed-by tag and local MemOp cleanup for ZCB/ZCBT.
- Added Philippe's Tested-by tags for VMULU, VMM0, and Octeon68XX CP1.
- Restored the original constant-fold output ordering in the TCG mul[us]2
optimization patch.
- Kept Octeon COP2 crypto state architectural by dropping shared-mode and
AES, GFM, SHA3, ZUC, and SNOW3G shadow state.
- Ordered Octeon COP2 crypto CPU state and VMState fields by architectural
selector groups.
- Reworked GFM reflected helpers around the full 128-bit architectural state
and direct RESINP XOR operations.
- Preserved the 64-bit UIA2 GFM reduction path used by SNOW3G F9.
- Added Richard's Reviewed-by tag for the CRC COP2 helpers and masked
variable-length CRC writes to CRCLEN<3:0>.
- Link to v9: https://lore.kernel.org/qemu-devel/20260519-mips-octeon-missing-insns-v2-v9-0-d7dd735ecddd@gmail.com
Changes in v9:
- Used MO_ATOM_NONE for the 128-bit ZCB/ZCBT zero stores.
- Reused octeon_zero_partial_product_state() in the VMM0 translator.
- Removed the shared MIPSOcteonCop2Sel enum from CPU state headers.
- Replaced generic selector-dispatch COP2 helpers with per-operation
helper functions.
- Split COP2 helper implementation into smaller functional subcategory
patches: plumbing, CRC, GFM, SHA3, ZUC, SNOW3G, AES, SMS4, 3DES/KASUMI,
Camellia, HSH, and CHORD/LLM.
- Added COP2 helper declarations to helper.h alongside the per-engine
helper implementation commits.
- Used signed 32-bit DMFC2 direct loads for 32-bit COP2 register
readback.
- Documented the AESRESINP direct register-transfer handling in the translator.
- Combined COP2 selector readback with QMAC/CvmCount smoke coverage.
- Link to v8: https://lore.kernel.org/qemu-devel/20260517-mips-octeon-missing-insns-v2-v8-0-206151ee77ec@gmail.com
Changes in v8:
- Incorporated Richard Henderson's v7.5 9-patch multiplier/QMAC rework
directly into the series.
- Added the two v7.5 TCG prep patches as standalone patches:
tcg_gen_addN_i64 and mul[us]2 zero/one optimization.
- Replaced the helper-backed Octeon multiplier/QMAC sequence with the
seven v7.5-shaped patches: multiplier state, MTM, MTP, VMULU, VMM0,
V3MULU, and QMAC.
- Split Octeon COP2 crypto core support into state/migration, helper
implementation, explicit selector decode, and selector readback test
patches.
- Decoded Octeon COP2 selectors explicitly in decodetree and used direct
TCG loads/stores for simple COP2 register moves.
- Kept COP2 helper calls for operation selectors and shared-window state
that require side effects.
- Folded ZCB/ZCBT into one patch so the decodetree wildcard is
introduced in final form.
- Added new Reviewed-by tags from Richard Henderson for MTM/MTP, LA*,
CvmCount, and QMAC/CvmCount test patches.
- Link to v7: https://lore.kernel.org/qemu-devel/20260514-mips-octeon-missing-insns-v2-v7-0-226686be4ce1@gmail.com
Changes in v7:
- Rebased on current qemu.git staging (edcc429e9e).
- Reordered the zero-register cleanup after the BADDU/DMUL destination fix
and moved the multiplier-state patch next to the MTM/MTP instruction
patches.
- Applied Philippe's MIPS_FIXADE TB-flag readability tweak.
- Used explicit MO_32/MO_64 MemOps for SAA/SAAD atomic transaction sizes.
- Folded ZCB/ZCBT decode with a decodetree wildcard and zero the cache
block with 128-bit stores.
- Added new Reviewed-by tags from Philippe Mathieu-Daudé and Richard
Henderson.
- Link to v6: https://lore.kernel.org/qemu-devel/20260511-mips-octeon-missing-insns-v2-v6-0-5062889c4d3c@gmail.com
Changes in v6:
- Added Octeon QMAC/QMACS fixed-point accumulator support and smoke
coverage.
- Added Octeon RDHWR $31/CvmCount support and smoke coverage.
- Clarified MTM0/VMM0 reset behavior against the CN71XX
register-state tables.
- Fixed MTP0 to zero P1 per the CN71XX register-state table and added
smoke coverage.
- Fixed VMM0 MPL1 reset handling and added smoke coverage for MPL1.
- Cleaned up internal VMUL, LA*, COP2 payload/state, and COP2 selector
naming to better match hardware register/selector terminology.
- Renamed the MIPS_FIXADE TB flag, HSH register word-packing helpers,
and sparse LLM backing fields to match ABI and hardware terminology.
- Link to v5: https://lore.kernel.org/qemu-devel/20260510-mips-octeon-missing-insns-v2-v5-0-d5d2668d15ab@gmail.com
Changes in v5:
- Added Richard Henderson's Reviewed-by tags for LBX, LHUX, LWUX, SAA,
and SAAD, plus Acked-by tags for ZCB and ZCBT.
- Dropped the separate Octeon+ feature bit; QEMU has a single Octeon CPU
model today, so SAA/SAAD stay under the existing Octeon feature bucket.
- Folded ZCBT into the ZCB decodetree entry with a selector comment.
- Link to v4: https://lore.kernel.org/qemu-devel/20260509-mips-octeon-missing-insns-v2-v4-0-d669dcd05c2f@gmail.com
Changes in v4:
- Added Richard Henderson's Reviewed-by tags to the reviewed sysmips and
Octeon translator cleanup patches.
- Kept the Octeon3 MPL3-MPL5/P3-P5 high-lane multiplier state
documented by Cavium SDK/toolchain sources.
- Documented the Octeon3 two-source MTM/MTP forms and preserved the rt
high-lane operands while legacy one-source encodings use rt == $zero.
- Simplified SAA/SAAD translation to use the i64 TCG atomic add path for
both word and doubleword sizes.
- Marked SAA/SAAD as Octeon+ instructions and gated them behind a
separate Octeon+ feature bit.
- Simplified LA* translation to use i64 TCG atomic helpers for word and
doubleword operations, with MO_SL selecting word result sign-extension.
- Link to v3: https://lore.kernel.org/qemu-devel/20260508-mips-octeon-missing-insns-v2-v3-0-bcbec96357d9@gmail.com
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/ZCBT, multiplier, and test patches.
- Reworked Octeon multiplier limb accumulation as requested.
- 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]>
Cc: Richard Henderson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
---
James Hilliard (21):
target/mips: add Octeon COP2 crypto state target/mips: add Octeon COP2 crypto helper plumbing target/mips: add Octeon CRC COP2 helpers target/mips: add Octeon GFM COP2 helpers target/mips: add Octeon SHA3 COP2 helpers target/mips: add Octeon ZUC COP2 helpers target/mips: add Octeon SNOW3G COP2 helpers target/mips: add Octeon AES COP2 helpers target/mips: add Octeon SMS4 COP2 helpers target/mips: add Octeon 3DES and KASUMI COP2 helpers target/mips: add Octeon Camellia COP2 helpers target/mips: add Octeon HSH COP2 helpers target/mips: add Octeon CHORD and LLM COP2 helpers target/mips: decode Octeon COP2 register selectors target/mips: decode Octeon CRC and GFM COP2 selectors target/mips: decode Octeon HSH and SHA3 COP2 selectors target/mips: decode Octeon ZUC and SNOW3G COP2 selectors target/mips: decode Octeon block-cipher COP2 selectors target/mips: decode Octeon CHORD and LLM COP2 selectors target/mips: add Octeon CvmCount RDHWR support tests/tcg/mips: cover Octeon QMAC instructions
target/mips/cpu.c | 68 + target/mips/cpu.h | 31 + target/mips/helper.h | 61 + target/mips/internal.h | 3 + target/mips/system/machine.c | 94 + target/mips/tcg/meson.build | 1 + target/mips/tcg/octeon.decode | 213 +++ target/mips/tcg/octeon_crypto.c | 2314 +++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 396 +++++ target/mips/tcg/op_helper.c | 19 +- target/mips/tcg/translate.c | 19 + tests/tcg/mips/user/isa/octeon/octeon-insns.c | 216 +++ 12 files changed, 3434 insertions(+), 1 deletion(-)
---
base-commit: cc329c491768b2d91eb0b0984f3baa0bf805776d
change-id: 20260420-mips-octeon-missing-insns-v2-5e693770cf2c
Best regards,
Signature · 1 line
James Hilliard <[email protected]>
PATCH v16 1/21 target/mips: add Octeon COP2 crypto state
Add the common architectural state needed by Octeon's selector-driven COP2 crypto interfaces. This includes storage for the base hash, AES, CRC, GFM, 3DES, KASUMI, and overlapping HSH/SHA512/SHA3/SNOW3G/ZUC selector windows.
Keep selector values and helper-local aliasing logic out of the CPU state header so the state definition remains limited to architectural storage. Helper code uses the same register banks instead of adding non-architectural shadow state. Model the SHA3 view as a direct 25-lane alias of the architectural HSH DAT/IV/SHA3_DAT24 storage.
Migrate the state in an Octeon-only subsection so non-Octeon CPU models do not grow migration data.
---
Changes v14 -> v15:
- Model SHA3 as a direct 25-lane architectural view over the HSH DAT/IV and SHA3_DAT24 storage.
Changes v10 -> v13:
- Keep reflected GFM selectors mapped onto the architectural GFM state from the start instead of adding temporary reflected shadow fields.
Changes v9 -> v10:
- Drop non-architectural shared-mode, AES input/result split, GFM XOR, and ZUC/SNOW3G shadow state.
- Model HSH/SHA512/SHA3/SNOW3G/ZUC overlap with the architectural HSH DAT/IV register banks.
- Store CRCLEN as the architectural 4-bit state.
Changes v8 -> v9:
- Remove the MIPSOcteonCop2Sel enum; selector values are decoded by decodetree or kept local to helper plumbing.
- Leave only COP2 state and migration data in this patch.
Changes v7 -> v8:
- Split COP2 crypto state and migration coverage out of the combined COP2 crypto core patch.
--- target/mips/cpu.h | 26 ++++++++++++++++++++++++++ target/mips/system/machine.c | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
target/mips/cpu.h +26 -0
@@ -537,6 +537,30 @@ struct TCState { };struct MIPSITUState ; +typedef struct MIPSOcteonCryptoState { +union { +struct { +uint64_t hsh_dat[16 ]; +uint64_t hsh_iv[8 ]; +uint64_t sha3_dat24; + }; +uint64_t sha3_dat[25 ]; + }; +uint64_t des3_key[3 ]; +uint64_t des3_iv; +uint64_t des3_result; +uint64_t aes_resinp[2 ]; +uint64_t aes_iv[2 ]; +uint64_t aes_key[4 ]; +uint32_t crc_poly; +uint32_t crc_iv; +uint64_t gfm_mul[2 ]; +uint64_t gfm_resinp[2 ]; +uint16_t gfm_poly; +uint8_t aes_keylen; +uint8_t crc_len; +}MIPSOcteonCryptoState ; + typedef struct CPUArchState { TCState active_tc; CPUMIPSFPUContext active_fpu;
@@ -558,6 +582,8 @@ typedef struct CPUArchState {#define MSAIR_ProcID 8#define MSAIR_Rev 0 +MIPSOcteonCryptoState octeon_crypto; +/* * CP0 Register 0 */
target/mips/system/machine.c +27 -0
@@ -279,6 +279,32 @@ 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.hsh_dat,MIPSCPU ,16 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_iv,MIPSCPU ,8 ), +VMSTATE_UINT64 (env.octeon_crypto.sha3_dat24,MIPSCPU ), +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.aes_resinp,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_iv,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_key,MIPSCPU ,4 ), +VMSTATE_UINT32 (env.octeon_crypto.crc_poly,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.crc_iv,MIPSCPU ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_mul,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_resinp,MIPSCPU ,2 ), +VMSTATE_UINT16 (env.octeon_crypto.gfm_poly,MIPSCPU ), +VMSTATE_UINT8 (env.octeon_crypto.aes_keylen,MIPSCPU ), +VMSTATE_UINT8 (env.octeon_crypto.crc_len,MIPSCPU ), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_mips_cpu = { .name ="cpu" , .version_id =21 ,
@@ -396,6 +422,7 @@ const VMStateDescription vmstate_mips_cpu = { .subsections = (const VMStateDescription * const []) { &mips_vmstate_timer, &mips_vmstate_octeon_multiplier, + &mips_vmstate_octeon_crypto,NULL } };
Signature · 1 line
2.54.0
PATCH v16 2/21 target/mips: add Octeon COP2 crypto helper plumbing
In reply to James HilliardAdd the Octeon COP2 crypto helper source file and build it with the MIPS TCG target. This provides the common compilation unit for the COP2 engine helpers.
The instruction dispatch itself remains fully decoded by decodetree, and operation selectors call per-operation helpers rather than a common selector-dispatch helper.
---
Changes v9 -> v10:
- Remove shared-window selector constants and the shared-mode setter.
Changes v8 -> v9:
- Split helper plumbing out of the former monolithic COP2 helper patch.
- Keep shared-window selector arithmetic local to octeon_crypto.c.
--- target/mips/tcg/meson.build | 1 + target/mips/tcg/octeon_crypto.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
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 +16 -0
@@ -0,0 +1,16 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* MIPS Octeon crypto emulation helpers. +* +* Copyright (c) 2026 James Hilliard +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "internal.h" +#include "exec/helper-proto.h" +#include "crypto/aes.h" +#include "crypto/sm4.h" +#include "qemu/bitops.h" +#include "qemu/host-utils.h"
Signature · 1 line
2.54.0
PATCH v16 3/21 target/mips: add Octeon CRC COP2 helpers
In reply to James HilliardAdd helper support for the Octeon COP2 CRC register interface. This covers normal and reflected CRC state handling, byte/halfword/word/ doubleword/variable-width update selectors, and the reflected IV readback operation.
Register moves that can be represented as direct TCG loads/stores do not need helpers. Add only the side-effecting CRC helper implementation here.
---
Changes v9 -> v10:
- Mask variable-length CRC writes to CRCLEN<3:0>.
- Add Richard's Reviewed-by tag.
Changes v8 -> v9:
- Split CRC selector operations into their own COP2 helper patch.
- Expose per-operation helpers instead of a generic selector helper.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 14 +++++ target/mips/tcg/octeon_crypto.c | 131 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+)
target/mips/helper.h +14 -0
@@ -25,6 +25,20 @@ 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) +/* Octeon COP2 selector operation helpers. */ +DEF_HELPER_1(octeon_cp2_mf_crc_iv_reflect, i64, env) +DEF_HELPER_2(octeon_cp2_mt_crc_write_iv_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_byte, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_half, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_word, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_byte_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_half_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_word_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_dword, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_var, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_dword_reflect, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_crc_write_var_reflect, void, env, i64) + /* microMIPS functions */ DEF_HELPER_4(lwm, void, env, tl, tl, i32)DEF_HELPER_4 (swm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +131 -0
134 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 4/21 target/mips: add Octeon GFM COP2 helpers
In reply to James HilliardAdd helper support for the Octeon GFM carryless multiply selectors. This models the normal and reflected multiplication paths, including the XOR-and-multiply forms that update the result/input state used by Octeon crypto code.
Reflected selectors operate on the architectural GFM register bank using bit-reflected register transfers rather than a separate shadow state. Keep the 64-bit UIA2 reduction path used by SNOW3G F9 and share that shortcut between the normal and reflected XORMUL1 paths.
---
Changes v14 -> v15:
- Document the reflected-polynomial reduction form used by the GFM multiplier.
- Share the 64-bit UIA2 shortcut between normal and reflected XORMUL1.
- Inline the simple non-reflected GFM XOR selector in the translator.
Changes v10 -> v13:
- Map reflected GFM selectors directly onto the architectural GFM state in this patch instead of adding temporary reflected shadow state.
- Preserve the 64-bit UIA2 GFM reduction path used by SNOW3G F9.
Changes v8 -> v9:
- Split GFM selector operations into their own COP2 helper patch.
- Expose per-operation helpers instead of a generic selector helper.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 9 +++ target/mips/tcg/octeon_crypto.c | 142 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+)
target/mips/helper.h +9 -0
@@ -27,6 +27,10 @@ DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32)/* Octeon COP2 selector operation helpers. */ DEF_HELPER_1(octeon_cp2_mf_crc_iv_reflect, i64, env) +DEF_HELPER_1(octeon_cp2_mf_gfm_mul_reflect0, i64, env) +DEF_HELPER_1(octeon_cp2_mf_gfm_mul_reflect1, i64, env) +DEF_HELPER_1(octeon_cp2_mf_gfm_resinp_reflect0, i64, env) +DEF_HELPER_1(octeon_cp2_mf_gfm_resinp_reflect1, i64, env) DEF_HELPER_2(octeon_cp2_mt_crc_write_iv_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_byte, void, env, i64)DEF_HELPER_2 (octeon_cp2_mt_crc_write_half, void, env, i64)
@@ -38,6 +42,11 @@ DEF_HELPER_2(octeon_cp2_mt_crc_write_dword, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_var, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_dword_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_var_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_gfm_mul_reflect0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_gfm_mul_reflect1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_gfm_xor0_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1_reflect, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_gfm_xormul1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +142 -0
159 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 5/21 target/mips: add Octeon SHA3 COP2 helpers
In reply to James HilliardAdd the Octeon SHA3 helper operations for the architectural 25-lane Keccak state view and implement the Keccak-f[1600] permutation used by the STARTOP selector.
The simple SHA3 DAT register moves and XORDAT selectors are decoded as direct TCG transfers in the selector decode patch. This helper patch only keeps the side-effecting SHA3 operation support.
---
Changes v14 -> v15:
- Use the direct 25-lane architectural SHA3 state view from CPU state.
- Move simple SHA3 DAT and XORDAT selector handling to direct TCG transfers in the decode patch.
- Remove the unused STARTOP source operand from the helper ABI.
Changes v8 -> v9:
- Split SHA3 selector operations into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation SHA3 helpers.
- Use helper-local selector constants for shared-window position logic.
- Add matching helper.h declarations with the helper implementation.
Changes v5 -> v6:
- Rename SHA3 DAT15 selector aliases with MF/MT direction suffixes.
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/helper.h | 1 + target/mips/tcg/octeon_crypto.c | 93 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
target/mips/helper.h +1 -0
@@ -47,6 +47,7 @@ DEF_HELPER_2(octeon_cp2_mt_gfm_mul_reflect1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_gfm_xor0_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1, void, env, i64) +DEF_HELPER_1 (octeon_cp2_mt_sha3_startop, void, env) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +93 -0
105 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 6/21 target/mips: add Octeon ZUC COP2 helpers
In reply to James HilliardAdd the Octeon ZUC START and MORE helper operations 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.
Keep the LFSR words in the architectural HSH DAT input registers and the runtime MAC/FSM/result state in the documented HASHIV window. The third MAC lookahead word is generated on demand instead of being kept in a non-architectural shadow slot.
---
Changes v14 -> v15:
- Keep ZUC runtime state in the documented HASHIV window instead of HSH DAT aliases.
- Generate the third MAC lookahead word on demand.
Changes v8 -> v9:
- Split ZUC selector operations into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation ZUC helpers.
- Use helper-local selector constants for shared-window position logic.
- Add matching helper.h declarations with the helper implementation.
Changes v5 -> v6:
- Use the manual-aligned HSH_DATW field and shared HSH window helper names introduced by the COP2 crypto core patch.
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/helper.h | 2 + target/mips/tcg/octeon_crypto.c | 346 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+)
target/mips/helper.h +2 -0
@@ -48,6 +48,8 @@ DEF_HELPER_2(octeon_cp2_mt_gfm_xor0_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1, void, env, i64) DEF_HELPER_1(octeon_cp2_mt_sha3_startop, void, env) +DEF_HELPER_2(octeon_cp2_mt_zuc_start, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_zuc_more, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +346 -0
352 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 7/21 target/mips: add Octeon SNOW3G COP2 helpers
In reply to James HilliardAdd helper support for the Octeon SNOW3G START and MORE selectors. The engine state and result are represented through the architectural HSH IV and DAT register banks that SNOW3G aliases for save and restore.
---
Changes v9 -> v10:
- Drop non-architectural SNOW3G shadow state and shared-mode tracking.
- Use the architectural HSH IV/DAT register banks for aliased state.
Changes v8 -> v9:
- Split SNOW3G selector operations into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation SNOW3G helpers.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 2 + target/mips/tcg/octeon_crypto.c | 275 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+)
target/mips/helper.h +2 -0
@@ -50,6 +50,8 @@ DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1, void, env, i64) DEF_HELPER_1(octeon_cp2_mt_sha3_startop, void, env) DEF_HELPER_2(octeon_cp2_mt_zuc_start, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_zuc_more, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_snow3g_start, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_snow3g_more, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +275 -0
281 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 8/21 target/mips: add Octeon AES COP2 helpers
In reply to James HilliardAdd helper support for the Octeon AES operation selectors. Direct register-transfer selectors do not need helpers; the ECB/CBC encrypt and decrypt operations consume the AES input, key, IV, and key-length state.
AESRESINP is modeled as one architectural register bank; operation helpers consume the current AESRESINP block and write the result back to the same bank.
---
Changes v9 -> v10:
- Drop the non-architectural AES input/result split.
- Model AESRESINP as a single architectural input/result bank.
Changes v8 -> v9:
- Split AES operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation AES helpers.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 4 ++ target/mips/tcg/octeon_crypto.c | 145 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+)
target/mips/helper.h +4 -0
@@ -52,6 +52,10 @@ DEF_HELPER_2(octeon_cp2_mt_zuc_start, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_zuc_more, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_snow3g_start, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_snow3g_more, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_aes_enc_cbc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_aes_enc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_aes_dec_cbc1, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_aes_dec1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +145 -0
151 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 9/21 target/mips: add Octeon SMS4 COP2 helpers
In reply to James HilliardAdd helper support for the Octeon SMS4 operation selectors. SMS4 reuses the AES RESINP, IV, and key banks, so the helpers share the existing AES state while implementing the SMS4 ECB/CBC encrypt and decrypt operations.
---
Changes v8 -> v9:
- Split SMS4 operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation SMS4 helpers.
- Add matching helper.h declarations with the helper implementation.
Changes v5 -> v6:
- Use RESINP wording for the SMS4 shared selector aliases.
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/helper.h | 4 ++ target/mips/tcg/octeon_crypto.c | 124 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+)
target/mips/helper.h +4 -0
@@ -56,6 +56,10 @@ DEF_HELPER_2(octeon_cp2_mt_aes_enc_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_aes_enc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_aes_dec_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_aes_dec1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sms4_enc_cbc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sms4_enc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sms4_dec_cbc1, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_sms4_dec1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +124 -0
130 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 10/21 target/mips: add Octeon 3DES and KASUMI COP2 helpers
In reply to James HilliardAdd helper support for the Octeon 3DES and KASUMI operation selectors. The 3DES helpers implement ECB and CBC encrypt/decrypt over the shared 3DES key, IV, and result bank. KASUMI reuses the same register bank and adds its own encrypt selectors.
Only the operation selectors require helper code. Simple key, IV, and result register transfers are handled by direct selector decode.
---
Changes v8 -> v9:
- Split 3DES/KASUMI operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation 3DES/KASUMI helpers.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 6 + target/mips/tcg/octeon_crypto.c | 458 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 464 insertions(+)
target/mips/helper.h +6 -0
@@ -60,6 +60,12 @@ DEF_HELPER_2(octeon_cp2_mt_sms4_enc_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sms4_enc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sms4_dec_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sms4_dec1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_des3_enc_cbc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_kas_enc_cbc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_des3_enc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_kas_enc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_des3_dec_cbc, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_des3_dec, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +458 -0
464 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 11/21 target/mips: add Octeon Camellia COP2 helpers
In reply to James HilliardAdd helper support for the Octeon Camellia ROUND, FL, and FLINV selectors. The engine reuses the AES RESINP bank, and guest-managed key schedules drive the Camellia F-function and FL layers through these COP2 operations.
Implement the Camellia F-function and FL layers directly from RFC 3713.
---
Changes v8 -> v9:
- Split Camellia operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation Camellia helpers.
- Add matching helper.h declarations with the helper implementation.
Changes v5 -> v6:
- Use RESINP wording for the Camellia shared selector aliases.
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/helper.h | 3 + target/mips/tcg/octeon_crypto.c | 126 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+)
target/mips/helper.h +3 -0
@@ -66,6 +66,9 @@ DEF_HELPER_2(octeon_cp2_mt_des3_enc, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_kas_enc, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_des3_dec_cbc, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_camellia_round, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +126 -0
132 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 12/21 target/mips: add Octeon HSH COP2 helpers
In reply to James HilliardAdd helper support for the Octeon HSH hash selectors. This includes the base HSH data/IV windows, MD5, SHA1, SHA256, and SHA512 transform paths, and the shared HSH/SHA512 register-window readback and write operations.
The SHA512 path shares the wide HSH register bank with SHA3, SNOW3G, and ZUC. Keep the aliased readback and write paths centralized so selector decode can route register accesses through these helpers when side effects are required.
---
Changes v13 -> v14:
- Keep HSH narrow DAT/IV state updates in the low 32-bit halves of the architectural HSH register bank so paired selector transfers preserve the wide shared-window state.
Changes v10 -> v13:
- Keep the 0x0057 SDK compatibility path as an explicit STARTSHA1 compatibility helper instead of a generic STARTSHA name.
Changes v9 -> v10:
- Remove references to shared-mode tracking; aliased state is kept in the architectural HSH register banks.
Changes v8 -> v9:
- Split HSH/SHA helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation HSH helpers.
- Keep shared-window readback and write helpers grouped with HSH.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 5 + target/mips/tcg/octeon_crypto.c | 375 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+)
target/mips/helper.h +5 -0
@@ -69,6 +69,11 @@ DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_round, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha1_compat, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_hsh_startsha512, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +375 -0
387 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v16 12/21] target/mips: add Octeon HSH COP2 helpers
Hi James,
Quoted 106 lines · James Hilliard
Add helper support for the Octeon HSH hash selectors. This includes the base HSH data/IV windows, MD5, SHA1, SHA256, and SHA512 transform paths, and the shared HSH/SHA512 register-window readback and write operations.
The SHA512 path shares the wide HSH register bank with SHA3, SNOW3G, and ZUC. Keep the aliased readback and write paths centralized so selector decode can route register accesses through these helpers when side effects are required.
Signed-off-by James Hilliard <[email protected]>---
Changes v13 -> v14:
- Keep HSH narrow DAT/IV state updates in the low 32-bit halves of the architectural HSH register bank so paired selector transfers preserve the wide shared-window state.Changes v10 -> v13:
- Keep the0x0057SDK compatibility path as an explicit STARTSHA1 compatibility helper instead of a generic STARTSHA name.Changes v9 -> v10:
- Remove references to shared-mode tracking; aliased state is kept in the architectural HSH register banks.Changes v8 -> v9:
- Split HSH/SHA helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation HSH helpers.
- Keep shared-window readback and write helpers grouped with HSH.
- Add matchinghelper.hdeclarations with the helper implementation.--- target/mips/helper.h | 5 + target/mips/tcg/octeon_crypto.c | 375 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+)target/mips/helper.h +5
-0@@ -69,6 +69,11 @@ DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_round, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha1_compat, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_hsh_startsha512, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)target/mips/tcg/octeon_crypto.c +48
-0@@ -153,6 +153,348 @@ static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], out[1 ] =revbit64 (res); } +static inline uint32_t octeon_hsh_get32 (const uint64_t *regs, +unsigned int index) +{ +return regs[index]; +} + +static inline void octeon_hsh_set32 (uint64_t *regs,unsigned int index, +uint32_t value) +{ + regs[index] = (regs[index] & ~(uint64_t )UINT32_MAX ) | value; +} + +static inline void octeon_hsh_set_pair (uint64_t *regs,unsigned int index, +uint64_t value) +{ +octeon_hsh_set32 (regs, index *2 , value >>32 ); +octeon_hsh_set32 (regs, index *2 +1 , value); +} + +static void octeon_md5_transform (MIPSOcteonCryptoState *crypto) +{ +static const uint32_t k[64 ] = { +0xd76aa478U ,0xe8c7b756U ,0x242070dbU ,0xc1bdceeeU , +0xf57c0fafU ,0x4787c62aU ,0xa8304613U ,0xfd469501U , +0x698098d8U ,0x8b44f7afU ,0xffff5bb1U ,0x895cd7beU , +0x6b901122U ,0xfd987193U ,0xa679438eU ,0x49b40821U , +0xf61e2562U ,0xc040b340U ,0x265e5a51U ,0xe9b6c7aaU , +0xd62f105dU ,0x02441453U ,0xd8a1e681U ,0xe7d3fbc8U , +0x21e1cde6U ,0xc33707d6U ,0xf4d50d87U ,0x455a14edU , +0xa9e3e905U ,0xfcefa3f8U ,0x676f02d9U ,0x8d2a4c8aU , +0xfffa3942U ,0x8771f681U ,0x6d9d6122U ,0xfde5380cU , +0xa4beea44U ,0x4bdecfa9U ,0xf6bb4b60U ,0xbebfbc70U , +0x289b7ec6U ,0xeaa127faU ,0xd4ef3085U ,0x04881d05U , +0xd9d4d039U ,0xe6db99e5U ,0x1fa27cf8U ,0xc4ac5665U , +0xf4292244U ,0x432aff97U ,0xab9423a7U ,0xfc93a039U , +0x655b59c3U ,0x8f0ccc92U ,0xffeff47dU ,0x85845dd1U , +0x6fa87e4fU ,0xfe2ce6e0U ,0xa3014314U ,0x4e0811a1U , +0xf7537e82U ,0xbd3af235U ,0x2ad7d2bbU ,0xeb86d391U , + }; +static const uint8_t s[64 ] = { +7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 , +5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 , +4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 , +6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 , + }; +uint32_t m[16 ]; +uint32_t a, b, c, d; +uint32_t aa, bb, cc, dd;
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 213
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+int i; + +for (i =0 ; i <16 ; i++) { + m[i] =bswap32 (octeon_hsh_get32 (crypto->hsh_dat, i)); + } + + a =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,0 )); + b =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,1 )); + c =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,2 )); + d =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,3 ));
The MD5 algorithm is little-endian, so I think for these we want cpu_to_le32(), ...
Quoted 27 lines
target/mips/tcg/octeon_crypto.c +27
-0+ aa = a; + bb = b; + cc = c; + dd = d; + +for (i =0 ; i <64 ; i++) { +uint32_t f, g, tmp; + +if (i <16 ) { + f = (b & c) | ((~b) & d); + g = i; + }else if (i <32 ) { + f = (d & b) | ((~d) & c); + g = (5 * i +1 ) &0xf ; + }else if (i <48 ) { + f = b ^ c ^ d; + g = (3 * i +5 ) &0xf ; + }else { + f = c ^ (b | (~d)); + g = (7 * i) &0xf ; + } + + tmp = d; + d = c; + c = b; + b = b +rol32 (a + f + k[i] + m[g], s[i]); + a = tmp;
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 250
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ } + + a += aa; + b += bb; + c += cc; + d += dd; +octeon_hsh_set32 (crypto->hsh_iv,0 ,bswap32 (a)); +octeon_hsh_set32 (crypto->hsh_iv,1 ,bswap32 (b)); +octeon_hsh_set32 (crypto->hsh_iv,2 ,bswap32 (c)); +octeon_hsh_set32 (crypto->hsh_iv,3 ,bswap32 (d));
... and le32_to_cpu() here.
Quoted 9 lines
target/mips/tcg/octeon_crypto.c +9
-0+} + +static void octeon_sha1_transform (MIPSOcteonCryptoState *crypto) +{ +uint32_t w[80 ]; +uint32_t a, b, c, d, e; +uint32_t orig[5 ]; +int i; +
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 269
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+for (i =0 ; i <16 ; i++) { + w[i] =octeon_hsh_get32 (crypto->hsh_dat, i); + } +for (i =16 ; i <80 ; i++) { + w[i] =rol32 (w[i -3 ] ^ w[i -8 ] ^ w[i -14 ] ^ w[i -16 ],1 ); + } + +for (i =0 ; i <5 ; i++) { + orig[i] =octeon_hsh_get32 (crypto->hsh_iv, i); + }
SHA is big-endian so we are good, but watch out this CPU could switch endianness.
Maybe safer to use cpu_to_be32() and be32_to_cpu()?
Quoted 33 lines
target/mips/tcg/octeon_crypto.c +33
-0+ a = orig[0 ]; + b = orig[1 ]; + c = orig[2 ]; + d = orig[3 ]; + e = orig[4 ]; + +for (i =0 ; i <80 ; i++) { +uint32_t f, k, temp; + +if (i <20 ) { + f = (b & c) | ((~b) & d); + k =0x5a827999 ; + }else if (i <40 ) { + f = b ^ c ^ d; + k =0x6ed9eba1 ; + }else if (i <60 ) { + f = (b & c) | (b & d) | (c & d); + k =0x8f1bbcdc ; + }else { + f = b ^ c ^ d; + k =0xca62c1d6 ; + } + + temp =rol32 (a,5 ) + f + e + k + w[i]; + e = d; + d = c; + c =rol32 (b,30 ); + b = a; + a = temp; + } + + orig[0 ] += a; + orig[1 ] += b;
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 312
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ orig[2 ] += c; + orig[3 ] += d; + orig[4 ] += e; +for (i =0 ; i <5 ; i++) { +octeon_hsh_set32 (crypto->hsh_iv, i, orig[i]); + } +} + +static void octeon_sha256_transform (MIPSOcteonCryptoState *crypto) +{
(ditto)
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 397
Quoted 4 lines
target/mips/tcg/octeon_crypto.c +4
-0+} + +static void octeon_sha512_transform (MIPSOcteonCryptoState *crypto) +{
(ditto)
Quoted 1 line
target/mips/tcg/octeon_crypto.c +1
-0+}
Re: [PATCH v16 12/21] target/mips: add Octeon HSH COP2 helpers
Quoted 115 lines · Philippe Mathieu-Daudé
Hi James,
Quoted 111 lines · James Hilliard
Add helper support for the Octeon HSH hash selectors. This includes the base HSH data/IV windows, MD5, SHA1, SHA256, and SHA512 transform paths, and the shared HSH/SHA512 register-window readback and write operations.
The SHA512 path shares the wide HSH register bank with SHA3, SNOW3G, and ZUC. Keep the aliased readback and write paths centralized so selector decode can route register accesses through these helpers when side effects are required.
Signed-off-by James Hilliard <[email protected]>---
Changes v13 -> v14:
- Keep HSH narrow DAT/IV state updates in the low 32-bit halves of the architectural HSH register bank so paired selector transfers preserve the wide shared-window state.Changes v10 -> v13:
- Keep the0x0057SDK compatibility path as an explicit STARTSHA1 compatibility helper instead of a generic STARTSHA name.Changes v9 -> v10:
- Remove references to shared-mode tracking; aliased state is kept in the architectural HSH register banks.Changes v8 -> v9:
- Split HSH/SHA helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation HSH helpers.
- Keep shared-window readback and write helpers grouped with HSH.
- Add matchinghelper.hdeclarations with the helper implementation.--- target/mips/helper.h | 5 + target/mips/tcg/octeon_crypto.c | 375 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+)target/mips/helper.h +5
-0@@ -69,6 +69,11 @@ DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_round, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha1_compat, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_hsh_startsha512, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)target/mips/tcg/octeon_crypto.c +53
-0@@ -153,6 +153,348 @@ static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], out[1 ] =revbit64 (res); } +static inline uint32_t octeon_hsh_get32 (const uint64_t *regs, +unsigned int index) +{ +return regs[index]; +} + +static inline void octeon_hsh_set32 (uint64_t *regs,unsigned int index, +uint32_t value) +{ + regs[index] = (regs[index] & ~(uint64_t )UINT32_MAX ) | value; +} + +static inline void octeon_hsh_set_pair (uint64_t *regs,unsigned int index, +uint64_t value) +{ +octeon_hsh_set32 (regs, index *2 , value >>32 ); +octeon_hsh_set32 (regs, index *2 +1 , value); +} + +static void octeon_md5_transform (MIPSOcteonCryptoState *crypto) +{ +static const uint32_t k[64 ] = { +0xd76aa478U ,0xe8c7b756U ,0x242070dbU ,0xc1bdceeeU , +0xf57c0fafU ,0x4787c62aU ,0xa8304613U ,0xfd469501U , +0x698098d8U ,0x8b44f7afU ,0xffff5bb1U ,0x895cd7beU , +0x6b901122U ,0xfd987193U ,0xa679438eU ,0x49b40821U , +0xf61e2562U ,0xc040b340U ,0x265e5a51U ,0xe9b6c7aaU , +0xd62f105dU ,0x02441453U ,0xd8a1e681U ,0xe7d3fbc8U , +0x21e1cde6U ,0xc33707d6U ,0xf4d50d87U ,0x455a14edU , +0xa9e3e905U ,0xfcefa3f8U ,0x676f02d9U ,0x8d2a4c8aU , +0xfffa3942U ,0x8771f681U ,0x6d9d6122U ,0xfde5380cU , +0xa4beea44U ,0x4bdecfa9U ,0xf6bb4b60U ,0xbebfbc70U , +0x289b7ec6U ,0xeaa127faU ,0xd4ef3085U ,0x04881d05U , +0xd9d4d039U ,0xe6db99e5U ,0x1fa27cf8U ,0xc4ac5665U , +0xf4292244U ,0x432aff97U ,0xab9423a7U ,0xfc93a039U , +0x655b59c3U ,0x8f0ccc92U ,0xffeff47dU ,0x85845dd1U , +0x6fa87e4fU ,0xfe2ce6e0U ,0xa3014314U ,0x4e0811a1U , +0xf7537e82U ,0xbd3af235U ,0x2ad7d2bbU ,0xeb86d391U , + }; +static const uint8_t s[64 ] = { +7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 , +5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 , +4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 , +6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 , + }; +uint32_t m[16 ]; +uint32_t a, b, c, d; +uint32_t aa, bb, cc, dd; +int i; + +for (i =0 ; i <16 ; i++) { + m[i] =bswap32 (octeon_hsh_get32 (crypto->hsh_dat, i)); + }
Quoted 8 lines
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 213
Quoted 5 lines
target/mips/tcg/octeon_crypto.c +5
-0+ + a =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,0 )); + b =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,1 )); + c =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,2 )); + d =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,3 ));The MD5 algorithm is little-endian, so I think for these we want
cpu_to_le32(), ...
Looking at the CN71XX manual, I think the current handling matches the architectural HSH register view. The HSH DAT/IV narrow selectors build HASHDAT/HASHIV words from GPR halves, and the SHA-512 wide selectors move whole GPR values into HASHDAT/HASHIV. These are COP2 register values, not target-memory byte arrays.
The manual calls out MD5 specially: HASHDAT/HASHIV are in the big-endian HSH register-word order, while MD5 is little-endian, so the MD5 operation byte-swaps HASHDAT/HASHIV on entry and exit. That is what the current bswap32() calls model.
Quoted 63 lines
Quoted 27 lines
target/mips/tcg/octeon_crypto.c +27
-0+ aa = a; + bb = b; + cc = c; + dd = d; + +for (i =0 ; i <64 ; i++) { +uint32_t f, g, tmp; + +if (i <16 ) { + f = (b & c) | ((~b) & d); + g = i; + }else if (i <32 ) { + f = (d & b) | ((~d) & c); + g = (5 * i +1 ) &0xf ; + }else if (i <48 ) { + f = b ^ c ^ d; + g = (3 * i +5 ) &0xf ; + }else { + f = c ^ (b | (~d)); + g = (7 * i) &0xf ; + } + + tmp = d; + d = c; + c = b; + b = b +rol32 (a + f + k[i] + m[g], s[i]); + a = tmp;target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 250
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ } + + a += aa; + b += bb; + c += cc; + d += dd; +octeon_hsh_set32 (crypto->hsh_iv,0 ,bswap32 (a)); +octeon_hsh_set32 (crypto->hsh_iv,1 ,bswap32 (b)); +octeon_hsh_set32 (crypto->hsh_iv,2 ,bswap32 (c)); +octeon_hsh_set32 (crypto->hsh_iv,3 ,bswap32 (d));... and
le32_to_cpu()here.Quoted 9 lines
target/mips/tcg/octeon_crypto.c +9
-0+} + +static void octeon_sha1_transform (MIPSOcteonCryptoState *crypto) +{ +uint32_t w[80 ]; +uint32_t a, b, c, d, e; +uint32_t orig[5 ]; +int i; +target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 269
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+for (i =0 ; i <16 ; i++) { + w[i] =octeon_hsh_get32 (crypto->hsh_dat, i); + } +for (i =16 ; i <80 ; i++) { + w[i] =rol32 (w[i -3 ] ^ w[i -8 ] ^ w[i -14 ] ^ w[i -16 ],1 ); + } + +for (i =0 ; i <5 ; i++) { + orig[i] =octeon_hsh_get32 (crypto->hsh_iv, i); + }SHA is big-endian so we are good, but watch out this CPU could switch endianness.
Quoted 1 line
Maybe safer to use
cpu_to_be32()andbe32_to_cpu()?
For SHA-1, SHA-256, and SHA-512, the manual pseudo-code feeds the HSH register words directly into the SHA operation and does not describe a similar byte-swap. So using cpu_to_be32()/be32_to_cpu() here would byte-swap based on host endianness, which is not the architectural HSH operation.
Quoted 54 lines
Quoted 33 lines
target/mips/tcg/octeon_crypto.c +33
-0+ a = orig[0 ]; + b = orig[1 ]; + c = orig[2 ]; + d = orig[3 ]; + e = orig[4 ]; + +for (i =0 ; i <80 ; i++) { +uint32_t f, k, temp; + +if (i <20 ) { + f = (b & c) | ((~b) & d); + k =0x5a827999 ; + }else if (i <40 ) { + f = b ^ c ^ d; + k =0x6ed9eba1 ; + }else if (i <60 ) { + f = (b & c) | (b & d) | (c & d); + k =0x8f1bbcdc ; + }else { + f = b ^ c ^ d; + k =0xca62c1d6 ; + } + + temp =rol32 (a,5 ) + f + e + k + w[i]; + e = d; + d = c; + c =rol32 (b,30 ); + b = a; + a = temp; + } + + orig[0 ] += a; + orig[1 ] += b;target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 312
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ orig[2 ] += c; + orig[3 ] += d; + orig[4 ] += e; +for (i =0 ; i <5 ; i++) { +octeon_hsh_set32 (crypto->hsh_iv, i, orig[i]); + } +} + +static void octeon_sha256_transform (MIPSOcteonCryptoState *crypto) +{(ditto)
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 397
Quoted 4 lines
target/mips/tcg/octeon_crypto.c +4
-0+} + +static void octeon_sha512_transform (MIPSOcteonCryptoState *crypto) +{(ditto)
Quoted 1 line
target/mips/tcg/octeon_crypto.c +1
-0+}
Re: [PATCH v16 12/21] target/mips: add Octeon HSH COP2 helpers
Quoted 132 lines · James Hilliard
Quoted 115 lines · Philippe Mathieu-Daudé
Hi James,
Quoted 111 lines · James Hilliard
Add helper support for the Octeon HSH hash selectors. This includes the base HSH data/IV windows, MD5, SHA1, SHA256, and SHA512 transform paths, and the shared HSH/SHA512 register-window readback and write operations.
The SHA512 path shares the wide HSH register bank with SHA3, SNOW3G, and ZUC. Keep the aliased readback and write paths centralized so selector decode can route register accesses through these helpers when side effects are required.
Signed-off-by James Hilliard <[email protected]>---
Changes v13 -> v14:
- Keep HSH narrow DAT/IV state updates in the low 32-bit halves of the architectural HSH register bank so paired selector transfers preserve the wide shared-window state.Changes v10 -> v13:
- Keep the0x0057SDK compatibility path as an explicit STARTSHA1 compatibility helper instead of a generic STARTSHA name.Changes v9 -> v10:
- Remove references to shared-mode tracking; aliased state is kept in the architectural HSH register banks.Changes v8 -> v9:
- Split HSH/SHA helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation HSH helpers.
- Keep shared-window readback and write helpers grouped with HSH.
- Add matchinghelper.hdeclarations with the helper implementation.--- target/mips/helper.h | 5 + target/mips/tcg/octeon_crypto.c | 375 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+)target/mips/helper.h +5
-0@@ -69,6 +69,11 @@ DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_round, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha1_compat, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_hsh_startsha512, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)target/mips/tcg/octeon_crypto.c +53
-0@@ -153,6 +153,348 @@ static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], out[1 ] =revbit64 (res); } +static inline uint32_t octeon_hsh_get32 (const uint64_t *regs, +unsigned int index) +{ +return regs[index]; +} + +static inline void octeon_hsh_set32 (uint64_t *regs,unsigned int index, +uint32_t value) +{ + regs[index] = (regs[index] & ~(uint64_t )UINT32_MAX ) | value; +} + +static inline void octeon_hsh_set_pair (uint64_t *regs,unsigned int index, +uint64_t value) +{ +octeon_hsh_set32 (regs, index *2 , value >>32 ); +octeon_hsh_set32 (regs, index *2 +1 , value); +} + +static void octeon_md5_transform (MIPSOcteonCryptoState *crypto) +{ +static const uint32_t k[64 ] = { +0xd76aa478U ,0xe8c7b756U ,0x242070dbU ,0xc1bdceeeU , +0xf57c0fafU ,0x4787c62aU ,0xa8304613U ,0xfd469501U , +0x698098d8U ,0x8b44f7afU ,0xffff5bb1U ,0x895cd7beU , +0x6b901122U ,0xfd987193U ,0xa679438eU ,0x49b40821U , +0xf61e2562U ,0xc040b340U ,0x265e5a51U ,0xe9b6c7aaU , +0xd62f105dU ,0x02441453U ,0xd8a1e681U ,0xe7d3fbc8U , +0x21e1cde6U ,0xc33707d6U ,0xf4d50d87U ,0x455a14edU , +0xa9e3e905U ,0xfcefa3f8U ,0x676f02d9U ,0x8d2a4c8aU , +0xfffa3942U ,0x8771f681U ,0x6d9d6122U ,0xfde5380cU , +0xa4beea44U ,0x4bdecfa9U ,0xf6bb4b60U ,0xbebfbc70U , +0x289b7ec6U ,0xeaa127faU ,0xd4ef3085U ,0x04881d05U , +0xd9d4d039U ,0xe6db99e5U ,0x1fa27cf8U ,0xc4ac5665U , +0xf4292244U ,0x432aff97U ,0xab9423a7U ,0xfc93a039U , +0x655b59c3U ,0x8f0ccc92U ,0xffeff47dU ,0x85845dd1U , +0x6fa87e4fU ,0xfe2ce6e0U ,0xa3014314U ,0x4e0811a1U , +0xf7537e82U ,0xbd3af235U ,0x2ad7d2bbU ,0xeb86d391U , + }; +static const uint8_t s[64 ] = { +7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 , +5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 , +4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 , +6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 , + }; +uint32_t m[16 ]; +uint32_t a, b, c, d; +uint32_t aa, bb, cc, dd; +int i; + +for (i =0 ; i <16 ; i++) { + m[i] =bswap32 (octeon_hsh_get32 (crypto->hsh_dat, i)); + }Quoted 8 lines
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 213
Quoted 5 lines
target/mips/tcg/octeon_crypto.c +5
-0+ + a =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,0 )); + b =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,1 )); + c =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,2 )); + d =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,3 ));The MD5 algorithm is little-endian, so I think for these we want
cpu_to_le32(), ...Looking at the CN71XX manual, I think the current handling matches the architectural HSH register view. The HSH DAT/IV narrow selectors build HASHDAT/HASHIV words from GPR halves, and the SHA-512 wide selectors move whole GPR values into HASHDAT/HASHIV. These are COP2 register values, not target-memory byte arrays.
Quoted 4 lines
The manual calls out MD5 specially: HASHDAT/HASHIV are in the big-endian HSH register-word order, while MD5 is little-endian, so the MD5 operation byte-swaps HASHDAT/HASHIV on entry and exit. That is what the current
bswap32()calls model.
This call works on little endian hosts, because the target CPU is only built for big-endian in user-mode. I don't expect your tests to pass on a big-endian host, because we don't want to swap in this case.
See in include/qemu/bswap.h:
60 * Endianness conversion functions between host cpu and specified
endianness.
63 * 64 * uint16_t le16_to_cpu(uint16_t v); 65 * uint32_t le32_to_cpu(uint32_t v); 66 * uint64_t le64_to_cpu(uint64_t v); 67 * uint16_t be16_to_cpu(uint16_t v); 68 * uint32_t be32_to_cpu(uint32_t v); 69 * uint64_t be64_to_cpu(uint64_t v); 70 * 71 * Convert the value @v from the specified format to the native 72 * endianness of the host CPU by byteswapping if necessary, and 73 * return the converted value. 74 * 75 * uint16_t cpu_to_le16(uint16_t v); 76 * uint32_t cpu_to_le32(uint32_t v); 77 * uint64_t cpu_to_le64(uint64_t v); 78 * uint16_t cpu_to_be16(uint16_t v); 79 * uint32_t cpu_to_be32(uint32_t v); 80 * uint64_t cpu_to_be64(uint64_t v); 81 * 82 * Convert the value @v from the native endianness of the host CPU 83 * to the specified format by byteswapping if necessary, and return 84 * the converted value.
Quoted 127 lines
Quoted 64 lines
Quoted 28 lines
target/mips/tcg/octeon_crypto.c +27
-0+ aa = a; + bb = b; + cc = c; + dd = d; + +for (i =0 ; i <64 ; i++) { +uint32_t f, g, tmp; + +if (i <16 ) { + f = (b & c) | ((~b) & d); + g = i; + }else if (i <32 ) { + f = (d & b) | ((~d) & c); + g = (5 * i +1 ) &0xf ; + }else if (i <48 ) { + f = b ^ c ^ d; + g = (3 * i +5 ) &0xf ; + }else { + f = c ^ (b | (~d)); + g = (7 * i) &0xf ; + } + + tmp = d; + d = c; + c = b; + b = b +rol32 (a + f + k[i] + m[g], s[i]); + a = tmp;target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 250
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ } + + a += aa; + b += bb; + c += cc; + d += dd; +octeon_hsh_set32 (crypto->hsh_iv,0 ,bswap32 (a)); +octeon_hsh_set32 (crypto->hsh_iv,1 ,bswap32 (b)); +octeon_hsh_set32 (crypto->hsh_iv,2 ,bswap32 (c)); +octeon_hsh_set32 (crypto->hsh_iv,3 ,bswap32 (d));... and
le32_to_cpu()here.Quoted 9 lines
target/mips/tcg/octeon_crypto.c +9
-0+} + +static void octeon_sha1_transform (MIPSOcteonCryptoState *crypto) +{ +uint32_t w[80 ]; +uint32_t a, b, c, d, e; +uint32_t orig[5 ]; +int i; +target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 269
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+for (i =0 ; i <16 ; i++) { + w[i] =octeon_hsh_get32 (crypto->hsh_dat, i); + } +for (i =16 ; i <80 ; i++) { + w[i] =rol32 (w[i -3 ] ^ w[i -8 ] ^ w[i -14 ] ^ w[i -16 ],1 ); + } + +for (i =0 ; i <5 ; i++) { + orig[i] =octeon_hsh_get32 (crypto->hsh_iv, i); + }SHA is big-endian so we are good, but watch out this CPU could switch endianness.
Quoted 1 line
Maybe safer to use
cpu_to_be32()andbe32_to_cpu()?For SHA-1, SHA-256, and SHA-512, the manual pseudo-code feeds the HSH register words directly into the SHA operation and does not describe a similar byte-swap. So using cpu_to_be32()/be32_to_cpu() here would byte-swap based on host endianness, which is not the architectural HSH operation.
Quoted 54 lines
Quoted 33 lines
target/mips/tcg/octeon_crypto.c +33
-0+ a = orig[0 ]; + b = orig[1 ]; + c = orig[2 ]; + d = orig[3 ]; + e = orig[4 ]; + +for (i =0 ; i <80 ; i++) { +uint32_t f, k, temp; + +if (i <20 ) { + f = (b & c) | ((~b) & d); + k =0x5a827999 ; + }else if (i <40 ) { + f = b ^ c ^ d; + k =0x6ed9eba1 ; + }else if (i <60 ) { + f = (b & c) | (b & d) | (c & d); + k =0x8f1bbcdc ; + }else { + f = b ^ c ^ d; + k =0xca62c1d6 ; + } + + temp =rol32 (a,5 ) + f + e + k + w[i]; + e = d; + d = c; + c =rol32 (b,30 ); + b = a; + a = temp; + } + + orig[0 ] += a; + orig[1 ] += b;target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 312
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ orig[2 ] += c; + orig[3 ] += d; + orig[4 ] += e; +for (i =0 ; i <5 ; i++) { +octeon_hsh_set32 (crypto->hsh_iv, i, orig[i]); + } +} + +static void octeon_sha256_transform (MIPSOcteonCryptoState *crypto) +{(ditto)
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 397
Quoted 4 lines
target/mips/tcg/octeon_crypto.c +4
-0+} + +static void octeon_sha512_transform (MIPSOcteonCryptoState *crypto) +{(ditto)
Quoted 1 line
target/mips/tcg/octeon_crypto.c +1
-0+}
Re: [PATCH v16 12/21] target/mips: add Octeon HSH COP2 helpers
Quoted 134 lines · Philippe Mathieu-Daudé
Quoted 132 lines · James Hilliard
Quoted 115 lines · Philippe Mathieu-Daudé
Hi James,
Quoted 111 lines · James Hilliard
Add helper support for the Octeon HSH hash selectors. This includes the base HSH data/IV windows, MD5, SHA1, SHA256, and SHA512 transform paths, and the shared HSH/SHA512 register-window readback and write operations.
The SHA512 path shares the wide HSH register bank with SHA3, SNOW3G, and ZUC. Keep the aliased readback and write paths centralized so selector decode can route register accesses through these helpers when side effects are required.
Signed-off-by James Hilliard <[email protected]>---
Changes v13 -> v14:
- Keep HSH narrow DAT/IV state updates in the low 32-bit halves of the architectural HSH register bank so paired selector transfers preserve the wide shared-window state.Changes v10 -> v13:
- Keep the0x0057SDK compatibility path as an explicit STARTSHA1 compatibility helper instead of a generic STARTSHA name.Changes v9 -> v10:
- Remove references to shared-mode tracking; aliased state is kept in the architectural HSH register banks.Changes v8 -> v9:
- Split HSH/SHA helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation HSH helpers.
- Keep shared-window readback and write helpers grouped with HSH.
- Add matchinghelper.hdeclarations with the helper implementation.--- target/mips/helper.h | 5 + target/mips/tcg/octeon_crypto.c | 375 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+)target/mips/helper.h +5
-0@@ -69,6 +69,11 @@ DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_round, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha1_compat, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_hsh_startsha512, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)target/mips/tcg/octeon_crypto.c +53
-0@@ -153,6 +153,348 @@ static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], out[1 ] =revbit64 (res); } +static inline uint32_t octeon_hsh_get32 (const uint64_t *regs, +unsigned int index) +{ +return regs[index]; +} + +static inline void octeon_hsh_set32 (uint64_t *regs,unsigned int index, +uint32_t value) +{ + regs[index] = (regs[index] & ~(uint64_t )UINT32_MAX ) | value; +} + +static inline void octeon_hsh_set_pair (uint64_t *regs,unsigned int index, +uint64_t value) +{ +octeon_hsh_set32 (regs, index *2 , value >>32 ); +octeon_hsh_set32 (regs, index *2 +1 , value); +} + +static void octeon_md5_transform (MIPSOcteonCryptoState *crypto) +{ +static const uint32_t k[64 ] = { +0xd76aa478U ,0xe8c7b756U ,0x242070dbU ,0xc1bdceeeU , +0xf57c0fafU ,0x4787c62aU ,0xa8304613U ,0xfd469501U , +0x698098d8U ,0x8b44f7afU ,0xffff5bb1U ,0x895cd7beU , +0x6b901122U ,0xfd987193U ,0xa679438eU ,0x49b40821U , +0xf61e2562U ,0xc040b340U ,0x265e5a51U ,0xe9b6c7aaU , +0xd62f105dU ,0x02441453U ,0xd8a1e681U ,0xe7d3fbc8U , +0x21e1cde6U ,0xc33707d6U ,0xf4d50d87U ,0x455a14edU , +0xa9e3e905U ,0xfcefa3f8U ,0x676f02d9U ,0x8d2a4c8aU , +0xfffa3942U ,0x8771f681U ,0x6d9d6122U ,0xfde5380cU , +0xa4beea44U ,0x4bdecfa9U ,0xf6bb4b60U ,0xbebfbc70U , +0x289b7ec6U ,0xeaa127faU ,0xd4ef3085U ,0x04881d05U , +0xd9d4d039U ,0xe6db99e5U ,0x1fa27cf8U ,0xc4ac5665U , +0xf4292244U ,0x432aff97U ,0xab9423a7U ,0xfc93a039U , +0x655b59c3U ,0x8f0ccc92U ,0xffeff47dU ,0x85845dd1U , +0x6fa87e4fU ,0xfe2ce6e0U ,0xa3014314U ,0x4e0811a1U , +0xf7537e82U ,0xbd3af235U ,0x2ad7d2bbU ,0xeb86d391U , + }; +static const uint8_t s[64 ] = { +7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 ,7 ,12 ,17 ,22 , +5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 ,5 ,9 ,14 ,20 , +4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 ,4 ,11 ,16 ,23 , +6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 ,6 ,10 ,15 ,21 , + }; +uint32_t m[16 ]; +uint32_t a, b, c, d; +uint32_t aa, bb, cc, dd; +int i; + +for (i =0 ; i <16 ; i++) { + m[i] =bswap32 (octeon_hsh_get32 (crypto->hsh_dat, i)); + }Quoted 8 lines
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 213
Quoted 5 lines
target/mips/tcg/octeon_crypto.c +5
-0+ + a =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,0 )); + b =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,1 )); + c =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,2 )); + d =bswap32 (octeon_hsh_get32 (crypto->hsh_iv,3 ));The MD5 algorithm is little-endian, so I think for these we want
cpu_to_le32(), ...Looking at the CN71XX manual, I think the current handling matches the architectural HSH register view. The HSH DAT/IV narrow selectors build HASHDAT/HASHIV words from GPR halves, and the SHA-512 wide selectors move whole GPR values into HASHDAT/HASHIV. These are COP2 register values, not target-memory byte arrays.
Quoted 8 lines
Quoted 4 lines
The manual calls out MD5 specially: HASHDAT/HASHIV are in the big-endian HSH register-word order, while MD5 is little-endian, so the MD5 operation byte-swaps HASHDAT/HASHIV on entry and exit. That is what the current
bswap32()calls model.This call works on little endian hosts, because the target CPU is only built for big-endian in user-mode. I don't expect your tests to pass on a big-endian host, because we don't want to swap in this case.
I agree those helpers are host-endian conversions, but that is why I don't think they apply here.
The HSH state is modeled as architectural COP2 register values, not as a host byte array. The narrow HSH DAT/IV selectors split GPR[rt] into HASHDAT/HASHIV low-32 register words, and the translator already handles host layout when placing those low 32 bits in the uint64_t state. After that, octeon_hsh_get32() is reading an architectural register word.
For MD5, the CN71XX manual describes a byte swap between the HSH big-endian register-word view and MD5's little-endian word order. That swap is part of the Octeon operation, so it must be unconditional with respect to the QEMU host. Using cpu_to_le32() would make it host-dependent:
identity on little-endian hosts and swapped on big-endian hosts.
Likewise, the SHA paths consume the HSH register words directly in the manual pseudo-code, with no analogous MD5 byte-swap step. Using cpu_to_be32()/be32_to_cpu() there would also introduce host-dependent behavior that the modeled hardware operation does not have.
Quoted 155 lines
See in
include/qemu/bswap.h:60 * Endianness conversion functions between host cpu and specified
endianness.63 * 64 * uint16_t le16_to_cpu(uint16_t v); 65 * uint32_t le32_to_cpu(uint32_t v); 66 * uint64_t le64_to_cpu(uint64_t v); 67 * uint16_t be16_to_cpu(uint16_t v); 68 * uint32_t be32_to_cpu(uint32_t v); 69 * uint64_t be64_to_cpu(uint64_t v); 70 * 71 * Convert the value @v from the specified format to the native 72 * endianness of the host CPU by byteswapping if necessary, and 73 * return the converted value. 74 * 75 * uint16_t cpu_to_le16(uint16_t v); 76 * uint32_t cpu_to_le32(uint32_t v); 77 * uint64_t cpu_to_le64(uint64_t v); 78 * uint16_t cpu_to_be16(uint16_t v); 79 * uint32_t cpu_to_be32(uint32_t v); 80 * uint64_t cpu_to_be64(uint64_t v); 81 * 82 * Convert the value @v from the native endianness of the host CPU 83 * to the specified format by byteswapping if necessary, and return 84 * the converted value.Quoted 127 lines
Quoted 64 lines
Quoted 28 lines
target/mips/tcg/octeon_crypto.c +27
-0+ aa = a; + bb = b; + cc = c; + dd = d; + +for (i =0 ; i <64 ; i++) { +uint32_t f, g, tmp; + +if (i <16 ) { + f = (b & c) | ((~b) & d); + g = i; + }else if (i <32 ) { + f = (d & b) | ((~d) & c); + g = (5 * i +1 ) &0xf ; + }else if (i <48 ) { + f = b ^ c ^ d; + g = (3 * i +5 ) &0xf ; + }else { + f = c ^ (b | (~d)); + g = (7 * i) &0xf ; + } + + tmp = d; + d = c; + c = b; + b = b +rol32 (a + f + k[i] + m[g], s[i]); + a = tmp;target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 250
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ } + + a += aa; + b += bb; + c += cc; + d += dd; +octeon_hsh_set32 (crypto->hsh_iv,0 ,bswap32 (a)); +octeon_hsh_set32 (crypto->hsh_iv,1 ,bswap32 (b)); +octeon_hsh_set32 (crypto->hsh_iv,2 ,bswap32 (c)); +octeon_hsh_set32 (crypto->hsh_iv,3 ,bswap32 (d));... and
le32_to_cpu()here.Quoted 9 lines
target/mips/tcg/octeon_crypto.c +9
-0+} + +static void octeon_sha1_transform (MIPSOcteonCryptoState *crypto) +{ +uint32_t w[80 ]; +uint32_t a, b, c, d, e; +uint32_t orig[5 ]; +int i; +target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 269
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+for (i =0 ; i <16 ; i++) { + w[i] =octeon_hsh_get32 (crypto->hsh_dat, i); + } +for (i =16 ; i <80 ; i++) { + w[i] =rol32 (w[i -3 ] ^ w[i -8 ] ^ w[i -14 ] ^ w[i -16 ],1 ); + } + +for (i =0 ; i <5 ; i++) { + orig[i] =octeon_hsh_get32 (crypto->hsh_iv, i); + }SHA is big-endian so we are good, but watch out this CPU could switch endianness.
Quoted 1 line
Maybe safer to use
cpu_to_be32()andbe32_to_cpu()?For SHA-1, SHA-256, and SHA-512, the manual pseudo-code feeds the HSH register words directly into the SHA operation and does not describe a similar byte-swap. So using cpu_to_be32()/be32_to_cpu() here would byte-swap based on host endianness, which is not the architectural HSH operation.
Quoted 54 lines
Quoted 33 lines
target/mips/tcg/octeon_crypto.c +33
-0+ a = orig[0 ]; + b = orig[1 ]; + c = orig[2 ]; + d = orig[3 ]; + e = orig[4 ]; + +for (i =0 ; i <80 ; i++) { +uint32_t f, k, temp; + +if (i <20 ) { + f = (b & c) | ((~b) & d); + k =0x5a827999 ; + }else if (i <40 ) { + f = b ^ c ^ d; + k =0x6ed9eba1 ; + }else if (i <60 ) { + f = (b & c) | (b & d) | (c & d); + k =0x8f1bbcdc ; + }else { + f = b ^ c ^ d; + k =0xca62c1d6 ; + } + + temp =rol32 (a,5 ) + f + e + k + w[i]; + e = d; + d = c; + c =rol32 (b,30 ); + b = a; + a = temp; + } + + orig[0 ] += a; + orig[1 ] += b;target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 312
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ orig[2 ] += c; + orig[3 ] += d; + orig[4 ] += e; +for (i =0 ; i <5 ; i++) { +octeon_hsh_set32 (crypto->hsh_iv, i, orig[i]); + } +} + +static void octeon_sha256_transform (MIPSOcteonCryptoState *crypto) +{(ditto)
target/mips/tcg/octeon_crypto.c static void octeon_gfm_mul64_uia2(const uint64_t x[2], const uint64_t y[2], · line 397
Quoted 4 lines
target/mips/tcg/octeon_crypto.c +4
-0+} + +static void octeon_sha512_transform (MIPSOcteonCryptoState *crypto) +{(ditto)
Quoted 1 line
target/mips/tcg/octeon_crypto.c +1
-0+}
PATCH v16 13/21 target/mips: add Octeon CHORD and LLM COP2 helpers
In reply to James HilliardAdd the Octeon CHORD hardware register access path and the LLM 36-bit and 64-bit read and write windows. Model both CHORD access forms, including the RDHWR $30 path and the legacy DMFC2 alias.
Implement sparse backing storage for the two LLM sets so user-mode code can save, restore, and probe the architectural state without allocating a full hardware-sized backing array.
---
Changes v10 -> v13:
- Keep this patch limited to CHORD/LLM additions; existing crypto helpers and state fields stay in their original commit order.
Changes v8 -> v9:
- Split CHORD and LLM helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation LLM helpers.
- Add matching helper.h declarations with the helper implementation.
Changes v5 -> v6:
- Rename sparse LLM backing fields from llm_narrow/llm_wide to llm36/llm64 to match the 36-bit and 64-bit selector windows.
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 | 5 +++ target/mips/helper.h | 9 +++++ target/mips/internal.h | 3 ++ target/mips/system/machine.c | 67 ++++++++++++++++++++++++++++++++++++ target/mips/tcg/octeon_crypto.c | 76 +++++++++++++++++++++++++++++++++++++++++ target/mips/tcg/op_helper.c | 6 ++++ target/mips/tcg/translate.c | 8 +++++ 8 files changed, 241 insertions(+)
target/mips/cpu.c +67 -0
@@ -26,6 +26,7 @@#include "cpu.h" #include "internal.h" #include "qemu/module.h" +#include "qemu/qtree.h" #include "system/qtest.h" #include "hw/core/qdev-properties.h" #include "hw/core/qdev-clock.h"
@@ -181,6 +182,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->llm36) { +q_tree_destroy (crypto->llm36); + crypto->llm36 =NULL ; + } +if (crypto->llm64) { +q_tree_destroy (crypto->llm64); + crypto->llm64 =NULL ; + } +} +static void mips_cpu_reset_hold (Object *obj,ResetType type) {CPUState *cs =CPU (obj);
@@ -192,6 +244,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 */
@@ -246,6 +299,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);
@@ -262,6 +318,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); }
@@ -417,6 +476,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);
@@ -645,6 +711,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 +5 -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 ;
@@ -559,6 +560,10 @@ typedef struct MIPSOcteonCryptoState {uint16_t gfm_poly;uint8_t aes_keylen;uint8_t crc_len; +uint64_t chord; +uint64_t llm_data[2 ]; +QTree *llm36; +QTree *llm64; } MIPSOcteonCryptoState; typedef struct CPUArchState {
target/mips/helper.h +9 -0
@@ -74,6 +74,14 @@ DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_hsh_startsha512, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_write_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read64_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_write64_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read_addr1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_write_addr1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read64_addr1, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_llm_write64_addr1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
@@ -245,6 +253,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 +76 -0
85 lines not on this page · raw message
target/mips/tcg/op_helper.c +6 -0
@@ -255,6 +255,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
@@ -10925,6 +10925,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 v16 14/21 target/mips: decode Octeon COP2 register selectors
In reply to James HilliardAdd explicit decodetree entries and translator bindings for Octeon DMFC2/DMTC2 selectors that are simple COP2 register transfers.
Emit direct TCG loads and stores for register moves. Use signed 32-bit loads for 32-bit DMFC2 readback and mask narrow writable fields such as AESKEYLEN and CRCLEN on DMTC2.
Keep operation selectors with side effects in later functional decode patches.
---
Changes v13 -> v14:
- Add missing HSH DAT readback selectors.
- Implement HSH DAT/IV selector transfers as paired low-32 architectural word moves using tcg_gen_concat32_i64().
- Move the CP2_Undef fallback into this selector patch.
- Remove the redundant AES RESINP translator path.
- Add HSH DAT readback smoke coverage.
Changes v10 -> v13:
- Keep simple register moves in their own selector patch.
- Use final KAS result naming and final CRC register selector names.
- Mask AESKEYLEN and CRCLEN direct writes.
--- target/mips/tcg/octeon.decode | 80 ++++++++++ target/mips/tcg/octeon_translate.c | 210 ++++++++++++++++++++++++++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 89 +++++++++++ 3 files changed, 379 insertions(+)
target/mips/tcg/octeon.decode +80 -0
@@ -97,3 +97,83 @@ LBUX 011111 ..... ..... ..... 00110 001010 @lx LWUX 011111 ..... ..... ..... 10000 001010 @lx LBX 011111 ..... ..... ..... 10110 001010 @lx LDX 011111 ..... ..... ..... 01000 001010 @lx + +# Selector-driven DMFC2/DMTC2 interfaces for Octeon COP2 engines. +&cp2 rt +{ + [ + CVM_MF_HSH_IV0 010010 00001 rt:5 0000 0000 0100 1000 &cp2 + CVM_MF_HSH_IV1 010010 00001 rt:5 0000 0000 0100 1001 &cp2 + CVM_MF_HSH_IV2 010010 00001 rt:5 0000 0000 0100 1010 &cp2 + CVM_MF_HSH_IV3 010010 00001 rt:5 0000 0000 0100 1011 &cp2 + CVM_MF_HSH_DAT0 010010 00001 rt:5 0000 0000 0100 0000 &cp2 + CVM_MF_HSH_DAT1 010010 00001 rt:5 0000 0000 0100 0001 &cp2 + CVM_MF_HSH_DAT2 010010 00001 rt:5 0000 0000 0100 0010 &cp2 + CVM_MF_HSH_DAT3 010010 00001 rt:5 0000 0000 0100 0011 &cp2 + CVM_MF_HSH_DAT4 010010 00001 rt:5 0000 0000 0100 0100 &cp2 + CVM_MF_HSH_DAT5 010010 00001 rt:5 0000 0000 0100 0101 &cp2 + CVM_MF_HSH_DAT6 010010 00001 rt:5 0000 0000 0100 0110 &cp2 + CVM_MF_3DES_KEY0 010010 00001 rt:5 0000 0000 1000 0000 &cp2 + CVM_MF_3DES_KEY1 010010 00001 rt:5 0000 0000 1000 0001 &cp2 + CVM_MF_3DES_KEY2 010010 00001 rt:5 0000 0000 1000 0010 &cp2 + CVM_MF_3DES_IV 010010 00001 rt:5 0000 0000 1000 0100 &cp2 + CVM_MF_3DES_RESULT 010010 00001 rt:5 0000 0000 1000 1000 &cp2 + CVM_MF_KAS_RESULT 010010 00001 rt:5 0000 0000 1001 1000 &cp2 + CVM_MF_AES_RESINP0 010010 00001 rt:5 0000 0001 0000 0000 &cp2 + CVM_MF_AES_RESINP1 010010 00001 rt:5 0000 0001 0000 0001 &cp2 + CVM_MF_AES_IV0 010010 00001 rt:5 0000 0001 0000 0010 &cp2 + CVM_MF_AES_IV1 010010 00001 rt:5 0000 0001 0000 0011 &cp2 + CVM_MF_AES_KEY0 010010 00001 rt:5 0000 0001 0000 0100 &cp2 + CVM_MF_AES_KEY1 010010 00001 rt:5 0000 0001 0000 0101 &cp2 + CVM_MF_AES_KEY2 010010 00001 rt:5 0000 0001 0000 0110 &cp2 + CVM_MF_AES_KEY3 010010 00001 rt:5 0000 0001 0000 0111 &cp2 + CVM_MF_AES_KEYLENGTH 010010 00001 rt:5 0000 0001 0001 0000 &cp2 + CVM_MF_AES_INP0 010010 00001 rt:5 0000 0001 0001 0001 &cp2 + CVM_MF_CRC_POLYNOMIAL 010010 00001 rt:5 0000 0010 0000 0000 &cp2 + CVM_MF_CRC_IV 010010 00001 rt:5 0000 0010 0000 0001 &cp2 + CVM_MF_CRC_LEN 010010 00001 rt:5 0000 0010 0000 0010 &cp2 + CVM_MF_GFM_MUL0 010010 00001 rt:5 0000 0010 0101 1000 &cp2 + CVM_MF_GFM_MUL1 010010 00001 rt:5 0000 0010 0101 1001 &cp2 + CVM_MF_GFM_RESINP0 010010 00001 rt:5 0000 0010 0101 1010 &cp2 + CVM_MF_GFM_RESINP1 010010 00001 rt:5 0000 0010 0101 1011 &cp2 + CVM_MF_GFM_POLY 010010 00001 rt:5 0000 0010 0101 1110 &cp2 + CVM_MT_HSH_DAT0 010010 00101 rt:5 0000 0000 0100 0000 &cp2 + CVM_MT_HSH_DAT1 010010 00101 rt:5 0000 0000 0100 0001 &cp2 + CVM_MT_HSH_DAT2 010010 00101 rt:5 0000 0000 0100 0010 &cp2 + CVM_MT_HSH_DAT3 010010 00101 rt:5 0000 0000 0100 0011 &cp2 + CVM_MT_HSH_DAT4 010010 00101 rt:5 0000 0000 0100 0100 &cp2 + CVM_MT_HSH_DAT5 010010 00101 rt:5 0000 0000 0100 0101 &cp2 + CVM_MT_HSH_DAT6 010010 00101 rt:5 0000 0000 0100 0110 &cp2 + CVM_MT_HSH_IV0 010010 00101 rt:5 0000 0000 0100 1000 &cp2 + CVM_MT_HSH_IV1 010010 00101 rt:5 0000 0000 0100 1001 &cp2 + CVM_MT_HSH_IV2 010010 00101 rt:5 0000 0000 0100 1010 &cp2 + CVM_MT_HSH_IV3 010010 00101 rt:5 0000 0000 0100 1011 &cp2 + CVM_MT_3DES_KEY0 010010 00101 rt:5 0000 0000 1000 0000 &cp2 + CVM_MT_3DES_KEY1 010010 00101 rt:5 0000 0000 1000 0001 &cp2 + CVM_MT_3DES_KEY2 010010 00101 rt:5 0000 0000 1000 0010 &cp2 + CVM_MT_3DES_IV 010010 00101 rt:5 0000 0000 1000 0100 &cp2 + CVM_MT_3DES_RESULT 010010 00101 rt:5 0000 0000 1001 1000 &cp2 + CVM_MT_AES_RESINP0 010010 00101 rt:5 0000 0001 0000 0000 &cp2 + CVM_MT_AES_RESINP1 010010 00101 rt:5 0000 0001 0000 0001 &cp2 + CVM_MT_AES_IV0 010010 00101 rt:5 0000 0001 0000 0010 &cp2 + CVM_MT_AES_IV1 010010 00101 rt:5 0000 0001 0000 0011 &cp2 + CVM_MT_AES_KEY0 010010 00101 rt:5 0000 0001 0000 0100 &cp2 + CVM_MT_AES_KEY1 010010 00101 rt:5 0000 0001 0000 0101 &cp2 + CVM_MT_AES_KEY2 010010 00101 rt:5 0000 0001 0000 0110 &cp2 + CVM_MT_AES_KEY3 010010 00101 rt:5 0000 0001 0000 0111 &cp2 + CVM_MT_AES_ENC_CBC0 010010 00101 rt:5 0000 0001 0000 1000 &cp2 + CVM_MT_AES_ENC0 010010 00101 rt:5 0000 0001 0000 1010 &cp2 + CVM_MT_AES_DEC_CBC0 010010 00101 rt:5 0000 0001 0000 1100 &cp2 + CVM_MT_AES_DEC0 010010 00101 rt:5 0000 0001 0000 1110 &cp2 + CVM_MT_AES_KEYLENGTH 010010 00101 rt:5 0000 0001 0001 0000 &cp2 + CVM_MT_CRC_IV 010010 00101 rt:5 0000 0010 0000 0001 &cp2 + CVM_MT_GFM_MUL0 010010 00101 rt:5 0000 0010 0101 1000 &cp2 + CVM_MT_GFM_MUL1 010010 00101 rt:5 0000 0010 0101 1001 &cp2 + CVM_MT_GFM_RESINP0 010010 00101 rt:5 0000 0010 0101 1010 &cp2 + CVM_MT_GFM_RESINP1 010010 00101 rt:5 0000 0010 0101 1011 &cp2 + CVM_MT_GFM_POLY 010010 00101 rt:5 0000 0010 0101 1110 &cp2 + CVM_MT_CRC_LEN 010010 00101 rt:5 0001 0010 0000 0010 &cp2 + CVM_MT_CRC_POLYNOMIAL 010010 00101 rt:5 0100 0010 0000 0000 &cp2 + ] + CP2_Undef 010010 ----- ----- ---- ---- ---- ---- +}
target/mips/tcg/octeon_translate.c +210 -0
216 lines not on this page · raw message
tests/tcg/mips/user/isa/octeon/octeon-insns.c +89 -0
101 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 15/21 target/mips: decode Octeon CRC and GFM COP2 selectors
In reply to James HilliardAdd explicit decodetree entries and translator bindings for the Octeon CRC and GFM COP2 operation selectors. Unlike simple register moves, these selectors update CRC or Galois-field state and therefore remain per-operation helper calls.
Keep CRC/GFM decode next to the helpers that implement these side effects while avoiding a monolithic selector-dispatch helper.
---
Changes v10 -> v13:
- Split simple register-transfer selectors into a separate COP2 register selector patch.
- Use final CRC selector names in this patch instead of renaming them later in the series.
- Route reflected GFM selectors through helpers immediately so no non-architectural reflected GFM state is introduced.
- Add the reflected CRC polynomial helper with the selector decode that uses it.
--- target/mips/helper.h | 1 + target/mips/tcg/octeon.decode | 22 +++++++++ target/mips/tcg/octeon_crypto.c | 7 +++ target/mips/tcg/octeon_translate.c | 50 +++++++++++++++++++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 70 +++++++++++++++++++++++++++ 5 files changed, 150 insertions(+)
target/mips/helper.h +1 -0
@@ -32,6 +32,7 @@ DEF_HELPER_1(octeon_cp2_mf_gfm_mul_reflect1, i64, env) DEF_HELPER_1(octeon_cp2_mf_gfm_resinp_reflect0, i64, env) DEF_HELPER_1(octeon_cp2_mf_gfm_resinp_reflect1, i64, env) DEF_HELPER_2(octeon_cp2_mt_crc_write_iv_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_polynomial_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_byte, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_half, void, env, i64)DEF_HELPER_2 (octeon_cp2_mt_crc_write_word, void, env, i64)
target/mips/tcg/octeon.decode +22 -0
@@ -132,6 +132,11 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MF_CRC_POLYNOMIAL 010010 00001 rt:5 0000 0010 0000 0000 &cp2 CVM_MF_CRC_IV 010010 00001 rt:5 0000 0010 0000 0001 &cp2 CVM_MF_CRC_LEN 010010 00001 rt:5 0000 0010 0000 0010 &cp2 + CVM_MF_CRC_IV_REFLECT 010010 00001 rt:5 0000 0010 0000 0011 &cp2 + CVM_MF_GFM_MUL_REFLECT0 010010 00001 rt:5 0000 0000 0101 1000 &cp2 + CVM_MF_GFM_MUL_REFLECT1 010010 00001 rt:5 0000 0000 0101 1001 &cp2 + CVM_MF_GFM_RESINP_REFLECT0 010010 00001 rt:5 0000 0000 0101 1010 &cp2 + CVM_MF_GFM_RESINP_REFLECT1 010010 00001 rt:5 0000 0000 0101 1011 &cp2 CVM_MF_GFM_MUL0 010010 00001 rt:5 0000 0010 0101 1000 &cp2 CVM_MF_GFM_MUL1 010010 00001 rt:5 0000 0010 0101 1001 &cp2 CVM_MF_GFM_RESINP0 010010 00001 rt:5 0000 0010 0101 1010 &cp2
@@ -148,6 +153,9 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_HSH_IV1 010010 00101 rt:5 0000 0000 0100 1001 &cp2 CVM_MT_HSH_IV2 010010 00101 rt:5 0000 0000 0100 1010 &cp2 CVM_MT_HSH_IV3 010010 00101 rt:5 0000 0000 0100 1011 &cp2 + CVM_MT_GFM_MUL_REFLECT0 010010 00101 rt:5 0000 0000 0101 1000 &cp2 + CVM_MT_GFM_MUL_REFLECT1 010010 00101 rt:5 0000 0000 0101 1001 &cp2 + CVM_MT_GFM_XOR0_REFLECT 010010 00101 rt:5 0000 0000 0101 1100 &cp2 CVM_MT_3DES_KEY0 010010 00101 rt:5 0000 0000 1000 0000 &cp2 CVM_MT_3DES_KEY1 010010 00101 rt:5 0000 0000 1000 0001 &cp2 CVM_MT_3DES_KEY2 010010 00101 rt:5 0000 0000 1000 0010 &cp2
@@ -167,13 +175,27 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_AES_DEC0 010010 00101 rt:5 0000 0001 0000 1110 &cp2 CVM_MT_AES_KEYLENGTH 010010 00101 rt:5 0000 0001 0001 0000 &cp2 CVM_MT_CRC_IV 010010 00101 rt:5 0000 0010 0000 0001 &cp2 + CVM_MT_CRC_IV_REFLECT 010010 00101 rt:5 0000 0010 0001 0001 &cp2 + CVM_MT_CRC_BYTE 010010 00101 rt:5 0000 0010 0000 0100 &cp2 + CVM_MT_CRC_HALF 010010 00101 rt:5 0000 0010 0000 0101 &cp2 + CVM_MT_CRC_WORD 010010 00101 rt:5 0000 0010 0000 0110 &cp2 + CVM_MT_CRC_BYTE_REFLECT 010010 00101 rt:5 0000 0010 0001 0100 &cp2 + CVM_MT_CRC_HALF_REFLECT 010010 00101 rt:5 0000 0010 0001 0101 &cp2 + CVM_MT_CRC_WORD_REFLECT 010010 00101 rt:5 0000 0010 0001 0110 &cp2 CVM_MT_GFM_MUL0 010010 00101 rt:5 0000 0010 0101 1000 &cp2 CVM_MT_GFM_MUL1 010010 00101 rt:5 0000 0010 0101 1001 &cp2 CVM_MT_GFM_RESINP0 010010 00101 rt:5 0000 0010 0101 1010 &cp2 CVM_MT_GFM_RESINP1 010010 00101 rt:5 0000 0010 0101 1011 &cp2 CVM_MT_GFM_POLY 010010 00101 rt:5 0000 0010 0101 1110 &cp2 CVM_MT_CRC_LEN 010010 00101 rt:5 0001 0010 0000 0010 &cp2 + CVM_MT_CRC_DWORD 010010 00101 rt:5 0001 0010 0000 0111 &cp2 + CVM_MT_CRC_VAR 010010 00101 rt:5 0001 0010 0000 1000 &cp2 + CVM_MT_CRC_DWORD_REFLECT 010010 00101 rt:5 0001 0010 0001 0111 &cp2 + CVM_MT_CRC_VAR_REFLECT 010010 00101 rt:5 0001 0010 0001 1000 &cp2 + CVM_MT_GFM_XORMUL1_REFLECT 010010 00101 rt:5 0100 0000 0101 1101 &cp2 CVM_MT_CRC_POLYNOMIAL 010010 00101 rt:5 0100 0010 0000 0000 &cp2 + CVM_MT_CRC_POLYNOMIAL_REFLECT 010010 00101 rt:5 0100 0010 0001 0000 &cp2 + CVM_MT_GFM_XORMUL1 010010 00101 rt:5 0100 0010 0101 1101 &cp2 ] CP2_Undef 010010 ----- ----- ---- ---- ---- ---- }
target/mips/tcg/octeon_crypto.c +7 -0
@@ -2207,6 +2207,13 @@ void helper_octeon_cp2_mt_crc_write_iv_reflect(CPUMIPSState *env,octeon_crc_reflect32_by_byte ((uint32_t )value); } +void helper_octeon_cp2_mt_crc_write_polynomial_reflect (CPUMIPSState *env, +uint64_t value) +{ + env->octeon_crypto.crc_poly = +octeon_crc_reflect32_by_byte ((uint32_t )value); +} +void helper_octeon_cp2_mt_crc_write_byte (CPUMIPSState *env,uint64_t value) {octeon_crc_update_normal (&env->octeon_crypto, value,1 );
target/mips/tcg/octeon_translate.c +50 -0
92 lines not on this page · raw message
tests/tcg/mips/user/isa/octeon/octeon-insns.c +70 -0
82 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 16/21 target/mips: decode Octeon HSH and SHA3 COP2 selectors
In reply to James HilliardAdd explicit decodetree entries and translator bindings for the Octeon HSH shared-window selectors and SHA3 operation selectors. Simple SHA3 DAT register moves and XORDAT selectors use direct TCG transfers, while HSH operation selectors and SHA3 STARTOP remain helper-backed for their visible side effects.
Keep HSH/SHA3 decode separate from direct register transfers because the shared hash-window aliases and side-effecting operations need their own selector coverage.
---
Changes v14 -> v15:
- Use direct TCG moves for SHA3 DAT24 and DAT15 selectors.
- Use direct TCG XORs for SHA3 XORDAT selectors.
- Switch SHA3 STARTOP to an env-only helper call.
- Add Richard Henderson's Reviewed-by tag.
Changes v10 -> v13:
- Keep this patch limited to HSH/SHA3 selector additions; CRC/GFM selector finalization stays in the CRC/GFM selector patch.
- Name the 0x0057 SDK compatibility selector as STARTSHA1_COMPAT and document why it is kept despite not appearing in the public manuals.
Changes v9 -> v10:
- Split HSH/SHA3 selector decode out of the monolithic Octeon COP2 selector decode patch.
- Reworked the shared HSH/SHA3 register-window transfers around the architectural hash state instead of DATW/IVW shadow state.
--- target/mips/tcg/octeon.decode | 77 ++++++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 102 +++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+)
target/mips/tcg/octeon.decode +77 -0
@@ -113,6 +113,7 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MF_HSH_DAT4 010010 00001 rt:5 0000 0000 0100 0100 &cp2 CVM_MF_HSH_DAT5 010010 00001 rt:5 0000 0000 0100 0101 &cp2 CVM_MF_HSH_DAT6 010010 00001 rt:5 0000 0000 0100 0110 &cp2 + CVM_MF_SHA3_DAT24 010010 00001 rt:5 0000 0000 0101 0000 &cp2 CVM_MF_3DES_KEY0 010010 00001 rt:5 0000 0000 1000 0000 &cp2 CVM_MF_3DES_KEY1 010010 00001 rt:5 0000 0000 1000 0001 &cp2 CVM_MF_3DES_KEY2 010010 00001 rt:5 0000 0000 1000 0010 &cp2
@@ -137,6 +138,30 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MF_GFM_MUL_REFLECT1 010010 00001 rt:5 0000 0000 0101 1001 &cp2 CVM_MF_GFM_RESINP_REFLECT0 010010 00001 rt:5 0000 0000 0101 1010 &cp2 CVM_MF_GFM_RESINP_REFLECT1 010010 00001 rt:5 0000 0000 0101 1011 &cp2 + CVM_MF_HSH_DATW0 010010 00001 rt:5 0000 0010 0100 0000 &cp2 + CVM_MF_HSH_DATW1 010010 00001 rt:5 0000 0010 0100 0001 &cp2 + CVM_MF_HSH_DATW2 010010 00001 rt:5 0000 0010 0100 0010 &cp2 + CVM_MF_HSH_DATW3 010010 00001 rt:5 0000 0010 0100 0011 &cp2 + CVM_MF_HSH_DATW4 010010 00001 rt:5 0000 0010 0100 0100 &cp2 + CVM_MF_HSH_DATW5 010010 00001 rt:5 0000 0010 0100 0101 &cp2 + CVM_MF_HSH_DATW6 010010 00001 rt:5 0000 0010 0100 0110 &cp2 + CVM_MF_HSH_DATW7 010010 00001 rt:5 0000 0010 0100 0111 &cp2 + CVM_MF_HSH_DATW8 010010 00001 rt:5 0000 0010 0100 1000 &cp2 + CVM_MF_HSH_DATW9 010010 00001 rt:5 0000 0010 0100 1001 &cp2 + CVM_MF_HSH_DATW10 010010 00001 rt:5 0000 0010 0100 1010 &cp2 + CVM_MF_HSH_DATW11 010010 00001 rt:5 0000 0010 0100 1011 &cp2 + CVM_MF_HSH_DATW12 010010 00001 rt:5 0000 0010 0100 1100 &cp2 + CVM_MF_HSH_DATW13 010010 00001 rt:5 0000 0010 0100 1101 &cp2 + CVM_MF_HSH_DATW14 010010 00001 rt:5 0000 0010 0100 1110 &cp2 + CVM_MF_HSH_DATW15 010010 00001 rt:5 0000 0010 0100 1111 &cp2 + CVM_MF_HSH_IVW0 010010 00001 rt:5 0000 0010 0101 0000 &cp2 + CVM_MF_HSH_IVW1 010010 00001 rt:5 0000 0010 0101 0001 &cp2 + CVM_MF_HSH_IVW2 010010 00001 rt:5 0000 0010 0101 0010 &cp2 + CVM_MF_HSH_IVW3 010010 00001 rt:5 0000 0010 0101 0011 &cp2 + CVM_MF_HSH_IVW4 010010 00001 rt:5 0000 0010 0101 0100 &cp2 + CVM_MF_HSH_IVW5 010010 00001 rt:5 0000 0010 0101 0101 &cp2 + CVM_MF_HSH_IVW6 010010 00001 rt:5 0000 0010 0101 0110 &cp2 + CVM_MF_HSH_IVW7 010010 00001 rt:5 0000 0010 0101 0111 &cp2 CVM_MF_GFM_MUL0 010010 00001 rt:5 0000 0010 0101 1000 &cp2 CVM_MF_GFM_MUL1 010010 00001 rt:5 0000 0010 0101 1001 &cp2 CVM_MF_GFM_RESINP0 010010 00001 rt:5 0000 0010 0101 1010 &cp2
@@ -153,6 +178,10 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_HSH_IV1 010010 00101 rt:5 0000 0000 0100 1001 &cp2 CVM_MT_HSH_IV2 010010 00101 rt:5 0000 0000 0100 1010 &cp2 CVM_MT_HSH_IV3 010010 00101 rt:5 0000 0000 0100 1011 &cp2 + CVM_MT_SHA3_DAT24 010010 00101 rt:5 0000 0000 0101 0000 &cp2 + CVM_MT_SHA3_DAT15 010010 00101 rt:5 0000 0000 0101 0001 &cp2 + # Cavium SDK code uses 0x0057 as a STARTSHA1 compatibility alias. + CVM_MT_HSH_STARTSHA1_COMPAT 010010 00101 rt:5 0000 0000 0101 0111 &cp2 CVM_MT_GFM_MUL_REFLECT0 010010 00101 rt:5 0000 0000 0101 1000 &cp2 CVM_MT_GFM_MUL_REFLECT1 010010 00101 rt:5 0000 0000 0101 1001 &cp2 CVM_MT_GFM_XOR0_REFLECT 010010 00101 rt:5 0000 0000 0101 1100 &cp2
@@ -182,19 +211,67 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_CRC_BYTE_REFLECT 010010 00101 rt:5 0000 0010 0001 0100 &cp2 CVM_MT_CRC_HALF_REFLECT 010010 00101 rt:5 0000 0010 0001 0101 &cp2 CVM_MT_CRC_WORD_REFLECT 010010 00101 rt:5 0000 0010 0001 0110 &cp2 + CVM_MT_HSH_DATW0 010010 00101 rt:5 0000 0010 0100 0000 &cp2 + CVM_MT_HSH_DATW1 010010 00101 rt:5 0000 0010 0100 0001 &cp2 + CVM_MT_HSH_DATW2 010010 00101 rt:5 0000 0010 0100 0010 &cp2 + CVM_MT_HSH_DATW3 010010 00101 rt:5 0000 0010 0100 0011 &cp2 + CVM_MT_HSH_DATW4 010010 00101 rt:5 0000 0010 0100 0100 &cp2 + CVM_MT_HSH_DATW5 010010 00101 rt:5 0000 0010 0100 0101 &cp2 + CVM_MT_HSH_DATW6 010010 00101 rt:5 0000 0010 0100 0110 &cp2 + CVM_MT_HSH_DATW7 010010 00101 rt:5 0000 0010 0100 0111 &cp2 + CVM_MT_HSH_DATW8 010010 00101 rt:5 0000 0010 0100 1000 &cp2 + CVM_MT_HSH_DATW9 010010 00101 rt:5 0000 0010 0100 1001 &cp2 + CVM_MT_HSH_DATW10 010010 00101 rt:5 0000 0010 0100 1010 &cp2 + CVM_MT_HSH_DATW11 010010 00101 rt:5 0000 0010 0100 1011 &cp2 + CVM_MT_HSH_DATW12 010010 00101 rt:5 0000 0010 0100 1100 &cp2 + CVM_MT_HSH_DATW13 010010 00101 rt:5 0000 0010 0100 1101 &cp2 + CVM_MT_HSH_DATW14 010010 00101 rt:5 0000 0010 0100 1110 &cp2 + CVM_MT_HSH_DATW15 010010 00101 rt:5 0000 0010 0100 1111 &cp2 + CVM_MT_HSH_IVW0 010010 00101 rt:5 0000 0010 0101 0000 &cp2 + CVM_MT_HSH_IVW1 010010 00101 rt:5 0000 0010 0101 0001 &cp2 + CVM_MT_HSH_IVW2 010010 00101 rt:5 0000 0010 0101 0010 &cp2 + CVM_MT_HSH_IVW3 010010 00101 rt:5 0000 0010 0101 0011 &cp2 + CVM_MT_HSH_IVW4 010010 00101 rt:5 0000 0010 0101 0100 &cp2 + CVM_MT_HSH_IVW5 010010 00101 rt:5 0000 0010 0101 0101 &cp2 + CVM_MT_HSH_IVW6 010010 00101 rt:5 0000 0010 0101 0110 &cp2 + CVM_MT_HSH_IVW7 010010 00101 rt:5 0000 0010 0101 0111 &cp2 CVM_MT_GFM_MUL0 010010 00101 rt:5 0000 0010 0101 1000 &cp2 CVM_MT_GFM_MUL1 010010 00101 rt:5 0000 0010 0101 1001 &cp2 CVM_MT_GFM_RESINP0 010010 00101 rt:5 0000 0010 0101 1010 &cp2 CVM_MT_GFM_RESINP1 010010 00101 rt:5 0000 0010 0101 1011 &cp2 + CVM_MT_GFM_XOR0 010010 00101 rt:5 0000 0010 0101 1100 &cp2 CVM_MT_GFM_POLY 010010 00101 rt:5 0000 0010 0101 1110 &cp2 + CVM_MT_SHA3_XORDAT0 010010 00101 rt:5 0000 0010 1100 0000 &cp2 + CVM_MT_SHA3_XORDAT1 010010 00101 rt:5 0000 0010 1100 0001 &cp2 + CVM_MT_SHA3_XORDAT2 010010 00101 rt:5 0000 0010 1100 0010 &cp2 + CVM_MT_SHA3_XORDAT3 010010 00101 rt:5 0000 0010 1100 0011 &cp2 + CVM_MT_SHA3_XORDAT4 010010 00101 rt:5 0000 0010 1100 0100 &cp2 + CVM_MT_SHA3_XORDAT5 010010 00101 rt:5 0000 0010 1100 0101 &cp2 + CVM_MT_SHA3_XORDAT6 010010 00101 rt:5 0000 0010 1100 0110 &cp2 + CVM_MT_SHA3_XORDAT7 010010 00101 rt:5 0000 0010 1100 0111 &cp2 + CVM_MT_SHA3_XORDAT8 010010 00101 rt:5 0000 0010 1100 1000 &cp2 + CVM_MT_SHA3_XORDAT9 010010 00101 rt:5 0000 0010 1100 1001 &cp2 + CVM_MT_SHA3_XORDAT10 010010 00101 rt:5 0000 0010 1100 1010 &cp2 + CVM_MT_SHA3_XORDAT11 010010 00101 rt:5 0000 0010 1100 1011 &cp2 + CVM_MT_SHA3_XORDAT12 010010 00101 rt:5 0000 0010 1100 1100 &cp2 + CVM_MT_SHA3_XORDAT13 010010 00101 rt:5 0000 0010 1100 1101 &cp2 + CVM_MT_SHA3_XORDAT14 010010 00101 rt:5 0000 0010 1100 1110 &cp2 + CVM_MT_SHA3_XORDAT15 010010 00101 rt:5 0000 0010 1100 1111 &cp2 + CVM_MT_SHA3_XORDAT16 010010 00101 rt:5 0000 0010 1101 0000 &cp2 + CVM_MT_SHA3_XORDAT17 010010 00101 rt:5 0000 0010 1101 0001 &cp2 CVM_MT_CRC_LEN 010010 00101 rt:5 0001 0010 0000 0010 &cp2 CVM_MT_CRC_DWORD 010010 00101 rt:5 0001 0010 0000 0111 &cp2 CVM_MT_CRC_VAR 010010 00101 rt:5 0001 0010 0000 1000 &cp2 CVM_MT_CRC_DWORD_REFLECT 010010 00101 rt:5 0001 0010 0001 0111 &cp2 CVM_MT_CRC_VAR_REFLECT 010010 00101 rt:5 0001 0010 0001 1000 &cp2 + CVM_MT_HSH_STARTMD5 010010 00101 rt:5 0100 0000 0100 0111 &cp2 + CVM_MT_HSH_STARTSHA256 010010 00101 rt:5 0100 0000 0100 1111 &cp2 + CVM_MT_SHA3_STARTOP 010010 00101 rt:5 0100 0000 0101 0010 &cp2 + CVM_MT_HSH_STARTSHA 010010 00101 rt:5 0100 0000 0101 0111 &cp2 CVM_MT_GFM_XORMUL1_REFLECT 010010 00101 rt:5 0100 0000 0101 1101 &cp2 CVM_MT_CRC_POLYNOMIAL 010010 00101 rt:5 0100 0010 0000 0000 &cp2 CVM_MT_CRC_POLYNOMIAL_REFLECT 010010 00101 rt:5 0100 0010 0001 0000 &cp2 + CVM_MT_HSH_STARTSHA512 010010 00101 rt:5 0100 0010 0100 1111 &cp2 CVM_MT_GFM_XORMUL1 010010 00101 rt:5 0100 0010 0101 1101 &cp2 ] CP2_Undef 010010 ----- ----- ---- ---- ---- ----
target/mips/tcg/octeon_translate.c +102 -0
147 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v16 17/21 target/mips: decode Octeon ZUC and SNOW3G COP2 selectors
In reply to James HilliardAdd explicit decodetree entries and translator bindings for the Octeon ZUC and SNOW3G COP2 operation selectors. These stream-cipher selectors operate on the shared HSH register window state, so dispatch them through the per-operation helpers added with the corresponding engine support.
Keep stream-cipher decode separate because these selectors share the HSH register window with unrelated engines.
---
Changes v9 -> v10:
- Split ZUC/SNOW3G selector decode out of the monolithic Octeon COP2 selector decode patch.
- Kept stream-cipher operation selectors helper-backed because they operate on the shared HSH register-window state.
--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 4 ++++ 2 files changed, 8 insertions(+)
target/mips/tcg/octeon.decode +4 -0
@@ -265,8 +265,12 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_CRC_DWORD_REFLECT 010010 00101 rt:5 0001 0010 0001 0111 &cp2 CVM_MT_CRC_VAR_REFLECT 010010 00101 rt:5 0001 0010 0001 1000 &cp2 CVM_MT_HSH_STARTMD5 010010 00101 rt:5 0100 0000 0100 0111 &cp2 + CVM_MT_SNOW3G_START 010010 00101 rt:5 0100 0000 0100 1101 &cp2 + CVM_MT_SNOW3G_MORE 010010 00101 rt:5 0100 0000 0100 1110 &cp2 CVM_MT_HSH_STARTSHA256 010010 00101 rt:5 0100 0000 0100 1111 &cp2 CVM_MT_SHA3_STARTOP 010010 00101 rt:5 0100 0000 0101 0010 &cp2 + CVM_MT_ZUC_START 010010 00101 rt:5 0100 0000 0101 0101 &cp2 + CVM_MT_ZUC_MORE 010010 00101 rt:5 0100 0000 0101 0110 &cp2 CVM_MT_HSH_STARTSHA 010010 00101 rt:5 0100 0000 0101 0111 &cp2 CVM_MT_GFM_XORMUL1_REFLECT 010010 00101 rt:5 0100 0000 0101 1101 &cp2 CVM_MT_CRC_POLYNOMIAL 010010 00101 rt:5 0100 0010 0000 0000 &cp2
target/mips/tcg/octeon_translate.c +4 -0
@@ -345,6 +345,10 @@ CP2_MT_XOR_I64(CVM_MT_SHA3_XORDAT15, sha3_dat[15]);CP2_MT_XOR_I64 (CVM_MT_SHA3_XORDAT16 , sha3_dat[16 ]);CP2_MT_XOR_I64 (CVM_MT_SHA3_XORDAT17 , sha3_dat[17 ]);CP2_MT_HELPER_ENV (CVM_MT_SHA3_STARTOP , sha3_startop); +CP2_MT_HELPER (CVM_MT_ZUC_START , zuc_start); +CP2_MT_HELPER (CVM_MT_ZUC_MORE , zuc_more); +CP2_MT_HELPER (CVM_MT_SNOW3G_START , snow3g_start); +CP2_MT_HELPER (CVM_MT_SNOW3G_MORE , snow3g_more);CP2_MT_HELPER (CVM_MT_HSH_STARTSHA1_COMPAT , hsh_startsha1_compat);CP2_MT_I64 (CVM_MT_HSH_DATW0 , hsh_dat[0 ]);CP2_MT_I64 (CVM_MT_HSH_DATW1 , hsh_dat[1 ]);
Signature · 1 line
2.54.0
PATCH v16 18/21 target/mips: decode Octeon block-cipher COP2 selectors
In reply to James HilliardAdd explicit decodetree entries and translator bindings for the Octeon AES, SMS4, 3DES, KASUMI, and Camellia COP2 operation selectors. These selectors consume or update engine state, so keep them as per-operation helper calls while the simple block-cipher register moves remain direct TCG loads and stores from the earlier register-selector patch.
This completes the block-cipher selector coverage without reintroducing a generic runtime selector dispatch path.
---
Changes v9 -> v10:
- Split AES, SMS4, 3DES, KASUMI, and Camellia selector decode out of the monolithic Octeon COP2 selector decode patch.
- Kept block-cipher operation selectors helper-backed while simple register moves remain direct TCG transfers.
--- target/mips/tcg/octeon.decode | 17 +++++++++++++++++ target/mips/tcg/octeon_translate.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+)
target/mips/tcg/octeon.decode +17 -0
@@ -203,6 +203,8 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_AES_DEC_CBC0 010010 00101 rt:5 0000 0001 0000 1100 &cp2 CVM_MT_AES_DEC0 010010 00101 rt:5 0000 0001 0000 1110 &cp2 CVM_MT_AES_KEYLENGTH 010010 00101 rt:5 0000 0001 0001 0000 &cp2 + CVM_MT_CAMELLIA_FL 010010 00101 rt:5 0000 0001 0001 0101 &cp2 + CVM_MT_CAMELLIA_FLINV 010010 00101 rt:5 0000 0001 0001 0110 &cp2 CVM_MT_CRC_IV 010010 00101 rt:5 0000 0010 0000 0001 &cp2 CVM_MT_CRC_IV_REFLECT 010010 00101 rt:5 0000 0010 0001 0001 &cp2 CVM_MT_CRC_BYTE 010010 00101 rt:5 0000 0010 0000 0100 &cp2
@@ -264,6 +266,15 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_CRC_VAR 010010 00101 rt:5 0001 0010 0000 1000 &cp2 CVM_MT_CRC_DWORD_REFLECT 010010 00101 rt:5 0001 0010 0001 0111 &cp2 CVM_MT_CRC_VAR_REFLECT 010010 00101 rt:5 0001 0010 0001 1000 &cp2 + CVM_MT_AES_ENC_CBC1 010010 00101 rt:5 0011 0001 0000 1001 &cp2 + CVM_MT_AES_ENC1 010010 00101 rt:5 0011 0001 0000 1011 &cp2 + CVM_MT_AES_DEC_CBC1 010010 00101 rt:5 0011 0001 0000 1101 &cp2 + CVM_MT_AES_DEC1 010010 00101 rt:5 0011 0001 0000 1111 &cp2 + CVM_MT_CAMELLIA_ROUND 010010 00101 rt:5 0011 0001 0001 0100 &cp2 + CVM_MT_SMS4_ENC_CBC1 010010 00101 rt:5 0011 0001 0001 1001 &cp2 + CVM_MT_SMS4_ENC1 010010 00101 rt:5 0011 0001 0001 1011 &cp2 + CVM_MT_SMS4_DEC_CBC1 010010 00101 rt:5 0011 0001 0001 1101 &cp2 + CVM_MT_SMS4_DEC1 010010 00101 rt:5 0011 0001 0001 1111 &cp2 CVM_MT_HSH_STARTMD5 010010 00101 rt:5 0100 0000 0100 0111 &cp2 CVM_MT_SNOW3G_START 010010 00101 rt:5 0100 0000 0100 1101 &cp2 CVM_MT_SNOW3G_MORE 010010 00101 rt:5 0100 0000 0100 1110 &cp2
@@ -273,6 +284,12 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_ZUC_MORE 010010 00101 rt:5 0100 0000 0101 0110 &cp2 CVM_MT_HSH_STARTSHA 010010 00101 rt:5 0100 0000 0101 0111 &cp2 CVM_MT_GFM_XORMUL1_REFLECT 010010 00101 rt:5 0100 0000 0101 1101 &cp2 + CVM_MT_3DES_ENC_CBC 010010 00101 rt:5 0100 0000 1000 1000 &cp2 + CVM_MT_KAS_ENC_CBC 010010 00101 rt:5 0100 0000 1000 1001 &cp2 + CVM_MT_3DES_ENC 010010 00101 rt:5 0100 0000 1000 1010 &cp2 + CVM_MT_KAS_ENC 010010 00101 rt:5 0100 0000 1000 1011 &cp2 + CVM_MT_3DES_DEC_CBC 010010 00101 rt:5 0100 0000 1000 1100 &cp2 + CVM_MT_3DES_DEC 010010 00101 rt:5 0100 0000 1000 1110 &cp2 CVM_MT_CRC_POLYNOMIAL 010010 00101 rt:5 0100 0010 0000 0000 &cp2 CVM_MT_CRC_POLYNOMIAL_REFLECT 010010 00101 rt:5 0100 0010 0001 0000 &cp2 CVM_MT_HSH_STARTSHA512 010010 00101 rt:5 0100 0010 0100 1111 &cp2
target/mips/tcg/octeon_translate.c +17 -0
@@ -349,6 +349,23 @@ CP2_MT_HELPER(CVM_MT_ZUC_START, zuc_start);CP2_MT_HELPER (CVM_MT_ZUC_MORE , zuc_more);CP2_MT_HELPER (CVM_MT_SNOW3G_START , snow3g_start);CP2_MT_HELPER (CVM_MT_SNOW3G_MORE , snow3g_more); +CP2_MT_HELPER (CVM_MT_AES_ENC_CBC1 , aes_enc_cbc1); +CP2_MT_HELPER (CVM_MT_AES_ENC1 , aes_enc1); +CP2_MT_HELPER (CVM_MT_AES_DEC_CBC1 , aes_dec_cbc1); +CP2_MT_HELPER (CVM_MT_AES_DEC1 , aes_dec1); +CP2_MT_HELPER (CVM_MT_SMS4_ENC_CBC1 , sms4_enc_cbc1); +CP2_MT_HELPER (CVM_MT_SMS4_ENC1 , sms4_enc1); +CP2_MT_HELPER (CVM_MT_SMS4_DEC_CBC1 , sms4_dec_cbc1); +CP2_MT_HELPER (CVM_MT_SMS4_DEC1 , sms4_dec1); +CP2_MT_HELPER (CVM_MT_3DES_ENC_CBC , des3_enc_cbc); +CP2_MT_HELPER (CVM_MT_KAS_ENC_CBC , kas_enc_cbc); +CP2_MT_HELPER (CVM_MT_3DES_ENC , des3_enc); +CP2_MT_HELPER (CVM_MT_KAS_ENC , kas_enc); +CP2_MT_HELPER (CVM_MT_3DES_DEC_CBC , des3_dec_cbc); +CP2_MT_HELPER (CVM_MT_3DES_DEC , des3_dec); +CP2_MT_HELPER (CVM_MT_CAMELLIA_FL , camellia_fl); +CP2_MT_HELPER (CVM_MT_CAMELLIA_FLINV , camellia_flinv); +CP2_MT_HELPER (CVM_MT_CAMELLIA_ROUND , camellia_round);CP2_MT_HELPER (CVM_MT_HSH_STARTSHA1_COMPAT , hsh_startsha1_compat);CP2_MT_I64 (CVM_MT_HSH_DATW0 , hsh_dat[0 ]);CP2_MT_I64 (CVM_MT_HSH_DATW1 , hsh_dat[1 ]);
Signature · 1 line
2.54.0
PATCH v16 19/21 target/mips: decode Octeon CHORD and LLM COP2 selectors
In reply to James HilliardAdd explicit decodetree entries and translator bindings for the Octeon CHORD and sparse LLM COP2 selectors. CHORD and LLM use their own COP2 selector window rather than the crypto engine windows covered by the preceding decode patches.
This completes the explicit COP2 selector coverage by adding the remaining CHORD and LLM register and operation selectors.
---
Changes v13 -> v14:
- Leave the CP2_Undef fallback in the register-selector patch and keep this patch limited to CHORD/LLM selector additions.
Changes v9 -> v10:
- Split CHORD/LLM selector decode out of the monolithic Octeon COP2 selector decode patch.
- Kept sparse LLM operations helper-backed.
--- target/mips/tcg/octeon.decode | 13 +++++++++++++ target/mips/tcg/octeon_translate.c | 13 +++++++++++++ 2 files changed, 26 insertions(+)
target/mips/tcg/octeon.decode +13 -0
@@ -167,6 +167,9 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MF_GFM_RESINP0 010010 00001 rt:5 0000 0010 0101 1010 &cp2 CVM_MF_GFM_RESINP1 010010 00001 rt:5 0000 0010 0101 1011 &cp2 CVM_MF_GFM_POLY 010010 00001 rt:5 0000 0010 0101 1110 &cp2 + CVM_MF_CHORD 010010 00001 rt:5 0000 0100 0000 0000 &cp2 + CVM_MF_LLM_DATA0 010010 00001 rt:5 0000 0100 0000 0010 &cp2 + CVM_MF_LLM_DATA1 010010 00001 rt:5 0000 0100 0000 1010 &cp2 CVM_MT_HSH_DAT0 010010 00101 rt:5 0000 0000 0100 0000 &cp2 CVM_MT_HSH_DAT1 010010 00101 rt:5 0000 0000 0100 0001 &cp2 CVM_MT_HSH_DAT2 010010 00101 rt:5 0000 0000 0100 0010 &cp2
@@ -261,6 +264,16 @@ LDX 011111 ..... ..... ..... 01000 001010 @lx CVM_MT_SHA3_XORDAT15 010010 00101 rt:5 0000 0010 1100 1111 &cp2 CVM_MT_SHA3_XORDAT16 010010 00101 rt:5 0000 0010 1101 0000 &cp2 CVM_MT_SHA3_XORDAT17 010010 00101 rt:5 0000 0010 1101 0001 &cp2 + CVM_MT_LLM_READ_ADDR0 010010 00101 rt:5 0000 0100 0000 0000 &cp2 + CVM_MT_LLM_WRITE_ADDR0 010010 00101 rt:5 0000 0100 0000 0001 &cp2 + CVM_MT_LLM_DATA0 010010 00101 rt:5 0000 0100 0000 0010 &cp2 + CVM_MT_LLM_READ64_ADDR0 010010 00101 rt:5 0000 0100 0000 0100 &cp2 + CVM_MT_LLM_WRITE64_ADDR0 010010 00101 rt:5 0000 0100 0000 0101 &cp2 + CVM_MT_LLM_READ_ADDR1 010010 00101 rt:5 0000 0100 0000 1000 &cp2 + CVM_MT_LLM_WRITE_ADDR1 010010 00101 rt:5 0000 0100 0000 1001 &cp2 + CVM_MT_LLM_DATA1 010010 00101 rt:5 0000 0100 0000 1010 &cp2 + CVM_MT_LLM_READ64_ADDR1 010010 00101 rt:5 0000 0100 0000 1100 &cp2 + CVM_MT_LLM_WRITE64_ADDR1 010010 00101 rt:5 0000 0100 0000 1101 &cp2 CVM_MT_CRC_LEN 010010 00101 rt:5 0001 0010 0000 0010 &cp2 CVM_MT_CRC_DWORD 010010 00101 rt:5 0001 0010 0000 0111 &cp2 CVM_MT_CRC_VAR 010010 00101 rt:5 0001 0010 0000 1000 &cp2
target/mips/tcg/octeon_translate.c +13 -0
@@ -235,6 +235,9 @@ CP2_MF_I64(CVM_MF_GFM_MUL1, gfm_mul[1]);CP2_MF_I64 (CVM_MF_GFM_RESINP0 , gfm_resinp[0 ]);CP2_MF_I64 (CVM_MF_GFM_RESINP1 , gfm_resinp[1 ]);CP2_MF_U16 (CVM_MF_GFM_POLY , gfm_poly); +CP2_MF_I64 (CVM_MF_CHORD , chord); +CP2_MF_I64 (CVM_MF_LLM_DATA0 , llm_data[0 ]); +CP2_MF_I64 (CVM_MF_LLM_DATA1 , llm_data[1 ]);CP2_MF_HELPER (CVM_MF_CRC_IV_REFLECT , crc_iv_reflect);CP2_MF_I64 (CVM_MF_SHA3_DAT24 , sha3_dat24);
@@ -306,6 +309,8 @@ CP2_MT_I64(CVM_MT_GFM_RESINP0, gfm_resinp[0]);CP2_MT_I64 (CVM_MT_GFM_RESINP1 , gfm_resinp[1 ]);CP2_MT_XOR_I64 (CVM_MT_GFM_XOR0 , gfm_resinp[0 ]);CP2_MT_U16 (CVM_MT_GFM_POLY , gfm_poly); +CP2_MT_I64 (CVM_MT_LLM_DATA0 , llm_data[0 ]); +CP2_MT_I64 (CVM_MT_LLM_DATA1 , llm_data[1 ]);CP2_MT_U8_MASKED (CVM_MT_CRC_LEN , crc_len,0xf );CP2_MT_U32 (CVM_MT_CRC_POLYNOMIAL , crc_poly);
@@ -395,6 +400,14 @@ CP2_MT_HELPER(CVM_MT_HSH_STARTMD5, hsh_startmd5);CP2_MT_HELPER (CVM_MT_HSH_STARTSHA256 , hsh_startsha256);CP2_MT_HELPER (CVM_MT_HSH_STARTSHA , hsh_startsha);CP2_MT_HELPER (CVM_MT_HSH_STARTSHA512 , hsh_startsha512); +CP2_MT_HELPER (CVM_MT_LLM_READ_ADDR0 , llm_read_addr0); +CP2_MT_HELPER (CVM_MT_LLM_WRITE_ADDR0 , llm_write_addr0); +CP2_MT_HELPER (CVM_MT_LLM_READ64_ADDR0 , llm_read64_addr0); +CP2_MT_HELPER (CVM_MT_LLM_WRITE64_ADDR0 , llm_write64_addr0); +CP2_MT_HELPER (CVM_MT_LLM_READ_ADDR1 , llm_read_addr1); +CP2_MT_HELPER (CVM_MT_LLM_WRITE_ADDR1 , llm_write_addr1); +CP2_MT_HELPER (CVM_MT_LLM_READ64_ADDR1 , llm_read64_addr1); +CP2_MT_HELPER (CVM_MT_LLM_WRITE64_ADDR1 , llm_write64_addr1);static bool trans_BBIT (DisasContext *ctx,arg_BBIT *a) {
Signature · 1 line
2.54.0
PATCH v16 20/21 target/mips: add Octeon CvmCount RDHWR support
In reply to James HilliardOcteon exposes CvmCount through RDHWR register 31. Add the Octeon-only decode path, enable the corresponding HWREna bit for linux-user, and use an unsigned mask when checking HWREna so bit 31 is handled safely.
For user-mode emulation, return host ticks as a monotonic counter source suitable for existing Octeon userspace code. In system mode, fall back to the existing CP0 Count value.
---
Changes v5 -> v6:
- New patch.
--- target/mips/cpu.c | 1 + target/mips/helper.h | 1 + target/mips/tcg/op_helper.c | 13 ++++++++++++- target/mips/tcg/translate.c | 11 +++++++++++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 17 +++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-)
target/mips/cpu.c +1 -0
@@ -320,6 +320,7 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type) env->CP0_HWREna |=0x0000000F ;if (env->insn_flags &INSN_OCTEON ) { env->CP0_HWREna |=0x40000000u ; + env->CP0_HWREna |=0x80000000u ; }if (env->CP0_Config1 & (1 <<CP0C1_FP )) { env->CP0_Status |= (1 << CP0St_CU1);
target/mips/helper.h +1 -0
@@ -255,6 +255,7 @@ 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_1(rdhwr_cvmcount, tl, env) DEF_HELPER_2(pmon, void, env, int)DEF_HELPER_1 (wait, void, env)
target/mips/tcg/op_helper.c +12 -1
@@ -25,6 +25,7 @@#include "exec/memop.h" #include "fpu_helper.h" #include "qemu/crc32c.h" +#include "qemu/timer.h" #include <zlib.h> static inline target_ulong bitswap (target_ulong v)
@@ -209,7 +210,7 @@ target_ulong helper_yield(CPUMIPSState *env, target_ulong arg)static inline void check_hwrena (CPUMIPSState *env,int reg,uintptr_t pc) { -if ((env->hflags &MIPS_HFLAG_CP0 ) || (env->CP0_HWREna & (1 << reg))) { +if ((env->hflags &MIPS_HFLAG_CP0 ) || (env->CP0_HWREna & (1u << reg))) {return ; }do_raise_exception (env,EXCP_RI , pc);
@@ -261,6 +262,16 @@ target_ulong helper_rdhwr_chord(CPUMIPSState *env)return env->octeon_crypto.chord; } +target_ulong helper_rdhwr_cvmcount (CPUMIPSState *env) +{ +check_hwrena (env,31 ,GETPC ()); +#ifdef CONFIG_USER_ONLY +return cpu_get_host_ticks (); +#else +return (uint32_t )cpu_mips_get_count (env); +#endif +} +void helper_pmon (CPUMIPSState *env,int function) { function /=2 ;
target/mips/tcg/translate.c +11 -0
@@ -10933,6 +10933,17 @@ void gen_rdhwr(DisasContext *ctx, int rt, int rd, int sel)gen_helper_rdhwr_chord (t0, tcg_env);gen_store_gpr (t0, rt);break ; +case 31 : +if (!(ctx->insn_flags &INSN_OCTEON )) { +gen_reserved_instruction (ctx); +break ; + } +translator_io_start (&ctx->base); +gen_helper_rdhwr_cvmcount (t0, tcg_env); +gen_store_gpr (t0, rt); +gen_save_pc (ctx->base.pc_next +4 ); + ctx->base.is_jmp =DISAS_EXIT ; +break ;default :/* Invalid */ MIPS_INVAL ("rdhwr" );gen_reserved_instruction (ctx);
tests/tcg/mips/user/isa/octeon/octeon-insns.c +17 -0
@@ -330,6 +330,22 @@ static uint64_t octeon_cop2_gfm_mul_reflect_readback(uint64_t value)return rd; } +static uint64_t octeon_rdhwr31_non_decreasing (void ) +{ +uint64_t first, second; + + asmvolatile ( +".word 0x7c08f83b\n\t" /* rdhwr $8, $31 */ +".word 0x7c09f83b\n\t" /* rdhwr $9, $31 */ +"move %[first], $8\n\t" +"move %[second], $9\n\t" + : [first]"=r" (first), [second]"=r" (second) + : + :"$8" ,"$9" ); + +return second >= first; +} +int main (void ) {assert (octeon_baddu (0x123 ,0x0f0 ) ==0x13 );
@@ -358,6 +374,7 @@ int main(void) 0x0123456789abcdefULL) == 0xf7b3d591e6a2c480ULL);assert (octeon_cop2_gfm_mul_reflect_readback (0xfedcba9876543210ULL ) ==0x084c2a6e195d3b7fULL ); +assert (octeon_rdhwr31_non_decreasing ());return 0 ; }
Signature · 1 line
2.54.0
PATCH v16 21/21 tests/tcg/mips: cover Octeon QMAC instructions
In reply to James HilliardAdd smoke coverage for Octeon QMAC and QMACS fixed-point accumulator instruction paths.
The coverage exercises normal accumulation, saturating accumulation, and the sticky saturation flag.
---
Changes v12 -> v13:
- Add QMAC/QMACS smoke coverage.
--- tests/tcg/mips/user/isa/octeon/octeon-insns.c | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
tests/tcg/mips/user/isa/octeon/octeon-insns.c +40 -0
@@ -129,6 +129,43 @@ static uint64_t octeon_vmm0(uint64_t mpl0, uint64_t p0,return rd; } +static uint64_t octeon_qmac_lo (uint64_t rs,uint64_t rt,uint64_t lo) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +"mtlo %[lo]\n\t" +"mthi $0\n\t" +".word 0x710904d2\n\t" /* qmac.03 $8, $9 */ +"mflo %[rd]\n\t" + : [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt), [lo]"r" (lo) + :"$8" ,"$9" ); + +return rd; +} + +static uint64_t octeon_qmacs_state (uint64_t rs,uint64_t rt,uint64_t lo) +{ +uint64_t hi, rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +"mtlo %[lo]\n\t" +"mthi $0\n\t" +".word 0x71090012\n\t" /* qmacs.00 $8, $9 */ +"mfhi %[hi]\n\t" +"mflo %[rd]\n\t" + : [hi]"=r" (hi), [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt), [lo]"r" (lo) + :"$8" ,"$9" ); + +return ((hi &1 ) <<32 ) | (rd &0xffffffff ); +} +static uint64_t octeon_vmm0_zeroes_mpl1 (void ) {uint64_t rd;
@@ -355,6 +392,9 @@ int main(void)assert (octeon_seq (0xabc ,0xdef ) ==0 );assert (octeon_sne (0xabc ,0xabc ) ==0 );assert (octeon_sne (0xabc ,0xdef ) ==1 ); +assert (octeon_qmac_lo (0x0003000000000000ULL ,2 ,1 ) ==13 ); +assert (octeon_qmacs_state (1 ,1 ,0x7ffffffe ) ==0x17fffffffULL ); +assert (octeon_qmacs_state (0x8000 ,0x8000 ,0 ) ==0x17fffffffULL );assert (octeon_vmulu (5 ,7 ,11 ) ==46 );assert (octeon_vmm0 (5 ,13 ,7 ,11 ) ==59 );assert (octeon_vmm0_zeroes_mpl1 () ==0 );
Signature · 1 line
2.54.0