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.

482 lines
12 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. vdm.h
  5. Abstract:
  6. This include file defines the usermode visible portions of the vdm support
  7. Author:
  8. Revision History:
  9. --*/
  10. /* XLATOFF */
  11. #ifndef _VDM_H_
  12. #define _VDM_H_
  13. typedef enum _VdmServiceClass {
  14. VdmStartExecution, // is also defined in ntos\ke\i386\biosa.asm
  15. VdmQueueInterrupt,
  16. VdmDelayInterrupt,
  17. VdmInitialize,
  18. VdmFeatures,
  19. VdmSetInt21Handler,
  20. VdmQueryDir,
  21. VdmPrinterDirectIoOpen,
  22. VdmPrinterDirectIoClose,
  23. VdmPrinterInitialize,
  24. VdmSetLdtEntries,
  25. VdmSetProcessLdtInfo,
  26. VdmAdlibEmulation,
  27. VdmPMCliControl
  28. } VDMSERVICECLASS, *PVDMSERVICECLASS;
  29. #if defined (_NTDEF_)
  30. NTSYSCALLAPI
  31. NTSTATUS
  32. NtVdmControl(
  33. IN VDMSERVICECLASS Service,
  34. IN OUT PVOID ServiceData
  35. );
  36. typedef struct _VdmQueryDirInfo {
  37. HANDLE FileHandle;
  38. PVOID FileInformation;
  39. ULONG Length;
  40. PUNICODE_STRING FileName;
  41. ULONG FileIndex;
  42. } VDMQUERYDIRINFO, *PVDMQUERYDIRINFO;
  43. #endif
  44. /*
  45. * The Vdm Virtual Ica
  46. * note: this structure definition is duplicated in
  47. * mvdm\softpc\base\inc\ica.c. KEEP IN SYNC
  48. *
  49. */
  50. typedef struct _VdmVirtualIca{
  51. LONG ica_count[8]; /* Count of Irq pending not in irr */
  52. LONG ica_int_line; /* Current pending interrupt */
  53. LONG ica_cpu_int; /* The state of the INT line to the CPU */
  54. USHORT ica_base; /* Interrupt base address for cpu */
  55. USHORT ica_hipri; /* Line no. of highest priority line */
  56. USHORT ica_mode; /* Various single-bit modes */
  57. UCHAR ica_master; /* 1 = Master; 0 = Slave */
  58. UCHAR ica_irr; /* Interrupt Request Register */
  59. UCHAR ica_isr; /* In Service Register */
  60. UCHAR ica_imr; /* Interrupt Mask Register */
  61. UCHAR ica_ssr; /* Slave Select Register */
  62. } VDMVIRTUALICA, *PVDMVIRTUALICA;
  63. //
  64. // copied from softpc\base\system\ica.c
  65. //
  66. #define ICA_AEOI 0x0020
  67. #define ICA_SMM 0x0200
  68. #define ICA_SFNM 0x0100
  69. #if defined(i386)
  70. #define VDM_PM_IRETBOPSEG 0x147
  71. #define VDM_PM_IRETBOPOFF 0x6
  72. #define VDM_PM_IRETBOPSIZE 8
  73. #else
  74. #define VDM_PM_IRETBOPSEG 0xd3
  75. #define VDM_PM_IRETBOPOFF 0x0
  76. #define VDM_PM_IRETBOPSIZE 4
  77. #endif
  78. #define VDM_RM_IRETBOPSIZE 4
  79. // VDM state which was earlier in vdmtib->flags has been moved to
  80. // dos arena at following fixed address.
  81. #ifdef _VDMNTOS_
  82. #define FIXED_NTVDMSTATE_LINEAR VdmFixedStateLinear
  83. #define FIXED_NTVDMSTATE_SIZE 4
  84. #else // _VDMNTOS_
  85. /* XLATON */
  86. #define FIXED_NTVDMSTATE_SEGMENT 0x70
  87. #define FIXED_NTVDMSTATE_OFFSET 0x14
  88. #define FIXED_NTVDMSTATE_LINEAR ((FIXED_NTVDMSTATE_SEGMENT << 4) + FIXED_NTVDMSTATE_OFFSET)
  89. #define FIXED_NTVDMSTATE_SIZE 4
  90. /* XLATOFF */
  91. #endif // _VDMNTOS_
  92. #if defined (i386)
  93. // defined on x86 only since on mips we must reference thru sas
  94. #define pNtVDMState ((PULONG)FIXED_NTVDMSTATE_LINEAR)
  95. #endif
  96. /* XLATON */
  97. //
  98. // Vdm State Flags
  99. //
  100. #define VDM_INT_HARDWARE 0x00000001
  101. #define VDM_INT_TIMER 0x00000002
  102. // defined as VDM_INTS_HOOKED_IN_PM in mvdm\inc\vint.h
  103. #define VDM_INT_HOOK_IN_PM 0x00000004
  104. // A bitMask which includes all interrupts
  105. #define VDM_INTERRUPT_PENDING (VDM_INT_HARDWARE | VDM_INT_TIMER)
  106. #define VDM_BREAK_EXCEPTIONS 0x00000008
  107. #define VDM_BREAK_DEBUGGER 0x00000010
  108. #define VDM_PROFILE 0x00000020
  109. #define VDM_ANALYZE_PROFILE 0x00000040
  110. #define VDM_TRACE_HISTORY 0x00000080
  111. #define VDM_32BIT_APP 0x00000100
  112. #define VDM_VIRTUAL_INTERRUPTS 0x00000200
  113. #define VDM_ON_MIPS 0x00000400
  114. #define VDM_EXEC 0x00000800
  115. #define VDM_RM 0x00001000
  116. #define VDM_USE_DBG_VDMEVENT 0x00004000
  117. #define VDM_WOWBLOCKED 0x00100000
  118. #define VDM_IDLEACTIVITY 0x00200000
  119. #define VDM_TIMECHANGE 0x00400000
  120. #define VDM_WOWHUNGAPP 0x00800000
  121. #define VDM_PE_MASK 0x80000000
  122. /* XLATOFF */
  123. #if DBG
  124. #define INITIAL_VDM_TIB_FLAGS (VDM_USE_DBG_VDMEVENT | VDM_BREAK_DEBUGGER | VDM_TRACE_HISTORY)
  125. #else
  126. #define INITIAL_VDM_TIB_FLAGS (VDM_USE_DBG_VDMEVENT | VDM_BREAK_DEBUGGER)
  127. #endif
  128. //
  129. // bits defined in Eflags
  130. //
  131. #define EFLAGS_TF_MASK 0x00000100
  132. #define EFLAGS_IF_MASK 0x00000200
  133. #define EFLAGS_PL_MASK 0x00003000
  134. #define EFLAGS_NT_MASK 0x00004000
  135. #define EFLAGS_RF_MASK 0x00010000
  136. #define EFLAGS_VM_MASK 0x00020000
  137. #define EFLAGS_AC_MASK 0x00040000
  138. //
  139. // If the size of the structure is changed, ke\i386\instemul.asm must
  140. // be modified too. If not, it will fail to build
  141. //
  142. #pragma pack(1)
  143. typedef struct _Vdm_InterruptHandler {
  144. USHORT CsSelector;
  145. USHORT Flags;
  146. ULONG Eip;
  147. } VDM_INTERRUPTHANDLER, *PVDM_INTERRUPTHANDLER;
  148. #pragma pack()
  149. typedef struct _Vdm_FaultHandler {
  150. USHORT CsSelector;
  151. USHORT SsSelector;
  152. ULONG Eip;
  153. ULONG Esp;
  154. ULONG Flags;
  155. } VDM_FAULTHANDLER, *PVDM_FAULTHANDLER;
  156. #pragma pack(1)
  157. typedef struct _VdmDpmiInfo { /* VDMTIB */
  158. USHORT LockCount;
  159. USHORT Flags;
  160. USHORT SsSelector;
  161. USHORT SaveSsSelector;
  162. ULONG SaveEsp;
  163. ULONG SaveEip;
  164. ULONG DosxIntIret;
  165. ULONG DosxIntIretD;
  166. ULONG DosxFaultIret;
  167. ULONG DosxFaultIretD;
  168. ULONG DosxRmReflector;
  169. } VDM_DPMIINFO, *PVDM_DPMIINFO;
  170. #pragma pack()
  171. //
  172. // Interrupt handler flags
  173. //
  174. #define VDM_INT_INT_GATE 0x00000001
  175. #define VDM_INT_TRAP_GATE 0x00000000
  176. #define VDM_INT_32 0x00000002
  177. #define VDM_INT_16 0x00000000
  178. #define VDM_INT_HOOKED 0x00000004
  179. #pragma pack(1)
  180. //
  181. // CAVEAT: This structure was designed to be exactly 64 bytes in size.
  182. // There is code that assumes that an array of these structures
  183. // will fit neatly into a 4096 byte page.
  184. //
  185. typedef struct _VdmTraceEntry {
  186. USHORT Type;
  187. USHORT wData;
  188. ULONG lData;
  189. ULONG Time;
  190. ULONG eax;
  191. ULONG ebx;
  192. ULONG ecx;
  193. ULONG edx;
  194. ULONG esi;
  195. ULONG edi;
  196. ULONG ebp;
  197. ULONG esp;
  198. ULONG eip;
  199. ULONG eflags;
  200. USHORT cs;
  201. USHORT ds;
  202. USHORT es;
  203. USHORT fs;
  204. USHORT gs;
  205. USHORT ss;
  206. } VDM_TRACEENTRY, *PVDM_TRACEENTRY;
  207. #pragma pack()
  208. #pragma pack(1)
  209. typedef struct _VdmTraceInfo {
  210. PVDM_TRACEENTRY pTraceTable;
  211. UCHAR Flags;
  212. UCHAR NumPages; // size of trace buffer in 4k pages
  213. USHORT CurrentEntry;
  214. LARGE_INTEGER TimeStamp;
  215. } VDM_TRACEINFO, *PVDM_TRACEINFO;
  216. #pragma pack()
  217. //
  218. // Definitions for flags in VDM_TRACEINFO
  219. //
  220. #define VDMTI_TIMER_MODE 3
  221. #define VDMTI_TIMER_TICK 1
  222. #define VDMTI_TIMER_PERFCTR 2
  223. #define VDMTI_TIMER_STAT 3
  224. #define VDMTI_TIMER_PENTIUM 3
  225. //
  226. // Kernel trace entry types
  227. //
  228. #define VDMTR_KERNEL_OP_PM 1
  229. #define VDMTR_KERNEL_OP_V86 2
  230. #define VDMTR_KERNEL_HW_INT 3
  231. #if defined(i386)
  232. typedef struct _VdmIcaUserData {
  233. PVOID pIcaLock; // rtl critical section
  234. PVDMVIRTUALICA pIcaMaster;
  235. PVDMVIRTUALICA pIcaSlave;
  236. PULONG pDelayIrq;
  237. PULONG pUndelayIrq;
  238. PULONG pDelayIret;
  239. PULONG pIretHooked;
  240. PULONG pAddrIretBopTable;
  241. PHANDLE phWowIdleEvent;
  242. }VDMICAUSERDATA, *PVDMICAUSERDATA;
  243. typedef struct _VdmDelayIntsServiceData {
  244. ULONG Delay; /* Delay Time in usecs */
  245. ULONG DelayIrqLine; /* IRQ Number of ints delayed */
  246. HANDLE hThread; /* Thread Handle of CurrentMonitorTeb */
  247. }VDMDELAYINTSDATA, *PVDMDELAYINTSDATA;
  248. typedef struct _VDMSET_INT21_HANDLER_DATA {
  249. ULONG Selector;
  250. ULONG Offset;
  251. BOOLEAN Gate32;
  252. }VDMSET_INT21_HANDLER_DATA, *PVDMSET_INT21_HANDLER_DATA;
  253. typedef struct _VDMSET_LDT_ENTRIES_DATA {
  254. ULONG Selector0;
  255. ULONG Entry0Low;
  256. ULONG Entry0Hi;
  257. ULONG Selector1;
  258. ULONG Entry1Low;
  259. ULONG Entry1Hi;
  260. }VDMSET_LDT_ENTRIES_DATA, *PVDMSET_LDT_ENTRIES_DATA;
  261. typedef struct _VDMSET_PROCESS_LDT_INFO_DATA {
  262. PVOID LdtInformation;
  263. ULONG LdtInformationLength;
  264. }VDMSET_PROCESS_LDT_INFO_DATA, *PVDMSET_PROCESS_LDT_INFO_DATA;
  265. //
  266. // Define the action code of VDM_ADLIB_DATA
  267. //
  268. #define ADLIB_USER_EMULATION 0 // default action
  269. #define ADLIB_DIRECT_IO 1
  270. #define ADLIB_KERNEL_EMULATION 2
  271. typedef struct _VDM_ADLIB_DATA {
  272. USHORT VirtualPortStart;
  273. USHORT VirtualPortEnd;
  274. USHORT PhysicalPortStart;
  275. USHORT PhysicalPortEnd;
  276. USHORT Action;
  277. }VDM_ADLIB_DATA, *PVDM_ADLIB_DATA;
  278. //
  279. // Definitions for Protected Mode DOS apps cli control
  280. //
  281. #define PM_CLI_CONTROL_DISABLE 0
  282. #define PM_CLI_CONTROL_ENABLE 1
  283. #define PM_CLI_CONTROL_CHECK 2
  284. #define PM_CLI_CONTROL_SET 3
  285. #define PM_CLI_CONTROL_CLEAR 4
  286. typedef struct _VDM_PM_CLI_DATA {
  287. ULONG Control;
  288. }VDM_PM_CLI_DATA, *PVDM_PM_CLI_DATA;
  289. //
  290. // Definitions for VdmInitialize
  291. //
  292. typedef struct _VDM_INITIALIZE_DATA {
  293. PVOID TrapcHandler;
  294. PVDMICAUSERDATA IcaUserData;
  295. }VDM_INITIALIZE_DATA, *PVDM_INITIALIZE_DATA;
  296. #if defined (_NTDEF_)
  297. typedef enum _VdmEventClass {
  298. VdmIO,
  299. VdmStringIO,
  300. VdmMemAccess,
  301. VdmIntAck,
  302. VdmBop,
  303. VdmError,
  304. VdmIrq13,
  305. VdmMaxEvent
  306. } VDMEVENTCLASS, *PVDMEVENTCLASS;
  307. // VdmPrinterInfo
  308. #define VDM_NUMBER_OF_LPT 3
  309. #define PRT_MODE_NO_SIMULATION 1
  310. #define PRT_MODE_SIMULATE_STATUS_PORT 2
  311. #define PRT_MODE_DIRECT_IO 3
  312. #define PRT_MODE_VDD_CONNECTED 4
  313. #define PRT_DATA_BUFFER_SIZE 16
  314. typedef struct _Vdm_Printer_Info {
  315. PUCHAR prt_State;
  316. PUCHAR prt_Control;
  317. PUCHAR prt_Status;
  318. PUCHAR prt_HostState;
  319. USHORT prt_PortAddr[VDM_NUMBER_OF_LPT];
  320. HANDLE prt_Handle[VDM_NUMBER_OF_LPT];
  321. UCHAR prt_Mode[VDM_NUMBER_OF_LPT];
  322. USHORT prt_BytesInBuffer[VDM_NUMBER_OF_LPT];
  323. UCHAR prt_Buffer[VDM_NUMBER_OF_LPT][PRT_DATA_BUFFER_SIZE];
  324. ULONG prt_Scratch;
  325. } VDM_PRINTER_INFO, *PVDM_PRINTER_INFO;
  326. typedef struct _VdmIoInfo {
  327. USHORT PortNumber;
  328. USHORT Size;
  329. BOOLEAN Read;
  330. } VDMIOINFO, *PVDMIOINFO;
  331. typedef struct _VdmFaultInfo{
  332. ULONG FaultAddr;
  333. ULONG RWMode;
  334. } VDMFAULTINFO, *PVDMFAULTINFO;
  335. typedef struct _VdmStringIoInfo {
  336. USHORT PortNumber;
  337. USHORT Size;
  338. BOOLEAN Rep;
  339. BOOLEAN Read;
  340. ULONG Count;
  341. ULONG Address;
  342. } VDMSTRINGIOINFO, *PVDMSTRINGIOINFO;
  343. typedef ULONG VDMBOPINFO;
  344. typedef NTSTATUS VDMERRORINFO;
  345. typedef ULONG VDMINTACKINFO;
  346. #define VDMINTACK_RAEOIMASK 0x0000ffff
  347. #define VDMINTACK_SLAVE 0x00010000
  348. #define VDMINTACK_AEOI 0x00020000
  349. typedef struct _VdmEventInfo {
  350. ULONG Size;
  351. VDMEVENTCLASS Event;
  352. ULONG InstructionSize;
  353. union {
  354. VDMIOINFO IoInfo;
  355. VDMSTRINGIOINFO StringIoInfo;
  356. VDMBOPINFO BopNumber;
  357. VDMFAULTINFO FaultInfo;
  358. VDMERRORINFO ErrorStatus;
  359. VDMINTACKINFO IntAckInfo;
  360. };
  361. } VDMEVENTINFO, *PVDMEVENTINFO;
  362. // Sudeepb 12-Mar-1993
  363. // Scratch areas are used from VDMTib to get user space while
  364. // in kernel. This allows us to make Nt APIs (faster) from kernel
  365. // rather than Zw apis (slower). These are currently being used
  366. // for DOS read/write.
  367. typedef struct _Vdm_Tib {
  368. ULONG Size;
  369. PVDM_INTERRUPTHANDLER VdmInterruptTable;
  370. PVDM_FAULTHANDLER VdmFaultTable;
  371. CONTEXT MonitorContext;
  372. CONTEXT VdmContext;
  373. VDMEVENTINFO EventInfo;
  374. VDM_PRINTER_INFO PrinterInfo;
  375. ULONG TempArea1[2]; // Scratch area
  376. ULONG TempArea2[2]; // Scratch aArea
  377. VDM_DPMIINFO DpmiInfo;
  378. VDM_TRACEINFO TraceInfo;
  379. ULONG IntelMSW;
  380. LONG NumTasks;
  381. BOOLEAN ContinueExecution;
  382. } VDM_TIB, *PVDM_TIB;
  383. //
  384. // Feature flags returned by NtVdmControl(VdmFeatures...)
  385. //
  386. // System/processor supports fast emulation for IF instructions
  387. #define V86_VIRTUAL_INT_EXTENSIONS 0x00000001 // in v86 mode
  388. #define PM_VIRTUAL_INT_EXTENSIONS 0x00000002 // in protected mode (non-flat)
  389. #endif // if defined _NTDEF_
  390. #endif
  391. #endif