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.

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