1 /****************************************************************************
3 * SciTech Nucleus Graphics Architecture
5 * Copyright (C) 1991-1998 SciTech Software, Inc.
8 * ======================================================================
9 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
11 * |This copyrighted computer code contains proprietary technology |
12 * |owned by SciTech Software, Inc., located at 505 Wall Street, |
13 * |Chico, CA 95928 USA (http://www.scitechsoft.com). |
15 * |The contents of this file are subject to the SciTech Nucleus |
16 * |License; you may *not* use this file or related software except in |
17 * |compliance with the License. You may obtain a copy of the License |
18 * |at http://www.scitechsoft.com/nucleus-license.txt |
20 * |Software distributed under the License is distributed on an |
21 * |"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
22 * |implied. See the License for the specific language governing |
23 * |rights and limitations under the License. |
25 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
26 * ======================================================================
29 * Environment: OS/2 32-bit
31 * Description: OS specific Nucleus Graphics Architecture services for
32 * the OS/2 operating system environments.
34 ****************************************************************************/
37 #define INCL_DOSERRORS
44 /*--------------------------- Global variables ----------------------------*/
46 static ibool haveRDTSC = false;
47 static ulong parms[3]; /* Must not cross 64Kb boundary! */
48 static ulong result[4]; /* Must not cross 64Kb boundary! */
50 /*-------------------------- Implementation -------------------------------*/
52 /****************************************************************************
54 func - Helper device driver function to call
57 First return value from the device driver in parmsOut[0]
60 Function to open our helper device driver, call it and close the file
61 handle. Note that we have to open the device driver for every call because
64 1. We cannot open a single file handle in a DLL that is shared amongst
65 programs, since every process must have it's own open file handle.
67 2. For some reason there appears to be a limit of about 12 open file
68 handles on a device driver in the system. Hence when we open more
69 than about 12 file handles things start to go very strange.
71 Hence we simply open the file handle every time that we need to call the
72 device driver to work around these problems.
73 ****************************************************************************/
74 static ulong CallSDDHelp(
77 static ulong inLen; /* Must not cross 64Kb boundary! */
78 static ulong outLen; /* Must not cross 64Kb boundary! */
81 /* If this code in here fails, we are screwed! Many of our drivers
82 * use this code and don't have a C library, so we simply assume we
85 DosOpen(PMHELP_NAME,&hSDDHelp,&result[0],0,0,
86 FILE_OPEN, OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
88 DosDevIOCtl(hSDDHelp,PMHELP_IOCTL,func,
89 &parms, inLen = sizeof(parms), &inLen,
90 &result, outLen = sizeof(result), &outLen);
95 /****************************************************************************
97 path - Local path to the Nucleus driver files.
100 This function is used by the application program to override the location
101 of the Nucleus driver files that are loaded. Normally the loader code
102 will look in the system Nucleus directories first, then in the 'drivers'
103 directory relative to the current working directory, and finally relative
104 to the MGL_ROOT environment variable.
105 ****************************************************************************/
106 void NAPI GA_setLocalPath(
109 PM_setLocalBPDPath(path);
112 /****************************************************************************
114 Pointer to the system wide PM library imports, or the internal version if none
117 For OS/2 we don't need to do anything special because Nucleus is always
118 loaded via the shared SDDPMI driver when SDD is loaded so we don't need
119 a system wide PM library imports function.
120 ****************************************************************************/
121 PM_imports * NAPI GA_getSystemPMImports(void)
126 /****************************************************************************
128 gaExp - Place to store the exported functions
129 shared - True if connecting to the shared, global Nucleus driver
132 For OS/2 if SDD is loaded we *always* connect to the shared Nucleus functions
133 contained within the SDDPMI driver. This allows the Nucleus functions contained
134 within this driver to be utilised by all Nucleus apps in the system and
135 maintains a consistent state between versions.
136 ****************************************************************************/
137 ibool NAPI GA_getSharedExports(
141 /* In test harness mode, we need to load a local copy of Nucleus */
142 #if !defined (TEST_HARNESS) || defined (DEBUG_SDDPMI)
147 /* Initialise the PM library and connect to our runtime DLL's */
149 if (CallSDDHelp(PMHELP_GETSHAREDEXP) != 0) {
150 /* We have found the shared Nucleus exports. Because not all processes
151 * map to SDDPMI.DLL, we need to ensure that we connect to this
152 * DLL so that it gets mapped into our address space (that is
153 * where the shared Nucleus loader code is located). Simply doing a
154 * DosLoadModule on it is enough for this.
156 DosLoadModule((PSZ)buf,sizeof(buf),(PSZ)"SDDPMI.DLL",&hModSDDPMI);
157 exp = (GA_exports*)result[0];
158 memcpy(gaExp,exp,MIN(gaExp->dwSize,exp->dwSize));
167 /****************************************************************************
169 Nothing special for this OS
170 ****************************************************************************/
171 ibool NAPI GA_queryFunctions(
176 return __GA_exports.GA_queryFunctions(dc,id,funcs);
179 /****************************************************************************
181 Nothing special for this OS
182 ****************************************************************************/
183 ibool NAPI REF2D_queryFunctions(
188 return __GA_exports.REF2D_queryFunctions(ref2d,id,funcs);
192 /****************************************************************************
194 This function initialises the high precision timing functions for the
195 Nucleus loader library.
196 ****************************************************************************/
197 ibool NAPI GA_TimerInit(void)
199 if (_GA_haveCPUID() && (_GA_getCPUIDFeatures() & CPU_HaveRDTSC) != 0)
204 /****************************************************************************
206 This function reads the high resolution timer.
207 ****************************************************************************/
208 void NAPI GA_TimerRead(
209 GA_largeInteger *value)
212 _GA_readTimeStamp(value);
214 DosTmrQueryTime((QWORD*)value);
217 /****************************************************************************
219 On OS/2, we need special memory allocation functions if we build SDDPMI in
220 test harness mode. But if we build GATest etc. in test mode, we want to use
221 the normal C runtime functions, so route them back here.
222 ****************************************************************************/
224 #if defined (TEST_HARNESS) && !defined (DEBUG_SDDPMI)
226 /* Undefine these macros first or we'll recurse to hell! */
232 void *SDDPMI_malloc(size_t size) {
236 void *SDDPMI_calloc(size_t num, size_t size) {
237 return calloc(num, size);
240 void SDDPMI_free(void *ptr) {
244 void *SDDPMI_realloc(void *ptr, size_t size) {
245 return realloc(ptr, size);