Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6286 lines
170 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) Copyright MICROSOFT Corp., 1988-1990
  4. *
  5. * Title: VMM.H - Include file for Virtual Machine Manager
  6. *
  7. * Version: 1.00
  8. *
  9. * Date: 05-May-1988
  10. *
  11. * Author: RAL
  12. *
  13. *-----------------------------------------------------------------------------
  14. *
  15. * Change log:
  16. *
  17. * DATE REV DESCRIPTION
  18. * ----------- --- -----------------------------------------------------------
  19. * 05-May-1988 RAL Original
  20. * 13-Nov-1991 PBS C version
  21. * 17-Dec-1993 Adds Far East VxDs identifiers
  22. */
  23. #ifndef _VMM_
  24. #define _VMM_
  25. /*
  26. * NON Windows/386 Virtual Device sources can include this file to get
  27. * some useful equates by declaring the symbol "Not_VxD" If this symbol
  28. * is defined, then everything that has to do with the specifics of the
  29. * 32 bit environment for virtual devices is removed. Useful equates
  30. * include: device ID's, pushad structure, BeginDoc, EndDoc, BeginMsg,
  31. * EndMsg, page table equates, etc.
  32. */
  33. #define FALSE 0 // False
  34. #define VMM_TRUE (~FALSE) // The opposite of False!
  35. #define DEBLEVELRETAIL 0
  36. #define DEBLEVELNORMAL 1
  37. #define DEBLEVELMAX 2
  38. #ifndef DEBLEVEL
  39. #ifdef DEBUG
  40. #define DEBLEVEL DEBLEVELNORMAL
  41. #else
  42. #define DEBLEVEL DEBLEVELRETAIL
  43. #endif
  44. #endif
  45. #ifndef WIN31COMPAT
  46. #define WIN40SERVICES
  47. #define WIN403SERVICES /*OPK-3 Services*/
  48. #endif
  49. #ifndef WIN40COMPAT
  50. #define WIN41SERVICES
  51. #endif
  52. /* ASM
  53. ifdef MASM6
  54. ifndef NO_MASM6_OPTIONS
  55. ;
  56. ; option switches necessary to build VMM/VxD sources with MASM 6
  57. ;
  58. option oldmacros
  59. ifndef NEWSTRUCTS ; define NEWSTRUCTS for MASM6 struct semantics
  60. option oldstructs
  61. endif
  62. option noscoped
  63. option segment:flat
  64. option offset:flat
  65. option proc:private
  66. endif
  67. endif
  68. ;
  69. ; These null macros are recognized by a utility program that produces
  70. ; documentation files.
  71. ;
  72. IFDEF MASM6
  73. BeginDoc MACRO
  74. ENDM
  75. EndDoc MACRO
  76. ENDM
  77. BeginMsg MACRO
  78. ENDM
  79. EndMsg MACRO
  80. ENDM
  81. ELSE
  82. BeginDoc EQU <>
  83. EndDoc EQU <>
  84. BeginMsg EQU <>
  85. EndMsg EQU <>
  86. ENDIF
  87. */
  88. /******************************************************************************
  89. *
  90. * EQUATES FOR REQUIRED DEVICES
  91. *
  92. * Device ID formulation note:
  93. *
  94. * The high bit of the device ID is reserved for future use.
  95. * Microsoft reserves the device ID's 0-1FFh for standard devices. If
  96. * an OEM VxD is a replacement for a standard VxD, then it must use the
  97. * standard VxD ID.
  98. *
  99. * OEMS WHO WANT A VXD DEVICE ID ASSIGNED TO THEM,
  100. * PLEASE CONTACT MICROSOFT PRODUCT SUPPORT. ID's are only required for
  101. * devices which provide services, V86 API's or PM API's. Also, calling
  102. * services or API's by VxD name is now supported in version 4.0, so an
  103. * ID may not be necessary as long as a unique 8 character name is used.
  104. *
  105. *****************************************************************************/
  106. #define UNDEFINED_DEVICE_ID 0x00000
  107. #define VMM_DEVICE_ID 0x00001 /* Used for dynalink table */
  108. #define DEBUG_DEVICE_ID 0x00002
  109. #define VPICD_DEVICE_ID 0x00003
  110. #define VDMAD_DEVICE_ID 0x00004
  111. #define VTD_DEVICE_ID 0x00005
  112. #define V86MMGR_DEVICE_ID 0x00006
  113. #define PAGESWAP_DEVICE_ID 0x00007
  114. #define PARITY_DEVICE_ID 0x00008
  115. #define REBOOT_DEVICE_ID 0x00009
  116. #define VDD_DEVICE_ID 0x0000A
  117. #define VSD_DEVICE_ID 0x0000B
  118. #define VMD_DEVICE_ID 0x0000C
  119. #define VKD_DEVICE_ID 0x0000D
  120. #define VCD_DEVICE_ID 0x0000E
  121. #define VPD_DEVICE_ID 0x0000F
  122. #define BLOCKDEV_DEVICE_ID 0x00010
  123. #define VMCPD_DEVICE_ID 0x00011
  124. #define EBIOS_DEVICE_ID 0x00012
  125. #define BIOSXLAT_DEVICE_ID 0x00013
  126. #define VNETBIOS_DEVICE_ID 0x00014
  127. #define DOSMGR_DEVICE_ID 0x00015
  128. #define WINLOAD_DEVICE_ID 0x00016
  129. #define SHELL_DEVICE_ID 0x00017
  130. #define VMPOLL_DEVICE_ID 0x00018
  131. #define VPROD_DEVICE_ID 0x00019
  132. #define DOSNET_DEVICE_ID 0x0001A
  133. #define VFD_DEVICE_ID 0x0001B
  134. #define VDD2_DEVICE_ID 0x0001C /* Secondary display adapter */
  135. #define WINDEBUG_DEVICE_ID 0x0001D
  136. #define TSRLOAD_DEVICE_ID 0x0001E /* TSR instance utility ID */
  137. #define BIOSHOOK_DEVICE_ID 0x0001F /* Bios interrupt hooker VxD */
  138. #define INT13_DEVICE_ID 0x00020
  139. #define PAGEFILE_DEVICE_ID 0x00021 /* Paging File device */
  140. #define SCSI_DEVICE_ID 0x00022 /* SCSI device */
  141. #define MCA_POS_DEVICE_ID 0x00023 /* MCA_POS device */
  142. #define SCSIFD_DEVICE_ID 0x00024 /* SCSI FastDisk device */
  143. #define VPEND_DEVICE_ID 0x00025 /* Pen device */
  144. #define APM_DEVICE_ID 0x00026 /* Power Management device */
  145. #define VPOWERD_DEVICE_ID APM_DEVICE_ID /* We overload APM since we replace it */
  146. #define VXDLDR_DEVICE_ID 0x00027 /* VxD Loader device */
  147. #define NDIS_DEVICE_ID 0x00028 /* NDIS wrapper */
  148. #define BIOS_EXT_DEVICE_ID 0x00029 /* Fix Broken BIOS device */
  149. #define VWIN32_DEVICE_ID 0x0002A /* for new WIN32-VxD */
  150. #define VCOMM_DEVICE_ID 0x0002B /* New COMM device driver */
  151. #define SPOOLER_DEVICE_ID 0x0002C /* Local Spooler */
  152. #define WIN32S_DEVICE_ID 0x0002D /* Win32S on Win 3.1 driver */
  153. #define DEBUGCMD_DEVICE_ID 0x0002E /* Debug command extensions */
  154. /* #define RESERVED_DEVICE_ID 0x0002F /* Not currently in use */
  155. /* #define ATI_HELPER_DEVICE_ID 0x00030 /* grabbed by ATI */
  156. /* 31-32 USED BY WFW NET COMPONENTS */
  157. /* #define VNB_DEVICE_ID 0x00031 /* Netbeui of snowball */
  158. /* #define SERVER_DEVICE_ID 0x00032 /* Server of snowball */
  159. #define CONFIGMG_DEVICE_ID 0x00033 /* Configuration manager (Plug&Play) */
  160. #define DWCFGMG_DEVICE_ID 0x00034 /* Configuration manager for win31 and DOS */
  161. #define SCSIPORT_DEVICE_ID 0x00035 /* Dragon miniport loader/driver */
  162. #define VFBACKUP_DEVICE_ID 0x00036 /* allows backup apps to work with NEC */
  163. #define ENABLE_DEVICE_ID 0x00037 /* for access VxD */
  164. #define VCOND_DEVICE_ID 0x00038 /* Virtual Console Device - check vcond.inc */
  165. /* 39 used by WFW VFat Helper device */
  166. /* 3A used by WFW E-FAX */
  167. /* #define EFAX_DEVICE_ID 0x0003A /* EFAX VxD ID */
  168. /* 3B used by MS-DOS 6.1 for the DblSpace VxD which has APIs */
  169. /* #define DSVXD_DEVICE_ID 0x0003B /* Dbl Space VxD ID */
  170. #define ISAPNP_DEVICE_ID 0x0003C /* ISA P&P Enumerator */
  171. #define BIOS_DEVICE_ID 0x0003D /* BIOS P&P Enumerator */
  172. /* #define WINSOCK_DEVICE_ID 0x0003E /* WinSockets */
  173. /* #define WSIPX_DEVICE_ID 0x0003F /* WinSockets for IPX */
  174. #define IFSMgr_Device_ID 0x00040 /* Installable File System Manager */
  175. #define VCDFSD_DEVICE_ID 0x00041 /* Static CDFS ID */
  176. #define MRCI2_DEVICE_ID 0x00042 /* DrvSpace compression engine */
  177. #define PCI_DEVICE_ID 0x00043 /* PCI P&P Enumerator */
  178. #define PELOADER_DEVICE_ID 0x00044 /* PE Image Loader */
  179. #define EISA_DEVICE_ID 0x00045 /* EISA P&P Enumerator */
  180. #define DRAGCLI_DEVICE_ID 0x00046 /* Dragon network client */
  181. #define DRAGSRV_DEVICE_ID 0x00047 /* Dragon network server */
  182. #define PERF_DEVICE_ID 0x00048 /* Config/stat info */
  183. #define AWREDIR_DEVICE_ID 0x00049 /* AtWork Network FSD */
  184. #define DDS_DEVICE_ID 0x0004A /* Device driver services */
  185. #define NTKERN_DEVICE_ID 0x0004B /* NT kernel device id */
  186. #define VDOSKEYD_DEVICE_ID 0x0004B /* DOSKEY device id */
  187. /*
  188. * Far East DOS support VxD ID
  189. */
  190. #define ETEN_Device_ID 0x00060 /* ETEN DOS (Taiwan) driver */
  191. #define CHBIOS_Device_ID 0x00061 /* CHBIOS DOS (Korean) driver */
  192. #define VMSGD_Device_ID 0x00062 /* DBCS Message Mode driver */
  193. #define VPPID_Device_ID 0x00063 /* PC-98 System Control PPI */
  194. #define VIME_Device_ID 0x00064 /* Virtual DOS IME */
  195. #define VHBIOSD_Device_ID 0x00065 /* HBIOS (Korean) for HWin31 driver */
  196. #define BASEID_FOR_NAMEBASEDVXD 0xf000 /* Name based VxD IDs start here */
  197. #define BASEID_FOR_NAMEBASEDVXD_MASK 0x0fff /* Mask to get the real vxd id */
  198. /*
  199. * Initialization order equates. Devices are initialized in order from
  200. * LOWEST to HIGHEST. If 2 or more devices have the same initialization
  201. * order value, then they are initialized in order of occurance, so a
  202. * specific order is not guaranteed. Holes have been left to allow maximum
  203. * flexibility in ordering devices.
  204. */
  205. #define VMM_INIT_ORDER 0x000000000
  206. #define DEBUG_INIT_ORDER 0x000000000 /* normally using 0 is bad */
  207. #define DEBUGCMD_INIT_ORDER 0x000000000 /* but debug must be first */
  208. #define PERF_INIT_ORDER 0x000900000
  209. #define APM_INIT_ORDER 0x001000000
  210. #define VPOWERD_INIT_ORDER APM_INIT_ORDER /* We overload APM since we replace it */
  211. #define BIOSHOOK_INIT_ORDER 0x006000000
  212. #define VPROD_INIT_ORDER 0x008000000
  213. #define VPICD_INIT_ORDER 0x00C000000
  214. #define VTD_INIT_ORDER 0x014000000
  215. #define VWIN32_INIT_ORDER 0x014100000
  216. #define NTKERN_INIT_ORDER 0x015000000 /* Must be before VxDLdr (so that it is ready for devnodes) */
  217. #define VXDLDR_INIT_ORDER 0x016000000
  218. #define ENUMERATOR_INIT_ORDER 0x016800000 /* Should be before IOS */
  219. #define ISAPNP_INIT_ORDER ENUMERATOR_INIT_ORDER
  220. #define EISA_INIT_ORDER ENUMERATOR_INIT_ORDER
  221. #define PCI_INIT_ORDER ENUMERATOR_INIT_ORDER
  222. #define BIOS_INIT_ORDER ENUMERATOR_INIT_ORDER+1 /* To simplify reenumeration */
  223. #define CONFIGMG_INIT_ORDER ENUMERATOR_INIT_ORDER+0xFFFF /* After all enumerators */
  224. #define VCDFSD_INIT_ORDER 0x016F00000
  225. #define IOS_INIT_ORDER 0x017000000
  226. #define PAGEFILE_INIT_ORDER 0x018000000
  227. #define PAGESWAP_INIT_ORDER 0x01C000000
  228. #define PARITY_INIT_ORDER 0x020000000
  229. #define REBOOT_INIT_ORDER 0x024000000
  230. #define EBIOS_INIT_ORDER 0x026000000
  231. #define VDD_INIT_ORDER 0x028000000
  232. #define VSD_INIT_ORDER 0x02C000000
  233. #define VCD_INIT_ORDER 0x030000000
  234. #define COMMDRVR_INIT_ORDER (VCD_INIT_ORDER - 1)
  235. #define PRTCL_INIT_ORDER (COMMDRVR_INIT_ORDER - 2)
  236. #define MODEM_INIT_ORDER (COMMDRVR_INIT_ORDER - 3)
  237. #define PORT_INIT_ORDER (COMMDRVR_INIT_ORDER - 4)
  238. #define VMD_INIT_ORDER 0x034000000
  239. #define VKD_INIT_ORDER 0x038000000
  240. #define VPD_INIT_ORDER 0x03C000000
  241. #define BLOCKDEV_INIT_ORDER 0x040000000
  242. #define MCA_POS_INIT_ORDER 0x041000000
  243. #define SCSIFD_INIT_ORDER 0x041400000
  244. #define SCSIMASTER_INIT_ORDER 0x041800000
  245. #define INT13_INIT_ORDER 0x042000000
  246. #define VMCPD_INIT_ORDER 0x048000000
  247. #define BIOSXLAT_INIT_ORDER 0x050000000
  248. #define VNETBIOS_INIT_ORDER 0x054000000
  249. #define DOSMGR_INIT_ORDER 0x058000000
  250. #define DOSNET_INIT_ORDER 0x05C000000
  251. #define WINLOAD_INIT_ORDER 0x060000000
  252. #define VMPOLL_INIT_ORDER 0x064000000
  253. #define UNDEFINED_INIT_ORDER 0x080000000
  254. #define VCOND_INIT_ORDER UNDEFINED_INIT_ORDER
  255. #define WINDEBUG_INIT_ORDER 0x081000000
  256. #define VDMAD_INIT_ORDER 0x090000000
  257. #define V86MMGR_INIT_ORDER 0x0A0000000
  258. #define IFSMgr_Init_Order 0x10000 + V86MMGR_Init_Order
  259. #define FSD_Init_Order 0x00100 + IFSMgr_Init_Order
  260. #define VFD_INIT_ORDER 0x50000 + IFSMgr_Init_Order
  261. /* Device that must touch memory in 1st Mb at crit init (after V86mmgr) */
  262. #define UNDEF_TOUCH_MEM_INIT_ORDER 0x0A8000000
  263. #define SHELL_INIT_ORDER 0x0B0000000
  264. /* ASM
  265. ;******************************************************************************
  266. ;
  267. ; Macro to cause a delay in between I/O accesses to the same device.
  268. ;
  269. ;------------------------------------------------------------------------------
  270. IO_Delay macro
  271. jmp $+2
  272. ENDM
  273. */
  274. #define VXD_FAILURE 0
  275. #define VXD_SUCCESS 1
  276. typedef ULONG HVM; /* VM handle typedef */
  277. /*
  278. * Registers as they appear on the stack after a PUSHAD.
  279. */
  280. struct Pushad_Struc {
  281. ULONG Pushad_EDI; /* Client's EDI */
  282. ULONG Pushad_ESI; /* Client's ESI */
  283. ULONG Pushad_EBP; /* Client's EBP */
  284. ULONG Pushad_ESP; /* ESP before pushad */
  285. ULONG Pushad_EBX; /* Client's EBX */
  286. ULONG Pushad_EDX; /* Client's EDX */
  287. ULONG Pushad_ECX; /* Client's ECX */
  288. ULONG Pushad_EAX; /* Client's EAX */
  289. };
  290. /* XLATOFF */
  291. #ifdef RC_INVOKED
  292. #define NOBASEDEFS
  293. #endif
  294. #ifndef NOBASEDEFS
  295. #pragma warning (disable:4209) // turn off redefinition warning
  296. typedef unsigned char UCHAR;
  297. typedef unsigned short USHORT;
  298. #pragma warning (default:4209) // turn off redefinition warning
  299. #endif
  300. #define GetVxDServiceOrdinal(service) __##service
  301. #define Begin_Service_Table(device, seg) \
  302. enum device##_SERVICES { \
  303. device##_dummy = (device##_DEVICE_ID << 16) - 1,
  304. #define Declare_Service(service, local) \
  305. GetVxDServiceOrdinal(service),
  306. #define Declare_SCService(service, args, local) \
  307. GetVxDServiceOrdinal(service),
  308. #define End_Service_Table(device, seg) \
  309. Num_##device##_Services};
  310. #define VXDINLINE static __inline
  311. /* XLATON */
  312. #ifndef Not_VxD
  313. /* XLATOFF */
  314. #define VxD_LOCKED_CODE_SEG code_seg("_LTEXT", "LCODE")
  315. #define VxD_LOCKED_DATA_SEG data_seg("_LDATA", "LCODE")
  316. #define VxD_INIT_CODE_SEG code_seg("_ITEXT", "ICODE")
  317. #define VxD_INIT_DATA_SEG data_seg("_IDATA", "ICODE")
  318. #define VxD_ICODE_SEG code_seg("_ITEXT", "ICODE")
  319. #define VxD_IDATA_SEG data_seg("_IDATA", "ICODE")
  320. #define VxD_PAGEABLE_CODE_SEG code_seg("_PTEXT", "PCODE")
  321. #define VxD_PAGEABLE_DATA_SEG data_seg("_PDATA", "PDATA")
  322. #define VxD_STATIC_CODE_SEG code_seg("_STEXT", "SCODE")
  323. #define VxD_STATIC_DATA_SEG data_seg("_SDATA", "SCODE")
  324. #define VxD_DEBUG_ONLY_CODE_SEG code_seg("_DBOCODE", "DBOCODE")
  325. #define VxD_DEBUG_ONLY_DATA_SEG data_seg("_DBODATA", "DBOCODE")
  326. #define VxD_SYSEXIT_CODE_SEG code_seg("SYSEXIT", "SYSEXITCODE")
  327. #define VxD_INT21_CODE_SEG code_seg("INT21", "INT21CODE")
  328. #define VxD_RARE_CODE_SEG code_seg("RARE", "RARECODE")
  329. #define VxD_W16_CODE_SEG code_seg("W16", "W16CODE")
  330. #define VxD_W32_CODE_SEG code_seg("W32", "W32CODE")
  331. #define VxD_VMCREATE_CODE_SEG code_seg("VMCREATE", "VMCREATECODE")
  332. #define VxD_VMDESTROY_CODE_SEG code_seg("VMDESTROY", "VMDESTROYCODE")
  333. #define VxD_THCREATE_CODE_SEG code_seg("THCREATE", "THCREATECODE")
  334. #define VxD_THDESTROY_CODE_SEG code_seg("THDESTROY", "THDESTROYCODE")
  335. #define VxD_VMSUSPEND_CODE_SEG code_seg("VMSUSPEND", "VMSUSPENDCODE")
  336. #define VxD_VMRESUME_CODE_SEG code_seg("VMRESUME", "VMRESUMECODE")
  337. #define VxD_PNP_CODE_SEG code_seg("PNP", "PNPCODE")
  338. #define VxD_DOSVM_CODE_SEG code_seg("DOSVM", "DOSVMCODE")
  339. #define VxD_LOCKABLE_CODE_SEG code_seg("LOCKABLE", "LOCKABLECODE")
  340. /* XLATON */
  341. /* ASM
  342. ??_CUR_CODE_SEG = 0
  343. ??_LCODE = 1
  344. ??_ICODE = 2
  345. ??_PCODE = 3
  346. ??_SCODE = 4
  347. ??_DBOCODE = 5
  348. ??_16ICODE = 6
  349. ??_RCODE = 7
  350. ??_LOCKABLECODE = 8
  351. ?_LCODE equ <(??_CUR_CODE_SEG MOD 16) - ??_LCODE>
  352. ?_ICODE equ <(??_CUR_CODE_SEG MOD 16) - ??_ICODE>
  353. ?_PCODE equ <(??_CUR_CODE_SEG MOD 16) - ??_PCODE>
  354. ?_SCODE equ <(??_CUR_CODE_SEG MOD 16) - ??_SCODE>
  355. ?_DBOCODE equ <(??_CUR_CODE_SEG MOD 16) - ??_DBOCODE>
  356. ?_16ICODE equ <(??_CUR_CODE_SEG MOD 16) - ??_16ICODE>
  357. ?_RCODE equ <(??_CUR_CODE_SEG MOD 16) - ??_RCODE>
  358. ?_LOCKABLECODE equ <(??_CUR_CODE_SEG MOD 16) - ??_LOCKABLECODE>
  359. ifndef NO_SEGMENTS
  360. ;
  361. ; SEGMENT definitions and order
  362. ;
  363. IFDEF MASM6
  364. _FLAT EQU FLAT
  365. ELSE
  366. _FLAT EQU USE32
  367. ENDIF
  368. ;* 32 bit locked code
  369. _LTEXT SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  370. _LTEXT ENDS
  371. _TEXT SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  372. _TEXT ENDS
  373. ;* 32 bit pageable code
  374. _PTEXT SEGMENT DWORD PUBLIC _FLAT 'PCODE'
  375. _PTEXT ENDS
  376. MakeCodeSeg MACRO seglist, classname, grpname, iseg
  377. IRP segname,<seglist> ;; For each name in the list
  378. IFNB <classname>
  379. segname SEGMENT DWORD PUBLIC _FLAT "&classname&CODE"
  380. ELSE
  381. segname SEGMENT DWORD PUBLIC _FLAT "&segname&CODE"
  382. ENDIF
  383. IFB <iseg>
  384. VxD_&&segname&&_CODE_SEG MACRO
  385. segname SEGMENT
  386. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_PCODE
  387. ASSUME cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  388. ENDM
  389. ELSE
  390. VxD_&&segname&&_CODE_SEG MACRO
  391. segname SEGMENT
  392. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + iseg
  393. ASSUME cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  394. ENDM
  395. ENDIF
  396. VxD_&&segname&&_CODE_ENDS MACRO
  397. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  398. segname ENDS
  399. ENDM
  400. segname ENDS
  401. IFNDEF BLD_COFF
  402. IFNB <grpname>
  403. _&grpname GROUP segname
  404. ELSE
  405. _&&segname GROUP segname
  406. ENDIF
  407. ENDIF
  408. ENDM ;; End for each segment
  409. ENDM
  410. MakeCodeSeg <LOCKABLE_BEGIN, LOCKABLE, LOCKABLE_END>, \
  411. LOCKABLE, LOCKABLE, ??_LOCKABLECODE
  412. MakeCodeSeg INT21
  413. MakeCodeSeg SYSEXIT
  414. MakeCodeSeg RARE
  415. MakeCodeSeg W16
  416. MakeCodeSeg W32
  417. MakeCodeSeg VMCREATE
  418. MakeCodeSeg VMDESTROY
  419. MakeCodeSeg THCREATE
  420. MakeCodeSeg THDESTROY
  421. MakeCodeSeg VMSUSPEND
  422. MakeCodeSeg VMRESUME
  423. MakeCodeSeg PNP
  424. MakeCodeSeg DOSVM
  425. ;*** DefLockableCodeBegin - define beginning of lockable code
  426. ;
  427. ; Defines a label with the given name to mark the beginning
  428. ; of the lockable code area for this VxD. In the debug version,
  429. ; also defines a DWORD containing DFS_TEST_BLOCK so that
  430. ; procedures in the lockable code segment defined with
  431. ; BeginProc may call _Debug_Flags_Service with flags appropriate
  432. ; to the code's current state.
  433. DefLockableCodeBegin MACRO name, private
  434. VxD_LOCKABLE_BEGIN_CODE_SEG
  435. IFB <private>
  436. PUBLIC name
  437. ENDIF
  438. name LABEL NEAR
  439. VxD_LOCKABLE_BEGIN_CODE_ENDS
  440. ifndef WIN31COMPAT
  441. if DEBLEVEL
  442. VxD_LOCKED_DATA_SEG
  443. PUBLIC name&_Debug_Flags
  444. name&_Debug_Flags DD DFS_TEST_BLOCK
  445. VxD_LOCKED_DATA_ENDS
  446. ??_debug_flags equ <name&_Debug_Flags>
  447. endif
  448. endif
  449. ENDM
  450. ;*** DefLockableCodeEnd - define end of lockable code
  451. ;
  452. ; Defines a label with the given name to mark the end
  453. ; of the lockable code area for this VxD. By subtracting
  454. ; the offset of the beginning label from the offset of
  455. ; the ending label, the VxD may determine how many bytes
  456. ; of memory to lock or unlock.
  457. DefLockableCodeEnd MACRO name, private
  458. VxD_LOCKABLE_END_CODE_SEG
  459. IFB <private>
  460. PUBLIC name
  461. ENDIF
  462. name LABEL NEAR
  463. VxD_LOCKABLE_END_CODE_ENDS
  464. ENDM
  465. ;*** CodeLockFlags - declare locked code debug flags
  466. ;
  467. ; This macro declares the locked code debug flags.
  468. CodeLockFlags MACRO name
  469. ifndef WIN31COMPAT
  470. if DEBLEVEL
  471. ifndef name&_Debug_Flags
  472. VxD_LOCKED_DATA_SEG
  473. extrn name&_Debug_Flags:dword
  474. VxD_LOCKED_DATA_ENDS
  475. ??_debug_flags equ <name&_Debug_Flags>
  476. endif
  477. endif
  478. endif
  479. ENDM
  480. ;*** MarkCodeLocked - signify that lockable code is locked
  481. ;
  482. ; This macro clears DFS_TEST_BLOCK in the debug flags
  483. ; DWORD.
  484. MarkCodeLocked MACRO
  485. ifndef WIN31COMPAT
  486. if DEBLEVEL
  487. ifdef ??_debug_flags
  488. pushfd
  489. and ??_debug_flags,NOT DFS_TEST_BLOCK
  490. popfd
  491. endif
  492. endif
  493. endif
  494. ENDM
  495. ;*** MarkCodeUnlocked - signify that lockable code is unlocked
  496. ;
  497. ; This macro sets DFS_TEST_BLOCK in the debug flags
  498. ; DWORD.
  499. MarkCodeUnlocked MACRO
  500. ifndef WIN31COMPAT
  501. if DEBLEVEL
  502. ifdef ??_debug_flags
  503. pushfd
  504. or ??_debug_flags,DFS_TEST_BLOCK
  505. popfd
  506. endif
  507. endif
  508. endif
  509. ENDM
  510. ;* 32 bit initialization code
  511. _ITEXT SEGMENT DWORD PUBLIC _FLAT 'ICODE'
  512. _ITEXT ENDS
  513. ;* 32 bit locked data
  514. _LDATA SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  515. _LDATA ENDS
  516. _DATA SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  517. _DATA ENDS
  518. ;* 32 bit pageable data
  519. _PDATA SEGMENT DWORD PUBLIC _FLAT 'PDATA'
  520. _PDATA ENDS
  521. ;* 32 Bit initialization data
  522. _IDATA SEGMENT DWORD PUBLIC _FLAT 'ICODE'
  523. _IDATA ENDS
  524. ;* Created by C8
  525. _BSS SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  526. _BSS ENDS
  527. CONST SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  528. CONST ENDS
  529. _TLS SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  530. _TLS ENDS
  531. ;* 32 Bit static code for DL-VxDs
  532. _STEXT SEGMENT DWORD PUBLIC _FLAT 'SCODE'
  533. _STEXT ENDS
  534. ;* 32 Bit static data for DL-VxDs
  535. _SDATA SEGMENT DWORD PUBLIC _FLAT 'SCODE'
  536. _SDATA ENDS
  537. ;* dummy segment for IsDebugOnlyLoaded
  538. _DBOSTART SEGMENT DWORD PUBLIC _FLAT 'DBOCODE'
  539. _DBOSTART ENDS
  540. ;* 32 bit debug only code; loaded only if debugger is present
  541. _DBOCODE SEGMENT DWORD PUBLIC _FLAT 'DBOCODE'
  542. _DBOCODE ENDS
  543. ;* 32 bit debug only data; loaded only if debugger is present
  544. _DBODATA SEGMENT DWORD PUBLIC _FLAT 'DBOCODE'
  545. _DBODATA ENDS
  546. if DEBLEVEL
  547. ;* Start of 32 bit path coverage data
  548. _PATHSTART SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  549. _PATHSTART ENDS
  550. ;* 32 bit path coverage data
  551. _PATHDATA SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  552. _PATHDATA ENDS
  553. ;* End of 32 bit path coverage data
  554. _PATHEND SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  555. _PATHEND ENDS
  556. endif
  557. ;* 16 bit code/data that is put into IGROUP automaticly
  558. _16ICODE SEGMENT WORD USE16 PUBLIC '16ICODE'
  559. _16ICODE ENDS
  560. ;* Real Mode initialization code/data for devices
  561. _RCODE SEGMENT WORD USE16 PUBLIC 'RCODE'
  562. _RCODE ENDS
  563. IFNDEF BLD_COFF
  564. _LGROUP GROUP _LTEXT, _TEXT, _LDATA, _DATA, _BSS, CONST, _TLS
  565. _IGROUP GROUP _ITEXT, _IDATA
  566. _SGROUP GROUP _STEXT, _SDATA
  567. _DBOGROUP GROUP _DBOSTART, _DBOCODE, _DBODATA
  568. IF DEBLEVEL
  569. _PGROUP GROUP _PATHSTART, _PATHDATA, _PATHEND
  570. ENDIF
  571. ENDIF
  572. endif ; NO_SEGMENTS
  573. ASSUME CS:FLAT, DS:FLAT, ES:FLAT, SS:FLAT
  574. OFFSET32 EQU <OFFSET FLAT:>
  575. BeginDoc
  576. ;==============================================================================
  577. ; The following macros are used in defining the routines
  578. ; in a VxD which are going to be registered with VMM as callable entry
  579. ; points. Once registered, the entry points can be called by any other
  580. ; devices via the "VxDCall" macro, defined below. In the comments below,
  581. ; replace "VxD" with the appropriate device name.
  582. ;
  583. ;*******
  584. ; In the VxD.INC file, put the following lines, replacing <function_name>
  585. ; with an appropriate name describing the function of the routine.
  586. ;
  587. ; Begin_Service_Table VxD[,<segname>]
  588. ; VxD_Service <function_name>[,<local segname>]
  589. ; VxD_Service <function_name>[,<local segname>]
  590. ; . . .
  591. ; VxD_Service <function_name>[,<local segname>]
  592. ; End_Service_Table VxD[,<segname>]
  593. ;
  594. ; Note that <segname> is an optional argument and, if specified, the
  595. ; table is put in the segment defined by the macro "yyy_Data_Seg",
  596. ; where yyy=segname. Otherwise the segment is defined by the
  597. ; "VxD_Data_Seg" macro, defined below.
  598. ; Note that <local segname> is an optional argument and, if specified,
  599. ; the procedure's segment is defined by the macro "zzz_Code_Seg",
  600. ; where zzz=segname. Otherwise the segment is defined by the
  601. ; "VxD_Code_Seg" macro, defined below.
  602. ;
  603. ;*******
  604. ; One VxD module should have the following in order to define the entry points:
  605. ;Create_VxD_Service_Table = 1 ; Only in module where table is
  606. ; INCLUDE VxD.INC ; Include the table definition
  607. ;
  608. ;*******
  609. ; All modules that want to call the services defined in the table should include
  610. ; VxD.INC, but not define the label "Create_VxD_Service_Table". This
  611. ; will define the service names to be used with the VxDCall macro.
  612. ;
  613. EndDoc
  614. Begin_Service_Table MACRO Device_Name, Def_Segment
  615. IFDEF Device_Name&_Name_Based
  616. IFNDEF @@NextInternalID
  617. @@NextInternalID = 0
  618. ENDIF
  619. @@NextInternalID = (@@NextInternalID + 1)
  620. Device_Name&_Internal_ID = @@NextInternalID + BASEID_FOR_NAMEBASEDVXD
  621. DefineVxDName Device_Name, %Device_Name&_Internal_ID
  622. ENDIF
  623. IFB <Def_Segment>
  624. BST2 Device_Name, VxD
  625. ELSE
  626. BST2 Device_Name, Def_Segment
  627. ENDIF
  628. ENDM
  629. DefineVxDName MACRO Device_Name, InternalID
  630. @@VxDName&InternalID EQU <___&Device_Name&STable>
  631. ENDM
  632. BST2 MACRO Device_Name, Def_Segment
  633. Num_&Device_Name&_Services = 0
  634. IFDEF Create_&Device_Name&_Service_Table
  635. Def_Segment&_LOCKED_DATA_SEG
  636. Device_Name&_Service_Table LABEL DWORD
  637. Device_Name&_Service MACRO Procedure, Local_Seg, Condition, StdCallBytes, fastcall
  638. LOCAL $$&Procedure, extrnproc, tableproc
  639. extrnproc MACRO
  640. IFNB <fastcall>
  641. IFB <StdCallBytes>
  642. .err ;StdCallBytes required
  643. ENDIF
  644. EXTRN @&&Procedure&&@&&StdCallBytes:NEAR
  645. ELSE
  646. IFNB <StdCallBytes>
  647. EXTRN _&&Procedure&&@&&StdCallBytes:NEAR
  648. ELSE
  649. EXTRN Procedure:NEAR
  650. ENDIF
  651. ENDIF
  652. ENDM
  653. tableproc MACRO
  654. IFNB <fastcall>
  655. dd OFFSET32 @&&Procedure&&@&&StdCallBytes
  656. ELSE
  657. IFNB <StdCallBytes>
  658. dd OFFSET32 _&&Procedure&&@&&StdCallBytes
  659. ELSE
  660. dd OFFSET32 Procedure
  661. ENDIF
  662. ENDIF
  663. ENDM
  664. IFNB <Condition>
  665. $$&&Procedure MACRO extern
  666. IFDEF &Condition
  667. IFNB <extern>
  668. extrnproc
  669. ELSE
  670. tableproc
  671. ENDIF
  672. ELSE
  673. IFB <extern>
  674. dd 0
  675. ENDIF
  676. ENDIF
  677. ENDM
  678. ENDIF
  679. IFDIFI <Procedure>, <RESERVED>
  680. PUBLIC _&&Procedure
  681. IF1
  682. _&&Procedure LABEL DWORD
  683. IFNB <fastcall>
  684. PUBLIC __&&Procedure
  685. __&&Procedure LABEL DWORD
  686. ENDIF
  687. ENDIF
  688. IFDIFI <Local_Seg>, <LOCAL>
  689. IFNB <Local_Seg>
  690. Local_Seg&&_SEG
  691. ELSE
  692. Def_Segment&_CODE_SEG
  693. ENDIF
  694. IFNB <Condition>
  695. $$&&Procedure extern
  696. ELSE
  697. extrnproc
  698. ENDIF
  699. IFNB <Local_Seg>
  700. Local_Seg&&_ENDS
  701. ELSE
  702. Def_Segment&_CODE_ENDS
  703. ENDIF
  704. ENDIF
  705. IFNB <Condition>
  706. $$&&Procedure
  707. ELSE
  708. tableproc
  709. ENDIF
  710. IFDEF Device_Name&_Name_Based
  711. @@&&Procedure = (Device_Name&_Internal_ID SHL 16) + Num_&Device_Name&_Services
  712. ELSE
  713. @@&&Procedure = (Device_Name&_Device_ID SHL 16) + Num_&Device_Name&_Services
  714. ENDIF
  715. ELSE
  716. dd 0
  717. ENDIF
  718. Num_&Device_Name&_Services = Num_&Device_Name&_Services + 1
  719. IFNB <Condition>
  720. Purge $$&&Procedure
  721. ENDIF
  722. Purge extrnproc
  723. Purge tableproc
  724. ENDM
  725. Device_Name&_StdCall_Service MACRO Procedure, Args, Local_Seg, Condition
  726. Device_Name&_Service Procedure, Local_Seg, Condition, %Args*4
  727. ??_standardccall&&_Procedure = Args
  728. ENDM
  729. Device_Name&_FastCall_Service MACRO Procedure, Args, Local_Seg, Condition
  730. Device_Name&_Service Procedure, Local_Seg, Condition, %Args*4, TRUE
  731. ??_fastcall&&_Procedure = Args
  732. ENDM
  733. ELSE
  734. ; Local_Seg and Condition are placeholders only in this form
  735. IFDEF Device_Name&_Name_Based
  736. Device_Name&_Service MACRO Procedure, Local_Seg, Condition
  737. IFDIFI <Procedure>, <RESERVED>
  738. @@&&Procedure = (Device_Name&_Internal_ID SHL 16) + Num_&Device_Name&_Services
  739. ENDIF
  740. Num_&Device_Name&_Services = Num_&Device_Name&_Services + 1
  741. ENDM
  742. ELSE
  743. Device_Name&_Service MACRO Procedure, Local_Seg, Condition
  744. IFDIFI <Procedure>, <RESERVED>
  745. @@&&Procedure = (Device_Name&_Device_ID SHL 16) + Num_&Device_Name&_Services
  746. ENDIF
  747. Num_&Device_Name&_Services = Num_&Device_Name&_Services + 1
  748. ENDM
  749. ENDIF
  750. Device_Name&_StdCall_Service MACRO Procedure, Args, Local_Seg, Condition
  751. Device_Name&_Service Procedure, Local_Seg, Condition
  752. ??_standardccall_&&Procedure = Args
  753. ENDM
  754. Device_Name&_FastCall_Service MACRO Procedure, Args, Local_Seg, Condition
  755. Device_Name&_Service Procedure, Local_Seg, Condition
  756. ??_fastcall_&&Procedure = Args
  757. ENDM
  758. ENDIF
  759. ENDM
  760. ;------------------------------------------------------------------------------
  761. End_Service_Table MACRO Device_Name, Def_Segment
  762. PURGE Device_Name&_Service
  763. IFDEF Create_&Device_Name&_Service_Table
  764. IFB <Def_Segment>
  765. VxD_LOCKED_DATA_ENDS
  766. ELSE
  767. Def_Segment&_LOCKED_DATA_ENDS
  768. ENDIF
  769. ENDIF
  770. ENDM
  771. GetVxDServiceOrdinal macro reg,service
  772. mov reg,@@&service
  773. endm
  774. GetVxDServiceAddress macro reg,service
  775. mov reg,OFFSET32 service
  776. endm
  777. ;*** Begin_Win32_Services - begin defining Win32 Service Table
  778. ;
  779. ; This macro is used to begin the definition of the Win32
  780. ; Service table. It is modelled after, but not identical
  781. ; to, the Begin_Service_Table macro. If the the special
  782. ; symbol Create_Win32_Services is defined to be true, then
  783. ; the actual table is emitted. Otherwise, only the service
  784. ; numbers are defined.
  785. ;
  786. ; ENTRY VxDName - the name of the VxD; it is assumed
  787. ; that a corresponding Device_ID is
  788. ; also defined.
  789. ; EXIT The macro VxDName&_Win32_Sevice is defined; it
  790. ; accepts a service name as its only parameter.
  791. ; This macro is then used to define each service.
  792. Begin_Win32_Services MACRO VxDName
  793. ifndef Create_Win32_Services
  794. Create_Win32_Services = 0
  795. endif
  796. .errb <VxDName>, <VxD name missing>
  797. ??w32svcno = 0
  798. if Create_Win32_Services
  799. VxDName&_Win32_Services label dword
  800. dd csvc&VxDName, 0
  801. endif
  802. ??inw32svc = 1
  803. VxDName&_Win32_Service MACRO Name
  804. .erre ??inw32svc, <Missing Begin_Win32_Services>
  805. if Create_Win32_Services
  806. dd OFFSET32 Name,cparm&&Name
  807. endif
  808. @32&&Name equ ((VxDName&_Device_ID SHL 16) + ??w32svcno)
  809. ??w32svcno = ??w32svcno + 1
  810. ENDM
  811. ENDM
  812. ;*** End_Win32_Services - mark end of Win32 Service Table
  813. ;
  814. ; This macro completes initialization of the Win32
  815. ; Service table.
  816. ;
  817. ; ENTRY VxDName - the same name passed to
  818. ; Begin_Win32_services
  819. End_Win32_Services MACRO VxDName
  820. .errb <VxDName>, <VxD name misssing>
  821. if Create_Win32_Services
  822. csvc&VxDName equ ($ - VxDName&_Win32_Services)/8 - 1
  823. endif
  824. ??inw32svc = 0
  825. PURGE VxDName&_Win32_Service
  826. ENDM
  827. ;*** Declare_Win32_Service - declare an external Win32 Service
  828. ;
  829. ; This macro is used to declare a Win32 service that
  830. ; is defined elsewhere, perhaps in a C module.
  831. ;
  832. ; ENTRY Name - the service name
  833. ; cParms - the number of DWORD parameters
  834. ; EXIT The name is defined as external
  835. Declare_Win32_Service MACRO Name, cParms
  836. ifndef Create_Win32_Services
  837. Create_Win32_Services = 0
  838. endif
  839. if Create_Win32_Services
  840. ?merge <Name>,,,,<EQU>,<_>,<Name>,<@>,%(cParms*4 + 8)
  841. ?merge <cparm>,<Name>,,,<EQU>,<cParms>
  842. VxD_CODE_SEG
  843. ?merge <EXTRN>,,,,,<_>,<Name>,<@>,%(cParms*4 + 8),<:NEAR>
  844. VxD_CODE_ENDS
  845. endif
  846. ENDM
  847. ;*** Win32call - call a Win32 service from a ring 3 thunk
  848. ;
  849. ; This macro is used to call a Win32 service from
  850. ; a ring 3 thunk. Note that control will not return
  851. ; to the instruction following the call, but to the
  852. ; instruction following the call to the thunk.
  853. ;
  854. ; ENTRY Service - the name of the service
  855. ; CallBack - the fword containing the callback
  856. Win32call MACRO Service, CallBack
  857. ifndef Create_Win32_Services
  858. Create_Win32_Services = 0
  859. endif
  860. ife Create_Win32_Services
  861. mov eax,@32&Service
  862. ifdef IS_16
  863. movzx esp,sp
  864. endif
  865. call fword ptr [CallBack]
  866. ifdef DEBUG
  867. int 3
  868. endif
  869. endif
  870. ENDM
  871. */
  872. /*XLATOFF*/
  873. #define GetVxDServiceAddress(service) service
  874. #define VxDCall(service) \
  875. _asm _emit 0xcd \
  876. _asm _emit 0x20 \
  877. _asm _emit (GetVxDServiceOrdinal(service) & 0xff) \
  878. _asm _emit (GetVxDServiceOrdinal(service) >> 8) & 0xff \
  879. _asm _emit (GetVxDServiceOrdinal(service) >> 16) & 0xff \
  880. _asm _emit (GetVxDServiceOrdinal(service) >> 24) & 0xff \
  881. #define VMMCall VxDCall
  882. #define VxDJmp(service) \
  883. _asm _emit 0xcd \
  884. _asm _emit 0x20 \
  885. _asm _emit (GetVxDServiceOrdinal(service) & 0xff) \
  886. _asm _emit ((GetVxDServiceOrdinal(service) >> 8) & 0xff) | 0x80 \
  887. _asm _emit (GetVxDServiceOrdinal(service) >> 16) & 0xff \
  888. _asm _emit (GetVxDServiceOrdinal(service) >> 24) & 0xff \
  889. #define VMMJmp VxDJmp
  890. #define SERVICE __cdecl
  891. #define ASYNC_SERVICE __cdecl
  892. #define WIN32_SERVICE void __stdcall
  893. #ifndef FASTCALL
  894. #define FASTCALL __fastcall
  895. #endif
  896. /*XLATON*/
  897. /* ASM
  898. ;******************************************************************************
  899. ;
  900. ; Dword_Align -- Aligns code to dword boundry by inserting nops
  901. ;
  902. ;------------------------------------------------------------------------------
  903. Dword_Align MACRO Seg_Name
  904. LOCAL segn
  905. IFDEF MASM6
  906. align 4
  907. ELSE
  908. IFNB <Seg_Name>
  909. segn equ Seg_Name
  910. ELSE
  911. IFE ?_LCODE
  912. segn equ <_LTEXT>
  913. ELSE
  914. IFE ?_ICODE
  915. segn equ <_ITEXT>
  916. ELSE
  917. IFE ?_PCODE
  918. segn equ <_PTEXT>
  919. ELSE
  920. IFE ?_SCODE
  921. segn equ <_STEXT>
  922. ELSE
  923. .err <Dword_Align not supported>
  924. ENDIF
  925. ENDIF
  926. ENDIF
  927. ENDIF
  928. ENDIF
  929. IF (($-OFFSET segn:0) MOD 4)
  930. db 4 - (($-OFFSET segn:0) MOD 4) DUP (90h)
  931. ENDIF
  932. ENDIF
  933. ENDM
  934. BeginDoc
  935. ;******************************************************************************
  936. ;
  937. ; Fatal_Error
  938. ;
  939. ; DESCRIPTION:
  940. ; This macro is used to crash Windows/386 when an unrecoverable error
  941. ; is detected. If Msg_Ptr is ommitted then no error message will be
  942. ; displayed, otherwise Msg_Ptr is the address
  943. ; when the
  944. ;
  945. ; PARAMETERS:
  946. ; Msg_Ptr (OPTIONAL) - Points to an ASCIIZ string to display.
  947. ;
  948. ; EXIT:
  949. ; To DOS (hopefully). This macro never returns.
  950. ;
  951. ;==============================================================================
  952. EndDoc
  953. Fatal_Error MACRO Msg_Ptr, Exit_Flags
  954. pushad
  955. IFB <Msg_Ptr>
  956. xor esi, esi
  957. ELSE
  958. mov esi, Msg_Ptr
  959. IFB <Exit_Flags>
  960. xor eax, eax
  961. ELSE
  962. mov eax, Exit_Flags
  963. ENDIF
  964. ENDIF
  965. VMMCall Fatal_Error_Handler
  966. ENDM
  967. EF_Hang_On_Exit EQU 1h
  968. */
  969. /******************************************************************************
  970. *
  971. * The following are control block headers and flags of interest to VxDs.
  972. *
  973. *****************************************************************************/
  974. struct cb_s {
  975. ULONG CB_VM_Status; /* VM status flags */
  976. ULONG CB_High_Linear; /* Address of VM mapped high */
  977. ULONG CB_Client_Pointer;
  978. ULONG CB_VMID;
  979. ULONG CB_Signature;
  980. };
  981. #define VMCB_ID 0x62634D56 /* VMcb */
  982. /*
  983. * VM status indicates globally interesting VM states
  984. */
  985. #define VMSTAT_EXCLUSIVE_BIT 0x00 /* VM is exclusive mode */
  986. #define VMSTAT_EXCLUSIVE (1L << VMSTAT_EXCLUSIVE_BIT)
  987. #define VMSTAT_BACKGROUND_BIT 0x01 /* VM runs in background */
  988. #define VMSTAT_BACKGROUND (1L << VMSTAT_BACKGROUND_BIT)
  989. #define VMSTAT_CREATING_BIT 0x02 /* In process of creating */
  990. #define VMSTAT_CREATING (1L << VMSTAT_CREATING_BIT)
  991. #define VMSTAT_SUSPENDED_BIT 0x03 /* VM not scheduled */
  992. #define VMSTAT_SUSPENDED (1L << VMSTAT_SUSPENDED_BIT)
  993. #define VMSTAT_NOT_EXECUTEABLE_BIT 0x04 /* VM partially destroyed */
  994. #define VMSTAT_NOT_EXECUTEABLE (1L << VMSTAT_NOT_EXECUTEABLE_BIT)
  995. #define VMSTAT_PM_EXEC_BIT 0x05 /* Currently in PM app */
  996. #define VMSTAT_PM_EXEC (1L << VMSTAT_PM_EXEC_BIT)
  997. #define VMSTAT_PM_APP_BIT 0x06 /* PM app present in VM */
  998. #define VMSTAT_PM_APP (1L << VMSTAT_PM_APP_BIT)
  999. #define VMSTAT_PM_USE32_BIT 0x07 /* PM app is 32-bit */
  1000. #define VMSTAT_PM_USE32 (1L << VMSTAT_PM_USE32_BIT)
  1001. #define VMSTAT_VXD_EXEC_BIT 0x08 /* Call from VxD */
  1002. #define VMSTAT_VXD_EXEC (1L << VMSTAT_VXD_EXEC_BIT)
  1003. #define VMSTAT_HIGH_PRI_BACK_BIT 0x09 /* High pri background */
  1004. #define VMSTAT_HIGH_PRI_BACK (1L << VMSTAT_HIGH_PRI_BACK_BIT)
  1005. #define VMSTAT_BLOCKED_BIT 0x0A /* Blocked on semaphore */
  1006. #define VMSTAT_BLOCKED (1L << VMSTAT_BLOCKED_BIT)
  1007. #define VMSTAT_AWAKENING_BIT 0x0B /* Woke up after blocked */
  1008. #define VMSTAT_AWAKENING (1L << VMSTAT_AWAKENING_BIT)
  1009. #define VMSTAT_PAGEABLEV86BIT 0x0C /* part of V86 is pageable (PM app) */
  1010. #define VMSTAT_PAGEABLEV86_BIT VMSTAT_PAGEABLEV86BIT
  1011. #define VMSTAT_PAGEABLEV86 (1L << VMSTAT_PAGEABLEV86BIT)
  1012. #define VMSTAT_V86INTSLOCKEDBIT 0x0D /* Locked regardless of pager type */
  1013. #define VMSTAT_V86INTSLOCKED_BIT VMSTAT_V86INTSLOCKEDBIT
  1014. #define VMSTAT_V86INTSLOCKED (1L << VMSTAT_V86INTSLOCKEDBIT)
  1015. #define VMSTAT_IDLE_TIMEOUT_BIT 0x0E /* Scheduled by time-slicer */
  1016. #define VMSTAT_IDLE_TIMEOUT (1L << VMSTAT_IDLE_TIMEOUT_BIT)
  1017. #define VMSTAT_IDLE_BIT 0x0F /* VM has released time slice */
  1018. #define VMSTAT_IDLE (1L << VMSTAT_IDLE_BIT)
  1019. #define VMSTAT_CLOSING_BIT 0x10 /* Close_VM called for VM */
  1020. #define VMSTAT_CLOSING (1L << VMSTAT_CLOSING_BIT)
  1021. #define VMSTAT_TS_SUSPENDED_BIT 0x11 /* VM suspended by */
  1022. #define VMSTAT_TS_SUSPENDED (1L << VMSTAT_TS_SUSPENDED_BIT)
  1023. #define VMSTAT_TS_MAXPRI_BIT 0x12 /* this is fgd_pri 10,000 internally*/
  1024. #define VMSTAT_TS_MAXPRI (1L << VMSTAT_TS_MAXPRI_BIT)
  1025. #define VMSTAT_USE32_MASK (VMSTAT_PM_USE32 | VMSTAT_VXD_EXEC)
  1026. struct tcb_s {
  1027. ULONG TCB_Flags; /* Thread status flags */
  1028. ULONG TCB_Reserved1; /* Used internally by VMM */
  1029. ULONG TCB_Reserved2; /* Used internally by VMM */
  1030. ULONG TCB_Signature;
  1031. ULONG TCB_ClientPtr; /* Client registers of thread */
  1032. ULONG TCB_VMHandle; /* VM that thread is part of */
  1033. USHORT TCB_ThreadId; /* Unique Thread ID */
  1034. USHORT TCB_PMLockOrigSS; /* Original SS:ESP before lock stack */
  1035. ULONG TCB_PMLockOrigESP;
  1036. ULONG TCB_PMLockOrigEIP; /* Original CS:EIP before lock stack */
  1037. ULONG TCB_PMLockStackCount;
  1038. USHORT TCB_PMLockOrigCS;
  1039. USHORT TCB_PMPSPSelector;
  1040. ULONG TCB_ThreadType; /* dword passed to VMMCreateThread */
  1041. USHORT TCB_pad1; /* reusable; for dword align */
  1042. UCHAR TCB_pad2; /* reusable; for dword align */
  1043. UCHAR TCB_extErrLocus; /* extended error Locus */
  1044. USHORT TCB_extErr; /* extended error Code */
  1045. UCHAR TCB_extErrAction; /* " " Action */
  1046. UCHAR TCB_extErrClass; /* " " Class */
  1047. ULONG TCB_extErrPtr; /* " pointer */
  1048. };
  1049. typedef struct tcb_s TCB;
  1050. typedef TCB *PTCB;
  1051. #define SCHED_OBJ_ID_THREAD 0x42434854 // THCB in ASCII
  1052. /*
  1053. * Thread status indicates globally interesting thread states.
  1054. * Flags are for information only and must not be modified.
  1055. */
  1056. #define THFLAG_SUSPENDED_BIT 0x03 // Thread not scheduled
  1057. #define THFLAG_SUSPENDED (1L << THFLAG_SUSPENDED_BIT)
  1058. #define THFLAG_NOT_EXECUTEABLE_BIT 0x04 // Thread partially destroyed
  1059. #define THFLAG_NOT_EXECUTEABLE (1L << THFLAG_NOT_EXECUTEABLE_BIT)
  1060. #define THFLAG_THREAD_CREATION_BIT 0x08 // Thread in status nascendi
  1061. #define THFLAG_THREAD_CREATION (1L << THFLAG_THREAD_CREATION_BIT)
  1062. #define THFLAG_THREAD_BLOCKED_BIT 0x0A // Blocked on semaphore
  1063. #define THFLAG_THREAD_BLOCKED (1L << THFLAG_THREAD_BLOCKED_BIT)
  1064. #define THFLAG_RING0_THREAD_BIT 0x1C // thread runs only at ring 0
  1065. #define THFLAG_RING0_THREAD (1L << THFLAG_RING0_THREAD_BIT)
  1066. #define THFLAG_ASYNC_THREAD_BIT 0x1F // thread is asynchronous
  1067. #define THFLAG_ASYNC_THREAD (1L << THFLAG_ASYNC_THREAD_BIT)
  1068. #define THFLAG_CHARSET_BITS 0x10 // Default character set
  1069. #define THFLAG_CHARSET_MASK (3L << THFLAG_CHARSET_BITS)
  1070. #define THFLAG_ANSI (0L << THFLAG_CHARSET_BITS)
  1071. #define THFLAG_OEM (1L << THFLAG_CHARSET_BITS)
  1072. #define THFLAG_UNICODE (2L << THFLAG_CHARSET_BITS)
  1073. #define THFLAG_RESERVED (3L << THFLAG_CHARSET_BITS)
  1074. #define THFLAG_EXTENDED_HANDLES_BIT 0x12 // Thread uses extended file handles
  1075. #define THFLAG_EXTENDED_HANDLES (1L << THFLAG_EXTENDED_HANDLES_BIT)
  1076. /* the win32 loader opens win32 exes with this bit set to notify IFS
  1077. * so a defragger won't move these files
  1078. * the bit is turned off once the open completes.
  1079. * file open flags are overloaded which is why this is here
  1080. */
  1081. #define THFLAG_OPEN_AS_IMMOVABLE_FILE_BIT 0x13 // File thus opened not moved
  1082. #define THFLAG_OPEN_AS_IMMOVABLE_FILE (1L << THFLAG_OPEN_AS_IMMOVABLE_FILE_BIT)
  1083. /*
  1084. * Protected mode application control blocks
  1085. */
  1086. struct pmcb_s {
  1087. ULONG PMCB_Flags;
  1088. ULONG PMCB_Parent;
  1089. };
  1090. /*
  1091. * The reference data for fault error codes 1-5 (GSDVME_PRIVINST through
  1092. * GSDVME_INVALFLT) is a pointer to the following fault information structure.
  1093. */
  1094. struct VMFaultInfo {
  1095. ULONG VMFI_EIP; // faulting EIP
  1096. WORD VMFI_CS; // faulting CS
  1097. WORD VMFI_Ints; // interrupts in service, if any
  1098. };
  1099. typedef struct VMFaultInfo *PVMFaultInfo;
  1100. /******************************************************************************
  1101. * V M M S E R V I C E S
  1102. ******************************************************************************/
  1103. /*XLATOFF*/
  1104. #define VMM_Service Declare_Service
  1105. #define VMM_StdCall_Service Declare_SCService
  1106. #define VMM_FastCall_Service Declare_SCService
  1107. #pragma warning (disable:4003) // turn off not enough params warning
  1108. /*XLATON*/
  1109. /*MACROS*/
  1110. Begin_Service_Table(VMM, VMM)
  1111. VMM_Service (Get_VMM_Version, LOCAL) // MUST REMAIN SERVICE 0!
  1112. VMM_Service (Get_Cur_VM_Handle)
  1113. VMM_Service (Test_Cur_VM_Handle)
  1114. VMM_Service (Get_Sys_VM_Handle)
  1115. VMM_Service (Test_Sys_VM_Handle)
  1116. VMM_Service (Validate_VM_Handle)
  1117. VMM_Service (Get_VMM_Reenter_Count)
  1118. VMM_Service (Begin_Reentrant_Execution)
  1119. VMM_Service (End_Reentrant_Execution)
  1120. VMM_Service (Install_V86_Break_Point)
  1121. VMM_Service (Remove_V86_Break_Point)
  1122. VMM_Service (Allocate_V86_Call_Back)
  1123. VMM_Service (Allocate_PM_Call_Back)
  1124. VMM_Service (Call_When_VM_Returns)
  1125. VMM_Service (Schedule_Global_Event)
  1126. VMM_Service (Schedule_VM_Event)
  1127. VMM_Service (Call_Global_Event)
  1128. VMM_Service (Call_VM_Event)
  1129. VMM_Service (Cancel_Global_Event)
  1130. VMM_Service (Cancel_VM_Event)
  1131. VMM_Service (Call_Priority_VM_Event)
  1132. VMM_Service (Cancel_Priority_VM_Event)
  1133. VMM_Service (Get_NMI_Handler_Addr)
  1134. VMM_Service (Set_NMI_Handler_Addr)
  1135. VMM_Service (Hook_NMI_Event)
  1136. VMM_Service (Call_When_VM_Ints_Enabled)
  1137. VMM_Service (Enable_VM_Ints)
  1138. VMM_Service (Disable_VM_Ints)
  1139. VMM_Service (Map_Flat)
  1140. VMM_Service (Map_Lin_To_VM_Addr)
  1141. // Scheduler services
  1142. VMM_Service (Adjust_Exec_Priority)
  1143. VMM_Service (Begin_Critical_Section)
  1144. VMM_Service (End_Critical_Section)
  1145. VMM_Service (End_Crit_And_Suspend)
  1146. VMM_Service (Claim_Critical_Section)
  1147. VMM_Service (Release_Critical_Section)
  1148. VMM_Service (Call_When_Not_Critical)
  1149. VMM_Service (Create_Semaphore)
  1150. VMM_Service (Destroy_Semaphore)
  1151. VMM_Service (Wait_Semaphore)
  1152. VMM_Service (Signal_Semaphore)
  1153. VMM_Service (Get_Crit_Section_Status)
  1154. VMM_Service (Call_When_Task_Switched)
  1155. VMM_Service (Suspend_VM)
  1156. VMM_Service (Resume_VM)
  1157. VMM_Service (No_Fail_Resume_VM)
  1158. VMM_Service (Nuke_VM)
  1159. VMM_Service (Crash_Cur_VM)
  1160. VMM_Service (Get_Execution_Focus)
  1161. VMM_Service (Set_Execution_Focus)
  1162. VMM_Service (Get_Time_Slice_Priority)
  1163. VMM_Service (Set_Time_Slice_Priority)
  1164. VMM_Service (Get_Time_Slice_Granularity)
  1165. VMM_Service (Set_Time_Slice_Granularity)
  1166. VMM_Service (Get_Time_Slice_Info)
  1167. VMM_Service (Adjust_Execution_Time)
  1168. VMM_Service (Release_Time_Slice)
  1169. VMM_Service (Wake_Up_VM)
  1170. VMM_Service (Call_When_Idle)
  1171. VMM_Service (Get_Next_VM_Handle)
  1172. // Time-out and system timer services
  1173. VMM_Service (Set_Global_Time_Out)
  1174. VMM_Service (Set_VM_Time_Out)
  1175. VMM_Service (Cancel_Time_Out)
  1176. VMM_Service (Get_System_Time)
  1177. VMM_Service (Get_VM_Exec_Time)
  1178. VMM_Service (Hook_V86_Int_Chain)
  1179. VMM_Service (Get_V86_Int_Vector)
  1180. VMM_Service (Set_V86_Int_Vector)
  1181. VMM_Service (Get_PM_Int_Vector)
  1182. VMM_Service (Set_PM_Int_Vector)
  1183. VMM_Service (Simulate_Int)
  1184. VMM_Service (Simulate_Iret)
  1185. VMM_Service (Simulate_Far_Call)
  1186. VMM_Service (Simulate_Far_Jmp)
  1187. VMM_Service (Simulate_Far_Ret)
  1188. VMM_Service (Simulate_Far_Ret_N)
  1189. VMM_Service (Build_Int_Stack_Frame)
  1190. VMM_Service (Simulate_Push)
  1191. VMM_Service (Simulate_Pop)
  1192. // Heap Manager
  1193. VMM_Service (_HeapAllocate)
  1194. VMM_Service (_HeapReAllocate)
  1195. VMM_Service (_HeapFree)
  1196. VMM_Service (_HeapGetSize)
  1197. /*ENDMACROS*/
  1198. /****************************************************
  1199. *
  1200. * Flags for heap allocator calls
  1201. *
  1202. * NOTE: HIGH 8 BITS (bits 24-31) are reserved
  1203. *
  1204. ***************************************************/
  1205. //
  1206. // Flags affecting the returned block
  1207. //
  1208. #define HEAPZEROINIT 0x00000001
  1209. #define HEAPZEROREINIT 0x00000002
  1210. #define HEAPNOCOPY 0x00000004
  1211. //
  1212. // Alignment flags
  1213. //
  1214. #define HEAPALIGN_SHIFT 16
  1215. #define HEAPALIGN_MASK 0x000F0000
  1216. #define HEAPALIGN_4 0x00000000 // dword aligned
  1217. #define HEAPALIGN_8 0x00000000 // quadword aligned
  1218. #define HEAPALIGN_16 0x00000000 // paragraph aligned
  1219. #define HEAPALIGN_32 0x00010000 // etc.
  1220. #define HEAPALIGN_64 0x00020000
  1221. #define HEAPALIGN_128 0x00030000
  1222. #define HEAPALIGN_256 0x00040000
  1223. #define HEAPALIGN_512 0x00050000
  1224. #define HEAPALIGN_1K 0x00060000
  1225. #define HEAPALIGN_2K 0x00070000
  1226. #define HEAPALIGN_4K 0x00080000
  1227. #define HEAPALIGN_8K 0x00090000
  1228. #define HEAPALIGN_16K 0x000A0000
  1229. #define HEAPALIGN_32K 0x000B0000
  1230. #define HEAPALIGN_64K 0x000C0000
  1231. #define HEAPALIGN_128K 0x000D0000
  1232. //
  1233. // Flags indicating which system heap to use. There are four bits reserved
  1234. // to identify the heap to use. Four are currently defined by the system.
  1235. //
  1236. #define HEAPTYPESHIFT 8
  1237. #define HEAPTYPEMASK 0x00000700
  1238. #define HEAPLOCKEDHIGH 0x00000000
  1239. #define HEAPLOCKEDIFDP 0x00000100
  1240. #define HEAPSWAP 0x00000200
  1241. #define HEAPLOCKEDLOW 0x00000300
  1242. #define HEAPINIT 0x00000400 // will be automatically freed after
  1243. // init complete
  1244. #define HEAPSYSVM 0x00000500
  1245. //
  1246. // other flags
  1247. //
  1248. #define HEAPCLEAN 0x00000800
  1249. #define HEAPCONTIG 0x00001000 // memory must be physically contiguous
  1250. #define HEAPFORGET 0x00002000 // this memory will never be freed
  1251. // Page Manager
  1252. /*MACROS*/
  1253. VMM_Service (_PageAllocate)
  1254. VMM_Service (_PageReAllocate)
  1255. VMM_Service (_PageFree)
  1256. VMM_Service (_PageLock)
  1257. VMM_Service (_PageUnLock)
  1258. VMM_Service (_PageGetSizeAddr)
  1259. VMM_Service (_PageGetAllocInfo)
  1260. VMM_Service (_GetFreePageCount)
  1261. VMM_Service (_GetSysPageCount)
  1262. VMM_Service (_GetVMPgCount)
  1263. VMM_Service (_MapIntoV86)
  1264. VMM_Service (_PhysIntoV86)
  1265. VMM_Service (_TestGlobalV86Mem)
  1266. VMM_Service (_ModifyPageBits)
  1267. VMM_Service (_CopyPageTable)
  1268. VMM_Service (_LinMapIntoV86)
  1269. VMM_Service (_LinPageLock)
  1270. VMM_Service (_LinPageUnLock)
  1271. VMM_Service (_SetResetV86Pageable)
  1272. VMM_Service (_GetV86PageableArray)
  1273. VMM_Service (_PageCheckLinRange)
  1274. VMM_Service (_PageOutDirtyPages)
  1275. VMM_Service (_PageDiscardPages)
  1276. /*ENDMACROS*/
  1277. /****************************************************
  1278. *
  1279. * Flags for other page allocator calls
  1280. *
  1281. * NOTE: HIGH 8 BITS (bits 24-31) are reserved
  1282. *
  1283. ***************************************************/
  1284. #define PAGEZEROINIT 0x00000001
  1285. #define PAGEUSEALIGN 0x00000002
  1286. #define PAGECONTIG 0x00000004
  1287. #define PAGEFIXED 0x00000008
  1288. #define PAGEDEBUGNULFAULT 0x00000010
  1289. #define PAGEZEROREINIT 0x00000020
  1290. #define PAGENOCOPY 0x00000040
  1291. #define PAGELOCKED 0x00000080
  1292. #define PAGELOCKEDIFDP 0x00000100
  1293. #define PAGESETV86PAGEABLE 0x00000200
  1294. #define PAGECLEARV86PAGEABLE 0x00000400
  1295. #define PAGESETV86INTSLOCKED 0x00000800
  1296. #define PAGECLEARV86INTSLOCKED 0x00001000
  1297. #define PAGEMARKPAGEOUT 0x00002000
  1298. #define PAGEPDPSETBASE 0x00004000
  1299. #define PAGEPDPCLEARBASE 0x00008000
  1300. #define PAGEDISCARD 0x00010000
  1301. #define PAGEPDPQUERYDIRTY 0x00020000
  1302. #define PAGEMAPFREEPHYSREG 0x00040000
  1303. #define PAGEPHYSONLY 0x04000000
  1304. //efine PAGEDONTUSE 0x08000000 // ;Internal
  1305. #define PAGENOMOVE 0x10000000
  1306. #define PAGEMAPGLOBAL 0x40000000
  1307. #define PAGEMARKDIRTY 0x80000000
  1308. /****************************************************
  1309. *
  1310. * Flags for _PhysIntoV86,
  1311. * _MapIntoV86, and _LinMapIntoV86
  1312. *
  1313. ***************************************************/
  1314. #define MAPV86_IGNOREWRAP 0x00000001
  1315. // Informational services
  1316. /*MACROS*/
  1317. VMM_Service (_GetNulPageHandle)
  1318. VMM_Service (_GetFirstV86Page)
  1319. VMM_Service (_MapPhysToLinear)
  1320. VMM_Service (_GetAppFlatDSAlias)
  1321. VMM_Service (_SelectorMapFlat)
  1322. VMM_Service (_GetDemandPageInfo)
  1323. VMM_Service (_GetSetPageOutCount)
  1324. /*ENDMACROS*/
  1325. /*
  1326. * Flags bits for _GetSetPageOutCount
  1327. */
  1328. #define GSPOC_F_GET 0x00000001
  1329. // Device VM page manager
  1330. /*MACROS*/
  1331. VMM_Service (Hook_V86_Page)
  1332. VMM_Service (_Assign_Device_V86_Pages)
  1333. VMM_Service (_DeAssign_Device_V86_Pages)
  1334. VMM_Service (_Get_Device_V86_Pages_Array)
  1335. VMM_Service (MMGR_SetNULPageAddr)
  1336. // GDT/LDT management
  1337. VMM_Service (_Allocate_GDT_Selector)
  1338. VMM_Service (_Free_GDT_Selector)
  1339. VMM_Service (_Allocate_LDT_Selector)
  1340. VMM_Service (_Free_LDT_Selector)
  1341. VMM_Service (_BuildDescriptorDWORDs)
  1342. VMM_Service (_GetDescriptor)
  1343. VMM_Service (_SetDescriptor)
  1344. /*ENDMACROS*/
  1345. /*
  1346. * Flag equates for _BuildDescriptorDWORDs
  1347. */
  1348. #define BDDEXPLICITDPL 0x00000001
  1349. /*
  1350. * Flag equates for _Allocate_LDT_Selector
  1351. */
  1352. #define ALDTSPECSEL 0x00000001
  1353. /*MACROS*/
  1354. VMM_Service (_MMGR_Toggle_HMA)
  1355. /*ENDMACROS*/
  1356. /*
  1357. * Flag equates for _MMGR_Toggle_HMA
  1358. */
  1359. #define MMGRHMAPHYSICAL 0x00000001
  1360. #define MMGRHMAENABLE 0x00000002
  1361. #define MMGRHMADISABLE 0x00000004
  1362. #define MMGRHMAQUERY 0x00000008
  1363. /*MACROS*/
  1364. VMM_Service (Get_Fault_Hook_Addrs)
  1365. VMM_Service (Hook_V86_Fault)
  1366. VMM_Service (Hook_PM_Fault)
  1367. VMM_Service (Hook_VMM_Fault)
  1368. VMM_Service (Begin_Nest_V86_Exec)
  1369. VMM_Service (Begin_Nest_Exec)
  1370. VMM_Service (Exec_Int)
  1371. VMM_Service (Resume_Exec)
  1372. VMM_Service (End_Nest_Exec)
  1373. VMM_Service (Allocate_PM_App_CB_Area, VMM_ICODE)
  1374. VMM_Service (Get_Cur_PM_App_CB)
  1375. VMM_Service (Set_V86_Exec_Mode)
  1376. VMM_Service (Set_PM_Exec_Mode)
  1377. VMM_Service (Begin_Use_Locked_PM_Stack)
  1378. VMM_Service (End_Use_Locked_PM_Stack)
  1379. VMM_Service (Save_Client_State)
  1380. VMM_Service (Restore_Client_State)
  1381. VMM_Service (Exec_VxD_Int)
  1382. VMM_Service (Hook_Device_Service)
  1383. VMM_Service (Hook_Device_V86_API)
  1384. VMM_Service (Hook_Device_PM_API)
  1385. VMM_Service (System_Control)
  1386. // I/O and software interrupt hooks
  1387. VMM_Service (Simulate_IO)
  1388. VMM_Service (Install_Mult_IO_Handlers)
  1389. VMM_Service (Install_IO_Handler)
  1390. VMM_Service (Enable_Global_Trapping)
  1391. VMM_Service (Enable_Local_Trapping)
  1392. VMM_Service (Disable_Global_Trapping)
  1393. VMM_Service (Disable_Local_Trapping)
  1394. // Linked List Abstract Data Type Services
  1395. VMM_Service (List_Create)
  1396. VMM_Service (List_Destroy)
  1397. VMM_Service (List_Allocate)
  1398. VMM_Service (List_Attach)
  1399. VMM_Service (List_Attach_Tail)
  1400. VMM_Service (List_Insert)
  1401. VMM_Service (List_Remove)
  1402. VMM_Service (List_Deallocate)
  1403. VMM_Service (List_Get_First)
  1404. VMM_Service (List_Get_Next)
  1405. VMM_Service (List_Remove_First)
  1406. /*ENDMACROS*/
  1407. /*
  1408. * Flags used by List_Create
  1409. */
  1410. #define LF_ASYNC_BIT 0
  1411. #define LF_ASYNC (1 << LF_ASYNC_BIT)
  1412. #define LF_USE_HEAP_BIT 1
  1413. #define LF_USE_HEAP (1 << LF_USE_HEAP_BIT)
  1414. #define LF_ALLOC_ERROR_BIT 2
  1415. #define LF_ALLOC_ERROR (1 << LF_ALLOC_ERROR_BIT)
  1416. /*
  1417. * Swappable lists must use the heap.
  1418. */
  1419. #define LF_SWAP (LF_USE_HEAP + (1 << 3))
  1420. /******************************************************************************
  1421. * I N I T I A L I Z A T I O N P R O C E D U R E S
  1422. ******************************************************************************/
  1423. // Instance data manager
  1424. /*MACROS*/
  1425. VMM_Service (_AddInstanceItem)
  1426. // System structure data manager
  1427. VMM_Service (_Allocate_Device_CB_Area)
  1428. VMM_Service (_Allocate_Global_V86_Data_Area, VMM_ICODE)
  1429. VMM_Service (_Allocate_Temp_V86_Data_Area, VMM_ICODE)
  1430. VMM_Service (_Free_Temp_V86_Data_Area, VMM_ICODE)
  1431. /*ENDMACROS*/
  1432. /*
  1433. * Flag bits for _Allocate_Global_V86_Data_Area
  1434. */
  1435. #define GVDAWordAlign 0x00000001
  1436. #define GVDADWordAlign 0x00000002
  1437. #define GVDAParaAlign 0x00000004
  1438. #define GVDAPageAlign 0x00000008
  1439. #define GVDAInstance 0x00000100
  1440. #define GVDAZeroInit 0x00000200
  1441. #define GVDAReclaim 0x00000400
  1442. #define GVDAInquire 0x00000800
  1443. #define GVDAHighSysCritOK 0x00001000
  1444. #define GVDAOptInstance 0x00002000
  1445. #define GVDAForceLow 0x00004000
  1446. /*
  1447. * Flag bits for _Allocate_Temp_V86_Data_Area
  1448. */
  1449. #define TVDANeedTilInitComplete 0x00000001
  1450. // Initialization information calls (win.ini and environment parameters)
  1451. /*MACROS*/
  1452. VMM_Service (Get_Profile_Decimal_Int, VMM_ICODE)
  1453. VMM_Service (Convert_Decimal_String, VMM_ICODE)
  1454. VMM_Service (Get_Profile_Fixed_Point, VMM_ICODE)
  1455. VMM_Service (Convert_Fixed_Point_String, VMM_ICODE)
  1456. VMM_Service (Get_Profile_Hex_Int, VMM_ICODE)
  1457. VMM_Service (Convert_Hex_String, VMM_ICODE)
  1458. VMM_Service (Get_Profile_Boolean, VMM_ICODE)
  1459. VMM_Service (Convert_Boolean_String, VMM_ICODE)
  1460. VMM_Service (Get_Profile_String, VMM_ICODE)
  1461. VMM_Service (Get_Next_Profile_String, VMM_ICODE)
  1462. VMM_Service (Get_Environment_String, VMM_ICODE)
  1463. VMM_Service (Get_Exec_Path, VMM_ICODE)
  1464. VMM_Service (Get_Config_Directory, VMM_ICODE)
  1465. VMM_Service (OpenFile, VMM_ICODE)
  1466. /*ENDMACROS*/
  1467. // OpenFile, if called after init, must point EDI to a buffer of at least
  1468. // this size.
  1469. #define VMM_OPENFILE_BUF_SIZE 260
  1470. /*MACROS*/
  1471. VMM_Service (Get_PSP_Segment, VMM_ICODE)
  1472. VMM_Service (GetDOSVectors, VMM_ICODE)
  1473. VMM_Service (Get_Machine_Info)
  1474. /*ENDMACROS*/
  1475. #define GMIF_80486_BIT 0x10
  1476. #define GMIF_80486 (1 << GMIF_80486_BIT)
  1477. #define GMIF_PCXT_BIT 0x11
  1478. #define GMIF_PCXT (1 << GMIF_PCXT_BIT)
  1479. #define GMIF_MCA_BIT 0x12
  1480. #define GMIF_MCA (1 << GMIF_MCA_BIT)
  1481. #define GMIF_EISA_BIT 0x13
  1482. #define GMIF_EISA (1 << GMIF_EISA_BIT)
  1483. #define GMIF_CPUID_BIT 0x14
  1484. #define GMIF_CPUID (1 << GMIF_CPUID_BIT)
  1485. // Following service is not restricted to initialization
  1486. /*MACROS*/
  1487. VMM_Service (GetSet_HMA_Info)
  1488. VMM_Service (Set_System_Exit_Code)
  1489. VMM_Service (Fatal_Error_Handler)
  1490. VMM_Service (Fatal_Memory_Error)
  1491. // Called by VTD only
  1492. VMM_Service (Update_System_Clock)
  1493. /******************************************************************************
  1494. * D E B U G G I N G E X T E R N S
  1495. ******************************************************************************/
  1496. VMM_Service (Test_Debug_Installed) // Valid call in retail also
  1497. VMM_Service (Out_Debug_String)
  1498. VMM_Service (Out_Debug_Chr)
  1499. VMM_Service (In_Debug_Chr)
  1500. VMM_Service (Debug_Convert_Hex_Binary)
  1501. VMM_Service (Debug_Convert_Hex_Decimal)
  1502. VMM_Service (Debug_Test_Valid_Handle)
  1503. VMM_Service (Validate_Client_Ptr)
  1504. VMM_Service (Test_Reenter)
  1505. VMM_Service (Queue_Debug_String)
  1506. VMM_Service (Log_Proc_Call)
  1507. VMM_Service (Debug_Test_Cur_VM)
  1508. VMM_Service (Get_PM_Int_Type)
  1509. VMM_Service (Set_PM_Int_Type)
  1510. VMM_Service (Get_Last_Updated_System_Time)
  1511. VMM_Service (Get_Last_Updated_VM_Exec_Time)
  1512. VMM_Service (Test_DBCS_Lead_Byte) // for DBCS Enabling
  1513. /*ENDMACROS*/
  1514. /* ASM
  1515. .errnz @@Test_DBCS_Lead_Byte - 100D1h ; VMM service table changed above this service
  1516. */
  1517. /*************************************************************************
  1518. *************************************************************************
  1519. * END OF 3.00 SERVICE TABLE MUST NOT SHUFFLE SERVICES BEFORE THIS POINT
  1520. * FOR COMPATIBILITY.
  1521. *************************************************************************
  1522. *************************************************************************/
  1523. /*MACROS*/
  1524. VMM_Service (_AddFreePhysPage, VMM_ICODE)
  1525. VMM_Service (_PageResetHandlePAddr)
  1526. VMM_Service (_SetLastV86Page, VMM_ICODE)
  1527. VMM_Service (_GetLastV86Page)
  1528. VMM_Service (_MapFreePhysReg)
  1529. VMM_Service (_UnmapFreePhysReg)
  1530. VMM_Service (_XchgFreePhysReg)
  1531. VMM_Service (_SetFreePhysRegCalBk, VMM_ICODE)
  1532. VMM_Service (Get_Next_Arena, VMM_ICODE)
  1533. VMM_Service (Get_Name_Of_Ugly_TSR, VMM_ICODE)
  1534. VMM_Service (Get_Debug_Options, VMM_ICODE)
  1535. /*ENDMACROS*/
  1536. /*
  1537. * Flags for AddFreePhysPage
  1538. */
  1539. #define AFPP_SWAPOUT 0x0001 // physical memory that must be swapped out
  1540. // and subsequently restored at system exit
  1541. /*
  1542. * Flags for PageChangePager
  1543. */
  1544. #define PCP_CHANGEPAGER 0x1 // change the pager for the page range
  1545. #define PCP_CHANGEPAGERDATA 0x2 // change the pager data dword for the pages
  1546. #define PCP_VIRGINONLY 0x4 // make the above changes to virgin pages only
  1547. /*
  1548. * Bits for the ECX return of Get_Next_Arena
  1549. */
  1550. #define GNA_HIDOSLINKED 0x0002 // High DOS arenas linked when WIN386 started
  1551. #define GNA_ISHIGHDOS 0x0004 // High DOS arenas do exist
  1552. /*MACROS*/
  1553. VMM_Service (Set_Physical_HMA_Alias, VMM_ICODE)
  1554. VMM_Service (_GetGlblRng0V86IntBase, VMM_ICODE)
  1555. VMM_Service (_Add_Global_V86_Data_Area, VMM_ICODE)
  1556. VMM_Service (GetSetDetailedVMError)
  1557. /*ENDMACROS*/
  1558. /*
  1559. * Error code values for the GetSetDetailedVMError service. PLEASE NOTE
  1560. * that all of these error code values need to have bits set in the high
  1561. * word. This is to prevent collisions with other VMDOSAPP standard errors.
  1562. * Also, the low word must be non-zero.
  1563. *
  1564. * First set of errors (high word = 0001) are intended to be used
  1565. * when a VM is CRASHED (VNE_Crashed or VNE_Nuked bit set on
  1566. * VM_Not_Executeable).
  1567. *
  1568. * PLEASE NOTE that each of these errors (high word == 0001) actually
  1569. * has two forms:
  1570. *
  1571. * 0001xxxxh
  1572. * 8001xxxxh
  1573. *
  1574. * The device which sets the error initially always sets the error with
  1575. * the high bit CLEAR. The system will then optionally set the high bit
  1576. * depending on the result of the attempt to "nicely" crash the VM. This
  1577. * bit allows the system to tell the user whether the crash is likely or
  1578. * unlikely to destabalize the system.
  1579. */
  1580. #define GSDVME_PRIVINST 0x00010001 /* Privledged instruction */
  1581. #define GSDVME_INVALINST 0x00010002 /* Invalid instruction */
  1582. #define GSDVME_INVALPGFLT 0x00010003 /* Invalid page fault */
  1583. #define GSDVME_INVALGPFLT 0x00010004 /* Invalid GP fault */
  1584. #define GSDVME_INVALFLT 0x00010005 /* Unspecified invalid fault */
  1585. #define GSDVME_USERNUKE 0x00010006 /* User requested NUKE of VM */
  1586. #define GSDVME_DEVNUKE 0x00010007 /* Device specific problem */
  1587. #define GSDVME_DEVNUKEHDWR 0x00010008 /* Device specific problem:
  1588. * invalid hardware fiddling
  1589. * by VM (invalid I/O)
  1590. */
  1591. #define GSDVME_NUKENOMSG 0x00010009 /* Supress standard messages:
  1592. * SHELL_Message used for
  1593. * custom msg.
  1594. */
  1595. #define GSDVME_OKNUKEMASK 0x80000000 /* "Nice nuke" bit */
  1596. /*
  1597. * Second set of errors (high word = 0002) are intended to be used
  1598. * when a VM start up is failed (VNE_CreateFail, VNE_CrInitFail, or
  1599. * VNE_InitFail bit set on VM_Not_Executeable).
  1600. */
  1601. #define GSDVME_INSMEMV86 0x00020001 /* base V86 mem - V86MMGR */
  1602. #define GSDVME_INSV86SPACE 0x00020002 /* Kb Req too large - V86MMGR */
  1603. #define GSDVME_INSMEMXMS 0x00020003 /* XMS Kb Req - V86MMGR */
  1604. #define GSDVME_INSMEMEMS 0x00020004 /* EMS Kb Req - V86MMGR */
  1605. #define GSDVME_INSMEMV86HI 0x00020005 /* Hi DOS V86 mem - DOSMGR
  1606. * V86MMGR
  1607. */
  1608. #define GSDVME_INSMEMVID 0x00020006 /* Base Video mem - VDD */
  1609. #define GSDVME_INSMEMVM 0x00020007 /* Base VM mem - VMM
  1610. * CB, Inst Buffer
  1611. */
  1612. #define GSDVME_INSMEMDEV 0x00020008 /* Couldn't alloc base VM
  1613. * memory for device.
  1614. */
  1615. #define GSDVME_CRTNOMSG 0x00020009 /* Supress standard messages:
  1616. * SHELL_Message used for
  1617. * custom msg.
  1618. */
  1619. /*MACROS*/
  1620. VMM_Service (Is_Debug_Chr)
  1621. // Mono_Out services
  1622. VMM_Service (Clear_Mono_Screen)
  1623. VMM_Service (Out_Mono_Chr)
  1624. VMM_Service (Out_Mono_String)
  1625. VMM_Service (Set_Mono_Cur_Pos)
  1626. VMM_Service (Get_Mono_Cur_Pos)
  1627. VMM_Service (Get_Mono_Chr)
  1628. // Service locates a byte in ROM
  1629. VMM_Service (Locate_Byte_In_ROM, VMM_ICODE)
  1630. VMM_Service (Hook_Invalid_Page_Fault)
  1631. VMM_Service (Unhook_Invalid_Page_Fault)
  1632. /*ENDMACROS*/
  1633. /*
  1634. * Flag bits of IPF_Flags
  1635. */
  1636. #define IPF_PGDIR 0x00000001 /* Page directory entry not-present */
  1637. #define IPF_V86PG 0x00000002 /* Unexpected not present Page in V86 */
  1638. #define IPF_V86PGH 0x00000004 /* Like IPF_V86PG at high linear */
  1639. #define IPF_INVTYP 0x00000008 /* page has invalid not present type */
  1640. #define IPF_PGERR 0x00000010 /* pageswap device failure */
  1641. #define IPF_REFLT 0x00000020 /* re-entrant page fault */
  1642. #define IPF_VMM 0x00000040 /* Page fault caused by a VxD */
  1643. #define IPF_PM 0x00000080 /* Page fault by VM in Prot Mode */
  1644. #define IPF_V86 0x00000100 /* Page fault by VM in V86 Mode */
  1645. /*MACROS*/
  1646. VMM_Service (Set_Delete_On_Exit_File)
  1647. VMM_Service (Close_VM)
  1648. /*ENDMACROS*/
  1649. /*
  1650. * Flags for Close_VM service
  1651. */
  1652. #define CVF_CONTINUE_EXEC_BIT 0
  1653. #define CVF_CONTINUE_EXEC (1 << CVF_CONTINUE_EXEC_BIT)
  1654. /*MACROS*/
  1655. VMM_Service (Enable_Touch_1st_Meg) // Debugging only
  1656. VMM_Service (Disable_Touch_1st_Meg) // Debugging only
  1657. VMM_Service (Install_Exception_Handler)
  1658. VMM_Service (Remove_Exception_Handler)
  1659. VMM_Service (Get_Crit_Status_No_Block)
  1660. /*ENDMACROS*/
  1661. /* ASM
  1662. ; Check if VMM service table has changed above this service
  1663. .errnz @@Get_Crit_Status_No_Block - 100F1h
  1664. */
  1665. #ifdef WIN40SERVICES
  1666. /*************************************************************************
  1667. *************************************************************************
  1668. *
  1669. * END OF 3.10 SERVICE TABLE MUST NOT SHUFFLE SERVICES BEFORE THIS POINT
  1670. * FOR COMPATIBILITY.
  1671. *************************************************************************
  1672. *************************************************************************/
  1673. /*MACROS*/
  1674. VMM_Service (_GetLastUpdatedThreadExecTime)
  1675. VMM_Service (_Trace_Out_Service)
  1676. VMM_Service (_Debug_Out_Service)
  1677. VMM_Service (_Debug_Flags_Service)
  1678. /*ENDMACROS*/
  1679. #endif /* WIN40SERVICES */
  1680. /*
  1681. * Flags for _Debug_Flags_Service service.
  1682. *
  1683. * Don't change these unless you really really know what you're doing.
  1684. * We need to define these even if we are in WIN31COMPAT mode.
  1685. */
  1686. #define DFS_LOG_BIT 0
  1687. #define DFS_LOG (1 << DFS_LOG_BIT)
  1688. #define DFS_PROFILE_BIT 1
  1689. #define DFS_PROFILE (1 << DFS_PROFILE_BIT)
  1690. #define DFS_TEST_CLD_BIT 2
  1691. #define DFS_TEST_CLD (1 << DFS_TEST_CLD_BIT)
  1692. #define DFS_NEVER_REENTER_BIT 3
  1693. #define DFS_NEVER_REENTER (1 << DFS_NEVER_REENTER_BIT)
  1694. #define DFS_TEST_REENTER_BIT 4
  1695. #define DFS_TEST_REENTER (1 << DFS_TEST_REENTER_BIT)
  1696. #define DFS_NOT_SWAPPING_BIT 5
  1697. #define DFS_NOT_SWAPPING (1 << DFS_NOT_SWAPPING_BIT)
  1698. #define DFS_TEST_BLOCK_BIT 6
  1699. #define DFS_TEST_BLOCK (1 << DFS_TEST_BLOCK_BIT)
  1700. #define DFS_RARE_SERVICES 0xFFFFFF80
  1701. #define DFS_EXIT_NOBLOCK (DFS_RARE_SERVICES+0)
  1702. #define DFS_ENTER_NOBLOCK (DFS_RARE_SERVICES+DFS_TEST_BLOCK)
  1703. #define DFS_TEST_NEST_EXEC (DFS_RARE_SERVICES+1)
  1704. #ifdef WIN40SERVICES
  1705. /*MACROS*/
  1706. VMM_Service (VMMAddImportModuleName)
  1707. VMM_Service (VMM_Add_DDB)
  1708. VMM_Service (VMM_Remove_DDB)
  1709. VMM_Service (Test_VM_Ints_Enabled)
  1710. VMM_Service (_BlockOnID)
  1711. VMM_Service (Schedule_Thread_Event)
  1712. VMM_Service (Cancel_Thread_Event)
  1713. VMM_Service (Set_Thread_Time_Out)
  1714. VMM_Service (Set_Async_Time_Out)
  1715. VMM_Service (_AllocateThreadDataSlot)
  1716. VMM_Service (_FreeThreadDataSlot)
  1717. /*ENDMACROS*/
  1718. /*
  1719. * Flag equates for _CreateMutex
  1720. */
  1721. #define MUTEX_MUST_COMPLETE 1L
  1722. #define MUTEX_NO_CLEANUP_THREAD_STATE 2L
  1723. /*MACROS*/
  1724. VMM_Service (_CreateMutex)
  1725. VMM_Service (_DestroyMutex)
  1726. VMM_Service (_GetMutexOwner)
  1727. VMM_Service (Call_When_Thread_Switched)
  1728. VMM_Service (VMMCreateThread)
  1729. VMM_Service (_GetThreadExecTime)
  1730. VMM_Service (VMMTerminateThread)
  1731. VMM_Service (Get_Cur_Thread_Handle)
  1732. VMM_Service (Test_Cur_Thread_Handle)
  1733. VMM_Service (Get_Sys_Thread_Handle)
  1734. VMM_Service (Test_Sys_Thread_Handle)
  1735. VMM_Service (Validate_Thread_Handle)
  1736. VMM_Service (Get_Initial_Thread_Handle)
  1737. VMM_Service (Test_Initial_Thread_Handle)
  1738. VMM_Service (Debug_Test_Valid_Thread_Handle)
  1739. VMM_Service (Debug_Test_Cur_Thread)
  1740. VMM_Service (VMM_GetSystemInitState)
  1741. VMM_Service (Cancel_Call_When_Thread_Switched)
  1742. VMM_Service (Get_Next_Thread_Handle)
  1743. VMM_Service (Adjust_Thread_Exec_Priority)
  1744. VMM_Service (_Deallocate_Device_CB_Area)
  1745. VMM_Service (Remove_IO_Handler)
  1746. VMM_Service (Remove_Mult_IO_Handlers)
  1747. VMM_Service (Unhook_V86_Int_Chain)
  1748. VMM_Service (Unhook_V86_Fault)
  1749. VMM_Service (Unhook_PM_Fault)
  1750. VMM_Service (Unhook_VMM_Fault)
  1751. VMM_Service (Unhook_Device_Service)
  1752. VMM_Service (_PageReserve)
  1753. VMM_Service (_PageCommit)
  1754. VMM_Service (_PageDecommit)
  1755. VMM_Service (_PagerRegister)
  1756. VMM_Service (_PagerQuery)
  1757. VMM_Service (_PagerDeregister)
  1758. VMM_Service (_ContextCreate)
  1759. VMM_Service (_ContextDestroy)
  1760. VMM_Service (_PageAttach)
  1761. VMM_Service (_PageFlush)
  1762. VMM_Service (_SignalID)
  1763. VMM_Service (_PageCommitPhys)
  1764. VMM_Service (_Register_Win32_Services)
  1765. VMM_Service (Cancel_Call_When_Not_Critical)
  1766. VMM_Service (Cancel_Call_When_Idle)
  1767. VMM_Service (Cancel_Call_When_Task_Switched)
  1768. VMM_Service (_Debug_Printf_Service)
  1769. VMM_Service (_EnterMutex)
  1770. VMM_Service (_LeaveMutex)
  1771. VMM_Service (Simulate_VM_IO)
  1772. VMM_Service (Signal_Semaphore_No_Switch)
  1773. VMM_Service (_ContextSwitch)
  1774. VMM_Service (_PageModifyPermissions)
  1775. VMM_Service (_PageQuery)
  1776. VMM_Service (_EnterMustComplete)
  1777. VMM_Service (_LeaveMustComplete)
  1778. VMM_Service (_ResumeExecMustComplete)
  1779. /*ENDMACROS*/
  1780. /*
  1781. * Flag equates for _GetThreadTerminationStatus
  1782. */
  1783. #define THREAD_TERM_STATUS_CRASH_PEND 1L
  1784. #define THREAD_TERM_STATUS_NUKE_PEND 2L
  1785. #define THREAD_TERM_STATUS_SUSPEND_PEND 4L
  1786. /*MACROS*/
  1787. VMM_Service (_GetThreadTerminationStatus)
  1788. VMM_Service (_GetInstanceInfo)
  1789. /*ENDMACROS*/
  1790. /*
  1791. * Return values for _GetInstanceInfo
  1792. */
  1793. #define INSTINFO_NONE 0 /* no data instanced in range */
  1794. #define INSTINFO_SOME 1 /* some data instanced in range */
  1795. #define INSTINFO_ALL 2 /* all data instanced in range */
  1796. /*MACROS*/
  1797. VMM_Service (_ExecIntMustComplete)
  1798. VMM_Service (_ExecVxDIntMustComplete)
  1799. VMM_Service (Begin_V86_Serialization)
  1800. VMM_Service (Unhook_V86_Page)
  1801. VMM_Service (VMM_GetVxDLocationList)
  1802. VMM_Service (VMM_GetDDBList)
  1803. VMM_Service (Unhook_NMI_Event)
  1804. VMM_Service (Get_Instanced_V86_Int_Vector)
  1805. VMM_Service (Get_Set_Real_DOS_PSP)
  1806. /*ENDMACROS*/
  1807. #define GSRDP_Set 0x0001
  1808. /*MACROS*/
  1809. VMM_Service (Call_Priority_Thread_Event)
  1810. VMM_Service (Get_System_Time_Address)
  1811. VMM_Service (Get_Crit_Status_Thread)
  1812. VMM_Service (Get_DDB)
  1813. VMM_Service (Directed_Sys_Control)
  1814. /*ENDMACROS*/
  1815. // Registry APIs for VxDs
  1816. /*MACROS*/
  1817. VMM_Service (_RegOpenKey)
  1818. VMM_Service (_RegCloseKey)
  1819. VMM_Service (_RegCreateKey)
  1820. VMM_Service (_RegDeleteKey)
  1821. VMM_Service (_RegEnumKey)
  1822. VMM_Service (_RegQueryValue)
  1823. VMM_Service (_RegSetValue)
  1824. VMM_Service (_RegDeleteValue)
  1825. VMM_Service (_RegEnumValue)
  1826. VMM_Service (_RegQueryValueEx)
  1827. VMM_Service (_RegSetValueEx)
  1828. /*ENDMACROS*/
  1829. #ifndef REG_SZ // define only if not there already
  1830. #define REG_SZ 0x0001
  1831. #define REG_BINARY 0x0003
  1832. #endif
  1833. #ifndef HKEY_LOCAL_MACHINE // define only if not there already
  1834. #define HKEY_CLASSES_ROOT 0x80000000
  1835. #define HKEY_CURRENT_USER 0x80000001
  1836. #define HKEY_LOCAL_MACHINE 0x80000002
  1837. #define HKEY_USERS 0x80000003
  1838. #define HKEY_PERFORMANCE_DATA 0x80000004
  1839. #define HKEY_CURRENT_CONFIG 0x80000005
  1840. #define HKEY_DYN_DATA 0x80000006
  1841. #endif
  1842. /*MACROS*/
  1843. VMM_Service (_CallRing3)
  1844. VMM_Service (Exec_PM_Int)
  1845. VMM_Service (_RegFlushKey)
  1846. VMM_Service (_PageCommitContig)
  1847. VMM_Service (_GetCurrentContext)
  1848. VMM_Service (_LocalizeSprintf)
  1849. VMM_Service (_LocalizeStackSprintf)
  1850. VMM_Service (Call_Restricted_Event)
  1851. VMM_Service (Cancel_Restricted_Event)
  1852. VMM_Service (Register_PEF_Provider, VMM_ICODE)
  1853. VMM_Service (_GetPhysPageInfo)
  1854. VMM_Service (_RegQueryInfoKey)
  1855. VMM_Service (MemArb_Reserve_Pages)
  1856. /*ENDMACROS*/
  1857. /*
  1858. * Return values for _GetPhysPageInfo
  1859. */
  1860. #define PHYSINFO_NONE 0 /* no pages in the specified range exist */
  1861. #define PHYSINFO_SOME 1 /* some pages in the specified range exist */
  1862. #define PHYSINFO_ALL 2 /* all pages in the specified range exist */
  1863. // New timeslicer services
  1864. /*MACROS*/
  1865. VMM_Service (Time_Slice_Sys_VM_Idle)
  1866. VMM_Service (Time_Slice_Sleep)
  1867. VMM_Service (Boost_With_Decay)
  1868. VMM_Service (Set_Inversion_Pri)
  1869. VMM_Service (Reset_Inversion_Pri)
  1870. VMM_Service (Release_Inversion_Pri)
  1871. VMM_Service (Get_Thread_Win32_Pri)
  1872. VMM_Service (Set_Thread_Win32_Pri)
  1873. VMM_Service (Set_Thread_Static_Boost)
  1874. VMM_Service (Set_VM_Static_Boost)
  1875. VMM_Service (Release_Inversion_Pri_ID)
  1876. VMM_Service (Attach_Thread_To_Group)
  1877. VMM_Service (Detach_Thread_From_Group)
  1878. VMM_Service (Set_Group_Static_Boost)
  1879. VMM_Service (_GetRegistryPath, VMM_ICODE)
  1880. VMM_Service (_GetRegistryKey)
  1881. /*ENDMACROS*/
  1882. // TYPE definitions for _GetRegistryKey
  1883. #define REGTYPE_ENUM 0
  1884. #define REGTYPE_CLASS 1
  1885. #define REGTYPE_VXD 2
  1886. // Flag definitions for _GetRegistryKey
  1887. #define REGKEY_OPEN 0
  1888. #define REGKEY_CREATE_IFNOTEXIST 1
  1889. // Flag definitions for _Assert_Range
  1890. #define ASSERT_RANGE_NULL_BAD 0x00000000
  1891. #define ASSERT_RANGE_NULL_OK 0x00000001
  1892. #define ASSERT_RANGE_IS_ASCIIZ 0x00000002
  1893. #define ASSERT_RANGE_IS_NOT_ASCIIZ 0x00000000
  1894. #define ASSERT_RANGE_NO_DEBUG 0x80000000
  1895. #define ASSERT_RANGE_BITS 0x80000003
  1896. /*MACROS*/
  1897. VMM_Service (Cleanup_Thread_State)
  1898. VMM_Service (_RegRemapPreDefKey)
  1899. VMM_Service (End_V86_Serialization)
  1900. VMM_Service (_Assert_Range)
  1901. VMM_Service (_Sprintf)
  1902. VMM_Service (_PageChangePager)
  1903. VMM_Service (_RegCreateDynKey)
  1904. VMM_Service (_RegQueryMultipleValues)
  1905. // Additional timeslicer services
  1906. VMM_Service (Boost_Thread_With_VM)
  1907. /*ENDMACROS*/
  1908. // Flag definitions for Get_Boot_Flags
  1909. #define BOOT_CLEAN 0x00000001
  1910. #define BOOT_DOSCLEAN 0x00000002
  1911. #define BOOT_NETCLEAN 0x00000004
  1912. #define BOOT_INTERACTIVE 0x00000008
  1913. /*MACROS*/
  1914. VMM_Service (Get_Boot_Flags)
  1915. VMM_Service (Set_Boot_Flags)
  1916. // String and memory services
  1917. VMM_Service (_lstrcpyn)
  1918. VMM_Service (_lstrlen)
  1919. VMM_Service (_lmemcpy)
  1920. VMM_Service (_GetVxDName)
  1921. // For vwin32 use only
  1922. VMM_Service (Force_Mutexes_Free)
  1923. VMM_Service (Restore_Forced_Mutexes)
  1924. /*ENDMACROS*/
  1925. // Reclaimable low memory services
  1926. /*MACROS*/
  1927. VMM_Service (_AddReclaimableItem)
  1928. VMM_Service (_SetReclaimableItem)
  1929. VMM_Service (_EnumReclaimableItem)
  1930. /*ENDMACROS*/
  1931. // completely wake sys VM from idle state
  1932. /*MACROS*/
  1933. VMM_Service (Time_Slice_Wake_Sys_VM)
  1934. VMM_Service (VMM_Replace_Global_Environment)
  1935. VMM_Service (Begin_Non_Serial_Nest_V86_Exec)
  1936. VMM_Service (Get_Nest_Exec_Status)
  1937. /*ENDMACROS*/
  1938. // Bootlogging services
  1939. /*MACROS*/
  1940. VMM_Service (Open_Boot_Log)
  1941. VMM_Service (Write_Boot_Log)
  1942. VMM_Service (Close_Boot_Log)
  1943. VMM_Service (EnableDisable_Boot_Log)
  1944. VMM_Service (_Call_On_My_Stack)
  1945. /*ENDMACROS*/
  1946. // Another instance data service
  1947. /*MACROS*/
  1948. VMM_Service (Get_Inst_V86_Int_Vec_Base)
  1949. /*ENDMACROS*/
  1950. // Case insensitive functions -- SEE WARNINGS IN DOCS BEFORE USING!
  1951. /*MACROS*/
  1952. VMM_Service (_lstrcmpi)
  1953. VMM_Service (_strupr)
  1954. /*ENDMACROS*/
  1955. /*MACROS*/
  1956. VMM_Service (Log_Fault_Call_Out)
  1957. VMM_Service (_AtEventTime)
  1958. /*ENDMACROS*/
  1959. #endif /* WIN40SERVICES */
  1960. #ifdef WIN403SERVICES
  1961. //
  1962. // 4.03 Services
  1963. //
  1964. /*MACROS*/
  1965. VMM_Service (_PageOutPages)
  1966. /*ENDMACROS*/
  1967. // Flag definitions for _PageOutPages
  1968. #define PAGEOUT_PRIVATE 0x00000001
  1969. #define PAGEOUT_SHARED 0x00000002
  1970. #define PAGEOUT_SYSTEM 0x00000004
  1971. #define PAGEOUT_REGION 0x00000008
  1972. #define PAGEOUT_ALL (PAGEOUT_PRIVATE | PAGEOUT_SHARED | PAGEOUT_SYSTEM)
  1973. /*MACROS*/
  1974. VMM_Service (_Call_On_My_Not_Flat_Stack)
  1975. VMM_Service (_LinRegionLock)
  1976. VMM_Service (_LinRegionUnLock)
  1977. VMM_Service (_AttemptingSomethingDangerous)
  1978. VMM_Service (_Vsprintf)
  1979. VMM_Service (_Vsprintfw)
  1980. VMM_Service (Load_FS_Service)
  1981. VMM_Service (Assert_FS_Service)
  1982. VMM_StdCall_Service (RtlUnwind, 4)
  1983. VMM_StdCall_Service (RtlRaiseException, 1)
  1984. VMM_StdCall_Service (RtlRaiseStatus, 1)
  1985. VMM_StdCall_Service (KeGetCurrentIrql, 0)
  1986. VMM_FastCall_Service (KfRaiseIrql, 1)
  1987. VMM_FastCall_Service (KfLowerIrql, 1)
  1988. VMM_Service (_Begin_Preemptable_Code)
  1989. VMM_Service (_End_Preemptable_Code)
  1990. VMM_FastCall_Service (Set_Preemptable_Count, 1)
  1991. VMM_StdCall_Service (KeInitializeDpc, 3)
  1992. VMM_StdCall_Service (KeInsertQueueDpc, 3)
  1993. VMM_StdCall_Service (KeRemoveQueueDpc, 1)
  1994. VMM_StdCall_Service (HeapAllocateEx, 4)
  1995. VMM_StdCall_Service (HeapReAllocateEx, 5)
  1996. VMM_StdCall_Service (HeapGetSizeEx, 2)
  1997. VMM_StdCall_Service (HeapFreeEx, 2)
  1998. //VMM_Service (_Get_CPUID_Flags)
  1999. /*ENDMACROS*/
  2000. #endif /* WIN403SERVICES */
  2001. /*MACROS*/
  2002. End_Service_Table(VMM, VMM)
  2003. /*ENDMACROS*/
  2004. /*XLATOFF*/
  2005. #pragma warning (default:4003) // turn on not enough params warning
  2006. #ifndef try
  2007. #define try __try
  2008. #define except __except
  2009. #define finally __finally
  2010. #define leave __leave
  2011. #ifndef exception_code
  2012. #define exception_code __exception_code
  2013. #endif // exception_code
  2014. #endif // try
  2015. #ifndef EXCEPTION_EXECUTE_HANDLER
  2016. #define EXCEPTION_EXECUTE_HANDLER 1
  2017. #define EXCEPTION_CONTINUE_SEARCH 0
  2018. #define EXCEPTION_CONTINUE_EXECUTION -1
  2019. #endif
  2020. /*XLATON*/
  2021. #define COMNFS_FLAT 0xFFFFFFFF
  2022. #define ASD_MAX_REF_DATA 64 // If bigger than this, a checksum is used
  2023. struct _vmmguid {
  2024. unsigned long Data1;
  2025. unsigned short Data2;
  2026. unsigned short Data3;
  2027. unsigned char Data4[8];
  2028. };
  2029. typedef struct _vmmguid VMMGUID;
  2030. typedef VMMGUID *VMMREFIID;
  2031. typedef DWORD ASD_RESULT;
  2032. #define ASD_ERROR_NONE 0x00000000
  2033. #define ASD_CHECK_FAIL 0x00000001 // The flag is set that this failed before
  2034. #define ASD_CHECK_SUCCESS 0x00000002 // The flag is set that this succeeded before
  2035. #define ASD_CHECK_UNKNOWN 0x00000003 // No flag is set
  2036. #define ASD_ERROR_BAD_TIME 0x00000004 // Under cli
  2037. #define ASD_REGISTRY_ERROR 0x00000005 // Unknown registry error
  2038. #define ASD_CLEAN_BOOT 0x00000006 // Clean booting fails everything
  2039. #define ASD_OUT_OF_MEMORY 0x00000007 // Ran out of memory (extremely rare)
  2040. #define ASD_FILE_ERROR 0x00000008 // Int 21 to flush the info file failed
  2041. #define ASD_ALREADY_SET 0x00000009 // ASD_CHECK* done twice on same vgOperation/pRefData
  2042. #define ASD_MISSING_CHECK 0x0000000A // ASD_DONE* on something not set
  2043. #define ASD_BAD_PARAMETER 0x0000000B // Invalid operation, refiid or ref pointer
  2044. #define ASD_OP_CHECK_AND_WRITE_FAIL_IF_UNKNOWN 0x00000000
  2045. #define ASD_OP_CHECK_AND_ALWAYS_WRITE_FAIL 0x00000001
  2046. #define ASD_OP_CHECK 0x00000002
  2047. #define ASD_OP_DONE_AND_SET_SUCCESS 0x00000003
  2048. #define ASD_OP_SET_FAIL 0x00000004
  2049. #define ASD_OP_SET_SUCCESS 0x00000005
  2050. #define ASD_OP_SET_UNKNOWN 0x00000006
  2051. #define ASD_OP_DONE 0x00000007
  2052. // Flag definitions for _Add/_Set/_EnumReclaimableItem
  2053. #define RS_RECLAIM 0x00000001
  2054. #define RS_RESTORE 0x00000002
  2055. #define RS_DOSARENA 0x00000004
  2056. // Structure definition for _EnumReclaimableItem
  2057. struct ReclaimStruc {
  2058. ULONG RS_Linear; // low (< 1meg) address of item
  2059. ULONG RS_Bytes; // size of item in bytes
  2060. ULONG RS_CallBack; // callback, if any (zero if none)
  2061. ULONG RS_RefData; // reference data for callback, if any
  2062. ULONG RS_HookTable; // real-mode hook table (zero if none)
  2063. ULONG RS_Flags; // 0 or more of the RS_* equates
  2064. };
  2065. typedef struct ReclaimStruc *PReclaimStruc;
  2066. //
  2067. // Structures for Force_Mutexes_Free/Restore_Forced_Mutexes
  2068. //
  2069. typedef struct frmtx {
  2070. struct frmtx *frmtx_pfrmtxNext;
  2071. DWORD frmtx_hmutex;
  2072. DWORD frmtx_cEnterCount;
  2073. DWORD frmtx_pthcbOwner;
  2074. DWORD frmtx_htimeout;
  2075. } FRMTX;
  2076. typedef struct vmmfrinfo {
  2077. struct frmtx vmmfrinfo_frmtxDOS;
  2078. struct frmtx vmmfrinfo_frmtxV86;
  2079. struct frmtx vmmfrinfo_frmtxOther;
  2080. } VMMFRINFO;
  2081. /*
  2082. * Data structure for _GetDemandPageInfo
  2083. */
  2084. struct DemandInfoStruc {
  2085. ULONG DILin_Total_Count; /* # pages in linear address space */
  2086. ULONG DIPhys_Count; /* Count of phys pages */
  2087. ULONG DIFree_Count; /* Count of free phys pages */
  2088. ULONG DIUnlock_Count; /* Count of unlocked Phys Pages */
  2089. ULONG DILinear_Base_Addr; /* Base of pageable address space */
  2090. ULONG DILin_Total_Free; /* Total Count of free linear pages */
  2091. /*
  2092. * The following 5 fields are all running totals, kept from the time
  2093. * the system was started
  2094. */
  2095. ULONG DIPage_Faults; /* total page faults */
  2096. ULONG DIPage_Ins; /* calls to pagers to page in a page */
  2097. ULONG DIPage_Outs; /* calls to pagers to page out a page*/
  2098. ULONG DIPage_Discards; /* pages discarded w/o calling pager */
  2099. ULONG DIInstance_Faults; /* instance page faults */
  2100. ULONG DIPagingFileMax; /* maximum # of pages that could be in paging file */
  2101. ULONG DIPagingFileInUse; /* # of pages of paging file currently in use */
  2102. ULONG DICommit_Count; /* Total committed memory, in pages */
  2103. ULONG DIReserved[2]; /* Reserved for expansion */
  2104. };
  2105. /*
  2106. * Data structure for _AddInstanceItem
  2107. */
  2108. struct InstDataStruc {
  2109. ULONG InstLinkF; /* INIT <0> RESERVED */
  2110. ULONG InstLinkB; /* INIT <0> RESERVED */
  2111. ULONG InstLinAddr; /* Linear address of start of block */
  2112. ULONG InstSize; /* Size of block in bytes */
  2113. ULONG InstType; /* Type of block */
  2114. };
  2115. /*
  2116. * Values for InstType
  2117. */
  2118. #define INDOS_FIELD 0x100 /* Bit indicating INDOS switch requirements */
  2119. #define ALWAYS_FIELD 0x200 /* Bit indicating ALWAYS switch requirements */
  2120. #define OPTIONAL_FIELD 0x400 /* Bit indicating optional instancing requirements */
  2121. /*
  2122. * Data structure for Hook_Invalid_Page_Fault handlers.
  2123. *
  2124. * This is the structure of the "invalid page fault information"
  2125. * which is pointed to by EDI when Invalid page fault hookers
  2126. * are called.
  2127. *
  2128. * Page faults can occur on a VM which is not current by touching the VM at
  2129. * its high linear address. In this case, IPF_FaultingVM may not be the
  2130. * current VM, it will be set to the VM whos high linear address was touched.
  2131. */
  2132. struct IPF_Data {
  2133. ULONG IPF_LinAddr; /* CR2 address of fault */
  2134. ULONG IPF_MapPageNum; /* Possible converted page # of fault */
  2135. ULONG IPF_PTEEntry; /* Contents of PTE that faulted */
  2136. ULONG IPF_FaultingVM; /* May not = Current VM (IPF_V86PgH set) */
  2137. ULONG IPF_Flags; /* Flags */
  2138. };
  2139. /*
  2140. *
  2141. * Install_Exception_Handler data structure
  2142. *
  2143. */
  2144. struct Exception_Handler_Struc {
  2145. ULONG EH_Reserved;
  2146. ULONG EH_Start_EIP;
  2147. ULONG EH_End_EIP;
  2148. ULONG EH_Handler;
  2149. };
  2150. /*
  2151. * Flags passed in new memory manager functions
  2152. */
  2153. /* PageReserve arena values */
  2154. #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
  2155. #define PR_SHARED 0x80060000 /* anywhere in shared arena */
  2156. #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
  2157. /* PageReserve flags */
  2158. #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
  2159. #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
  2160. #define PR_STATIC 0x00000010 /* see PageReserve documentation */
  2161. /* PageCommit default pager handle values */
  2162. #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
  2163. #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
  2164. #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
  2165. #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
  2166. /* PageCommit flags */
  2167. #define PC_FIXED 0x00000008 /* pages are permanently locked */
  2168. #define PC_LOCKED 0x00000080 /* pages are made present and locked*/
  2169. #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
  2170. #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
  2171. #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
  2172. #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
  2173. #define PC_PRESENT 0x80000000 /* make pages initially present */
  2174. #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
  2175. #define PC_DIRTY 0x08000000 /* make pages initially dirty */
  2176. #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
  2177. #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
  2178. /* PageCommitContig additional flags */
  2179. #define PCC_ZEROINIT 0x00000001 /* zero-initialize new pages */
  2180. #define PCC_NOLIN 0x10000000 /* don't map to any linear address */
  2181. /*MTRR type flags */
  2182. #define MTRR_UC 0
  2183. #define MTRR_WC 1
  2184. #define MTRR_WT 4
  2185. #define MTRR_WP 5
  2186. #define MTRR_WB 6
  2187. /*
  2188. * Structure and flags for PageQuery
  2189. */
  2190. #ifndef _WINNT_
  2191. typedef struct _MEMORY_BASIC_INFORMATION {
  2192. ULONG mbi_BaseAddress;
  2193. ULONG mbi_AllocationBase;
  2194. ULONG mbi_AllocationProtect;
  2195. ULONG mbi_RegionSize;
  2196. ULONG mbi_State;
  2197. ULONG mbi_Protect;
  2198. ULONG mbi_Type;
  2199. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  2200. #define PAGE_NOACCESS 0x01
  2201. #define PAGE_READONLY 0x02
  2202. #define PAGE_READWRITE 0x04
  2203. #define MEM_COMMIT 0x1000
  2204. #define MEM_RESERVE 0x2000
  2205. #define MEM_FREE 0x10000
  2206. #define MEM_PRIVATE 0x20000
  2207. #endif
  2208. /***ET+ PD - Pager Descriptor
  2209. *
  2210. * A PD describes a set of routines to call to bring a page into
  2211. * the system or to get it out. Each committed page in the system
  2212. * has an associated PD, a handle to which is stored in the page's
  2213. * VP.
  2214. *
  2215. * For any field that is 0, the pager will not be notified
  2216. * when that action takes place.
  2217. *
  2218. * For the purpose of pagers, a page can be in one of the two states
  2219. * describing its current contents:
  2220. *
  2221. * clean - page has not been written to since its last page out
  2222. * dirty - page has been written to since its last page out
  2223. *
  2224. * A page also is in one of two persistent states:
  2225. *
  2226. * virgin - page has never been written to since it was committed
  2227. * tainted - page has been written to since it was committed
  2228. *
  2229. * Note that a tainted page may be either dirty or clean, but a
  2230. * virgin page is by definition clean.
  2231. *
  2232. * Examples of PDs:
  2233. *
  2234. * For 32-bit EXE code or read-only data:
  2235. *
  2236. * pd_virginin = routine to load page from an exe file
  2237. * pd_taintedin = 0
  2238. * pd_cleanout = 0
  2239. * pd_dirtyout = 0
  2240. * pd_virginfree = 0
  2241. * pd_taintedfree = 0
  2242. * pd_dirty = 0
  2243. * pd_type = PD_PAGERONLY
  2244. *
  2245. * For 32-bit EXE writeable data:
  2246. *
  2247. * pd_virginin = routine to load page from an exe file
  2248. * pd_taintedin = routine to load page from swap file
  2249. * pd_cleanout = 0
  2250. * pd_dirtyout = routine to write a page out to the swap file
  2251. * pd_virginfree = 0
  2252. * pd_taintedfree = routine to free page from the swap file
  2253. * pd_dirty = routine to free page from the swap file
  2254. * pd_type = PD_SWAPPER
  2255. *
  2256. * For zero-initialized swappable data:
  2257. *
  2258. * pd_virginin = routine to zero-fill a page
  2259. * pd_taintedin = routine to load page from swap file
  2260. * pd_cleanout = 0
  2261. * pd_dirtyout = routine to write a page out to the swap file
  2262. * pd_virginfree = 0
  2263. * pd_taintedfree = routine to free page from the swap file
  2264. * pd_dirty = routine to free page from the swap file
  2265. * pd_type = PD_SWAPPER
  2266. */
  2267. /* typedefs for various pager functions */
  2268. typedef ULONG _cdecl FUNPAGE(PULONG ppagerdata, PVOID ppage, ULONG faultpage);
  2269. typedef FUNPAGE * PFUNPAGE;
  2270. struct pd_s {
  2271. /*
  2272. * The following four fields are entry points in the pager which
  2273. * we call to page in or page out a page. The following parameters
  2274. * are passed to the pager during these calls:
  2275. *
  2276. * ppagerdata - pointer to the pager-specific dword of data
  2277. * stored with the virtual page. The pager is
  2278. * free to modify the contents of this dword
  2279. * DURING the page in or out, but not afterwards.
  2280. *
  2281. * ppage - pointer to page going in or out (a ring 0 alias
  2282. * to the physical page). The pager should use this
  2283. * address to access the contents of the page.
  2284. *
  2285. * faultpage - faulting linear page number for page-ins, -1 for
  2286. * page-outs. This address should not be accessed
  2287. * by the pager. It is provided for information
  2288. * only. Note that a single page can be mapped at
  2289. * more than one linear address because of the
  2290. * MapIntoV86 and LinMapIntoV86 services.
  2291. *
  2292. * The pager should return non-0 if the page was successfully
  2293. * paged, or 0 if it failed.
  2294. */
  2295. PFUNPAGE pd_virginin; /* in - while page has never been written to */
  2296. PFUNPAGE pd_taintedin; /* in - page written to at least once */
  2297. PFUNPAGE pd_cleanout; /* out - page not written to since last out */
  2298. PFUNPAGE pd_dirtyout; /* out - page was written to since last out */
  2299. /*
  2300. * The pd_*free routines are used to inform the pager when the last
  2301. * reference to a virtual page controlled by the pager is
  2302. * decommitted. A common use of this notification is to
  2303. * free space in a backing file, or write the page contents
  2304. * into the backing file.
  2305. *
  2306. * These calls take the same parameters as the page-out and -in
  2307. * functions, but no return value is recognized. The "ppage"
  2308. * and "faultpage" parameters will always be 0.
  2309. */
  2310. PFUNPAGE pd_virginfree; /* decommit of never-written-to page */
  2311. PFUNPAGE pd_taintedfree; /* decommit of page written to at least once*/
  2312. /*
  2313. * The pd_dirty routine is used to inform the pager when the
  2314. * memory manager detects that a page has been written to. The memory
  2315. * manager does not detect the write at the instant it occurs, so
  2316. * the pager should not depend upon prompt notification. A common
  2317. * use of this notification might be to invalidate cached data.
  2318. * If the page was dirtied in more than one memory context,
  2319. * the pager's pd_dirty routine will be called once for each
  2320. * context.
  2321. *
  2322. * These calls take the same parameters as the page-out and -in
  2323. * functions except that the "ppage" parameter isn't valid and
  2324. * no return value is recognized.
  2325. */
  2326. PFUNPAGE pd_dirty;
  2327. /*
  2328. * The pd_type field gives the sytem information about the
  2329. * overcommit characteristics of pages controlled by this pager.
  2330. * The following are allowable values for the field:
  2331. *
  2332. * PD_SWAPPER - under some conditions, pages of this type
  2333. * may be paged out into the swap file
  2334. * PD_PAGERONLY - pages controlled by this pager will never
  2335. * be paged out to the swap file
  2336. *
  2337. * In addition, the following value may be or'ed in to the pd_type field:
  2338. *
  2339. * PD_NESTEXEC - must be specified if either the pd_cleanout or pd_dirtyout
  2340. * functions perform nested excecution or block using the
  2341. * BLOCK_SVC_INTS flag. To be safe, this flag should always be
  2342. * specified if the pager does any sort of file i/o to anything
  2343. * other than the default paging file.
  2344. */
  2345. ULONG pd_type;
  2346. };
  2347. typedef struct pd_s PD;
  2348. typedef PD * PPD;
  2349. /* values for pd_type */
  2350. #define PD_SWAPPER 0 /* pages need direct accounting in swap file */
  2351. #define PD_PAGERONLY 1 /* pages will never be swapped */
  2352. #define PD_NESTEXEC 2 /* page out funtion uses nested execution */
  2353. #endif // Not_VxD
  2354. /*
  2355. * The size of a page of memory
  2356. */
  2357. #define PAGESHIFT 12
  2358. #define PAGESIZE (1 << PAGESHIFT)
  2359. #define PAGEMASK (PAGESIZE - 1)
  2360. #define PAGE(p) ((DWORD)(p) >> PAGESHIFT)
  2361. #define NPAGES(cb) (((DWORD)(cb) + PAGEMASK) >> PAGESHIFT)
  2362. /*
  2363. * Address space (arena) boundaries
  2364. */
  2365. #define MAXSYSTEMLADDR ((ULONG) 0xffbfffff) /* 4 gig - 4meg */
  2366. #define MINSYSTEMLADDR ((ULONG) 0xc0000000) /* 3 gig */
  2367. #define MAXSHAREDLADDR ((ULONG) 0xbfffffff)
  2368. #define MINSHAREDLADDR ((ULONG) 0x80000000) /* 2 gig */
  2369. #define MAXPRIVATELADDR ((ULONG) 0x7fffffff)
  2370. #define MINPRIVATELADDR ((ULONG) 0x00400000) /* 4 meg */
  2371. #define MAXDOSLADDR ((ULONG) 0x003fffff)
  2372. #define MINDOSLADDR ((ULONG) 0x00000000)
  2373. #define MAXSYSTEMPAGE (MAXSYSTEMLADDR >> PAGESHIFT)
  2374. #define MINSYSTEMPAGE (MINSYSTEMLADDR >> PAGESHIFT)
  2375. #define MAXSHAREDPAGE (MAXSHAREDLADDR >> PAGESHIFT)
  2376. #define MINSHAREDPAGE (MINSHAREDLADDR >> PAGESHIFT)
  2377. #define MAXPRIVATEPAGE (MAXPRIVATELADDR >> PAGESHIFT)
  2378. #define MINPRIVATEPAGE (MINPRIVATELADDR >> PAGESHIFT)
  2379. #define MAXDOSPAGE (MAXDOSLADDR >> PAGESHIFT)
  2380. #define MINDOSPAGE (MINDOSLADDR >> PAGESHIFT)
  2381. #define CBPRIVATE (1 + MAXPRIVATELADDR - MINPRIVATELADDR)
  2382. #define CBSHARED (1 + MAXSHAREDLADDR - MINSHAREDLADDR)
  2383. #define CBSYSTEM (1 + MAXSYSTEMLADDR - MINSYSTEMLADDR)
  2384. #define CBDOS (1 + MAXDOSLADDR - MINDOSLADDR)
  2385. #define CPGPRIVATE (1 + MAXPRIVATEPAGE - MINPRIVATEPAGE)
  2386. #define CPGSHARED (1 + MAXSHAREDPAGE - MINSHAREDPAGE)
  2387. #define CPGSYSTEM (1 + MAXSYSTEMPAGE - MINSYSTEMPAGE)
  2388. #define CPGDOS (1 + MAXDOSPAGE - MINDOSPAGE)
  2389. /*XLATOFF*/
  2390. /*
  2391. * Largest object that could theoretically be allocated
  2392. */
  2393. #define CBMAXALLOC (max(CBSHARED,max(CBPRIVATE, CBSYSTEM)))
  2394. #define CPGMAXALLOC (max(CPGSHARED,max(CPGPRIVATE, CPGSYSTEM)))
  2395. /*XLATON*/
  2396. /* ASM
  2397. IFDEF DEBUG
  2398. DebFar EQU NEAR PTR
  2399. ELSE
  2400. DebFar EQU SHORT
  2401. ENDIF
  2402. */
  2403. #ifndef Not_VxD
  2404. /******************************************************************************
  2405. *
  2406. * EQUATES FOR SYSTEM_CONTROL CALLS
  2407. *
  2408. *****************************************************************************/
  2409. /*
  2410. * SYS_CRITICAL_INIT is a device init call. Devices that have a
  2411. * critical function that needs initializing before interrupts are
  2412. * enabled should do it at Sys_Critical_Init. Devices which REQUIRE a
  2413. * certain range of V86 pages to operate (such as the VDD video memory)
  2414. * should claim them at Sys_Critical_Init. SYS VM Simulate_Int,
  2415. * Exec_Int ACTIVITY IS NOT ALLOWED. Returning carry aborts device
  2416. * load only.
  2417. */
  2418. #define SYS_CRITICAL_INIT 0x0000 /* Devices req'd for virt mode */
  2419. /*
  2420. * DEVICE_INIT is where most devices do the bulk of their initialization.
  2421. * SYS VM Simulate_Int, Exec_Int activity is allowed. Returning carry
  2422. * aborts device load only.
  2423. */
  2424. #define DEVICE_INIT 0x0001 /* All other devices init */
  2425. /*
  2426. * INIT_COMPLETE is the final phase of device init called just before the
  2427. * WIN386 INIT pages are released and the Instance snapshot is taken.
  2428. * Devices which wish to search for a region of V86 pages >= A0h to use
  2429. * should do it at INIT_COMPLETE.
  2430. * SYS VM Simulate_Int, Exec_Int activity is allowed. Returning carry
  2431. * aborts device load only.
  2432. */
  2433. #define INIT_COMPLETE 0x0002 /* All devices initialized */
  2434. /* --------------- INITIALIZATION CODE AND DATA DISCARDED ------------------ */
  2435. /*
  2436. * Same as VM_Init, except for SYS VM.
  2437. */
  2438. #define SYS_VM_INIT 0x0003 /* Execute the system VM */
  2439. /*
  2440. * Same as VM_Terminate, except for SYS VM (Normal WIN386 exit ONLY, on a crash
  2441. * exit this call is not made). SYS VM Simulate_Int, Exec_Int activity is
  2442. * allowed. This and Sys_VM_Terminate2 are your last chances to access
  2443. * and/or lock pageable data.
  2444. */
  2445. #define SYS_VM_TERMINATE 0x0004 /* System VM terminated */
  2446. /*
  2447. * System_Exit call is made when WIN386 is exiting either normally or via
  2448. * a crash. INTERRUPTS ARE ENABLED. Instance snapshot has been restored.
  2449. * SYS VM Simulate_Int, Exec_Int ACTIVITY IS NOT ALLOWED.
  2450. */
  2451. #define SYSTEM_EXIT 0x0005 /* Devices prepare to exit */
  2452. /*
  2453. * SYS_CRITICAL_EXIT call is made when WIN386 is exiting either normally or via
  2454. * a crash. INTERRUPTS ARE DISABLED. SYS VM Simulate_Int, Exec_Int ACTIVITY
  2455. * IS NOT ALLOWED.
  2456. */
  2457. #define SYS_CRITICAL_EXIT 0x0006 /* System critical devices reset */
  2458. /*
  2459. * Create_VM creates a new VM. EBX = VM handle of new VM. Returning
  2460. * Carry will fail the Create_VM.
  2461. */
  2462. #define CREATE_VM 0x0007
  2463. /*
  2464. * Second phase of Create_VM. EBX = VM handle of new VM. Returning
  2465. * Carry will cause the VM to go Not_Executeable, then be destroyed.
  2466. * VM Simulate_Int, Exec_Int activity is NOT allowed.
  2467. */
  2468. #define VM_CRITICAL_INIT 0x0008
  2469. /*
  2470. * Third phase of Create_VM. EBX = VM handle of new VM. Returning
  2471. * Carry will cause the VM to go Not_Executeable, then be destroyed.
  2472. * VM Simulate_Int, Exec_Int activity is allowed.
  2473. */
  2474. #define VM_INIT 0x0009
  2475. /*
  2476. * NORMAL (First phase) of Destroy_VM. EBX = VM Hanlde. This occurs
  2477. * on normal termination of the VM. Call cannot be failed. VM
  2478. * Simulate_Int, Exec_Int activity is allowed.
  2479. */
  2480. #define VM_TERMINATE 0x000A /* Still in VM -- About to die */
  2481. /*
  2482. * Second phase of Destroy_VM. EBX = VM Handle, EDX = Flags (see
  2483. * below). Note that in the case of destroying a running VM, this is
  2484. * the first call made (VM_Terminate call does not occur). Call cannot
  2485. * be failed. VM Simulate_Int, Exec_Int activity is NOT allowed.
  2486. */
  2487. #define VM_NOT_EXECUTEABLE 0x000B /* Most devices die (except VDD) */
  2488. /*
  2489. * Final phase of Destroy_VM. EBX = VM Handle. Note that considerable
  2490. * time can elaps between the VM_Not_Executeable call and this call.
  2491. * Call cannot be failed. VM Simulate_Int, Exec_Int activity is NOT
  2492. * allowed.
  2493. */
  2494. #define DESTROY_VM 0x000C /* VM's control block about to go */
  2495. /*
  2496. * Flags for VM_Not_Executeable control call (passed in EDX)
  2497. */
  2498. #define VNE_CRASHED_BIT 0x00 /* VM was crashed */
  2499. #define VNE_CRASHED (1 << VNE_CRASHED_BIT)
  2500. #define VNE_NUKED_BIT 0x01 /* VM was destroyed while active */
  2501. #define VNE_NUKED (1 << VNE_NUKED_BIT)
  2502. #define VNE_CREATEFAIL_BIT 0x02 /* Some device failed Create_VM */
  2503. #define VNE_CREATEFAIL (1 << VNE_CREATEFAIL_BIT)
  2504. #define VNE_CRINITFAIL_BIT 0x03 /* Some device failed VM_Critical_Init */
  2505. #define VNE_CRINITFAIL (1 << VNE_CRINITFAIL_BIT)
  2506. #define VNE_INITFAIL_BIT 0x04 /* Some device failed VM_Init */
  2507. #define VNE_INITFAIL (1 << VNE_INITFAIL_BIT)
  2508. #define VNE_CLOSED_BIT 0x05
  2509. #define VNE_CLOSED (1 << VNE_CLOSED_BIT)
  2510. /*
  2511. * EBX = VM Handle. Call cannot be failed.
  2512. */
  2513. #define VM_SUSPEND 0x000D /* VM not runnable until resume */
  2514. /*
  2515. * EBX = VM Handle. Returning carry fails and backs out the resume.
  2516. */
  2517. #define VM_RESUME 0x000E /* VM is leaving suspended state */
  2518. /*
  2519. * EBX = VM Handle to set device focus to. EDX = Device ID if device
  2520. * specific setfocus, == 0 if device critical setfocus (all devices).
  2521. * THIS CALL CANNOT BE FAILED.
  2522. *
  2523. * NOTE: In case where EDX == 0, ESI is a FLAG word that indicates
  2524. * special functions. Currently Bit 0 being set indicates that this
  2525. * Device critical set focus is also "VM critical". It means that we
  2526. * do not want some other VM to take the focus from this app now. This
  2527. * is primarily used when doing a device critical set focus to Windows
  2528. * (the SYS VM) it is interpreted by the SHELL to mean "if an old app
  2529. * currently has the Windows activation, set the activation to the
  2530. * Windows Shell, not back to the old app". ALSO in the case where Bit
  2531. * 0 is set, EDI = The VM handle of the VM that is "having trouble".
  2532. * Set this to 0 if there is no specific VM associated with the
  2533. * problem.
  2534. */
  2535. #define SET_DEVICE_FOCUS 0x000F
  2536. /*
  2537. * EBX = VM Handle going into message mode. THIS CALL CANNOT BE FAILED.
  2538. */
  2539. #define BEGIN_MESSAGE_MODE 0x0010
  2540. /*
  2541. * EBX = VM Handle leaving message mode. THIS CALL CANNOT BE FAILED.
  2542. */
  2543. #define END_MESSAGE_MODE 0x0011
  2544. /* ----------------------- SPECIAL CONTROL CALLS --------------------------- */
  2545. /*
  2546. * Request for reboot. Call cannot be failed.
  2547. */
  2548. #define REBOOT_PROCESSOR 0x0012 /* Request a machine reboot */
  2549. /*
  2550. * Query_Destroy is an information call made by the SHELL device before
  2551. * an attempt is made to initiate a destroy VM sequence on a running VM
  2552. * which has not exited normally. EBX = VM Handle. Returning carry
  2553. * indicates that a device "has a problem" with allowing this. THE
  2554. * DESTROY SEQUENCE CANNOT BE ABORTED HOWEVER, this decision is up to
  2555. * the user. All this does is indicate that there is a "problem" with
  2556. * allowing the destroy. The device which returns carry should call
  2557. * the SHELL_Message service to post an informational dialog about the
  2558. * reason for the problem.
  2559. */
  2560. #define QUERY_DESTROY 0x0013 /* OK to destroy running VM? */
  2561. /* ----------------------- DEBUGGING CONTROL CALL -------------------------- */
  2562. /*
  2563. * Special call for device specific DEBUG information display and activity.
  2564. */
  2565. #define DEBUG_QUERY 0x0014
  2566. /* -------- CALLS FOR BEGIN/END OF PROTECTED MODE VM EXECUTION ------------- */
  2567. /*
  2568. * About to run a protected mode application.
  2569. * EBX = Current VM handle.
  2570. * EDX = Flags
  2571. * EDI -> Application Control Block
  2572. * Returning with carry set fails the call.
  2573. */
  2574. #define BEGIN_PM_APP 0x0015
  2575. /*
  2576. * Flags for Begin_PM_App (passed in EDX)
  2577. */
  2578. #define BPA_32_BIT 0x01
  2579. #define BPA_32_BIT_FLAG 1
  2580. /*
  2581. * Protected mode application is terminating.
  2582. * EBX = Current VM handle. THIS CALL CAN NOT FAIL.
  2583. * EDI -> Application Control Block
  2584. */
  2585. #define END_PM_APP 0x0016
  2586. /*
  2587. * Called whenever system is about to be rebooted. Allows VxDs to clean
  2588. * up in preperation for reboot.
  2589. */
  2590. #define DEVICE_REBOOT_NOTIFY 0x0017
  2591. #define CRIT_REBOOT_NOTIFY 0x0018
  2592. /*
  2593. * Called when VM is about to be terminated using the Close_VM service
  2594. * EBX = Current VM handle (Handle of VM to close)
  2595. * EDX = Flags
  2596. * CVNF_CRIT_CLOSE = 1 if VM is in critical section while closing
  2597. */
  2598. #define CLOSE_VM_NOTIFY 0x0019
  2599. #define CVNF_CRIT_CLOSE_BIT 0
  2600. #define CVNF_CRIT_CLOSE (1 << CVNF_CRIT_CLOSE_BIT)
  2601. /*
  2602. * Power management event notification.
  2603. * EBX = 0
  2604. * ESI = event notification message
  2605. * EDI -> DWORD return value; VxD's modify the DWORD to return info, not EDI
  2606. * EDX is reserved
  2607. */
  2608. #define POWER_EVENT 0x001A
  2609. #define SYS_DYNAMIC_DEVICE_INIT 0x001B
  2610. #define SYS_DYNAMIC_DEVICE_EXIT 0x001C
  2611. /*
  2612. * Create_THREAD creates a new thread. EDI = handle of new thread.
  2613. * Returning Carry will fail the Create_THREAD. Message is sent in the
  2614. * context of the creating thread.
  2615. *
  2616. */
  2617. #define CREATE_THREAD 0x001D
  2618. /*
  2619. * Second phase of creating a thread. EDI = handle of new thread. Call cannot
  2620. * be failed. VM Simulate_Int, Exec_Int activity is not allowed (because
  2621. * never allowed in non-initial threads). Message is sent in the context
  2622. * of the newly created thread.
  2623. *
  2624. */
  2625. #define THREAD_INIT 0x001E
  2626. /*
  2627. * Normal (first) phase of Destroy_THREAD. EDI = handle of thread.
  2628. * This occurs on normal termination of the thread. Call cannot be failed.
  2629. * Simulate_Int, Exec_Int activity is allowed.
  2630. */
  2631. #define TERMINATE_THREAD 0x001F
  2632. /*
  2633. * Second phase of Destroy_THREAD. EDI = Handle of thread,
  2634. * EDX = flags (see below). Note that in the case of destroying a
  2635. * running thread, this is the first call made (THREAD_Terminate call
  2636. * does not occur). Call cannot be failed. VM Simulate_Int, Exec_Int
  2637. * activity is NOT allowed.
  2638. *
  2639. */
  2640. #define THREAD_Not_Executeable 0x0020
  2641. /*
  2642. * Final phase of Destroy_THREAD. EDI = Thread Handle. Note that considerable
  2643. * time can elapse between the THREAD_Not_Executeable call and this call.
  2644. * Call cannot be failed. VM Simulate_Int, Exec_Int activity is NOT
  2645. * allowed.
  2646. *
  2647. */
  2648. #define DESTROY_THREAD 0x0021
  2649. /* -------------------- CALLS FOR PLUG&PLAY ------------------------- */
  2650. /*
  2651. * Configuration manager or a devloader is telling a DLVxD that a new devnode
  2652. * has been created. EBX is the handle of the new devnode and EDX is the load
  2653. * type (one of the DLVxD_LOAD_* defined in CONFIGMG.H). This is a 'C'
  2654. * system control call. Contrarily to the other calls, carry flags must be
  2655. * set if any error code other than CR_SUCCESS is to be return.
  2656. *
  2657. */
  2658. #define PNP_NEW_DEVNODE 0x0022
  2659. /* -------------------- CALLS FOR Win32 ------------------------- */
  2660. /* vWin32 communicates with Vxds on behalf of Win32 apps thru this mechanism.
  2661. * FEATURE: need more doc here, describing the interface
  2662. */
  2663. #define W32_DEVICEIOCONTROL 0x0023
  2664. /* sub-functions */
  2665. #define DIOC_GETVERSION 0x0
  2666. #define DIOC_OPEN DIOC_GETVERSION
  2667. #define DIOC_CLOSEHANDLE -1
  2668. /* -------------------- MORE SYSTEM CALLS ------------------------- */
  2669. /*
  2670. * All these messages are sent immediately following the corresponding
  2671. * message of the same name, except that the "2" messages are sent
  2672. * in *reverse* init order.
  2673. */
  2674. #define SYS_VM_TERMINATE2 0x0024
  2675. #define SYSTEM_EXIT2 0x0025
  2676. #define SYS_CRITICAL_EXIT2 0x0026
  2677. #define VM_TERMINATE2 0x0027
  2678. #define VM_NOT_EXECUTEABLE2 0x0028
  2679. #define DESTROY_VM2 0x0029
  2680. #define VM_SUSPEND2 0x002A
  2681. #define END_MESSAGE_MODE2 0x002B
  2682. #define END_PM_APP2 0x002C
  2683. #define DEVICE_REBOOT_NOTIFY2 0x002D
  2684. #define CRIT_REBOOT_NOTIFY2 0x002E
  2685. #define CLOSE_VM_NOTIFY2 0x002F
  2686. /*
  2687. * VCOMM gets Address of Contention handler from VxDs by sending this
  2688. * control message
  2689. */
  2690. #define GET_CONTENTION_HANDLER 0x0030
  2691. #define KERNEL32_INITIALIZED 0x0031
  2692. #define KERNEL32_SHUTDOWN 0x0032
  2693. #define CREATE_PROCESS 0x0033
  2694. #define DESTROY_PROCESS 0x0034
  2695. #define MAX_SYSTEM_CONTROL 0x0034
  2696. /*
  2697. * Dynamic VxD's can communicate with each other using Directed_Sys_Control
  2698. * and a private control message in the following range:
  2699. */
  2700. #define BEGIN_RESERVED_PRIVATE_SYSTEM_CONTROL 0x70000000
  2701. #define END_RESERVED_PRIVATE_SYSTEM_CONTROL 0x7FFFFFFF
  2702. #endif // Not_VxD
  2703. /*
  2704. * Values returned from VMM_GetSystemInitState in EAX.
  2705. *
  2706. * Comments represent operations performed by VMM; #define's indicate
  2707. * what VMM_GetSystemInitState will return if you call it between the
  2708. * previous operation and the next.
  2709. *
  2710. * Future versions of Windows may have additional init states between the
  2711. * ones defined here, so you should be careful to use range checks instead
  2712. * of test for equality.
  2713. */
  2714. /* Protected mode is entered */
  2715. #define SYSSTATE_PRESYSCRITINIT 0x00000000
  2716. /* SYS_CRITICAL_INIT is broadcast */
  2717. #define SYSSTATE_PREDEVICEINIT 0x10000000
  2718. /* DEVICE_INIT is broadcast */
  2719. #define SYSSTATE_PREINITCOMPLETE 0x20000000
  2720. /* INIT_COMPLETE is broadcast */
  2721. /* VxD initialization complete */
  2722. #define SYSSTATE_VXDINITCOMPLETED 0x40000000
  2723. /* KERNEL32_INITIALIZED is broadcast */
  2724. #define SYSSTATE_KERNEL32INITED 0x50000000
  2725. /* All initialization completed */
  2726. /* System running normally */
  2727. /* System shutdown initiated */
  2728. /* KERNEL32_SHUTDOWN is broadcast */
  2729. #define SYSSTATE_KERNEL32TERMINATED 0xA0000000
  2730. /* System shutdown continues */
  2731. #define SYSSTATE_PRESYSVMTERMINATE 0xB0000000
  2732. /* SYS_VM_TERMINATE is broadcast */
  2733. #define SYSSTATE_PRESYSTEMEXIT 0xE0000000
  2734. /* SYSTEM_EXIT is broadcast */
  2735. #define SYSSTATE_PRESYSTEMEXIT2 0xE4000000
  2736. /* SYSTEM_EXIT2 is broadcast */
  2737. #define SYSSTATE_PRESYSCRITEXIT 0xF0000000
  2738. /* SYS_CRITICAL_EXIT is broadcast */
  2739. #define SYSSTATE_PRESYSCRITEXIT2 0xF4000000
  2740. /* SYS_CRITICAL_EXIT2 is broadcast */
  2741. #define SYSSTATE_POSTSYSCRITEXIT2 0xFFF00000
  2742. /* Return to real mode */
  2743. /* Alternate path: CAD reboot */
  2744. #define SYSSTATE_PREDEVICEREBOOT 0xFFFF0000
  2745. /* DEVICE_REBOOT_NOTIFY is broadcast */
  2746. #define SYSSTATE_PRECRITREBOOT 0xFFFFF000
  2747. /* CRIT_REBOOT_NOTIFY is broadcast */
  2748. #define SYSSTATE_PREREBOOTCPU 0xFFFFFF00
  2749. /* REBOOT_PROCESSOR is broadcast */
  2750. /* Return to real mode */
  2751. /* ASM
  2752. BeginDoc
  2753. ;******************************************************************************
  2754. ; BeginProc is a macro for defining entry points to routines in VMM and in the
  2755. ; VxDs. It correctly defines the procedure name for VxD services, DWORD
  2756. ; aligns the procedure, takes care of public declaration and does some
  2757. ; calling verification for debug versions of the software. EndProc is a
  2758. ; macro which defines the end of the procedure.
  2759. ;
  2760. ; Valid parameters to the BeginProc macro are:
  2761. ; PUBLIC ; Used outside this module (default)
  2762. ; LOCAL ; Local to this module
  2763. ; HIGH_FREQ ; DWORD align procedure
  2764. ; SERVICE ; Routine is called via VxDCall
  2765. ; ASYNC_SERVICE ; Same as "SERVICE" plus routine can
  2766. ; ; be called under interrupt.
  2767. ; HOOK_PROC ; Proc is a handler installed with
  2768. ; ; with a call to Hook_xxx_Fault
  2769. ; ; or Hook_Device_Service. The
  2770. ; ; following parameter must be
  2771. ; ; the label of a DWORD location
  2772. ; ; which will hold the ptr to next
  2773. ; ; hook proc. e.g.
  2774. ;
  2775. ; ;BeginProc foo, SERVICE, HOOK_PROC, foo_next_ptr
  2776. ;
  2777. ; NO_LOG ; Disable Queue_Out call logging
  2778. ; NO_PROFILE ; Disable DynaLink profile counts
  2779. ; NO_TEST_CLD ; Disable direction flag check
  2780. ;
  2781. ; TEST_BLOCK ; Trap if in NOBLOCK state
  2782. ; ; (default if in pageable code seg)
  2783. ; TEST_REENTER ; Trap if Get_VMM_Reenter_Count != 0
  2784. ; ; (default for non-async services)
  2785. ; NEVER_REENTER ; Trap if VMM has been reentered
  2786. ; NOT_SWAPPING ; Trap if this thread is swapping
  2787. ;
  2788. ; NO_PROLOG ; Disable all prolog tests
  2789. ;
  2790. ; ESP ; Use ESP instead of EBP for stack
  2791. ; ; frame base
  2792. ; PCALL ; pascal calling convention
  2793. ; SCALL ; stdcall calling convention
  2794. ; FASTCALL ; stdcall, but first 2 parameters are passed in ECX & EDX
  2795. ; CCALL ; "C" calling convention
  2796. ; ICALL ; default calling convention
  2797. ; W32SVC ; Win32 service
  2798. ;
  2799. ; segment type ; Place function in specified segment
  2800. ;
  2801. ; The NO_PROFILE flag merely suppresses incrementing the profile count.
  2802. ; The DWORD of profiling information will still be emitted to appease
  2803. ; the debugger. If you want to increment the profile count manually,
  2804. ; use the IncProfileCount macro.
  2805. ;
  2806. ; TEST_REENTER and NEVER_REENTER differ in that the VMM reentry count
  2807. ; returned by Get_VMM_Reenter_Count is artifically forced to zero by
  2808. ; Begin_Reentrant_Execution, whereas the counter checked by NEVER_REENTER
  2809. ; reflects the genuine count of VMM reentry.
  2810. ;
  2811. ; A segment type (such as LOCKED, PAGEABLE, STATIC, INIT, DEBUG_ONLY) can be
  2812. ; provided, in which case the BeginProc and EndProc macros will
  2813. ; automatically place the appropriate segment directives around the
  2814. ; definition of the function.
  2815. ;
  2816. ; segment type ; Place function in specified segment
  2817. ;
  2818. ; After the routine header in which the routine entry conditions, exit
  2819. ; conditions, side affects and functionality are specified, the BeginProc
  2820. ; macro should be used to define the routine's entry point. It has up to
  2821. ; four parameters as specified below. For example:
  2822. ;
  2823. ;BeginProc <Function_Name>,PUBLIC, HIGH_FREQ, SERVICE, ASYNC_SERVICE, ESP
  2824. ;
  2825. ; <code>
  2826. ;
  2827. ;EndProc <Function_Name>
  2828. ;==============================================================================
  2829. EndDoc
  2830. ;
  2831. ; BeginProc handling takes place in the following phases:
  2832. ;
  2833. ; Phase 1: Parsing the arguments.
  2834. ; Phase 2: Setting default flags.
  2835. ; Phase 3: Combining the flags.
  2836. ; Phase 4: Code emitted before the label
  2837. ; Phase 5: Munge the name as exported to C/Pascal/whoever
  2838. ; Phase 6: _Debug_Flags_Service prolog
  2839. ; Phase 7: Code emitted after the label
  2840. ;
  2841. ??_pf_Check equ 1 ;; Do Enter/LeaveProc checking?
  2842. ??_pf_ArgsUsed equ 2 ;; ArgVars were used
  2843. ??_pf_Entered equ 4 ;; EnterProc performed
  2844. ??_pf_Left equ 8 ;; LeaveProc performed
  2845. ??_pf_Returned equ 16 ;; Return performed
  2846. ??_pushed = 0 ;; For WIN31COMPAT
  2847. ??_align = 0 ;; For WIN31COMPAT
  2848. ??_ends equ <> ;; BeginProc segment
  2849. BeginProc macro Name, P1, P2, P3, P4, P5, P6, P7, LastArg
  2850. local Profile_Data, prelabeldata, ??_hookvar
  2851. ??_frame = 0 ;; local frame base
  2852. ??_aframe = 0 ;; argument frame base
  2853. ??_taframe = 0 ;; true argument frame base
  2854. ??_initaframe = 0 ;; initial aframe value
  2855. ??_numargs = 0 ;; number of argvars
  2856. ??_numlocals = 0 ;; number of localvars
  2857. ??_numlocalsymbols = 0 ;; number of local symbols
  2858. ??_procflags = 0 ;; misc. Enter/LeaveProc flags
  2859. ??_esp = 0 ;; if VMM_TRUE, use esp instead of ebp
  2860. ??_pushed = 0 ;; number of bytes pushed
  2861. ??_align = 0 ;; set if proc should be dword aligned
  2862. ??_hook = 0 ;; set if proc is a Hook_Proc
  2863. ??_hookarg = 0
  2864. ??_service = 0
  2865. ??_async_service = 0
  2866. IF DEBLEVEL GT DEBLEVELNORMAL
  2867. ??_log = DFS_LOG ;; logging on by default
  2868. ??_profile = DFS_PROFILE ;; service profiling on by default
  2869. ??_test_cld = DFS_TEST_CLD ;; test that direction is clear
  2870. ELSE
  2871. ??_log = 0 ;; logging off
  2872. IFDEF DEBUG
  2873. IFDEF profileall
  2874. IF ?_ICODE
  2875. ??_profile = DFS_PROFILE ;; service profiling on by default
  2876. ELSE
  2877. ??_profile = 0 ;; service profiling off
  2878. ENDIF
  2879. ELSE
  2880. ??_profile = 0 ;; service profiling off
  2881. ENDIF
  2882. ELSE
  2883. ??_profile = 0 ;; service profiling off
  2884. ENDIF
  2885. ??_test_cld = 0 ;; test that direction is clear
  2886. ENDIF
  2887. ??_might_block = 0 ;; entering fn might cause VM to block
  2888. ??_test_reenter = 0 ;; don't test for VMM reentry
  2889. ??_never_reenter = 0 ;; don't test for genuine VMM reentry
  2890. ??_not_swapping = 0 ;; don't test that we're not swapping
  2891. ??_prolog_disabled = 0 ;; use a prolog by default
  2892. ??_public = 1 ;; everything's public by default
  2893. ??_cleanoff = 0 ;; don't cleanoff parameters
  2894. ??_ccall = 0
  2895. ??_pcall = 0
  2896. ??_scall = 0
  2897. ??_fastcall = 0
  2898. ??_w32svc = 0
  2899. ??_fleave = FALSE
  2900. ; ??_dfs = 0 ;; parm for _Debug_Flags_Service
  2901. ??_name equ <Name>
  2902. .errnb ??_ends, <Cannot nest functions with named segments>
  2903. .errnb <LastArg>, <Too many arguments to BeginProc>
  2904. ;; Phase 1: Parsing the arguments
  2905. irp arg, <P1, P2, P3, P4, P5, P6, P7>
  2906. if ??_hookarg
  2907. ??_hookarg = 0
  2908. ??_hookvar equ <arg>
  2909. elseifdef ?&&arg&&_BeginProc
  2910. ?&&arg&&_BeginProc
  2911. elseifdef VxD_&&arg&&_CODE_SEG
  2912. ??_ends textequ <VxD_&&arg&&_CODE_ENDS>
  2913. VxD_&&arg&&_CODE_SEG
  2914. else
  2915. .err <Bad param "&arg" to BeginProc>
  2916. endif
  2917. endm
  2918. ;; Phase 2: Setting default flags
  2919. ifndef Not_VxD
  2920. ife ??_service
  2921. ifndef profileall
  2922. ??_profile = 0 ;; only services can be profiled
  2923. endif
  2924. ifdef VMMSYS
  2925. ??_prolog_disabled = 1
  2926. endif
  2927. else
  2928. ??_test_cld = DFS_TEST_CLD
  2929. endif ; ife ??_service
  2930. ife ?_16ICODE
  2931. ??_prolog_disabled = 1
  2932. else
  2933. ife ?_RCODE ;; if real-mode code segment
  2934. ??_prolog_disabled = 1 ;; don't do anything bad
  2935. else ;; else protected mode code segment
  2936. ife ?_PCODE ;; if swappable code
  2937. ??_might_block = DFS_TEST_BLOCK
  2938. endif
  2939. if ??_service
  2940. ife ??_async_service
  2941. ??_test_reenter = DFS_TEST_REENTER
  2942. endif
  2943. endif
  2944. endif ; ife ?_RCODE
  2945. endif ; ife ?_16ICODE
  2946. endif ; Not_VxD
  2947. if ??_esp
  2948. ;; just return address on stack
  2949. ??_basereg equ <esp+??_pushed>
  2950. ??_initaframe = 4
  2951. else
  2952. ;; ret addr and EBP on stack
  2953. ??_basereg equ <ebp>
  2954. ??_initaframe = 8
  2955. endif
  2956. @Caller equ <dword ptr [??_basereg+??_initaframe-4]>
  2957. ??_cleanoff = ??_pcall or ??_scall or ??_fastcall
  2958. ;; Phase 3: Combining the flags
  2959. ??_dfs = ??_never_reenter + ??_test_reenter + ??_not_swapping + \
  2960. ??_log + ??_profile + ??_test_cld + ??_might_block
  2961. if ??_prolog_disabled
  2962. ??_dfs = 0
  2963. endif
  2964. ;; Phase 4: Pre-label code
  2965. ifndef Not_VxD
  2966. if ??_hook
  2967. if ??_align
  2968. Dword_Align
  2969. endif
  2970. prelabeldata:
  2971. ifndef ??_hookvar
  2972. .err <HOOK_PROC requires next arg to be name of dword location>
  2973. endif
  2974. jmp short Name
  2975. jmp [??_hookvar]
  2976. ifdef DEBUG
  2977. Profile_Data dd 0
  2978. endif
  2979. if ??_align
  2980. .errnz ($ - prelabeldata) mod 4
  2981. endif
  2982. endif
  2983. ifdef DEBUG
  2984. ?prolog_&Name label near
  2985. if (??_service OR ??_profile) AND (??_hook EQ 0)
  2986. jmp short Name
  2987. if ??_align
  2988. Dword_Align ; This also aligns the proc
  2989. endif ; since Profile_Data is a dd
  2990. IF ?_ICODE
  2991. ifdef profileall
  2992. ?ProfileHeader_BeginProc Profile_Data, %@filename
  2993. else
  2994. Profile_Data dd 0
  2995. endif
  2996. ELSE
  2997. Profile_Data dd 0
  2998. ENDIF
  2999. endif
  3000. endif
  3001. if ??_align
  3002. Dword_Align
  3003. endif
  3004. endif ; Not_VxD
  3005. Name proc near ;; The label
  3006. ;; Phase 5: Munge the name as exported to C/Pascal/whoever
  3007. ;; Warning! Phase 5 cannot emit code!
  3008. ife ??_pcall or ??_ccall or ??_scall or ??_fastcall ;; if no munging
  3009. if ??_public
  3010. public Name
  3011. else
  3012. ifdef DEBUG
  3013. % ?merge @FileName,$,Name,:
  3014. % ?merge public,,,,,@FileName,$,Name
  3015. endif
  3016. endif
  3017. endif
  3018. if ??_ccall
  3019. if ??_public
  3020. _&Name equ Name
  3021. ifdef Not_VxD
  3022. public C Name
  3023. else
  3024. public _&Name
  3025. endif
  3026. endif
  3027. endif
  3028. if ??_pcall
  3029. if ??_public
  3030. ?toupper Name
  3031. ?merge public,,,,%?upper
  3032. endif
  3033. endif
  3034. ;; Phase 6: _Debug_Flags_Service prolog
  3035. ;; DO NOT CHANGE UNTIL YOU UNDERSTAND _Debug_Flags_Service
  3036. ife ??_scall or ??_fastcall
  3037. ?_BeginProc_Debug_Prologue
  3038. endif
  3039. ;; Phase 7: Post-label code
  3040. ;; <none>
  3041. endm
  3042. ?_BeginProc_Debug_Prologue MACRO
  3043. ifndef Not_VxD
  3044. ifdef DEBUG
  3045. if ??_dfs EQ DFS_LOG
  3046. VMMCall Log_Proc_Call ;; no test, just log
  3047. else
  3048. if ??_dfs EQ DFS_TEST_REENTER
  3049. VMMCall Test_Reenter ;; no log, just reenter
  3050. else
  3051. if ??_dfs or ?_LOCKABLECODE eq 0
  3052. ifdef WIN31COMPAT
  3053. if ??_dfs AND DFS_LOG
  3054. VMMCall Log_Proc_Call
  3055. endif
  3056. if ??_dfs AND DFS_TEST_REENTER
  3057. VMMCall Test_Reenter
  3058. endif
  3059. else
  3060. ife ?_LOCKABLECODE
  3061. ifdef ??_debug_flags
  3062. push ??_debug_flags
  3063. if ??_dfs
  3064. pushfd
  3065. or dword ptr [esp+4],??_dfs
  3066. popfd
  3067. endif
  3068. VMMCall _Debug_Flags_Service
  3069. elseif ??_dfs
  3070. push ??_dfs
  3071. VMMCall _Debug_Flags_Service
  3072. endif
  3073. else
  3074. push ??_dfs
  3075. VMMCall _Debug_Flags_Service
  3076. endif
  3077. endif
  3078. else
  3079. ifdef profileall
  3080. IncProfileCount
  3081. endif
  3082. endif ;if ??_dfs
  3083. endif ; if ??_dfs EQ DFS_TEST_REENTER
  3084. endif ; if ??_dfs EQ DFS_LOG
  3085. endif ; DEBUG
  3086. endif ; Not_VxD
  3087. ENDM
  3088. ;
  3089. ; For each BeginProc keyword, there is a corresponding macro ?XX_BeginProc.
  3090. ;
  3091. ; The macro ?_BeginProc is so that the null keyword is not an error.
  3092. ?_BeginProc macro
  3093. endm
  3094. ?PUBLIC_BeginProc macro
  3095. ??_public = 1
  3096. endm
  3097. ?LOCAL_BeginProc macro
  3098. ??_public = 0
  3099. endm
  3100. ?HIGH_FREQ_BeginProc macro
  3101. ??_align = 1
  3102. endm
  3103. ?HOOK_PROC_BeginProc macro
  3104. ??_hook = 1
  3105. ??_hookarg = 1 ; next arg is dword storage location
  3106. endm
  3107. ?SERVICE_BeginProc macro
  3108. ??_service = 1
  3109. .erre ?_16ICODE, <SERVICEs must be in 32 bit code>
  3110. .erre ?_RCODE, <SERVICEs must be in 32 bit code>
  3111. endm
  3112. ?ASYNC_SERVICE_BeginProc macro
  3113. ??_service = 1
  3114. ??_async_service = 1
  3115. .errnz ?_LCODE, <ASYNC_SERVICE's must be in LOCKED code>
  3116. endm
  3117. ?NO_LOG_BeginProc macro
  3118. ??_log = 0
  3119. endm
  3120. ?NO_PROFILE_BeginProc macro
  3121. ??_profile = 0
  3122. endm
  3123. ?NO_TEST_CLD_BeginProc macro
  3124. ??_test_cld = 0
  3125. endm
  3126. ?TEST_BLOCK_BeginProc macro
  3127. ??_might_block = DFS_TEST_BLOCK
  3128. endm
  3129. ?TEST_REENTER_BeginProc macro
  3130. ??_test_reenter = DFS_TEST_REENTER
  3131. endm
  3132. ?NEVER_REENTER_BeginProc macro
  3133. ??_never_reenter = DFS_NEVER_REENTER
  3134. endm
  3135. ?NOT_SWAPPING_BeginProc macro
  3136. ??_not_swapping = DFS_NOT_SWAPPING
  3137. endm
  3138. ?NO_PROLOG_BeginProc macro
  3139. ??_prolog_disabled = 1
  3140. endm
  3141. ?ESP_BeginProc macro
  3142. ??_esp = VMM_TRUE
  3143. ifndef Not_VxD
  3144. .erre ?_16ICODE, <Beginproc ESP attribute invalid in 16 bit seg.>
  3145. .erre ?_RCODE, <Beginproc ESP attribute invalid in real-mode seg.>
  3146. endif
  3147. endm
  3148. ?CCALL_BeginProc macro
  3149. ??_ccall = 1
  3150. endm
  3151. ?PCALL_BeginProc macro
  3152. ??_pcall = 1
  3153. endm
  3154. ?SCALL_BeginProc macro
  3155. ??_scall = 1
  3156. endm
  3157. ?FASTCALL_BeginProc macro
  3158. ??_fastcall = 1
  3159. endm
  3160. ?ICALL_BeginProc macro
  3161. ??_scall = 1 ;; internal calling convention is StdCall
  3162. endm
  3163. ?W32SVC_BeginProc macro
  3164. ??_scall = 1
  3165. ??_w32svc = 1
  3166. endm
  3167. ifdef DEBUG
  3168. ifdef profileall
  3169. ?ProfileHeader_BeginProc macro PL, filename
  3170. ifndef _&filename&__proc_list
  3171. _&filename&__proc_list = 0
  3172. PUBLIC _&filename&__proc_list
  3173. endif
  3174. dd OFFSET32 _&filename&__proc_list
  3175. PL dd 0
  3176. _&filename&__proc_list = PL
  3177. endm
  3178. endif
  3179. IncProfileCount macro
  3180. if ??_service OR ??_profile
  3181. inc dword ptr [??_name-4]
  3182. else
  3183. ifndef profileall
  3184. .err <IncProfileCount can be used only in services.>
  3185. endif
  3186. endif
  3187. endm
  3188. else
  3189. IncProfileCount macro
  3190. endm
  3191. endif
  3192. ;*** ArgVar - declares stack arguments
  3193. ;
  3194. ; Usage:
  3195. ;
  3196. ; name = name of argument.
  3197. ; length = a numeric expression denoting the size (in bytes)
  3198. ; of the argument. The symbols BYTE, WORD, and DWORD
  3199. ; are synonyms for 1, 2, and 4 respectively.
  3200. ; NB! All arguments sizes are rounded up to the nearest
  3201. ; multiple of 4.
  3202. ; used = usually blank, but can be the symbol NOTUSED
  3203. ; to indicate that the argument will not be used
  3204. ; by the procedure.
  3205. ;
  3206. ArgVar macro name,length,used
  3207. ??_numargs = ??_numargs + 1
  3208. if ??_pcall
  3209. ?mkarg <name>, <length>, <used>, %??_numargs
  3210. else
  3211. ?arg <name>, <length>, <used>
  3212. endif
  3213. ??_procflags = ??_procflags OR ??_pf_Check
  3214. endm
  3215. ?mkarg macro name, length, used, num
  3216. .xcref ?MKA&num
  3217. ?deflocal <name>
  3218. ?MKA&num &macro
  3219. ?argvar <name>, <length>, <used>
  3220. &endm
  3221. ??_aframe = ??_aframe + 4
  3222. endm
  3223. .xcref ?mkarg
  3224. ?argvar macro name,length,used
  3225. local a
  3226. a = ??_taframe
  3227. ??_aframe = ??_aframe + 4
  3228. ??_taframe = ??_taframe + 4
  3229. ifidni <length>,<BYTE>
  3230. ?setname <name>, <byte ptr [??_basereg+??_initaframe+a]>, <used>
  3231. elseifidni <length>,<WORD>
  3232. ?setname <name>, <word ptr [??_basereg+??_initaframe+a]>, <used>
  3233. elseifidni <length>,<DWORD>
  3234. ?setname <name>, <dword ptr [??_basereg+??_initaframe+a]>, <used>
  3235. ?setname <name&l>,<word ptr [??_basereg+??_initaframe+a]>, <used>
  3236. ?setname <name&ll>,<byte ptr [??_basereg+??_initaframe+a]>, <used>
  3237. ?setname <name&lh>,<byte ptr [??_basereg+??_initaframe+a+1]>, <used>
  3238. ?setname <name&h>,<word ptr [??_basereg+??_initaframe+a+2]>, <used>
  3239. ?setname <name&hl>,<byte ptr [??_basereg+??_initaframe+a+2]>, <used>
  3240. ?setname <name&hh>,<byte ptr [??_basereg+??_initaframe+a+3]>, <used>
  3241. else
  3242. ??_aframe = ??_aframe - 4 + ((length + 3)/4)*4
  3243. ??_taframe = ??_taframe - 4 + ((length + 3)/4)*4
  3244. ?setname <name>, <[??_basereg+??_initaframe+a]>, <used>
  3245. endif
  3246. endm
  3247. ?arg macro name,length,used
  3248. if ??_fastcall
  3249. if ??_numargs le 2
  3250. if length gt 4
  3251. .err <First 2 parameters are dwords (ecx,edx) for fastcall functions>
  3252. endif
  3253. ??_aframe = ??_aframe + 4
  3254. if ??_numargs eq 1
  3255. ?merge ecx_,name,,,equ,ecx
  3256. else
  3257. ?merge edx_,name,,,equ,edx
  3258. endif
  3259. else
  3260. ?argvar name, length, used
  3261. endif
  3262. else
  3263. ?argvar name, length, used
  3264. endif
  3265. endm
  3266. ;*** ?setname - optionally creates the name of an ArgVar
  3267. ;
  3268. ; If <used> is <NOTUSED>, then the name is defined to something
  3269. ; bogus.
  3270. ?setname macro name, value, used
  3271. ?deflocal <name>
  3272. ifidni <used>, <NOTUSED>
  3273. name equ _inaccessible_NOTUSED_
  3274. else
  3275. name equ value
  3276. ??_procflags = ??_procflags OR ??_pf_ArgsUsed OR ??_pf_Check
  3277. endif
  3278. endm
  3279. ;*** LocalVar - declares local stack variables
  3280. ;
  3281. ; Usage:
  3282. ;
  3283. ; name = name of local variable
  3284. ; length = a numeric expression denoting the size (in bytes)
  3285. ; of the argument. The symbols BYTE, WORD, and DWORD
  3286. ; are synonyms for 1, 2, and 4 respectively.
  3287. ; NB! All arguments sizes are rounded up to the nearest
  3288. ; multiple of 4 (unless PACK is indicated)
  3289. ; flag = usually blank, but can be the symbol PACK
  3290. ; to suppress the usual padding and aligning of variables
  3291. ; PACK is typically used when declaring a bunch of
  3292. ; byte or word variables. Make sure that the total
  3293. ; size of PACKed variables is a multiple of 4.
  3294. ;
  3295. LocalVar macro name,length,flag
  3296. local a
  3297. ??_numlocals = ??_numlocals + 1
  3298. ??_pad = 1
  3299. ifidni <flag>, <PACK>
  3300. ??_pad = 0
  3301. endif
  3302. ifidni <length>,<BYTE>
  3303. ??_frame = ??_frame + 1 + 3 * ??_pad
  3304. a = ??_frame
  3305. ?deflocal <name>
  3306. name equ byte ptr [??_basereg-a]
  3307. elseifidni <length>,<WORD>
  3308. ??_frame = ??_frame + 2 + 2 * ??_pad
  3309. a = ??_frame
  3310. ?deflocal <name>
  3311. name equ word ptr [??_basereg-a]
  3312. elseifidni <length>,<DWORD>
  3313. ??_frame = ??_frame + 4
  3314. a = ??_frame
  3315. ?deflocal <name, name&l, name&ll, name&lh, name&h, name&hl, name&hh>
  3316. name equ dword ptr [??_basereg-a]
  3317. name&l equ word ptr [??_basereg-a]
  3318. name&ll equ byte ptr [??_basereg-a]
  3319. name&lh equ byte ptr [??_basereg-a+1]
  3320. name&h equ word ptr [??_basereg-a+2]
  3321. name&hl equ byte ptr [??_basereg-a+2]
  3322. name&hh equ byte ptr [??_basereg-a+3]
  3323. else
  3324. ??_frame = ??_frame + ((length + 3)/4)*4
  3325. a = ??_frame
  3326. ?deflocal <name>
  3327. name equ [??_basereg-a]
  3328. endif
  3329. ??_procflags = ??_procflags OR ??_pf_Check
  3330. endm
  3331. ?deflocal macro name
  3332. irp nm, <name>
  3333. ??_numlocalsymbols = ??_numlocalsymbols + 1
  3334. ?dodeflocal <nm>, %(??_numlocalsymbols)
  3335. endm
  3336. endm
  3337. .xcref ?deflocal
  3338. ?dodeflocal macro name, num
  3339. .xcref ?LOC&num
  3340. ?LOC&num &macro
  3341. name equ <__inaccessible__NOTINSCOPE__>
  3342. &endm
  3343. endm
  3344. .xcref ?dodeflocal
  3345. ;*** EnterProc - generates stack frame on entry
  3346. EnterProc macro
  3347. .errnz ??_frame and 3, <Total size of local variables not a multiple of 4.>
  3348. if ??_scall
  3349. if ??_public
  3350. ifdef Not_VxD
  3351. ?merge %??_name,@,%(??_aframe),,label,near
  3352. ?merge public,,,,C,%??_name,@,%(??_aframe)
  3353. else
  3354. ?merge _,%??_name,@,%(??_aframe),label,near
  3355. ?merge public,,,,,_,%??_name,@,%(??_aframe)
  3356. endif
  3357. endif
  3358. ?_BeginProc_Debug_Prologue
  3359. endif
  3360. if ??_fastcall
  3361. if ??_public
  3362. ifdef Not_VxD
  3363. ?merge %??_name,@,%(??_aframe),,label,near
  3364. ?merge public,,,,C,%??_name,@,%(??_aframe)
  3365. else
  3366. ?merge @,%??_name,@,%(??_aframe),label,near
  3367. ?merge public,,,,,@,%??_name,@,%(??_aframe)
  3368. endif
  3369. endif
  3370. ?_BeginProc_Debug_Prologue
  3371. endif
  3372. if ??_pcall
  3373. ??_aframe = 0
  3374. ?count = ??_numargs
  3375. rept ??_numargs
  3376. ?invprg <?MKA>,%?count
  3377. ?count = ?count - 1
  3378. endm
  3379. endif
  3380. ??_fleave = FALSE
  3381. if ??_esp
  3382. if ??_frame
  3383. sub esp, ??_frame
  3384. ??_pushed = ??_pushed + ??_frame
  3385. ??_fleave = VMM_TRUE
  3386. endif
  3387. else
  3388. if ??_frame eq 0
  3389. if (??_taframe eq 0) OR ((??_procflags AND ??_pf_ArgsUsed) EQ 0)
  3390. ifdef DEBUG
  3391. push ebp
  3392. mov ebp,esp
  3393. ??_fleave = VMM_TRUE
  3394. endif
  3395. else
  3396. push ebp
  3397. mov ebp,esp
  3398. ??_fleave = VMM_TRUE
  3399. endif
  3400. else
  3401. enter ??_frame, 0
  3402. ??_fleave = VMM_TRUE
  3403. endif
  3404. endif
  3405. ??_procflags = ??_procflags OR ??_pf_Entered
  3406. endm
  3407. ;*** LeaveProc - removes stack frame on exit
  3408. ;
  3409. ; NOTE: If there are localvar and ESP kind of stack frame
  3410. ; LeaveProc will destroy flags unless the "PRESERVE_FLAGS"
  3411. ; flag is given. PRESERVE_FLAGS generates bigger, slower
  3412. ; code, so use it only when necessary.
  3413. ;
  3414. ; WARNING: For "ESP" type stack frames, this macro DOES NOT adjust
  3415. ; the internal stack depth for the local frame. This is
  3416. ; to allow jumping around the LeaveProc/Return to code
  3417. ; after the LeaveProc/Return to use args/local variables,
  3418. ; but code that uses the stack frame executed after the
  3419. ; LeaveProc won't work.
  3420. LeaveProc macro flags
  3421. if ??_fleave
  3422. if ??_esp
  3423. ifidni <flags>,<PRESERVE_FLAGS>
  3424. lea esp,[esp + ??_frame]
  3425. else
  3426. add esp,??_frame
  3427. endif
  3428. else
  3429. leave
  3430. endif
  3431. endif
  3432. ??_procflags = ??_procflags OR ??_pf_Left
  3433. endm
  3434. ;*** Return - return appropriately from a procedure
  3435. ;
  3436. ; For "ccall" functions it's just a ret; for "pcall" and "scall"
  3437. ; it cleans the parameters off.
  3438. ;
  3439. Return macro
  3440. if ??_cleanoff OR ??_w32svc
  3441. if ??_w32svc AND (??_taframe LT 8)
  3442. ret 8
  3443. else
  3444. ret ??_taframe
  3445. endif
  3446. else
  3447. ret
  3448. endif
  3449. ??_procflags = ??_procflags OR ??_pf_Returned
  3450. endm
  3451. ;*** EndProc - end the procedure
  3452. ;
  3453. EndProc macro Name, Flag
  3454. Name endp ;; Masm will provide error msg for us
  3455. if ??_w32svc
  3456. if ??_taframe lt 8
  3457. cparm&Name equ 0
  3458. else
  3459. cparm&Name equ (??_taframe/4 - 2)
  3460. endif
  3461. endif
  3462. if ??_procflags AND ??_pf_Left
  3463. if ??_fleave
  3464. if ??_esp
  3465. ??_pushed = ??_pushed - ??_frame
  3466. endif
  3467. endif
  3468. endif
  3469. ifdifi <Flag>,<NOCHECK>
  3470. if ??_pushed ne 0
  3471. %out Warning: stack not balanced in Name
  3472. endif
  3473. if ??_procflags AND ??_pf_Check
  3474. ife ??_procflags AND ??_pf_Entered
  3475. %out Warning: ArgVar/LocalVar without EnterProc in Name
  3476. endif
  3477. ife ??_procflags AND ??_pf_Left
  3478. %out Warning: ArgVar/LocalVar without LeaveProc in Name
  3479. endif
  3480. ife ??_procflags AND ??_pf_Returned
  3481. %out Warning: ArgVar/LocalVar without Return in Name
  3482. endif
  3483. endif
  3484. endif
  3485. ifdifi <Flag>,<KEEPFRAMEVARS>
  3486. ?count = 0
  3487. rept ??_numlocalsymbols
  3488. ?count = ?count + 1
  3489. ?invprg <?LOC>,%?count
  3490. endm
  3491. endif
  3492. ??_ends
  3493. ??_ends equ <>
  3494. endm
  3495. ;*** cCall - "C" call
  3496. ;
  3497. ; Arguments pushed in "C" order, caller cleans stack
  3498. ;
  3499. ; USES: Flags.
  3500. cCall macro name, arglst, flags
  3501. ife .TYPE name
  3502. CondExtern name, near
  3503. endif
  3504. ifdef ??_nonstandardccall_&name
  3505. PushCParams <arglst>, <FAST>
  3506. else
  3507. PushCParams <arglst>, <flags>
  3508. endif
  3509. call name
  3510. ifdef ??_nonstandardccall_&name
  3511. ClearCParams PRESERVE_FLAGS
  3512. else
  3513. ClearCParams <flags>
  3514. endif
  3515. endm
  3516. .xcref cCall
  3517. ;*** pCall - pascal call
  3518. ;
  3519. ; Arguments pushed in pascal order, callee cleans stack
  3520. ;
  3521. pCall macro name, arglst
  3522. local ??saved
  3523. ife .TYPE name
  3524. ?toupper name
  3525. else
  3526. ?upper equ <name>
  3527. endif
  3528. CondExtern %?upper, near
  3529. ??saved = ??_pushed
  3530. irp x,<arglst>
  3531. push x
  3532. ??_pushed = ??_pushed + 4
  3533. endm
  3534. call ?upper
  3535. ??_pushed = ??saved
  3536. endm
  3537. .xcref pCall
  3538. ;*** sCall - standard call
  3539. ;
  3540. ; Arguments pushed in "C" order, callee cleans stack,
  3541. ; @argc appended to name
  3542. ;
  3543. sCall macro name, arglst
  3544. local ??saved
  3545. ??saved = ??_pushed
  3546. PushCParams <arglst>
  3547. ?scall _, name, %(??_argc * 4)
  3548. ??_pushed = ??saved
  3549. endm
  3550. .xcref sCall
  3551. ;*** fCall - fastcall call
  3552. ;
  3553. ; Arguments pushed in "C" order (except first two parms,
  3554. ; which are passed in ECX and EDX), callee cleans stack, and
  3555. ; @argc appended to name.
  3556. ;
  3557. ; The only useful value for flags is PRESERVE_FLAGS,
  3558. ; which can also be achieved by simply declaring the function
  3559. ; as non-standard, like so:
  3560. ;
  3561. ; DeclareNonstandardCcallService <functionname>
  3562. ;
  3563. fCall macro name, arglst, flags
  3564. local ??saved
  3565. ??saved = ??_pushed
  3566. ife .TYPE name
  3567. CondExtern name, near
  3568. endif
  3569. PushCParams <arglst>, <FASTCALL>
  3570. ?scall @, name, %(??_argc * 4)
  3571. ifdef ??_nonstandardccall_&name
  3572. ClearCParams PRESERVE_FLAGS
  3573. else
  3574. ClearCParams <flags>
  3575. endif
  3576. ??_pushed = ??saved
  3577. endm
  3578. .xcref fCall
  3579. ;*** iCall - internal routine call
  3580. ;
  3581. ; Set to whatever type we want to use as a default.
  3582. iCall equ <sCall>
  3583. ;*** PushCParams
  3584. ;
  3585. ; Processes argument list
  3586. ;
  3587. ; arglist = <arg1, arg2, arg3, ...>
  3588. ; flags = the word SMALL if we should prefer size over speed
  3589. ; the word FAST if we should prefer speed over size
  3590. ;
  3591. ; The default flag is SMALL, unless the current procedure
  3592. ; is High_Freq, in which case we default to FAST.
  3593. ;
  3594. ; To disable this optimization, define the symbol NONSTANDARD_CCALL.
  3595. ;
  3596. IFNDEF STANDARD_CCALL
  3597. NONSTANDARD_CCALL = 1 ;; disabled by default for now
  3598. ENDIF
  3599. PushCParams macro arglst, flags
  3600. LOCAL ??_pushedargs
  3601. ??_argc = 0 ;; number of dwords on stack (global)
  3602. IFDEF NONSTANDARD_CCALL
  3603. ??_popargs = 0 ;; establish default
  3604. ELSE
  3605. ??_popargs = ??_align EQ 0 ;; establish default
  3606. ENDIF
  3607. ifidni <flags>, <SMALL>
  3608. ??_popargs = 1 ;; size, not speed
  3609. elseifidni <flags>, <FAST>
  3610. ??_popargs = 0 ;; speed, not size
  3611. elseifidni <flags>, <FASTCALL>
  3612. ??_popargs = 0 ;; speed, not size
  3613. endif
  3614. irp x,<arglst>
  3615. ??_argc = ??_argc + 1
  3616. ifidni <flags>, <FASTCALL>
  3617. if ??_argc eq 1
  3618. ifdifi <x>, <ecx>
  3619. .err <first parameter must be ECX for fastcall functions>
  3620. endif
  3621. elseif ??_argc eq 2
  3622. ifdifi <x>, <edx>
  3623. .err <first parameter must be EDX for fastcall functions>
  3624. endif
  3625. else
  3626. ?marg <x>,%??_argc
  3627. endif
  3628. else
  3629. ?marg <x>,%??_argc
  3630. endif
  3631. endm
  3632. ?count = ??_argc
  3633. ifidni <flags>, <FASTCALL>
  3634. ??_pushedargs = ??_argc-2
  3635. else
  3636. ??_pushedargs = ??_argc
  3637. endif
  3638. if ??_pushedargs GT 0
  3639. rept ??_argc
  3640. ?invprg <?AM>,%?count
  3641. ?count = ?count - 1
  3642. endm
  3643. endif
  3644. endm
  3645. ;*** ClearCParams
  3646. ;
  3647. ; Processes stack clean up
  3648. ;
  3649. ; This routine will trade size for speed (if requested)
  3650. ; by using `pop ecx' to clean off one or two arguments.
  3651. ; This relies on the convention that C-call routines do
  3652. ; not return useful information in ECX.
  3653. ;
  3654. ; To disable this optimization, define the symbol NONSTANDARD_CCALL.
  3655. ;
  3656. ; If flags must be preserved, pass PRESERVE_FLAGS as an argument.
  3657. ; This will generate bigger, slower code, so use it only when
  3658. ; necessary.
  3659. ClearCParams macro fPreserveFlags
  3660. if ??_argc ne 0
  3661. if (??_popargs) AND (??_argc LE 2)
  3662. rept ??_argc
  3663. pop ecx
  3664. endm
  3665. elseifidni <fPreserveFlags>, <PRESERVE_FLAGS>
  3666. lea esp, [esp][??_argc * 4]
  3667. else
  3668. add esp,??_argc * 4
  3669. endif
  3670. endif
  3671. ??_pushed = ??_pushed - (??_argc * 4)
  3672. endm
  3673. ; Makes a macro that will push argment when invoke - used by cCall only
  3674. ?marg macro name, num
  3675. .xcref
  3676. .xcref ?AM&num
  3677. .cref
  3678. ?AM&num &macro
  3679. push name
  3680. ??_pushed = ??_pushed + 4
  3681. &endm
  3682. endm
  3683. .xcref ?marg
  3684. ; Concatenates, invokes and purges a macro name - used by PushCParams
  3685. ?invprg macro name1, name2
  3686. name1&name2
  3687. purge name1&name2
  3688. endm
  3689. .xcref ?invprg
  3690. ; Calls a concatenated standard call name and makes it external
  3691. ?scall macro prefix, name1, name2
  3692. CondExtern prefix&name1&@&name2, near
  3693. call prefix&name1&@&name2
  3694. endm
  3695. .xcref ?scall
  3696. ; Equates name to a name
  3697. ?merge macro l1, l2, l3, l4, op, r1, r2, r3, r4, r5, r6, r7, r8, r9
  3698. l1&l2&l3&l4 op r1&r2&r3&r4&r5&r6&r7&r8&r9
  3699. endm
  3700. ; Converts string to upper-case, returned in ?upper
  3701. ?toupper macro s
  3702. ?upper equ <>
  3703. irpc x,<s>
  3704. if '&x' GE 'a'
  3705. if '&x' LE 'z'
  3706. ?t1 substr <ABCDEFGHIJKLMNOPQRSTUVWXYZ>,'&x'-'a'+1,1
  3707. ?upper catstr ?upper,?t1
  3708. else
  3709. ?upper catstr ?upper,<&x>
  3710. endif
  3711. else
  3712. ?upper catstr ?upper,<&x>
  3713. endif
  3714. endm
  3715. endm
  3716. .xcref
  3717. ;*** CondExtern - Make name external if not already defined
  3718. ;
  3719. ; This operation is quite different between MASM 5.1 and 6.0.
  3720. ;
  3721. CondExtern macro name,dist
  3722. ifdef MASM6
  3723. ifndef name
  3724. externdef name:dist
  3725. endif
  3726. else
  3727. if2
  3728. ifndef name
  3729. extrn name:dist
  3730. endif
  3731. endif
  3732. endif
  3733. endm
  3734. ;*** SaveReg - Save register, "fd" pushes flags, "ad" pushes all
  3735. SaveReg macro reglist ;; push those registers
  3736. irp reg,<reglist>
  3737. ifidni <reg>, <fd>
  3738. pushfd
  3739. ??_pushed = ??_pushed + 4
  3740. else
  3741. ifidni <reg>, <ad>
  3742. pushad
  3743. ??_pushed = ??_pushed + SIZE Pushad_Struc
  3744. else
  3745. push reg
  3746. ??_pushed = ??_pushed + 4
  3747. endif
  3748. endif
  3749. endm
  3750. endm
  3751. ;*** RestoreReg - Restore register, "fd" pops flags, "ad" pops all
  3752. ;
  3753. ; Note that registers must be restored in reverse order that they
  3754. ; were saved.
  3755. ;
  3756. RestoreReg macro reglist ;; pop those registers
  3757. irp reg,<reglist>
  3758. ifidni <reg>, <fd>
  3759. popfd
  3760. ??_pushed = ??_pushed - 4
  3761. else
  3762. ifidni <reg>, <ad>
  3763. popad
  3764. ??_pushed = ??_pushed - SIZE Pushad_Struc
  3765. else
  3766. pop reg
  3767. ??_pushed = ??_pushed - 4
  3768. endif
  3769. endif
  3770. endm
  3771. endm
  3772. */
  3773. #ifdef DEBUG
  3774. /******************************************************************************
  3775. * The following macros are for enabling procedure call profile counting
  3776. * of VxD's written in assembler.
  3777. *
  3778. * Begin_Profile_List needs to be used in the file that declares the device
  3779. * immediately after the Declare_Virtual_Device line. Then one Profile_Link
  3780. * line is required for each individual source file. The list is ended with
  3781. * the End_Profile_List macro. Profiling only works for debug builds and
  3782. * the sources must all be built with "-Dprofileall" masm switch.
  3783. ******************************************************************************/
  3784. /* ASM
  3785. Begin_Profile_List macro devname
  3786. ifdef profileall
  3787. VxD_DATA_SEG
  3788. db 'PROCLIST'
  3789. PUBLIC devname&_Proc_Profile_List
  3790. devname&_Proc_Profile_List label dword
  3791. endif
  3792. endm
  3793. Profile_Link macro modname
  3794. ifdef profileall
  3795. ifdifi <modname>,@filename
  3796. EXTRN _&modname&__proc_list:near
  3797. endif
  3798. dd OFFSET32 _&modname&__proc_list
  3799. endif
  3800. endm
  3801. End_Profile_List macro
  3802. ifdef profileall
  3803. dd 0
  3804. VxD_DATA_ENDS
  3805. endif
  3806. endm
  3807. */
  3808. #endif
  3809. #ifndef Not_VxD
  3810. /******************************************************************************
  3811. * S C H E D U L E R B O O S T V A L U E S
  3812. *****************************************************************************/
  3813. #define RESERVED_LOW_BOOST 0x00000001
  3814. #define CUR_RUN_VM_BOOST 0x00000004
  3815. #define LOW_PRI_DEVICE_BOOST 0x00000010
  3816. #define HIGH_PRI_DEVICE_BOOST 0x00001000
  3817. #define CRITICAL_SECTION_BOOST 0x00100000
  3818. #define TIME_CRITICAL_BOOST 0x00400000
  3819. #define RESERVED_HIGH_BOOST 0x40000000
  3820. /******************************************************************************
  3821. * F L A G S F O R C A L L _ P R I O R I T Y _ V M _ E V E N T
  3822. *****************************************************************************/
  3823. #define PEF_WAIT_FOR_STI_BIT 0
  3824. #define PEF_WAIT_FOR_STI (1 << PEF_WAIT_FOR_STI_BIT)
  3825. #define PEF_WAIT_NOT_CRIT_BIT 1
  3826. #define PEF_WAIT_NOT_CRIT (1 << PEF_WAIT_NOT_CRIT_BIT)
  3827. #define PEF_DONT_UNBOOST_BIT 2
  3828. #define PEF_DONT_UNBOOST (1 << PEF_DONT_UNBOOST_BIT)
  3829. #define PEF_ALWAYS_SCHED_BIT 3
  3830. #define PEF_ALWAYS_SCHED (1 << PEF_ALWAYS_SCHED_BIT)
  3831. #define PEF_TIME_OUT_BIT 4
  3832. #define PEF_TIME_OUT (1 << PEF_TIME_OUT_BIT)
  3833. #define PEF_WAIT_NOT_HW_INT_BIT 5
  3834. #define PEF_WAIT_NOT_HW_INT (1 << PEF_WAIT_NOT_HW_INT_BIT)
  3835. #define PEF_WAIT_NOT_NESTED_EXEC_BIT 6
  3836. #define PEF_WAIT_NOT_NESTED_EXEC (1 << PEF_WAIT_NOT_NESTED_EXEC_BIT)
  3837. #define PEF_WAIT_IN_PM_BIT 7
  3838. #define PEF_WAIT_IN_PM (1 << PEF_WAIT_IN_PM_BIT)
  3839. #define PEF_THREAD_EVENT_BIT 8
  3840. #define PEF_THREAD_EVENT (1 << PEF_THREAD_EVENT_BIT)
  3841. #define PEF_WAIT_FOR_THREAD_STI_BIT 9
  3842. #define PEF_WAIT_FOR_THREAD_STI (1 << PEF_WAIT_FOR_THREAD_STI_BIT)
  3843. #define PEF_RING0_EVENT_BIT 10
  3844. #define PEF_RING0_EVENT (1 << PEF_RING0_EVENT_BIT)
  3845. #define PEF_WAIT_CRIT_BIT 11
  3846. #define PEF_WAIT_CRIT (1 << PEF_WAIT_CRIT_BIT)
  3847. #define PEF_WAIT_CRIT_VM_BIT 12
  3848. #define PEF_WAIT_CRIT_VM (1 << PEF_WAIT_CRIT_VM_BIT)
  3849. #define PEF_PROCESS_LAST_BIT 13
  3850. #define PEF_PROCESS_LAST (1 << PEF_PROCESS_LAST_BIT)
  3851. #define PEF_WAIT_PREEMPTABLE_BIT 14
  3852. #define PEF_WAIT_PREEMPTABLE (1 << PEF_WAIT_PREEMPTABLE_BIT)
  3853. // synonyms for event restrictions above
  3854. #define PEF_WAIT_NOT_TIME_CRIT_BIT PEF_WAIT_NOT_HW_INT_BIT
  3855. #define PEF_WAIT_NOT_TIME_CRIT PEF_WAIT_NOT_HW_INT
  3856. #define PEF_WAIT_NOT_PM_LOCKED_STACK_BIT PEF_WAIT_NOT_NESTED_EXEC_BIT
  3857. #define PEF_WAIT_NOT_PM_LOCKED_STACK PEF_WAIT_NOT_NESTED_EXEC
  3858. /******************************************************************************
  3859. * F L A G S F O R B E G I N _ C R I T I C A L _ S E C T I O N,
  3860. * E N T E R _ M U T E X
  3861. * A N D W A I T _ S E M A P H O R E
  3862. *****************************************************************************/
  3863. #define BLOCK_SVC_INTS_BIT 0
  3864. #define BLOCK_SVC_INTS (1 << BLOCK_SVC_INTS_BIT)
  3865. #define BLOCK_SVC_IF_INTS_LOCKED_BIT 1
  3866. #define BLOCK_SVC_IF_INTS_LOCKED (1 << BLOCK_SVC_IF_INTS_LOCKED_BIT)
  3867. #define BLOCK_ENABLE_INTS_BIT 2
  3868. #define BLOCK_ENABLE_INTS (1 << BLOCK_ENABLE_INTS_BIT)
  3869. #define BLOCK_POLL_BIT 3
  3870. #define BLOCK_POLL (1 << BLOCK_POLL_BIT)
  3871. #define BLOCK_THREAD_IDLE_BIT 4
  3872. #define BLOCK_THREAD_IDLE (1 << BLOCK_THREAD_IDLE_BIT)
  3873. #define BLOCK_FORCE_SVC_INTS_BIT 5
  3874. #define BLOCK_FORCE_SVC_INTS (1 << BLOCK_FORCE_SVC_INTS_BIT)
  3875. /******************************************************************************
  3876. * The following structures are pointed to by EBP when VxD routines are
  3877. * entered, both for VxD control calls and traps(I/O traps, software INT
  3878. * traps, etc.). The first structure as DWORD values, the second WORD
  3879. * values and the last has BYTE values.
  3880. *****************************************************************************/
  3881. struct Client_Reg_Struc {
  3882. ULONG Client_EDI; /* Client's EDI */
  3883. ULONG Client_ESI; /* Client's ESI */
  3884. ULONG Client_EBP; /* Client's EBP */
  3885. ULONG Client_res0; /* ESP at pushall */
  3886. ULONG Client_EBX; /* Client's EBX */
  3887. ULONG Client_EDX; /* Client's EDX */
  3888. ULONG Client_ECX; /* Client's ECX */
  3889. ULONG Client_EAX; /* Client's EAX */
  3890. ULONG Client_Error; /* Dword error code */
  3891. ULONG Client_EIP; /* EIP */
  3892. USHORT Client_CS; /* CS */
  3893. USHORT Client_res1; /* (padding) */
  3894. ULONG Client_EFlags; /* EFLAGS */
  3895. ULONG Client_ESP; /* ESP */
  3896. USHORT Client_SS; /* SS */
  3897. USHORT Client_res2; /* (padding) */
  3898. USHORT Client_ES; /* ES */
  3899. USHORT Client_res3; /* (padding) */
  3900. USHORT Client_DS; /* DS */
  3901. USHORT Client_res4; /* (padding) */
  3902. USHORT Client_FS; /* FS */
  3903. USHORT Client_res5; /* (padding) */
  3904. USHORT Client_GS; /* GS */
  3905. USHORT Client_res6; /* (padding) */
  3906. ULONG Client_Alt_EIP;
  3907. USHORT Client_Alt_CS;
  3908. USHORT Client_res7;
  3909. ULONG Client_Alt_EFlags;
  3910. ULONG Client_Alt_ESP;
  3911. USHORT Client_Alt_SS;
  3912. USHORT Client_res8;
  3913. USHORT Client_Alt_ES;
  3914. USHORT Client_res9;
  3915. USHORT Client_Alt_DS;
  3916. USHORT Client_res10;
  3917. USHORT Client_Alt_FS;
  3918. USHORT Client_res11;
  3919. USHORT Client_Alt_GS;
  3920. USHORT Client_res12;
  3921. };
  3922. struct Client_Word_Reg_Struc {
  3923. USHORT Client_DI; /* Client's DI */
  3924. USHORT Client_res13; /* (padding) */
  3925. USHORT Client_SI; /* Client's SI */
  3926. USHORT Client_res14; /* (padding) */
  3927. USHORT Client_BP; /* Client's BP */
  3928. USHORT Client_res15; /* (padding) */
  3929. ULONG Client_res16; /* ESP at pushall */
  3930. USHORT Client_BX; /* Client's BX */
  3931. USHORT Client_res17; /* (padding) */
  3932. USHORT Client_DX; /* Client's DX */
  3933. USHORT Client_res18; /* (padding) */
  3934. USHORT Client_CX; /* Client's CX */
  3935. USHORT Client_res19; /* (padding) */
  3936. USHORT Client_AX; /* Client's AX */
  3937. USHORT Client_res20; /* (padding) */
  3938. ULONG Client_res21; /* Dword error code */
  3939. USHORT Client_IP; /* Client's IP */
  3940. USHORT Client_res22; /* (padding) */
  3941. ULONG Client_res23; /* CS */
  3942. USHORT Client_Flags; /* Client's flags (low) */
  3943. USHORT Client_res24; /* (padding) */
  3944. USHORT Client_SP; /* SP */
  3945. USHORT Client_res25;
  3946. ULONG Client_res26[5];
  3947. USHORT Client_Alt_IP;
  3948. USHORT Client_res27;
  3949. ULONG Client_res28;
  3950. USHORT Client_Alt_Flags;
  3951. USHORT Client_res29;
  3952. USHORT Client_Alt_SP;
  3953. };
  3954. struct Client_Byte_Reg_Struc {
  3955. ULONG Client_res30[4]; /* EDI, ESI, EBP, ESP at pushall */
  3956. UCHAR Client_BL; /* Client's BL */
  3957. UCHAR Client_BH; /* Client's BH */
  3958. USHORT Client_res31;
  3959. UCHAR Client_DL; /* Client's DL */
  3960. UCHAR Client_DH; /* Client's DH */
  3961. USHORT Client_res32;
  3962. UCHAR Client_CL; /* Client's CL */
  3963. UCHAR Client_CH; /* Client's CH */
  3964. USHORT Client_res33;
  3965. UCHAR Client_AL; /* Client's AL */
  3966. UCHAR Client_AH; /* Client's AH */
  3967. };
  3968. typedef union tagCLIENT_STRUC { /* */
  3969. struct Client_Reg_Struc CRS;
  3970. struct Client_Word_Reg_Struc CWRS;
  3971. struct Client_Byte_Reg_Struc CBRS;
  3972. } CLIENT_STRUCT;
  3973. typedef struct Client_Reg_Struc CRS;
  3974. typedef CRS *PCRS;
  3975. #if 0 /* causes problems with MASM 6 */
  3976. /* ASM
  3977. .ERRNZ Client_SP - Client_ESP
  3978. .ERRNZ Client_AL - Client_EAX
  3979. */
  3980. #endif
  3981. #define DYNA_LINK_INT 0x20
  3982. /* ASM
  3983. ;*** DeclareNonstandardCcallService
  3984. ;
  3985. ; Declare services as conforming to the C calling convention
  3986. ; for parameter-passing, but *not* conforming to the C calling
  3987. ; convention for register usage.
  3988. ;
  3989. ; Services which do not use the C calling convention for
  3990. ; parameter-passing need not be declared as nonstandard.
  3991. ;
  3992. ; arglst - list of services to declare as nonstandard
  3993. ;
  3994. DeclareNonstandardCcallService macro arglst
  3995. irp x,<arglst>
  3996. ??_nonstandardccall_&&x = 1
  3997. endm
  3998. endm
  3999. ;
  4000. ; The following VMM services are nonstandard:
  4001. ; _BlockOnID and _LocalizeSprintf modify no registers except flags.
  4002. ; _SetLastV86Page modifies no registers except EAX and flags.
  4003. ;
  4004. DeclareNonstandardCcallService <_BlockOnID, _LocalizeSprintf>
  4005. DeclareNonstandardCcallService <_SetLastV86Page>
  4006. BeginDoc
  4007. ;******************************************************************************
  4008. ; The VMMCall and VxDCall macros provide a dynamic link to the VMM and VxD
  4009. ; service routines. For example:
  4010. ;
  4011. ; VMMCall Enable_VM_Ints ; Equivalent to STI in VM code
  4012. ;
  4013. ; mov eax,[My_IRQ_Handle]
  4014. ; VxDCall VPICD_Set_Int_Request ; Set IRQ for my device's interrupt
  4015. ;
  4016. ; Note that Enable_VM_Ints is defined in VMM.INC and VPICD_Set_Int_Request is
  4017. ; defined in VPICD.INC
  4018. ;
  4019. ;==============================================================================
  4020. EndDoc
  4021. BeginDoc
  4022. ;******************************************************************************
  4023. ; VxDCall
  4024. ;==============================================================================
  4025. ;
  4026. ; BlockOnID is always FAST because it doesn't
  4027. ; conform to the C calling convention. (It preserves
  4028. ; all registers.)
  4029. EndDoc
  4030. DefTable MACRO vt, vn
  4031. vt EQU <vn>
  4032. ENDM
  4033. GenDD2 MACRO vt, sn, jf
  4034. dd OFFSET32 vt[sn+jf]
  4035. ENDM
  4036. GenDD MACRO P, vid, snum, jflag
  4037. LOCAL vtable
  4038. IFDEF @@VxDName&vid
  4039. Deftable vtable, %@@VxDName&vid
  4040. EXTRN vtable:DWORD
  4041. GenDD2 %vtable, snum, jflag
  4042. ELSE
  4043. dd @@&P+jflag
  4044. ENDIF
  4045. ENDM
  4046. VxDCall MACRO P, Param, flags
  4047. ??_vxdid = (@@&P SHR 16)
  4048. ??_servicenum = (@@&P AND 0FFFFh)
  4049. ifdef ??_standardccall_&P
  4050. PushCParams <Param>, <FAST>
  4051. .errnz ??_argc ne ??_standardccall_&P, <wrong # of parameters passed to &P&>
  4052. else
  4053. ifdef ??_fastcall_&P
  4054. PushCParams <Param>, <FASTCALL>
  4055. .errnz ??_argc ne (??_fastcall_&P), <wrong # of parameters passed to fastcall function &P&>
  4056. else
  4057. ifdef ??_nonstandardccall_&P
  4058. PushCParams <Param>, <flags>
  4059. else
  4060. PushCParams <Param>, <FAST>
  4061. endif
  4062. endif
  4063. endif
  4064. int Dyna_Link_Int
  4065. GenDD P, %??_vxdid, %??_servicenum, 0
  4066. ifndef ??_standardccall_&P
  4067. ifndef ??_fastcall_&P
  4068. ifdef ??_nonstandardccall_&P
  4069. ClearCParams PRESERVE_FLAGS
  4070. else
  4071. ClearCParams
  4072. endif
  4073. else
  4074. if(??_argc gt 2)
  4075. ??_pushed = ??_pushed - ((??_argc - 2) * 4)
  4076. endif
  4077. endif
  4078. else
  4079. ??_pushed = ??_pushed - (??_argc * 4)
  4080. endif
  4081. ENDM
  4082. VxDJmp MACRO P, Param
  4083. ??_vxdid = (@@&P SHR 16)
  4084. ??_servicenum = (@@&P AND 0FFFFh)
  4085. ifdef ??_fastcall_&P
  4086. PushCParams <Param>, <FASTCALL>
  4087. .errnz ??_argc gt 2, <More than 2 parameters may not be passed to fastcall functions thru VxDJmp>
  4088. else
  4089. .errnb <Param>, <Parameters may not be passed to VxDJmp or VMMJmp>
  4090. endif
  4091. int Dyna_Link_Int
  4092. GenDD P, %??_vxdid, %??_servicenum, DL_Jmp_Mask
  4093. ENDM
  4094. DL_Jmp_Mask EQU 8000h
  4095. DL_Jmp_Bit EQU 0Fh
  4096. VMMCall MACRO P, Param
  4097. .ERRNZ (@@&P SHR 16) - VMM_DEVICE_ID
  4098. VxDCall <P>, <Param>
  4099. ENDM
  4100. VMMJmp MACRO P, Param
  4101. .ERRNZ (@@&P SHR 16) - VMM_DEVICE_ID
  4102. VxDJmp <P>, <Param>
  4103. ENDM
  4104. BeginDoc
  4105. ;******************************************************************************
  4106. ; Segment definition macros
  4107. ;
  4108. ; The segment definition macros are a convenience used in defining the
  4109. ; segments used by the device driver. They are:
  4110. ;VxD_INIT_CODE_SEG defines start of initialization code segment
  4111. ;VxD_INIT_CODE_ENDS defines end of initialization code segment
  4112. ;VxD_ICODE_SEG is an alias for VxD_INIT_CODE_SEG
  4113. ;VxD_ICODE_ENDS is an alias for VxD_INIT_CODE_ENDS
  4114. ;VxD_IDATA_SEG defines start of initialization data segment
  4115. ;VxD_IDATA_ENDS defines end of initialization data segment
  4116. ;VxD_CODE_SEG defines start of always present code segment
  4117. ;VxD_CODE_ENDS defines end of always present code segment
  4118. ;VxD_DATA_SEG defines start of always present data segment
  4119. ;VxD_DATA_ENDS defines end of always present data segment
  4120. ;VxD_LOCKED_CODE_SEG defines start of always present code segment
  4121. ;VxD_LOCKED_CODE_ENDS defines end of always present code segment
  4122. ;VxD_PAGEABLE_CODE_SEG defines start of swappable code segment
  4123. ;VxD_PAGEABLE_CODE_ENDS defines end of swappable code segment
  4124. ;VxD_DEBUG_ONLY_CODE_SEG defines code only loaded if debugger is present
  4125. ;VxD_DEBUG_ONLY_CODE_ENDS
  4126. ;VxD_DEBUG_ONLY_DATA_SEG defines data only loaded if debugger is present
  4127. ;VxD_DEBUG_ONLY_DATA_ENDS
  4128. ;==============================================================================
  4129. EndDoc
  4130. ; Resident protected mode code
  4131. VxD_CODE_SEG EQU <VxD_LOCKED_CODE_SEG>
  4132. VxD_CODE_ENDS EQU <VxD_LOCKED_CODE_ENDS>
  4133. VxD_LOCKED_CODE_SEG MACRO
  4134. _LTEXT SEGMENT
  4135. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_LCODE
  4136. ASSUME cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  4137. ENDM
  4138. VxD_LOCKED_CODE_ENDS MACRO
  4139. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  4140. _LTEXT ENDS
  4141. ENDM
  4142. ; Pageable protected mode code
  4143. VxD_PAGEABLE_CODE_SEG MACRO
  4144. _PTEXT SEGMENT
  4145. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_PCODE
  4146. ASSUME cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  4147. ENDM
  4148. VxD_PAGEABLE_CODE_ENDS MACRO
  4149. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  4150. _PTEXT ENDS
  4151. ENDM
  4152. ; Debug only protected mode code
  4153. VxD_DEBUG_ONLY_CODE_SEG MACRO
  4154. _DBOCODE SEGMENT
  4155. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_DBOCODE
  4156. ASSUME cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  4157. ENDM
  4158. VxD_DEBUG_ONLY_CODE_ENDS MACRO
  4159. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  4160. _DBOCODE ENDS
  4161. ENDM
  4162. ; Protected mode initialization code
  4163. VxD_INIT_CODE_SEG MACRO
  4164. _ITEXT SEGMENT
  4165. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_ICODE
  4166. ASSUME cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  4167. ENDM
  4168. VxD_INIT_CODE_ENDS MACRO
  4169. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  4170. _ITEXT ENDS
  4171. ENDM
  4172. VxD_ICODE_SEG equ VxD_INIT_CODE_SEG
  4173. VxD_ICODE_ENDS equ VxD_INIT_CODE_ENDS
  4174. ; Resident protected mode data
  4175. VxD_DATA_SEG EQU <VxD_LOCKED_DATA_SEG>
  4176. VxD_DATA_ENDS EQU <VxD_LOCKED_DATA_ENDS>
  4177. VxD_LOCKED_DATA_SEG MACRO NO_ALIGN
  4178. _LDATA SEGMENT
  4179. IFB <NO_ALIGN>
  4180. ALIGN 4
  4181. ENDIF
  4182. ENDM
  4183. VxD_LOCKED_DATA_ENDS MACRO
  4184. _LDATA ENDS
  4185. ENDM
  4186. ; Protected mode initialization data
  4187. VxD_IDATA_SEG MACRO
  4188. _IDATA SEGMENT
  4189. ENDM
  4190. VxD_IDATA_ENDS MACRO
  4191. _IDATA ENDS
  4192. ENDM
  4193. ; Pageable protected mode data
  4194. VxD_PAGEABLE_DATA_SEG MACRO NO_ALIGN
  4195. _PDATA SEGMENT
  4196. IFB <NO_ALIGN>
  4197. ALIGN 4
  4198. ENDIF
  4199. ENDM
  4200. VxD_PAGEABLE_DATA_ENDS MACRO
  4201. _PDATA ENDS
  4202. ENDM
  4203. ; Static code segment for DL-VxDs
  4204. VxD_STATIC_CODE_SEG MACRO
  4205. _STEXT SEGMENT
  4206. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_SCODE
  4207. ASSUME cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  4208. ENDM
  4209. VxD_STATIC_CODE_ENDS MACRO
  4210. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  4211. _STEXT ENDS
  4212. ENDM
  4213. ; Static data segment for DL-VxDs
  4214. VxD_STATIC_DATA_SEG MACRO NO_ALIGN
  4215. _SDATA SEGMENT
  4216. IFB <NO_ALIGN>
  4217. ALIGN 4
  4218. ENDIF
  4219. ENDM
  4220. VxD_STATIC_DATA_ENDS MACRO
  4221. _SDATA ENDS
  4222. ENDM
  4223. ; Debug only protected mode data
  4224. VxD_DEBUG_ONLY_DATA_SEG MACRO NO_ALIGN
  4225. _DBODATA SEGMENT
  4226. IFB <NO_ALIGN>
  4227. ALIGN 4
  4228. ENDIF
  4229. ENDM
  4230. VxD_DEBUG_ONLY_DATA_ENDS MACRO
  4231. _DBODATA ENDS
  4232. ENDM
  4233. ; 16 bit code/data put in the init group (IGROUP)
  4234. VxD_16BIT_INIT_SEG MACRO
  4235. _16ICODE SEGMENT
  4236. ASSUME CS:_16ICODE, DS:NOTHING, ES:NOTHING, SS:NOTHING
  4237. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_16ICODE
  4238. ENDM
  4239. VxD_16BIT_INIT_ENDS MACRO
  4240. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  4241. _16ICODE ENDS
  4242. ENDM
  4243. ; Real mode segment (16 bit)
  4244. VxD_REAL_INIT_SEG MACRO
  4245. _RCODE SEGMENT
  4246. ASSUME CS:_RCODE, DS:_RCODE, ES:_RCODE, SS:_RCODE
  4247. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_RCODE
  4248. ENDM
  4249. VxD_REAL_INIT_ENDS MACRO
  4250. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  4251. _RCODE ENDS
  4252. ENDM
  4253. */
  4254. #endif // Not_VxD
  4255. #ifndef DDK_VERSION
  4256. #ifdef WIN31COMPAT
  4257. #define DDK_VERSION 0x30A /* 3.10 */
  4258. #else // WIN31COMPAT
  4259. #ifdef WIN40COMPAT
  4260. #define DDK_VERSION 0x400 /* 4.00 */
  4261. #else // WIN40COMPAT
  4262. #ifdef OPK3
  4263. #define DDK_VERSION 0x403 /* 4.03 */
  4264. #else // OPK3
  4265. #define DDK_VERSION 0x40A /*Memphis is 4.1 */
  4266. #endif // OPK3
  4267. #endif // WIN40COMPAT
  4268. #endif // WIN31COMPAT
  4269. #endif // DDK_VERSION
  4270. struct VxD_Desc_Block {
  4271. ULONG DDB_Next; /* VMM RESERVED FIELD */
  4272. USHORT DDB_SDK_Version; /* INIT <DDK_VERSION> RESERVED FIELD */
  4273. USHORT DDB_Req_Device_Number; /* INIT <UNDEFINED_DEVICE_ID> */
  4274. UCHAR DDB_Dev_Major_Version; /* INIT <0> Major device number */
  4275. UCHAR DDB_Dev_Minor_Version; /* INIT <0> Minor device number */
  4276. USHORT DDB_Flags; /* INIT <0> for init calls complete */
  4277. UCHAR DDB_Name[8]; /* AINIT <" "> Device name */
  4278. ULONG DDB_Init_Order; /* INIT <UNDEFINED_INIT_ORDER> */
  4279. ULONG DDB_Control_Proc; /* Offset of control procedure */
  4280. ULONG DDB_V86_API_Proc; /* INIT <0> Offset of API procedure */
  4281. ULONG DDB_PM_API_Proc; /* INIT <0> Offset of API procedure */
  4282. ULONG DDB_V86_API_CSIP; /* INIT <0> CS:IP of API entry point */
  4283. ULONG DDB_PM_API_CSIP; /* INIT <0> CS:IP of API entry point */
  4284. ULONG DDB_Reference_Data; /* Reference data from real mode */
  4285. ULONG DDB_Service_Table_Ptr; /* INIT <0> Pointer to service table */
  4286. ULONG DDB_Service_Table_Size; /* INIT <0> Number of services */
  4287. ULONG DDB_Win32_Service_Table; /* INIT <0> Pointer to Win32 services */
  4288. ULONG DDB_Prev; /* INIT <'Prev'> Ptr to prev 4.0 DDB */
  4289. ULONG DDB_Size; /* INIT <SIZE(VxD_Desc_Block)> Reserved */
  4290. ULONG DDB_Reserved1; /* INIT <'Rsv1'> Reserved */
  4291. ULONG DDB_Reserved2; /* INIT <'Rsv2'> Reserved */
  4292. ULONG DDB_Reserved3; /* INIT <'Rsv3'> Reserved */
  4293. };
  4294. typedef struct VxD_Desc_Block *PVMMDDB;
  4295. typedef PVMMDDB *PPVMMDDB;
  4296. #ifndef Not_VxD
  4297. /*
  4298. * Flag values for DDB_Flags
  4299. */
  4300. #define DDB_SYS_CRIT_INIT_DONE_BIT 0
  4301. #define DDB_SYS_CRIT_INIT_DONE (1 << DDB_SYS_CRIT_INIT_DONE_BIT)
  4302. #define DDB_DEVICE_INIT_DONE_BIT 1
  4303. #define DDB_DEVICE_INIT_DONE (1 << DDB_DEVICE_INIT_DONE_BIT)
  4304. #define DDB_HAS_WIN32_SVCS_BIT 14
  4305. #define DDB_HAS_WIN32_SVCS (1 << DDB_HAS_WIN32_SVCS_BIT)
  4306. #define DDB_DYNAMIC_VXD_BIT 15
  4307. #define DDB_DYNAMIC_VXD (1 << DDB_DYNAMIC_VXD_BIT)
  4308. #define DDB_DEVICE_DYNALINKED_BIT 13
  4309. #define DDB_DEVICE_DYNALINKED (1 << DDB_DEVICE_DYNALINKED_BIT)
  4310. /* ASM
  4311. BeginDoc
  4312. ;******************************************************************************
  4313. ;
  4314. ; Declare_Virtual_Device macro
  4315. ;
  4316. ; ???? Write something here ????
  4317. ;
  4318. ;==============================================================================
  4319. EndDoc
  4320. Declare_Virtual_Device MACRO Name, Major_Ver, Minor_Ver, Ctrl_Proc, Device_Num, Init_Order, V86_Proc, PM_Proc, Reference_Data
  4321. LOCAL V86_API_Offset, PM_API_Offset, Serv_Tab_Offset, Serv_Tab_Len, Ref_Data_Offset
  4322. dev_id_err MACRO
  4323. IFNDEF Name&_Name_Based
  4324. .err <Device ID required when providing services>
  4325. ENDIF
  4326. ENDM
  4327. IFB <V86_Proc>
  4328. V86_API_Offset EQU 0
  4329. ELSE
  4330. IFB <Device_Num>
  4331. dev_id_err
  4332. ENDIF
  4333. V86_API_Offset EQU <OFFSET32 V86_Proc>
  4334. ENDIF
  4335. IFB <PM_Proc>
  4336. PM_API_Offset EQU 0
  4337. ELSE
  4338. IFB <Device_Num>
  4339. dev_id_err
  4340. ENDIF
  4341. PM_API_Offset EQU <OFFSET32 PM_Proc>
  4342. ENDIF
  4343. IFDEF Name&_Service_Table
  4344. IFB <Device_Num>
  4345. dev_id_err
  4346. ELSE
  4347. IFE Device_Num - UNDEFINED_DEVICE_ID
  4348. dev_id_err
  4349. ENDIF
  4350. ENDIF
  4351. Serv_Tab_Offset EQU <OFFSET32 Name&_Service_Table>
  4352. Serv_Tab_Len EQU Num_&Name&_Services
  4353. ELSE
  4354. Serv_Tab_Offset EQU 0
  4355. Serv_Tab_Len EQU 0
  4356. ENDIF
  4357. IFNB <Device_Num>
  4358. .erre (Device_Num LT BASEID_FOR_NAMEBASEDVXD), <Device ID must be less than BASEID_FOR_NAMEBASEDVXD>
  4359. ENDIF
  4360. IFB <Reference_Data>
  4361. Ref_Data_Offset EQU 0
  4362. ELSE
  4363. Ref_Data_Offset EQU <OFFSET32 Reference_Data>
  4364. ENDIF
  4365. IFDEF DEBUG
  4366. VxD_IDATA_SEG
  4367. db 0dh, 0ah, 'D_E_B_U_G===>'
  4368. db "&Name", '<===', 0dh, 0ah
  4369. VxD_IDATA_ENDS
  4370. ENDIF
  4371. VxD_LOCKED_DATA_SEG
  4372. PUBLIC Name&_DDB
  4373. Name&_DDB VxD_Desc_Block <,,Device_Num,Major_Ver,Minor_Ver,,"&Name",Init_Order,\
  4374. OFFSET32 Ctrl_Proc, V86_API_Offset, PM_API_Offset, \
  4375. ,,Ref_Data_Offset,Serv_Tab_Offset, Serv_Tab_Len>
  4376. VxD_LOCKED_DATA_ENDS
  4377. ENDM
  4378. ;BeginDoc ; comment out to make masm work ???
  4379. ;******************************************************************************
  4380. ; The Begin_Control_Dispatch macro is used for building a table for dispatching
  4381. ; messages passed to the VxD_Control procedure. It is used with
  4382. ; Control_Dispatch and End_Control_Dispatch. The only parameter is used to
  4383. ; contruct the procedure label by adding "_Control" to the end (normally the
  4384. ; device name is used i.e. VKD results in creating the procedure VKD_Control,
  4385. ; this created procedure label must be included in Declare_Virtual_Device)
  4386. ;
  4387. ; An example of building a complete dispatch table:
  4388. ;
  4389. ; Begin_Control_Dispatch MyDevice
  4390. ; Control_Dispatch Device_Init, MyDeviceInitProcedure
  4391. ; Control_Dispatch Sys_VM_Init, MyDeviceSysInitProcedure
  4392. ; Control_Dispatch Create_VM, MyDeviceCreateVMProcedure
  4393. ; End_Control_Dispatch MyDevice
  4394. ;
  4395. ; (NOTE: Control_Dispatch can be used without Begin_Control_Dispatch, but
  4396. ; then it is the programmer's responsibility for declaring a procedure
  4397. ; in locked code (VxD_LOCKED_CODE_SEG) and returning Carry clear for
  4398. ; any messages not processed. The advantage in using
  4399. ; Begin_Control_Dispatch is when a large # of messages are processed by
  4400. ; a device, because a jump table is built which will usually require
  4401. ; less code space then the compares and jumps that are done when
  4402. ; Control_Dispatch is used alone.
  4403. ;
  4404. ;==============================================================================
  4405. ;EndDoc
  4406. Begin_Control_Dispatch MACRO VxD_Name, p1, p2
  4407. ??_cd_low = 0FFFFFFFFh
  4408. ??_cd_high = 0
  4409. BeginProc VxD_Name&_Control, p1, p2, LOCKED
  4410. ENDM
  4411. End_Control_Dispatch MACRO VxD_Name
  4412. LOCAL ignore, table
  4413. procoff MACRO num
  4414. IFDEF ??_cd_&&num
  4415. dd OFFSET32 ??_cd_&&num
  4416. ELSE
  4417. dd OFFSET32 ignore
  4418. ENDIF
  4419. ENDM
  4420. IF ??_cd_low EQ ??_cd_high
  4421. cmp eax, ??_cd_low
  4422. ?merge <jz>,,,,,<??_cd_>, %(??_cd_low)
  4423. clc
  4424. ret
  4425. ELSE
  4426. IF ??_cd_low GT 0
  4427. sub eax, ??_cd_low
  4428. ENDIF ; ??cd_low GT 0
  4429. cmp eax, ??_cd_high - ??_cd_low + 1
  4430. jae short ignore
  4431. jmp [eax*4+table]
  4432. ignore:
  4433. clc ;; this is not redundant
  4434. ret
  4435. table label dword
  4436. REPT ??_cd_high - ??_cd_low + 1
  4437. procoff %(??_cd_low)
  4438. ??_cd_low = ??_cd_low + 1
  4439. ENDM
  4440. ENDIF
  4441. EndProc VxD_Name&_Control
  4442. PURGE procoff
  4443. PURGE Begin_Control_Dispatch
  4444. PURGE Control_Dispatch
  4445. PURGE End_Control_Dispatch
  4446. ENDM
  4447. BeginDoc
  4448. ;******************************************************************************
  4449. ; The Control_Dispatch macro is used for dispatching based on message
  4450. ; passed to the VxD_Control procedure. E.G.:
  4451. ;
  4452. ; Control_Dispatch Device_Init, MyDeviceInitProcedure
  4453. ;
  4454. ; For "C" control functions:
  4455. ;
  4456. ; Control_Dispatch Device_Init, MyDeviceInitProcedure, sCall, <arglst>
  4457. ;
  4458. ; The "callc" can be sCall, cCall or pCall depending on the calling
  4459. ; convention. "arglst" is the list of registers to pass as parameters
  4460. ; to "C" control procedure. The "C" control procedure returns VXD_SUCCESS
  4461. ; or VXD_FAILURE and the carry flag gets set appropriately.
  4462. ;
  4463. ; (NOTE: Control_Dispatch can be used with Begin_Control_Dispatch and
  4464. ; End_Control_Dispatch to create a jump table for dispatching messages,
  4465. ; when a large # of messages are processed.)
  4466. ;
  4467. ;==============================================================================
  4468. EndDoc
  4469. Control_Dispatch MACRO Service, Procedure, callc, arglst
  4470. LOCAL Skip_Interseg_Jump
  4471. .errnz ?_LCODE, <Control_Dispatch must be in VxD_LOCKED_CODE_SEG.>
  4472. IFB <callc>
  4473. IFDEF ??_cd_low
  4474. Equate_Service MACRO Serv
  4475. ??_cd_&&Serv equ Procedure
  4476. ENDM
  4477. Equate_Service %(Service)
  4478. IF Service LT ??_cd_low
  4479. ??_cd_low = Service
  4480. ENDIF
  4481. IF Service GT ??_cd_high
  4482. ??_cd_high = Service
  4483. ENDIF
  4484. PURGE Equate_Service
  4485. ELSE
  4486. cmp eax, Service
  4487. jz Procedure
  4488. ENDIF
  4489. ELSE ; ifb callc
  4490. cmp eax, Service
  4491. jne SHORT Skip_Interseg_Jump
  4492. callc Procedure, <arglst>
  4493. IF Service EQ PNP_NEW_DEVNODE
  4494. stc
  4495. ELSE
  4496. cmp eax,1
  4497. ENDIF
  4498. ret
  4499. Skip_Interseg_Jump:
  4500. ENDIF ; ifb callc
  4501. ENDM
  4502. */
  4503. /******************************************************************************
  4504. * The following are the definitions for the "type of I/O" parameter passed
  4505. * to a I/O trap routine.
  4506. *****************************************************************************/
  4507. #define BYTE_INPUT 0x000
  4508. #define BYTE_OUTPUT 0x004
  4509. #define WORD_INPUT 0x008
  4510. #define WORD_OUTPUT 0x00C
  4511. #define DWORD_INPUT 0x010
  4512. #define DWORD_OUTPUT 0x014
  4513. #define OUTPUT_BIT 2
  4514. #define OUTPUT (1 << OUTPUT_BIT)
  4515. #define WORD_IO_BIT 3
  4516. #define WORD_IO (1 << WORD_IO_BIT)
  4517. #define DWORD_IO_BIT 4
  4518. #define DWORD_IO (1 << DWORD_IO_BIT)
  4519. #define STRING_IO_BIT 5
  4520. #define STRING_IO (1 << STRING_IO_BIT)
  4521. #define REP_IO_BIT 6
  4522. #define REP_IO (1 << REP_IO_BIT)
  4523. #define ADDR_32_IO_BIT 7
  4524. #define ADDR_32_IO (1 << ADDR_32_IO_BIT)
  4525. #define REVERSE_IO_BIT 8
  4526. #define REVERSE_IO (1 << REVERSE_IO_BIT)
  4527. #define IO_SEG_MASK 0x0FFFF0000 /* Use this to get segment */
  4528. #define IO_SEG_SHIFT 0x10 /* Must shift right this many */
  4529. /* ASM
  4530. BeginDoc
  4531. ;******************************************************************************
  4532. ;
  4533. ; Dispatch_Byte_IO macro
  4534. ;
  4535. ; Dispatch_Byte_IO Byte_In_Proc, Byte_Out_Proc
  4536. ;==============================================================================
  4537. EndDoc
  4538. Dispatch_Byte_IO MACRO In_Proc, Out_Proc
  4539. LOCAL Byte_IO
  4540. cmp ecx, Byte_Output
  4541. jbe SHORT Byte_IO
  4542. VMMJmp Simulate_IO
  4543. Byte_IO:
  4544. IFIDNI <In_Proc>, <Fall_Through>
  4545. je Out_Proc
  4546. ELSE
  4547. IFIDNI <Out_Proc>, <Fall_Through>
  4548. jb In_Proc
  4549. ELSE
  4550. je Out_Proc
  4551. jmp In_Proc
  4552. ENDIF
  4553. ENDIF
  4554. ENDM
  4555. BeginDoc
  4556. ;******************************************************************************
  4557. ;
  4558. ; Emulate_Non_Byte_IO
  4559. ;
  4560. ; Emulate_Non_Byte_IO
  4561. ;
  4562. ;==============================================================================
  4563. EndDoc
  4564. Emulate_Non_Byte_IO MACRO
  4565. LOCAL Byte_IO
  4566. cmp ecx, Byte_Output
  4567. jbe SHORT Byte_IO
  4568. VMMJmp Simulate_IO
  4569. Byte_IO:
  4570. ENDM
  4571. */
  4572. /* ASM
  4573. BeginDoc
  4574. ;******************************************************************************
  4575. ;
  4576. ; Begin_VxD_IO_Table
  4577. ;
  4578. ; Example:
  4579. ; Begin_VxD_IO_Table MyTableName
  4580. ;
  4581. ;==============================================================================
  4582. EndDoc
  4583. */
  4584. struct VxD_IOT_Hdr {
  4585. USHORT VxD_IO_Ports;
  4586. };
  4587. struct VxD_IO_Struc {
  4588. USHORT VxD_IO_Port;
  4589. ULONG VxD_IO_Proc;
  4590. };
  4591. /* ASM
  4592. .ERRNZ SIZE VxD_IOT_Hdr - 2 ; Begin_VxD_IO_Table creates a 1 word count hdr
  4593. Begin_VxD_IO_Table MACRO Table_Name
  4594. PUBLIC Table_Name
  4595. Table_Name LABEL WORD
  4596. ifndef MASM6
  4597. IF2
  4598. IFNDEF Table_Name&_Entries
  4599. .err <No End_VxD_IO_Table for &Table_Name>
  4600. ENDIF
  4601. dw Table_Name&_Entries
  4602. ELSE
  4603. dw ?
  4604. ENDIF
  4605. ELSE ; MASM6 - skip the warning message - we'll get it anyway
  4606. dw Table_Name&_Entries
  4607. ENDIF ; MASM6
  4608. ENDM
  4609. .ERRNZ SIZE VxD_IO_Struc - 6 ; VxD_IO creates 6 byte I/O port entries
  4610. VxD_IO MACRO Port, Proc_Name
  4611. dw Port
  4612. dd OFFSET32 Proc_Name
  4613. ENDM
  4614. End_VxD_IO_Table MACRO Table_Name
  4615. IFNDEF Table_Name
  4616. .err <No Begin_VxD_IO_Table for &Table_Name>
  4617. ELSE
  4618. Table_Name&_Entries EQU (($-Table_Name)-2) / (SIZE VxD_IO_Struc)
  4619. IF Table_Name&_Entries LE 0
  4620. .err <Invalid number of port traps in &Table_Name>
  4621. ENDIF
  4622. ENDIF
  4623. ENDM
  4624. ;******************************************************************************
  4625. ;
  4626. ; Push_Client_State takes an optional argument which if equal to the symbol
  4627. ; USES_EDI saves code size by suppressing the preservation of the EDI register.
  4628. ;
  4629. ; Similarly, Pop_Client_State takes an optional argument which if equal to
  4630. ; the symbol USES_ESI saves code size by suppressing the preservation of
  4631. ; the ESI register.
  4632. ;
  4633. ;******************************************************************************
  4634. Push_Client_State MACRO Can_Trash_EDI
  4635. sub esp, SIZE Client_Reg_Struc
  4636. ??_pushed = ??_pushed + SIZE Client_Reg_Struc
  4637. ifidni <Can_Trash_EDI>, <USES_EDI>
  4638. mov edi, esp
  4639. VMMCall Save_Client_State
  4640. else
  4641. push edi
  4642. lea edi, [esp+4]
  4643. VMMCall Save_Client_State
  4644. pop edi
  4645. endif
  4646. ENDM
  4647. Pop_Client_State MACRO Can_Trash_ESI
  4648. ifdifi <Can_Trash_ESI>, <USES_ESI>
  4649. push esi
  4650. lea esi, [esp+4]
  4651. VMMCall Restore_Client_State
  4652. pop esi
  4653. else
  4654. mov esi, esp
  4655. VMMCall Restore_Client_State
  4656. endif
  4657. add esp, SIZE Client_Reg_Struc
  4658. ??_pushed = ??_pushed - SIZE Client_Reg_Struc
  4659. ENDM
  4660. BeginDoc
  4661. ;******************************************************************************
  4662. ;
  4663. ; CallRet -- Call procedure and return. For debugging purposes only.
  4664. ; If compiled with debugging then this will generate a call
  4665. ; followed by a return. If non-debugging version then the
  4666. ; specified label will be jumped to.
  4667. ;
  4668. ; PARAMETERS:
  4669. ; Label_Name = Procedure to be called
  4670. ;
  4671. ; EXIT:
  4672. ; Return from current procedure
  4673. ;
  4674. ;------------------------------------------------------------------------------
  4675. EndDoc
  4676. CallRet MACRO P1, P2
  4677. IFDEF DEBUG
  4678. IFIDNI <P1>, <SHORT>
  4679. call P2
  4680. ELSE
  4681. call P1
  4682. ENDIF
  4683. ret
  4684. ELSE
  4685. jmp P1 P2
  4686. ENDIF
  4687. ENDM
  4688. BeginDoc
  4689. ;******************************************************************************
  4690. ;
  4691. ; VxDCallRet
  4692. ; VMMCallRet -- CallRet for VxDCall and VMMCall.
  4693. ;
  4694. ;------------------------------------------------------------------------------
  4695. EndDoc
  4696. IFDEF DEBUG
  4697. VxDCallRet macro p:req
  4698. VxDCall p
  4699. ret
  4700. endm
  4701. VMMCallRet macro p:req
  4702. VMMCall p
  4703. ret
  4704. endm
  4705. ELSE ; RETAIL
  4706. VxDCallRet equ <VxDJmp>
  4707. VMMCallRet equ <VMMJmp>
  4708. ENDIF
  4709. ; ebp offsets to segments pushed by PMode_Fault in Fault_Dispatch
  4710. PClient_DS equ WORD PTR -4
  4711. PClient_ES equ WORD PTR -8
  4712. PClient_FS equ WORD PTR -12
  4713. PClient_GS equ WORD PTR -16
  4714. ;******************************************************************************
  4715. ;
  4716. ; Client_Ptr_Flat takes an optional third argument which if equal to the
  4717. ; symbol USES_EAX saves code size by supressing the preservation of the
  4718. ; EAX register. The USES_EAX flag is ignored if the destination register
  4719. ; is itself EAX.
  4720. ;
  4721. ;******************************************************************************
  4722. Client_Ptr_Flat MACRO Reg_32, Cli_Seg, Cli_Off, Can_Trash_EAX
  4723. IFDIFI <Reg_32>, <EAX>
  4724. IFDIFI <Can_Trash_EAX>, <USES_EAX>
  4725. xchg Reg_32, eax
  4726. ENDIF
  4727. ENDIF
  4728. IFB <Cli_Off>
  4729. mov ax, (Client_&Cli_Seg * 100h) + 0FFh
  4730. ELSE
  4731. mov ax, (Client_&Cli_Seg * 100h) + Client_&Cli_Off
  4732. ENDIF
  4733. VMMCall Map_Flat
  4734. IFDIFI <Reg_32>, <EAX>
  4735. xchg Reg_32, eax
  4736. ENDIF
  4737. ENDM
  4738. ;------------------------------------------------------------------------------
  4739. VxDint MACRO Int_Number
  4740. if (OPATTR Int_Number) AND 4
  4741. push Int_Number
  4742. else
  4743. push DWORD PTR Int_Number
  4744. endif
  4745. VMMCall Exec_VxD_Int
  4746. ENDM
  4747. VxDintMustComplete MACRO Int_Number
  4748. if (OPATTR Int_Number) AND 4
  4749. push Int_Number
  4750. else
  4751. push DWORD PTR Int_Number
  4752. endif
  4753. VMMCall _ExecVxDIntMustComplete
  4754. ENDM
  4755. Load_FS macro
  4756. VMMCall Load_FS_Service
  4757. endm
  4758. */
  4759. /*XLATOFF*/
  4760. #define Load_FS VMMCall(Load_FS_Service)
  4761. /*XLATON*/
  4762. #endif // Not_VxD
  4763. /******************************************************************************
  4764. *
  4765. * The following equates are for flags sent to the real mode
  4766. * initialization portion of a device driver:
  4767. *
  4768. *****************************************************************************/
  4769. #define DUPLICATE_DEVICE_ID_BIT 0 /* loaded */
  4770. #define DUPLICATE_DEVICE_ID (1 << DUPLICATE_DEVICE_ID_BIT)
  4771. #define DUPLICATE_FROM_INT2F_BIT 1 /* loaded from INT 2F list */
  4772. #define DUPLICATE_FROM_INT2F (1 << DUPLICATE_FROM_INT2F_BIT)
  4773. #define LOADING_FROM_INT2F_BIT 2 /* in the INT 2F device list */
  4774. #define LOADING_FROM_INT2F (1 << LOADING_FROM_INT2F_BIT)
  4775. /******************************************************************************
  4776. *
  4777. * The following equates are used to indicate the result of the real mode
  4778. * initialization portion of a device driver:
  4779. *
  4780. *****************************************************************************/
  4781. #define DEVICE_LOAD_OK 0 /* load protected mode portion */
  4782. #define ABORT_DEVICE_LOAD 1 /* don't load protected mode portion */
  4783. #define ABORT_WIN386_LOAD 2 /* fatal-error: abort load of Win386 */
  4784. #define DEVICE_NOT_NEEDED 3 /* don't load protected mode portion */
  4785. /* b/c the driver's presence is not needed */
  4786. #define NO_FAIL_MESSAGE_BIT 15 /* set bit to suppress error message */
  4787. #define NO_FAIL_MESSAGE (1 << NO_FAIL_MESSAGE_BIT)
  4788. /******************************************************************************
  4789. *
  4790. * The following equates define the loader services available to the real-mode
  4791. * initialization portion of a device driver:
  4792. *
  4793. *****************************************************************************/
  4794. #define LDRSRV_GET_PROFILE_STRING 0 /* search SYSTEM.INI for string */
  4795. #define LDRSRV_GET_NEXT_PROFILE_STRING 1 /* search for next string */
  4796. #define LDRSRV_RESERVED 2 /* RESERVED */
  4797. #define LDRSRV_GET_PROFILE_BOOLEAN 3 /* search SYSTEM.INI for boolean */
  4798. #define LDRSRV_GET_PROFILE_DECIMAL_INT 4 /* search SYSTEM.INI for integer */
  4799. #define LDRSRV_GET_PROFILE_HEX_INT 5 /* search SYSTEM.INI for hex int */
  4800. #define LDRSRV_COPY_EXTENDED_MEMORY 6 /* allocate/init extended memory */
  4801. #define LDRSRV_GET_MEMORY_INFO 7 /* get info about machine memory */
  4802. /* Add the new loader services contiguously here */
  4803. /****** Registry services for Real mode init time *************
  4804. * The parameters for these are as defined in Windows.h for the
  4805. * corresponding Win Reg API and should be on Stack. These are
  4806. * C Callable except that the function no has to be in AX
  4807. * ************************************************************
  4808. */
  4809. #define LDRSRV_RegOpenKey 0x100
  4810. #define LDRSRV_RegCreateKey 0x101
  4811. #define LDRSRV_RegCloseKey 0x102
  4812. #define LDRSRV_RegDeleteKey 0x103
  4813. #define LDRSRV_RegSetValue 0x104
  4814. #define LDRSRV_RegQueryValue 0x105
  4815. #define LDRSRV_RegEnumKey 0x106
  4816. #define LDRSRV_RegDeleteValue 0x107
  4817. #define LDRSRV_RegEnumValue 0x108
  4818. #define LDRSRV_RegQueryValueEx 0x109
  4819. #define LDRSRV_RegSetValueEx 0x10A
  4820. #define LDRSRV_RegFlushKey 0x10B
  4821. /*
  4822. * For the Copy_Extended_Memory service, the following types of memory can be
  4823. * requested:
  4824. */
  4825. #define LDRSRV_COPY_INIT 1 /* memory discarded after init */
  4826. #define LDRSRV_COPY_LOCKED 2 /* locked memory */
  4827. #define LDRSRV_COPY_PAGEABLE 3 /* pageable memory */
  4828. /****************************************************************************
  4829. *
  4830. * Object types supported by the vxd loader
  4831. *
  4832. * Notes : Low bit of all CODE type objects should be set (VXDLDR uses this)
  4833. * Also Init type objects should be added to the second part of the
  4834. * list (which starts with ICODE_OBJ).
  4835. *
  4836. *****************************************************************************/
  4837. #define RCODE_OBJ -1
  4838. #define LCODE_OBJ 0x01
  4839. #define LDATA_OBJ 0x02
  4840. #define PCODE_OBJ 0x03
  4841. #define PDATA_OBJ 0x04
  4842. #define SCODE_OBJ 0x05
  4843. #define SDATA_OBJ 0x06
  4844. #define CODE16_OBJ 0x07
  4845. #define LMSG_OBJ 0x08
  4846. #define PMSG_OBJ 0x09
  4847. #define DBOC_OBJ 0x0B
  4848. #define DBOD_OBJ 0x0C
  4849. #define PLCODE_OBJ 0x0D
  4850. #define PPCODE_OBJ 0x0F
  4851. #define ICODE_OBJ 0x11
  4852. #define IDATA_OBJ 0x12
  4853. #define ICODE16_OBJ 0x13
  4854. #define IMSG_OBJ 0x14
  4855. struct ObjectLocation {
  4856. ULONG OL_LinearAddr ;
  4857. ULONG OL_Size ;
  4858. UCHAR OL_ObjType ;
  4859. } ;
  4860. #define MAXOBJECTS 25
  4861. /*****************************************************************************
  4862. *
  4863. * Device_Location structure
  4864. *
  4865. *****************************************************************************/
  4866. struct Device_Location_List {
  4867. ULONG DLL_DDB ;
  4868. UCHAR DLL_NumObjects ;
  4869. struct ObjectLocation DLL_ObjLocation[1];
  4870. };
  4871. /* ========================================================================= */
  4872. /*
  4873. * CR0 bit assignments
  4874. */
  4875. #define PE_BIT 0 /* 1 = Protected Mode */
  4876. #define PE_MASK (1 << PE_BIT)
  4877. #define MP_BIT 1 /* 1 = Monitor Coprocessor */
  4878. #define MP_MASK (1 << MP_BIT)
  4879. #define EM_BIT 2 /* 1 = Emulate Math Coprocessor */
  4880. #define EM_MASK (1 << EM_BIT)
  4881. #define TS_BIT 3 /* 1 = Task Switch occured */
  4882. #define TS_MASK (1 << TS_BIT)
  4883. #define ET_BIT 4 /* 1 = 387 present, 0 = 287 present */
  4884. #define ET_MASK (1 << ET_BIT)
  4885. #define PG_BIT 31 /* 1 = paging enabled, 0 = paging disabled */
  4886. #define PG_MASK (1 << PG_BIT)
  4887. /*
  4888. * EFLAGs bit assignments
  4889. */
  4890. #define CF_BIT 0
  4891. #define CF_MASK (1 << CF_BIT)
  4892. #define PF_BIT 2
  4893. #define PF_MASK (1 << PF_BIT)
  4894. #define AF_BIT 4
  4895. #define AF_MASK (1 << AF_BIT)
  4896. #define ZF_BIT 6
  4897. #define ZF_MASK (1 << ZF_BIT)
  4898. #define SF_BIT 7
  4899. #define SF_MASK (1 << SF_BIT)
  4900. #define TF_BIT 8
  4901. #define TF_MASK (1 << TF_BIT)
  4902. #define IF_BIT 9
  4903. #define IF_MASK (1 << IF_BIT)
  4904. #define DF_BIT 10
  4905. #define DF_MASK (1 << DF_BIT)
  4906. #define OF_BIT 11 /* Overflow flag */
  4907. #define OF_MASK (1 << OF_BIT)
  4908. #define IOPL_MASK 0x3000 /* IOPL flags */
  4909. #define IOPL_BIT0 12
  4910. #define IOPL_BIT1 13
  4911. #define NT_BIT 14 /* Nested task flag */
  4912. #define NT_MASK (1 << NT_BIT)
  4913. #define RF_BIT 16 /* Resume flag */
  4914. #define RF_MASK (1 << RF_BIT)
  4915. #define VM_BIT 17 /* Virtual Mode flag */
  4916. #define VM_MASK (1 << VM_BIT)
  4917. #define AC_BIT 18 /* Alignment check */
  4918. #define AC_MASK (1 << AC_BIT)
  4919. #define VIF_BIT 19 /* Virtual Interrupt flag */
  4920. #define VIF_MASK (1 << VIF_BIT)
  4921. #define VIP_BIT 20 /* Virtual Interrupt pending */
  4922. #define VIP_MASK (1 << VIP_BIT)
  4923. /* ASM
  4924. ;------------------------------------------------------------------------------
  4925. ;
  4926. ; Temporary MASM macros (to be removed when supported by MASM)
  4927. ;
  4928. ;------------------------------------------------------------------------------
  4929. IFDEF MASM6
  4930. loopde EQU <looped>
  4931. loopdne EQU <loopned>
  4932. loopdz EQU <loopzd>
  4933. loopdnz EQU <loopnzd>
  4934. ELSE
  4935. loopd EQU <loop>
  4936. loopde EQU <loope>
  4937. loopdne EQU <loopne>
  4938. loopdz EQU <loopz>
  4939. loopdnz EQU <loopnz>
  4940. ENDIF
  4941. */
  4942. /******************************************************************************
  4943. * PAGE TABLE EQUATES
  4944. *****************************************************************************/
  4945. #define P_SIZE 0x1000 /* page size */
  4946. /******************************************************************************
  4947. *
  4948. * PAGE TABLE ENTRY BITS
  4949. *
  4950. *****************************************************************************/
  4951. #define P_PRESBIT 0
  4952. #define P_PRES (1 << P_PRESBIT)
  4953. #define P_WRITEBIT 1
  4954. #define P_WRITE (1 << P_WRITEBIT)
  4955. #define P_USERBIT 2
  4956. #define P_USER (1 << P_USERBIT)
  4957. #define P_ACCBIT 5
  4958. #define P_ACC (1 << P_ACCBIT)
  4959. #define P_DIRTYBIT 6
  4960. #define P_DIRTY (1 << P_DIRTYBIT)
  4961. #define P_AVAIL (P_PRES+P_WRITE+P_USER) /* avail to user & present */
  4962. /****************************************************
  4963. *
  4964. * Page types for page allocator calls
  4965. *
  4966. ***************************************************/
  4967. #define PG_VM 0
  4968. #define PG_SYS 1
  4969. #define PG_RESERVED1 2
  4970. #define PG_PRIVATE 3
  4971. #define PG_RESERVED2 4
  4972. #define PG_RELOCK 5 /* PRIVATE to MMGR */
  4973. #define PG_INSTANCE 6
  4974. #define PG_HOOKED 7
  4975. #define PG_IGNORE 0xFFFFFFFF
  4976. /****************************************************
  4977. *
  4978. * Definitions for the access byte in a descriptor
  4979. *
  4980. ***************************************************/
  4981. /*
  4982. * Following fields are common to segment and control descriptors
  4983. */
  4984. #define D_PRES 0x080 /* present in memory */
  4985. #define D_NOTPRES 0 /* not present in memory */
  4986. #define D_DPL0 0 /* Ring 0 */
  4987. #define D_DPL1 0x020 /* Ring 1 */
  4988. #define D_DPL2 0x040 /* Ring 2 */
  4989. #define D_DPL3 0x060 /* Ring 3 */
  4990. #define D_SEG 0x010 /* Segment descriptor */
  4991. #define D_CTRL 0 /* Control descriptor */
  4992. #define D_GRAN_BYTE 0x000 /* Segment length is byte granular */
  4993. #define D_GRAN_PAGE 0x080 /* Segment length is page granular */
  4994. #define D_DEF16 0x000 /* Default operation size is 16 bits */
  4995. #define D_DEF32 0x040 /* Default operation size is 32 bits */
  4996. /*
  4997. * Following fields are specific to segment descriptors
  4998. */
  4999. #define D_CODE 0x08 /* code */
  5000. #define D_DATA 0 /* data */
  5001. #define D_X 0 /* if code, exec only */
  5002. #define D_RX 0x02 /* if code, readable */
  5003. #define D_C 0x04 /* if code, conforming */
  5004. #define D_R 0 /* if data, read only */
  5005. #define D_W 0x02 /* if data, writable */
  5006. #define D_ED 0x04 /* if data, expand down */
  5007. #define D_ACCESSED 1 /* segment accessed bit */
  5008. /*
  5009. * Useful combination access rights bytes
  5010. */
  5011. #define RW_DATA_TYPE (D_PRES+D_SEG+D_DATA+D_W)
  5012. #define R_DATA_TYPE (D_PRES+D_SEG+D_DATA+D_R)
  5013. #define CODE_TYPE (D_PRES+D_SEG+D_CODE+D_RX)
  5014. #define D_PAGE32 (D_GRAN_PAGE+D_DEF32) /* 32 bit Page granular */
  5015. /*
  5016. * Masks for selector fields
  5017. */
  5018. #define SELECTOR_MASK 0xFFF8 /* selector index */
  5019. #define SEL_LOW_MASK 0xF8 /* mask for low byte of sel indx */
  5020. #define TABLE_MASK 0x04 /* table bit */
  5021. #define RPL_MASK 0x03 /* privilige bits */
  5022. #define RPL_CLR (~RPL_MASK) /* clear ring bits */
  5023. #define IVT_ROM_DATA_SIZE 0x500
  5024. /*XLATOFF*/
  5025. #ifndef Not_VxD
  5026. #define ENABLE_INTERRUPTS() {__asm sti}
  5027. #define DISABLE_INTERRUPTS() {__asm cli}
  5028. #define SAVE_FLAGS(flags) {\
  5029. {__asm pushfd}; \
  5030. {__asm pop flags}}
  5031. #define RESTORE_FLAGS(flags) {\
  5032. {__asm push flags}; \
  5033. {__asm popfd}}
  5034. #define IO_Delay() {\
  5035. {__asm _emit 0xeb}; \
  5036. {__asm _emit 0x00}}
  5037. #define Touch_Register(Register) {_asm xor Register, Register}
  5038. typedef DWORD HEVENT;
  5039. #define VMM_GET_DDB_NAMED 0
  5040. #pragma warning (disable:4209) // turn off redefine warning (with basedef.h)
  5041. typedef ULONG HTIMEOUT; // timeout handle
  5042. typedef ULONG CMS; // count of milliseconds
  5043. #pragma warning (default:4209) // turn on redefine warning (with basedef.h)
  5044. typedef DWORD VMM_SEMAPHORE;
  5045. #ifndef WANTVXDWRAPS
  5046. WORD VXDINLINE
  5047. Get_VMM_Version()
  5048. {
  5049. WORD w;
  5050. VMMCall(Get_VMM_Version);
  5051. _asm mov [w], ax
  5052. return(w);
  5053. }
  5054. PVOID VXDINLINE
  5055. _HeapAllocate(ULONG Bytes, ULONG Flags)
  5056. {
  5057. PVOID p;
  5058. Touch_Register(eax)
  5059. Touch_Register(ecx)
  5060. Touch_Register(edx)
  5061. _asm push [Flags]
  5062. _asm push [Bytes]
  5063. VMMCall(_HeapAllocate)
  5064. _asm add esp, 8
  5065. _asm mov [p], eax
  5066. return(p);
  5067. }
  5068. ULONG VXDINLINE
  5069. _HeapFree(PVOID Address, ULONG Flags)
  5070. {
  5071. ULONG ul;
  5072. Touch_Register(eax)
  5073. Touch_Register(ecx)
  5074. Touch_Register(edx)
  5075. _asm push [Flags]
  5076. _asm push [Address]
  5077. VMMCall(_HeapFree)
  5078. _asm add esp, 8
  5079. _asm mov [ul], eax
  5080. return(ul);
  5081. }
  5082. HEVENT VXDINLINE
  5083. Call_Global_Event(void (__cdecl *pfnEvent)(), ULONG ulRefData)
  5084. {
  5085. HEVENT hevent;
  5086. _asm mov edx, [ulRefData]
  5087. _asm mov esi, [pfnEvent]
  5088. VMMCall(Call_Global_Event)
  5089. _asm mov [hevent], esi
  5090. return(hevent);
  5091. }
  5092. HEVENT VXDINLINE
  5093. Schedule_Global_Event(void (__cdecl *pfnEvent)(), ULONG ulRefData)
  5094. {
  5095. HEVENT hevent;
  5096. _asm mov edx, [ulRefData]
  5097. _asm mov esi, [pfnEvent]
  5098. VMMCall(Schedule_Global_Event)
  5099. _asm mov [hevent], esi
  5100. return(hevent);
  5101. }
  5102. void VXDINLINE
  5103. Cancel_Global_Event( HEVENT hevent )
  5104. {
  5105. _asm mov esi, hevent
  5106. VMMCall( Cancel_Global_Event );
  5107. }
  5108. HVM VXDINLINE
  5109. Get_Sys_VM_Handle(VOID)
  5110. {
  5111. HVM hvm;
  5112. Touch_Register(ebx)
  5113. VxDCall(Get_Sys_VM_Handle);
  5114. _asm mov [hvm], ebx
  5115. return(hvm);
  5116. }
  5117. VOID VXDINLINE
  5118. Fatal_Error_Handler(PCHAR pszMessage, DWORD dwExitFlag)
  5119. {
  5120. _asm mov esi, [pszMessage]
  5121. _asm mov eax, [dwExitFlag]
  5122. VMMCall(Fatal_Error_Handler);
  5123. }
  5124. VMM_SEMAPHORE VXDINLINE
  5125. Create_Semaphore(LONG lTokenCount)
  5126. {
  5127. VMM_SEMAPHORE vmm_semaphore;
  5128. _asm mov ecx, [lTokenCount]
  5129. VMMCall(Create_Semaphore)
  5130. _asm cmc
  5131. _asm sbb ecx, ecx
  5132. _asm and eax, ecx
  5133. _asm mov [vmm_semaphore], eax
  5134. return(vmm_semaphore);
  5135. }
  5136. void VXDINLINE
  5137. Destroy_Semaphore(VMM_SEMAPHORE vsSemaphore)
  5138. {
  5139. _asm mov eax, [vsSemaphore]
  5140. VMMCall(Destroy_Semaphore)
  5141. }
  5142. void VXDINLINE
  5143. Signal_Semaphore(VMM_SEMAPHORE vsSemaphore)
  5144. {
  5145. _asm mov eax, [vsSemaphore]
  5146. VMMCall(Signal_Semaphore)
  5147. }
  5148. void VXDINLINE
  5149. Wait_Semaphore(VMM_SEMAPHORE vsSemaphore, DWORD dwFlags)
  5150. {
  5151. _asm mov eax, [vsSemaphore]
  5152. _asm mov ecx, [dwFlags]
  5153. VMMCall(Wait_Semaphore)
  5154. }
  5155. HVM VXDINLINE
  5156. Get_Execution_Focus(void)
  5157. {
  5158. HVM hvm;
  5159. Touch_Register(ebx)
  5160. VMMCall(Get_Execution_Focus)
  5161. _asm mov [hvm], ebx
  5162. return(hvm);
  5163. }
  5164. void VXDINLINE
  5165. Begin_Critical_Section(ULONG Flags)
  5166. {
  5167. _asm mov ecx, [Flags]
  5168. VMMCall(Begin_Critical_Section)
  5169. }
  5170. void VXDINLINE
  5171. End_Critical_Section(void)
  5172. {
  5173. VMMCall(End_Critical_Section)
  5174. }
  5175. void VXDINLINE
  5176. Fatal_Memory_Handler(void)
  5177. {
  5178. VMMCall(Fatal_Memory_Error);
  5179. }
  5180. void VXDINLINE
  5181. Begin_Nest_Exec(void)
  5182. {
  5183. VMMCall(Begin_Nest_Exec)
  5184. }
  5185. void VXDINLINE
  5186. End_Nest_Exec(void)
  5187. {
  5188. VMMCall(End_Nest_Exec)
  5189. }
  5190. void VXDINLINE
  5191. Resume_Exec(void)
  5192. {
  5193. VMMCall(Resume_Exec)
  5194. }
  5195. HTIMEOUT VXDINLINE
  5196. Set_VM_Time_Out(void (*pfnTimeout)(), CMS cms, ULONG ulRefData)
  5197. {
  5198. HTIMEOUT htimeout;
  5199. _asm mov eax, [cms]
  5200. _asm mov edx, [ulRefData]
  5201. _asm mov esi, [pfnTimeout]
  5202. VMMCall(Set_VM_Time_Out)
  5203. _asm mov [htimeout], esi
  5204. return(htimeout);
  5205. }
  5206. HTIMEOUT VXDINLINE
  5207. Set_Global_Time_Out(void (__cdecl *pfnTimeout)(), CMS cms, ULONG ulRefData)
  5208. {
  5209. HTIMEOUT htimeout;
  5210. _asm mov eax, [cms]
  5211. _asm mov edx, [ulRefData]
  5212. _asm mov esi, [pfnTimeout]
  5213. VMMCall(Set_Global_Time_Out)
  5214. _asm mov [htimeout], esi
  5215. return(htimeout);
  5216. }
  5217. void VXDINLINE
  5218. Cancel_Time_Out(HTIMEOUT htimeout)
  5219. {
  5220. _asm mov esi, htimeout
  5221. VMMCall(Cancel_Time_Out)
  5222. }
  5223. void VXDINLINE
  5224. Update_System_Clock(ULONG msElapsed)
  5225. {
  5226. __asm mov ecx,[msElapsed]
  5227. VMMCall(Update_System_Clock)
  5228. }
  5229. void VXDINLINE
  5230. Enable_Touch_1st_Meg(void)
  5231. {
  5232. VMMCall(Enable_Touch_1st_Meg)
  5233. }
  5234. void VXDINLINE
  5235. Disable_Touch_1st_Meg(void)
  5236. {
  5237. VMMCall(Disable_Touch_1st_Meg)
  5238. }
  5239. void VXDINLINE
  5240. Out_Debug_String(char *psz)
  5241. {
  5242. __asm pushad
  5243. __asm mov esi, [psz]
  5244. VMMCall(Out_Debug_String)
  5245. __asm popad
  5246. }
  5247. void VXDINLINE
  5248. Queue_Debug_String(char *psz, ULONG ulEAX, ULONG ulEBX)
  5249. {
  5250. _asm push esi
  5251. _asm push [ulEAX]
  5252. _asm push [ulEBX]
  5253. _asm mov esi, [psz]
  5254. VMMCall(Queue_Debug_String)
  5255. _asm pop esi
  5256. }
  5257. #ifdef WIN40SERVICES
  5258. HTIMEOUT VXDINLINE
  5259. Set_Async_Time_Out(void (*pfnTimeout)(), CMS cms, ULONG ulRefData)
  5260. {
  5261. HTIMEOUT htimeout;
  5262. _asm mov eax, [cms]
  5263. _asm mov edx, [ulRefData]
  5264. _asm mov esi, [pfnTimeout]
  5265. VMMCall(Set_Async_Time_Out)
  5266. _asm mov [htimeout], esi
  5267. return(htimeout);
  5268. }
  5269. VXDINLINE struct VxD_Desc_Block *
  5270. VMM_Get_DDB(WORD DeviceID, PCHAR Name)
  5271. {
  5272. struct VxD_Desc_Block *p;
  5273. _asm movzx eax, [DeviceID]
  5274. _asm mov edi, [Name]
  5275. VMMCall(Get_DDB);
  5276. _asm mov [p], ecx
  5277. return(p);
  5278. }
  5279. DWORD VXDINLINE
  5280. VMM_Directed_Sys_Control(struct VxD_Desc_Block *DDB, DWORD SysControl, DWORD rEBX, DWORD rEDX, DWORD rESI, DWORD rEDI)
  5281. {
  5282. DWORD dw;
  5283. _asm mov eax, [SysControl]
  5284. _asm mov ebx, [rEBX]
  5285. _asm mov ecx, [DDB]
  5286. _asm mov edx, [rEDX]
  5287. _asm mov esi, [rESI]
  5288. _asm mov edi, [rEDI]
  5289. VMMCall(Directed_Sys_Control);
  5290. _asm mov [dw], eax
  5291. return(dw);
  5292. }
  5293. void VXDINLINE
  5294. _Trace_Out_Service(char *psz)
  5295. {
  5296. __asm push psz
  5297. VMMCall(_Trace_Out_Service)
  5298. }
  5299. void VXDINLINE
  5300. _Debug_Out_Service(char *psz)
  5301. {
  5302. __asm push psz
  5303. VMMCall(_Debug_Out_Service)
  5304. }
  5305. void VXDINLINE
  5306. _Debug_Flags_Service(ULONG flags)
  5307. {
  5308. __asm push flags
  5309. VMMCall(_Debug_Flags_Service)
  5310. }
  5311. void VXDINLINE _cdecl
  5312. _Debug_Printf_Service(char *pszfmt, ...)
  5313. {
  5314. __asm lea eax,(pszfmt + 4)
  5315. __asm push eax
  5316. __asm push pszfmt
  5317. VMMCall(_Debug_Printf_Service)
  5318. __asm add esp, 2*4
  5319. }
  5320. #endif // WIN40SERVICES
  5321. #endif // WANTVXDWRAPS
  5322. #endif // Not_VxD
  5323. /*XLATON*/
  5324. #endif /* _VMM_ */