aboutsummaryrefslogtreecommitdiff
path: root/machine
diff options
context:
space:
mode:
Diffstat (limited to 'machine')
-rw-r--r--machine/mtrap.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/machine/mtrap.h b/machine/mtrap.h
index a8dbeff..e9ef139 100644
--- a/machine/mtrap.h
+++ b/machine/mtrap.h
@@ -48,9 +48,14 @@ typedef struct {
volatile uint32_t* plic_s_ie;
} hls_t;
-#define MACHINE_STACK_TOP() ({ \
- register uintptr_t sp asm ("sp"); \
- (void*)((sp + RISCV_PGSIZE) & -RISCV_PGSIZE); })
+#define STACK_POINTER() ({ \
+ uintptr_t __sp; \
+ __asm__("mv %0, sp" : "=r"(__sp)); \
+ __sp; \
+})
+
+#define MACHINE_STACK_TOP() \
+ ({ (void*)((STACK_POINTER() + RISCV_PGSIZE) & -RISCV_PGSIZE); })
// hart-local storage, at top of stack
#define HLS() ((hls_t*)(MACHINE_STACK_TOP() - HLS_SIZE))