aboutsummaryrefslogtreecommitdiff
path: root/machine
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2020-01-28 08:27:13 -0800
committerAndrew Waterman <andrew@sifive.com>2021-08-04 16:07:29 -0700
commit17bec41e9bd44c43901938b784680661b9b28a76 (patch)
tree7cde5e212dcb80e507eea7321360af5adf1dc765 /machine
parent717702ceec053afd424a41ef6a4078d3cbd755b8 (diff)
downloadriscv-pk-17bec41e9bd44c43901938b784680661b9b28a76.zip
riscv-pk-17bec41e9bd44c43901938b784680661b9b28a76.tar.gz
riscv-pk-17bec41e9bd44c43901938b784680661b9b28a76.tar.bz2
Use __builtin_frame_address() instead of "sp" directly.
Also use pointer arithmetic on char * instead of void *.
Diffstat (limited to 'machine')
-rw-r--r--machine/mtrap.h13
1 files changed, 4 insertions, 9 deletions
diff --git a/machine/mtrap.h b/machine/mtrap.h
index e9ef139..2f2e499 100644
--- a/machine/mtrap.h
+++ b/machine/mtrap.h
@@ -48,18 +48,13 @@ typedef struct {
volatile uint32_t* plic_s_ie;
} hls_t;
-#define STACK_POINTER() ({ \
- uintptr_t __sp; \
- __asm__("mv %0, sp" : "=r"(__sp)); \
- __sp; \
-})
-
-#define MACHINE_STACK_TOP() \
- ({ (void*)((STACK_POINTER() + RISCV_PGSIZE) & -RISCV_PGSIZE); })
+#define MACHINE_STACK_TOP() ({ \
+ uintptr_t sp = (uintptr_t)__builtin_frame_address(0) ; \
+ (char *)((sp + RISCV_PGSIZE) & -RISCV_PGSIZE); })
// hart-local storage, at top of stack
#define HLS() ((hls_t*)(MACHINE_STACK_TOP() - HLS_SIZE))
-#define OTHER_HLS(id) ((hls_t*)((void*)HLS() + RISCV_PGSIZE * ((id) - read_const_csr(mhartid))))
+#define OTHER_HLS(id) ((hls_t*)((char*)HLS() + RISCV_PGSIZE * ((id) - read_const_csr(mhartid))))
hls_t* hls_init(uintptr_t hart_id);
void parse_config_string();