Leaked source code of windows server 2003
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.

802 lines
32 KiB

  1. /*++ BUILD Version: 0001
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. SOFTPC.H
  5. Abstract:
  6. High-level include file for components interfacing to SoftPC
  7. Author:
  8. Dave Hastings (daveh) 25-Apr-1991
  9. Revision History:
  10. Sudeep Bharati 23-Aug-1991 Added SOFTPC_BLD
  11. Matt Felton 8-FEB-1992 Added getIntelRegistersPointer
  12. Jonle 18-Sep-1992 Add popup for unsupported functionality
  13. Jonle 21-Nov-1992 Add Standard Resource Error Dialog Box
  14. GetPIFConfigFiles
  15. --*/
  16. /********** COMMON STUFF FOR MIPS AND V86 *************/
  17. /* XLATOFF */
  18. #ifdef i386
  19. #include "v86def.h"
  20. #endif
  21. #include <vdm.h>
  22. extern VOID SbReinitialize(PCHAR, DWORD);
  23. /* XLATON */
  24. extern VOID nt_block_event_thread(ULONG);
  25. extern VOID nt_resume_event_thread(VOID);
  26. /* notification of PDB(Process Data Block, A.K.A PSP) termination */
  27. extern VOID HostTerminatePDB(USHORT pdb);
  28. /* disk subsystem reset notification. These functions will close all
  29. * outstanding opened handles for DASD(Direct AcceS Disk) */
  30. extern VOID HostFloppyReset(VOID);
  31. extern VOID HostFdiskReset(VOID);
  32. // unsupported services dialog box
  33. extern VOID host_direct_access_error(ULONG);
  34. extern VOID host_lpt_flush_initialize(VOID);
  35. #define NOSUPPORT_FLOPPY 0
  36. #define NOSUPPORT_HARDDISK 1
  37. #define NOSUPPORT_DRIVER 2
  38. #define NOSUPPORT_OLDPIF 3
  39. #define NOSUPPORT_ILLBOP 4
  40. #define NOSUPPORT_NOLIM 5
  41. #define NOSUPPORT_MOUSEDRVR 6
  42. // standard error dialog box using resources
  43. void RcErrorDialogBox(USHORT wId, CHAR *msg1, CHAR *msg2);
  44. /*
  45. * RcMessageBox\EditBox stuff
  46. */
  47. #define RMB_ABORT 1
  48. #define RMB_RETRY 2
  49. #define RMB_IGNORE 4
  50. #define RMB_ICON_INFO 8
  51. #define RMB_ICON_BANG 16
  52. #define RMB_ICON_STOP 32
  53. #define RMB_ICON_WHAT 64
  54. #define RMB_EDIT 128
  55. #define RMB_FLAGS_MASK 0x0000FFFF
  56. #define RMB_EDITBUFFERSIZE_MASK 0xFFFF0000
  57. // hiword of dwOptions is reserved for RMB_EDIT text buffer size
  58. int RcMessageBox(USHORT wId, CHAR *msg1, CHAR *msg2, ULONG dwOptions);
  59. // sudeepb 02-May-1993 these following defines are actually defined
  60. // in host\inc\error.h and host\inc\nt_uis.h. this stuff needs
  61. // major cleanup after product 1.0.
  62. #define EG_MALLOC_FAILURE 7
  63. #define EG_PIF_BAD_FORMAT 18
  64. #define EG_PIF_STARTDIR_ERR 19
  65. #define EG_PIF_STARTFILE_ERR 20
  66. #define EG_PIF_CMDLINE_ERR 21
  67. #define EG_PIF_ASK_CMDLINE 22
  68. #define EG_ENVIRONMENT_ERR 23
  69. #define EG_BAD_FAULT 27
  70. #define EG_DOS_PROG_EXTENSION 28
  71. #define ED_BADSYSFILE 336
  72. #define ED_INITMEMERR 337
  73. #define ED_INITTMPFILE 338
  74. //
  75. // SysErrorBox stuff -- duplicated in usersrv.h *and* kernel.inc
  76. //
  77. #define SEB_OK 1 /* Button with "OK". */
  78. #define SEB_CANCEL 2 /* Button with "Cancel" */
  79. #define SEB_YES 3 /* Button with "&Yes" */
  80. #define SEB_NO 4 /* Button with "&No" */
  81. #define SEB_RETRY 5 /* Button with "&Retry" */
  82. #define SEB_ABORT 6 /* Button with "&Abort" */
  83. #define SEB_IGNORE 7 /* Button with "&Ignore" */
  84. #define SEB_CLOSE 8 /* Button with "&Close" */
  85. #define SEB_DEFBUTTON 0x8000 /* Mask to make this button default */
  86. ULONG WOWSysErrorBox(
  87. LPSTR szTitle,
  88. LPSTR szMessage,
  89. USHORT wBtn1,
  90. USHORT wBtn2,
  91. USHORT wBtn3
  92. );
  93. // Called by WOW to force VdmAllocateVirtualMemory to alloc blocks of
  94. // memory with ever increasing linear address's.
  95. VOID SetWOWforceIncrAlloc(
  96. BOOL iEnable
  97. );
  98. // call out to softpc to get config.sys\autoexec.bat file names
  99. VOID GetPIFConfigFiles(BOOL bConfig, char *pchFileName, BOOL bFreMem);
  100. // exported interfaces
  101. extern VOID TerminateVDM (VOID);
  102. extern ULONG DosSessionId;
  103. // VDD idle callouts
  104. void WaitIfIdle(void);
  105. void WakeUpNow(void);
  106. //
  107. // Constants
  108. //
  109. #define MSW_PE 0x1
  110. /* XLATOFF */
  111. #define ISPESET (UCHAR) (getMSW() & MSW_PE ? 1 : 0)
  112. /* XLATON */
  113. //
  114. // Macros
  115. //
  116. #define EXPORT
  117. // Flag Register constants
  118. #define FLG_CARRY 0x00000001
  119. #define FLG_CARRY_BIT 0x00000000
  120. #define FLG_PARITY 0x00000004
  121. #define FLG_PARITY_BIT 0x00000003
  122. #define FLG_AUXILIARY 0x00000010
  123. #define FLG_AUXILIARY_BIT 0x00000005
  124. #define FLG_ZERO 0x00000040
  125. #define FLG_ZERO_BIT 0x00000006
  126. #define FLG_SIGN 0x00000080
  127. #define FLG_SIGN_BIT 0x00000007
  128. #define FLG_TRAP 0x00000100
  129. #define FLG_INTERRUPT 0x00000200
  130. #define FLG_INTERRUPT_BIT 0x00000009
  131. #define FLG_DIRECTION 0x00000400
  132. #define FLG_DIRECTION_BIT 0x0000000A
  133. #define FLG_OVERFLOW 0x00000800
  134. #define FLG_OVERFLOW_BIT 0x0000000B
  135. EXPORT
  136. VOID
  137. host_cpu_init(
  138. VOID
  139. );
  140. //EXPORT
  141. //VOID
  142. //sas_init(
  143. // IN sys_addr Size
  144. // );
  145. EXPORT
  146. VOID
  147. host_simulate(
  148. VOID
  149. );
  150. HANDLE
  151. host_CreateThread(
  152. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  153. DWORD dwStackSize,
  154. LPTHREAD_START_ROUTINE lpStartAddress,
  155. LPVOID lpParameter,
  156. DWORD dwCreationFlags,
  157. LPDWORD lpThreadId
  158. );
  159. VOID
  160. cpu_createthread(
  161. HANDLE hThread,
  162. PVDM_TIB VdmTib
  163. );
  164. VOID
  165. host_ExitThread(
  166. DWORD dwExitCode
  167. );
  168. EXPORT VOID host_com_close(int PortId);
  169. EXPORT int SuspendTimerThread(VOID);
  170. EXPORT int ResumeTimerThread(VOID);
  171. void *ch_malloc(unsigned int NumBytes);
  172. UCHAR *Sim32pGetVDMPointer(ULONG addr, UCHAR pm);
  173. #define Sim32GetVDMPointer(Addr,Size,Mode) Sim32pGetVDMPointer(Addr,Mode)
  174. #ifdef i386
  175. /********** FOR V86 BUILD *************/
  176. BOOL
  177. ThreadSetDebugContext(
  178. PULONG pDebugRegisters
  179. );
  180. BOOL
  181. ThreadGetDebugContext(
  182. PULONG pDebugRegisters
  183. );
  184. // external data
  185. extern ULONG IntelBase; // used by memory access macros
  186. extern X86CONTEXT IntelRegisters; // used by register access macros
  187. extern ULONG VdmDebugLevel; // used to control debugging
  188. extern ULONG VdmFeatureBits;
  189. // Register access macros
  190. #ifdef LINKED_INTO_MONITOR
  191. #include <vdm.h>
  192. #define DECLARE_LocalVdmContext VDM_TIB * _LocalVdmTib = (VDM_TIB *)(NtCurrentTeb()->Vdm); \
  193. CONTEXT * _LocalVdmContext = &(*_LocalVdmTib).VdmContext
  194. #ifndef FAST_VDM_REGISTERS
  195. #define getEAX() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax)
  196. #define getAX() ((USHORT)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax))
  197. #define getAL() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax))
  198. #define getAH() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax >> 8))
  199. #define getEBX() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx)
  200. #define getBX() ((USHORT)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx))
  201. #define getBL() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx))
  202. #define getBH() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx >> 8))
  203. #define getECX() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx)
  204. #define getCX() ((USHORT)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx))
  205. #define getCL() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx))
  206. #define getCH() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx >> 8))
  207. #define getEDX() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx)
  208. #define getDX() ((USHORT)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx))
  209. #define getDL() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx))
  210. #define getDH() ((BYTE)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx >> 8))
  211. #define getESP() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esp)
  212. #define getSP() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esp)
  213. #define getEBP() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebp)
  214. #define getBP() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebp)
  215. #define getESI() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esi)
  216. #define getSI() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esi)
  217. #define getEDI() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edi)
  218. #define getDI() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edi)
  219. #define getEIP() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eip)
  220. #define getIP() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eip)
  221. #define getCS() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegCs)
  222. #define getSS() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegSs)
  223. #define getDS() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegDs)
  224. #define getES() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegEs)
  225. #define getFS() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegFs)
  226. #define getGS() ((USHORT)(*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegGs)
  227. #define getCF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_CARRY) ? 1 : 0)
  228. #define getPF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_PARITY) ? 1 : 0)
  229. #define getAF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_AUXILIARY) ? 1 : 0)
  230. #define getZF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_ZERO) ? 1 : 0)
  231. #define getSF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_SIGN) ? 1 : 0)
  232. #define getTF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_TRAP) ? 1 : 0)
  233. #define getIF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_INTERRUPT) ? 1 : 0)
  234. #define getDF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_DIRECTION) ? 1 : 0)
  235. #define getOF() (((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & FLG_OVERFLOW) ? 1 : 0)
  236. #define getMSW() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).IntelMSW)
  237. #define getSTATUS() (USHORT)((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags)
  238. #define getEFLAGS() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags)
  239. #define setEAX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax = val;}
  240. #define setAX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  241. #define setAH(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  242. #define setAL(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eax & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  243. #define setEBX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx = val ;}
  244. #define setBX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  245. #define setBH(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  246. #define setBL(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebx & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  247. #define setECX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx = val ;}
  248. #define setCX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  249. #define setCH(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  250. #define setCL(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ecx & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  251. #define setEDX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx = val ;}
  252. #define setDX(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  253. #define setDH(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  254. #define setDL(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edx & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  255. #define setESP(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esp = val ;}
  256. #define setSP(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esp = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esp & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  257. #define setEBP(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebp = val;}
  258. #define setBP(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebp = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Ebp & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  259. #define setESI(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esi = val ;}
  260. #define setSI(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esi = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Esi & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  261. #define setEDI(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edi = val ;}
  262. #define setDI(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edi = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Edi & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  263. #define setEIP(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eip = val ;}
  264. #define setIP(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eip = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.Eip & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  265. #define setCS(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegCs = (ULONG) val & 0x0000FFFF ;}
  266. #define setSS(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegSs = (ULONG) val & 0x0000FFFF ;}
  267. #define setDS(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegDs = (ULONG) val & 0x0000FFFF ;}
  268. #define setES(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegEs = (ULONG) val & 0x0000FFFF ;}
  269. #define setFS(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegFs = (ULONG) val & 0x0000FFFF ;}
  270. #define setGS(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.SegGs = (ULONG) val & 0x0000FFFF ;}
  271. #define setCF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_CARRY) | (((ULONG)val << FLG_CARRY_BIT) & FLG_CARRY);}
  272. #define setPF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_PARITY) | (((ULONG)val << FLG_PARITY_BIT) & FLG_PARITY);}
  273. #define setAF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_AUXILIARY) | (((ULONG)val << FLG_AUXILIARY_BIT) & FLG_AUXILIARY);}
  274. #define setZF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_ZERO) | (((ULONG)val << FLG_ZERO_BIT) & FLG_ZERO);}
  275. #define setSF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_SIGN) | (((ULONG)val << FLG_SIGN_BIT) & FLG_SIGN);}
  276. #define setIF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_INTERRUPT) | (((ULONG)val << FLG_INTERRUPT_BIT) & FLG_INTERRUPT);}
  277. #define setDF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_DIRECTION) | (((ULONG)val << FLG_DIRECTION_BIT) & FLG_DIRECTION);}
  278. #define setOF(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & ~FLG_OVERFLOW) | (((ULONG)val << FLG_OVERFLOW_BIT) & FLG_OVERFLOW);}
  279. #define setMSW(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).IntelMSW = val ;}
  280. #define setSTATUS(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags & 0xFFFF0000) | val;}
  281. #define setEFLAGS(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).VdmContext.EFlags = val;}
  282. #else // FAST_VDM_REGISTERS
  283. #define getEAX() (_LocalVdmContext->Eax)
  284. #define getAX() ((USHORT)(_LocalVdmContext->Eax))
  285. #define getAL() ((BYTE)(_LocalVdmContext->Eax))
  286. #define getAH() ((BYTE)(_LocalVdmContext->Eax >> 8))
  287. #define getEBX() (_LocalVdmContext->Ebx)
  288. #define getBX() ((USHORT)(_LocalVdmContext->Ebx))
  289. #define getBL() ((BYTE)(_LocalVdmContext->Ebx))
  290. #define getBH() ((BYTE)(_LocalVdmContext->Ebx >> 8))
  291. #define getECX() (_LocalVdmContext->Ecx)
  292. #define getCX() ((USHORT)(_LocalVdmContext->Ecx))
  293. #define getCL() ((BYTE)(_LocalVdmContext->Ecx))
  294. #define getCH() ((BYTE)(_LocalVdmContext->Ecx >> 8))
  295. #define getEDX() (_LocalVdmContext->Edx)
  296. #define getDX() ((USHORT)(_LocalVdmContext->Edx))
  297. #define getDL() ((BYTE)(_LocalVdmContext->Edx))
  298. #define getDH() ((BYTE)(_LocalVdmContext->Edx >> 8))
  299. #define getESP() (_LocalVdmContext->Esp)
  300. #define getSP() ((USHORT)_LocalVdmContext->Esp)
  301. #define getEBP() (_LocalVdmContext->Ebp)
  302. #define getBP() ((USHORT)_LocalVdmContext->Ebp)
  303. #define getESI() (_LocalVdmContext->Esi)
  304. #define getSI() ((USHORT)_LocalVdmContext->Esi)
  305. #define getEDI() (_LocalVdmContext->Edi)
  306. #define getDI() ((USHORT)_LocalVdmContext->Edi)
  307. #define getEIP() (_LocalVdmContext->Eip)
  308. #define getIP() ((USHORT)_LocalVdmContext->Eip)
  309. #define getCS() ((USHORT)_LocalVdmContext->SegCs)
  310. #define getSS() ((USHORT)_LocalVdmContext->SegSs)
  311. #define getDS() ((USHORT)_LocalVdmContext->SegDs)
  312. #define getES() ((USHORT)_LocalVdmContext->SegEs)
  313. #define getFS() ((USHORT)_LocalVdmContext->SegFs)
  314. #define getGS() ((USHORT)_LocalVdmContext->SegGs)
  315. #define getCF() ((_LocalVdmContext->EFlags & FLG_CARRY) ? 1 : 0)
  316. #define getPF() ((_LocalVdmContext->EFlags & FLG_PARITY) ? 1 : 0)
  317. #define getAF() ((_LocalVdmContext->EFlags & FLG_AUXILIARY) ? 1 : 0)
  318. #define getZF() ((_LocalVdmContext->EFlags & FLG_ZERO) ? 1 : 0)
  319. #define getSF() ((_LocalVdmContext->EFlags & FLG_SIGN) ? 1 : 0)
  320. #define getTF() ((_LocalVdmContext->EFlags & FLG_TRAP) ? 1 : 0)
  321. #define getIF() ((_LocalVdmContext->EFlags & FLG_INTERRUPT) ? 1 : 0)
  322. #define getDF() ((_LocalVdmContext->EFlags & FLG_DIRECTION) ? 1 : 0)
  323. #define getOF() ((_LocalVdmContext->EFlags & FLG_OVERFLOW) ? 1 : 0)
  324. #define getMSW() ((*(VDM_TIB *)(NtCurrentTeb()->Vdm)).IntelMSW)
  325. #define getSTATUS() (USHORT)(_LocalVdmContext->EFlags)
  326. #define getEFLAGS() (_LocalVdmContext->EFlags)
  327. #define setEAX(val) { _LocalVdmContext->Eax = val;}
  328. #define setAX(val) { _LocalVdmContext->Eax = (_LocalVdmContext->Eax & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  329. #define setAH(val) { _LocalVdmContext->Eax = (_LocalVdmContext->Eax & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  330. #define setAL(val) { _LocalVdmContext->Eax = (_LocalVdmContext->Eax & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  331. #define setEBX(val) { _LocalVdmContext->Ebx = val ;}
  332. #define setBX(val) { _LocalVdmContext->Ebx = (_LocalVdmContext->Ebx & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  333. #define setBH(val) { _LocalVdmContext->Ebx = (_LocalVdmContext->Ebx & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  334. #define setBL(val) { _LocalVdmContext->Ebx = (_LocalVdmContext->Ebx & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  335. #define setECX(val) { _LocalVdmContext->Ecx = val ;}
  336. #define setCX(val) { _LocalVdmContext->Ecx = (_LocalVdmContext->Ecx & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  337. #define setCH(val) { _LocalVdmContext->Ecx = (_LocalVdmContext->Ecx & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  338. #define setCL(val) { _LocalVdmContext->Ecx = (_LocalVdmContext->Ecx & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  339. #define setEDX(val) { _LocalVdmContext->Edx = val ;}
  340. #define setDX(val) { _LocalVdmContext->Edx = (_LocalVdmContext->Edx & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  341. #define setDH(val) { _LocalVdmContext->Edx = (_LocalVdmContext->Edx & 0xFFFF00FF) | ((ULONG)(val << 8) & 0x0000FF00);}
  342. #define setDL(val) { _LocalVdmContext->Edx = (_LocalVdmContext->Edx & 0xFFFFFF00) | ((ULONG)val & 0x000000FF);}
  343. #define setESP(val) { _LocalVdmContext->Esp = val ;}
  344. #define setSP(val) { _LocalVdmContext->Esp = (_LocalVdmContext->Esp & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  345. #define setEBP(val) { _LocalVdmContext->Ebp = val;}
  346. #define setBP(val) { _LocalVdmContext->Ebp = (_LocalVdmContext->Ebp & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  347. #define setESI(val) { _LocalVdmContext->Esi = val ;}
  348. #define setSI(val) { _LocalVdmContext->Esi = (_LocalVdmContext->Esi & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  349. #define setEDI(val) { _LocalVdmContext->Edi = val ;}
  350. #define setDI(val) { _LocalVdmContext->Edi = (_LocalVdmContext->Edi & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  351. #define setEIP(val) { _LocalVdmContext->Eip = val ;}
  352. #define setIP(val) { _LocalVdmContext->Eip = (_LocalVdmContext->Eip & 0xFFFF0000) | ((ULONG)val & 0x0000FFFF);}
  353. #define setCS(val) { _LocalVdmContext->SegCs = (ULONG) val & 0x0000FFFF ;}
  354. #define setSS(val) { _LocalVdmContext->SegSs = (ULONG) val & 0x0000FFFF ;}
  355. #define setDS(val) { _LocalVdmContext->SegDs = (ULONG) val & 0x0000FFFF ;}
  356. #define setES(val) { _LocalVdmContext->SegEs = (ULONG) val & 0x0000FFFF ;}
  357. #define setFS(val) { _LocalVdmContext->SegFs = (ULONG) val & 0x0000FFFF ;}
  358. #define setGS(val) { _LocalVdmContext->SegGs = (ULONG) val & 0x0000FFFF ;}
  359. #define setCF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_CARRY) | (((ULONG)val << FLG_CARRY_BIT) & FLG_CARRY);}
  360. #define setPF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_PARITY) | (((ULONG)val << FLG_PARITY_BIT) & FLG_PARITY);}
  361. #define setAF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_AUXILIARY) | (((ULONG)val << FLG_AUXILIARY_BIT) & FLG_AUXILIARY);}
  362. #define setZF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_ZERO) | (((ULONG)val << FLG_ZERO_BIT) & FLG_ZERO);}
  363. #define setSF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_SIGN) | (((ULONG)val << FLG_SIGN_BIT) & FLG_SIGN);}
  364. #define setIF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_INTERRUPT) | (((ULONG)val << FLG_INTERRUPT_BIT) & FLG_INTERRUPT);}
  365. #define setDF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_DIRECTION) | (((ULONG)val << FLG_DIRECTION_BIT) & FLG_DIRECTION);}
  366. #define setOF(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & ~FLG_OVERFLOW) | (((ULONG)val << FLG_OVERFLOW_BIT) & FLG_OVERFLOW);}
  367. #define setMSW(val) { (*(VDM_TIB *)(NtCurrentTeb()->Vdm)).IntelMSW = val ;}
  368. #define setSTATUS(val) { _LocalVdmContext->EFlags = (_LocalVdmContext->EFlags & 0xFFFF0000) | val;}
  369. #define setEFLAGS(val) { _LocalVdmContext->EFlags = val;}
  370. #endif // FAST_VDM_REGISTERS
  371. #else // not linked into monitor
  372. extern ULONG getEAX(VOID);
  373. extern USHORT getAX(VOID);
  374. extern UCHAR getAL(VOID);
  375. extern UCHAR getAH(VOID);
  376. extern ULONG getEBX(VOID);
  377. extern USHORT getBX(VOID);
  378. extern UCHAR getBL(VOID);
  379. extern UCHAR getBH(VOID);
  380. extern ULONG getECX(VOID);
  381. extern USHORT getCX(VOID);
  382. extern UCHAR getCL(VOID);
  383. extern UCHAR getCH(VOID);
  384. extern ULONG getEDX(VOID);
  385. extern USHORT getDX(VOID);
  386. extern UCHAR getDL(VOID);
  387. extern UCHAR getDH(VOID);
  388. extern ULONG getESP(VOID);
  389. extern USHORT getSP(VOID);
  390. extern ULONG getEBP(VOID);
  391. extern USHORT getBP(VOID);
  392. extern ULONG getESI(VOID);
  393. extern USHORT getSI(VOID);
  394. extern ULONG getEDI(VOID);
  395. extern USHORT getDI(VOID);
  396. extern ULONG getEIP(VOID);
  397. extern USHORT getIP(VOID);
  398. extern USHORT getCS(VOID);
  399. extern USHORT getSS(VOID);
  400. extern USHORT getDS(VOID);
  401. extern USHORT getES(VOID);
  402. extern USHORT getFS(VOID);
  403. extern USHORT getGS(VOID);
  404. extern ULONG getCF(VOID);
  405. extern ULONG getPF(VOID);
  406. extern ULONG getAF(VOID);
  407. extern ULONG getZF(VOID);
  408. extern ULONG getSF(VOID);
  409. extern ULONG getIF(VOID);
  410. extern ULONG getDF(VOID);
  411. extern ULONG getOF(VOID);
  412. extern USHORT getMSW(VOID);
  413. extern USHORT getSTATUS(VOID);
  414. extern ULONG getEFLAGS(VOID);
  415. extern VOID setEAX(ULONG);
  416. extern VOID setAX(USHORT);
  417. extern VOID setAH(UCHAR);
  418. extern VOID setAL(UCHAR);
  419. extern VOID setEBX(ULONG);
  420. extern VOID setBX(USHORT);
  421. extern VOID setBH(UCHAR);
  422. extern VOID setBL(UCHAR);
  423. extern VOID setECX(ULONG);
  424. extern VOID setCX(USHORT);
  425. extern VOID setCH(UCHAR);
  426. extern VOID setCL(UCHAR);
  427. extern VOID setEDX(ULONG);
  428. extern VOID setDX(USHORT);
  429. extern VOID setDH(UCHAR);
  430. extern VOID setDL(UCHAR);
  431. extern VOID setESP(ULONG);
  432. extern VOID setSP(USHORT);
  433. extern VOID setEBP(ULONG);
  434. extern VOID setBP(USHORT);
  435. extern VOID setESI(ULONG);
  436. extern VOID setSI(USHORT);
  437. extern VOID setEDI(ULONG);
  438. extern VOID setDI(USHORT);
  439. extern VOID setEIP(ULONG);
  440. extern VOID setIP(USHORT);
  441. extern VOID setCS(USHORT);
  442. extern VOID setSS(USHORT);
  443. extern VOID setDS(USHORT);
  444. extern VOID setES(USHORT);
  445. extern VOID setFS(USHORT);
  446. extern VOID setGS(USHORT);
  447. extern VOID setCF(ULONG);
  448. extern VOID setPF(ULONG);
  449. extern VOID setAF(ULONG);
  450. extern VOID setZF(ULONG);
  451. extern VOID setSF(ULONG);
  452. extern VOID setIF(ULONG);
  453. extern VOID setDF(ULONG);
  454. extern VOID setOF(ULONG);
  455. extern VOID setMSW(USHORT);
  456. extern VOID setSTATUS(USHORT);
  457. extern VOID setEFLAGS(ULONG);
  458. #endif
  459. //
  460. // Sim32 macros
  461. //
  462. // no action is required for this macro.
  463. #define Sim32FlushVDMPointer( address, size, buffer, mode ) TRUE
  464. // no action is required for this macro.
  465. #define Sim32FreeVDMPointer( address, size, buffer, mode) TRUE
  466. #define Sim32GetVDMMemory( address, size, buffer, mode) (memcpy( \
  467. buffer, Sim32pGetVDMPointer(address, mode), size), TRUE)
  468. #define Sim32SetVDMMemory( address, size, buffer, mode) (memcpy( \
  469. Sim32pGetVDMPointer(address, mode), buffer, size), TRUE)
  470. // Address conversion macros
  471. #define RMOFF(address) (WORD)((ULONG)address & 0x0000FFFF)
  472. #define RMSEG(address) (WORD)(((ULONG)address - ((ULONG)address & 0x0000FFFF)) >> 4)
  473. #define RMSEGOFFTOLIN(seg, off) (PVOID)(IntelBase + ((ULONG)(seg) << 4) + (ULONG)(off))
  474. // Debugging Macros
  475. #define VDprint(value, arg) { if (value <= (VdmDebugLevel & VDP_LEVEL_MASK)) {\
  476. DbgPrint arg ; }}
  477. #define VDbreak(value) { if (value <= (VDB_LEVEL_MASK & VdmDebugLevel)) {\
  478. DbgBreakPoint(); }}
  479. #define VDP_LEVEL_MASK 0x0F
  480. #define VDP_LEVEL_NONE 0x0
  481. #define VDP_LEVEL_ERROR 0x2
  482. #define VDP_LEVEL_WARNING 0x4
  483. #define VDP_LEVEL_INFO 0x8
  484. #define VDB_LEVEL_MASK 0xF0
  485. #define VDB_LEVEL_NONE 0x00
  486. #define VDB_LEVEL_ERROR 0x20
  487. #define VDB_LEVEL_WARNING 0x40
  488. #define VDB_LEVEL_INFO 0x80
  489. //
  490. // Function prototypes
  491. //
  492. ULONG
  493. DbgPrint(
  494. PCH Format,
  495. ...
  496. );
  497. char *nt_fgets(char *buffer, int len, void *input_stream);
  498. char *nt_gets(char *buffer);
  499. #define GetVDMAddr(usSeg,usOff) (((ULONG)usSeg << 4) + usOff)
  500. PX86CONTEXT getIntelRegistersPointer(VOID);
  501. #else
  502. /*********************** FOR MIPS BUILD ***************************/
  503. #define GetVDMAddr(usSeg,usOff) Sim32pGetVDMPointer((ULONG)(((ULONG)usSeg << 16) | usOff),FALSE)
  504. #define RMSEGOFFTOLIN(seg, off) (PVOID)(((ULONG)(seg) << 4) + (ULONG)(off))
  505. extern BOOL Sim32FlushVDMPointer (ULONG, USHORT, PBYTE , BOOL);
  506. extern BOOL Sim32FreeVDMPointer (ULONG, USHORT, PBYTE , BOOL);
  507. extern BOOL Sim32GetVDMMemory (ULONG, USHORT, PBYTE , BOOL);
  508. extern BOOL Sim32SetVDMMemory (ULONG, USHORT, PBYTE , BOOL);
  509. extern VOID sas_overwrite_memory(PBYTE, ULONG);
  510. extern UCHAR getAL(VOID);
  511. extern UCHAR getCL(VOID);
  512. extern UCHAR getDL(VOID);
  513. extern UCHAR getBL(VOID);
  514. extern UCHAR getAH(VOID);
  515. extern UCHAR getCH(VOID);
  516. extern UCHAR getDH(VOID);
  517. extern UCHAR getBH(VOID);
  518. extern VOID setAL(UCHAR val);
  519. extern VOID setCL(UCHAR val);
  520. extern VOID setDL(UCHAR val);
  521. extern VOID setBL(UCHAR val);
  522. extern VOID setAH(UCHAR val);
  523. extern VOID setCH(UCHAR val);
  524. extern VOID setDH(UCHAR val);
  525. extern VOID setBH(UCHAR val);
  526. extern USHORT getAX(VOID);
  527. extern USHORT getCX(VOID);
  528. extern USHORT getDX(VOID);
  529. extern USHORT getBX(VOID);
  530. extern USHORT getSP(VOID);
  531. extern USHORT getBP(VOID);
  532. extern USHORT getSI(VOID);
  533. extern USHORT getDI(VOID);
  534. extern USHORT getIP(VOID);
  535. extern VOID setAX(USHORT val);
  536. extern VOID setCX(USHORT val);
  537. extern VOID setDX(USHORT val);
  538. extern VOID setBX(USHORT val);
  539. extern VOID setSP(USHORT val);
  540. extern VOID setBP(USHORT val);
  541. extern VOID setSI(USHORT val);
  542. extern VOID setDI(USHORT val);
  543. extern VOID setIP(USHORT val);
  544. extern ULONG getEAX(VOID);
  545. extern ULONG getECX(VOID);
  546. extern ULONG getEDX(VOID);
  547. extern ULONG getEBX(VOID);
  548. extern ULONG getESP(VOID);
  549. extern ULONG getEBP(VOID);
  550. extern ULONG getESI(VOID);
  551. extern ULONG getEDI(VOID);
  552. extern ULONG getEIP(VOID);
  553. extern VOID setEAX(ULONG val);
  554. extern VOID setECX(ULONG val);
  555. extern VOID setEDX(ULONG val);
  556. extern VOID setEBX(ULONG val);
  557. extern VOID setESP(ULONG val);
  558. extern VOID setEBP(ULONG val);
  559. extern VOID setESI(ULONG val);
  560. extern VOID setEDI(ULONG val);
  561. extern VOID setEIP(ULONG val);
  562. extern USHORT getES(VOID);
  563. extern USHORT getCS(VOID);
  564. extern USHORT getSS(VOID);
  565. extern USHORT getDS(VOID);
  566. extern USHORT getFS(VOID);
  567. extern USHORT getGS(VOID);
  568. extern VOID setES(USHORT val);
  569. extern VOID setCS(USHORT val);
  570. extern VOID setSS(USHORT val);
  571. extern VOID setDS(USHORT val);
  572. extern VOID setFS(USHORT val);
  573. extern VOID setGS(USHORT val);
  574. extern ULONG getAF(VOID);
  575. extern ULONG getCF(VOID);
  576. extern ULONG getDF(VOID);
  577. extern ULONG getIF(VOID);
  578. extern ULONG getOF(VOID);
  579. extern ULONG getPF(VOID);
  580. extern ULONG getSF(VOID);
  581. extern ULONG getTF(VOID);
  582. extern ULONG getZF(VOID);
  583. extern ULONG getIOPL(VOID);
  584. extern ULONG getNT(VOID);
  585. extern USHORT getSTATUS(VOID);
  586. extern ULONG getEFLAGS(VOID);
  587. extern USHORT getMSW(VOID);
  588. extern VOID setAF(ULONG val);
  589. extern VOID setCF(ULONG val);
  590. extern VOID setDF(ULONG val);
  591. extern VOID setIF(ULONG val);
  592. extern VOID setOF(ULONG val);
  593. extern VOID setPF(ULONG val);
  594. extern VOID setSF(ULONG val);
  595. extern VOID setTF(ULONG val);
  596. extern VOID setZF(ULONG val);
  597. extern VOID setIOPL(ULONG val);
  598. extern VOID setNT(ULONG val);
  599. extern VOID setSTATUS(USHORT val);
  600. extern VOID setEFLAGS(ULONG val);
  601. extern VOID setMSW(USHORT val);
  602. extern ULONG getCR0(VOID);
  603. extern VOID setCR0(ULONG val);
  604. extern ULONG getSS_AR(VOID);
  605. extern ULONG getSS_BASE(VOID);
  606. extern VOID setSS_BASE_LIMIT_AR(ULONG base, ULONG limit, ULONG ar);
  607. extern VOID setCPL(ULONG val);
  608. #endif