1#ifndef _ASM_SCORE_IRQFLAGS_H
2#define _ASM_SCORE_IRQFLAGS_H
3
4#ifndef __ASSEMBLY__
5
6#include <linux/types.h>
7
8static inline unsigned long arch_local_save_flags(void)
9{
10	unsigned long flags;
11
12	asm volatile(
13		"	mfcr	r8, cr0		\n"
14		"	nop			\n"
15		"	nop			\n"
16		"	mv	%0, r8		\n"
17		"	nop			\n"
18		"	nop			\n"
19		"	nop			\n"
20		"	nop			\n"
21		"	nop			\n"
22		"	ldi	r9, 0x1		\n"
23		"	and	%0, %0, r9	\n"
24		: "=r" (flags)
25		:
26		: "r8", "r9");
27	return flags;
28}
29
30static inline unsigned long arch_local_irq_save(void)
31{
32	unsigned long flags;
33
34	asm volatile(
35		"	mfcr	r8, cr0		\n"
36		"	li	r9, 0xfffffffe	\n"
37		"	nop			\n"
38		"	mv	%0, r8		\n"
39		"	and	r8, r8, r9	\n"
40		"	mtcr	r8, cr0		\n"
41		"	nop			\n"
42		"	nop			\n"
43		"	nop			\n"
44		"	nop			\n"
45		"	nop			\n"
46		: "=r" (flags)
47		:
48		: "r8", "r9", "memory");
49
50	return flags;
51}
52
53static inline void arch_local_irq_restore(unsigned long flags)
54{
55	asm volatile(
56		"	mfcr	r8, cr0		\n"
57		"	ldi	r9, 0x1		\n"
58		"	and	%0, %0, r9	\n"
59		"	or	r8, r8, %0	\n"
60		"	mtcr	r8, cr0		\n"
61		"	nop			\n"
62		"	nop			\n"
63		"	nop			\n"
64		"	nop			\n"
65		"	nop			\n"
66		:
67		: "r"(flags)
68		: "r8", "r9", "memory");
69}
70
71static inline void arch_local_irq_enable(void)
72{
73	asm volatile(
74		"	mfcr	r8,cr0		\n"
75		"	nop			\n"
76		"	nop			\n"
77		"	ori	r8,0x1		\n"
78		"	mtcr	r8,cr0		\n"
79		"	nop			\n"
80		"	nop			\n"
81		"	nop			\n"
82		"	nop			\n"
83		"	nop			\n"
84		:
85		:
86		: "r8", "memory");
87}
88
89static inline void arch_local_irq_disable(void)
90{
91	asm volatile(
92		"	mfcr	r8,cr0		\n"
93		"	nop			\n"
94		"	nop			\n"
95		"	srli	r8,r8,1		\n"
96		"	slli	r8,r8,1		\n"
97		"	mtcr	r8,cr0		\n"
98		"	nop			\n"
99		"	nop			\n"
100		"	nop			\n"
101		"	nop			\n"
102		"	nop			\n"
103		:
104		:
105		: "r8", "memory");
106}
107
108static inline bool arch_irqs_disabled_flags(unsigned long flags)
109{
110	return !(flags & 1);
111}
112
113static inline bool arch_irqs_disabled(void)
114{
115	return arch_irqs_disabled_flags(arch_local_save_flags());
116}
117
118#endif /* __ASSEMBLY__ */
119
120#endif /* _ASM_SCORE_IRQFLAGS_H */
121