2 * Copyright (c) 1996-1999 Distributed Processing Technology Corporation
5 * Redistribution and use in source form, with or without modification, are
6 * permitted provided that redistributions of source code must retain the
7 * above copyright notice, this list of conditions and the following disclaimer.
9 * This software is provided `as is' by Distributed Processing Technology and
10 * any express or implied warranties, including, but not limited to, the
11 * implied warranties of merchantability and fitness for a particular purpose,
12 * are disclaimed. In no event shall Distributed Processing Technology be
13 * liable for any direct, indirect, incidental, special, exemplary or
14 * consequential damages (including, but not limited to, procurement of
15 * substitute goods or services; loss of use, data, or profits; or business
16 * interruptions) however caused and on any theory of liability, whether in
17 * contract, strict liability, or tort (including negligence or otherwise)
18 * arising in any way out of the use of this driver software, even if advised
19 * of the possibility of such damage.
21 * $FreeBSD: src/sys/dev/asr/osd_util.h,v 1.10 2005/01/06 01:42:29 imp Exp $
28 ****************************************************************************
32 * This file contains defines and function prototypes that are
33 *operating system dependent. The resources defined in this file
34 *are not specific to any particular application.
36 *Copyright Distributed Processing Technology, Corp.
38 * Maitland, Fl. 32751 USA
39 * Phone: (407) 830-5522 Fax: (407) 260-5366
42 *Author: Doug Anderson
50 *****************************************************************************/
53 /*Definitions - Defines & Constants ----------------------------------------- */
55 /*----------------------------- */
56 /* Operating system selections: */
57 /*----------------------------- */
59 /*#define _DPT_MSDOS */
60 /*#define _DPT_WIN_3X */
61 /*#define _DPT_WIN_4X */
62 /*#define _DPT_WIN_NT */
63 /*#define _DPT_NETWARE */
66 /*#define _DPT_UNIXWARE */
67 /*#define _DPT_SOLARIS */
68 /*#define _DPT_NEXTSTEP */
69 /*#define _DPT_BANYAN */
71 /*-------------------------------- */
72 /* Include the OS specific defines */
73 /*-------------------------------- */
75 /*#define OS_SELECTION From Above List */
76 /*#define SEMAPHORE_T ??? */
77 /*#define DLL_HANDLE_T ??? */
93 #ifndef DPT_RUNTIME_IMPORT
94 #define DPT_RUNTIME_IMPORT DPT_IMPORT
97 /*--------------------- */
98 /* OS dependent defines */
99 /*--------------------- */
101 #if defined(_DPT_MSDOS) || defined(_DPT_WIN_3X)
107 #if defined(_DPT_SCO) || defined(_DPT_UNIXWARE) || defined(_DPT_SOLARIS) || defined(_DPT_AIX) || defined(SNI_MIPS) || defined(_DPT_BSDI) || defined(_DPT_FREE_BSD) || defined(_DPT_LINUX)
111 #if defined(_DPT_WIN_3x) || defined(_DPT_WIN_4X) || defined(_DPT_WIN_NT) \
113 #define _DPT_DLL_SUPPORT
116 #if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X) && !defined(_DPT_NETWARE)
117 #define _DPT_PREEMPTIVE
120 #if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X)
121 #define _DPT_MULTI_THREADED
124 #if !defined(_DPT_MSDOS)
125 #define _DPT_MULTI_TASKING
128 /* These exist for platforms that */
129 /* chunk when accessing mis-aligned */
131 #if defined(SNI_MIPS) || defined(_DPT_SOLARIS)
132 #if defined(_DPT_BIG_ENDIAN)
133 #if !defined(_DPT_STRICT_ALIGN)
134 #define _DPT_STRICT_ALIGN
139 /* Determine if in C or C++ mode */
146 /*-------------------------------------------------------------------*/
147 /* Under Solaris the compiler refuses to accept code like: */
148 /* { {"DPT"}, 0, NULL .... }, */
149 /* and complains about the {"DPT"} part by saying "cannot use { } */
150 /* to initialize char*". */
152 /* By defining these ugly macros we can get around this and also */
153 /* not have to copy and #ifdef large sections of code. I know that */
154 /* these macros are *really* ugly, but they should help reduce */
155 /* maintenance in the long run. */
157 /* In the meantime, just pray that we can all move to Win32 as soon */
159 /*-------------------------------------------------------------------*/
161 #if defined(_DPT_SOLARIS)
171 /*---------------------- */
172 /* OS dependent typedefs */
173 /*---------------------- */
175 #if defined(_DPT_MSDOS) || defined(_DPT_SCO)
176 #define BYTE unsigned char
177 #define WORD unsigned short
180 #ifndef _DPT_TYPEDEFS
181 #define _DPT_TYPEDEFS
182 typedef unsigned char uCHAR;
183 typedef unsigned short uSHORT;
184 typedef unsigned int uINT;
185 typedef unsigned long uLONG;
199 /*Prototypes - function ----------------------------------------------------- */
202 extern "C" { /* Declare all these functions as "C" functions */
205 /*------------------------ */
206 /* Byte reversal functions */
207 /*------------------------ */
209 /* Reverses the byte ordering of a 2 byte variable */
210 #if (!defined(osdSwap2))
211 uSHORT osdSwap2(DPT_UNALIGNED uSHORT *);
212 #endif /* !osdSwap2 */
214 /* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */
215 #if (!defined(osdSwap3))
216 uLONG osdSwap3(DPT_UNALIGNED uLONG *);
217 #endif /* !osdSwap3 */
221 #include "novpass.h" /* For DPT_Bswapl() prototype */
222 /* Inline the byte swap */
224 inline uLONG osdSwap4(uLONG *inLong) {
225 return *inLong = DPT_Bswapl(*inLong);
228 #define osdSwap4(inLong) DPT_Bswapl(inLong)
229 #endif /* cplusplus */
231 /* Reverses the byte ordering of a 4 byte variable */
232 # if (!defined(osdSwap4))
233 uLONG osdSwap4(DPT_UNALIGNED uLONG *);
234 # endif /* !osdSwap4 */
236 /* The following functions ALWAYS swap regardless of the *
237 * presence of DPT_BIG_ENDIAN */
239 uSHORT trueSwap2(DPT_UNALIGNED uSHORT *);
240 uLONG trueSwap4(DPT_UNALIGNED uLONG *);
245 /*-------------------------------------*
246 * Network order swap functions *
248 * These functions/macros will be used *
249 * by the structure insert()/extract() *
252 * We will enclose all structure *
253 * portability modifications inside *
254 * #ifdefs. When we are ready, we *
255 * will #define DPT_PORTABLE to begin *
256 * using the modifications. *
257 *-------------------------------------*/
258 uLONG netSwap4(uLONG val);
260 #if defined(_DPT_BIG_ENDIAN)
262 /* for big-endian we need to swap */
265 #define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8))
266 #endif /* NET_SWAP_2 */
269 #define NET_SWAP_4(x) netSwap4((x))
270 #endif /* NET_SWAP_4 */
274 /* for little-endian we don't need to do anything */
277 #define NET_SWAP_2(x) (x)
278 #endif /* NET_SWAP_2 */
281 #define NET_SWAP_4(x) (x)
282 #endif /* NET_SWAP_4 */
284 #endif /* big endian */
288 /*----------------------------------- */
289 /* Run-time loadable module functions */
290 /*----------------------------------- */
292 /* Loads the specified run-time loadable DLL */
293 DLL_HANDLE_T osdLoadModule(uCHAR *);
294 /* Unloads the specified run-time loadable DLL */
295 uSHORT osdUnloadModule(DLL_HANDLE_T);
296 /* Returns a pointer to a function inside a run-time loadable DLL */
297 void * osdGetFnAddr(DLL_HANDLE_T,uCHAR *);
299 /*--------------------------------------- */
300 /* Mutually exclusive semaphore functions */
301 /*--------------------------------------- */
303 /* Create a named semaphore */
304 SEMAPHORE_T osdCreateNamedSemaphore(char *);
305 /* Create a mutually exlusive semaphore */
306 SEMAPHORE_T osdCreateSemaphore(void);
307 /* create an event semaphore */
308 SEMAPHORE_T osdCreateEventSemaphore(void);
309 /* create a named event semaphore */
310 SEMAPHORE_T osdCreateNamedEventSemaphore(char *);
312 /* Destroy the specified mutually exclusive semaphore object */
313 uSHORT osdDestroySemaphore(SEMAPHORE_T);
314 /* Request access to the specified mutually exclusive semaphore */
315 uLONG osdRequestSemaphore(SEMAPHORE_T,uLONG);
316 /* Release access to the specified mutually exclusive semaphore */
317 uSHORT osdReleaseSemaphore(SEMAPHORE_T);
318 /* wait for an event to happen */
319 uLONG osdWaitForEventSemaphore(SEMAPHORE_T, uLONG);
320 /* signal an event */
321 uLONG osdSignalEventSemaphore(SEMAPHORE_T);
322 /* reset the event */
323 uLONG osdResetEventSemaphore(SEMAPHORE_T);
325 /*----------------- */
326 /* Thread functions */
327 /*----------------- */
329 /* Releases control to the task switcher in non-preemptive */
330 /* multitasking operating systems. */
331 void osdSwitchThreads(void);
333 /* Starts a thread function */
334 uLONG osdStartThread(void *,void *);
336 /* what is my thread id */
337 uLONG osdGetThreadID(void);
339 /* wakes up the specifed thread */
340 void osdWakeThread(uLONG);
342 /* osd sleep for x miliseconds */
343 void osdSleep(uLONG);
345 #define DPT_THREAD_PRIORITY_LOWEST 0x00
346 #define DPT_THREAD_PRIORITY_NORMAL 0x01
347 #define DPT_THREAD_PRIORITY_HIGHEST 0x02
349 uCHAR osdSetThreadPriority(uLONG tid, uCHAR priority);
352 } /* end the xtern "C" declaration */
355 #endif /* osd_util_h */