osd_util.h 10 KB

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