1/*	BSDI osd_util.h,v 1.8 1998/06/03 19:14:58 karels Exp	*/
2
3/*
4 * Copyright (c) 1996-1999 Distributed Processing Technology Corporation
5 * All rights reserved.
6 *
7 * Redistribution and use in source form, with or without modification, are
8 * permitted provided that redistributions of source code must retain the
9 * above copyright notice, this list of conditions and the following disclaimer.
10 *
11 * This software is provided `as is' by Distributed Processing Technology and
12 * any express or implied warranties, including, but not limited to, the
13 * implied warranties of merchantability and fitness for a particular purpose,
14 * are disclaimed. In no event shall Distributed Processing Technology be
15 * liable for any direct, indirect, incidental, special, exemplary or
16 * consequential damages (including, but not limited to, procurement of
17 * substitute goods or services; loss of use, data, or profits; or business
18 * interruptions) however caused and on any theory of liability, whether in
19 * contract, strict liability, or tort (including negligence or otherwise)
20 * arising in any way out of the use of this driver software, even if advised
21 * of the possibility of such damage.
22 *
23 */
24
25#ifndef         __OSD_UTIL_H
26#define         __OSD_UTIL_H
27
28/*File - OSD_UTIL.H
29 ****************************************************************************
30 *
31 *Description:
32 *
33 *      This file contains defines and function prototypes that are
34 *operating system dependent.  The resources defined in this file
35 *are not specific to any particular application.
36 *
37 *Copyright Distributed Processing Technology, Corp.
38 *        140 Candace Dr.
39 *        Maitland, Fl. 32751   USA
40 *        Phone: (407) 830-5522  Fax: (407) 260-5366
41 *        All Rights Reserved
42 *
43 *Author:       Doug Anderson
44 *Date:         1/7/94
45 *
46 *Editors:
47 *
48 *Remarks:
49 *
50 *
51 *****************************************************************************/
52
53
54/*Definitions - Defines & Constants ----------------------------------------- */
55
56/*----------------------------- */
57/* Operating system selections: */
58/*----------------------------- */
59
60/*#define               _DPT_MSDOS      */
61/*#define               _DPT_WIN_3X     */
62/*#define               _DPT_WIN_4X     */
63/*#define               _DPT_WIN_NT     */
64/*#define               _DPT_NETWARE    */
65/*#define               _DPT_OS2        */
66/*#define               _DPT_SCO        */
67/*#define               _DPT_UNIXWARE   */
68/*#define               _DPT_SOLARIS    */
69/*#define               _DPT_NEXTSTEP   */
70/*#define               _DPT_BANYAN     */
71
72/*-------------------------------- */
73/* Include the OS specific defines */
74/*-------------------------------- */
75
76/*#define       OS_SELECTION    From Above List */
77/*#define       SEMAPHORE_T     ??? */
78/*#define       DLL_HANDLE_T    ??? */
79
80#if (defined(KERNEL) && (defined(__FreeBSD__) || defined(__bsdi__)))
81# include        "i386/isa/dpt_osd_defs.h"
82#else
83# include        "osd_defs.h"
84#endif
85
86#ifndef DPT_UNALIGNED
87   #define      DPT_UNALIGNED
88#endif
89
90#ifndef DPT_EXPORT
91   #define      DPT_EXPORT
92#endif
93
94#ifndef DPT_IMPORT
95   #define      DPT_IMPORT
96#endif
97
98#ifndef DPT_RUNTIME_IMPORT
99   #define      DPT_RUNTIME_IMPORT  DPT_IMPORT
100#endif
101
102/*--------------------- */
103/* OS dependent defines */
104/*--------------------- */
105
106#if defined(_DPT_MSDOS) || defined(_DPT_WIN_3X)
107   #define      _DPT_16_BIT
108#else
109   #define      _DPT_32_BIT
110#endif
111
112#if defined(_DPT_SCO) || defined(_DPT_UNIXWARE) || defined(_DPT_SOLARIS) || \
113	defined(_DPT_AIX) || defined(SNI_MIPS) || defined(_DPT_BSDI) || defined(_DPT_FREE_BSD) \
114	|| defined(_DPT_LINUX)
115   #define      _DPT_UNIX
116#endif
117
118#if defined(_DPT_WIN_3x) || defined(_DPT_WIN_4X) || defined(_DPT_WIN_NT) || \
119	defined(_DPT_OS2)
120   #define      _DPT_DLL_SUPPORT
121#endif
122
123#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X) && !defined(_DPT_NETWARE)
124   #define      _DPT_PREEMPTIVE
125#endif
126
127#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X)
128   #define      _DPT_MULTI_THREADED
129#endif
130
131#if !defined(_DPT_MSDOS)
132   #define      _DPT_MULTI_TASKING
133#endif
134
135  /* These exist for platforms that   */
136  /* chunk when accessing mis-aligned */
137  /* data                             */
138#if defined(SNI_MIPS) || defined(_DPT_SOLARIS)
139   #if defined (_DPT_BIG_ENDIAN)
140	#if !defined (_DPT_STRICT_ALIGN)
141            #define _DPT_STRICT_ALIGN
142	#endif
143   #endif
144#endif
145
146  /* Determine if in C or C++ mode */
147#ifdef  __cplusplus
148   #define      _DPT_CPP
149#else
150   #define      _DPT_C
151#endif
152
153/*-------------------------------------------------------------------*/
154/* Under Solaris the compiler refuses to accept code like:           */
155/*   { {"DPT"}, 0, NULL .... },                                      */
156/* and complains about the {"DPT"} part by saying "cannot use { }    */
157/* to initialize char*".                                             */
158/*                                                                   */
159/* By defining these ugly macros we can get around this and also     */
160/* not have to copy and #ifdef large sections of code.  I know that  */
161/* these macros are *really* ugly, but they should help reduce       */
162/* maintenance in the long run.                                      */
163/*                                                                   */
164/*-------------------------------------------------------------------*/
165#if !defined(DPTSQO)
166   #if defined (_DPT_SOLARIS)
167      #define DPTSQO
168      #define DPTSQC
169   #else
170      #define DPTSQO {
171      #define DPTSQC }
172   #endif  /* solaris */
173#endif  /* DPTSQO */
174
175
176/*---------------------- */
177/* OS dependent typedefs */
178/*---------------------- */
179
180#if defined(_DPT_MSDOS) || defined(_DPT_SCO)
181   #define BYTE unsigned char
182   #define WORD unsigned short
183#endif
184
185#ifndef _DPT_TYPEDEFS
186   #define _DPT_TYPEDEFS
187   typedef unsigned char   uCHAR;
188   typedef unsigned short  uSHORT;
189   typedef unsigned int    uINT;
190   typedef unsigned long   uLONG;
191
192   typedef union {
193	 uCHAR        u8[4];
194	 uSHORT       u16[2];
195	 uLONG        u32;
196   } access_U;
197#endif
198
199#if !defined(NULL)
200   #define      NULL    0
201#endif
202
203
204/*Prototypes - function ----------------------------------------------------- */
205
206#ifdef  __cplusplus
207   extern "C" {         /* Declare all these functions as "C" functions */
208#endif
209
210/*------------------------ */
211/* Byte reversal functions */
212/*------------------------ */
213
214  /* Reverses the byte ordering of a 2 byte variable */
215#if !defined(osdSwap2)
216 uSHORT       osdSwap2(DPT_UNALIGNED uSHORT *);
217#endif  // !osdSwap2
218
219  /* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */
220#if !defined(osdSwap3)
221 uLONG        osdSwap3(DPT_UNALIGNED uLONG *);
222#endif  // !osdSwap3
223
224
225#ifdef  _DPT_NETWARE
226   #include "novpass.h" /* For DPT_Bswapl() prototype */
227	/* Inline the byte swap */
228   #ifdef __cplusplus
229	 inline uLONG osdSwap4(uLONG *inLong) {
230	 return *inLong = DPT_Bswapl(*inLong);
231	 }
232   #else
233	 #define osdSwap4(inLong)       DPT_Bswapl(inLong)
234   #endif  // cplusplus
235#else
236	/* Reverses the byte ordering of a 4 byte variable */
237# if !defined(osdSwap4)
238   uLONG        osdSwap4(DPT_UNALIGNED uLONG *);
239# endif  // !osdSwap4
240
241  /* The following functions ALWAYS swap regardless of the *
242   * presence of DPT_BIG_ENDIAN                            */
243
244   uSHORT       trueSwap2(DPT_UNALIGNED uSHORT *);
245   uLONG        trueSwap4(DPT_UNALIGNED uLONG *);
246
247#endif  // netware
248
249
250/*-------------------------------------*
251 * Network order swap functions        *
252 *                                     *
253 * These functions/macros will be used *
254 * by the structure insert()/extract() *
255 * functions.                          *
256 *
257 * We will enclose all structure       *
258 * portability modifications inside    *
259 * #ifdefs.  When we are ready, we     *
260 * will #define DPT_PORTABLE to begin  *
261 * using the modifications.            *
262 *-------------------------------------*/
263uLONG	netSwap4(uLONG val);
264
265#if defined(_DPT_BIG_ENDIAN)
266
267// for big-endian we need to swap
268
269#ifndef NET_SWAP_2
270#define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8))
271#endif  // NET_SWAP_2
272
273#ifndef NET_SWAP_4
274#define NET_SWAP_4(x) netSwap4((x))
275#endif  // NET_SWAP_4
276
277#else
278
279// for little-endian we don't need to do anything
280
281#ifndef NET_SWAP_2
282#define NET_SWAP_2(x) (x)
283#endif  // NET_SWAP_2
284
285#ifndef NET_SWAP_4
286#define NET_SWAP_4(x) (x)
287#endif  // NET_SWAP_4
288
289#endif  // big endian
290
291
292
293/*----------------------------------- */
294/* Run-time loadable module functions */
295/*----------------------------------- */
296
297  /* Loads the specified run-time loadable DLL */
298DLL_HANDLE_T    osdLoadModule(uCHAR *);
299  /* Unloads the specified run-time loadable DLL */
300uSHORT          osdUnloadModule(DLL_HANDLE_T);
301  /* Returns a pointer to a function inside a run-time loadable DLL */
302void *          osdGetFnAddr(DLL_HANDLE_T,uCHAR *);
303
304/*--------------------------------------- */
305/* Mutually exclusive semaphore functions */
306/*--------------------------------------- */
307
308  /* Create a named semaphore */
309SEMAPHORE_T     osdCreateNamedSemaphore(char *);
310  /* Create a mutually exlusive semaphore */
311SEMAPHORE_T     osdCreateSemaphore(void);
312	/* create an event semaphore */
313SEMAPHORE_T              osdCreateEventSemaphore(void);
314	/* create a named event semaphore */
315SEMAPHORE_T             osdCreateNamedEventSemaphore(char *);
316
317  /* Destroy the specified mutually exclusive semaphore object */
318uSHORT          osdDestroySemaphore(SEMAPHORE_T);
319  /* Request access to the specified mutually exclusive semaphore */
320uLONG           osdRequestSemaphore(SEMAPHORE_T,uLONG);
321  /* Release access to the specified mutually exclusive semaphore */
322uSHORT          osdReleaseSemaphore(SEMAPHORE_T);
323	/* wait for a event to happen */
324uLONG                            osdWaitForEventSemaphore(SEMAPHORE_T, uLONG);
325	/* signal an event */
326uLONG                            osdSignalEventSemaphore(SEMAPHORE_T);
327	/* reset the event */
328uLONG                            osdResetEventSemaphore(SEMAPHORE_T);
329
330/*----------------- */
331/* Thread functions */
332/*----------------- */
333
334  /* Releases control to the task switcher in non-preemptive */
335  /* multitasking operating systems. */
336void            osdSwitchThreads(void);
337
338  /* Starts a thread function */
339uLONG   osdStartThread(void *,void *);
340
341/* what is my thread id */
342uLONG osdGetThreadID(void);
343
344/* wakes up the specifed thread */
345void osdWakeThread(uLONG);
346
347/* osd sleep for x miliseconds */
348void osdSleep(uLONG);
349
350#define DPT_THREAD_PRIORITY_LOWEST 0x00
351#define DPT_THREAD_PRIORITY_NORMAL 0x01
352#define DPT_THREAD_PRIORITY_HIGHEST 0x02
353
354uCHAR osdSetThreadPriority(uLONG tid, uCHAR priority);
355
356#ifdef __cplusplus
357   }    /* end the xtern "C" declaration */
358#endif
359
360#endif  /* osd_util_h */
361