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 SetBitsSstatus(SstatusReg{.ie = 1 << modeS}.val); 24 } 25 26 27 static inline int 28 arch_int_disable_interrupts_inline(void) 29 { 30 SstatusReg oldStatus{.val = GetAndClearBitsSstatus(SstatusReg{.ie = 1 << modeS}.val)}; 31 return ((1 << modeS) & oldStatus.ie) != 0; 32 } 33 34 35 static inline void 36 arch_int_restore_interrupts_inline(int oldState) 37 { 38 if (oldState) 39 arch_int_enable_interrupts_inline(); 40 } 41 42 43 static inline bool 44 arch_int_are_interrupts_enabled_inline(void) 45 { 46 SstatusReg status{.val = Sstatus()}; 47 return ((1 << modeS) & status.ie) != 0; 48 } 49 50 51 // map the functions to the inline versions 52 #define arch_int_enable_interrupts() arch_int_enable_interrupts_inline() 53 #define arch_int_disable_interrupts() arch_int_disable_interrupts_inline() 54 #define arch_int_restore_interrupts(status) \ 55 arch_int_restore_interrupts_inline(status) 56 #define arch_int_are_interrupts_enabled() \ 57 arch_int_are_interrupts_enabled_inline() 58 59 60 enum { 61 kMSyscallSwitchToSmode = 0, 62 kMSyscallSetTimer = 1, 63 }; 64 65 extern "C" status_t MSyscall(uint64 op, ...); 66 67 #endif 68 69 70 #endif /* _KERNEL_ARCH_RISCV64_INT_H */ 71