Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zkn ISA extension #1039

Merged
merged 6 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mimpid = 0x01040312 -> Version 01.04.03.12 -> v1.4.3.12

| Date | Version | Comment | Ticket |
|:----:|:-------:|:--------|:------:|
| 28.09.2024 | 1.10.4.8 | :sparkles: add support for RISC-V "NIST algorithm suite" ISA extension `Zkn` | [#1039](https://github.com/stnolting/neorv32/pull/1039) |
| 27.09.2024 | 1.10.4.7 | :sparkles: add support for RISC-V "carry-less multiplication instruction for cryptography" ISA extension `Zbkc` | [#1038](https://github.com/stnolting/neorv32/pull/1038) |
| 27.09.2024 | 1.10.4.6 | :sparkles: add support for RISC-V "bit manipulation instructions for cryptography" ISA extension `Zbkb` | [#1037](https://github.com/stnolting/neorv32/pull/1037) |
| 27.09.2024 | 1.10.4.5 | :sparkles: add support for RISC-V "data independent execution time" ISA extension `Zknt` | [#1036](https://github.com/stnolting/neorv32/pull/1036) |
Expand Down
19 changes: 19 additions & 0 deletions docs/datasheet/cpu.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ This chapter gives a brief overview of all available ISA extensions.
| <<_zicond_isa_extension,`Zicond`>> | Integer conditional operations | `CPU_EXTENSION_RISCV_Zicond`
| <<_zicsr_isa_extension,`Zicsr`>> | Control and status register access instructions | Always enabled
| <<_zihpm_isa_extension,`Zihpm`>> | Hardware performance monitors extension | `CPU_EXTENSION_RISCV_Zihpm`
| <<_zkn_isa_extension,`Zkn`>> | Scalar cryptographic NIST algorithm suite | _Implicitly_ enabled
| <<_zknd_isa_extension,`Zknd`>> | Scalar cryptographic NIST AES decryption instructions | `CPU_EXTENSION_RISCV_Zknd`
| <<_zkne_isa_extension,`Zkne`>> | Scalar cryptographic NIST AES encryption instructions | `CPU_EXTENSION_RISCV_Zkne`
| <<_zknh_isa_extension,`Zknh`>> | Scalar cryptographic NIST hash function instructions | `CPU_EXTENSION_RISCV_Zknh`
Expand Down Expand Up @@ -798,6 +799,24 @@ Accessing any user-mode HPM CSR (`hpmcounter*[h]`) will raise an illegal instruc
The event-driven increment of the HPMs can be deactivated individually via the <<_mcountinhibit>> CSR.


==== `Zbn` ISA Extension

The `Zkn` ISA extension is part of the _RISC-V scalar cryptography_ ISA specification and defines the "NIST algorithm suite".
This ISA extension cannot be enabled by a specific generic. Instead, it is enabled if a specific set of cryptography-related
sub-extensions is enabled.

The `Zkn` extension is shorthand for the following set of other extensions:

* <<_zbkb_isa_extension>> - Bit manipulation instructions for cryptography.
* <<_zbkc_isa_extension>> - Carry-less multiply instructions.
* <<_zbkx_isa_extension>> - Cross-bar permutation instructions.
* <<_zbne_isa_extension>> - AES encryption instructions.
* <<_zbnd_isa_extension>> - AES decryption instructions.
* <<_zbnh_isa_extension>> - SHA2 hash function instructions.

A processor configuration which implements `Zkn` must implement all of the above extensions.


==== `Zbkb` ISA Extension

The `Zbkb` sub-extension is part of the _RISC-V scalar cryptography_ ISA specification and extends the _RISC-V bit manipulation_
Expand Down
7 changes: 4 additions & 3 deletions docs/datasheet/cpu_csr.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,10 @@ discover ISA sub-extensions and CPU configuration options
| 15 | `CSR_MXISA_ZKNH` | r/- | <<_zknh_isa_extension>> available
| 16 | `CSR_MXISA_ZBKB` | r/- | <<_zbkb_isa_extension>> available
| 17 | `CSR_MXISA_ZBKC` | r/- | <<_zbkc_isa_extension>> available
| 19:18 | - | r/- | hardwired to zero
| 20 | `CSR_MXISA_IS_SIM` | r/- | set if CPU is being **simulated** (⚠️ not guaranteed)
| 28:21 | - | r/- | hardwired to zero
| 18 | `CSR_MXISA_ZKN` | r/- | <<_zkn_isa_extension>> available
| 23:19 | - | r/- | hardwired to zero
| 24 | `CSR_MXISA_IS_SIM` | r/- | set if CPU is being **simulated** (⚠️ not guaranteed)
| 28:25 | - | r/- | hardwired to zero
| 29 | `CSR_MXISA_RFHWRST` | r/- | full hardware reset of register file available when set (`REGFILE_HW_RST`)
| 30 | `CSR_MXISA_FASTMUL` | r/- | fast multiplication available when set (`FAST_MUL_EN`)
| 31 | `CSR_MXISA_FASTSHIFT` | r/- | fast shifts available when set (`FAST_SHIFT_EN`)
Expand Down
Binary file modified docs/figures/neorv32_processor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion rtl/core/neorv32_cpu.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ architecture neorv32_cpu_rtl of neorv32_cpu is
-- auto-configuration --
constant rf_rs3_en_c : boolean := CPU_EXTENSION_RISCV_Zxcfu or CPU_EXTENSION_RISCV_Zfinx; -- 3rd register file read port
constant const_exe_c : boolean := FAST_SHIFT_EN; -- data-independent execution time for crypto operations (RISC-V Zknt ISA ext.)
constant riscv_zkn_c : boolean := CPU_EXTENSION_RISCV_Zbkb and CPU_EXTENSION_RISCV_Zbkc and CPU_EXTENSION_RISCV_Zbkx and
CPU_EXTENSION_RISCV_Zkne and CPU_EXTENSION_RISCV_Zknd and CPU_EXTENSION_RISCV_Zknh; -- Zkn: NIST suite

-- external CSR interface --
signal xcsr_we : std_ulogic;
Expand Down Expand Up @@ -123,7 +125,7 @@ begin

-- Sanity Checks --------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------
-- CPU ISA configuration --
-- CPU ISA configuration (in alphabetical order - not in canonical order!) --
assert false report "[NEORV32] CPU ISA: rv32" &
cond_sel_string_f(CPU_EXTENSION_RISCV_E, "e", "i") &
cond_sel_string_f(CPU_EXTENSION_RISCV_A, "a", "" ) &
Expand All @@ -141,6 +143,7 @@ begin
cond_sel_string_f(true, "_zifencei", "" ) & -- always enabled
cond_sel_string_f(CPU_EXTENSION_RISCV_Zihpm, "_zihpm", "" ) &
cond_sel_string_f(CPU_EXTENSION_RISCV_Zfinx, "_zfinx", "" ) &
cond_sel_string_f(riscv_zkn_c, "_zkn", "" ) &
cond_sel_string_f(CPU_EXTENSION_RISCV_Zknd, "_zknd", "" ) &
cond_sel_string_f(CPU_EXTENSION_RISCV_Zkne, "_zkne", "" ) &
cond_sel_string_f(CPU_EXTENSION_RISCV_Zknh, "_zknh", "" ) &
Expand Down Expand Up @@ -187,6 +190,7 @@ begin
CPU_EXTENSION_RISCV_Zicntr => CPU_EXTENSION_RISCV_Zicntr, -- implement base counters?
CPU_EXTENSION_RISCV_Zicond => CPU_EXTENSION_RISCV_Zicond, -- implement integer conditional operations?
CPU_EXTENSION_RISCV_Zihpm => CPU_EXTENSION_RISCV_Zihpm, -- implement hardware performance monitors?
CPU_EXTENSION_RISCV_Zkn => riscv_zkn_c, -- NIST algorithm suite available?
CPU_EXTENSION_RISCV_Zknd => CPU_EXTENSION_RISCV_Zknd, -- implement cryptography NIST AES decryption extension?
CPU_EXTENSION_RISCV_Zkne => CPU_EXTENSION_RISCV_Zkne, -- implement cryptography NIST AES encryption extension?
CPU_EXTENSION_RISCV_Zknh => CPU_EXTENSION_RISCV_Zknh, -- implement cryptography NIST hash extension?
Expand Down
4 changes: 3 additions & 1 deletion rtl/core/neorv32_cpu_control.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ entity neorv32_cpu_control is
CPU_EXTENSION_RISCV_Zicntr : boolean; -- implement base counters?
CPU_EXTENSION_RISCV_Zicond : boolean; -- implement integer conditional operations?
CPU_EXTENSION_RISCV_Zihpm : boolean; -- implement hardware performance monitors?
CPU_EXTENSION_RISCV_Zkn : boolean; -- NIST algorithm suite available?
CPU_EXTENSION_RISCV_Zknd : boolean; -- implement cryptography NIST AES decryption extension?
CPU_EXTENSION_RISCV_Zkne : boolean; -- implement cryptography NIST AES encryption extension?
CPU_EXTENSION_RISCV_Zknh : boolean; -- implement cryptography NIST hash extension?
Expand Down Expand Up @@ -1898,8 +1899,9 @@ begin
csr.rdata(15) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zknh); -- Zknh: cryptography NIST hash functions
csr.rdata(16) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zbkb); -- Zbkb: bit manipulation instructions for cryptography
csr.rdata(17) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zbkc); -- Zbkc: carry-less multiplication for cryptography
csr.rdata(18) <= bool_to_ulogic_f(CPU_EXTENSION_RISCV_Zkn); -- Zkn: NIST algorithm suite
-- misc --
csr.rdata(20) <= bool_to_ulogic_f(is_simulation_c); -- is this a simulation?
csr.rdata(24) <= bool_to_ulogic_f(is_simulation_c); -- is this a simulation?
-- tuning options --
csr.rdata(29) <= bool_to_ulogic_f(REGFILE_HW_RST); -- full hardware reset of register file
csr.rdata(30) <= bool_to_ulogic_f(FAST_MUL_EN); -- DSP-based multiplication (M extensions only)
Expand Down
2 changes: 1 addition & 1 deletion rtl/core/neorv32_package.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ package neorv32_package is

-- Architecture Constants -----------------------------------------------------------------
-- -------------------------------------------------------------------------------------------
constant hw_version_c : std_ulogic_vector(31 downto 0) := x"01100407"; -- hardware version
constant hw_version_c : std_ulogic_vector(31 downto 0) := x"01100408"; -- hardware version
constant archid_c : natural := 19; -- official RISC-V architecture ID
constant XLEN : natural := 32; -- native data path width

Expand Down
3 changes: 2 additions & 1 deletion sw/lib/include/neorv32_cpu_csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ enum NEORV32_CSR_XISA_enum {
CSR_MXISA_ZKNH = 15, /**< CPU mxisa CSR (15): scalar cryptography - NIST hash functions (r/-)*/
CSR_MXISA_ZBKB = 16, /**< CPU mxisa CSR (16): scalar cryptography - bit manipulation instructions (r/-)*/
CSR_MXISA_ZBKC = 17, /**< CPU mxisa CSR (17): scalar cryptography - carry-less multiplication instructions (r/-)*/
CSR_MXISA_ZKN = 18, /**< CPU mxisa CSR (18): scalar cryptography - NIST algorithm suite (r/-)*/

// Misc
CSR_MXISA_IS_SIM = 20, /**< CPU mxisa CSR (20): this might be a simulation when set (r/-)*/
CSR_MXISA_IS_SIM = 24, /**< CPU mxisa CSR (24): this might be a simulation when set (r/-)*/

// Tuning options
CSR_MXISA_RFHWRST = 29, /**< CPU mxisa CSR (29): Register file has full hardware reset (r/-)*/
Expand Down
1 change: 1 addition & 0 deletions sw/lib/source/neorv32_rte.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ void neorv32_rte_print_hw_config(void) {
if (tmp & (1<<CSR_MXISA_ZICSR)) { neorv32_uart0_printf("Zicsr "); }
if (tmp & (1<<CSR_MXISA_ZIFENCEI)) { neorv32_uart0_printf("Zifencei "); }
if (tmp & (1<<CSR_MXISA_ZIHPM)) { neorv32_uart0_printf("Zihpm "); }
if (tmp & (1<<CSR_MXISA_ZKN)) { neorv32_uart0_printf("Zkn "); }
if (tmp & (1<<CSR_MXISA_ZKND)) { neorv32_uart0_printf("Zknd "); }
if (tmp & (1<<CSR_MXISA_ZKNE)) { neorv32_uart0_printf("Zkne "); }
if (tmp & (1<<CSR_MXISA_ZKNH)) { neorv32_uart0_printf("Zknh "); }
Expand Down