From 23e88bfb156b1e3ac69b6bf7e9f8431ab94791c8 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 6 Apr 2020 17:30:56 +0200 Subject: [PATCH] arm: allow nesting in DisableInterrupts and EnableInterrupts This finally fixes a TODO left in the code. --- src/device/arm/arm.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/device/arm/arm.go b/src/device/arm/arm.go index ac11199e..a806bbc6 100644 --- a/src/device/arm/arm.go +++ b/src/device/arm/arm.go @@ -191,22 +191,21 @@ func SetPriority(irq uint32, priority uint32) { NVIC.IPR[regnum].Set((uint32(NVIC.IPR[regnum].Get()) &^ mask) | priority) } -// DisableInterrupts disables all interrupts, and returns the old state. -// -// TODO: it doesn't actually return the old state, meaning that it cannot be -// nested. +// DisableInterrupts disables all interrupts, and returns the old interrupt +// state. func DisableInterrupts() uintptr { - Asm("cpsid if") - return 0 + return AsmFull(` + mrs {}, PRIMASK + cpsid if + `, nil) } // EnableInterrupts enables all interrupts again. The value passed in must be // the mask returned by DisableInterrupts. -// -// TODO: it doesn't actually use the old state, meaning that it cannot be -// nested. func EnableInterrupts(mask uintptr) { - Asm("cpsie if") + AsmFull("msr PRIMASK, {mask}", map[string]interface{}{ + "mask": mask, + }) } // SystemReset performs a hard system reset.