Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch axel 7a #187

Closed
wants to merge 9 commits into from
Closed
86 changes: 54 additions & 32 deletions elfloader-tool/include/arch-riscv/sbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,54 @@
#define SBI_SHUTDOWN 8

#define SBI_CALL(which, arg0, arg1, arg2) ({ \
register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \
register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \
register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \
register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \
register word_t a0 asm ("a0") = (word_t)(arg0); \
register word_t a1 asm ("a1") = (word_t)(arg1); \
register word_t a2 asm ("a2") = (word_t)(arg2); \
register word_t a7 asm ("a7") = (word_t)(which); \
asm volatile ("ecall" \
: "+r" (a0) \
: "r" (a1), "r" (a2), "r" (a7) \
: "memory"); \
a0; \
})

typedef enum {
SBI_SUCCESS = 0,
SBI_ERR_FAILED = -1,
SBI_ERR_NOT_SUPPORTED = -2,
SBI_ERR_INVALID_PARAM = -3,
SBI_ERR_DENIED = -4,
SBI_ERR_INVALID_ADDRESS = -5,
SBI_ERR_ALREADY_AVAILABLE = -6,
SBI_ERR_ALREADY_STARTED = -7,
SBI_ERR_ALREADY_STOPPED = -8
} sbi_call_ret_t;

#define SBI_HSM 0x48534DULL
#define SBI_HSM_HART_START 0

#define SBI_EXT_CALL(extension, which, arg0, arg1, arg2) ({ \
register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \
register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \
register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \
register uintptr_t a6 asm ("a6") = (uintptr_t)(which); \
register uintptr_t a7 asm ("a7") = (uintptr_t)(extension); \
asm volatile ("ecall" \
: "+r" (a0) \
: "r" (a1), "r" (a2), "r" (a6), "r" (a7) \
: "memory"); \
a0; \
})

#define SBI_HSM_CALL(which, arg0, arg1, arg2) \
SBI_EXT_CALL(SBI_HSM, (which), (arg0), (arg1), (arg2))
typedef struct {
sbi_call_ret_t code;
word_t data;
} sbi_hsm_ret_t;

#define SBI_EXT_CALL(extension, which, arg0, arg1, arg2, var_sbi_hsm_ret) \
do { \
register word_t a0 asm ("a0") = (word_t)(arg0); \
register word_t a1 asm ("a1") = (word_t)(arg1); \
register word_t a2 asm ("a2") = (word_t)(arg2); \
register word_t a6 asm ("a6") = (word_t)(which); \
register word_t a7 asm ("a7") = (word_t)(extension); \
asm volatile ("ecall" \
: "+r" (a0), "+r" (a1) \
: "r" (a2), "r" (a6), "r" (a7) \
: "memory"); \
(var_sbi_hsm_ret).code = a0; \
(var_sbi_hsm_ret).data = a1; \
} while(0)

#define SBI_HSM_CALL(which, arg0, arg1, arg2, var_sbi_hsm_ret) \
SBI_EXT_CALL(SBI_HSM, (which), (arg0), (arg1), (arg2), var_sbi_hsm_ret)

/* Lazy implementations until SBI is finalized */
#define SBI_CALL_0(which) SBI_CALL(which, 0, 0, 0)
Expand Down Expand Up @@ -86,34 +105,37 @@ static inline void sbi_clear_ipi(void)
SBI_CALL_0(SBI_CLEAR_IPI);
}

static inline void sbi_send_ipi(const unsigned long *hart_mask)
static inline void sbi_send_ipi(const word_t *hart_mask)
{
SBI_CALL_1(SBI_SEND_IPI, hart_mask);
}

static inline void sbi_remote_fence_i(const unsigned long *hart_mask)
static inline void sbi_remote_fence_i(const word_t *hart_mask)
{
SBI_CALL_1(SBI_REMOTE_FENCE_I, hart_mask);
}

static inline void sbi_remote_sfence_vma(const unsigned long *hart_mask,
UNUSED unsigned long start,
UNUSED unsigned long size)
static inline void sbi_remote_sfence_vma(const word_t *hart_mask,
UNUSED word_t start,
UNUSED word_t size)
{
SBI_CALL_1(SBI_REMOTE_SFENCE_VMA, hart_mask);
}

static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask,
UNUSED unsigned long start,
UNUSED unsigned long size,
UNUSED unsigned long asid)
static inline void sbi_remote_sfence_vma_asid(const word_t *hart_mask,
UNUSED word_t start,
UNUSED word_t size,
UNUSED word_t asid)
{
SBI_CALL_1(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask);
}

static inline void sbi_hart_start(const unsigned long hart_id,
void (*start)(unsigned long),
unsigned long privilege)
static inline sbi_hsm_ret_t sbi_hart_start(const word_t hart_id,
void (*start)(word_t hart_id,
word_t arg),
word_t arg)
{
SBI_HSM_CALL(SBI_HSM_HART_START, hart_id, start, privilege);
sbi_hsm_ret_t ret = { 0 };
SBI_HSM_CALL(SBI_HSM_HART_START, hart_id, start, arg, ret);
return ret;
}
Loading