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