osd_util.h revision 87826
165312Smsmith/*
265312Smsmith * Copyright (c) 1996-1999 Distributed Processing Technology Corporation
365312Smsmith * All rights reserved.
465312Smsmith *
565312Smsmith * Redistribution and use in source form, with or without modification, are
665312Smsmith * permitted provided that redistributions of source code must retain the
765312Smsmith * above copyright notice, this list of conditions and the following disclaimer.
865312Smsmith *
965312Smsmith * This software is provided `as is' by Distributed Processing Technology and
1065312Smsmith * any express or implied warranties, including, but not limited to, the
1165312Smsmith * implied warranties of merchantability and fitness for a particular purpose,
1265312Smsmith * are disclaimed. In no event shall Distributed Processing Technology be
1365312Smsmith * liable for any direct, indirect, incidental, special, exemplary or
1465312Smsmith * consequential damages (including, but not limited to, procurement of
1565312Smsmith * substitute goods or services; loss of use, data, or profits; or business
1665312Smsmith * interruptions) however caused and on any theory of liability, whether in
1765312Smsmith * contract, strict liability, or tort (including negligence or otherwise)
1865312Smsmith * arising in any way out of the use of this driver software, even if advised
1965312Smsmith * of the possibility of such damage.
2065312Smsmith *
2187826Sobrien * $FreeBSD: head/sys/dev/asr/osd_util.h 87826 2001-12-13 23:48:34Z obrien $
2265312Smsmith */
2365312Smsmith
2465312Smsmith#ifndef         __OSD_UTIL_H
2565312Smsmith#define         __OSD_UTIL_H
2665312Smsmith
2765312Smsmith/*File - OSD_UTIL.H
2865312Smsmith ****************************************************************************
2965312Smsmith *
3065312Smsmith *Description:
3165312Smsmith *
3265312Smsmith *      This file contains defines and function prototypes that are
3365312Smsmith *operating system dependent.  The resources defined in this file
3465312Smsmith *are not specific to any particular application.
3565312Smsmith *
3665312Smsmith *Copyright Distributed Processing Technology, Corp.
3765312Smsmith *        140 Candace Dr.
3865312Smsmith *        Maitland, Fl. 32751   USA
3965312Smsmith *        Phone: (407) 830-5522  Fax: (407) 260-5366
4065312Smsmith *        All Rights Reserved
4165312Smsmith *
4265312Smsmith *Author:       Doug Anderson
4365312Smsmith *Date:         1/7/94
4465312Smsmith *
4565312Smsmith *Editors:
4665312Smsmith *
4765312Smsmith *Remarks:
4865312Smsmith *
4965312Smsmith *
5065312Smsmith *****************************************************************************/
5165312Smsmith
5265312Smsmith
5365312Smsmith/*Definitions - Defines & Constants ----------------------------------------- */
5465312Smsmith
5565312Smsmith/*----------------------------- */
5665312Smsmith/* Operating system selections: */
5765312Smsmith/*----------------------------- */
5865312Smsmith
5965312Smsmith/*#define               _DPT_MSDOS      */
6065312Smsmith/*#define               _DPT_WIN_3X     */
6165312Smsmith/*#define               _DPT_WIN_4X     */
6265312Smsmith/*#define               _DPT_WIN_NT     */
6365312Smsmith/*#define               _DPT_NETWARE    */
6465312Smsmith/*#define               _DPT_OS2        */
6565312Smsmith/*#define               _DPT_SCO        */
6665312Smsmith/*#define               _DPT_UNIXWARE   */
6765312Smsmith/*#define               _DPT_SOLARIS    */
6865312Smsmith/*#define               _DPT_NEXTSTEP   */
6965312Smsmith/*#define               _DPT_BANYAN     */
7065312Smsmith
7165312Smsmith/*-------------------------------- */
7265312Smsmith/* Include the OS specific defines */
7365312Smsmith/*-------------------------------- */
7465312Smsmith
7565312Smsmith/*#define       OS_SELECTION    From Above List */
7665312Smsmith/*#define       SEMAPHORE_T     ??? */
7765312Smsmith/*#define       DLL_HANDLE_T    ??? */
7865312Smsmith
7965312Smsmith#if (defined(KERNEL) && defined(__bsdi__))
8065312Smsmith# include        "i386/isa/dpt_osd_defs.h"
8165312Smsmith#elif ((defined(KERNEL) || defined(_KERNEL)) && defined(__FreeBSD__))
8265312Smsmith# if (KERN_VERSION < 3)
8365312Smsmith#  include        "i386/isa/dpt_osd_defs.h"
8465312Smsmith# else
8565312Smsmith#  include        "dev/asr/osd_defs.h"
8665312Smsmith# endif
8765312Smsmith#else
8865312Smsmith# include        "osd_defs.h"
8965312Smsmith#endif
9065312Smsmith
9165312Smsmith#ifndef DPT_UNALIGNED
9265312Smsmith   #define      DPT_UNALIGNED
9365312Smsmith#endif
9465312Smsmith
9565312Smsmith#ifndef DPT_EXPORT
9665312Smsmith   #define      DPT_EXPORT
9765312Smsmith#endif
9865312Smsmith
9965312Smsmith#ifndef DPT_IMPORT
10065312Smsmith   #define      DPT_IMPORT
10165312Smsmith#endif
10265312Smsmith
10365312Smsmith#ifndef DPT_RUNTIME_IMPORT
10465312Smsmith   #define      DPT_RUNTIME_IMPORT  DPT_IMPORT
10565312Smsmith#endif
10665312Smsmith
10765312Smsmith/*--------------------- */
10865312Smsmith/* OS dependent defines */
10965312Smsmith/*--------------------- */
11065312Smsmith
11165312Smsmith#if defined (_DPT_MSDOS) || defined (_DPT_WIN_3X)
11265312Smsmith   #define      _DPT_16_BIT
11365312Smsmith#else
11465312Smsmith   #define      _DPT_32_BIT
11565312Smsmith#endif
11665312Smsmith
11765312Smsmith#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)
11865312Smsmith   #define      _DPT_UNIX
11965312Smsmith#endif
12065312Smsmith
12165312Smsmith#if defined (_DPT_WIN_3x) || defined (_DPT_WIN_4X) || defined (_DPT_WIN_NT) \
12265312Smsmith	    || defined (_DPT_OS2)
12365312Smsmith   #define      _DPT_DLL_SUPPORT
12465312Smsmith#endif
12565312Smsmith
12665312Smsmith#if !defined (_DPT_MSDOS) && !defined (_DPT_WIN_3X) && !defined (_DPT_NETWARE)
12765312Smsmith   #define      _DPT_PREEMPTIVE
12865312Smsmith#endif
12965312Smsmith
13065312Smsmith#if !defined (_DPT_MSDOS) && !defined (_DPT_WIN_3X)
13165312Smsmith   #define      _DPT_MULTI_THREADED
13265312Smsmith#endif
13365312Smsmith
13465312Smsmith#if !defined (_DPT_MSDOS)
13565312Smsmith   #define      _DPT_MULTI_TASKING
13665312Smsmith#endif
13765312Smsmith
13865312Smsmith  /* These exist for platforms that   */
13965312Smsmith  /* chunk when accessing mis-aligned */
14065312Smsmith  /* data                             */
14165312Smsmith#if defined (SNI_MIPS) || defined (_DPT_SOLARIS)
14265312Smsmith   #if defined (_DPT_BIG_ENDIAN)
14365312Smsmith	#if !defined (_DPT_STRICT_ALIGN)
14465312Smsmith            #define _DPT_STRICT_ALIGN
14565312Smsmith	#endif
14665312Smsmith   #endif
14765312Smsmith#endif
14865312Smsmith
14965312Smsmith  /* Determine if in C or C++ mode */
15065312Smsmith#ifdef  __cplusplus
15165312Smsmith   #define      _DPT_CPP
15265312Smsmith#else
15365312Smsmith   #define      _DPT_C
15465312Smsmith#endif
15565312Smsmith
15665312Smsmith/*-------------------------------------------------------------------*/
15765312Smsmith/* Under Solaris the compiler refuses to accept code like:           */
15865312Smsmith/*   { {"DPT"}, 0, NULL .... },                                      */
15965312Smsmith/* and complains about the {"DPT"} part by saying "cannot use { }    */
16065312Smsmith/* to initialize char*".                                             */
16165312Smsmith/*                                                                   */
16265312Smsmith/* By defining these ugly macros we can get around this and also     */
16365312Smsmith/* not have to copy and #ifdef large sections of code.  I know that  */
16465312Smsmith/* these macros are *really* ugly, but they should help reduce       */
16565312Smsmith/* maintenance in the long run.                                      */
16665312Smsmith/*                                                                   */
16765312Smsmith/* In the meantime, just pray that we can all move to Win32 as soon  */
16865312Smsmith/* as possible...                                                    */
16965312Smsmith/*-------------------------------------------------------------------*/
17065312Smsmith#if !defined (DPTSQO)
17165312Smsmith   #if defined (_DPT_SOLARIS)
17265312Smsmith      #define DPTSQO
17365312Smsmith      #define DPTSQC
17465312Smsmith   #else
17565312Smsmith      #define DPTSQO {
17665312Smsmith      #define DPTSQC }
17765312Smsmith   #endif  /* solaris */
17865312Smsmith#endif  /* DPTSQO */
17965312Smsmith
18065312Smsmith
18165312Smsmith/*---------------------- */
18265312Smsmith/* OS dependent typedefs */
18365312Smsmith/*---------------------- */
18465312Smsmith
18565312Smsmith#if defined (_DPT_MSDOS) || defined (_DPT_SCO)
18665312Smsmith   #define BYTE unsigned char
18765312Smsmith   #define WORD unsigned short
18865312Smsmith#endif
18965312Smsmith
19065312Smsmith#ifndef _DPT_TYPEDEFS
19165312Smsmith   #define _DPT_TYPEDEFS
19265312Smsmith   typedef unsigned char   uCHAR;
19365312Smsmith   typedef unsigned short  uSHORT;
19465312Smsmith   typedef unsigned int    uINT;
19565312Smsmith   typedef unsigned long   uLONG;
19665312Smsmith
19765312Smsmith   typedef union {
19865312Smsmith	 uCHAR        u8[4];
19965312Smsmith	 uSHORT       u16[2];
20065312Smsmith	 uLONG        u32;
20165312Smsmith   } access_U;
20265312Smsmith#endif
20365312Smsmith
20465312Smsmith#if !defined (NULL)
20565312Smsmith   #define      NULL    0
20665312Smsmith#endif
20765312Smsmith
20865312Smsmith
20965312Smsmith/*Prototypes - function ----------------------------------------------------- */
21065312Smsmith
21165312Smsmith#ifdef  __cplusplus
21265312Smsmith   extern "C" {         /* Declare all these functions as "C" functions */
21365312Smsmith#endif
21465312Smsmith
21565312Smsmith/*------------------------ */
21665312Smsmith/* Byte reversal functions */
21765312Smsmith/*------------------------ */
21865312Smsmith
21965312Smsmith  /* Reverses the byte ordering of a 2 byte variable */
22065312Smsmith#if (!defined(osdSwap2))
22165312Smsmith uSHORT       osdSwap2(DPT_UNALIGNED uSHORT *);
22287816Sjhb#endif  /* !osdSwap2 */
22365312Smsmith
22465312Smsmith  /* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */
22565312Smsmith#if (!defined(osdSwap3))
22665312Smsmith uLONG        osdSwap3(DPT_UNALIGNED uLONG *);
22787816Sjhb#endif  /* !osdSwap3 */
22865312Smsmith
22965312Smsmith
23065312Smsmith#ifdef  _DPT_NETWARE
23165312Smsmith   #include "novpass.h" /* For DPT_Bswapl() prototype */
23265312Smsmith	/* Inline the byte swap */
23365312Smsmith   #ifdef __cplusplus
23465312Smsmith	 inline uLONG osdSwap4(uLONG *inLong) {
23565312Smsmith	 return *inLong = DPT_Bswapl(*inLong);
23665312Smsmith	 }
23765312Smsmith   #else
23865312Smsmith	 #define osdSwap4(inLong)       DPT_Bswapl(inLong)
23987816Sjhb   #endif  /* cplusplus */
24065312Smsmith#else
24165312Smsmith	/* Reverses the byte ordering of a 4 byte variable */
24265312Smsmith# if (!defined(osdSwap4))
24365312Smsmith   uLONG        osdSwap4(DPT_UNALIGNED uLONG *);
24487816Sjhb# endif  /* !osdSwap4 */
24565312Smsmith
24665312Smsmith  /* The following functions ALWAYS swap regardless of the *
24765312Smsmith   * presence of DPT_BIG_ENDIAN                            */
24865312Smsmith
24965312Smsmith   uSHORT       trueSwap2(DPT_UNALIGNED uSHORT *);
25065312Smsmith   uLONG        trueSwap4(DPT_UNALIGNED uLONG *);
25165312Smsmith
25287816Sjhb#endif  /* netware */
25365312Smsmith
25465312Smsmith
25565312Smsmith/*-------------------------------------*
25665312Smsmith * Network order swap functions        *
25765312Smsmith *                                     *
25865312Smsmith * These functions/macros will be used *
25965312Smsmith * by the structure insert()/extract() *
26065312Smsmith * functions.                          *
26165312Smsmith *
26265312Smsmith * We will enclose all structure       *
26365312Smsmith * portability modifications inside    *
26465312Smsmith * #ifdefs.  When we are ready, we     *
26565312Smsmith * will #define DPT_PORTABLE to begin  *
26665312Smsmith * using the modifications.            *
26765312Smsmith *-------------------------------------*/
26865312SmsmithuLONG	netSwap4(uLONG val);
26965312Smsmith
27065312Smsmith#if defined (_DPT_BIG_ENDIAN)
27165312Smsmith
27287816Sjhb/* for big-endian we need to swap */
27365312Smsmith
27465312Smsmith#ifndef NET_SWAP_2
27565312Smsmith#define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8))
27687816Sjhb#endif  /* NET_SWAP_2 */
27765312Smsmith
27865312Smsmith#ifndef NET_SWAP_4
27965312Smsmith#define NET_SWAP_4(x) netSwap4((x))
28087816Sjhb#endif  /* NET_SWAP_4 */
28165312Smsmith
28265312Smsmith#else
28365312Smsmith
28465312Smsmith/* for little-endian we don't need to do anything */
28565312Smsmith
28665312Smsmith#ifndef NET_SWAP_2
28765312Smsmith#define NET_SWAP_2(x) (x)
28887816Sjhb#endif  /* NET_SWAP_2 */
28965312Smsmith
29065312Smsmith#ifndef NET_SWAP_4
29165312Smsmith#define NET_SWAP_4(x) (x)
29287816Sjhb#endif  /* NET_SWAP_4 */
29365312Smsmith
29487816Sjhb#endif  /* big endian */
29565312Smsmith
29665312Smsmith
29765312Smsmith
29865312Smsmith/*----------------------------------- */
29965312Smsmith/* Run-time loadable module functions */
30065312Smsmith/*----------------------------------- */
30165312Smsmith
30265312Smsmith  /* Loads the specified run-time loadable DLL */
30365312SmsmithDLL_HANDLE_T    osdLoadModule(uCHAR *);
30465312Smsmith  /* Unloads the specified run-time loadable DLL */
30565312SmsmithuSHORT          osdUnloadModule(DLL_HANDLE_T);
30665312Smsmith  /* Returns a pointer to a function inside a run-time loadable DLL */
30765312Smsmithvoid *          osdGetFnAddr(DLL_HANDLE_T,uCHAR *);
30865312Smsmith
30965312Smsmith/*--------------------------------------- */
31065312Smsmith/* Mutually exclusive semaphore functions */
31165312Smsmith/*--------------------------------------- */
31265312Smsmith
31365312Smsmith  /* Create a named semaphore */
31465312SmsmithSEMAPHORE_T     osdCreateNamedSemaphore(char *);
31565312Smsmith  /* Create a mutually exlusive semaphore */
31665312SmsmithSEMAPHORE_T     osdCreateSemaphore(void);
31765312Smsmith	/* create an event semaphore */
31865312SmsmithSEMAPHORE_T              osdCreateEventSemaphore(void);
31965312Smsmith	/* create a named event semaphore */
32065312SmsmithSEMAPHORE_T             osdCreateNamedEventSemaphore(char *);
32165312Smsmith
32265312Smsmith  /* Destroy the specified mutually exclusive semaphore object */
32365312SmsmithuSHORT          osdDestroySemaphore(SEMAPHORE_T);
32465312Smsmith  /* Request access to the specified mutually exclusive semaphore */
32565312SmsmithuLONG           osdRequestSemaphore(SEMAPHORE_T,uLONG);
32665312Smsmith  /* Release access to the specified mutually exclusive semaphore */
32765312SmsmithuSHORT          osdReleaseSemaphore(SEMAPHORE_T);
32865312Smsmith	/* wait for a event to happen */
32965312SmsmithuLONG                            osdWaitForEventSemaphore(SEMAPHORE_T, uLONG);
33065312Smsmith	/* signal an event */
33165312SmsmithuLONG                            osdSignalEventSemaphore(SEMAPHORE_T);
33265312Smsmith	/* reset the event */
33365312SmsmithuLONG                            osdResetEventSemaphore(SEMAPHORE_T);
33465312Smsmith
33565312Smsmith/*----------------- */
33665312Smsmith/* Thread functions */
33765312Smsmith/*----------------- */
33865312Smsmith
33965312Smsmith  /* Releases control to the task switcher in non-preemptive */
34065312Smsmith  /* multitasking operating systems. */
34165312Smsmithvoid            osdSwitchThreads(void);
34265312Smsmith
34365312Smsmith  /* Starts a thread function */
34465312SmsmithuLONG   osdStartThread(void *,void *);
34565312Smsmith
34665312Smsmith/* what is my thread id */
34765312SmsmithuLONG osdGetThreadID(void);
34865312Smsmith
34965312Smsmith/* wakes up the specifed thread */
35065312Smsmithvoid osdWakeThread(uLONG);
35165312Smsmith
35265312Smsmith/* osd sleep for x miliseconds */
35365312Smsmithvoid osdSleep(uLONG);
35465312Smsmith
35565312Smsmith#define DPT_THREAD_PRIORITY_LOWEST 0x00
35665312Smsmith#define DPT_THREAD_PRIORITY_NORMAL 0x01
35765312Smsmith#define DPT_THREAD_PRIORITY_HIGHEST 0x02
35865312Smsmith
35965312SmsmithuCHAR osdSetThreadPriority(uLONG tid, uCHAR priority);
36065312Smsmith
36165312Smsmith#ifdef __cplusplus
36265312Smsmith   }    /* end the xtern "C" declaration */
36365312Smsmith#endif
36465312Smsmith
36565312Smsmith#endif  /* osd_util_h */
366