Line 43... |
Line 43... |
#include "neorv32_rte.h"
|
#include "neorv32_rte.h"
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* The >private< trap vector look-up table of the NEORV32 RTE.
|
* The >private< trap vector look-up table of the NEORV32 RTE.
|
**************************************************************************/
|
**************************************************************************/
|
static uint32_t __neorv32_rte_vector_lut[17] __attribute__((unused)); // trap handler vector table
|
static uint32_t __neorv32_rte_vector_lut[21] __attribute__((unused)); // trap handler vector table
|
|
|
// private functions
|
// private functions
|
static void __attribute__((__interrupt__)) __neorv32_rte_core(void) __attribute__((aligned(16))) __attribute__((unused));
|
static void __attribute__((__interrupt__)) __neorv32_rte_core(void) __attribute__((aligned(16))) __attribute__((unused));
|
static void __neorv32_rte_debug_exc_handler(void) __attribute__((unused));
|
static void __neorv32_rte_debug_exc_handler(void) __attribute__((unused));
|
static void __neorv32_rte_print_true_false(int state) __attribute__((unused));
|
static void __neorv32_rte_print_true_false(int state) __attribute__((unused));
|
static void __neorv32_rte_print_hex_word(uint32_t num);
|
static void __neorv32_rte_print_hex_word(uint32_t num);
|
|
static int __neorv32_rte_check_exc_id(uint32_t id);
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Setup NEORV32 runtime environment.
|
* Setup NEORV32 runtime environment.
|
*
|
*
|
Line 91... |
Line 92... |
* @return 0 if success, 1 if error (invalid id or targeted exception not supported).
|
* @return 0 if success, 1 if error (invalid id or targeted exception not supported).
|
**************************************************************************/
|
**************************************************************************/
|
int neorv32_rte_exception_install(uint8_t id, void (*handler)(void)) {
|
int neorv32_rte_exception_install(uint8_t id, void (*handler)(void)) {
|
|
|
// id valid?
|
// id valid?
|
if ((id == RTE_TRAP_I_MISALIGNED) || (id == RTE_TRAP_I_ACCESS) || (id == RTE_TRAP_I_ILLEGAL) ||
|
if (__neorv32_rte_check_exc_id(id) == 0) {
|
(id == RTE_TRAP_BREAKPOINT) || (id == RTE_TRAP_L_MISALIGNED) || (id == RTE_TRAP_L_ACCESS) ||
|
|
(id == RTE_TRAP_S_MISALIGNED) || (id == RTE_TRAP_S_ACCESS) || (id == RTE_TRAP_MENV_CALL) || (id == RTE_TRAP_UENV_CALL) ||
|
|
(id == RTE_TRAP_MSI) || (id == RTE_TRAP_MTI) || (id == RTE_TRAP_MEI) ||
|
|
(id == RTE_TRAP_FIRQ_0) || (id == RTE_TRAP_FIRQ_1) || (id == RTE_TRAP_FIRQ_2) || (id == RTE_TRAP_FIRQ_3)) {
|
|
|
|
__neorv32_rte_vector_lut[id] = (uint32_t)handler; // install handler
|
__neorv32_rte_vector_lut[id] = (uint32_t)handler; // install handler
|
|
|
return 0;
|
return 0;
|
}
|
}
|
return 1;
|
return 1;
|
}
|
}
|
|
|
Line 118... |
Line 113... |
* @return 0 if success, 1 if error (invalid id or targeted exception not supported).
|
* @return 0 if success, 1 if error (invalid id or targeted exception not supported).
|
**************************************************************************/
|
**************************************************************************/
|
int neorv32_rte_exception_uninstall(uint8_t id) {
|
int neorv32_rte_exception_uninstall(uint8_t id) {
|
|
|
// id valid?
|
// id valid?
|
if ((id == RTE_TRAP_I_MISALIGNED) || (id == RTE_TRAP_I_ACCESS) || (id == RTE_TRAP_I_ILLEGAL) ||
|
if (__neorv32_rte_check_exc_id(id) == 0) {
|
(id == RTE_TRAP_BREAKPOINT) || (id == RTE_TRAP_L_MISALIGNED) || (id == RTE_TRAP_L_ACCESS) ||
|
|
(id == RTE_TRAP_S_MISALIGNED) || (id == RTE_TRAP_S_ACCESS) || (id == RTE_TRAP_MENV_CALL) || (id == RTE_TRAP_UENV_CALL) ||
|
|
(id == RTE_TRAP_MSI) || (id == RTE_TRAP_MTI) || (id == RTE_TRAP_MEI) ||
|
|
(id == RTE_TRAP_FIRQ_0) || (id == RTE_TRAP_FIRQ_1) || (id == RTE_TRAP_FIRQ_2) || (id == RTE_TRAP_FIRQ_3)) {
|
|
|
|
__neorv32_rte_vector_lut[id] = (uint32_t)(&__neorv32_rte_debug_exc_handler); // use dummy handler in case the exception is accidently triggered
|
__neorv32_rte_vector_lut[id] = (uint32_t)(&__neorv32_rte_debug_exc_handler); // use dummy handler in case the exception is accidently triggered
|
|
|
return 0;
|
return 0;
|
}
|
}
|
return 1;
|
return 1;
|
}
|
}
|
|
|
Line 184... |
Line 173... |
case TRAP_CODE_MEI: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_MEI]; break;
|
case TRAP_CODE_MEI: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_MEI]; break;
|
case TRAP_CODE_FIRQ_0: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_0]; break;
|
case TRAP_CODE_FIRQ_0: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_0]; break;
|
case TRAP_CODE_FIRQ_1: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_1]; break;
|
case TRAP_CODE_FIRQ_1: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_1]; break;
|
case TRAP_CODE_FIRQ_2: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_2]; break;
|
case TRAP_CODE_FIRQ_2: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_2]; break;
|
case TRAP_CODE_FIRQ_3: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_3]; break;
|
case TRAP_CODE_FIRQ_3: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_3]; break;
|
|
case TRAP_CODE_FIRQ_4: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_4]; break;
|
|
case TRAP_CODE_FIRQ_5: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_5]; break;
|
|
case TRAP_CODE_FIRQ_6: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_6]; break;
|
|
case TRAP_CODE_FIRQ_7: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_7]; break;
|
default: break;
|
default: break;
|
}
|
}
|
|
|
// execute handler
|
// execute handler
|
void (*handler_pnt)(void);
|
void (*handler_pnt)(void);
|
Line 219... |
Line 212... |
case TRAP_CODE_UENV_CALL: neorv32_uart_print("Environment call from U-mode"); break;
|
case TRAP_CODE_UENV_CALL: neorv32_uart_print("Environment call from U-mode"); break;
|
case TRAP_CODE_MENV_CALL: neorv32_uart_print("Environment call from M-mode"); break;
|
case TRAP_CODE_MENV_CALL: neorv32_uart_print("Environment call from M-mode"); break;
|
case TRAP_CODE_MSI: neorv32_uart_print("Machine software interrupt"); break;
|
case TRAP_CODE_MSI: neorv32_uart_print("Machine software interrupt"); break;
|
case TRAP_CODE_MTI: neorv32_uart_print("Machine timer interrupt"); break;
|
case TRAP_CODE_MTI: neorv32_uart_print("Machine timer interrupt"); break;
|
case TRAP_CODE_MEI: neorv32_uart_print("Machine external interrupt"); break;
|
case TRAP_CODE_MEI: neorv32_uart_print("Machine external interrupt"); break;
|
case TRAP_CODE_FIRQ_0: neorv32_uart_print("Fast interrupt 0"); break;
|
case TRAP_CODE_FIRQ_0:
|
case TRAP_CODE_FIRQ_1: neorv32_uart_print("Fast interrupt 1"); break;
|
case TRAP_CODE_FIRQ_1:
|
case TRAP_CODE_FIRQ_2: neorv32_uart_print("Fast interrupt 2"); break;
|
case TRAP_CODE_FIRQ_2:
|
case TRAP_CODE_FIRQ_3: neorv32_uart_print("Fast interrupt 3"); break;
|
case TRAP_CODE_FIRQ_3:
|
|
case TRAP_CODE_FIRQ_4:
|
|
case TRAP_CODE_FIRQ_5:
|
|
case TRAP_CODE_FIRQ_6:
|
|
case TRAP_CODE_FIRQ_7: neorv32_uart_print("Fast interrupt "); neorv32_uart_putc((char)('0' + (trap_cause & 0x7))); break;
|
default: neorv32_uart_print("Unknown trap cause: "); __neorv32_rte_print_hex_word(trap_cause); break;
|
default: neorv32_uart_print("Unknown trap cause: "); __neorv32_rte_print_hex_word(trap_cause); break;
|
}
|
}
|
|
|
// instruction address
|
// instruction address
|
neorv32_uart_print(" @ PC=");
|
neorv32_uart_print(" @ PC=");
|
Line 429... |
Line 426... |
__neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_WDT));
|
__neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_WDT));
|
|
|
neorv32_uart_printf("TRNG - ");
|
neorv32_uart_printf("TRNG - ");
|
__neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_TRNG));
|
__neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_TRNG));
|
|
|
neorv32_uart_printf("CFU0 - ");
|
neorv32_uart_printf("CFS - ");
|
__neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_CFU0));
|
__neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_CFS));
|
|
|
neorv32_uart_printf("CFU1 - ");
|
|
__neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_CFU1));
|
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* NEORV32 runtime environment: Private function to print true or false.
|
* NEORV32 runtime environment: Private function to print true or false.
|
Line 474... |
Line 468... |
neorv32_uart_putc(hex_symbols[index]);
|
neorv32_uart_putc(hex_symbols[index]);
|
}
|
}
|
}
|
}
|
|
|
|
|
|
/**********************************************************************//**
|
|
* NEORV32 runtime environment: Private function to check exception id
|
|
* as 8-digit hexadecimal value (with "0x" suffix).
|
|
*
|
|
* @param[in] id Exception id (#NEORV32_RTE_TRAP_enum).
|
|
* @return Return 0 if id is valid
|
|
**************************************************************************/
|
|
static int __neorv32_rte_check_exc_id(uint32_t id) {
|
|
|
|
// id valid?
|
|
if ((id == RTE_TRAP_I_MISALIGNED) || (id == RTE_TRAP_I_ACCESS) || (id == RTE_TRAP_I_ILLEGAL) ||
|
|
(id == RTE_TRAP_BREAKPOINT) || (id == RTE_TRAP_L_MISALIGNED) || (id == RTE_TRAP_L_ACCESS) ||
|
|
(id == RTE_TRAP_S_MISALIGNED) || (id == RTE_TRAP_S_ACCESS) || (id == RTE_TRAP_MENV_CALL) || (id == RTE_TRAP_UENV_CALL) ||
|
|
(id == RTE_TRAP_MSI) || (id == RTE_TRAP_MTI) || (id == RTE_TRAP_MEI) ||
|
|
(id == RTE_TRAP_FIRQ_0) || (id == RTE_TRAP_FIRQ_1) || (id == RTE_TRAP_FIRQ_2) || (id == RTE_TRAP_FIRQ_3) ||
|
|
(id == RTE_TRAP_FIRQ_4) || (id == RTE_TRAP_FIRQ_5) || (id == RTE_TRAP_FIRQ_6) || (id == RTE_TRAP_FIRQ_7)) {
|
|
return 0;
|
|
}
|
|
else {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* NEORV32 runtime environment: Print the processor version in human-readable format.
|
* NEORV32 runtime environment: Print the processor version in human-readable format.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_rte_print_hw_version(void) {
|
void neorv32_rte_print_hw_version(void) {
|
Line 545... |
Line 563... |
for (u=0; u<11; u++) {
|
for (u=0; u<11; u++) {
|
neorv32_uart_print("\n");
|
neorv32_uart_print("\n");
|
for (v=0; v<4; v++) {
|
for (v=0; v<4; v++) {
|
tmp = logo_data_c[u][v];
|
tmp = logo_data_c[u][v];
|
for (w=0; w<32; w++){
|
for (w=0; w<32; w++){
|
if (tmp & (1 << (31-w))) {
|
if (tmp & 0x80000000UL) { // check MSB
|
neorv32_uart_putc('#');
|
neorv32_uart_putc('#');
|
}
|
}
|
else {
|
else {
|
neorv32_uart_putc(' ');
|
neorv32_uart_putc(' ');
|
}
|
}
|
|
tmp <<= 1;
|
}
|
}
|
}
|
}
|
}
|
}
|
neorv32_uart_print("\n");
|
neorv32_uart_print("\n");
|
}
|
}
|