cpufunc.h revision 78878
1275988Sngie/*- 2240116Smarcel * Copyright (c) 1998 Doug Rabson 3240116Smarcel * All rights reserved. 4240116Smarcel * 5240116Smarcel * Redistribution and use in source and binary forms, with or without 6240116Smarcel * modification, are permitted provided that the following conditions 7240116Smarcel * are met: 8240116Smarcel * 1. Redistributions of source code must retain the above copyright 9240116Smarcel * notice, this list of conditions and the following disclaimer. 10240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright 11240116Smarcel * notice, this list of conditions and the following disclaimer in the 12240116Smarcel * documentation and/or other materials provided with the distribution. 13240116Smarcel * 14240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15240116Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16240116Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17240116Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18240116Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20240116Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21240116Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22240116Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23240116Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24275988Sngie * SUCH DAMAGE. 25240116Smarcel * 26240116Smarcel * $FreeBSD: head/sys/powerpc/include/cpufunc.h 78878 2001-06-27 12:17:23Z benno $ 27240116Smarcel */ 28240116Smarcel 29240116Smarcel#ifndef _MACHINE_CPUFUNC_H_ 30240116Smarcel#define _MACHINE_CPUFUNC_H_ 31240116Smarcel 32240116Smarcel#ifdef _KERNEL 33240116Smarcel 34240116Smarcel#include <sys/types.h> 35240116Smarcel 36240116Smarcel#include <machine/psl.h> 37240116Smarcel 38240116Smarcel#ifdef __GNUC__ 39240116Smarcel 40240116Smarcelstatic __inline void 41240116Smarcelbreakpoint(void) 42240116Smarcel{ 43240116Smarcel return; 44240116Smarcel} 45240116Smarcel 46240116Smarcel#endif 47240116Smarcel 48240116Smarcel/* CPU register mangling inlines */ 49240116Smarcel 50240116Smarcelstatic __inline void 51240116Smarcelmtmsr(unsigned int value) 52240116Smarcel{ 53240116Smarcel __asm __volatile ("mtmsr %0" :: "r"(value)); 54240116Smarcel} 55240116Smarcel 56240116Smarcelstatic __inline unsigned int 57240116Smarcelmfmsr(void) 58240116Smarcel{ 59240116Smarcel unsigned int value; 60240116Smarcel 61240116Smarcel __asm __volatile ("mfmsr %0" : "=r"(value)); 62240116Smarcel 63240116Smarcel return (value); 64240116Smarcel} 65240116Smarcel 66240116Smarcelstatic __inline void 67240116Smarcelmtdec(unsigned int value) 68240116Smarcel{ 69275988Sngie __asm __volatile ("mtdec %0" :: "r"(value)); 70} 71 72static __inline unsigned int 73mfdec(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 */ 85static __inline void 86disable_intr(void) 87{ 88 unsigned int msr; 89 90 msr = mfmsr(); 91 mtmsr(msr & ~PSL_EE); 92} 93 94static __inline void 95enable_intr(void) 96{ 97 unsigned int msr; 98 99 msr = mfmsr(); 100 mtmsr(msr | PSL_EE); 101} 102 103static __inline unsigned int 104save_intr(void) 105{ 106 unsigned int msr; 107 108 msr = mfmsr(); 109 110 return msr; 111} 112 113static __inline critical_t 114critical_enter(void) 115{ 116 return ((critical_t)save_intr()); 117} 118 119static __inline void 120restore_intr(unsigned int msr) 121{ 122 mtmsr(msr); 123} 124 125static __inline void 126critical_exit(critical_t msr) 127{ 128 return (restore_intr((unsigned int)msr)); 129} 130 131static __inline void 132powerpc_mb(void) 133{ 134 __asm __volatile("eieio; sync" : : : "memory"); 135} 136 137static __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