xref: /freebsd/sys/powerpc/include/cpufunc.h (revision 5521ff5a4d1929056e7ffc982fac3341ca54df7c)
1 /*-
2  * Copyright (c) 1998 Doug Rabson
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _MACHINE_CPUFUNC_H_
30 #define	_MACHINE_CPUFUNC_H_
31 
32 #ifdef _KERNEL
33 
34 #include <sys/types.h>
35 
36 #include <machine/psl.h>
37 
38 #ifdef __GNUC__
39 
40 static __inline void
41 breakpoint(void)
42 {
43 	return;
44 }
45 
46 #endif
47 
48 /* CPU register mangling inlines */
49 
50 static __inline void
51 mtmsr(unsigned int value)
52 {
53 	__asm __volatile ("mtmsr %0" :: "r"(value));
54 }
55 
56 static __inline unsigned int
57 mfmsr(void)
58 {
59 	unsigned int	value;
60 
61 	__asm __volatile ("mfmsr %0" : "=r"(value));
62 
63 	return (value);
64 }
65 
66 static __inline void
67 mtdec(unsigned int value)
68 {
69 	__asm __volatile ("mtdec %0" :: "r"(value));
70 }
71 
72 static __inline unsigned int
73 mfdec(void)
74 {
75 	unsigned int	value;
76 
77 	__asm __volatile ("mfdec %0" : "=r"(value));
78 
79 	return (value);
80 }
81 
82 /*
83  * Bogus interrupt manipulation
84  */
85 static __inline void
86 disable_intr(void)
87 {
88 	unsigned int	msr;
89 
90 	msr = mfmsr();
91 	mtmsr(msr & ~PSL_EE);
92 }
93 
94 static __inline void
95 enable_intr(void)
96 {
97 	unsigned int	msr;
98 
99 	msr = mfmsr();
100 	mtmsr(msr | PSL_EE);
101 }
102 
103 static __inline unsigned int
104 save_intr(void)
105 {
106 	unsigned int	msr;
107 
108 	msr = mfmsr();
109 
110 	return msr;
111 }
112 
113 static __inline critical_t
114 critical_enter(void)
115 {
116 	return ((critical_t)save_intr());
117 }
118 
119 static __inline void
120 restore_intr(unsigned int msr)
121 {
122 	mtmsr(msr);
123 }
124 
125 static __inline void
126 critical_exit(critical_t msr)
127 {
128 	return (restore_intr((unsigned int)msr));
129 }
130 
131 static __inline void
132 powerpc_mb(void)
133 {
134 	__asm __volatile("eieio; sync" : : : "memory");
135 }
136 
137 static __inline struct globaldata
138 *powerpc_get_globalp(void)
139 {
140 	struct globaldata	*ret;
141 
142 	__asm ("mfsprg %0, 0" : "=r"(ret));
143 
144 	return(ret);
145 }
146 
147 #endif /* _KERNEL */
148 
149 #endif /* !_MACHINE_CPUFUNC_H_ */
150