Merge pull request #14 from micprog/ibex_int

Add compatibility for ibex
This commit is contained in:
bluew 2021-02-02 12:01:34 +01:00 committed by GitHub
commit 252cecba03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 539 additions and 56 deletions

16
configs/pulp_ibex.sh Normal file
View file

@ -0,0 +1,16 @@
#!/bin/bash -e
export PULPRT_TARGET=pulp
export PULPRUN_TARGET=pulp
export USE_IBEX=1
if [ -n "${ZSH_VERSION:-}" ]; then
DIR="$(readlink -f -- "${(%):-%x}")"
scriptDir="$(dirname $DIR)"
else
scriptDir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
fi
source $scriptDir/common.sh

View file

@ -0,0 +1,16 @@
#!/bin/bash -e
export PULPRT_TARGET=pulpissimo
export PULPRUN_TARGET=pulpissimo
export USE_IBEX=1
if [ -n "${ZSH_VERSION:-}" ]; then
DIR="$(readlink -f -- "${(%):-%x}")"
scriptDir="$(dirname $DIR)"
else
scriptDir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
fi
source $scriptDir/common.sh

View file

@ -23,7 +23,11 @@
#include "archi/gpio/gpio_v3.h"
#include "archi/riscv/priv_1_10.h"
#ifdef __ibex__
#include "archi/ibex/mhpm.h"
#else // __ibex__
#include "archi/riscv/pcer_v2.h"
#endif // __ibex__
#include "archi/itc/itc_v1.h"
#include "archi/chips/pulp/memory_map.h"

View file

@ -24,7 +24,11 @@
//#include "archi/periph_v2.h"
#include "archi/gpio/gpio_v3.h"
#include "archi/riscv/priv_1_10.h"
#ifdef __ibex__
#include "archi/ibex/mhpm.h"
#else // __ibex__
#include "archi/riscv/pcer_v2.h"
#endif // __ibex__
#include "archi/chips/pulpissimo/memory_map.h"
#include "archi/chips/pulpissimo/apb_soc.h"

96
include/archi/ibex/mhpm.h Normal file
View file

@ -0,0 +1,96 @@
/*
* Copyright (C) 2020 ETH Zurich and University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _ARCHI_IBEX_MHPM_H
#define _ARCHI_IBEX_MHPM_H
/*
* Bit definitions for Performance counters mode registers
* (see https://ibex-core.readthedocs.io/en/latest/03_reference/performance_counters.html)
*/
#define IBEX_MHPMCOUNTER_BASE 0xB00
// Currently the additional register for more perf. counting is not yet implemented
// ibex performance counters
#define IBEX_NUM_CYCLES 0 /* NumCycles: Number of cycles */
#define IBEX_NUM_INSTR_RET 2 /* NumInstrRet: Number of instructions retired */
#define IBEX_NUM_CYCLES_LSU 3 /* NumCyclesLSU: Number of cycles waiting for data memory */
#define IBEX_NUM_CYCLES_IF 4 /* NumCyclesIF: Cycles waiting for instruction fetches, i.e., number of instructions wasted due to non-ideal caching */
#define IBEX_NUM_LOADS 5 /* NumLoads: Number of data memory loads. Misaligned accesses are counted as two accesses */
#define IBEX_NUM_STORES 6 /* NumStores: Number of data memory stores. Misaligned accesses are counted as two accesses */
#define IBEX_NUM_JUMPS 7 /* NumJumps: Number of unconditional jumps (j, jal, jr, jalr) */
#define IBEX_NUM_BRANCHES 8 /* NumBranches: Number of branches (conditional) */
#define IBEX_NUM_BRANCHES_TAKEN 9 /* NumBranchesTaken: Number of taken branches (conditional) */
#define IBEX_NUM_INSTR_RET_C 10 /* NumInstrRetC: Number of compressed instructions retired */
#define IBEX_NUM_CYCLES_MUL_WAIT 11 /* NumCyclesMulWait: Cycles waiting for multiply to complete */
#define IBEX_NUM_CYCLES_DIV_WAIT 12 /* NumCyclesDivWait: Cycles waiting for divide to complete */
// riscv map for ibex counters
#define CSR_PCER_CYCLES IBEX_NUM_CYCLES /* Count the number of cycles the core was running */
#define CSR_PCER_INSTR IBEX_NUM_INSTR_RET /* Count the number of instructions executed */
#define CSR_PCER_LD_STALL IBEX_NUM_CYCLES_LSU /* Number of load use hazards */
#define CSR_PCER_IMISS IBEX_NUM_CYCLES_IF /* Cycles waiting for instruction fetches. i.e. the number of instructions wasted due to non-ideal caches */
#define CSR_PCER_LD IBEX_NUM_LOADS /* Number of memory loads executed. Misaligned accesses are counted twice */
#define CSR_PCER_ST IBEX_NUM_STORES /* Number of memory stores executed. Misaligned accesses are counted twice */
#define CSR_PCER_JUMP IBEX_NUM_JUMPS /* Number of jump instructions seen, i.e. j, jr, jal, jalr */
#define CSR_PCER_BRANCH IBEX_NUM_BRANCHES /* Number of branch instructions seen, i.e. bf, bnf */
#define CSR_PCER_TAKEN_BRANCH IBEX_NUM_BRANCHES_TAKEN /* Number of taken branch instructions seen, i.e. bf, bnf */
#define CSR_PCER_RVC IBEX_NUM_INSTR_RET_C /* Number of compressed instructions */
// Not implemented in ibex
// #define CSR_PCER_ELW 0 /* Cycles wasted due to ELW instruction */
// #define CSR_PCER_JMP_STALL 0 /* Number of jump register hazards */
// External perf counters
#define IBEX_EXTERNAL_BASE 13
#define CSR_PCER_LD_EXT 13 /* Number of memory loads to EXT executed. Misaligned accesses are counted twice. Every non-TCDM access is considered external */
#define CSR_PCER_ST_EXT 14 /* Number of memory stores to EXT executed. Misaligned accesses are counted twice. Every non-TCDM access is considered external */
#define CSR_PCER_LD_EXT_CYC 15 /* Cycles used for memory loads to EXT. Every non-TCDM access is considered external */
#define CSR_PCER_ST_EXT_CYC 16 /* Cycles used for memory stores to EXT. Every non-TCDM access is considered external */
#define CSR_PCER_TCDM_CONT 17 /* Cycles wasted due to TCDM/log-interconnect contention */
#define CSR_PCER_NB_EVENTS 16
#define CSR_PCER_TOP_EVENT 17
#define CSR_PCER_NB_INTERNAL_EVENTS 11
#define CSR_PCER_TOP_INTERNAL_EVENTS 12
#define CSR_NB_PCCR 32
// Gives from the event ID, the HW mask that can be stored (with an OR with other events mask) to the PCER
#define CSR_PCER_EVENT_MASK(eventId) (1<<(eventId))
#define CSR_PCER_ALL_EVENTS_MASK 0xffffffff
#define CSR_PCER_NAME(id) \
( id == IBEX_NUM_CYCLES ? "Cycles" : \
id == IBEX_NUM_INSTR_RET ? "Instructions" : \
id == IBEX_NUM_CYCLES_LSU ? "LD_Stall" : \
id == IBEX_NUM_CYCLES_IF ? "IMISS" : \
id == IBEX_NUM_LOADS ? "LD" : \
id == IBEX_NUM_STORES ? "ST" : \
id == IBEX_NUM_JUMPS ? "JUMP" : \
id == IBEX_NUM_BRANCHES ? "BRANCH" : \
id == IBEX_NUM_BRANCHES_TAKEN ? "TAKEN_BRANCH" : \
id == IBEX_NUM_INSTR_RET_C ? "RVC" : \
id == 16 ? "LD_EXT" : \
id == 17 ? "ST_EXT" : \
id == 18 ? "LD_EXT_CYC" : \
id == 19 ? "ST_EXT_CYC" : \
id == 20 ? "TCDM_CONT" : \
"NA")
#endif

