Line 50... |
Line 50... |
|
|
// Standard libraries
|
// Standard libraries
|
#include <stdint.h>
|
#include <stdint.h>
|
#include <inttypes.h>
|
#include <inttypes.h>
|
#include <limits.h>
|
#include <limits.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Available CPU Control and Status Registers (CSRs)
|
* Available CPU Control and Status Registers (CSRs)
|
**************************************************************************/
|
**************************************************************************/
|
Line 192... |
Line 194... |
CSR_PMPADDR60 = 0x3ec, /**< 0x3ec - pmpaddr60 (r/w): Physical memory protection address register 60 */
|
CSR_PMPADDR60 = 0x3ec, /**< 0x3ec - pmpaddr60 (r/w): Physical memory protection address register 60 */
|
CSR_PMPADDR61 = 0x3ed, /**< 0x3ed - pmpaddr61 (r/w): Physical memory protection address register 61 */
|
CSR_PMPADDR61 = 0x3ed, /**< 0x3ed - pmpaddr61 (r/w): Physical memory protection address register 61 */
|
CSR_PMPADDR62 = 0x3ee, /**< 0x3ee - pmpaddr62 (r/w): Physical memory protection address register 62 */
|
CSR_PMPADDR62 = 0x3ee, /**< 0x3ee - pmpaddr62 (r/w): Physical memory protection address register 62 */
|
CSR_PMPADDR63 = 0x3ef, /**< 0x3ef - pmpaddr63 (r/w): Physical memory protection address register 63 */
|
CSR_PMPADDR63 = 0x3ef, /**< 0x3ef - pmpaddr63 (r/w): Physical memory protection address register 63 */
|
|
|
|
CSR_TSELECT = 0x7a0, /**< 0x7a0 - tselect (r/(w)): Trigger select */
|
|
CSR_TDATA1 = 0x7a1, /**< 0x7a1 - tdata1 (r/(w)): Trigger data register 0 */
|
|
CSR_TDATA2 = 0x7a2, /**< 0x7a2 - tdata2 (r/(w)): Trigger data register 1 */
|
|
CSR_TDATA3 = 0x7a3, /**< 0x7a3 - tdata3 (r/(w)): Trigger data register 2 */
|
|
CSR_TINFO = 0x7a4, /**< 0x7a4 - tinfo (r/(w)): Trigger info */
|
|
CSR_TCONTROL = 0x7a5, /**< 0x7a5 - tcontrol (r/(w)): Trigger control */
|
|
CSR_MCONTEXT = 0x7a8, /**< 0x7a8 - mcontext (r/(w)): Machine context register */
|
|
CSR_SCONTEXT = 0x7aa, /**< 0x7aa - scontext (r/(w)): Supervisor context register */
|
|
|
|
//CSR_DCSR = 0x7b0, /**< 0x7b0 - dcsr (-/-): Debug status and control register */
|
|
//CSR_DPC = 0x7b1, /**< 0x7b1 - dpc (-/-): Debug program counter */
|
|
//CSR_DSCRATCHC = 0x7b2, /**< 0x7b2 - dscratch (-/-): Debug scratch register */
|
|
|
CSR_MCYCLE = 0xb00, /**< 0xb00 - mcycle (r/w): Machine cycle counter low word */
|
CSR_MCYCLE = 0xb00, /**< 0xb00 - mcycle (r/w): Machine cycle counter low word */
|
CSR_MINSTRET = 0xb02, /**< 0xb02 - minstret (r/w): Machine instructions-retired counter low word */
|
CSR_MINSTRET = 0xb02, /**< 0xb02 - minstret (r/w): Machine instructions-retired counter low word */
|
|
|
CSR_MHPMCOUNTER3 = 0xb03, /**< 0xb03 - mhpmcounter3 (r/w): Machine hardware performance monitor 3 counter low word */
|
CSR_MHPMCOUNTER3 = 0xb03, /**< 0xb03 - mhpmcounter3 (r/w): Machine hardware performance monitor 3 counter low word */
|
CSR_MHPMCOUNTER4 = 0xb04, /**< 0xb04 - mhpmcounter4 (r/w): Machine hardware performance monitor 4 counter low word */
|
CSR_MHPMCOUNTER4 = 0xb04, /**< 0xb04 - mhpmcounter4 (r/w): Machine hardware performance monitor 4 counter low word */
|
Line 270... |
Line 285... |
|
|
CSR_MVENDORID = 0xf11, /**< 0xf11 - mvendorid (r/-): Vendor ID */
|
CSR_MVENDORID = 0xf11, /**< 0xf11 - mvendorid (r/-): Vendor ID */
|
CSR_MARCHID = 0xf12, /**< 0xf12 - marchid (r/-): Architecture ID */
|
CSR_MARCHID = 0xf12, /**< 0xf12 - marchid (r/-): Architecture ID */
|
CSR_MIMPID = 0xf13, /**< 0xf13 - mimpid (r/-): Implementation ID/version */
|
CSR_MIMPID = 0xf13, /**< 0xf13 - mimpid (r/-): Implementation ID/version */
|
CSR_MHARTID = 0xf14, /**< 0xf14 - mhartid (r/-): Hardware thread ID (always 0) */
|
CSR_MHARTID = 0xf14, /**< 0xf14 - mhartid (r/-): Hardware thread ID (always 0) */
|
CSR_MCONFIGPTR = 0xf15 /**< 0xf15 - mconfigptr (r/-): Machine configuration pointer register */
|
CSR_MCONFIGPTR = 0xf15, /**< 0xf15 - mconfigptr (r/-): Machine configuration pointer register */
|
|
|
|
CSR_MXISA = 0xfc0 /**< 0xfc0 - xisa (r/-): NEORV32-specific machine "extended CPU ISA and extensions" */
|
};
|
};
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* CPU <b>mstatus</b> CSR (r/w): Machine status (RISC-V spec.)
|
* CPU <b>mstatus</b> CSR (r/w): Machine status (RISC-V spec.)
|
Line 408... |
Line 425... |
CSR_MISA_MXL_HI = 31 /**< CPU misa CSR (31): MXL.Hi: CPU data width (r/-) */
|
CSR_MISA_MXL_HI = 31 /**< CPU misa CSR (31): MXL.Hi: CPU data width (r/-) */
|
};
|
};
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
|
* CPU <b>mxisa</b> CSR (r/-): Machine _extended_ instruction set extensions (NEORV32-spec.)
|
|
**************************************************************************/
|
|
enum NEORV32_CSR_XISA_enum {
|
|
// ISA (sub-)extensions
|
|
CSR_MXISA_ZICSR = 0, /**< CPU mxisa CSR (0): privileged architecture (r/-)*/
|
|
CSR_MXISA_ZIFENCEI = 1, /**< CPU mxisa CSR (1): instruction stream sync (r/-)*/
|
|
CSR_MXISA_ZMMUL = 2, /**< CPU mxisa CSR (2): hardware mul/div (r/-)*/
|
|
CSR_MXISA_ZXCFU = 3, /**< CPU mxisa CSR (3): custom RISC-V instructions (r/-)*/
|
|
|
|
CSR_MXISA_ZFINX = 5, /**< CPU mxisa CSR (5): FPU using x registers, "F-alternative" (r/-)*/
|
|
CSR_MXISA_ZXSCNT = 6, /**< CPU mxisa CSR (6): reduced-size CPU counters (from Zicntr) (r/-)*/
|
|
CSR_MXISA_ZICNTR = 7, /**< CPU mxisa CSR (7): base instructions, cycle and time CSRs (r/-)*/
|
|
CSR_MXISA_PMP = 8, /**< CPU mxisa CSR (8): physical memory protection (also "Smpmp") (r/-)*/
|
|
CSR_MXISA_ZIHPM = 9, /**< CPU mxisa CSR (9): hardware performance monitors (r/-)*/
|
|
CSR_MXISA_DEBUGMODE = 10, /**< CPU mxisa CSR (10): RISC-V debug mode (r/-)*/
|
|
|
|
// Tuning options
|
|
CSR_MXISA_FASTMUL = 30, /**< CPU mxisa CSR (30): DSP-based multiplication (M extensions only) (r/-)*/
|
|
CSR_MXISA_FASTSHIFT = 31 /**< CPU mxisa CSR (31): parallel logic for shifts (barrel shifters) (r/-)*/
|
|
};
|
|
|
|
|
|
/**********************************************************************//**
|
* CPU <b>mhpmevent</b> hardware performance monitor events
|
* CPU <b>mhpmevent</b> hardware performance monitor events
|
**************************************************************************/
|
**************************************************************************/
|
enum NEORV32_HPMCNT_EVENT_enum {
|
enum NEORV32_HPMCNT_EVENT_enum {
|
HPMCNT_EVENT_CY = 0, /**< CPU mhpmevent CSR (0): Active cycle */
|
HPMCNT_EVENT_CY = 0, /**< CPU mhpmevent CSR (0): Active cycle */
|
HPMCNT_EVENT_IR = 2, /**< CPU mhpmevent CSR (2): Retired instruction */
|
HPMCNT_EVENT_IR = 2, /**< CPU mhpmevent CSR (2): Retired instruction */
|
Line 1235... |
Line 1275... |
**************************************************************************/
|
**************************************************************************/
|
/**@{*/
|
/**@{*/
|
/** SYSINFO module prototype - whole module is read-only */
|
/** SYSINFO module prototype - whole module is read-only */
|
typedef struct __attribute__((packed,aligned(4))) {
|
typedef struct __attribute__((packed,aligned(4))) {
|
const uint32_t CLK; /**< offset 0: clock speed in Hz */
|
const uint32_t CLK; /**< offset 0: clock speed in Hz */
|
const uint32_t CPU; /**< offset 4: CPU core features (#NEORV32_SYSINFO_CPU_enum) */
|
const uint32_t reserved; /**< offset 4: reserved */
|
const uint32_t SOC; /**< offset 8: SoC features (#NEORV32_SYSINFO_SOC_enum) */
|
const uint32_t SOC; /**< offset 8: SoC features (#NEORV32_SYSINFO_SOC_enum) */
|
const uint32_t CACHE; /**< offset 12: cache configuration (#NEORV32_SYSINFO_CACHE_enum) */
|
const uint32_t CACHE; /**< offset 12: cache configuration (#NEORV32_SYSINFO_CACHE_enum) */
|
const uint32_t ISPACE_BASE; /**< offset 16: instruction memory address space base */
|
const uint32_t ISPACE_BASE; /**< offset 16: instruction memory address space base */
|
const uint32_t DSPACE_BASE; /**< offset 20: data memory address space base */
|
const uint32_t DSPACE_BASE; /**< offset 20: data memory address space base */
|
const uint32_t IMEM_SIZE; /**< offset 24: internal instruction memory (IMEM) size in bytes */
|
const uint32_t IMEM_SIZE; /**< offset 24: internal instruction memory (IMEM) size in bytes */
|
Line 1247... |
Line 1287... |
} neorv32_sysinfo_t;
|
} neorv32_sysinfo_t;
|
|
|
/** SYSINFO module hardware access (#neorv32_sysinfo_t) */
|
/** SYSINFO module hardware access (#neorv32_sysinfo_t) */
|
#define NEORV32_SYSINFO (*((volatile neorv32_sysinfo_t*) (0xFFFFFFE0UL)))
|
#define NEORV32_SYSINFO (*((volatile neorv32_sysinfo_t*) (0xFFFFFFE0UL)))
|
|
|
/** NEORV32_SYSINFO.CPU (r/-): Implemented CPU sub-extensions/features */
|
|
enum NEORV32_SYSINFO_CPU_enum {
|
|
SYSINFO_CPU_ZICSR = 0, /**< SYSINFO_CPU (0): Zicsr extension (I sub-extension) available when set (r/-) */
|
|
SYSINFO_CPU_ZIFENCEI = 1, /**< SYSINFO_CPU (1): Zifencei extension (I sub-extension) available when set (r/-) */
|
|
SYSINFO_CPU_ZMMUL = 2, /**< SYSINFO_CPU (2): Zmmul extension (M sub-extension) available when set (r/-) */
|
|
|
|
SYSINFO_CPU_ZFINX = 5, /**< SYSINFO_CPU (5): Zfinx extension (F sub-/alternative-extension) available when set (r/-) */
|
|
SYSINFO_CPU_ZXSCNT = 6, /**< SYSINFO_CPU (6): Custom extension - Small CPU counters: "cycle" & "instret" CSRs have less than 64-bit when set (r/-) */
|
|
SYSINFO_CPU_ZICNTR = 7, /**< SYSINFO_CPU (7): Basic CPU counters available when set (r/-) */
|
|
SYSINFO_CPU_PMP = 8, /**< SYSINFO_CPU (8): PMP (physical memory protection) extension available when set (r/-) */
|
|
SYSINFO_CPU_ZIHPM = 9, /**< SYSINFO_CPU (9): HPM (hardware performance monitors) extension available when set (r/-) */
|
|
SYSINFO_CPU_DEBUGMODE = 10, /**< SYSINFO_CPU (10): RISC-V CPU debug mode available when set (r/-) */
|
|
|
|
SYSINFO_CPU_FASTMUL = 30, /**< SYSINFO_CPU (30): fast multiplications (via FAST_MUL_EN generic) available when set (r/-) */
|
|
SYSINFO_CPU_FASTSHIFT = 31 /**< SYSINFO_CPU (31): fast shifts (via FAST_SHIFT_EN generic) available when set (r/-) */
|
|
};
|
|
|
|
/** NEORV32_SYSINFO.SOC (r/-): Implemented processor devices/features */
|
/** NEORV32_SYSINFO.SOC (r/-): Implemented processor devices/features */
|
enum NEORV32_SYSINFO_SOC_enum {
|
enum NEORV32_SYSINFO_SOC_enum {
|
SYSINFO_SOC_BOOTLOADER = 0, /**< SYSINFO_FEATURES (0) (r/-): Bootloader implemented when 1 (via INT_BOOTLOADER_EN generic) */
|
SYSINFO_SOC_BOOTLOADER = 0, /**< SYSINFO_FEATURES (0) (r/-): Bootloader implemented when 1 (via INT_BOOTLOADER_EN generic) */
|
SYSINFO_SOC_MEM_EXT = 1, /**< SYSINFO_FEATURES (1) (r/-): External bus interface implemented when 1 (via MEM_EXT_EN generic) */
|
SYSINFO_SOC_MEM_EXT = 1, /**< SYSINFO_FEATURES (1) (r/-): External bus interface implemented when 1 (via MEM_EXT_EN generic) */
|
SYSINFO_SOC_MEM_INT_IMEM = 2, /**< SYSINFO_FEATURES (2) (r/-): Processor-internal instruction memory implemented when 1 (via MEM_INT_IMEM_EN generic) */
|
SYSINFO_SOC_MEM_INT_IMEM = 2, /**< SYSINFO_FEATURES (2) (r/-): Processor-internal instruction memory implemented when 1 (via MEM_INT_IMEM_EN generic) */
|
Line 1320... |
Line 1343... |
};
|
};
|
/**@}*/
|
/**@}*/
|
|
|
|
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
// Include all IO driver headers
|
// Include all system header files
|
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
// cpu core
|
|
#include "neorv32_cpu.h"
|
|
|
|
// intrinsics
|
// intrinsics
|
#include "neorv32_intrinsics.h"
|
#include "neorv32_intrinsics.h"
|
|
|
|
// cpu core
|
|
#include "neorv32_cpu.h"
|
|
#include "neorv32_cpu_cfu.h"
|
|
|
// neorv32 runtime environment
|
// neorv32 runtime environment
|
#include "neorv32_rte.h"
|
#include "neorv32_rte.h"
|
|
|
// io/peripheral devices
|
// io/peripheral devices
|
#include "neorv32_cfs.h"
|
#include "neorv32_cfs.h"
|