xref: /haiku/headers/private/kernel/arch/riscv64/arch_int.h (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2  * Copyright 2005-2019, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  * 		Axel Dörfler <axeld@pinc-software.de>
7  * 		Ingo Weinhold <bonefish@cs.tu-berlin.de>
8  */
9 #ifndef _KERNEL_ARCH_RISCV64_INT_H
10 #define _KERNEL_ARCH_RISCV64_INT_H
11 
12 #include <SupportDefs.h>
13 #include <arch_cpu_defs.h>
14 
15 #define NUM_IO_VECTORS	256
16 
17 
18 #ifdef __cplusplus
19 
20 static inline void
21 arch_int_enable_interrupts_inline(void)
22 {
23 	// TODO: Use atomic CSRRS?
24 	SstatusReg status(Sstatus());
25 	status.ie |= (1 << modeS);
26 	SetSstatus(status.val);
27 }
28 
29 
30 static inline int
31 arch_int_disable_interrupts_inline(void)
32 {
33 	// TODO: Use atomic CSRRC?
34 	SstatusReg status(Sstatus());
35 	int oldState = ((1 << modeS) & status.ie) != 0;
36 	status.ie &= ~(1 << modeS);
37 	SetSstatus(status.val);
38 	return oldState;
39 }
40 
41 
42 static inline void
43 arch_int_restore_interrupts_inline(int oldState)
44 {
45 	if (oldState)
46 		arch_int_enable_interrupts_inline();
47 }
48 
49 
50 static inline bool
51 arch_int_are_interrupts_enabled_inline(void)
52 {
53 	SstatusReg status(Sstatus());
54 	return ((1 << modeS) & status.ie) != 0;
55 }
56 
57 
58 // map the functions to the inline versions
59 #define arch_int_enable_interrupts()	arch_int_enable_interrupts_inline()
60 #define arch_int_disable_interrupts()	arch_int_disable_interrupts_inline()
61 #define arch_int_restore_interrupts(status)	\
62 	arch_int_restore_interrupts_inline(status)
63 #define arch_int_are_interrupts_enabled()	\
64 	arch_int_are_interrupts_enabled_inline()
65 
66 
67 enum {
68 	kMSyscallSwitchToSmode = 0,
69 	kMSyscallSetTimer      = 1,
70 };
71 
72 extern "C" status_t MSyscall(uint64 op, ...);
73 
74 #endif
75 
76 
77 #endif /* _KERNEL_ARCH_RISCV64_INT_H */
78