From 313c9e31dd5deb7e6167eec81ca31b27dcfa82c5 Mon Sep 17 00:00:00 2001 From: "Justin A. Wilson" Date: Sat, 4 Mar 2023 10:19:27 -0600 Subject: [PATCH] Refactor EnableInterrupts and DisableInterrupts Removes usage of AsmFull which required an optimization pass to remove the map parameter passed into it. This caused issues when compiling with -opt=0 where memory for the map was being allocated as an unintended side-effect of using AsmFull with no optimizations enabled. --- src/device/arm/arm.go | 18 +++++++----------- src/device/arm/interrupts.c | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 src/device/arm/interrupts.c diff --git a/src/device/arm/arm.go b/src/device/arm/arm.go index 04637f31..4b54da8f 100644 --- a/src/device/arm/arm.go +++ b/src/device/arm/arm.go @@ -29,6 +29,7 @@ // POSSIBILITY OF SUCH DAMAGE. package arm +import "C" import ( "errors" "runtime/volatile" @@ -174,20 +175,15 @@ func SetPriority(irq uint32, priority uint32) { // DisableInterrupts disables all interrupts, and returns the old interrupt // state. -func DisableInterrupts() uintptr { - return AsmFull(` - mrs {}, PRIMASK - cpsid i - `, nil) -} +// +//export DisableInterrupts +func DisableInterrupts() uintptr // EnableInterrupts enables all interrupts again. The value passed in must be // the mask returned by DisableInterrupts. -func EnableInterrupts(mask uintptr) { - AsmFull("msr PRIMASK, {mask}", map[string]interface{}{ - "mask": mask, - }) -} +// +//export EnableInterrupts +func EnableInterrupts(mask uintptr) // Set up the system timer to generate periodic tick events. // This will cause SysTick_Handler to fire once per tick. diff --git a/src/device/arm/interrupts.c b/src/device/arm/interrupts.c new file mode 100644 index 00000000..d94a3134 --- /dev/null +++ b/src/device/arm/interrupts.c @@ -0,0 +1,22 @@ +#include + +void EnableInterrupts(uintptr_t mask) { + asm volatile( + "msr PRIMASK, %0" + : + : "r"(mask) + : "memory" + ); +} + +uintptr_t DisableInterrupts() { + uintptr_t mask; + asm volatile( + "mrs %0, PRIMASK\n\t" + "cpsid i" + : "=r"(mask) + : + : "memory" + ); + return mask; +} \ No newline at end of file