osd_util.h revision 139749
190075Sobrien/*- 290075Sobrien * Copyright (c) 1996-1999 Distributed Processing Technology Corporation 3169699Skan * All rights reserved. 490075Sobrien * 590075Sobrien * Redistribution and use in source form, with or without modification, are 690075Sobrien * permitted provided that redistributions of source code must retain the 790075Sobrien * above copyright notice, this list of conditions and the following disclaimer. 890075Sobrien * 990075Sobrien * This software is provided `as is' by Distributed Processing Technology and 1090075Sobrien * any express or implied warranties, including, but not limited to, the 1190075Sobrien * implied warranties of merchantability and fitness for a particular purpose, 1290075Sobrien * are disclaimed. In no event shall Distributed Processing Technology be 1390075Sobrien * liable for any direct, indirect, incidental, special, exemplary or 1490075Sobrien * consequential damages (including, but not limited to, procurement of 1590075Sobrien * substitute goods or services; loss of use, data, or profits; or business 1690075Sobrien * interruptions) however caused and on any theory of liability, whether in 1790075Sobrien * contract, strict liability, or tort (including negligence or otherwise) 1890075Sobrien * arising in any way out of the use of this driver software, even if advised 19169699Skan * of the possibility of such damage. 20169699Skan * 2190075Sobrien * $FreeBSD: head/sys/dev/asr/osd_util.h 139749 2005-01-06 01:43:34Z imp $ 2290075Sobrien */ 2390075Sobrien 2490075Sobrien#ifndef __OSD_UTIL_H 2590075Sobrien#define __OSD_UTIL_H 2690075Sobrien 27132729Skan/*File - OSD_UTIL.H 2890075Sobrien **************************************************************************** 2990075Sobrien * 30169699Skan *Description: 3190075Sobrien * 3290075Sobrien * This file contains defines and function prototypes that are 3390075Sobrien *operating system dependent. The resources defined in this file 34169699Skan *are not specific to any particular application. 35169699Skan * 36169699Skan *Copyright Distributed Processing Technology, Corp. 37169699Skan * 140 Candace Dr. 3890075Sobrien * Maitland, Fl. 32751 USA 3990075Sobrien * Phone: (407) 830-5522 Fax: (407) 260-5366 4090075Sobrien * All Rights Reserved 41117406Skan * 4290075Sobrien *Author: Doug Anderson 4390075Sobrien *Date: 1/7/94 4490075Sobrien * 4590075Sobrien *Editors: 4690075Sobrien * 4790075Sobrien *Remarks: 4890075Sobrien * 4990075Sobrien * 5090075Sobrien *****************************************************************************/ 5190075Sobrien 5290075Sobrien 5390075Sobrien/*Definitions - Defines & Constants ----------------------------------------- */ 5490075Sobrien 5590075Sobrien/*----------------------------- */ 56132729Skan/* Operating system selections: */ 5790075Sobrien/*----------------------------- */ 5890075Sobrien 5990075Sobrien/*#define _DPT_MSDOS */ 6090075Sobrien/*#define _DPT_WIN_3X */ 6190075Sobrien/*#define _DPT_WIN_4X */ 6290075Sobrien/*#define _DPT_WIN_NT */ 6390075Sobrien/*#define _DPT_NETWARE */ 6490075Sobrien/*#define _DPT_OS2 */ 6590075Sobrien/*#define _DPT_SCO */ 6690075Sobrien/*#define _DPT_UNIXWARE */ 6790075Sobrien/*#define _DPT_SOLARIS */ 6890075Sobrien/*#define _DPT_NEXTSTEP */ 6990075Sobrien/*#define _DPT_BANYAN */ 7090075Sobrien 7190075Sobrien/*-------------------------------- */ 7290075Sobrien/* Include the OS specific defines */ 73169699Skan/*-------------------------------- */ 74169699Skan 75169699Skan/*#define OS_SELECTION From Above List */ 7690075Sobrien/*#define SEMAPHORE_T ??? */ 7790075Sobrien/*#define DLL_HANDLE_T ??? */ 7890075Sobrien 7990075Sobrien#if (defined(KERNEL) && defined(__bsdi__)) 8090075Sobrien# include "i386/isa/dpt_osd_defs.h" 8190075Sobrien#elif ((defined(KERNEL) || defined(_KERNEL)) && defined(__FreeBSD__)) 8290075Sobrien# if (KERN_VERSION < 3) 8390075Sobrien# include "i386/isa/dpt_osd_defs.h" 8490075Sobrien# else 85169699Skan# include "dev/asr/osd_defs.h" 86169699Skan# endif 87169699Skan#else 88132729Skan# include "osd_defs.h" 8990075Sobrien#endif 9090075Sobrien 9190075Sobrien#ifndef DPT_UNALIGNED 9290075Sobrien #define DPT_UNALIGNED 93117406Skan#endif 94169699Skan 9590075Sobrien#ifndef DPT_EXPORT 9690075Sobrien #define DPT_EXPORT 97169699Skan#endif 98132729Skan 99132729Skan#ifndef DPT_IMPORT 100132729Skan #define DPT_IMPORT 10190075Sobrien#endif 10290075Sobrien 10390075Sobrien#ifndef DPT_RUNTIME_IMPORT 10490075Sobrien #define DPT_RUNTIME_IMPORT DPT_IMPORT 10590075Sobrien#endif 10690075Sobrien 10790075Sobrien/*--------------------- */ 10890075Sobrien/* OS dependent defines */ 10990075Sobrien/*--------------------- */ 11090075Sobrien 11190075Sobrien#if defined(_DPT_MSDOS) || defined(_DPT_WIN_3X) 11290075Sobrien #define _DPT_16_BIT 11390075Sobrien#else 11490075Sobrien #define _DPT_32_BIT 115169699Skan#endif 116169699Skan 11790075Sobrien#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) 11890075Sobrien #define _DPT_UNIX 119169699Skan#endif 120169699Skan 12190075Sobrien#if defined(_DPT_WIN_3x) || defined(_DPT_WIN_4X) || defined(_DPT_WIN_NT) \ 12290075Sobrien || defined(_DPT_OS2) 12390075Sobrien #define _DPT_DLL_SUPPORT 124169699Skan#endif 12590075Sobrien 12690075Sobrien#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X) && !defined(_DPT_NETWARE) 12790075Sobrien #define _DPT_PREEMPTIVE 12890075Sobrien#endif 12990075Sobrien 13090075Sobrien#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X) 13190075Sobrien #define _DPT_MULTI_THREADED 13290075Sobrien#endif 13390075Sobrien 13490075Sobrien#if !defined(_DPT_MSDOS) 13590075Sobrien #define _DPT_MULTI_TASKING 13690075Sobrien#endif 13790075Sobrien 13890075Sobrien /* These exist for platforms that */ 13990075Sobrien /* chunk when accessing mis-aligned */ 14090075Sobrien /* data */ 14190075Sobrien#if defined(SNI_MIPS) || defined(_DPT_SOLARIS) 14290075Sobrien #if defined(_DPT_BIG_ENDIAN) 14390075Sobrien #if !defined(_DPT_STRICT_ALIGN) 14490075Sobrien #define _DPT_STRICT_ALIGN 14590075Sobrien #endif 14690075Sobrien #endif 14790075Sobrien#endif 148132729Skan 149132729Skan /* Determine if in C or C++ mode */ 150132729Skan#ifdef __cplusplus 151132729Skan #define _DPT_CPP 15290075Sobrien#else 15390075Sobrien #define _DPT_C 15490075Sobrien#endif 15590075Sobrien 15690075Sobrien/*-------------------------------------------------------------------*/ 15790075Sobrien/* Under Solaris the compiler refuses to accept code like: */ 15890075Sobrien/* { {"DPT"}, 0, NULL .... }, */ 159169699Skan/* and complains about the {"DPT"} part by saying "cannot use { } */ 16090075Sobrien/* to initialize char*". */ 16190075Sobrien/* */ 162169699Skan/* By defining these ugly macros we can get around this and also */ 163169699Skan/* not have to copy and #ifdef large sections of code. I know that */ 16490075Sobrien/* these macros are *really* ugly, but they should help reduce */ 16590075Sobrien/* maintenance in the long run. */ 16690075Sobrien/* */ 16790075Sobrien/* In the meantime, just pray that we can all move to Win32 as soon */ 16890075Sobrien/* as possible... */ 16990075Sobrien/*-------------------------------------------------------------------*/ 17090075Sobrien#if !defined(DPTSQO) 171117406Skan #if defined(_DPT_SOLARIS) 17290075Sobrien #define DPTSQO 17390075Sobrien #define DPTSQC 174132729Skan #else 17590075Sobrien #define DPTSQO { 17690075Sobrien #define DPTSQC } 17790075Sobrien #endif /* solaris */ 17890075Sobrien#endif /* DPTSQO */ 17990075Sobrien 18090075Sobrien 18190075Sobrien/*---------------------- */ 18290075Sobrien/* OS dependent typedefs */ 18390075Sobrien/*---------------------- */ 18490075Sobrien 18590075Sobrien#if defined(_DPT_MSDOS) || defined(_DPT_SCO) 18690075Sobrien #define BYTE unsigned char 18790075Sobrien #define WORD unsigned short 188132729Skan#endif 189132729Skan 190132729Skan#ifndef _DPT_TYPEDEFS 19190075Sobrien #define _DPT_TYPEDEFS 19290075Sobrien typedef unsigned char uCHAR; 19390075Sobrien typedef unsigned short uSHORT; 19490075Sobrien typedef unsigned int uINT; 19590075Sobrien typedef unsigned long uLONG; 19690075Sobrien 19790075Sobrien typedef union { 19890075Sobrien uCHAR u8[4]; 19990075Sobrien uSHORT u16[2]; 20090075Sobrien uLONG u32; 20190075Sobrien } access_U; 20290075Sobrien#endif 20390075Sobrien 20490075Sobrien#if !defined(NULL) 20590075Sobrien #define NULL 0 20690075Sobrien#endif 20790075Sobrien 208169699Skan 209169699Skan/*Prototypes - function ----------------------------------------------------- */ 210169699Skan 211117406Skan#ifdef __cplusplus 21290075Sobrien extern "C" { /* Declare all these functions as "C" functions */ 213132729Skan#endif 214132729Skan 215132729Skan/*------------------------ */ 216132729Skan/* Byte reversal functions */ 217132729Skan/*------------------------ */ 218132729Skan 219132729Skan /* Reverses the byte ordering of a 2 byte variable */ 220132729Skan#if (!defined(osdSwap2)) 22190075Sobrien uSHORT osdSwap2(DPT_UNALIGNED uSHORT *); 22290075Sobrien#endif /* !osdSwap2 */ 22390075Sobrien 22490075Sobrien /* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */ 22590075Sobrien#if (!defined(osdSwap3)) 22690075Sobrien uLONG osdSwap3(DPT_UNALIGNED uLONG *); 227132729Skan#endif /* !osdSwap3 */ 228132729Skan 229132729Skan 230132729Skan#ifdef _DPT_NETWARE 23190075Sobrien #include "novpass.h" /* For DPT_Bswapl() prototype */ 23290075Sobrien /* Inline the byte swap */ 23390075Sobrien #ifdef __cplusplus 234132729Skan inline uLONG osdSwap4(uLONG *inLong) { 235132729Skan return *inLong = DPT_Bswapl(*inLong); 236132729Skan } 237132729Skan #else 238132729Skan #define osdSwap4(inLong) DPT_Bswapl(inLong) 239132729Skan #endif /* cplusplus */ 240132729Skan#else 24190075Sobrien /* Reverses the byte ordering of a 4 byte variable */ 24290075Sobrien# if (!defined(osdSwap4)) 243117406Skan uLONG osdSwap4(DPT_UNALIGNED uLONG *); 244169699Skan# endif /* !osdSwap4 */ 245169699Skan 246169699Skan /* The following functions ALWAYS swap regardless of the * 247117406Skan * presence of DPT_BIG_ENDIAN */ 24890075Sobrien 24990075Sobrien uSHORT trueSwap2(DPT_UNALIGNED uSHORT *); 25090075Sobrien uLONG trueSwap4(DPT_UNALIGNED uLONG *); 25190075Sobrien 252117406Skan#endif /* netware */ 25390075Sobrien 25490075Sobrien 25590075Sobrien/*-------------------------------------* 25690075Sobrien * Network order swap functions * 25790075Sobrien * * 25890075Sobrien * These functions/macros will be used * 25990075Sobrien * by the structure insert()/extract() * 26090075Sobrien * functions. * 26190075Sobrien * 26290075Sobrien * We will enclose all structure * 26390075Sobrien * portability modifications inside * 26490075Sobrien * #ifdefs. When we are ready, we * 26590075Sobrien * will #define DPT_PORTABLE to begin * 26690075Sobrien * using the modifications. * 26790075Sobrien *-------------------------------------*/ 26890075SobrienuLONG netSwap4(uLONG val); 269117406Skan 27090075Sobrien#if defined(_DPT_BIG_ENDIAN) 27190075Sobrien 27290075Sobrien/* for big-endian we need to swap */ 27390075Sobrien 27490075Sobrien#ifndef NET_SWAP_2 275169699Skan#define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8)) 276169699Skan#endif /* NET_SWAP_2 */ 277169699Skan 27890075Sobrien#ifndef NET_SWAP_4 279169699Skan#define NET_SWAP_4(x) netSwap4((x)) 28090075Sobrien#endif /* NET_SWAP_4 */ 28190075Sobrien 28290075Sobrien#else 28390075Sobrien 28490075Sobrien/* for little-endian we don't need to do anything */ 285132729Skan 28690075Sobrien#ifndef NET_SWAP_2 287169699Skan#define NET_SWAP_2(x) (x) 288169699Skan#endif /* NET_SWAP_2 */ 289169699Skan 290169699Skan#ifndef NET_SWAP_4 291169699Skan#define NET_SWAP_4(x) (x) 292169699Skan#endif /* NET_SWAP_4 */ 293132729Skan 294169699Skan#endif /* big endian */ 295169699Skan 296132729Skan 297169699Skan 298169699Skan/*----------------------------------- */ 299169699Skan/* Run-time loadable module functions */ 300169699Skan/*----------------------------------- */ 301169699Skan 30290075Sobrien /* Loads the specified run-time loadable DLL */ 303169699SkanDLL_HANDLE_T osdLoadModule(uCHAR *); 30490075Sobrien /* Unloads the specified run-time loadable DLL */ 305132729SkanuSHORT osdUnloadModule(DLL_HANDLE_T); 306169699Skan /* Returns a pointer to a function inside a run-time loadable DLL */ 307169699Skanvoid * osdGetFnAddr(DLL_HANDLE_T,uCHAR *); 308169699Skan 309132729Skan/*--------------------------------------- */ 310132729Skan/* Mutually exclusive semaphore functions */ 31190075Sobrien/*--------------------------------------- */ 312132729Skan 31390075Sobrien /* Create a named semaphore */ 314132729SkanSEMAPHORE_T osdCreateNamedSemaphore(char *); 31590075Sobrien /* Create a mutually exlusive semaphore */ 316132729SkanSEMAPHORE_T osdCreateSemaphore(void); 317132729Skan /* create an event semaphore */ 318132729SkanSEMAPHORE_T osdCreateEventSemaphore(void); 319132729Skan /* create a named event semaphore */ 32090075SobrienSEMAPHORE_T osdCreateNamedEventSemaphore(char *); 321132729Skan 322132729Skan /* Destroy the specified mutually exclusive semaphore object */ 323132729SkanuSHORT osdDestroySemaphore(SEMAPHORE_T); 32490075Sobrien /* Request access to the specified mutually exclusive semaphore */ 325169699SkanuLONG osdRequestSemaphore(SEMAPHORE_T,uLONG); 326169699Skan /* Release access to the specified mutually exclusive semaphore */ 327169699SkanuSHORT osdReleaseSemaphore(SEMAPHORE_T); 328132729Skan /* wait for an event to happen */ 329132729SkanuLONG osdWaitForEventSemaphore(SEMAPHORE_T, uLONG); 330132729Skan /* signal an event */ 331132729SkanuLONG osdSignalEventSemaphore(SEMAPHORE_T); 33290075Sobrien /* reset the event */ 333132729SkanuLONG osdResetEventSemaphore(SEMAPHORE_T); 334132729Skan 335132729Skan/*----------------- */ 336132729Skan/* Thread functions */ 33790075Sobrien/*----------------- */ 338132729Skan 33990075Sobrien /* Releases control to the task switcher in non-preemptive */ 340132729Skan /* multitasking operating systems. */ 34190075Sobrienvoid osdSwitchThreads(void); 342132729Skan 343132729Skan /* Starts a thread function */ 344132729SkanuLONG osdStartThread(void *,void *); 345132729Skan 346132729Skan/* what is my thread id */ 347132729SkanuLONG osdGetThreadID(void); 348132729Skan 349132729Skan/* wakes up the specifed thread */ 350132729Skanvoid osdWakeThread(uLONG); 351132729Skan 352132729Skan/* osd sleep for x miliseconds */ 353132729Skanvoid osdSleep(uLONG); 354132729Skan 355132729Skan#define DPT_THREAD_PRIORITY_LOWEST 0x00 356169699Skan#define DPT_THREAD_PRIORITY_NORMAL 0x01 357169699Skan#define DPT_THREAD_PRIORITY_HIGHEST 0x02 358169699Skan 359169699SkanuCHAR osdSetThreadPriority(uLONG tid, uCHAR priority); 360132729Skan 361132729Skan#ifdef __cplusplus 362132729Skan } /* end the xtern "C" declaration */ 363132729Skan#endif 364132729Skan 365117406Skan#endif /* osd_util_h */ 366117406Skan