-
Notifications
You must be signed in to change notification settings - Fork 0
/
PHAPI.h
586 lines (401 loc) · 15.8 KB
/
PHAPI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
/* PHAPI.H - 286|DOS-Extender Phar Lap API definition file */
/************************************************************************/
/* Copyright (C) 1986-1990 Phar Lap Software, Inc. */
/* Unpublished - rights reserved under the Copyright Laws of the */
/* United States. Use, duplication, or disclosure by the */
/* Government is subject to restrictions as set forth in */
/* subparagraph (c)(1)(ii) of the Rights in Technical Data and */
/* Computer Software clause at 252.227-7013. */
/* Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138 */
/************************************************************************/
/* $Id: phapi.h 1.7 92/03/11 11:05:07 rms Exp $ */
/*
This file provides C data structure declarations and function
prototypes that define the Phar Lap Application Program Interface
(PHAPI) for use in 286|DOS-Extender programs. The functions declared
in this file provide the following services:
o manipulating protected mode selectors
o manipulating pages on the 80386
o allocated conventional (DOS) memory
o interrupt and exception handling
o communicating with real mode code
o dynamic linking
o miscellaneous services
The code for PHAPI is located in PHAPI.DLL, a dynamic link
library that is part of 286|DOS-Extender. In addition to #including
PHAPI.H, programs that use the PHAPI should also link in the import
library, PHAPI.LIB.
All PHAPI functions must be invoked with a FAR call. With the
exception of three functions that allow a variable number of
arguments, all PHAPI routines use the Pascal calling convention. In
the following function prototypes, APIENTRY designates a FAR PASCAL
function.
286|DOS-Extender provides character-mode OS/2 API calls for
use by protected mode MS-DOS programs. The OS/2 API data structures
and function prototypes are declared in the file OS2.H, provided with
Microsoft C and compatible compilers (you DO NOT need the OS/2 SDK!).
The functions declared in this file, PHAPI.H, are those PHAPI
functions which are not already declared in OS2.H or in its helper
include files such as OS2DEF.H, BSEDOS.H, or BSESUB.H. This file,
PHAPI.H, automatically includes (and requires) the Microsoft C
OS2DEF.H include file. Most programs that #include will
probably also need to #include .
*/
#ifndef PHAPI_H_INCLUDED
#define PHAPI_H_INCLUDED
/*
If the OS/2 .H files haven't been included, then define the
following base types.
*/
#ifndef OS2DEF_INCLUDED
#define OS2DEF_INCLUDED
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef CHAR
typedef char CHAR;
#endif
#ifndef INT
typedef int INT;
#endif
typedef short SHORT;
typedef long LONG;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned char UCHAR;
typedef unsigned int UINT;
typedef unsigned short USHORT;
typedef unsigned long ULONG;
typedef char _far *PCHAR;
typedef int _far *PINT;
typedef short _far *PSHORT;
typedef long _far *PLONG;
typedef unsigned char _far *PUCHAR;
typedef unsigned int _far *PUINT;
typedef unsigned short _far *PUSHORT;
typedef unsigned long _far *PULONG;
typedef unsigned short SEL;
typedef unsigned short _far *PSEL;
typedef unsigned short HMODULE;
typedef unsigned short _far *PHMODULE;
typedef void _far *PVOID;
typedef unsigned char _far *PSZ;
typedef void(pascal _far *PFN)();
typedef PFN _far *PPFN;
#define VOID void
#define APIENTRY pascal _far
/*
Utility macros
*/
#define MAKEP(sel, off) ((PVOID)((((ULONG)(sel)) << 16) + (off)))
#define SELECTOROF(fp) ((SEL)(((ULONG)(fp)) >> 16))
#define OFFSETOF(fp) ((UINT)(ULONG)(fp))
#define MAKETYPE(var, type) (*((type _far *)&var))
#define FIELDOFFSET(type, field) ((UINT) & (((type *)0)->field))
#define MAKELONG(lo, hi) ((((LONG)(hi)) << 16) + (USHORT)(lo))
#define MAKEULONG(lo, hi) ((((ULONG)(hi)) << 16) + (USHORT)(lo))
#define MAKESHORT(lo, hi) ((((USHORT)(hi)) << 8) + (UCHAR)(lo))
#define MAKEUSHORT(lo, hi) ((((USHORT)(hi)) << 8) + (UCHAR)(lo))
#define LOBYTE(val) ((UCHAR)(val))
#define HIBYTE(val) ((UCHAR)(((USHORT)(val)) >> 8))
#define LOUCHAR(val) ((UCHAR)(val))
#define HIUCHAR(val) ((UCHAR)(((USHORT)(val)) >> 8))
#define LOWORD(val) ((USHORT)(val))
#define HIWORD(val) ((USHORT)(((ULONG)(val)) >> 16))
#define LOUSHORT(val) ((USHORT)(val))
#define HIUSHORT(val) ((USHORT)(((ULONG)(val)) >> 16))
#endif
/*
Force PHAPI.LIB to be linked into the resulting .EXE
*/
#pragma comment(lib, "PHAPI")
/*
Types
*/
typedef unsigned long REALPTR;
/*
Idealized segment descriptor
*/
typedef struct
{
ULONG base; /* Segment linear base address */
ULONG size; /* Size in bytes of segment */
USHORT attrib; /* Attribute byte */
} DESC;
typedef DESC _far *PDESC;
/*
Segment types
*/
#define CODE16 1 /* Code segment */
#define DATA16 2 /* Data segment */
#define CODE16_NOREAD 3 /* Execute only code segment */
#define DATA16_NOWRITE 4 /* Read only data segment */
/*
Mask values returned by "DosVerifyAccess"
*/
#define IS_SEL 0x0001 /* Is a valid selector */
#define IS_READABLE 0x0002 /* Is readable */
#define IS_WRITEABLE 0x0004 /* Is writeable */
#define IS_CODE 0x0008 /* Is executable */
/*
Registers structure
*/
typedef struct
{
USHORT es;
USHORT ds;
USHORT di;
USHORT si;
USHORT bp;
USHORT sp;
USHORT bx;
USHORT dx;
USHORT cx;
USHORT ax;
USHORT ip;
USHORT cs;
USHORT flags;
} REGS16;
typedef REGS16 _far *PREGS;
/*
Borland C registers for an interrupt function
*/
#ifdef __BORLANDC__
typedef struct
{
USHORT bp;
USHORT di;
USHORT si;
USHORT ds;
USHORT es;
USHORT dx;
USHORT cx;
USHORT bx;
USHORT ax;
USHORT ip;
USHORT cs;
USHORT flags;
} REGS_BINT;
typedef REGS_BINT _far *PREGS_BINT;
#define DosIsRealIntr BorIsRealIntr
#define DosIsProtIntr BorIsProtIntr
#define DosChainToRealIntr BorChainToRealIntr
#define DosChainToProtIntr BorChainToProtIntr
#endif
/*
DosSetExceptionHandler Stack Frame
*/
#ifndef __BORLANDC__
typedef struct
{
USHORT es;
USHORT ds;
USHORT di;
USHORT si;
USHORT bp;
USHORT sp;
USHORT bx;
USHORT dx;
USHORT cx;
USHORT ax;
USHORT rsv1; /* reserved - glue ip */
USHORT rsv2; /* reserved - glue cs */
USHORT rsv3; /* reserved - glue flags */
USHORT error_code;
USHORT ret_ip;
USHORT ret_cs;
USHORT ret_flags;
USHORT ret_rsv4; /* reserved - int sp */
USHORT ret_rsv5; /* reserved - int ss */
} EXCEP_FRAME;
#else
typedef struct
{
USHORT bp;
USHORT di;
USHORT si;
USHORT ds;
USHORT es;
USHORT dx;
USHORT cx;
USHORT bx;
USHORT ax;
USHORT rsv1; /* reserved - glue ip */
USHORT rsv2; /* reserved - glue cs */
USHORT rsv3; /* reserved - glue flags */
USHORT error_code;
USHORT ret_ip;
USHORT ret_cs;
USHORT ret_flags;
USHORT ret_rsv4; /* reserved - int sp */
USHORT ret_rsv5; /* reserved - int ss */
} EXCEP_FRAME;
#endif
typedef EXCEP_FRAME _far *PEXCEP_FRAME;
/*
Interrupt and Exception handler typedef's
*/
#ifndef __BORLANDC__
typedef void(_interrupt _far *PIHANDLER)(REGS16 regs);
#else
typedef void(_interrupt _far *PIHANDLER)(REGS_BINT regs);
#endif
typedef void(_interrupt _far *PEHANDLER)(EXCEP_FRAME regs);
/*
Function prototypes
*/
USHORT APIENTRY DosCreateDSAlias(SEL sel, PSEL aselp);
USHORT APIENTRY DosMapLinSeg(ULONG lin_addr, ULONG size, PSEL selp);
USHORT APIENTRY DosMapRealSeg(USHORT rm_para, ULONG size, PSEL selp);
USHORT APIENTRY DosMapPhysSeg(ULONG phys_addr, ULONG size, PSEL selp);
USHORT APIENTRY DosGetBIOSSeg(PSEL selp);
USHORT APIENTRY DosGetSegDesc(SEL sel, PDESC descp);
USHORT APIENTRY DosSetSegAttrib(SEL sel, USHORT attrib);
USHORT APIENTRY DosVerifyAccess(SEL sel, PUSHORT flagp);
USHORT APIENTRY DosLockSegPages(SEL sel);
USHORT APIENTRY DosUnlockSegPages(SEL sel);
USHORT APIENTRY DosGetPhysAddr(PVOID addr, PULONG phys_addrp, PULONG countp);
USHORT APIENTRY DosAllocRealSeg(ULONG size, PUSHORT parap, PSEL selp);
USHORT APIENTRY DosRealAvail(PULONG max_sizep);
USHORT APIENTRY DosSetRealVec(USHORT int_no, REALPTR new_ptr,
REALPTR _far *old_ptrp);
USHORT APIENTRY DosGetRealVec(USHORT int_no, REALPTR _far *ptrp);
USHORT APIENTRY DosSetProtVec(USHORT int_no, PIHANDLER new_ptr,
PIHANDLER _far *old_ptrp);
USHORT APIENTRY DosGetProtVec(USHORT int_no, PIHANDLER _far *ptrp);
USHORT APIENTRY DosGetSavedProtVec(USHORT int_no, PIHANDLER _far *ptrp);
USHORT APIENTRY DosSetExceptionHandler(USHORT excep_no, PEHANDLER new_ptr,
PEHANDLER _far *old_ptrp);
USHORT APIENTRY DosGetExceptionHandler(USHORT excep_no, PEHANDLER _far *ptrp);
USHORT APIENTRY DosSetRealProtVec(USHORT int_no, PIHANDLER prot_new_ptr,
REALPTR real_new_ptr,
PIHANDLER _far *prot_old_ptrp,
REALPTR _far *real_old_ptrp);
USHORT APIENTRY DosGetRealProtVec(USHORT int_no, PIHANDLER _far *prot_ptrp,
REALPTR _far *real_ptrp);
USHORT APIENTRY DosSetPassToProtVec(USHORT int_no, PIHANDLER prot_new_ptr,
PIHANDLER _far *prot_old_ptrp,
REALPTR _far *real_old_ptrp);
USHORT APIENTRY DosSetPassToRealVec(USHORT int_no, REALPTR real_new_ptr,
PIHANDLER _far *prot_old_ptrp,
REALPTR _far *real_old_ptrp);
USHORT _far _cdecl DosRealIntr(USHORT int_no, PREGS regsp, REALPTR reserved,
SHORT word_count, ...);
USHORT APIENTRY DosVRealIntr(USHORT int_no, PREGS regsp, REALPTR reserved,
SHORT word_count, PUSHORT argsp);
USHORT _far _cdecl DosRealFarCall(REALPTR funcp, PREGS regsp,
REALPTR reserved, SHORT word_count,
...);
USHORT APIENTRY DosVRealFarCall(REALPTR funcp, PREGS regsp, REALPTR reserved,
SHORT word_count, PUSHORT argsp);
USHORT _far _cdecl DosRealICall(REALPTR funcp, PREGS regsp,
REALPTR reserved, SHORT word_count,
...);
USHORT APIENTRY DosVRealICall(REALPTR funcp, PREGS regsp, REALPTR reserved,
SHORT word_count, PUSHORT argsp);
USHORT _far _cdecl DosRealFarJump(REALPTR funcp, PREGS regsp,
REALPTR reserved, SHORT word_count, ...);
USHORT APIENTRY DosVRealFarJump(REALPTR funcp, PREGS regsp, REALPTR reserved,
SHORT word_count, PUSHORT argsp);
USHORT APIENTRY DosFreeRealStack(REALPTR stack_ptr);
USHORT _far _cdecl DosProtIntr(USHORT int_no, PREGS regsp, PVOID reserved,
SHORT word_count, ...);
USHORT APIENTRY DosVProtIntr(USHORT int_no, PREGS regsp, PVOID reserved,
SHORT word_count, PUSHORT argsp);
USHORT _far _cdecl DosProtFarCall(PFN funcp, PREGS regsp, PVOID reserved,
SHORT word_count, ...);
USHORT APIENTRY DosVProtFarCall(PFN funcp, PREGS regsp, PVOID reserved,
SHORT word_count, PUSHORT argcp);
USHORT _far _cdecl DosProtFarJump(PFN funcp, PREGS regsp, PVOID reserved,
SHORT word_count, ...);
USHORT APIENTRY DosVProtFarJump(PFN funcp, PREGS regsp, PVOID reserved,
SHORT word_count, PUSHORT argsp);
USHORT APIENTRY DosFreeProtStack(PVOID stack_ptr);
USHORT APIENTRY DosEnumMod(PSZ name_buff, USHORT name_len, PHMODULE handp);
USHORT APIENTRY DosEnumProc(USHORT mod_handle, PSZ name_buff,
PUSHORT ordinalp);
USHORT APIENTRY DosIsPharLap(void);
REALPTR APIENTRY DosProtToReal(PVOID ptr);
PVOID APIENTRY DosRealToProt(REALPTR ptr);
BOOL APIENTRY DosIsRealIntr(PVOID stack_addr);
BOOL APIENTRY DosIsProtIntr(PVOID stack_addr);
USHORT APIENTRY DosChainToRealIntr(REALPTR hand_ptr);
USHORT APIENTRY DosChainToProtIntr(PIHANDLER hand_ptr);
USHORT APIENTRY DosGetRealProcAddr(USHORT mhand, PUCHAR namep,
REALPTR _far *paddrp);
USHORT APIENTRY DosSetProcAddr(HMODULE mhand, PSZ pnamep,
PFN paddr);
/*
Low level memory management functions
*/
USHORT APIENTRY DosRemapLinSeg(ULONG lin_addr, ULONG size, SEL sel);
USHORT APIENTRY DosRemapRealSeg(USHORT rm_para, ULONG size, SEL sel);
USHORT APIENTRY DosRemapPhysSeg(ULONG phys_addr, ULONG size, SEL sel);
USHORT APIENTRY DosAllocLinMem(ULONG size, PULONG lin_addp);
USHORT APIENTRY DosFreeLinMem(ULONG lin_add);
USHORT APIENTRY DosReallocLinMem(ULONG old_lin_add, ULONG new_size,
PULONG new_lin_addp);
USHORT APIENTRY DosMapLinMemToSelector(USHORT sel, ULONG lin_addr,
ULONG size);
USHORT APIENTRY DosAllocSpecificSelectors(SEL sel, USHORT count);
USHORT APIENTRY DosFreeSelectors(SEL sel, USHORT count);
/*
OS/2 compatible API's
*/
#ifndef INCL_DOSPROCESS_INCLUDED
#define INCL_DOSPROCESS_INCLUDED
typedef struct _RESULTCODES
{
USHORT codeTerminate;
USHORT codeResult;
} RESULTCODES;
typedef RESULTCODES _far *PRESULTCODES;
typedef void(pascal _far *PFNEXITLIST)(USHORT);
#define EXLST_ADD 1
#define EXLST_REMOVE 2
#define EXLST_EXIT 3
#define MODE_REAL 0
#define MODE_PROTECTED 1
#define TC_EXIT 0
#define TC_HARDERROR 1
#define TC_TRAP 2
#define TC_KILLPROCESS 3
#define EXEC_SYNC 0
#define EXEC_ASYNC 1
#define EXEC_ASYNCRESULT 2
#define EXEC_TRACE 3
#define EXEC_BACKGROUND 4
USHORT APIENTRY DosExecPgm(PCHAR failp, SHORT failc,
USHORT flags, PSZ argsp, PSZ envp,
PRESULTCODES resultp, PSZ namep);
VOID APIENTRY DosExit(USHORT flag, USHORT rc);
USHORT APIENTRY DosExitList(USHORT code, PFNEXITLIST funcp);
USHORT APIENTRY DosGetMachineMode(PUCHAR modep);
#endif
#ifndef INCL_DOSMEMMGR_INCLUDED
#define INCL_DOSMEMMGR_INCLUDED
USHORT APIENTRY DosAllocHuge(USHORT nseg, USHORT lcount, PSEL selp,
USHORT maxsel, USHORT flags);
USHORT APIENTRY DosAllocSeg(USHORT size, PSEL selp, USHORT flags);
USHORT APIENTRY DosCreateCSAlias(SEL dsel, PSEL cselp);
USHORT APIENTRY DosGetHugeShift(PUSHORT countp);
USHORT APIENTRY DosFreeSeg(SEL sel);
USHORT APIENTRY DosMemAvail(PULONG availp);
USHORT APIENTRY DosReallocHuge(USHORT nseg, USHORT lcount, SEL sel);
USHORT APIENTRY DosReallocSeg(USHORT nsize, SEL sel);
#endif
#ifndef INCL_DOSMODULEMGR_INCLUDED
#define INCL_DOSMODULEMGR_INCLUDED
USHORT APIENTRY DosFreeModule(HMODULE mhand);
USHORT APIENTRY DosGetModHandle(PSZ namep, PHMODULE mhandp);
USHORT APIENTRY DosGetModName(HMODULE mhand, USHORT buffc, PCHAR buffp);
USHORT APIENTRY DosGetProcAddr(HMODULE mhand, PSZ pnamep,
PPFN paddrp);
USHORT APIENTRY DosLoadModule(PSZ failp, USHORT failc,
PSZ modnamep, PHMODULE mhandp);
#ifdef __cplusplus
}
#endif
#endif
#endif