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