1/*
2 * Copyright 2005-2021, 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 * 		Adrien Destugues <pulkomandy@pulkomandy.tk>
9 */
10#ifndef _KERNEL_ARCH_SPARC_INT_H
11#define _KERNEL_ARCH_SPARC_INT_H
12
13#include <SupportDefs.h>
14
15#define NUM_IO_VECTORS	256
16
17static inline void
18arch_int_enable_interrupts_inline(void)
19{
20	int tmp;
21	asm volatile(
22		"rdpr %%pstate, %0\n"
23		"or %0, 2, %0\n"
24		"wrpr %0, %%pstate\n"
25		: "=r" (tmp)
26	);
27}
28
29
30static inline int
31arch_int_disable_interrupts_inline(void)
32{
33	int flags;
34	int tmp;
35	asm volatile(
36		"rdpr %%pstate, %0\n"
37		"andn %0, 2, %1\n"
38		"wrpr %1, %%pstate\n"
39		: "=r" (flags), "=r" (tmp)
40	);
41	return flags & 2;
42}
43
44
45static inline void
46arch_int_restore_interrupts_inline(int oldState)
47{
48	if (oldState)
49		arch_int_enable_interrupts_inline();
50}
51
52
53static inline bool
54arch_int_are_interrupts_enabled_inline(void)
55{
56	int flags;
57	asm volatile(
58		"rdpr %%pstate, %0\n"
59		: "=r" (flags)
60	);
61
62	return flags & 2;
63}
64
65
66// map the functions to the inline versions
67#define arch_int_enable_interrupts()	arch_int_enable_interrupts_inline()
68#define arch_int_disable_interrupts()	arch_int_disable_interrupts_inline()
69#define arch_int_restore_interrupts(status)	\
70	arch_int_restore_interrupts_inline(status)
71#define arch_int_are_interrupts_enabled()	\
72	arch_int_are_interrupts_enabled_inline()
73
74
75#endif /* _KERNEL_ARCH_SPARC_INT_H */
76