cpufunc.h revision 87702
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: head/sys/powerpc/include/cpufunc.h 87702 2001-12-11 23:33:44Z jhb $ 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 40static __inline void 41breakpoint(void) 42{ 43 44 return; 45} 46 47#endif 48 49/* CPU register mangling inlines */ 50 51static __inline void 52mtmsr(unsigned int value) 53{ 54 55 __asm __volatile ("mtmsr %0" :: "r"(value)); 56} 57 58static __inline unsigned int 59mfmsr(void) 60{ 61 unsigned int value; 62 63 __asm __volatile ("mfmsr %0" : "=r"(value)); 64 65 return (value); 66} 67 68static __inline void 69mtdec(unsigned int value) 70{ 71 72 __asm __volatile ("mtdec %0" :: "r"(value)); 73} 74 75static __inline unsigned int 76mfdec(void) 77{ 78 unsigned int value; 79 80 __asm __volatile ("mfdec %0" : "=r"(value)); 81 82 return (value); 83} 84 85/* 86 * Bogus interrupt manipulation 87 */ 88static __inline void 89disable_intr(void) 90{ 91 unsigned int msr; 92 93 msr = mfmsr(); 94 mtmsr(msr & ~PSL_EE); 95} 96 97static __inline void 98enable_intr(void) 99{ 100 unsigned int msr; 101 102 msr = mfmsr(); 103 mtmsr(msr | PSL_EE); 104} 105 106static __inline unsigned int 107save_intr(void) 108{ 109 unsigned int msr; 110 111 msr = mfmsr(); 112 113 return msr; 114} 115 116static __inline critical_t 117critical_enter(void) 118{ 119 120 return ((critical_t)save_intr()); 121} 122 123static __inline void 124restore_intr(unsigned int msr) 125{ 126 127 mtmsr(msr); 128} 129 130static __inline void 131critical_exit(critical_t msr) 132{ 133 134 return (restore_intr((unsigned int)msr)); 135} 136 137static __inline void 138powerpc_mb(void) 139{ 140 141 __asm __volatile("eieio; sync" : : : "memory"); 142} 143 144static __inline struct pcpu * 145powerpc_get_pcpup(void) 146{ 147 struct pcpu *ret; 148 149 __asm ("mfsprg %0, 0" : "=r"(ret)); 150 151 return(ret); 152} 153 154#endif /* _KERNEL */ 155 156#endif /* !_MACHINE_CPUFUNC_H_ */ 157