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.

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