countertest: support probe counter before tests
This commit is contained in:
parent
6f4db8e1f7
commit
ee3eb9edda
|
@ -2,6 +2,7 @@
|
|||
#define __COUNTERTEST_H__
|
||||
|
||||
#define MSG_ERROR "\33[1;31mERROR\033[0m"
|
||||
#define MSG_WARNING "\33[1;33mWARNING\033[0m"
|
||||
|
||||
#define MAP(c, f) c(f)
|
||||
|
||||
|
@ -24,10 +25,27 @@
|
|||
f(hpmcounter24 , 0xC18) f(hpmcounter25 , 0xC19) f(hpmcounter26 , 0xC1A) f(hpmcounter27 , 0xC1B) \
|
||||
f(hpmcounter28 , 0xC1C) f(hpmcounter29 , 0xC1D) f(hpmcounter30 , 0xC1E) f(hpmcounter31 , 0xC1F)
|
||||
|
||||
#define CSR_ALL_UNPRIV_COUNTER(f) \
|
||||
#define CSRS_UNPRIV_COUNTER_TIMERS(f) \
|
||||
CSRS_UNPRIV_CNTR(f) \
|
||||
CSRS_UNPRIV_HPM(f)
|
||||
|
||||
#define CSRS_M_CNTR(f) \
|
||||
f(mcycle , 0xB00) f(minstret , 0xB02)
|
||||
|
||||
#define CSRS_M_HPM(f) \
|
||||
f(mhpmcounter3 , 0xB03) \
|
||||
f(mhpmcounter4 , 0xB04) f(mhpmcounter5 , 0xB05) f(mhpmcounter6 , 0xB06) f(mhpmcounter7 , 0xB07) \
|
||||
f(mhpmcounter8 , 0xB08) f(mhpmcounter9 , 0xB09) f(mhpmcounter10 , 0xB0A) f(mhpmcounter11 , 0xB0B) \
|
||||
f(mhpmcounter12 , 0xB0C) f(mhpmcounter13 , 0xB0D) f(mhpmcounter14 , 0xB0E) f(mhpmcounter15 , 0xB0F) \
|
||||
f(mhpmcounter16 , 0xB10) f(mhpmcounter17 , 0xB11) f(mhpmcounter18 , 0xB12) f(mhpmcounter19 , 0xB13) \
|
||||
f(mhpmcounter20 , 0xB14) f(mhpmcounter21 , 0xB15) f(mhpmcounter22 , 0xB16) f(mhpmcounter23 , 0xB17) \
|
||||
f(mhpmcounter24 , 0xB18) f(mhpmcounter25 , 0xB19) f(mhpmcounter26 , 0xB1A) f(mhpmcounter27 , 0xB1B) \
|
||||
f(mhpmcounter28 , 0xB1C) f(mhpmcounter29 , 0xB1D) f(mhpmcounter30 , 0xB1E) f(mhpmcounter31 , 0xB1F)
|
||||
|
||||
#define CSRS_M_COUNTER_TIMERS(f)\
|
||||
CSRS_M_CNTR(f) \
|
||||
CSRS_M_HPM(f)
|
||||
|
||||
#define ACCESSIBLE 0
|
||||
#define EX_II 2
|
||||
#define EX_VI 22
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef __ENABLE_H__
|
||||
#define __ENABLE_H__
|
||||
|
||||
typedef void (*func_void_t)();
|
||||
extern func_void_t check_enable_func_arr[32];
|
||||
typedef void (*func_enable_t)();
|
||||
extern func_enable_t check_enable_func_arr[32];
|
||||
|
||||
#define check_enable_detail(csr, addr, m, h, s, mode, res) \
|
||||
do { \
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef __PROBE_H__
|
||||
#define __PROBE_H__
|
||||
|
||||
typedef int (*func_probe_t)();
|
||||
extern func_probe_t probe_unpriv_cntr_func_arr[32];
|
||||
extern func_probe_t probe_machine_cntr_func_arr[32];
|
||||
|
||||
#define def_func_probe_csr(csr, addr) \
|
||||
int probe_counter_##csr() { \
|
||||
setup_expected_exception(); \
|
||||
int csr_read_res; \
|
||||
csr_read_res = csr_read(csr); \
|
||||
csr_read_res &= csr_read_res; \
|
||||
if (last_exception.actual_trap) { /* Not exist */ \
|
||||
printf(MSG_WARNING ": " #csr " does not exist.\n"); \
|
||||
clear_last_exception(); \
|
||||
return -1; \
|
||||
} else { \
|
||||
clear_last_exception(); \
|
||||
return 0;\
|
||||
} \
|
||||
}
|
||||
|
||||
#define list_func_probe_csr(csr, addr) \
|
||||
probe_counter_##csr,
|
||||
|
||||
#endif // __PROBE_H__
|
|
@ -8,6 +8,7 @@
|
|||
#include "priv.h"
|
||||
#include "countertest.h"
|
||||
#include "enable.h"
|
||||
#include "probe.h"
|
||||
|
||||
extern void m_trap_entry();
|
||||
|
||||
|
@ -17,8 +18,29 @@ int main() {
|
|||
// setup trap vector
|
||||
csr_write(mtvec, m_trap_entry);
|
||||
|
||||
check_enable_func_arr[1] = 0;
|
||||
// probe machine counter
|
||||
for (int i = 0; i < COUNTER_NUM; i++) {
|
||||
if (probe_machine_cntr_func_arr[i]) {
|
||||
int res = probe_machine_cntr_func_arr[i]();
|
||||
if (res) {
|
||||
probe_unpriv_cntr_func_arr[i] = NULL;
|
||||
check_enable_func_arr[i] = NULL;
|
||||
error += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// probe unprivileged counter
|
||||
for (int i = 0; i < COUNTER_NUM; i++) {
|
||||
if (probe_unpriv_cntr_func_arr[i]) {
|
||||
int res = probe_unpriv_cntr_func_arr[i]();
|
||||
if (res) {
|
||||
check_enable_func_arr[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test counter-enable
|
||||
for (int i = 0; i < COUNTER_NUM; i++) {
|
||||
if (check_enable_func_arr[i]) {
|
||||
check_enable_func_arr[i]();
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include <am.h>
|
||||
#include <csr.h>
|
||||
#include <xsextra.h>
|
||||
|
@ -10,9 +9,9 @@
|
|||
#include "enable.h"
|
||||
|
||||
// define all check_enable_* function
|
||||
MAP(CSR_ALL_UNPRIV_COUNTER, def_func_check_enable)
|
||||
MAP(CSRS_UNPRIV_COUNTER_TIMERS, def_func_check_enable)
|
||||
|
||||
// link all check_enable_* function to array of function pointers
|
||||
func_void_t check_enable_func_arr[32] = {
|
||||
MAP(CSR_ALL_UNPRIV_COUNTER, list_func_check_enable)
|
||||
func_enable_t check_enable_func_arr[32] = {
|
||||
MAP(CSRS_UNPRIV_COUNTER_TIMERS, list_func_check_enable)
|
||||
};
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#include <am.h>
|
||||
#include <csr.h>
|
||||
#include <xsextra.h>
|
||||
#include <klib.h>
|
||||
#include <klib-macros.h>
|
||||
|
||||
#include "priv.h"
|
||||
#include "countertest.h"
|
||||
#include "probe.h"
|
||||
|
||||
// define all probe_counter_* function
|
||||
MAP(CSRS_UNPRIV_COUNTER_TIMERS, def_func_probe_csr)
|
||||
MAP(CSRS_M_COUNTER_TIMERS, def_func_probe_csr)
|
||||
|
||||
// link all probe_counter_* function to array of function pointers
|
||||
func_probe_t probe_unpriv_cntr_func_arr[32] = {
|
||||
MAP(CSRS_UNPRIV_COUNTER_TIMERS, list_func_probe_csr)
|
||||
};
|
||||
func_probe_t probe_machine_cntr_func_arr[32] = {
|
||||
probe_counter_mcycle,
|
||||
NULL,
|
||||
probe_counter_minstret,
|
||||
MAP(CSRS_M_HPM, list_func_probe_csr)
|
||||
};
|
Loading…
Reference in New Issue