From a3fdbec13d3da3a337e0202fecbaf8c08db17b96 Mon Sep 17 00:00:00 2001 From: "Justin A. Wilson" Date: Sun, 5 Mar 2023 00:57:23 -0600 Subject: [PATCH] Refactor SystemStack function for arm targets. Removing usage of AsmFull in favor of writing inline assembly in C. --- src/internal/task/task_stack_cortexm.c | 12 ++++++++++++ src/internal/task/task_stack_cortexm.go | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 src/internal/task/task_stack_cortexm.c diff --git a/src/internal/task/task_stack_cortexm.c b/src/internal/task/task_stack_cortexm.c new file mode 100644 index 00000000..8580fdbf --- /dev/null +++ b/src/internal/task/task_stack_cortexm.c @@ -0,0 +1,12 @@ +#include + +uintptr_t SystemStack() { + uintptr_t sp; + asm volatile( + "mrs %0, MSP" + : "=r"(sp) + : + : "memory" + ); + return sp; +} \ No newline at end of file diff --git a/src/internal/task/task_stack_cortexm.go b/src/internal/task/task_stack_cortexm.go index 442a717a..39b90b75 100644 --- a/src/internal/task/task_stack_cortexm.go +++ b/src/internal/task/task_stack_cortexm.go @@ -8,8 +8,8 @@ package task // PSP, which is used for goroutines) so that goroutines do not need extra stack // space for interrupts. +import "C" import ( - "device/arm" "unsafe" ) @@ -67,6 +67,6 @@ func (s *state) pause() { // SystemStack returns the system stack pointer. On Cortex-M, it is always // available. -func SystemStack() uintptr { - return arm.AsmFull("mrs {}, MSP", nil) -} +// +//export SystemStack +func SystemStack() uintptr