View file

@ -21,23 +21,23 @@
* Bit definitions for Performance counters mode registers
*
*/
#define CSR_PCER_CYCLES 0 /* Count the number of cycles the core was running */
#define CSR_PCER_INSTR 1 /* Count the number of instructions executed */
#define CSR_PCER_LD_STALL 2 /* Number of load use hazards */
#define CSR_PCER_JMP_STALL 3 /* Number of jump register hazards */
#define CSR_PCER_IMISS 4 /* Cycles waiting for instruction fetches. i.e. the number of instructions wasted due to non-ideal caches */
#define CSR_PCER_LD 5 /* Number of memory loads executed. Misaligned accesses are counted twice */
#define CSR_PCER_ST 6 /* Number of memory stores executed. Misaligned accesses are counted twice */
#define CSR_PCER_JUMP 7 /* Number of jump instructions seen, i.e. j, jr, jal, jalr */
#define CSR_PCER_BRANCH 8 /* Number of branch instructions seen, i.e. bf, bnf */
#define CSR_PCER_TAKEN_BRANCH 9 /* Number of taken branch instructions seen, i.e. bf, bnf */
#define CSR_PCER_RVC 10 /* Number of compressed instructions */
#define CSR_PCER_ELW 11 /* Cycles wasted due to ELW instruction */
#define CSR_PCER_LD_EXT 12 /* Number of memory loads to EXT executed. Misaligned accesses are counted twice. Every non-TCDM access is considered external */
#define CSR_PCER_ST_EXT 13 /* Number of memory stores to EXT executed. Misaligned accesses are counted twice. Every non-TCDM access is considered external */
#define CSR_PCER_LD_EXT_CYC 14 /* Cycles used for memory loads to EXT. Every non-TCDM access is considered external */
#define CSR_PCER_ST_EXT_CYC 15 /* Cycles used for memory stores to EXT. Every non-TCDM access is considered external */
#define CSR_PCER_TCDM_CONT 16 /* Cycles wasted due to TCDM/log-interconnect contention */
#define CSR_PCER_CYCLES 0 /* Count the number of cycles the core was running */
#define CSR_PCER_INSTR 1 /* Count the number of instructions executed */
#define CSR_PCER_LD_STALL 2 /* Number of load use hazards */
#define CSR_PCER_JMP_STALL 3 /* Number of jump register hazards */
#define CSR_PCER_IMISS 4 /* Cycles waiting for instruction fetches. i.e. the number of instructions wasted due to non-ideal caches */
#define CSR_PCER_LD 5 /* Number of memory loads executed. Misaligned accesses are counted twice */
#define CSR_PCER_ST 6 /* Number of memory stores executed. Misaligned accesses are counted twice */
#define CSR_PCER_JUMP 7 /* Number of jump instructions seen, i.e. j, jr, jal, jalr */
#define CSR_PCER_BRANCH 8 /* Number of branch instructions seen, i.e. bf, bnf */
#define CSR_PCER_TAKEN_BRANCH 9 /* Number of taken branch instructions seen, i.e. bf, bnf */
#define CSR_PCER_RVC 10 /* Number of compressed instructions */
#define CSR_PCER_ELW 11 /* Cycles wasted due to ELW instruction */
#define CSR_PCER_LD_EXT 12 /* Number of memory loads to EXT executed. Misaligned accesses are counted twice. Every non-TCDM access is considered external */
#define CSR_PCER_ST_EXT 13 /* Number of memory stores to EXT executed. Misaligned accesses are counted twice. Every non-TCDM access is considered external */
#define CSR_PCER_LD_EXT_CYC 14 /* Cycles used for memory loads to EXT. Every non-TCDM access is considered external */
#define CSR_PCER_ST_EXT_CYC 15 /* Cycles used for memory stores to EXT. Every non-TCDM access is considered external */
#define CSR_PCER_TCDM_CONT 16 /* Cycles wasted due to TCDM/log-interconnect contention */
#define CSR_PCER_NB_EVENTS 17
@ -51,6 +51,24 @@
#define CSR_PCMR_ACTIVE 0x1 /* Activate counting */
#define CSR_PCMR_SATURATE 0x2 /* Activate saturation */
#define CSR_PCER_NAME(id) (id == 0 ? "Cycles" : id == 1 ? "Instructions" : id == 2 ? "LD_Stall" : id == 3 ? "Jmp_Stall" : id == 4 ? "IMISS" : id == 5 ? "LD" : id == 6 ? "ST" : id == 7 ? "JUMP" : id == 8 ? "BRANCH" : id == 9 ? "TAKEN_BRANCH" : id == 10 ? "RVC" : id == 11 ? "ELW" : id == 12 ? "LD_EXT" : id == 13 ? "ST_EXT" : id == 14 ? "LD_EXT_CYC" : id == 15 ? "ST_EXT_CYC" : id == 16 ? "TCDM_CONT" : "NA")
#define CSR_PCER_NAME(id) \
( id == 0 ? "Cycles" : \
id == 1 ? "Instructions" : \
id == 2 ? "LD_Stall" : \
id == 3 ? "Jmp_Stall" : \
id == 4 ? "IMISS" : \
id == 5 ? "LD" : \
id == 6 ? "ST" : \
id == 7 ? "JUMP" : \
id == 8 ? "BRANCH" : \
id == 9 ? "TAKEN_BRANCH" : \
id == 10 ? "RVC" : \
id == 11 ? "ELW" : \
id == 12 ? "LD_EXT" : \
id == 13 ? "ST_EXT" : \
id == 14 ? "LD_EXT_CYC" : \
id == 15 ? "ST_EXT_CYC" : \
id == 16 ? "TCDM_CONT" : \
"NA")
#endif

