1/* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* 29 * @OSF_COPYRIGHT@ 30 * 31 */ 32 33/* 34 * mach/i386/flipc_dep.h 35 * 36 * This file will have all of the FLIPC implementation machine dependent 37 * defines that need to be visible to both kernel and AIL (eg. bus locks 38 * and bus synchronization primitives). 39 */ 40 41#ifndef _MACH_FLIPC_DEP_H_ 42#define _MACH_FLIPC_DEP_H_ 43 44/* For the 386, we don't need to wrap synchronization variable writes 45 at all. */ 46#define SYNCVAR_WRITE(statement) statement 47 48/* And similarly (I believe; check on this), for the 386 there isn't any 49 requirement for write fences. */ 50#define WRITE_FENCE() 51 52/* 53 * Flipc simple lock defines. These are almost completely for the use 54 * of the AIL; the reason they are in this file is that they need to 55 * be initialized properly in the communications buffer initialization 56 * routine. Sigh. Note in particular that the kernel has no defined 57 * "simple_lock_yield_function", so it had better never expand the 58 * macro simple_lock_acquire. 59 * 60 * These locks may be declared by "flipc_simple_lock lock;". If they 61 * are instead declared by FLIPC_DECL_SIMPLE_LOCK(class,lockname) they 62 * may be used without initialization. 63 */ 64 65#define SIMPLE_LOCK_INITIALIZER 0 66#define FLIPC_DECL_SIMPLE_LOCK(class,lockname) \ 67class flipc_simple_lock (lockname) = SIMPLE_LOCK_INITIALIZER 68 69/* 70 * Lower case because they may be macros or functions. 71 * I'll include the function prototypes just for examples here. 72 */ 73 74#define flipc_simple_lock_init(lock) \ 75do { \ 76 *(lock) = SIMPLE_LOCK_INITIALIZER; \ 77} while (0) 78 79/* 80 * Defines of the actual routines, for gcc. 81 */ 82 83#define flipc_simple_lock_locked(lock) ((*lock) != SIMPLE_LOCK_INITIALIZER) 84 85#ifdef __GNUC__ 86 extern __inline__ int flipc_simple_lock_try(flipc_simple_lock *lock) 87{ 88 int r; 89 __asm__ volatile("movl $1, %0; xchgl %0, %1" : "=&r" (r), "=m" (*lock)); 90 return !r; 91} 92 93/* I don't know why this requires an ASM, but I'll follow the leader. */ 94extern __inline__ void flipc_simple_lock_release(flipc_simple_lock *lock) 95{ 96 register int t; 97 98 __asm__ volatile("xorl %0, %0; xchgl %0, %1" : "=&r" (t), "=m" (*lock)); 99} 100#else /* __GNUC__ */ 101/* If we aren't compiling with gcc, the above need to be functions. */ 102#endif /* __GNUC__ */ 103 104#endif /* _MACH_FLIPC_DEP_H_ */ 105