-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbi.c
78 lines (65 loc) · 2.7 KB
/
sbi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "sbi.h"
#include "vm_defs.h"
#define SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE 0x08424b45
#define SBI_CALL(___ext, ___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)(___ext); \
__asm__ volatile("ecall" \
: "+r"(a0) \
: "r"(a1), "r"(a2), "r"(a6), "r"(a7) \
: "memory"); \
a0; \
})
/* Lazy implementations until SBI is finalized */
#define SBI_CALL_0(___ext, ___which) SBI_CALL(___ext, ___which, 0, 0, 0)
#define SBI_CALL_1(___ext, ___which, ___arg0) SBI_CALL(___ext, ___which, ___arg0, 0, 0)
#define SBI_CALL_2(___ext, ___which, ___arg0, ___arg1) \
SBI_CALL(___ext, ___which, ___arg0, ___arg1, 0)
#define SBI_CALL_3(___ext, ___which, ___arg0, ___arg1, ___arg2) \
SBI_CALL(___ext, ___which, ___arg0, ___arg1, ___arg2)
void
sbi_putchar(char character) {
SBI_CALL_1(SBI_CONSOLE_PUTCHAR, 0, character);
}
void
sbi_set_timer(uint64_t stime_value) {
#if __riscv_xlen == 32
SBI_CALL_2(SBI_SET_TIMER, 0, stime_value, stime_value >> 32);
#else
SBI_CALL_1(SBI_SET_TIMER, 0, stime_value);
#endif
}
uintptr_t
sbi_stop_enclave(uint64_t request) {
return SBI_CALL_1(SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, SBI_SM_STOP_ENCLAVE, request);
}
void
sbi_exit_enclave(uint64_t retval) {
SBI_CALL_1(SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, SBI_SM_EXIT_ENCLAVE, retval);
}
uintptr_t
sbi_random() {
return SBI_CALL_0(SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, SBI_SM_RANDOM);
}
uintptr_t
sbi_query_multimem(size_t *size) {
return SBI_CALL_3(SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE,
SBI_SM_CALL_PLUGIN, SM_MULTIMEM_PLUGIN_ID, SM_MULTIMEM_CALL_GET_SIZE, size);
}
uintptr_t
sbi_query_multimem_addr(uintptr_t *addr) {
return SBI_CALL_3(SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE,
SBI_SM_CALL_PLUGIN, SM_MULTIMEM_PLUGIN_ID, SM_MULTIMEM_CALL_GET_ADDR, addr);
}
uintptr_t
sbi_attest_enclave(void* report, void* buf, uintptr_t len) {
return SBI_CALL_3(SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, SBI_SM_ATTEST_ENCLAVE, report, buf, len);
}
uintptr_t
sbi_get_sealing_key(uintptr_t key_struct, uintptr_t key_ident, uintptr_t len) {
return SBI_CALL_3(SBI_EXT_EXPERIMENTAL_KEYSTONE_ENCLAVE, SBI_SM_GET_SEALING_KEY, key_struct, key_ident, len);
}