1139749Simp/*- 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$ 2265312Smsmith */ 2365312Smsmith 2496554Sobrien#ifndef __OSD_UTIL_H 2596554Sobrien#define __OSD_UTIL_H 2665312Smsmith 2765312Smsmith/*File - OSD_UTIL.H 2865312Smsmith **************************************************************************** 2965312Smsmith * 3065312Smsmith *Description: 3165312Smsmith * 3296554Sobrien * 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. 3796554Sobrien * 140 Candace Dr. 3896554Sobrien * Maitland, Fl. 32751 USA 3996554Sobrien * Phone: (407) 830-5522 Fax: (407) 260-5366 4096554Sobrien * All Rights Reserved 4165312Smsmith * 4296554Sobrien *Author: Doug Anderson 4396554Sobrien *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 5996554Sobrien/*#define _DPT_MSDOS */ 6096554Sobrien/*#define _DPT_WIN_3X */ 6196554Sobrien/*#define _DPT_WIN_4X */ 6296554Sobrien/*#define _DPT_WIN_NT */ 6396554Sobrien/*#define _DPT_NETWARE */ 6496554Sobrien/*#define _DPT_OS2 */ 6596554Sobrien/*#define _DPT_SCO */ 6696554Sobrien/*#define _DPT_UNIXWARE */ 6796554Sobrien/*#define _DPT_SOLARIS */ 6896554Sobrien/*#define _DPT_NEXTSTEP */ 6996554Sobrien/*#define _DPT_BANYAN */ 7065312Smsmith 7165312Smsmith/*-------------------------------- */ 7265312Smsmith/* Include the OS specific defines */ 7365312Smsmith/*-------------------------------- */ 7465312Smsmith 7596551Sobrien/*#define OS_SELECTION From Above List */ 7696551Sobrien/*#define SEMAPHORE_T ??? */ 7796551Sobrien/*#define DLL_HANDLE_T ??? */ 7865312Smsmith 7965312Smsmith#if (defined(KERNEL) && defined(__bsdi__)) 8096554Sobrien# include "i386/isa/dpt_osd_defs.h" 8165312Smsmith#elif ((defined(KERNEL) || defined(_KERNEL)) && defined(__FreeBSD__)) 8265312Smsmith# if (KERN_VERSION < 3) 8396554Sobrien# include "i386/isa/dpt_osd_defs.h" 8465312Smsmith# else 8596554Sobrien# include "dev/asr/osd_defs.h" 8665312Smsmith# endif 8765312Smsmith#else 8896554Sobrien# include "osd_defs.h" 8965312Smsmith#endif 9065312Smsmith 9165312Smsmith#ifndef DPT_UNALIGNED 9296551Sobrien #define DPT_UNALIGNED 9365312Smsmith#endif 9465312Smsmith 9565312Smsmith#ifndef DPT_EXPORT 9696551Sobrien #define DPT_EXPORT 9765312Smsmith#endif 9865312Smsmith 9965312Smsmith#ifndef DPT_IMPORT 10096551Sobrien #define DPT_IMPORT 10165312Smsmith#endif 10265312Smsmith 10365312Smsmith#ifndef DPT_RUNTIME_IMPORT 10496554Sobrien #define DPT_RUNTIME_IMPORT DPT_IMPORT 10565312Smsmith#endif 10665312Smsmith 10765312Smsmith/*--------------------- */ 10865312Smsmith/* OS dependent defines */ 10965312Smsmith/*--------------------- */ 11065312Smsmith 11196614Sobrien#if defined(_DPT_MSDOS) || defined(_DPT_WIN_3X) 11296551Sobrien #define _DPT_16_BIT 11365312Smsmith#else 11496551Sobrien #define _DPT_32_BIT 11565312Smsmith#endif 11665312Smsmith 11796614Sobrien#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) 11896551Sobrien #define _DPT_UNIX 11965312Smsmith#endif 12065312Smsmith 12196614Sobrien#if defined(_DPT_WIN_3x) || defined(_DPT_WIN_4X) || defined(_DPT_WIN_NT) \ 12296614Sobrien || defined(_DPT_OS2) 12396551Sobrien #define _DPT_DLL_SUPPORT 12465312Smsmith#endif 12565312Smsmith 12696614Sobrien#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X) && !defined(_DPT_NETWARE) 12796551Sobrien #define _DPT_PREEMPTIVE 12865312Smsmith#endif 12965312Smsmith 13096614Sobrien#if !defined(_DPT_MSDOS) && !defined(_DPT_WIN_3X) 13196551Sobrien #define _DPT_MULTI_THREADED 13265312Smsmith#endif 13365312Smsmith 13496614Sobrien#if !defined(_DPT_MSDOS) 13596551Sobrien #define _DPT_MULTI_TASKING 13665312Smsmith#endif 13765312Smsmith 13865312Smsmith /* These exist for platforms that */ 13965312Smsmith /* chunk when accessing mis-aligned */ 14096554Sobrien /* data */ 14196614Sobrien#if defined(SNI_MIPS) || defined(_DPT_SOLARIS) 14296614Sobrien #if defined(_DPT_BIG_ENDIAN) 14396614Sobrien #if !defined(_DPT_STRICT_ALIGN) 14496554Sobrien #define _DPT_STRICT_ALIGN 14565312Smsmith #endif 14665312Smsmith #endif 14765312Smsmith#endif 14865312Smsmith 14965312Smsmith /* Determine if in C or C++ mode */ 15096554Sobrien#ifdef __cplusplus 15196551Sobrien #define _DPT_CPP 15265312Smsmith#else 15396551Sobrien #define _DPT_C 15465312Smsmith#endif 15565312Smsmith 15665312Smsmith/*-------------------------------------------------------------------*/ 15796554Sobrien/* Under Solaris the compiler refuses to accept code like: */ 15896554Sobrien/* { {"DPT"}, 0, NULL .... }, */ 15965312Smsmith/* and complains about the {"DPT"} part by saying "cannot use { } */ 16096554Sobrien/* to initialize char*". */ 16196554Sobrien/* */ 16265312Smsmith/* By defining these ugly macros we can get around this and also */ 16396554Sobrien/* not have to copy and #ifdef large sections of code. I know that */ 16496554Sobrien/* these macros are *really* ugly, but they should help reduce */ 16596554Sobrien/* maintenance in the long run. */ 16696554Sobrien/* */ 16765312Smsmith/* In the meantime, just pray that we can all move to Win32 as soon */ 16896554Sobrien/* as possible... */ 16965312Smsmith/*-------------------------------------------------------------------*/ 17096614Sobrien#if !defined(DPTSQO) 17196614Sobrien #if defined(_DPT_SOLARIS) 17296551Sobrien #define DPTSQO 17396551Sobrien #define DPTSQC 17465312Smsmith #else 17596551Sobrien #define DPTSQO { 17696551Sobrien #define DPTSQC } 17765312Smsmith #endif /* solaris */ 17896554Sobrien#endif /* DPTSQO */ 17965312Smsmith 18065312Smsmith 18165312Smsmith/*---------------------- */ 18265312Smsmith/* OS dependent typedefs */ 18365312Smsmith/*---------------------- */ 18465312Smsmith 18596614Sobrien#if defined(_DPT_MSDOS) || defined(_DPT_SCO) 18696551Sobrien #define BYTE unsigned char 18796551Sobrien #define WORD unsigned short 18865312Smsmith#endif 18965312Smsmith 19065312Smsmith#ifndef _DPT_TYPEDEFS 19196551Sobrien #define _DPT_TYPEDEFS 19265312Smsmith typedef unsigned char uCHAR; 19365312Smsmith typedef unsigned short uSHORT; 19496554Sobrien typedef unsigned int uINT; 19565312Smsmith typedef unsigned long uLONG; 19665312Smsmith 19765312Smsmith typedef union { 19896554Sobrien uCHAR u8[4]; 19996554Sobrien uSHORT u16[2]; 20096554Sobrien uLONG u32; 20165312Smsmith } access_U; 20265312Smsmith#endif 20365312Smsmith 20496614Sobrien#if !defined(NULL) 20596551Sobrien #define NULL 0 20665312Smsmith#endif 20765312Smsmith 20865312Smsmith 20965312Smsmith/*Prototypes - function ----------------------------------------------------- */ 21065312Smsmith 21196554Sobrien#ifdef __cplusplus 21296554Sobrien 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)) 22196554Sobrien uSHORT osdSwap2(DPT_UNALIGNED uSHORT *); 22296554Sobrien#endif /* !osdSwap2 */ 22365312Smsmith 22465312Smsmith /* Reverses the byte ordering of a 4 byte variable and shifts left 8 bits */ 22565312Smsmith#if (!defined(osdSwap3)) 22696554Sobrien uLONG osdSwap3(DPT_UNALIGNED uLONG *); 22796554Sobrien#endif /* !osdSwap3 */ 22865312Smsmith 22965312Smsmith 23096554Sobrien#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 23896551Sobrien #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)) 24396554Sobrien uLONG osdSwap4(DPT_UNALIGNED uLONG *); 24496554Sobrien# endif /* !osdSwap4 */ 24565312Smsmith 24665312Smsmith /* The following functions ALWAYS swap regardless of the * 24796554Sobrien * presence of DPT_BIG_ENDIAN */ 24865312Smsmith 24996554Sobrien uSHORT trueSwap2(DPT_UNALIGNED uSHORT *); 25096554Sobrien uLONG trueSwap4(DPT_UNALIGNED uLONG *); 25165312Smsmith 25296554Sobrien#endif /* netware */ 25365312Smsmith 25465312Smsmith 25565312Smsmith/*-------------------------------------* 25696554Sobrien * Network order swap functions * 25796554Sobrien * * 25865312Smsmith * These functions/macros will be used * 25965312Smsmith * by the structure insert()/extract() * 26096554Sobrien * functions. * 26165312Smsmith * 26265312Smsmith * We will enclose all structure * 26365312Smsmith * portability modifications inside * 26465312Smsmith * #ifdefs. When we are ready, we * 26596615Sobrien * will #define DPT_PORTABLE to begin * 26696554Sobrien * using the modifications. * 26765312Smsmith *-------------------------------------*/ 26865312SmsmithuLONG netSwap4(uLONG val); 26965312Smsmith 27096614Sobrien#if defined(_DPT_BIG_ENDIAN) 27165312Smsmith 27287816Sjhb/* for big-endian we need to swap */ 27365312Smsmith 27465312Smsmith#ifndef NET_SWAP_2 27596615Sobrien#define NET_SWAP_2(x) (((x) >> 8) | ((x) << 8)) 27696554Sobrien#endif /* NET_SWAP_2 */ 27765312Smsmith 27865312Smsmith#ifndef NET_SWAP_4 27996615Sobrien#define NET_SWAP_4(x) netSwap4((x)) 28096554Sobrien#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 28796615Sobrien#define NET_SWAP_2(x) (x) 28896554Sobrien#endif /* NET_SWAP_2 */ 28965312Smsmith 29065312Smsmith#ifndef NET_SWAP_4 29196615Sobrien#define NET_SWAP_4(x) (x) 29296554Sobrien#endif /* NET_SWAP_4 */ 29365312Smsmith 29496554Sobrien#endif /* big endian */ 29565312Smsmith 29665312Smsmith 29765312Smsmith 29865312Smsmith/*----------------------------------- */ 29965312Smsmith/* Run-time loadable module functions */ 30065312Smsmith/*----------------------------------- */ 30165312Smsmith 30265312Smsmith /* Loads the specified run-time loadable DLL */ 30396554SobrienDLL_HANDLE_T osdLoadModule(uCHAR *); 30465312Smsmith /* Unloads the specified run-time loadable DLL */ 30596554SobrienuSHORT osdUnloadModule(DLL_HANDLE_T); 30665312Smsmith /* Returns a pointer to a function inside a run-time loadable DLL */ 30796554Sobrienvoid * osdGetFnAddr(DLL_HANDLE_T,uCHAR *); 30865312Smsmith 30965312Smsmith/*--------------------------------------- */ 31065312Smsmith/* Mutually exclusive semaphore functions */ 31165312Smsmith/*--------------------------------------- */ 31265312Smsmith 31365312Smsmith /* Create a named semaphore */ 31496554SobrienSEMAPHORE_T osdCreateNamedSemaphore(char *); 31565312Smsmith /* Create a mutually exlusive semaphore */ 31696554SobrienSEMAPHORE_T osdCreateSemaphore(void); 31765312Smsmith /* create an event semaphore */ 31896554SobrienSEMAPHORE_T osdCreateEventSemaphore(void); 31965312Smsmith /* create a named event semaphore */ 32096554SobrienSEMAPHORE_T osdCreateNamedEventSemaphore(char *); 32165312Smsmith 32265312Smsmith /* Destroy the specified mutually exclusive semaphore object */ 32396554SobrienuSHORT osdDestroySemaphore(SEMAPHORE_T); 32465312Smsmith /* Request access to the specified mutually exclusive semaphore */ 32596554SobrienuLONG osdRequestSemaphore(SEMAPHORE_T,uLONG); 32665312Smsmith /* Release access to the specified mutually exclusive semaphore */ 32796554SobrienuSHORT osdReleaseSemaphore(SEMAPHORE_T); 328108533Sschweikh /* wait for an event to happen */ 32996554SobrienuLONG osdWaitForEventSemaphore(SEMAPHORE_T, uLONG); 33065312Smsmith /* signal an event */ 33196554SobrienuLONG osdSignalEventSemaphore(SEMAPHORE_T); 33265312Smsmith /* reset the event */ 33396554SobrienuLONG osdResetEventSemaphore(SEMAPHORE_T); 33465312Smsmith 33565312Smsmith/*----------------- */ 33665312Smsmith/* Thread functions */ 33765312Smsmith/*----------------- */ 33865312Smsmith 33965312Smsmith /* Releases control to the task switcher in non-preemptive */ 34065312Smsmith /* multitasking operating systems. */ 34196554Sobrienvoid osdSwitchThreads(void); 34265312Smsmith 34365312Smsmith /* Starts a thread function */ 34496554SobrienuLONG 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 35596615Sobrien#define DPT_THREAD_PRIORITY_LOWEST 0x00 35696615Sobrien#define DPT_THREAD_PRIORITY_NORMAL 0x01 35796615Sobrien#define DPT_THREAD_PRIORITY_HIGHEST 0x02 35865312Smsmith 35965312SmsmithuCHAR osdSetThreadPriority(uLONG tid, uCHAR priority); 36065312Smsmith 36165312Smsmith#ifdef __cplusplus 36296554Sobrien } /* end the xtern "C" declaration */ 36365312Smsmith#endif 36465312Smsmith 36596554Sobrien#endif /* osd_util_h */ 366