105dda88dSAlexander von Gluck IV /* 205dda88dSAlexander von Gluck IV * Copyright 2005-2019, Haiku, Inc. All rights reserved. 305dda88dSAlexander von Gluck IV * Distributed under the terms of the MIT License. 405dda88dSAlexander von Gluck IV * 505dda88dSAlexander von Gluck IV * Authors: 605dda88dSAlexander von Gluck IV * Axel Dörfler <axeld@pinc-software.de> 705dda88dSAlexander von Gluck IV * Ingo Weinhold <bonefish@cs.tu-berlin.de> 805dda88dSAlexander von Gluck IV */ 905dda88dSAlexander von Gluck IV #ifndef _KERNEL_ARCH_RISCV64_INT_H 1005dda88dSAlexander von Gluck IV #define _KERNEL_ARCH_RISCV64_INT_H 1105dda88dSAlexander von Gluck IV 1205dda88dSAlexander von Gluck IV #include <SupportDefs.h> 13f0e1bca0SX512 #include <arch_cpu_defs.h> 1405dda88dSAlexander von Gluck IV 15*6d13693aSX512 #define NUM_IO_VECTORS 4096 1605dda88dSAlexander von Gluck IV 17d407b17bSX512 188ca0f03dSX512 #ifdef __cplusplus 198ca0f03dSX512 20d407b17bSX512 static inline void arch_int_enable_interrupts_inline(void)21d407b17bSX512arch_int_enable_interrupts_inline(void) 22d407b17bSX512 { 23fa557843SX512 SetBitsSstatus(SstatusReg{.ie = 1 << modeS}.val); 24d407b17bSX512 } 25d407b17bSX512 26d407b17bSX512 27d407b17bSX512 static inline int arch_int_disable_interrupts_inline(void)28d407b17bSX512arch_int_disable_interrupts_inline(void) 29d407b17bSX512 { 30fa557843SX512 SstatusReg oldStatus{.val = GetAndClearBitsSstatus(SstatusReg{.ie = 1 << modeS}.val)}; 31fa557843SX512 return ((1 << modeS) & oldStatus.ie) != 0; 32d407b17bSX512 } 33d407b17bSX512 34d407b17bSX512 35d407b17bSX512 static inline void arch_int_restore_interrupts_inline(int oldState)36d407b17bSX512arch_int_restore_interrupts_inline(int oldState) 37d407b17bSX512 { 38f0e1bca0SX512 if (oldState) 39f0e1bca0SX512 arch_int_enable_interrupts_inline(); 40d407b17bSX512 } 41d407b17bSX512 42d407b17bSX512 43d407b17bSX512 static inline bool arch_int_are_interrupts_enabled_inline(void)44d407b17bSX512arch_int_are_interrupts_enabled_inline(void) 45d407b17bSX512 { 46fa557843SX512 SstatusReg status{.val = Sstatus()}; 47f0e1bca0SX512 return ((1 << modeS) & status.ie) != 0; 48d407b17bSX512 } 49d407b17bSX512 50d407b17bSX512 51d407b17bSX512 // map the functions to the inline versions 52d407b17bSX512 #define arch_int_enable_interrupts() arch_int_enable_interrupts_inline() 53d407b17bSX512 #define arch_int_disable_interrupts() arch_int_disable_interrupts_inline() 54d407b17bSX512 #define arch_int_restore_interrupts(status) \ 55d407b17bSX512 arch_int_restore_interrupts_inline(status) 56d407b17bSX512 #define arch_int_are_interrupts_enabled() \ 57d407b17bSX512 arch_int_are_interrupts_enabled_inline() 58d407b17bSX512 59d407b17bSX512 60f0e1bca0SX512 enum { 61f0e1bca0SX512 kMSyscallSwitchToSmode = 0, 62f0e1bca0SX512 kMSyscallSetTimer = 1, 63f0e1bca0SX512 }; 64f0e1bca0SX512 65f0e1bca0SX512 extern "C" status_t MSyscall(uint64 op, ...); 66f0e1bca0SX512 678ca0f03dSX512 #endif 688ca0f03dSX512 69f0e1bca0SX512 7005dda88dSAlexander von Gluck IV #endif /* _KERNEL_ARCH_RISCV64_INT_H */ 71