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.

368 lines
13 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // X86 machine implementation.
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __I386_MACH_HPP__
  9. #define __I386_MACH_HPP__
  10. //
  11. // NOTE: Be very careful when using machine-specific header files
  12. // such as nt<plat>.h. The machine implementation class is
  13. // compiled for all platforms so the nt<plat>.h file will be the
  14. // one for the build platform, not necessarily the platform
  15. // of the machine implementation. ntdbg.h contains many cross-platform
  16. // types and definitions that can be used to avoid problems.
  17. //
  18. //----------------------------------------------------------------------------
  19. //
  20. // X86 instruction support exists on many different processors.
  21. // BaseX86MachineInfo contains implementations of MachineInfo
  22. // methods that apply to all machines supporting X86 instructions.
  23. //
  24. //----------------------------------------------------------------------------
  25. #define X86_MAX_INSTRUCTION_LEN 16
  26. #define X86_INT3_LEN 1
  27. class BaseX86MachineInfo : public MachineInfo
  28. {
  29. public:
  30. // MachineInfo.
  31. virtual void Assemble(PADDR Addr, PSTR Input);
  32. virtual BOOL Disassemble(PADDR Addr, PSTR Buffer, BOOL EffAddr);
  33. virtual BOOL IsBreakpointInstruction(PADDR Addr);
  34. virtual HRESULT InsertBreakpointInstruction(PUSER_DEBUG_SERVICES Services,
  35. ULONG64 Process,
  36. ULONG64 Offset,
  37. PUCHAR SaveInstr,
  38. PULONG64 ChangeStart,
  39. PULONG ChangeLen);
  40. virtual HRESULT RemoveBreakpointInstruction(PUSER_DEBUG_SERVICES Services,
  41. ULONG64 Process,
  42. ULONG64 Offset,
  43. PUCHAR SaveInstr,
  44. PULONG64 ChangeStart,
  45. PULONG ChangeLen);
  46. virtual void AdjustPCPastBreakpointInstruction(PADDR Addr,
  47. ULONG BreakType);
  48. virtual BOOL IsCallDisasm(PCSTR Disasm);
  49. virtual BOOL IsReturnDisasm(PCSTR Disasm);
  50. virtual BOOL IsSystemCallDisasm(PCSTR Disasm);
  51. virtual BOOL IsDelayInstruction(PADDR Addr);
  52. virtual void GetEffectiveAddr(PADDR Addr);
  53. virtual void GetNextOffset(BOOL StepOver,
  54. PADDR NextAddr, PULONG NextMachine);
  55. virtual void IncrementBySmallestInstruction(PADDR Addr);
  56. virtual void DecrementBySmallestInstruction(PADDR Addr);
  57. // BaseX86MachineInfo.
  58. protected:
  59. ULONG GetMmxRegOffset(ULONG Index, ULONG Fpsw)
  60. {
  61. // The FP register area where the MMX registers are
  62. // aliased onto is stored out relative to the stack top. MMX
  63. // register assignments are fixed, though, so we need to
  64. // take into account the current FP stack top to correctly
  65. // determine which slot corresponds to which MMX
  66. // register.
  67. return (Index - (Fpsw >> 11)) & 7;
  68. }
  69. void DIdoModrm(char **, int, BOOL);
  70. void OutputSymbol(char **, PUCHAR, int, int);
  71. BOOL OutputExactSymbol(char **, PUCHAR, int, int);
  72. ULONG GetSegReg(int SegOpcode);
  73. int ComputeJccEa(int Opcode, BOOL EaOut);
  74. };
  75. //----------------------------------------------------------------------------
  76. //
  77. // X86MachineInfo is the MachineInfo implementation specific
  78. // to a true X86 processor.
  79. //
  80. //----------------------------------------------------------------------------
  81. extern BOOL g_X86InCode16;
  82. extern BOOL g_X86InVm86;
  83. class X86MachineInfo : public BaseX86MachineInfo
  84. {
  85. public:
  86. // MachineInfo.
  87. virtual HRESULT InitializeConstants(void);
  88. virtual HRESULT InitializeForTarget(void);
  89. virtual HRESULT InitializeForProcessor(void);
  90. virtual void InitializeContext
  91. (ULONG64 Pc, PDBGKD_ANY_CONTROL_REPORT ControlReport);
  92. virtual HRESULT KdGetContextState(ULONG State);
  93. virtual HRESULT KdSetContext(void);
  94. virtual HRESULT ConvertContextFrom(PCROSS_PLATFORM_CONTEXT Context,
  95. ULONG FromSver,
  96. ULONG FromSize, PVOID From);
  97. virtual HRESULT ConvertContextTo(PCROSS_PLATFORM_CONTEXT Context,
  98. ULONG ToSver, ULONG ToSize, PVOID To);
  99. virtual void InitializeContextFlags(PCROSS_PLATFORM_CONTEXT Context,
  100. ULONG Version);
  101. virtual HRESULT GetContextFromThreadStack(ULONG64 ThreadBase,
  102. PCROSS_PLATFORM_THREAD Thread,
  103. PCROSS_PLATFORM_CONTEXT Context,
  104. PDEBUG_STACK_FRAME Frame,
  105. PULONG RunningOnProc);
  106. virtual HRESULT GetExdiContext(IUnknown* Exdi, PEXDI_CONTEXT Context);
  107. virtual HRESULT SetExdiContext(IUnknown* Exdi, PEXDI_CONTEXT Context);
  108. virtual void ConvertExdiContextFromContext(PCROSS_PLATFORM_CONTEXT Context,
  109. PEXDI_CONTEXT ExdiContext);
  110. virtual void ConvertExdiContextToContext(PEXDI_CONTEXT ExdiContext,
  111. PCROSS_PLATFORM_CONTEXT Context);
  112. virtual void ConvertExdiContextToSegDescs(PEXDI_CONTEXT ExdiContext,
  113. ULONG Start, ULONG Count,
  114. PDESCRIPTOR64 Descs);
  115. virtual void ConvertExdiContextFromSpecial
  116. (PCROSS_PLATFORM_KSPECIAL_REGISTERS Special,
  117. PEXDI_CONTEXT ExdiContext);
  118. virtual void ConvertExdiContextToSpecial
  119. (PEXDI_CONTEXT ExdiContext,
  120. PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  121. virtual int GetType(ULONG index);
  122. virtual BOOL GetVal(ULONG index, REGVAL *val);
  123. virtual BOOL SetVal(ULONG index, REGVAL *val);
  124. virtual void GetPC(PADDR Address);
  125. virtual void SetPC(PADDR Address);
  126. virtual void GetFP(PADDR Address);
  127. virtual void GetSP(PADDR Address);
  128. virtual ULONG64 GetArgReg(void);
  129. virtual ULONG GetSegRegNum(ULONG SegReg);
  130. virtual HRESULT GetSegRegDescriptor(ULONG SegReg, PDESCRIPTOR64 Desc);
  131. virtual void OutputAll(ULONG Mask, ULONG OutMask);
  132. virtual TRACEMODE GetTraceMode(void);
  133. virtual void SetTraceMode(TRACEMODE Mode);
  134. virtual BOOL IsStepStatusSupported(ULONG Status);
  135. virtual void KdUpdateControlSet
  136. (PDBGKD_ANY_CONTROL_SET ControlSet);
  137. virtual void KdSaveProcessorState(void);
  138. virtual void KdRestoreProcessorState(void);
  139. virtual ULONG ExecutingMachine(void);
  140. virtual HRESULT SetPageDirectory(ULONG Idx, ULONG64 PageDir,
  141. PULONG NextIdx);
  142. virtual HRESULT GetVirtualTranslationPhysicalOffsets
  143. (ULONG64 Virt, PULONG64 Offsets, ULONG OffsetsSize,
  144. PULONG Levels, PULONG PfIndex, PULONG64 LastVal);
  145. virtual HRESULT GetBaseTranslationVirtualOffset(PULONG64 Offset);
  146. virtual HRESULT NewBreakpoint(DebugClient* Client,
  147. ULONG Type,
  148. ULONG Id,
  149. Breakpoint** RetBp);
  150. virtual void InsertAllDataBreakpoints(void);
  151. virtual void RemoveAllDataBreakpoints(void);
  152. virtual ULONG IsBreakpointOrStepException(PEXCEPTION_RECORD64 Record,
  153. ULONG FirstChance,
  154. PADDR BpAddr,
  155. PADDR RelAddr);
  156. virtual BOOL DisplayTrapFrame(ULONG64 FrameAddress,
  157. PCROSS_PLATFORM_CONTEXT Context);
  158. virtual void ValidateCxr(PCROSS_PLATFORM_CONTEXT Context);
  159. HRESULT DumpTSS(void);
  160. virtual void PrintStackFrameAddressesTitle(ULONG Flags);
  161. virtual void PrintStackFrameAddresses(ULONG Flags,
  162. PDEBUG_STACK_FRAME StackFrame);
  163. virtual void PrintStackArgumentsTitle(ULONG Flags);
  164. virtual void PrintStackArguments(ULONG Flags,
  165. PDEBUG_STACK_FRAME StackFrame);
  166. virtual void PrintStackCallSiteTitle(ULONG Flags);
  167. virtual void PrintStackCallSite(ULONG Flags,
  168. PDEBUG_STACK_FRAME StackFrame,
  169. CHAR SymBuf[], DWORD64 Displacement,
  170. USHORT StdCallArgs);
  171. virtual void OutputFunctionEntry(PVOID RawEntry);
  172. virtual HRESULT ReadKernelProcessorId
  173. (ULONG Processor, PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id);
  174. // X86MachineInfo.
  175. protected:
  176. X86_KSPECIAL_REGISTERS m_SpecialRegContext, m_SavedSpecialRegContext;
  177. BOOL m_SupportsBranchTrace;
  178. void KdGetSpecialRegistersFromContext(void);
  179. void KdSetSpecialRegistersInContext(void);
  180. ULONG GetIntReg(ULONG regnum);
  181. PULONG64 GetMmxRegSlot(ULONG regnum);
  182. void GetMmxReg(ULONG regnum, REGVAL *val);
  183. void GetFloatReg(ULONG regnum, REGVAL *val);
  184. ULONG64 Selector2Address(USHORT TaskRegister);
  185. };
  186. extern X86MachineInfo g_X86Machine;
  187. //
  188. // X86 register names that are reused in other places.
  189. //
  190. extern char g_Gs[];
  191. extern char g_Fs[];
  192. extern char g_Es[];
  193. extern char g_Ds[];
  194. extern char g_Edi[];
  195. extern char g_Esi[];
  196. extern char g_Ebx[];
  197. extern char g_Edx[];
  198. extern char g_Ecx[];
  199. extern char g_Eax[];
  200. extern char g_Ebp[];
  201. extern char g_Eip[];
  202. extern char g_Cs[];
  203. extern char g_Efl[];
  204. extern char g_Esp[];
  205. extern char g_Ss[];
  206. extern char g_Dr0[];
  207. extern char g_Dr1[];
  208. extern char g_Dr2[];
  209. extern char g_Dr3[];
  210. extern char g_Dr6[];
  211. extern char g_Dr7[];
  212. extern char g_Cr0[];
  213. extern char g_Cr2[];
  214. extern char g_Cr3[];
  215. extern char g_Cr4[];
  216. extern char g_Gdtr[];
  217. extern char g_Gdtl[];
  218. extern char g_Idtr[];
  219. extern char g_Idtl[];
  220. extern char g_Tr[];
  221. extern char g_Ldtr[];
  222. extern char g_Di[];
  223. extern char g_Si[];
  224. extern char g_Bx[];
  225. extern char g_Dx[];
  226. extern char g_Cx[];
  227. extern char g_Ax[];
  228. extern char g_Bp[];
  229. extern char g_Ip[];
  230. extern char g_Fl[];
  231. extern char g_Sp[];
  232. extern char g_Bl[];
  233. extern char g_Dl[];
  234. extern char g_Cl[];
  235. extern char g_Al[];
  236. extern char g_Bh[];
  237. extern char g_Dh[];
  238. extern char g_Ch[];
  239. extern char g_Ah[];
  240. extern char g_Iopl[];
  241. extern char g_Of[];
  242. extern char g_Df[];
  243. extern char g_If[];
  244. extern char g_Tf[];
  245. extern char g_Sf[];
  246. extern char g_Zf[];
  247. extern char g_Af[];
  248. extern char g_Pf[];
  249. extern char g_Cf[];
  250. extern char g_Vip[];
  251. extern char g_Vif[];
  252. extern char g_Fpcw[];
  253. extern char g_Fpsw[];
  254. extern char g_Fptw[];
  255. extern char g_St0[];
  256. extern char g_St1[];
  257. extern char g_St2[];
  258. extern char g_St3[];
  259. extern char g_St4[];
  260. extern char g_St5[];
  261. extern char g_St6[];
  262. extern char g_St7[];
  263. extern char g_Mm0[];
  264. extern char g_Mm1[];
  265. extern char g_Mm2[];
  266. extern char g_Mm3[];
  267. extern char g_Mm4[];
  268. extern char g_Mm5[];
  269. extern char g_Mm6[];
  270. extern char g_Mm7[];
  271. extern char g_Mxcsr[];
  272. extern char g_Xmm0[];
  273. extern char g_Xmm1[];
  274. extern char g_Xmm2[];
  275. extern char g_Xmm3[];
  276. extern char g_Xmm4[];
  277. extern char g_Xmm5[];
  278. extern char g_Xmm6[];
  279. extern char g_Xmm7[];
  280. //----------------------------------------------------------------------------
  281. //
  282. // This class handles the case of X86 instructions executing natively
  283. // on an IA64 processor. It operates just as the X86 machine does
  284. // except that:
  285. // Context state is retrieved and set through the
  286. // IA64 register state as defined in the X86-on-IA64 support.
  287. //
  288. // Implementation is in the IA64 code.
  289. //
  290. //----------------------------------------------------------------------------
  291. class X86OnIa64MachineInfo : public X86MachineInfo
  292. {
  293. public:
  294. virtual HRESULT InitializeForProcessor(void);
  295. virtual HRESULT UdGetContextState(ULONG State);
  296. virtual HRESULT UdSetContext(void);
  297. virtual HRESULT KdGetContextState(ULONG State);
  298. virtual HRESULT KdSetContext(void);
  299. virtual HRESULT GetSegRegDescriptor(ULONG SegReg, PDESCRIPTOR64 Desc);
  300. virtual HRESULT NewBreakpoint(DebugClient* Client,
  301. ULONG Type,
  302. ULONG Id,
  303. Breakpoint** RetBp);
  304. virtual void InsertAllDataBreakpoints(void);
  305. virtual void RemoveAllDataBreakpoints(void);
  306. virtual ULONG IsBreakpointOrStepException(PEXCEPTION_RECORD64 Record,
  307. ULONG FirstChance,
  308. PADDR BpAddr,
  309. PADDR RelAddr);
  310. private:
  311. void X86ContextToIa64(PX86_NT5_CONTEXT X86Context,
  312. PIA64_CONTEXT Ia64Context);
  313. void Ia64ContextToX86(PIA64_CONTEXT Ia64Context,
  314. PX86_NT5_CONTEXT X86Context);
  315. };
  316. extern X86OnIa64MachineInfo g_X86OnIa64Machine;
  317. #endif // #ifndef __I386_MACH_HPP__