blob: 0995f88305d44a0952531b9b274c0d439c50e292 (
plain)
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
|
#ifndef _ASM_H
#define _ASM_H
#include <stdint.h>
#define SSTATUS_SIE (1L << 1)
static inline uint64_t
csrr_sstatus(void)
{
uint64_t x;
asm volatile("csrr %0, sstatus" : "=r"(x));
return x;
}
static inline void
csrw_sstatus(uint64_t x)
{
asm volatile("csrw sstatus, %0" : : "r"(x));
}
/* will enable all supervisor interrupts using the bit in sstatus */
static inline void
sie_enable(void)
{
csrw_sstatus(csrr_sstatus() | SSTATUS_SIE);
}
/* will disable all supervisor interrupts by using the bitin sstatus (though sie can also be used) */
static inline void
sie_disable(void)
{
csrw_sstatus(csrr_sstatus() & ~SSTATUS_SIE);
}
/* returns the status of the sie bit in sstatus
* 1 if enabled, 0 if disabled.
* for more specific info see the sie register
*/
static inline uint64_t
sie_status()
{
return (csrr_sstatus() & SSTATUS_SIE) != 0;
}
/* we use tp to store hartid */
static inline uint64_t
read_tp(void)
{
uint64_t x;
asm volatile("addi %0, tp, 0" : "=r"(x));
return x;
}
#endif /* _ASM_H */
|