View file

@ -143,6 +143,8 @@ static inline void perf_start(void) {
#ifdef __riscv__
cpu_perf_conf_events(CSR_PCER_ALL_EVENTS_MASK);
cpu_perf_conf(CSR_PCMR_ACTIVE | CSR_PCMR_SATURATE);
#elif defined(__ibex__)
cpu_perf_start();
#else
cpu_perf_conf_events(SPR_PCER_ALL_EVENTS_MASK);
cpu_perf_conf(SPR_PCMR_ACTIVE | SPR_PCMR_SATURATE);
@ -159,7 +161,7 @@ static inline void perf_start(void) {
*/
static inline void perf_stop(void) {
#ifdef CSR_PCER_ALL_EVENTS_MASK
cpu_perf_conf(0);
cpu_perf_stop();
#endif
// TODO this is failing on most targets, please include that also for specific ones
#if 0
@ -172,7 +174,9 @@ static inline void perf_stop(void) {
*/
static inline void perf_reset(void) {
#ifdef CSR_PCER_ALL_EVENTS_MASK
perf_stop();
cpu_perf_setall(0);
perf_start();
#endif
// TODO this is failing on most targets, please include that also for specific ones
#if 0
@ -188,6 +192,8 @@ static inline void perf_enable_id( int eventid){
#ifdef __riscv__
cpu_perf_conf_events(CSR_PCER_EVENT_MASK(eventid));
cpu_perf_conf(CSR_PCMR_ACTIVE | CSR_PCMR_SATURATE);
#elif defined(__ibex__)
cpu_perf_conf_events(CSR_PCER_EVENT_MASK(eventid));
#else
cpu_perf_conf_events(SPR_PCER_EVENT_MASK(eventid));
cpu_perf_conf(SPR_PCMR_ACTIVE | SPR_PCMR_SATURATE);

View file

@ -17,7 +17,11 @@
#ifndef __HAL_CHIPS_PULP_PULP_H__
#define __HAL_CHIPS_PULP_PULP_H__
#ifdef __ibex__
#include "hal/ibex/ibex.h"
#else // __ibex__
#include "hal/riscv/riscv_v5.h"
#endif // __ibex__
#include "hal/eu/eu_v3.h"
#include "hal/itc/itc_v1.h"
#include "hal/dma/mchan_v7.h"

View file

@ -17,7 +17,11 @@
#ifndef __HAL_CHIPS_PULPISSIMO_PULP_H__
#define __HAL_CHIPS_PULPISSIMO_PULP_H__
#ifdef __ibex__
#include "hal/ibex/ibex.h"
#else // __ibex__
#include "hal/riscv/riscv_v5.h"
#endif // __ibex__
#include "hal/itc/itc_v1.h"
#include "hal/timer/timer_v2.h"
#include "hal/soc_eu/soc_eu_v2.h"

View file

@ -294,7 +294,7 @@ static inline unsigned int plp_dma_getCmd(int ext2loc, unsigned int size, int is
res = __builtin_bitinsert(res, broadcast, 1, MCHAN_CMD_CMD_BLE_BIT);
return res;
#else
return (ext2loc << MCHAN_CMD_CMD_TYPE_BIT) | (PLP_DMA_INC << MCHAN_CMD_CMD_INC_BIT) | (is2D << MCHAN_CMD_CMD__2D_EXT_BIT) | (size << MCHAN_CMD_CMD_LEN_BIT) | (trigEvt<<MCHAN_CMD_ELE_BIT) | (trigIrq<<MCHAN_CMD_ILE_BIT) | (broadcast<<MCHAN_CMD_CMD_BLE_BIT);
return (ext2loc << MCHAN_CMD_CMD_TYPE_BIT) | (PLP_DMA_INC << MCHAN_CMD_CMD_INC_BIT) | (is2D << MCHAN_CMD_CMD__2D_EXT_BIT) | (size << MCHAN_CMD_CMD_LEN_BIT) | (trigEvt<<MCHAN_CMD_CMD_ELE_BIT) | (trigIrq<<MCHAN_CMD_CMD_ILE_BIT) | (broadcast<<MCHAN_CMD_CMD_BLE_BIT);
#endif
}

View file

@ -39,7 +39,7 @@
static inline unsigned int evt_read32(unsigned int base, unsigned int offset)
{
unsigned int value;
#if !defined(__LLVM__) && ((defined(OR1K_VERSION) && OR1K_VERSION >= 5) || (defined(RISCV_VERSION) && RISCV_VERSION >= 4))
#if !defined(__LLVM__) && ((defined(OR1K_VERSION) && OR1K_VERSION >= 5) || (defined(RISCV_VERSION) && RISCV_VERSION >= 4)) && !defined(RV_ISA_RV32)
value = __builtin_pulp_event_unit_read((int *)base, offset);
#else
__asm__ __volatile__ ("" : : : "memory");

293
include/hal/ibex/ibex.h Normal file
View file

@ -0,0 +1,293 @@
/*
* Copyright (C) 2020 ETH Zurich and University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __HAL_IBEX_IBEX_H__
#define __HAL_IBEX_IBEX_H__
#include "archi/pulp.h"
#include "archi/riscv/builtins_v2_emu.h"
// For PULP, ibex added non-standard irqs to allow for 32 fast interrupts.
// These use custom CSRs: MIE: 0x7D0, MTVEC: 0x7D1, MIP: 0x7D2
#define SR_MTVEC 0x7D1
#define hal_spr_read_then_clr(reg,val) \
({ \
int state; \
asm volatile ("csrrc %0, %1, %2" : "=r" (state) : "I" (reg), "I" (val) ); \
state; \
})
#define hal_spr_read_then_set(reg,val) \
({ \
int state; \
asm volatile ("csrrs %0, %1, %2" : "=r" (state) : "I" (reg), "I" (val) ); \
state; \
})
#define hal_spr_read_then_clr_from_reg(reg,val) \
({ \
int state; \
asm volatile ("csrrc %0, %1, %2" : "=r" (state) : "I" (reg), "r" (val) ); \
state; \
})
#define hal_spr_read_then_set(reg,val) \
({ \
int state; \
asm volatile ("csrrs %0, %1, %2" : "=r" (state) : "I" (reg), "I" (val) ); \
state; \
})
#define hal_spr_read_then_set_from_reg(reg,val) \
({ \
int state; \
asm volatile ("csrrs %0, %1, %2" : "=r" (state) : "I" (reg), "r" (val) ); \
state; \
})
#define hal_spr_write(reg,val) \
({do { \
asm volatile ("csrw %0, %1" : : "I" (reg), "r" (val) ); \
} while(0); \
})
#define hal_spr_read(reg) \
({ \
int result; \
asm volatile ("csrr %0, %1" : "=r" (result) : "I" (reg) ); \
result; \
})
#define hal_mepc_read() hal_spr_read(RV_CSR_MEPC)
static inline unsigned int core_id() {
int hart_id;
asm("csrr %0, 0xF14" : "=r" (hart_id) : );
// in PULP the hart id is {22'b0, cluster_id, core_id}
return hart_id & 0x01f;
}
static inline unsigned int cluster_id() {
int hart_id;
asm("csrr %0, 0xF14" : "=r" (hart_id) : );
// in PULP the hart id is {22'b0, cluster_id, core_id}
return (hart_id >> 5) & 0x3f;
}
static inline unsigned int hal_core_id() {
return core_id();
}
static inline unsigned int hal_cluster_id() {
return cluster_id();
}
// TODO replace by compiler builtin
static inline __attribute__((always_inline)) unsigned int hal_has_fc() {
#ifdef ARCHI_HAS_FC
return 1;
#else
return 0;
#endif
}
static inline __attribute__((always_inline)) unsigned int hal_is_fc() {
#ifndef ARCHI_HAS_FC
return 0;
#else
if (hal_has_fc()) return hal_cluster_id() == ARCHI_FC_CID;
else return 0;
#endif
}
static inline int hal_irq_disable()
{
int irq = hal_spr_read_then_clr(0x300, 0x1<<3);
// This memory barrier is needed to prevent the compiler to cross the irq barrier
__asm__ __volatile__ ("" : : : "memory");
return irq;
}
static inline void hal_irq_restore(int state)
{
// This memory barrier is needed to prevent the compiler to cross the irq barrier
__asm__ __volatile__ ("" : : : "memory");
hal_spr_write(0x300, state);
}
static inline void hal_irq_enable()
{
// This memory barrier is needed to prevent the compiler to cross the irq barrier
__asm__ __volatile__ ("" : : : "memory");
hal_spr_read_then_set(0x300, 0x1<<3);
}
/*
* PERFORMANCE COUNTERS
*
* API for accessing performance counters registers.
* Have a look at file mhpm.h to speficy registers through defines
* CSR_PCER_* and CSR_PCMR_*
*/
#define PCER_NB_EVENTS CSR_PCER_NB_EVENTS
#define PCER_ALL_EVENTS_MASK CSR_PCER_ALL_EVENTS_MASK
/* Configure the active events. eventMask is an OR of events got through SPR_PCER_EVENT_MASK */
static inline void cpu_perf_conf_events(unsigned int eventMask)
{
#ifndef PLP_NO_PERF_COUNTERS
unsigned int test = ~eventMask;
asm volatile ("csrw 0x320, %0" : "+r" (test));
#endif
}
/* Return events configuration */
static inline unsigned int cpu_perf_conf_events_get()
{
#ifndef PLP_NO_PERF_COUNTERS
unsigned int result;
asm volatile ("csrr %0, 0x320" : "=r" (result));
return ~result;
#else
return 0;
#endif
}
/* Configure the mode. confMask is an OR of all SPR_PCMR_* macros */
static inline void cpu_perf_conf(unsigned int confMask)
{
#ifndef PLP_NO_PERF_COUNTERS
asm volatile ("csrw 0x320, %0" :: "r" (~confMask));
#endif
}
/* Starts counting in all counters. As this is using the mode register,
* the rest of the config can be given through conf parameter */
static inline void cpu_perf_start() {
#ifndef PLP_NO_PERF_COUNTERS
cpu_perf_conf(CSR_PCER_ALL_EVENTS_MASK);
#endif
}
/* Stops counting in all counters. As this is using the mode register,
* the rest of the config can be given through conf parameter */
static inline void cpu_perf_stop() {
#ifndef PLP_NO_PERF_COUNTERS
cpu_perf_conf(0);
#endif
}
/* Set the specified counter to the specified value */
static inline void cpu_perf_set(unsigned int counterId, unsigned int value) {
switch(counterId) {
case 0: asm volatile ("csrw 0xB00, %0" : : "r" (value) ); break;
case 1: break; // This CSR does not exist
case 2: asm volatile ("csrw 0xB02, %0" : : "r" (value) ); break;
case 3: asm volatile ("csrw 0xB03, %0" : : "r" (value) ); break;
case 4: asm volatile ("csrw 0xB04, %0" : : "r" (value) ); break;
case 5: asm volatile ("csrw 0xB05, %0" : : "r" (value) ); break;
case 6: asm volatile ("csrw 0xB06, %0" : : "r" (value) ); break;
case 7: asm volatile ("csrw 0xB07, %0" : : "r" (value) ); break;
case 8: asm volatile ("csrw 0xB08, %0" : : "r" (value) ); break;
case 9: asm volatile ("csrw 0xB09, %0" : : "r" (value) ); break;
case 10: asm volatile ("csrw 0xB0A, %0" : : "r" (value) ); break;
case 11: asm volatile ("csrw 0xB0B, %0" : : "r" (value) ); break;
case 12: asm volatile ("csrw 0xB0C, %0" : : "r" (value) ); break;
case 13: asm volatile ("csrw 0xB0D, %0" : : "r" (value) ); break;
case 14: asm volatile ("csrw 0xB0E, %0" : : "r" (value) ); break;
case 15: asm volatile ("csrw 0xB0F, %0" : : "r" (value) ); break;
case 16: asm volatile ("csrw 0xB10, %0" : : "r" (value) ); break;
case 17: asm volatile ("csrw 0xB11, %0" : : "r" (value) ); break;
case 18: asm volatile ("csrw 0xB12, %0" : : "r" (value) ); break;
case 19: asm volatile ("csrw 0xB13, %0" : : "r" (value) ); break;
case 20: asm volatile ("csrw 0xB14, %0" : : "r" (value) ); break;
case 21: asm volatile ("csrw 0xB15, %0" : : "r" (value) ); break;
case 22: asm volatile ("csrw 0xB16, %0" : : "r" (value) ); break;
case 23: asm volatile ("csrw 0xB17, %0" : : "r" (value) ); break;
case 24: asm volatile ("csrw 0xB18, %0" : : "r" (value) ); break;
case 25: asm volatile ("csrw 0xB19, %0" : : "r" (value) ); break;
case 26: asm volatile ("csrw 0xB1A, %0" : : "r" (value) ); break;
case 27: asm volatile ("csrw 0xB1B, %0" : : "r" (value) ); break;
case 28: asm volatile ("csrw 0xB1C, %0" : : "r" (value) ); break;
case 29: asm volatile ("csrw 0xB1D, %0" : : "r" (value) ); break;
case 30: asm volatile ("csrw 0xB1E, %0" : : "r" (value) ); break;
case 31: asm volatile ("csrw 0xB1F, %0" : : "r" (value) ); break;
}
}
/* Set all counters to the specified value */
static inline void cpu_perf_setall(unsigned int value) {
#ifndef PLP_NO_PERF_COUNTERS
// This implementation is rather slow. ri5cy has a register to set all, ibex does not.
for (int i = 0; i < CSR_PCER_TOP_EVENT; i++) {
cpu_perf_set(i, value);
}
#endif
}
/* Return the value of the specified counter */
static inline unsigned int cpu_perf_get(const unsigned int counterId) {
#ifndef PLP_NO_PERF_COUNTERS
unsigned int value;
switch(counterId) {
case 0: asm volatile ("csrr %0, 0xB00" : "=r" (value)); break;
case 1: break; // This CSR does not exist
case 2: asm volatile ("csrr %0, 0xB02" : "=r" (value)); break;
case 3: asm volatile ("csrr %0, 0xB03" : "=r" (value)); break;
case 4: asm volatile ("csrr %0, 0xB04" : "=r" (value)); break;
case 5: asm volatile ("csrr %0, 0xB05" : "=r" (value)); break;
case 6: asm volatile ("csrr %0, 0xB06" : "=r" (value)); break;
case 7: asm volatile ("csrr %0, 0xB07" : "=r" (value)); break;
case 8: asm volatile ("csrr %0, 0xB08" : "=r" (value)); break;
case 9: asm volatile ("csrr %0, 0xB09" : "=r" (value)); break;
case 10: asm volatile ("csrr %0, 0xB0A" : "=r" (value)); break;
case 11: asm volatile ("csrr %0, 0xB0B" : "=r" (value)); break;
case 12: asm volatile ("csrr %0, 0xB0C" : "=r" (value)); break;
case 13: asm volatile ("csrr %0, 0xB0D" : "=r" (value)); break;
case 14: asm volatile ("csrr %0, 0xB0E" : "=r" (value)); break;
case 15: asm volatile ("csrr %0, 0xB0F" : "=r" (value)); break;
case 16: asm volatile ("csrr %0, 0xB10" : "=r" (value)); break;
case 17: asm volatile ("csrr %0, 0xB11" : "=r" (value)); break;
case 18: asm volatile ("csrr %0, 0xB12" : "=r" (value)); break;
case 19: asm volatile ("csrr %0, 0xB13" : "=r" (value)); break;
case 20: asm volatile ("csrr %0, 0xB14" : "=r" (value)); break;
case 21: asm volatile ("csrr %0, 0xB15" : "=r" (value)); break;
case 22: asm volatile ("csrr %0, 0xB16" : "=r" (value)); break;
case 23: asm volatile ("csrr %0, 0xB17" : "=r" (value)); break;
case 24: asm volatile ("csrr %0, 0xB18" : "=r" (value)); break;
case 25: asm volatile ("csrr %0, 0xB19" : "=r" (value)); break;
case 26: asm volatile ("csrr %0, 0xB1A" : "=r" (value)); break;
case 27: asm volatile ("csrr %0, 0xB1B" : "=r" (value)); break;
case 28: asm volatile ("csrr %0, 0xB1C" : "=r" (value)); break;
case 29: asm volatile ("csrr %0, 0xB1D" : "=r" (value)); break;
case 30: asm volatile ("csrr %0, 0xB1E" : "=r" (value)); break;
case 31: asm volatile ("csrr %0, 0xB1F" : "=r" (value)); break;
}
return value;
#else
return 0;
#endif
}
static inline const char *cpu_perf_name(int event) {
return CSR_PCER_NAME(event);
}
#endif

View file

@ -146,7 +146,8 @@ static inline unsigned int core_id() {
return hart_id & 0x01f;
}
static inline unsigned int cluster_id() { int hart_id;
static inline unsigned int cluster_id() {
int hart_id;
#if RISCV_VERSION >= 4 && !defined(RISCV_1_7)
#if PULP_CHIP_FAMILY == CHIP_GAP
asm("csrr %0, 0x014" : "=r" (hart_id) : );
@ -288,8 +289,8 @@ static inline void hal_irq_enable()
* PERFORMANCE COUNTERS
*
* API for accessing performance counters registers.
* Have a look at file spr-defs.h to speficy registers through defines
* SPR_PCER_* and SPR_PCMR_*
* Have a look at file pcer_v2.h to speficy registers through defines
* CSR_PCER_* and CSR_PCMR_*
*/
#define PCER_NB_EVENTS CSR_PCER_NB_EVENTS
@ -335,9 +336,9 @@ static inline void cpu_perf_start(unsigned int conf) {
/* Stops counting in all counters. As this is using the mode register,
* the rest of the config can be given through conf parameter */
static inline void cpu_perf_stop(unsigned int conf) {
static inline void cpu_perf_stop() {
#ifndef PLP_NO_PERF_COUNTERS
cpu_perf_conf(conf); // TODO
cpu_perf_conf(0); // TODO
#endif
}
@ -399,26 +400,7 @@ static inline unsigned int cpu_perf_get(const unsigned int counterId) {
}
static inline const char *cpu_perf_name(int event) {
switch (event)
{
case 0: return "CYCLES";
case 1: return "INSTR";
case 2: return "LD_STALL";
case 3: return "JMP_STALL";
case 4: return "IMISS";
case 5: return "LD";
case 6: return "ST";
case 7: return "JUMP";
case 8: return "BRANCH";
case 9: return "TAKEN_BRANCH";
case 10: return "RVC";
case 11: return "LD_EXT";
case 12: return "ST_EXT";
case 13: return "LD_EXT_CYC";
case 14: return "ST_EXT_CYC";
case 15: return "TCDM_CONT";
}
return (char *)0;
return CSR_PCER_NAME(event);
}

View file

@ -108,9 +108,9 @@ static inline unsigned int rt_irq_get_fc_vector_base()
#if defined(__RISCV_GENERIC__)
return hal_spr_read(0x305) & ~1;
#elif defined(ARCHI_CORE_HAS_SECURITY) && !defined(ARCHI_CORE_HAS_1_10)
return __builtin_pulp_spr_read(SR_MTVEC);
return hal_spr_read(SR_MTVEC);
#elif defined(ARCHI_CORE_HAS_1_10)
return __builtin_pulp_spr_read(SR_MTVEC) & ~1;
return hal_spr_read(SR_MTVEC) & ~1;
#elif defined(APB_SOC_VERSION) && APB_SOC_VERSION >= 2
return apb_soc_bootaddr_get();
#endif
@ -118,8 +118,10 @@ static inline unsigned int rt_irq_get_fc_vector_base()
else
{
#if defined(ARCHI_HAS_CLUSTER)
#if defined(ARCHI_CORE_HAS_1_10)
return __builtin_pulp_spr_read(SR_MTVEC) & ~1;
#if defined(__RISCV_GENERIC__)
return hal_spr_read(0x305) & ~1;
#elif defined(ARCHI_CORE_HAS_1_10)
return hal_spr_read(SR_MTVEC) & ~1;
#elif defined(ARCHI_CLUSTER_CTRL_ADDR)
return plp_ctrl_bootaddr_get();
#endif
@ -138,9 +140,9 @@ static inline void rt_irq_set_fc_vector_base(unsigned int base)
#if defined(__RISCV_GENERIC__)
hal_spr_write(0x305, base);
#elif defined(ARCHI_CORE_HAS_SECURITY)
__builtin_pulp_spr_write(SR_MTVEC, base);
hal_spr_write(SR_MTVEC, base);
#elif defined(ARCHI_CORE_HAS_1_10)
__builtin_pulp_spr_write(SR_MTVEC, base | 1);
hal_spr_write(SR_MTVEC, base | 1);
#elif defined(APB_SOC_VERSION) && APB_SOC_VERSION >= 2
apb_soc_bootaddr_set(base);
#endif
@ -148,8 +150,10 @@ static inline void rt_irq_set_fc_vector_base(unsigned int base)
else
{
#if defined(ARCHI_HAS_CLUSTER)
#if defined(ARCHI_CORE_HAS_1_10)
__builtin_pulp_spr_write(SR_MTVEC, base | 1);
#if defined(__RISCV_GENERIC__)
hal_spr_write(0x305, base);
#elif defined(ARCHI_CORE_HAS_1_10)
hal_spr_write(SR_MTVEC, base | 1);
#elif defined(ARCHI_CLUSTER_CTRL_ADDR)
plp_ctrl_bootaddr_set(base);
#endif

View file

@ -145,7 +145,25 @@ void check_uint32(testresult_t* result, const char* fail_msg, uint32_t actual, u
}
void perf_print_all(void) {
#ifdef __riscv__
#ifdef __ibex__
printf("Perf CYCLES: %d\n", cpu_perf_get(CSR_PCER_CYCLES));
printf("Perf INSTR: %d\n", cpu_perf_get(CSR_PCER_INSTR));
printf("Perf CINSTR: %d\n", cpu_perf_get(CSR_PCER_RVC));
printf("Perf LD_STALL: %d\n", cpu_perf_get(CSR_PCER_LD_STALL));
printf("Perf JR_STALL: [Not Implemented]\n");
printf("Perf IMISS: %d\n", cpu_perf_get(CSR_PCER_IMISS));
printf("Perf LD: %d\n", cpu_perf_get(CSR_PCER_LD));
printf("Perf ST: %d\n", cpu_perf_get(CSR_PCER_ST));
printf("Perf JUMP: %d\n", cpu_perf_get(CSR_PCER_JUMP));
printf("Perf BRANCH: %d\n", cpu_perf_get(CSR_PCER_BRANCH));
printf("Perf BTAKEN: %d\n", cpu_perf_get(CSR_PCER_TAKEN_BRANCH));
printf("Perf LD EXT: %d\n", cpu_perf_get(CSR_PCER_LD_EXT));
printf("Perf ST EXT: %d\n", cpu_perf_get(CSR_PCER_ST_EXT));
printf("Perf LD EXT CYC: %d\n", cpu_perf_get(CSR_PCER_LD_EXT_CYC));
printf("Perf ST EXT CYC: %d\n", cpu_perf_get(CSR_PCER_ST_EXT_CYC));
printf("Perf TCDM CONT: %d\n", cpu_perf_get(CSR_PCER_TCDM_CONT));
printf("Perf CSR HAZARD: [Not Implemented]\n");
#elif defined( __riscv__ )
printf("Perf CYCLES: %d\n", cpu_perf_get(0));
printf("Perf INSTR: %d\n", cpu_perf_get(1));
printf("Perf CINSTR: %d\n", cpu_perf_get(10));
@ -211,7 +229,7 @@ void illegal_insn_handler_c(void)
{
#ifndef __ariane__
unsigned int exception_address, insn;
#ifdef __riscv__
#if defined( __riscv__ ) || defined( __ibex__)
asm("csrr %0, 0x341" : "=r" (exception_address) : );
#else
exception_address = hal_spr_read(SPR_EPCR_BASE);

View file

@ -1,8 +1,17 @@
ifdef USE_IBEX
PULP_LDFLAGS +=
PULP_CFLAGS += -D__ibex__ -U__riscv__ -UARCHI_CORE_HAS_PULPV2 -DRV_ISA_RV32
PULP_ARCH_CFLAGS ?= -march=rv32imc
PULP_ARCH_LDFLAGS ?= -march=rv32imc
PULP_ARCH_OBJDFLAGS ?= -Mmarch=rv32imc
else
PULP_LDFLAGS +=
PULP_CFLAGS += -D__riscv__
PULP_ARCH_CFLAGS ?= -march=rv32imcxgap9
PULP_ARCH_LDFLAGS ?= -march=rv32imcxgap9
PULP_ARCH_OBJDFLAGS ?= -Mmarch=rv32imcxgap9
endif
PULP_CFLAGS += -fdata-sections -ffunction-sections -include chips/pulp/config.h -I$(PULPRT_HOME)/include/chips/pulp
PULP_OMP_CFLAGS += -fopenmp -mnativeomp
PULP_LDFLAGS += -nostartfiles -nostdlib -Wl,--gc-sections -L$(PULPRT_HOME)/kernel -Tchips/pulp/link.ld -lgcc

View file

@ -1,8 +1,17 @@
ifdef USE_IBEX
PULP_LDFLAGS +=
PULP_CFLAGS += -D__ibex__ -U__riscv__ -UARCHI_CORE_HAS_PULPV2 -DRV_ISA_RV32
PULP_ARCH_CFLAGS ?= -march=rv32imc
PULP_ARCH_LDFLAGS ?= -march=rv32imc
PULP_ARCH_OBJDFLAGS ?= -Mmarch=rv32imc
else
PULP_LDFLAGS +=
PULP_CFLAGS += -D__riscv__
PULP_ARCH_CFLAGS ?= -march=rv32imcxgap9
PULP_ARCH_LDFLAGS ?= -march=rv32imcxgap9
PULP_ARCH_OBJDFLAGS ?= -Mmarch=rv32imcxgap9
endif
PULP_CFLAGS += -fdata-sections -ffunction-sections -include chips/pulpissimo/config.h -I$(PULPRT_HOME)/include/chips/pulpissimo
PULP_OMP_CFLAGS += -fopenmp -mnativeomp
PULP_LDFLAGS += -nostartfiles -nostdlib -Wl,--gc-sections -L$(PULPRT_HOME)/kernel -Tchips/pulpissimo/link.ld -lgcc