runtime/fe310: add support for PLIC interrupts

This commit adds support for software vectoring in the PLIC interrupt.
The interrupt table is created by the compiler, which leads to very
compact code while retaining the flexibility that the interrupt API
provides.
This commit is contained in:
Ayke van Laethem
2020-01-10 16:54:45 +01:00
committed by Ron Evans
parent a9174d9184
commit 415c60551e
8 changed files with 152 additions and 21 deletions
-5
View File
@@ -19,11 +19,6 @@ type Interrupt struct {
// function: closures are not supported.
func New(id int, handler func(Interrupt)) Interrupt
// Register is used to declare an interrupt. You should not normally call this
// function: it is only for telling the compiler about the mapping between an
// interrupt number and the interrupt handler name.
func Register(id int, handlerName string) int
// handle is used internally, between IR generation and interrupt lowering. The
// frontend will create runtime/interrupt.handle objects, cast them to an int,
// and use that in an Interrupt object. That way the compiler will be able to
@@ -0,0 +1,8 @@
// +build avr cortexm
package interrupt
// Register is used to declare an interrupt. You should not normally call this
// function: it is only for telling the compiler about the mapping between an
// interrupt number and the interrupt handler name.
func Register(id int, handlerName string) int
+18
View File
@@ -0,0 +1,18 @@
// +build sifive
package interrupt
import "device/sifive"
// Enable enables this interrupt. Right after calling this function, the
// interrupt may be invoked if it was already pending.
func (irq Interrupt) Enable() {
sifive.PLIC.ENABLE[irq.num/32].SetBits(1 << (uint(irq.num) % 32))
}
// SetPriority sets the interrupt priority for this interrupt. A higher priority
// number means a higher priority (unlike Cortex-M). Priority 0 effectively
// disables the interrupt.
func (irq Interrupt) SetPriority(priority uint8) {
sifive.PLIC.PRIORITY[irq.num].Set(uint32(priority))
}