cores/cpu/naxriscv: Add baremetal IRQ support

This commit is contained in:
Dolu1990 2024-05-14 14:57:29 +02:00
parent e03b097e8e
commit d4c1a10817
3 changed files with 21 additions and 9 deletions

View File

@ -93,7 +93,7 @@ class NaxRiscv(CPU):
def gcc_flags(self):
flags = f" -march={NaxRiscv.get_arch()} -mabi={NaxRiscv.get_abi()}"
flags += f" -D__NaxRiscv__"
flags += f" -DUART_POLLING"
flags += f" -D__riscv_plic__"
return flags
# Reserved Interrupts.

View File

@ -113,8 +113,10 @@ bss_loop:
j bss_loop
bss_done:
li a0, 0x880 //880 enable timer + external interrupt sources (until mstatus.MIE is set, they will never trigger an interrupt)
csrw mie,a0
call plic_init // initialize external interrupt controller
li t0, 0x800 // external interrupt sources only (using LiteX timer);
// NOTE: must still enable mstatus.MIE!
csrw mie,t0
call main
infinit_loop:

View File

@ -9,30 +9,40 @@ extern "C" {
#include <generated/csr.h>
#include <generated/soc.h>
// NaxRiscv uses a Platform-Level Interrupt Controller (PLIC) which
// is programmed and queried via a set of MMIO registerss
#define PLIC_BASE 0xf0c00000L // Base address and per-pin priority array
#define PLIC_PENDING 0xf0c01000L // Bit field matching currently pending pins
#define PLIC_ENABLED 0xf0c02000L // Bit field corresponding to the current mask
#define PLIC_THRSHLD 0xf0e00000L // Per-pin priority must be >= this to trigger
#define PLIC_CLAIM 0xf0e00004L // Claim & completion register address
#define PLIC_EXT_IRQ_BASE 0
static inline unsigned int irq_getie(void)
{
return 0;
return (csrr(mstatus) & CSR_MSTATUS_MIE) != 0;
}
static inline void irq_setie(unsigned int ie)
{
if(ie) csrs(mstatus,CSR_MSTATUS_MIE); else csrc(mstatus,CSR_MSTATUS_MIE);
}
static inline unsigned int irq_getmask(void)
{
return 0;
return *((unsigned int *)PLIC_ENABLED) >> PLIC_EXT_IRQ_BASE;
}
static inline void irq_setmask(unsigned int mask)
{
*((unsigned int *)PLIC_ENABLED) = mask << PLIC_EXT_IRQ_BASE;
}
static inline unsigned int irq_pending(void)
{
return 0;
return *((unsigned int *)PLIC_PENDING) >> PLIC_EXT_IRQ_BASE;
}
#ifdef __cplusplus