2021-12-14 07:23:24 +08:00
|
|
|
/*****************************************************************************\
|
2022-06-09 07:12:01 +08:00
|
|
|
| Copyright (C) 2021-2022 Luke Wren |
|
2021-12-14 07:23:24 +08:00
|
|
|
| SPDX-License-Identifier: Apache-2.0 |
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
2021-05-21 10:46:29 +08:00
|
|
|
// Hazard3 CPU configuration parameters
|
2021-05-21 09:34:16 +08:00
|
|
|
|
2021-05-21 10:46:29 +08:00
|
|
|
// To configure Hazard3 you can either edit this file, or set parameters on
|
2021-05-21 09:34:16 +08:00
|
|
|
// your top-level instantiation, it's up to you. These parameters are all
|
2021-05-21 10:46:29 +08:00
|
|
|
// plumbed through Hazard3's internal hierarchy to the appropriate places.
|
2021-05-21 09:34:16 +08:00
|
|
|
|
2021-06-01 00:54:12 +08:00
|
|
|
// If you add a parameter here, you should add a matching line to
|
|
|
|
// hazard3_config_inst.vh to propagate the parameter through module
|
|
|
|
// instantiations.
|
|
|
|
|
2021-05-21 09:34:16 +08:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Reset state configuration
|
|
|
|
|
|
|
|
// RESET_VECTOR: Address of first instruction executed.
|
2022-10-08 15:09:26 +08:00
|
|
|
parameter RESET_VECTOR = 32'h00000000,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
|
|
|
// MTVEC_INIT: Initial value of trap vector base. Bits clear in MTVEC_WMASK
|
|
|
|
// will never change from this initial value. Bits set in MTVEC_WMASK can be
|
2021-05-31 02:52:46 +08:00
|
|
|
// written/set/cleared as normal.
|
|
|
|
//
|
|
|
|
// Note that mtvec bits 1:0 do not affect the trap base (as per RISC-V spec).
|
|
|
|
// Bit 1 is don't care, bit 0 selects the vectoring mode: unvectored if == 0
|
|
|
|
// (all traps go to mtvec), vectored if == 1 (exceptions go to mtvec, IRQs to
|
|
|
|
// mtvec + mcause * 4). This means MTVEC_INIT also sets the initial vectoring
|
|
|
|
// mode.
|
2022-10-08 15:09:26 +08:00
|
|
|
parameter MTVEC_INIT = 32'h00000000,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-10-06 06:52:20 +08:00
|
|
|
// Standard RISC-V ISA support
|
2021-05-21 09:34:16 +08:00
|
|
|
|
2021-12-04 23:02:31 +08:00
|
|
|
// EXTENSION_A: Support for atomic read/modify/write instructions
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter EXTENSION_A = 1,
|
2021-12-04 23:02:31 +08:00
|
|
|
|
2021-05-21 09:34:16 +08:00
|
|
|
// EXTENSION_C: Support for compressed (variable-width) instructions
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter EXTENSION_C = 1,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
|
|
|
// EXTENSION_M: Support for hardware multiply/divide/modulo instructions
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter EXTENSION_M = 1,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
2021-11-26 06:58:49 +08:00
|
|
|
// EXTENSION_ZBA: Support for Zba address generation instructions
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_ZBA = 0,
|
2021-11-26 06:58:49 +08:00
|
|
|
|
|
|
|
// EXTENSION_ZBB: Support for Zbb basic bit manipulation instructions
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_ZBB = 0,
|
2021-11-26 06:58:49 +08:00
|
|
|
|
|
|
|
// EXTENSION_ZBC: Support for Zbc carry-less multiplication instructions
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_ZBC = 0,
|
2021-11-26 06:58:49 +08:00
|
|
|
|
|
|
|
// EXTENSION_ZBS: Support for Zbs single-bit manipulation instructions
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_ZBS = 0,
|
2022-04-09 20:49:16 +08:00
|
|
|
|
2022-05-07 00:36:25 +08:00
|
|
|
// EXTENSION_ZBKB: Support for Zbkb basic bit manipulation for cryptography
|
|
|
|
// Requires: Zbb. (This flag enables instructions in Zbkb which aren't in Zbb.)
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_ZBKB = 0,
|
2022-05-07 00:36:25 +08:00
|
|
|
|
2023-03-20 08:00:51 +08:00
|
|
|
// EXTENSION_ZCB: Support for Zcb basic additional compressed instructions
|
|
|
|
// Requires: EXTENSION_C. (Some Zcb instructions also require Zbb or M.)
|
2023-03-17 02:48:15 +08:00
|
|
|
// Note Zca is equivalent to C, as we do not support the F extension.
|
2023-03-23 11:07:09 +08:00
|
|
|
parameter EXTENSION_ZCB = 0,
|
2023-03-17 02:48:15 +08:00
|
|
|
|
2023-03-20 08:00:51 +08:00
|
|
|
// EXTENSION_ZCMP: Support for Zcmp push/pop instructions.
|
|
|
|
// Requires: EXTENSION_C.
|
2023-03-23 11:07:09 +08:00
|
|
|
parameter EXTENSION_ZCMP = 0,
|
2023-03-20 08:00:51 +08:00
|
|
|
|
2022-04-09 20:49:16 +08:00
|
|
|
// EXTENSION_ZIFENCEI: Support for the fence.i instruction
|
|
|
|
// Optional, since a plain branch/jump will also flush the prefetch queue.
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_ZIFENCEI = 0,
|
2022-04-09 20:49:16 +08:00
|
|
|
|
2022-10-06 06:52:20 +08:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Custom RISC-V extensions
|
|
|
|
|
2022-08-29 02:48:50 +08:00
|
|
|
// EXTENSION_XH3B: Custom bit-extract-multiple instructions for Hazard3
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_XH3BEXTM = 0,
|
2022-10-06 06:52:20 +08:00
|
|
|
|
|
|
|
// EXTENSION_XH3IRQ: Custom preemptive, prioritised interrupt support. Can be
|
2022-10-06 07:16:10 +08:00
|
|
|
// disabled if an external interrupt controller (e.g. PLIC) is used. If
|
|
|
|
// disabled, and NUM_IRQS > 1, the external interrupts are simply OR'd into
|
|
|
|
// mip.meip.
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_XH3IRQ = 0,
|
2022-10-06 06:52:20 +08:00
|
|
|
|
|
|
|
// EXTENSION_XH3PMPM: PMPCFGMx CSRs to enforce PMP regions in M-mode without
|
|
|
|
// locking. Unlike ePMP mseccfg.rlb, locked and unlocked regions can coexist
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_XH3PMPM = 0,
|
2022-08-29 02:48:50 +08:00
|
|
|
|
|
|
|
// EXTENSION_XH3POWER: Custom power management controls for Hazard3
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter EXTENSION_XH3POWER = 0,
|
2022-06-03 08:18:33 +08:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-10-06 06:52:20 +08:00
|
|
|
// Standard CSR support
|
2021-11-26 06:58:49 +08:00
|
|
|
|
2022-08-29 02:48:50 +08:00
|
|
|
// Note the Zicsr extension is implied by any of CSR_M_MANDATORY, CSR_M_TRAP,
|
|
|
|
// CSR_COUNTER.
|
|
|
|
|
2021-05-21 09:34:16 +08:00
|
|
|
// CSR_M_MANDATORY: Bare minimum CSR support e.g. misa. Spec says must = 1 if
|
|
|
|
// CSRs are present, but I won't tell anyone.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter CSR_M_MANDATORY = 1,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
|
|
|
// CSR_M_TRAP: Include M-mode trap-handling CSRs, and enable trap support.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter CSR_M_TRAP = 1,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
2022-10-08 15:43:25 +08:00
|
|
|
// CSR_COUNTER: Include performance counters and Zicntr CSRs
|
|
|
|
parameter CSR_COUNTER = 0,
|
2021-06-01 00:54:12 +08:00
|
|
|
|
2022-05-24 23:06:28 +08:00
|
|
|
// U_MODE: Support the U (user) execution mode. In U mode, the core performs
|
|
|
|
// unprivileged bus accesses, and software's access to CSRs is restricted.
|
|
|
|
// Additionally, if the PMP is included, the core may restrict U-mode
|
|
|
|
// software's access to memory.
|
|
|
|
// Requires: CSR_M_TRAP.
|
2022-05-24 00:52:08 +08:00
|
|
|
parameter U_MODE = 0,
|
|
|
|
|
|
|
|
// PMP_REGIONS: Number of physical memory protection regions, or 0 for no PMP.
|
2022-05-24 23:06:28 +08:00
|
|
|
// PMP is more useful if U mode is supported, but this is not a requirement.
|
2022-05-24 00:52:08 +08:00
|
|
|
parameter PMP_REGIONS = 0,
|
|
|
|
|
2022-06-04 00:09:43 +08:00
|
|
|
// PMP_GRAIN: This is the "G" parameter in the privileged spec. Minimum PMP
|
|
|
|
// region size is 1 << (G + 2) bytes. If G > 0, PMCFG.A can not be set to
|
|
|
|
// NA4 (will get set to OFF instead). If G > 1, the G - 1 LSBs of pmpaddr are
|
|
|
|
// read-only-0 when PMPCFG.A is OFF, and read-only-1 when PMPCFG.A is NAPOT.
|
|
|
|
parameter PMP_GRAIN = 0,
|
|
|
|
|
|
|
|
// PMPADDR_HARDWIRED: If a bit is 1, the corresponding region's pmpaddr and
|
|
|
|
// pmpcfg registers are read-only. PMP_GRAIN is ignored on hardwired regions.
|
|
|
|
// It's recommended to make hardwired regions the highest-numbered, so they
|
|
|
|
// can be overridden by lower-numbered regions.
|
|
|
|
parameter PMP_HARDWIRED = PMP_REGIONS > 0 ? {PMP_REGIONS{1'b0}} : 1'b0,
|
|
|
|
|
|
|
|
// PMPADDR_HARDWIRED_ADDR: Values of pmpaddr registers whose PMP_HARDWIRED
|
|
|
|
// bits are set to 1. Non-hardwired regions reset to all-zeroes.
|
|
|
|
parameter PMP_HARDWIRED_ADDR = PMP_REGIONS > 0 ? {PMP_REGIONS{32'h0}} : 1'b0,
|
|
|
|
|
|
|
|
// PMPCFG_RESET_VAL: Values of pmpcfg registers whose PMP_HARDWIRED bits are
|
|
|
|
// set to 1. Non-hardwired regions reset to all zeroes.
|
|
|
|
parameter PMP_HARDWIRED_CFG = PMP_REGIONS > 0 ? {PMP_REGIONS{8'h00}} : 1'b0,
|
2022-06-03 08:18:33 +08:00
|
|
|
|
2021-07-11 01:53:41 +08:00
|
|
|
// DEBUG_SUPPORT: Support for run/halt and instruction injection from an
|
|
|
|
// external Debug Module, support for Debug Mode, and Debug Mode CSRs.
|
|
|
|
// Requires: CSR_M_MANDATORY, CSR_M_TRAP.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter DEBUG_SUPPORT = 0,
|
2021-07-11 01:53:41 +08:00
|
|
|
|
2022-08-22 15:45:06 +08:00
|
|
|
// BREAKPOINT_TRIGGERS: Number of triggers which support type=2 execute=1
|
|
|
|
// (but not store/load=1, i.e. not a watchpoint). Requires: DEBUG_SUPPORT
|
|
|
|
parameter BREAKPOINT_TRIGGERS = 0,
|
|
|
|
|
2022-08-08 03:51:12 +08:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// External interrupt support
|
|
|
|
|
2022-10-08 15:43:25 +08:00
|
|
|
// NUM_IRQS: Number of external IRQs. Minimum 1, maximum 512. Note that if
|
|
|
|
// EXTENSION_XH3IRQ (Hazard3 interrupt controller) is disabled then multiple
|
|
|
|
// external interrupts are simply OR'd into mip.meip.
|
|
|
|
parameter NUM_IRQS = 1,
|
2022-08-08 03:51:12 +08:00
|
|
|
|
2022-10-06 06:52:20 +08:00
|
|
|
// IRQ_PRIORITY_BITS: Number of priority bits implemented for each interrupt
|
2022-10-08 15:43:25 +08:00
|
|
|
// in meipra, if EXTENSION_XH3IRQ is enabled. The number of distinct levels
|
|
|
|
// is (1 << IRQ_PRIORITY_BITS). Minimum 0, max 4. Note that multiple priority
|
|
|
|
// levels with a large number of IRQs will have a severe effect on timing.
|
2022-08-08 03:51:12 +08:00
|
|
|
parameter IRQ_PRIORITY_BITS = 0,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
2022-10-06 06:52:20 +08:00
|
|
|
// IRQ_INPUT_BYPASS: disable the input registers on the external interrupts,
|
2022-10-08 15:43:25 +08:00
|
|
|
// to reduce latency by one cycle. Can be applied on an IRQ-by-IRQ basis.
|
|
|
|
// Ignored if EXTENSION_XH3IRQ is disabled.
|
2022-10-06 06:52:20 +08:00
|
|
|
parameter IRQ_INPUT_BYPASS = {NUM_IRQS{1'b0}},
|
|
|
|
|
2021-05-31 01:42:43 +08:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ID registers
|
|
|
|
|
|
|
|
// JEDEC JEP106-compliant vendor ID, can be left at 0 if "not implemented or
|
2021-07-09 00:57:46 +08:00
|
|
|
// [...] this is a non-commercial implementation" (RISC-V spec).
|
2021-05-31 01:42:43 +08:00
|
|
|
// 31:7 is continuation code count, 6:0 is ID. Parity bit is not stored.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MVENDORID_VAL = 32'h0,
|
2021-05-31 01:42:43 +08:00
|
|
|
|
|
|
|
// Implementation ID for this specific version of Hazard3. Git hash is perfect.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MIMPID_VAL = 32'h0,
|
2021-05-31 01:42:43 +08:00
|
|
|
|
2021-07-07 23:08:08 +08:00
|
|
|
// Each core has a single hardware thread. Multiple cores should have unique IDs.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MHARTID_VAL = 32'h0,
|
2021-12-01 11:25:45 +08:00
|
|
|
|
|
|
|
// Pointer to configuration structure blob, or all-zeroes. Must be at least
|
|
|
|
// 4-byte-aligned.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MCONFIGPTR_VAL = 32'h0,
|
2021-07-07 23:08:08 +08:00
|
|
|
|
2021-05-21 09:34:16 +08:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Performance/size options
|
|
|
|
|
|
|
|
// REDUCED_BYPASS: Remove all forwarding paths except X->X (so back-to-back
|
|
|
|
// ALU ops can still run at 1 CPI), to save area.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter REDUCED_BYPASS = 0,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
|
|
|
// MULDIV_UNROLL: Bits per clock for multiply/divide circuit, if present. Must
|
|
|
|
// be a power of 2.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MULDIV_UNROLL = 1,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
|
|
|
// MUL_FAST: Use single-cycle multiply circuit for MUL instructions, retiring
|
2022-07-05 10:37:05 +08:00
|
|
|
// to stage 3. The sequential multiply/divide circuit is still used for MULH*
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MUL_FAST = 0,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
2022-07-05 10:37:05 +08:00
|
|
|
// MUL_FASTER: Retire fast multiply results to stage 2 instead of stage 3.
|
|
|
|
// Throughput is the same, but latency is reduced from 2 cycles to 1 cycle.
|
|
|
|
// Requires: MUL_FAST.
|
|
|
|
parameter MUL_FASTER = 0,
|
|
|
|
|
2021-11-30 02:48:02 +08:00
|
|
|
// MULH_FAST: extend the fast multiply circuit to also cover MULH*, and remove
|
|
|
|
// the multiply functionality from the sequential multiply/divide circuit.
|
2022-07-05 10:37:05 +08:00
|
|
|
// Requires: MUL_FAST
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MULH_FAST = 0,
|
2021-11-30 02:48:02 +08:00
|
|
|
|
2022-04-02 18:40:47 +08:00
|
|
|
// FAST_BRANCHCMP: Instantiate a separate comparator (eq/lt/ltu) for branch
|
2022-04-09 20:49:16 +08:00
|
|
|
// comparisons, rather than using the ALU. Improves fetch address delay,
|
|
|
|
// especially if Zba extension is enabled. Disabling may save area.
|
|
|
|
parameter FAST_BRANCHCMP = 1,
|
2022-04-02 18:40:47 +08:00
|
|
|
|
2022-05-23 20:29:44 +08:00
|
|
|
// RESET_REGFILE: whether to support reset of the general purpose registers.
|
|
|
|
// There are around 1k bits in the register file, so the reset can be
|
|
|
|
// disabled e.g. to permit block-RAM inference on FPGA.
|
2022-10-08 23:24:28 +08:00
|
|
|
parameter RESET_REGFILE = 0,
|
2022-05-23 20:29:44 +08:00
|
|
|
|
2022-06-15 09:05:12 +08:00
|
|
|
// BRANCH_PREDICTOR: enable branch prediction. The branch predictor consists
|
|
|
|
// of a single BTB entry which is allocated on a taken backward branch, and
|
|
|
|
// cleared on a mispredicted nontaken branch, a fence.i or a trap. Successful
|
|
|
|
// prediction eliminates the 1-cyle fetch bubble on a taken branch, usually
|
|
|
|
// making tight loops faster.
|
2022-10-08 15:43:25 +08:00
|
|
|
parameter BRANCH_PREDICTOR = 0,
|
2022-06-15 09:05:12 +08:00
|
|
|
|
|
|
|
// MTVEC_WMASK: Mask of which bits in mtvec are writable. Full writability is
|
|
|
|
// recommended, because a common idiom in setup code is to set mtvec just
|
|
|
|
// past code that may trap, as a hardware "try {...} catch" block.
|
2021-05-31 02:52:46 +08:00
|
|
|
//
|
|
|
|
// - The vectoring mode can be made fixed by clearing the LSB of MTVEC_WMASK
|
|
|
|
//
|
2022-06-15 09:05:12 +08:00
|
|
|
// - In vectored mode, the vector table must be aligned to its size, rounded
|
|
|
|
// up to a power of two.
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter MTVEC_WMASK = 32'hfffffffd,
|
2021-05-21 09:34:16 +08:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Port size parameters (do not modify)
|
|
|
|
|
2022-04-09 20:49:16 +08:00
|
|
|
parameter W_ADDR = 32, // Do not modify
|
|
|
|
parameter W_DATA = 32 // Do not modify
|