]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/MAI/bios_emulator/scitech/include/pmapi.h
* Patch by Thomas Frieden, 13 Nov 2002:
[karo-tx-uboot.git] / board / MAI / bios_emulator / scitech / include / pmapi.h
1 /****************************************************************************
2 *
3 *                   SciTech OS Portability Manager Library
4 *
5 *  ========================================================================
6 *
7 *    The contents of this file are subject to the SciTech MGL Public
8 *    License Version 1.0 (the "License"); you may not use this file
9 *    except in compliance with the License. You may obtain a copy of
10 *    the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 *    Software distributed under the License is distributed on an
13 *    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 *    implied. See the License for the specific language governing
15 *    rights and limitations under the License.
16 *
17 *    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 *    The Initial Developer of the Original Code is SciTech Software, Inc.
20 *    All Rights Reserved.
21 *
22 *  ========================================================================
23 *
24 * Language:     ANSI C
25 * Environment:  Any
26 *
27 * Description:  Header file for the OS Portability Manager Library, which
28 *               contains functions to implement OS specific services in a
29 *               generic, cross platform API. Porting the OS Portability
30 *               Manager library is the first step to porting any SciTech
31 *               products to a new platform.
32 *
33 ****************************************************************************/
34
35 #ifndef __PMAPI_H
36 #define __PMAPI_H
37
38 #include "scitech.h"
39 #include "pcilib.h"
40 #include "ztimerc.h"
41 #if !defined(__WIN32_VXD__) && !defined(__OS2_VDD__) && !defined(__NT_DRIVER__)
42 #include <stdio.h>
43 #include <stdlib.h>
44 #endif
45
46 /*--------------------------- Macros and Typedefs -------------------------*/
47
48 /* You will need to define one of the following before you compile this
49  * library for it to work correctly with the DOS extender that you are
50  * using when compiling for extended DOS:
51  *
52  *      TNT         - Phar Lap TNT DOS Extender
53  *      DOS4GW      - Rational DOS/4GW, DOS/4GW Pro, Causeway and PMODE/W
54  *      DJGPP       - DJGPP port of GNU C++
55  *
56  * If none is specified, we will automatically determine which operating
57  * system is being targetted and the following will be defined (provided by
58  * scitech.h header file):
59  *
60  *      __MSDOS16__     - Default for 16 bit MSDOS mode
61  *      __MSDOS32__     - Default for 32 bit MSDOS
62  *      __WINDOWS16__   - Default for 16 bit Windows
63  *      __WINDOWS32__   - Default for 32 bit Windows
64  *
65  * One of the following will be defined automatically for you to select
66  * which memory model is in effect:
67  *
68  *      REALMODE    - 16 bit real mode (large memory model)
69  *      PM286       - 16 protected mode (large memory model)
70  *      PM386       - 32 protected mode (flat memory model)
71  */
72
73 #if defined(__UNIX__) && !defined(_MAX_PATH)
74 #define _MAX_PATH 256
75 #endif
76
77 #if defined(TNT) || defined(DOSX) || defined(X32VM) || defined(DPMI32)      \
78     || defined(DOS4GW) || defined(DJGPP) || defined(__WINDOWS32__)          \
79     || defined(__MSDOS32__) || defined(__UNIX__) || defined(__WIN32_VXD__) \
80     || defined(__32BIT__) || defined(__SMX32__) || defined(__RTTARGET__)
81 #define PM386
82 #elif defined(DPMI16) || defined(__WINDOWS16__)
83 #define PM286
84 #else
85 #define REALMODE
86 #endif
87
88 #pragma pack(1)
89
90 /* Provide the typedefs for the PM_int386 functions, which issue native
91  * interrupts in real or protected mode and can pass extended registers
92  * around.
93  */
94
95 struct _PMDWORDREGS {
96     ulong   eax,ebx,ecx,edx,esi,edi,cflag;
97     };
98
99 struct _PMWORDREGS {
100     ushort  ax,ax_hi;
101     ushort  bx,bx_hi;
102     ushort  cx,cx_hi;
103     ushort  dx,dx_hi;
104     ushort  si,si_hi;
105     ushort  di,di_hi;
106     ushort  cflag,cflag_hi;
107     };
108
109 struct _PMBYTEREGS {
110     uchar   al, ah; ushort ax_hi;
111     uchar   bl, bh; ushort bx_hi;
112     uchar   cl, ch; ushort cx_hi;
113     uchar   dl, dh; ushort dx_hi;
114     };
115
116 typedef union {
117     struct  _PMDWORDREGS e;
118     struct  _PMWORDREGS  x;
119     struct  _PMBYTEREGS  h;
120     } PMREGS;
121
122 typedef struct {
123     ushort  es;
124     ushort  cs;
125     ushort  ss;
126     ushort  ds;
127     ushort  fs;
128     ushort  gs;
129     } PMSREGS;
130
131 /* Provide definitions for the real mode register structures passed to
132  * the PM_int86() and PM_int86x() routines. Note that we provide our own
133  * functions to do this for 16-bit code that calls the PM_int386 functions.
134  */
135
136 typedef PMREGS  RMREGS;
137 typedef PMSREGS RMSREGS;
138
139 typedef struct {
140     long    edi;
141     long    esi;
142     long    ebp;
143     long    reserved;
144     long    ebx;
145     long    edx;
146     long    ecx;
147     long    eax;
148     short   flags;
149     short   es,ds,fs,gs,ip,cs,sp,ss;
150     } DPMI_regs;
151
152 #ifdef  __MSDOS__
153 /* Register structure passed to PM_VxDCall function */
154 typedef struct {
155     ulong   eax;
156     ulong   ebx;
157     ulong   ecx;
158     ulong   edx;
159     ulong   esi;
160     ulong   edi;
161     ushort  ds,es;
162     } VXD_regs;
163 #endif
164
165 #define PM_MAX_DRIVE                3
166 #define PM_MAX_PATH                 256
167 #define PM_FILE_INVALID             (void*)0xFFFFFFFF
168
169 /* Structure for generic directory traversal and management. Also the same
170  * values are passed to PM_setFileAttr to change the file attributes.
171  */
172
173 typedef struct {
174     ulong   dwSize;
175     ulong   attrib;
176     ulong   sizeLo;
177     ulong   sizeHi;
178     char    name[PM_MAX_PATH];
179     } PM_findData;
180
181 /* Macro to compute the byte offset of a field in a structure of type type */
182
183 #define PM_FIELD_OFFSET(type,field) ((long)&(((type*)0)->field))
184
185 /* Marcto to compute the address of the base of the structure given its type,
186  * and an address of a field within the structure.
187  */
188
189 #define PM_CONTAINING_RECORD(address, type, field)      \
190     ((type*)(                                           \
191     (char*)(address) -                                  \
192     (char*)(&((type*)0)->field)))
193
194 /* Flags stored in the PM_findData structure, and also values passed to
195  * PM_setFileAttr to change the file attributes.
196  */
197
198 #define PM_FILE_NORMAL              0x00000000
199 #define PM_FILE_READONLY            0x00000001
200 #define PM_FILE_DIRECTORY           0x00000002
201 #define PM_FILE_ARCHIVE             0x00000004
202 #define PM_FILE_HIDDEN              0x00000008
203 #define PM_FILE_SYSTEM              0x00000010
204
205 /* Flags returned by the PM_splitpath function */
206
207 #define PM_HAS_WILDCARDS 0x01
208 #define PM_HAS_EXTENSION 0x02
209 #define PM_HAS_FILENAME  0x04
210 #define PM_HAS_DIRECTORY 0x08
211 #define PM_HAS_DRIVE     0x10
212
213 /* Structure passed to the PM_setFileTime functions */
214 typedef struct {
215     short   sec;        /* Seconds */
216     short   min;        /* Minutes */
217     short   hour;       /* Hour (0--23) */
218     short   day;        /* Day of month (1--31) */
219     short   mon;        /* Month (0--11) */
220     short   year;       /* Year (calendar year minus 1900) */
221     } PM_time;
222
223 /* Define a macro for creating physical base addresses from segment:offset */
224
225 #define MK_PHYS(s,o)  (((ulong)(s) << 4) + (ulong)(o))
226
227 /* Define the different types of modes supported. This is a global variable
228  * that can be used to determine the type at runtime which will contain
229  * one of these values.
230  */
231
232 typedef enum {
233     PM_realMode,
234     PM_286,
235     PM_386
236     } PM_mode_enum;
237
238 /* Define types passed to PM_enableWriteCombine */
239
240 #define PM_MTRR_UNCACHABLE  0
241 #define PM_MTRR_WRCOMB      1
242 #define PM_MTRR_WRTHROUGH   4
243 #define PM_MTRR_WRPROT      5
244 #define PM_MTRR_WRBACK      6
245 #define PM_MTRR_MAX         6
246
247 /* Error codes returned by PM_enableWriteCombine */
248
249 #define PM_MTRR_ERR_OK                  0
250 #define PM_MTRR_NOT_SUPPORTED           -1
251 #define PM_MTRR_ERR_PARAMS              -2
252 #define PM_MTRR_ERR_NOT_4KB_ALIGNED     -3
253 #define PM_MTRR_ERR_BELOW_1MB           -4
254 #define PM_MTRR_ERR_NOT_ALIGNED         -5
255 #define PM_MTRR_ERR_OVERLAP             -6
256 #define PM_MTRR_ERR_TYPE_MISMATCH       -7
257 #define PM_MTRR_ERR_NONE_FREE           -8
258 #define PM_MTRR_ERR_NOWRCOMB            -9
259 #define PM_MTRR_ERR_NO_OS_SUPPORT       -10
260
261 /* Values passed to the PM_DMACProgram function */
262
263 #define PM_DMA_READ_ONESHOT     0x44    /* One-shot DMA read        */
264 #define PM_DMA_WRITE_ONESHOT    0x48    /* One-shot DMA write       */
265 #define PM_DMA_READ_AUTOINIT    0x54    /* Auto-init DMA read       */
266 #define PM_DMA_WRITE_AUTOINIT   0x58    /* Auto-init DMA write      */
267
268 /* Flags passed to suspend application callback */
269
270 #define PM_DEACTIVATE       1
271 #define PM_REACTIVATE       2
272
273 /* Return codes that the application can return from the suspend application
274  * callback registered with the PM library. See the MGL documentation for
275  * more details.
276  */
277 #define PM_SUSPEND_APP      0
278 #define PM_NO_SUSPEND_APP   1
279
280 /****************************************************************************
281 REMARKS:
282 This enumeration defines the type values passed to the PM_agpReservePhysical
283 function, to define how the physical memory mapping should be handled.
284
285 The PM_agpUncached type indicates that the memory should be allocated as
286 uncached memory.
287
288 The PM_agpWriteCombine type indicates that write combining should be enabled
289 for physical memory mapping. This is used for framebuffer write combing and
290 speeds up direct framebuffer writes to the memory.
291
292 The PM_agpIntelDCACHE type indicates that memory should come from the Intel
293 i81x Display Cache (or DCACHE) memory pool. This flag is specific to the
294 Intel i810 and i815 controllers, and should not be passed for any other
295 controller type.
296
297 HEADER:
298 pmapi.h
299
300 MEMBERS:
301 PM_agpUncached      - Indicates that the memory should be uncached
302 PM_agpWriteCombine  - Indicates that the memory should be write combined
303 PM_agpIntelDCACHE   - Indicates that the memory should come from DCACHE pool
304 ****************************************************************************/
305 typedef enum {
306     PM_agpUncached,
307     PM_agpWriteCombine,
308     PM_agpIntelDCACHE
309     } PM_agpMemoryType;
310
311 /* Defines the size of an system memory page */
312
313 #define PM_PAGE_SIZE        4096
314
315 /* Type definition for a physical memory address */
316
317 typedef unsigned long PM_physAddr;
318
319 /* Define a bad physical address returned by map physical functions */
320
321 #define PM_BAD_PHYS_ADDRESS 0xFFFFFFFF
322
323 /* Type definition for the 12-byte lock handle for locking linear memory */
324
325 typedef struct {
326     ulong   h[3];
327     } PM_lockHandle;
328
329 /* 'C' calling conventions always       */
330
331 #define PMAPI   _ASMAPI
332 #define PMAPIP  _ASMAPIP
333
334 /* Internal typedef to override DPMI_int86 handler */
335
336 typedef ibool (PMAPIP DPMI_handler_t)(DPMI_regs *regs);
337 void PMAPI DPMI_setInt10Handler(DPMI_handler_t handler);
338
339 /* Type definitions for a window handle for console modes */
340
341 #if     defined(__DRIVER__) || defined(__WIN32_VXD__) || defined(__NT_DRIVER__)
342 typedef void        *PM_HWND;   /* Pointer for portable drivers         */
343 typedef void        *PM_MODULE; /* Module handle for portable drivers   */
344 #elif   defined(__WINDOWS__)
345 #ifdef  DECLARE_HANDLE
346 typedef HWND        PM_HWND;    /* Real window handle                   */
347 typedef HINSTANCE   PM_MODULE;  /* Win32 DLL handle                     */
348 #else
349 typedef void        *PM_HWND;   /* Place holder if windows.h not included */
350 typedef void        *PM_MODULE; /* Place holder if windows.h not included */
351 #endif
352 #elif   defined(__USE_X11__)
353 typedef struct {
354     Window      *window;
355     Display     *display;
356     } PM_HWND;                  /* X11 window handle */
357 #elif   defined(__OS2__)
358 typedef void    *PM_HWND;
359 typedef void    *PM_MODULE;
360 #elif   defined(__LINUX__)
361 typedef int     PM_HWND;        /* Console id for fullscreen Linux */
362 typedef void    *PM_MODULE;
363 #elif   defined(__QNX__)
364 typedef int     PM_HWND;        /* Console id for fullscreen QNX */
365 typedef void    *PM_MODULE;
366 #elif   defined(__RTTARGET__)
367 typedef int     PM_HWND;        /* Placeholder for RTTarget-32 */
368 typedef void    *PM_MODULE;
369 #elif   defined(__REALDOS__)
370 typedef int     PM_HWND;        /* Placeholder for fullscreen DOS */
371 typedef void    *PM_MODULE;     /* Placeholder for fullscreen DOS */
372 #elif   defined(__SMX32__)
373 typedef int     PM_HWND;        /* Placeholder for fullscreen SMX */
374 typedef void    *PM_MODULE;
375 #elif   defined(__SNAP__)
376 typedef void    *PM_HWND;
377 typedef void    *PM_MODULE;
378 #else
379 #error  PM library not ported to this platform yet!
380 #endif
381
382 /* Type definition for code pointers */
383
384 typedef void (*__codePtr)();
385
386 /* Type definition for a C based interrupt handler */
387
388 typedef void (PMAPIP PM_intHandler)(void);
389 typedef ibool (PMAPIP PM_irqHandler)(void);
390
391 /* Hardware IRQ handle used to save and restore the hardware IRQ */
392
393 typedef void *PM_IRQHandle;
394
395 /* Type definition for the fatal cleanup handler */
396
397 typedef void (PMAPIP PM_fatalCleanupHandler)(void);
398
399 /* Type defifinition for save state callback function */
400
401 typedef int (PMAPIP PM_saveState_cb)(int flags);
402
403 /* Type definintion for enum write combined callback function */
404
405 typedef void (PMAPIP PM_enumWriteCombine_t)(ulong base,ulong length,uint type);
406
407 /* Structure defining all the PM API functions as exported to
408  * the binary portable DLL's.
409  */
410
411 typedef struct {
412     ulong   dwSize;
413     int     (PMAPIP PM_getModeType)(void);
414     void *  (PMAPIP PM_getBIOSPointer)(void);
415     void *  (PMAPIP PM_getA0000Pointer)(void);
416     void *  (PMAPIP PM_mapPhysicalAddr)(ulong base,ulong limit,ibool isCached);
417     void *  (PMAPIP PM_mallocShared)(long size);
418     void *  reserved1;
419     void    (PMAPIP PM_freeShared)(void *ptr);
420     void *  (PMAPIP PM_mapToProcess)(void *linear,ulong limit);
421     void *  (PMAPIP PM_mapRealPointer)(uint r_seg,uint r_off);
422     void *  (PMAPIP PM_allocRealSeg)(uint size,uint *r_seg,uint *r_off);
423     void    (PMAPIP PM_freeRealSeg)(void *mem);
424     void *  (PMAPIP PM_allocLockedMem)(uint size,ulong *physAddr,ibool contiguous,ibool below16Meg);
425     void    (PMAPIP PM_freeLockedMem)(void *p,uint size,ibool contiguous);
426     void    (PMAPIP PM_callRealMode)(uint seg,uint off, RMREGS *regs,RMSREGS *sregs);
427     int     (PMAPIP PM_int86)(int intno, RMREGS *in, RMREGS *out);
428     int     (PMAPIP PM_int86x)(int intno, RMREGS *in, RMREGS *out,RMSREGS *sregs);
429     void    (PMAPIP DPMI_int86)(int intno, DPMI_regs *regs);
430     void    (PMAPIP PM_availableMemory)(ulong *physical,ulong *total);
431     void *  (PMAPIP PM_getVESABuf)(uint *len,uint *rseg,uint *roff);
432     long    (PMAPIP PM_getOSType)(void);
433     void    (PMAPIP PM_fatalError)(const char *msg);
434     void    (PMAPIP PM_setBankA)(int bank);
435     void    (PMAPIP PM_setBankAB)(int bank);
436     void    (PMAPIP PM_setCRTStart)(int x,int y,int waitVRT);
437     char *  (PMAPIP PM_getCurrentPath)(char *path,int maxLen);
438     const char * (PMAPIP PM_getVBEAFPath)(void);
439     const char * (PMAPIP PM_getNucleusPath)(void);
440     const char * (PMAPIP PM_getNucleusConfigPath)(void);
441     const char * (PMAPIP PM_getUniqueID)(void);
442     const char * (PMAPIP PM_getMachineName)(void);
443     ibool   (PMAPIP VF_available)(void);
444     void *  (PMAPIP VF_init)(ulong baseAddr,int bankSize,int codeLen,void *bankFunc);
445     void    (PMAPIP VF_exit)(void);
446     PM_HWND (PMAPIP PM_openConsole)(PM_HWND hwndUser,int device,int xRes,int yRes,int bpp,ibool fullScreen);
447     int     (PMAPIP PM_getConsoleStateSize)(void);
448     void    (PMAPIP PM_saveConsoleState)(void *stateBuf,PM_HWND hwndConsole);
449     void    (PMAPIP PM_restoreConsoleState)(const void *stateBuf,PM_HWND hwndConsole);
450     void    (PMAPIP PM_closeConsole)(PM_HWND hwndConsole);
451     void    (PMAPIP PM_setOSCursorLocation)(int x,int y);
452     void    (PMAPIP PM_setOSScreenWidth)(int width,int height);
453     int     (PMAPIP PM_enableWriteCombine)(ulong base,ulong length,uint type);
454     void    (PMAPIP PM_backslash)(char *filename);
455     int     (PMAPIP PM_lockDataPages)(void *p,uint len,PM_lockHandle *lockHandle);
456     int     (PMAPIP PM_unlockDataPages)(void *p,uint len,PM_lockHandle *lockHandle);
457     int     (PMAPIP PM_lockCodePages)(__codePtr p,uint len,PM_lockHandle *lockHandle);
458     int     (PMAPIP PM_unlockCodePages)(__codePtr p,uint len,PM_lockHandle *lockHandle);
459     ibool   (PMAPIP PM_setRealTimeClockHandler)(PM_intHandler ih,int frequency);
460     void    (PMAPIP PM_setRealTimeClockFrequency)(int frequency);
461     void    (PMAPIP PM_restoreRealTimeClockHandler)(void);
462     ibool   (PMAPIP PM_doBIOSPOST)(ushort axVal,ulong BIOSPhysAddr,void *BIOSPtr,ulong BIOSLen);
463     char    (PMAPIP PM_getBootDrive)(void);
464     void    (PMAPIP PM_freePhysicalAddr)(void *ptr,ulong limit);
465     uchar   (PMAPIP PM_inpb)(int port);
466     ushort  (PMAPIP PM_inpw)(int port);
467     ulong   (PMAPIP PM_inpd)(int port);
468     void    (PMAPIP PM_outpb)(int port,uchar val);
469     void    (PMAPIP PM_outpw)(int port,ushort val);
470     void    (PMAPIP PM_outpd)(int port,ulong val);
471     void *  reserved2;
472     void    (PMAPIP PM_setSuspendAppCallback)(PM_saveState_cb saveState);
473     ibool   (PMAPIP PM_haveBIOSAccess)(void);
474     int     (PMAPIP PM_kbhit)(void);
475     int     (PMAPIP PM_getch)(void);
476     ibool   (PMAPIP PM_findBPD)(const char *dllname,char *bpdpath);
477     ulong   (PMAPIP PM_getPhysicalAddr)(void *p);
478     void    (PMAPIP PM_sleep)(ulong milliseconds);
479     int     (PMAPIP PM_getCOMPort)(int port);
480     int     (PMAPIP PM_getLPTPort)(int port);
481     PM_MODULE (PMAPIP PM_loadLibrary)(const char *szDLLName);
482     void *  (PMAPIP PM_getProcAddress)(PM_MODULE hModule,const char *szProcName);
483     void    (PMAPIP PM_freeLibrary)(PM_MODULE hModule);
484     int     (PMAPIP PCI_enumerate)(PCIDeviceInfo info[]);
485     ulong   (PMAPIP PCI_accessReg)(int index,ulong value,int func,PCIDeviceInfo *info);
486     ibool   (PMAPIP PCI_setHardwareIRQ)(PCIDeviceInfo *info,uint intPin,uint IRQ);
487     void    (PMAPIP PCI_generateSpecialCyle)(uint bus,ulong specialCycleData);
488     void *  reserved3;
489     ulong   (PMAPIP PCIBIOS_getEntry)(void);
490     uint    (PMAPIP CPU_getProcessorType)(void);
491     ibool   (PMAPIP CPU_haveMMX)(void);
492     ibool   (PMAPIP CPU_have3DNow)(void);
493     ibool   (PMAPIP CPU_haveSSE)(void);
494     ibool   (PMAPIP CPU_haveRDTSC)(void);
495     ulong   (PMAPIP CPU_getProcessorSpeed)(ibool accurate);
496     void    (PMAPIP ZTimerInit)(void);
497     void    (PMAPIP LZTimerOn)(void);
498     ulong   (PMAPIP LZTimerLap)(void);
499     void    (PMAPIP LZTimerOff)(void);
500     ulong   (PMAPIP LZTimerCount)(void);
501     void    (PMAPIP LZTimerOnExt)(LZTimerObject *tm);
502     ulong   (PMAPIP LZTimerLapExt)(LZTimerObject *tm);
503     void    (PMAPIP LZTimerOffExt)(LZTimerObject *tm);
504     ulong   (PMAPIP LZTimerCountExt)(LZTimerObject *tm);
505     void    (PMAPIP ULZTimerOn)(void);
506     ulong   (PMAPIP ULZTimerLap)(void);
507     void    (PMAPIP ULZTimerOff)(void);
508     ulong   (PMAPIP ULZTimerCount)(void);
509     ulong   (PMAPIP ULZReadTime)(void);
510     ulong   (PMAPIP ULZElapsedTime)(ulong start,ulong finish);
511     void    (PMAPIP ULZTimerResolution)(ulong *resolution);
512     void *  (PMAPIP PM_findFirstFile)(const char *filename,PM_findData *findData);
513     ibool   (PMAPIP PM_findNextFile)(void *handle,PM_findData *findData);
514     void    (PMAPIP PM_findClose)(void *handle);
515     void    (PMAPIP PM_makepath)(char *p,const char *drive,const char *dir,const char *name,const char *ext);
516     int     (PMAPIP PM_splitpath)(const char *fn,char *drive,char *dir,char *name,char *ext);
517     ibool   (PMAPIP PM_driveValid)(char drive);
518     void    (PMAPIP PM_getdcwd)(int drive,char *dir,int len);
519     void    (PMAPIP PM_setFileAttr)(const char *filename,uint attrib);
520     ibool   (PMAPIP PM_mkdir)(const char *filename);
521     ibool   (PMAPIP PM_rmdir)(const char *filename);
522     uint    (PMAPIP PM_getFileAttr)(const char *filename);
523     ibool   (PMAPIP PM_getFileTime)(const char *filename,ibool gmtTime,PM_time *time);
524     ibool   (PMAPIP PM_setFileTime)(const char *filename,ibool gmtTime,PM_time *time);
525     char *  (PMAPIP CPU_getProcessorName)(void);
526     int     (PMAPIP PM_getVGAStateSize)(void);
527     void    (PMAPIP PM_saveVGAState)(void *stateBuf);
528     void    (PMAPIP PM_restoreVGAState)(const void *stateBuf);
529     void    (PMAPIP PM_vgaBlankDisplay)(void);
530     void    (PMAPIP PM_vgaUnblankDisplay)(void);
531     void    (PMAPIP PM_blockUntilTimeout)(ulong milliseconds);
532     void    (PMAPIP _PM_add64)(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
533     void    (PMAPIP _PM_sub64)(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
534     void    (PMAPIP _PM_mul64)(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
535     void    (PMAPIP _PM_div64)(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
536     void    (PMAPIP _PM_shr64)(u32 a_low,s32 a_high,s32 shift,__i64 *result);
537     void    (PMAPIP _PM_sar64)(u32 a_low,s32 a_high,s32 shift,__i64 *result);
538     void    (PMAPIP _PM_shl64)(u32 a_low,s32 a_high,s32 shift,__i64 *result);
539     void    (PMAPIP _PM_neg64)(u32 a_low,s32 a_high,__i64 *result);
540     ulong   (PMAPIP PCI_findBARSize)(int bar,PCIDeviceInfo *pci);
541     void    (PMAPIP PCI_readRegBlock)(PCIDeviceInfo *info,int index,void *dst,int count);
542     void    (PMAPIP PCI_writeRegBlock)(PCIDeviceInfo *info,int index,void *src,int count);
543     void    (PMAPIP PM_flushTLB)(void);
544     void    (PMAPIP PM_useLocalMalloc)(void * (*malloc)(size_t size),void * (*calloc)(size_t nelem,size_t size),void * (*realloc)(void *ptr,size_t size),void (*free)(void *p));
545     void *  (PMAPIP PM_malloc)(size_t size);
546     void *  (PMAPIP PM_calloc)(size_t nelem,size_t size);
547     void *  (PMAPIP PM_realloc)(void *ptr,size_t size);
548     void    (PMAPIP PM_free)(void *p);
549     ibool   (PMAPIP PM_getPhysicalAddrRange)(void *p,ulong length,ulong *physAddress);
550     void *  (PMAPIP PM_allocPage)(ibool locked);
551     void    (PMAPIP PM_freePage)(void *p);
552     ulong   (PMAPIP PM_agpInit)(void);
553     void    (PMAPIP PM_agpExit)(void);
554     ibool   (PMAPIP PM_agpReservePhysical)(ulong numPages,int type,void **physContext,PM_physAddr *physAddr);
555     ibool   (PMAPIP PM_agpReleasePhysical)(void *physContext);
556     ibool   (PMAPIP PM_agpCommitPhysical)(void *physContext,ulong numPages,ulong startOffset,PM_physAddr *physAddr);
557     ibool   (PMAPIP PM_agpFreePhysical)(void *physContext,ulong numPages,ulong startOffset);
558     int     (PMAPIP PCI_getNumDevices)(void);
559     void    (PMAPIP PM_setLocalBPDPath)(const char *path);
560     void *  (PMAPIP PM_loadDirectDraw)(int device);
561     void    (PMAPIP PM_unloadDirectDraw)(int device);
562     PM_HWND (PMAPIP PM_getDirectDrawWindow)(void);
563     void    (PMAPIP PM_doSuspendApp)(void);
564     } PM_imports;
565
566 #pragma pack()
567
568 /*---------------------------- Global variables ---------------------------*/
569
570 #ifdef  __cplusplus
571 extern "C" {            /* Use "C" linkage when in C++ mode */
572 #endif
573
574 #ifdef  __WIN32_VXD__
575 #define VESA_BUF_SIZE 1024
576 extern uchar *_PM_rmBufAddr;
577 #endif
578
579 /* {secret} Pointer to global exports structure.
580  * Should not be used by application programs.
581  */
582 extern PM_imports _VARAPI _PM_imports;
583
584 /* {secret} */
585 extern void * (*__PM_malloc)(size_t size);
586 /* {secret} */
587 extern void * (*__PM_calloc)(size_t nelem,size_t size);
588 /* {secret} */
589 extern void * (*__PM_realloc)(void *ptr,size_t size);
590 /* {secret} */
591 extern void (*__PM_free)(void *p);
592
593 /*--------------------------- Function Prototypes -------------------------*/
594
595 /* Routine to initialise the host side PM library. Note used from DLL's */
596
597 void    PMAPI PM_init(void);
598
599 /* Routine to return either PM_realMode, PM_286 or PM_386 */
600
601 int     PMAPI PM_getModeType(void);
602
603 /* Routine to return a selector to the BIOS data area at segment 0x40 */
604
605 void *  PMAPI PM_getBIOSPointer(void);
606
607 /* Routine to return a linear pointer to the VGA frame buffer memory */
608
609 void *  PMAPI PM_getA0000Pointer(void);
610
611 /* Routines to map/free physical memory into the current DS segment. In
612  * some environments (32-bit DOS is one), after the mapping has been
613  * allocated, it cannot be freed. Hence you should only allocate the
614  * mapping once and cache the value for use by other parts of your
615  * application. If the mapping cannot be createed, this function will
616  * return a NULL pointer.
617  *
618  * This routine will also work for memory addresses below 1Mb, but the
619  * mapped address cannot cross the 1Mb boundary.
620  */
621
622 void *  PMAPI PM_mapPhysicalAddr(ulong base,ulong limit,ibool isCached);
623 void    PMAPI PM_freePhysicalAddr(void *ptr,ulong limit);
624
625 /* Routine to determine the physical address of a linear address. It is
626  * up to the caller to ensure the entire address range for a linear
627  * block of memory is page aligned if that is required.
628  */
629
630 ulong   PMAPI PM_getPhysicalAddr(void *p);
631 ibool   PMAPI PM_getPhysicalAddrRange(void *p,ulong length,ulong *physAddress);
632
633 /* Routines for memory allocation. By default these functions use the regular
634  * C runtime library malloc/free functions, but you can use the
635  * PM_useLocalMalloc function to override the default memory allocator with
636  * your own memory allocator. This will ensure that all memory allocation
637  * used by SciTech products will use your overridden memory allocator
638  * functions.
639  *
640  * Note that BPD files automatically map the C runtime library
641  * malloc/calloc/realloc/free calls from inside the BPD to the PM library
642  * versions by default.
643  */
644
645 void    PMAPI PM_useLocalMalloc(void * (*malloc)(size_t size),void * (*calloc)(size_t nelem,size_t size),void * (*realloc)(void *ptr,size_t size),void (*free)(void *p));
646 void *  PMAPI PM_malloc(size_t size);
647 void *  PMAPI PM_calloc(size_t nelem,size_t size);
648 void *  PMAPI PM_realloc(void *ptr,size_t size);
649 void    PMAPI PM_free(void *p);
650
651 /* Routine to allocate a memory block in the global shared region that
652  * is common to all tasks and accessible from ring 0 code.
653  */
654
655 void *  PMAPI PM_mallocShared(long size);
656
657 /* Routine to free the allocated shared memory block */
658
659 void    PMAPI PM_freeShared(void *ptr);
660
661 /* Attach a previously allocated linear mapping to a new process */
662
663 void *  PMAPI PM_mapToProcess(void *linear,ulong limit);
664
665 /* Macros to extract byte, word and long values from a char pointer */
666
667 #define PM_getByte(p)       *((volatile uchar*)(p))
668 #define PM_getWord(p)       *((volatile ushort*)(p))
669 #define PM_getLong(p)       *((volatile ulong*)(p))
670 #define PM_setByte(p,v)     PM_getByte(p) = (v)
671 #define PM_setWord(p,v)     PM_getWord(p) = (v)
672 #define PM_setLong(p,v)     PM_getLong(p) = (v)
673
674 /* Routine for accessing a low 1Mb memory block. You dont need to free this
675  * pointer, but in 16 bit protected mode the selector allocated will be
676  * re-used the next time this routine is called.
677  */
678
679 void *  PMAPI PM_mapRealPointer(uint r_seg,uint r_off);
680
681 /* Routine to allocate a block of conventional memory below the 1Mb
682  * limit so that it can be accessed from real mode. Ensure that you free
683  * the segment when you are done with it.
684  *
685  * This routine returns a selector and offset to the segment that has been
686  * allocated, and also returns the real mode segment and offset which can
687  * be passed to real mode routines. Will return 0 if memory could not be
688  * allocated.
689  *
690  * Please note that with some DOS extenders, memory allocated with the
691  * following function cannot be freed, hence it will be allocated for the
692  * life of your program. Thus if you need to call a bunch of different
693  * real-mode routines in your program, allocate a single large buffer at
694  * program startup that can be re-used throughout the program execution.
695  */
696
697 void *  PMAPI PM_allocRealSeg(uint size,uint *r_seg,uint *r_off);
698 void    PMAPI PM_freeRealSeg(void *mem);
699
700 /* Routine to allocate a block of locked memory, and return both the
701  * linear and physical addresses of the memory. You should always
702  * allocate locked memory blocks in page sized chunks (ie: 4K on IA32).
703  * If the memory is not contiguous, you will need to use the
704  * PM_getPhysicalAddr function to get the physical address of linear
705  * pages within the memory block (the returned physical address will be
706  * for the first address in the memory block only).
707  */
708
709 void *  PMAPI PM_allocLockedMem(uint size,ulong *physAddr,ibool contiguous,ibool below16Meg);
710 void    PMAPI PM_freeLockedMem(void *p,uint size,ibool contiguous);
711
712 /* Routine to allocate and free paged sized blocks of shared memory.
713  * Addressable from all processes, but not from a ring 0 context
714  * under OS/2. Note that under OS/2 PM_mapSharedPages must be called
715  * to map the memory blocks into the shared memory address space
716  * of each connecting process.
717  */
718
719 void *  PMAPI PM_allocPage(ibool locked);
720 void    PMAPI PM_freePage(void *p);
721 #ifdef __OS2__
722 void    PMAPI PM_mapSharedPages(void);
723 #endif
724
725 /* Routine to return true if we have access to the BIOS on the host OS */
726
727 ibool   PMAPI PM_haveBIOSAccess(void);
728
729 /* Routine to call a real mode assembly language procedure. Register
730  * values are passed in and out in the 'regs' and 'sregs' structures. We
731  * do not provide any method of copying data from the protected mode stack
732  * to the real mode stack, so if you need to pass data to real mode, you will
733  * need to write a real mode assembly language hook to recieve the values
734  * in registers, and to pass the data through a real mode block allocated
735  * with the PM_allocRealSeg() routine.
736  */
737
738 void    PMAPI PM_callRealMode(uint seg,uint off, RMREGS *regs,RMSREGS *sregs);
739
740 /* Routines to generate real mode interrupts using the same interface that
741  * is used by int86() and int86x() in realmode. This routine is need to
742  * call certain BIOS and DOS functions that are not supported by some
743  * DOS extenders. No translation is done on any of the register values,
744  * so they must be correctly set up and translated by the calling program.
745  *
746  * Normally the DOS extenders will allow you to use the normal int86()
747  * function directly and will pass on unhandled calls to real mode to be
748  * handled by the real mode handler. However calls to int86x() with real
749  * mode segment values to be loaded will cause a GPF if used with the
750  * standard int86x(), so you should use these routines if you know you
751  * want to call a real mode handler.
752  */
753
754 int     PMAPI PM_int86(int intno, RMREGS *in, RMREGS *out);
755 int     PMAPI PM_int86x(int intno, RMREGS *in, RMREGS *out,RMSREGS *sregs);
756
757 /* Routine to generate a real mode interrupt. This is identical to the
758  * above function, but takes a DPMI_regs structure for the registers
759  * which has a lot more information. It is only available from 32-bit
760  * protected mode.
761  */
762
763 void    PMAPI DPMI_int86(int intno, DPMI_regs *regs);
764
765 /* Function to return the amount of available physical and total memory.
766  * The results of this function are *only* valid before you have made any
767  * calls to malloc() and free(). If you need to keep track of exactly how
768  * much memory is currently allocated, you need to call this function to
769  * get the total amount of memory available and then keep track of
770  * the available memory every time you call malloc() and free().
771  */
772
773 void    PMAPI PM_availableMemory(ulong *physical,ulong *total);
774
775 /* Return the address of a global VESA real mode transfer buffer for use
776  * by applications.
777  */
778
779 void *  PMAPI PM_getVESABuf(uint *len,uint *rseg,uint *roff);
780
781 /* Handle fatal error conditions */
782
783 void    PMAPI PM_fatalError(const char *msg);
784
785 /* Function to set a cleanup error handler called when PM_fatalError
786  * is called. This allows us to the console back into a normal state
787  * if we get a failure from deep inside a BPD file. This function is
788  * not exported to BPD files, and is only used by code compiled for the
789  * OS.
790  */
791
792 void    PMAPI PM_setFatalErrorCleanup(PM_fatalCleanupHandler cleanup);
793
794 /* Return the OS type flag as defined in <drvlib/os/os.h> */
795
796 long    PMAPI PM_getOSType(void);
797
798 /* Functions to set a VBE bank via an Int 10h */
799
800 void    PMAPI PM_setBankA(int bank);
801 void    PMAPI PM_setBankAB(int bank);
802 void    PMAPI PM_setCRTStart(int x,int y,int waitVRT);
803
804 /* Return the current working directory */
805
806 char *  PMAPI PM_getCurrentPath(char *path,int maxLen);
807
808 /* Return paths to the VBE/AF and Nucleus directories */
809
810 const char * PMAPI PM_getVBEAFPath(void);
811 const char * PMAPI PM_getNucleusPath(void);
812 const char * PMAPI PM_getNucleusConfigPath(void);
813
814 /* Find the path to a binary portable DLL */
815
816 void    PMAPI PM_setLocalBPDPath(const char *path);
817 ibool   PMAPI PM_findBPD(const char *dllname,char *bpdpath);
818
819 /* Returns the drive letter of the boot drive for DOS, OS/2 and Windows */
820
821 char    PMAPI PM_getBootDrive(void);
822
823 /* Return a network unique machine identifier as a string */
824
825 const char * PMAPI PM_getUniqueID(void);
826
827 /* Return the network machine name as a string */
828
829 const char * PMAPI PM_getMachineName(void);
830
831 /* Functions to install and remove the virtual linear framebuffer
832  * emulation code. For unsupported DOS extenders and when running under
833  * a DPMI host like Windows or OS/2, this function will return a NULL.
834  */
835
836 ibool   PMAPI VF_available(void);
837 void *  PMAPI VF_init(ulong baseAddr,int bankSize,int codeLen,void *bankFunc);
838 void    PMAPI VF_exit(void);
839
840 /* Functions to wait for a keypress and read a key for command line
841  * environments such as DOS, Win32 console and Unix.
842  */
843
844 int     PMAPI PM_kbhit(void);
845 int     PMAPI PM_getch(void);
846
847 /* Functions to create either a fullscreen or windowed console on the
848  * desktop, and to allow the resolution of fullscreen consoles to be
849  * changed on the fly without closing the console. For non-windowed
850  * environments (such as a Linux or OS/2 fullscreen console), these
851  * functions enable console graphics mode and restore console text mode.
852  *
853  * The suspend application callback is used to allow the application to
854  * save the state of the fullscreen console mode to allow temporary
855  * switching to another console or back to the regular GUI desktop. It
856  * is also called to restore the fullscreen graphics state after the
857  * fullscreen console regains the focus.
858  *
859  * The device parameter allows for the console to be opened on a different
860  * display controllers (0 is always the primary controller).
861  */
862
863 PM_HWND PMAPI PM_openConsole(PM_HWND hwndUser,int device,int xRes,int yRes,int bpp,ibool fullScreen);
864 int     PMAPI PM_getConsoleStateSize(void);
865 void    PMAPI PM_saveConsoleState(void *stateBuf,PM_HWND hwndConsole);
866 void    PMAPI PM_setSuspendAppCallback(PM_saveState_cb saveState);
867 void    PMAPI PM_restoreConsoleState(const void *stateBuf,PM_HWND hwndConsole);
868 void    PMAPI PM_closeConsole(PM_HWND hwndConsole);
869
870 /* Functions to modify OS console information */
871
872 void    PMAPI PM_setOSCursorLocation(int x,int y);
873 void    PMAPI PM_setOSScreenWidth(int width,int height);
874
875 /* Function to emable Intel PPro/PII write combining */
876
877 int     PMAPI PM_enableWriteCombine(ulong base,ulong length,uint type);
878 int     PMAPI PM_enumWriteCombine(PM_enumWriteCombine_t callback);
879
880 /* Function to add a path separator to the end of a filename (if not present) */
881
882 void    PMAPI PM_backslash(char *filename);
883
884 /* Routines to lock and unlock regions of memory under a virtual memory
885  * environment. These routines _must_ be used to lock all hardware
886  * and mouse interrupt handlers installed, _AND_ any global data that
887  * these handler manipulate, so that they will always be present in memory
888  * to handle the incoming interrupts.
889  *
890  * Note that it is important to call the correct routine depending on
891  * whether the area being locked is code or data, so that under 32 bit
892  * PM we will get the selector value correct.
893  */
894
895 int     PMAPI PM_lockDataPages(void *p,uint len,PM_lockHandle *lockHandle);
896 int     PMAPI PM_unlockDataPages(void *p,uint len,PM_lockHandle *lockHandle);
897 int     PMAPI PM_lockCodePages(__codePtr p,uint len,PM_lockHandle *lockHandle);
898 int     PMAPI PM_unlockCodePages(__codePtr p,uint len,PM_lockHandle *lockHandle);
899
900 /* Routines to install and remove Real Time Clock interrupt handlers. The
901  * frequency of the real time clock can be changed by calling
902  * PM_setRealTimeClockFrequeny, and the value can be any power of 2 value
903  * from 2Hz to 8192Hz.
904  *
905  * Note that you _must_ lock the memory containing the interrupt
906  * handlers with the PM_lockPages() function otherwise you may encounter
907  * problems in virtual memory environments.
908  *
909  * NOTE: User space versions of the PM library should fail these functions.
910  */
911
912 ibool   PMAPI PM_setRealTimeClockHandler(PM_intHandler ih,int frequency);
913 void    PMAPI PM_setRealTimeClockFrequency(int frequency);
914 void    PMAPI PM_restoreRealTimeClockHandler(void);
915
916 /* Routines to install and remove hardware interrupt handlers.
917  *
918  * Note that you _must_ lock the memory containing the interrupt
919  * handlers with the PM_lockPages() function otherwise you may encounter
920  * problems in virtual memory environments.
921  *
922  * NOTE: User space versions of the PM library should fail these functions.
923  */
924
925 PM_IRQHandle PMAPI PM_setIRQHandler(int IRQ,PM_irqHandler ih);
926 void    PMAPI PM_restoreIRQHandler(PM_IRQHandle irqHandle);
927
928 /* Functions to program DMA using the legacy ISA DMA controller */
929
930 void    PMAPI PM_DMACEnable(int channel);
931 void    PMAPI PM_DMACDisable(int channel);
932 void    PMAPI PM_DMACProgram(int channel,int mode,ulong bufferPhys,int count);
933 ulong   PMAPI PM_DMACPosition(int channel);
934
935 /* Function to post secondary graphics controllers using the BIOS */
936
937 ibool   PMAPI PM_doBIOSPOST(ushort axVal,ulong BIOSPhysAddr,void *mappedBIOS,ulong BIOSLen);
938
939 /* Function to init the AGP functions and return the AGP aperture size in MB */
940
941 ulong   PMAPI PM_agpInit(void);
942 void    PMAPI PM_agpExit(void);
943
944 /* Functions to reserve and release physical AGP memory ranges */
945
946 ibool   PMAPI PM_agpReservePhysical(ulong numPages,int type,void **physContext,PM_physAddr *physAddr);
947 ibool   PMAPI PM_agpReleasePhysical(void *physContext);
948
949 /* Functions to commit and free physical AGP memory ranges */
950
951 ibool   PMAPI PM_agpCommitPhysical(void *physContext,ulong numPages,ulong startOffset,PM_physAddr *physAddr);
952 ibool   PMAPI PM_agpFreePhysical(void *physContext,ulong numPages,ulong startOffset);
953
954 /* Functions to do I/O port manipulation directly from C code. These
955  * functions are portable and will work on any processor architecture
956  * to access I/O space registers on PCI devices.
957  */
958
959 uchar   PMAPI PM_inpb(int port);
960 ushort  PMAPI PM_inpw(int port);
961 ulong   PMAPI PM_inpd(int port);
962 void    PMAPI PM_outpb(int port,uchar val);
963 void    PMAPI PM_outpw(int port,ushort val);
964 void    PMAPI PM_outpd(int port,ulong val);
965
966 /* Functions to determine the I/O port locations for COM and LPT ports.
967  * The functions are zero based, so for COM1 or LPT1 pass in a value of 0,
968  * for COM2 or LPT2 pass in a value of 1 etc.
969  */
970
971 int     PMAPI PM_getCOMPort(int port);
972 int     PMAPI PM_getLPTPort(int port);
973
974 /* Internal functions that need prototypes */
975
976 void    PMAPI _PM_getRMvect(int intno, long *realisr);
977 void    PMAPI _PM_setRMvect(int intno, long realisr);
978 void    PMAPI _PM_freeMemoryMappings(void);
979
980 /* Function to override the default debug log file location */
981
982 void    PMAPI PM_setDebugLog(const char *logFilePath);
983
984 /* Function to put the process to sleep for the specified milliseconds */
985
986 void    PMAPI PM_sleep(ulong milliseconds);
987
988 /* Function to block until 'milliseconds' have passed since last call */
989
990 void    PMAPI PM_blockUntilTimeout(ulong milliseconds);
991
992 /* Functions for directory traversal and management */
993
994 void *  PMAPI PM_findFirstFile(const char *filename,PM_findData *findData);
995 ibool   PMAPI PM_findNextFile(void *handle,PM_findData *findData);
996 void    PMAPI PM_findClose(void *handle);
997 void    PMAPI PM_makepath(char *p,const char *drive,const char *dir,const char *name,const char *ext);
998 int     PMAPI PM_splitpath(const char *fn,char *drive,char *dir,char *name,char *ext);
999 ibool   PMAPI PM_driveValid(char drive);
1000 void    PMAPI PM_getdcwd(int drive,char *dir,int len);
1001 uint    PMAPI PM_getFileAttr(const char *filename);
1002 void    PMAPI PM_setFileAttr(const char *filename,uint attrib);
1003 ibool   PMAPI PM_getFileTime(const char *filename,ibool gmTime,PM_time *time);
1004 ibool   PMAPI PM_setFileTime(const char *filename,ibool gmTime,PM_time *time);
1005 ibool   PMAPI PM_mkdir(const char *filename);
1006 ibool   PMAPI PM_rmdir(const char *filename);
1007
1008 /* Functions to handle loading OS specific shared libraries */
1009
1010 PM_MODULE PMAPI PM_loadLibrary(const char *szDLLName);
1011 void *  PMAPI PM_getProcAddress(PM_MODULE hModule,const char *szProcName);
1012 void    PMAPI PM_freeLibrary(PM_MODULE hModule);
1013
1014 /* Functions and macros for 64-bit arithmetic */
1015
1016 void    PMAPI _PM_add64(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
1017 void    PMAPI _PM_sub64(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
1018 void    PMAPI _PM_mul64(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
1019 void    PMAPI _PM_div64(u32 a_low,s32 a_high,u32 b_low,s32 b_high,__i64 *result);
1020 void    PMAPI _PM_shr64(u32 a_low,s32 a_high,s32 shift,__i64 *result);
1021 void    PMAPI _PM_sar64(u32 a_low,s32 a_high,s32 shift,__i64 *result);
1022 void    PMAPI _PM_shl64(u32 a_low,s32 a_high,s32 shift,__i64 *result);
1023 void    PMAPI _PM_neg64(u32 a_low,s32 a_high,__i64 *result);
1024 #ifdef __NATIVE_INT64__
1025 #define PM_add64(r,a,b)     (r) = (a) + (b)
1026 #define PM_add64_32(r,a,b)  (r) = (a) + (b)
1027 #define PM_sub64(r,a,b)     (r) = (a) - (b)
1028 #define PM_sub64_32(r,a,b)  (r) = (a) - (b)
1029 #define PM_mul64(r,a,b)     (r) = (a) * (b)
1030 #define PM_mul64_32(r,a,b)  (r) = (a) * (b)
1031 #define PM_div64(r,a,b)     (r) = (a) / (b)
1032 #define PM_div64_32(r,a,b)  (r) = (a) / (b)
1033 #define PM_shr64(r,a,s)     (r) = (a) >> (s)
1034 #define PM_sar64(r,a,s)     (r) = ((s64)(a)) >> (s)
1035 #define PM_shl64(r,a,s)     (r) = (u64)(a) << (s)
1036 #define PM_neg64(r,a,s)     (r) = -(a)
1037 #define PM_not64(r,a,s)     (r) = ~(a)
1038 #define PM_eq64(a,b)        (a) == (b)
1039 #define PM_gt64(a,b)        (a) > (b)
1040 #define PM_lt64(a,b)        (a) < (b)
1041 #define PM_geq64(a,b)       (a) >= (b)
1042 #define PM_leq64(a,b)       (a) <= (b)
1043 #define PM_64to32(a)        (u32)(a)
1044 #define PM_64tos32(a)       (s32)(a)
1045 #define PM_set64(a,b,c)     (a) = ((u64)(b) << 32) + (c)
1046 #define PM_set64_32(a,b)    (a) = (b)
1047 #else
1048 #define PM_add64(r,a,b)     _PM_add64((a).low,(a).high,(b).low,(b).high,&(r))
1049 #define PM_add64_32(r,a,b)  _PM_add64((a).low,(a).high,b,0,&(r))
1050 #define PM_sub64(r,a,b)     _PM_sub64((a).low,(a).high,(b).low,(b).high,&(r))
1051 #define PM_sub64_32(r,a,b)  _PM_sub64((a).low,(a).high,b,0,&(r))
1052 #define PM_mul64(r,a,b)     _PM_mul64((a).low,(a).high,(b).low,(b).high,&(r))
1053 #define PM_mul64_32(r,a,b)  _PM_mul64((a).low,(a).high,b,0,&(r))
1054 #define PM_div64(r,a,b)     _PM_div64((a).low,(a).high,(b).low,(b).high,&(r))
1055 #define PM_div64_32(r,a,b)  _PM_div64((a).low,(a).high,b,0,&(r))
1056 #define PM_shr64(r,a,s)     _PM_shr64((a).low,(a).high,s,&(r))
1057 #define PM_sar64(r,a,s)     _PM_sar64((a).low,(a).high,s,&(r))
1058 #define PM_shl64(r,a,s)     _PM_shl64((a).low,(a).high,s,&(r))
1059 #define PM_neg64(r,a,s)     _PM_neg64((a).low,(a).high,&(r))
1060 #define PM_not64(r,a,s)     (r).low = ~(a).low, (r).high = ~(a).high
1061 #define PM_eq64(a,b)        ((a).low == (b).low && (a).high == (b).high)
1062 #define PM_gt64(a,b)        (((a).high > (b).high) || ((a).high == (b).high && (a).low > (b).low))
1063 #define PM_lt64(a,b)        (((a).high < (b).high) || ((a).high == (b).high && (a).low < (b).low))
1064 #define PM_geq64(a,b)       (PM_eq64(a,b) || PM_gt64(a,b))
1065 #define PM_leq64(a,b)       (PM_eq64(a,b) || PM_lt64(a,b))
1066 #define PM_64to32(a)        (u32)(a.low)
1067 #define PM_64tos32(a)       ((a).high < 0) ? -(a).low : (a).low)
1068 #define PM_set64(a,b,c)     (a).high = (b), (a).low = (c)
1069 #define PM_set64_32(a,b)    (a).high = 0, (a).low = (b)
1070 #endif
1071
1072 /* Function to enable IOPL access if required */
1073
1074 int     PMAPI PM_setIOPL(int iopl);
1075
1076 /* Function to flush the TLB and CPU caches */
1077
1078 void    PMAPI PM_flushTLB(void);
1079
1080 /* DOS specific fucntions */
1081
1082 #ifdef  __MSDOS__
1083 uint    PMAPI PMHELP_getVersion(void);
1084 void    PMAPI PM_VxDCall(VXD_regs *regs);
1085 #endif
1086
1087 /* Functions to save and restore the VGA hardware state */
1088
1089 int     PMAPI PM_getVGAStateSize(void);
1090 void    PMAPI PM_saveVGAState(void *stateBuf);
1091 void    PMAPI PM_restoreVGAState(const void *stateBuf);
1092 void    PMAPI PM_vgaBlankDisplay(void);
1093 void    PMAPI PM_vgaUnblankDisplay(void);
1094
1095 /* Functions to load and unload DirectDraw libraries. Only used on
1096  * Windows platforms.
1097  */
1098
1099 void *  PMAPI PM_loadDirectDraw(int device);
1100 void    PMAPI PM_unloadDirectDraw(int device);
1101 PM_HWND PMAPI PM_getDirectDrawWindow(void);
1102 void    PMAPI PM_doSuspendApp(void);
1103
1104 /* Functions to install, start, stop and remove NT services. Valid only
1105  * for Win32 apps running on Windows NT.
1106  */
1107
1108 #ifdef __WINDOWS32__
1109 ulong   PMAPI PM_installService(const char *szDriverName,const char *szServiceName,const char *szLoadGroup,ulong dwServiceType);
1110 ulong   PMAPI PM_startService(const char *szServiceName);
1111 ulong   PMAPI PM_stopService(const char *szServiceName);
1112 ulong   PMAPI PM_removeService(const char *szServiceName);
1113 #endif
1114
1115 /* Routines to generate native interrupts (ie: protected mode interrupts
1116  * for protected mode apps) using an interface the same as that use by
1117  * int86() and int86x() in realmode. These routines are required because
1118  * many 32 bit compilers use different register structures and different
1119  * functions causing major portability headaches. Thus we provide our
1120  * own and solve it all in one fell swoop, and we also get a routine to
1121  * put stuff into 32 bit registers from real mode ;-)
1122  */
1123
1124 void    PMAPI PM_segread(PMSREGS *sregs);
1125 int     PMAPI PM_int386(int intno, PMREGS *in, PMREGS *out);
1126 int     PMAPI PM_int386x(int intno, PMREGS *in, PMREGS *out,PMSREGS *sregs);
1127
1128 /* Call the X86 emulator or the real BIOS in our test harness */
1129
1130 #if defined(TEST_HARNESS) && !defined(PMLIB)
1131 #define PM_mapRealPointer(r_seg,r_off)      _PM_imports.PM_mapRealPointer(r_seg,r_off)
1132 #define PM_getVESABuf(len,rseg,roff)        _PM_imports.PM_getVESABuf(len,rseg,roff)
1133 #define PM_callRealMode(seg,off,regs,sregs) _PM_imports.PM_callRealMode(seg,off,regs,sregs)
1134 #define PM_int86(intno,in,out)              _PM_imports.PM_int86(intno,in,out)
1135 #define PM_int86x(intno,in,out,sregs)       _PM_imports.PM_int86x(intno,in,out,sregs)
1136 #endif
1137
1138 #ifdef  __cplusplus
1139 }                       /* End of "C" linkage for C++   */
1140 #endif
1141
1142 /* Include OS extensions for interrupt handling */
1143
1144 #if defined(__REALDOS__) || defined(__SMX32__)
1145 #include "pmint.h"
1146 #endif
1147
1148 #endif /* __PMAPI_H */
1149