Browse Source

Use __builtin_frame_address() instead of "sp" directly.

Also use pointer arithmetic on char * instead of void *.
pull/250/head
John Baldwin 6 years ago
committed by Andrew Waterman
parent
commit
17bec41e9b
  1. 13
      machine/mtrap.h

13
machine/mtrap.h

@ -48,18 +48,13 @@ typedef struct {
volatile uint32_t* plic_s_ie; volatile uint32_t* plic_s_ie;
} hls_t; } hls_t;
#define STACK_POINTER() ({ \ #define MACHINE_STACK_TOP() ({ \
uintptr_t __sp; \ uintptr_t sp = (uintptr_t)__builtin_frame_address(0) ; \
__asm__("mv %0, sp" : "=r"(__sp)); \ (char *)((sp + RISCV_PGSIZE) & -RISCV_PGSIZE); })
__sp; \
})
#define MACHINE_STACK_TOP() \
({ (void*)((STACK_POINTER() + RISCV_PGSIZE) & -RISCV_PGSIZE); })
// hart-local storage, at top of stack // hart-local storage, at top of stack
#define HLS() ((hls_t*)(MACHINE_STACK_TOP() - HLS_SIZE)) #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); hls_t* hls_init(uintptr_t hart_id);
void parse_config_string(); void parse_config_string();

Loading…
Cancel
Save