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.

441 lines
17 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // X86 machine implementation.
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  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 NUMBER_OF_387_REGS (X86_ST_LAST - X86_ST_FIRST + 1)
  26. #define NUMBER_OF_XMMI_REGS (X86_XMM_LAST - X86_XMM_FIRST + 1)
  27. #define X86_MAX_INSTRUCTION_LEN 16
  28. #define X86_INT3_LEN 1
  29. class BaseX86MachineInfo : public MachineInfo
  30. {
  31. public:
  32. BaseX86MachineInfo(TargetInfo* Target)
  33. : MachineInfo(Target) {}
  34. // MachineInfo.
  35. virtual void Assemble(ProcessInfo* Process,
  36. PADDR Addr, PSTR Input);
  37. virtual BOOL Disassemble(ProcessInfo* Process,
  38. PADDR Addr, PSTR Buffer, BOOL EffAddr);
  39. virtual BOOL IsBreakpointInstruction(ProcessInfo* Process, PADDR Addr);
  40. virtual HRESULT InsertBreakpointInstruction(PUSER_DEBUG_SERVICES Services,
  41. ULONG64 Process,
  42. ULONG64 Offset,
  43. ULONG Flags,
  44. PUCHAR SaveInstr,
  45. PULONG64 ChangeStart,
  46. PULONG ChangeLen);
  47. virtual HRESULT RemoveBreakpointInstruction(PUSER_DEBUG_SERVICES Services,
  48. ULONG64 Process,
  49. ULONG64 Offset,
  50. PUCHAR SaveInstr,
  51. PULONG64 ChangeStart,
  52. PULONG ChangeLen);
  53. virtual void AdjustPCPastBreakpointInstruction(PADDR Addr,
  54. ULONG BreakType);
  55. virtual BOOL IsCallDisasm(PCSTR Disasm);
  56. virtual BOOL IsReturnDisasm(PCSTR Disasm);
  57. virtual BOOL IsSystemCallDisasm(PCSTR Disasm);
  58. virtual BOOL IsDelayInstruction(PADDR Addr);
  59. virtual void GetEffectiveAddr(PADDR Addr, PULONG Size);
  60. virtual void GetNextOffset(ProcessInfo* Process, BOOL StepOver,
  61. PADDR NextAddr, PULONG NextMachine);
  62. virtual void IncrementBySmallestInstruction(PADDR Addr);
  63. virtual void DecrementBySmallestInstruction(PADDR Addr);
  64. // BaseX86MachineInfo.
  65. protected:
  66. ULONG GetMmxRegOffset(ULONG Index, ULONG Fpsw)
  67. {
  68. // The FP register area where the MMX registers are
  69. // aliased onto is stored out relative to the stack top. MMX
  70. // register assignments are fixed, though, so we need to
  71. // take into account the current FP stack top to correctly
  72. // determine which slot corresponds to which MMX
  73. // register.
  74. return (Index - (Fpsw >> 11)) & 7;
  75. }
  76. void DIdoModrm(ProcessInfo* Process, char **, int, BOOL);
  77. void OutputSymbol(char **, PUCHAR, int, int);
  78. BOOL OutputExactSymbol(char **, PUCHAR, int, int);
  79. ULONG GetSegReg(int SegOpcode);
  80. int ComputeJccEa(int Opcode, BOOL EaOut);
  81. };
  82. //----------------------------------------------------------------------------
  83. //
  84. // X86MachineInfo is the MachineInfo implementation specific
  85. // to a true X86 processor.
  86. //
  87. //----------------------------------------------------------------------------
  88. extern BOOL g_X86InCode16;
  89. extern BOOL g_X86InVm86;
  90. class X86MachineInfo : public BaseX86MachineInfo
  91. {
  92. public:
  93. X86MachineInfo(TargetInfo* Target);
  94. // MachineInfo.
  95. virtual HRESULT Initialize(void);
  96. virtual HRESULT InitializeForProcessor(void);
  97. virtual void GetSystemTypeInfo(PSYSTEM_TYPE_INFO Info);
  98. virtual void GetDefaultKdData(PKDDEBUGGER_DATA64 KdData);
  99. virtual void InitializeContext
  100. (ULONG64 Pc, PDBGKD_ANY_CONTROL_REPORT ControlReport);
  101. virtual HRESULT KdGetContextState(ULONG State);
  102. virtual HRESULT KdSetContext(void);
  103. virtual HRESULT ConvertContextFrom(PCROSS_PLATFORM_CONTEXT Context,
  104. ULONG FromSver,
  105. ULONG FromSize, PVOID From);
  106. virtual HRESULT ConvertContextTo(PCROSS_PLATFORM_CONTEXT Context,
  107. ULONG ToSver, ULONG ToSize, PVOID To);
  108. virtual void InitializeContextFlags(PCROSS_PLATFORM_CONTEXT Context,
  109. ULONG Version);
  110. virtual HRESULT GetContextFromThreadStack(ULONG64 ThreadBase,
  111. PCROSS_PLATFORM_CONTEXT Context,
  112. ULONG64 Stack);
  113. virtual HRESULT GetContextFromFiber(ProcessInfo* Process,
  114. ULONG64 FiberBase,
  115. PCROSS_PLATFORM_CONTEXT Context,
  116. BOOL Verbose);
  117. virtual HRESULT GetContextFromTrapFrame(ULONG64 TrapBase,
  118. PCROSS_PLATFORM_CONTEXT Context,
  119. BOOL Verbose);
  120. virtual HRESULT GetContextFromTaskSegment(ULONG64 TssBase,
  121. PCROSS_PLATFORM_CONTEXT Context,
  122. BOOL Verbose);
  123. virtual void GetScopeFrameFromContext(PCROSS_PLATFORM_CONTEXT Context,
  124. PDEBUG_STACK_FRAME ScopeFrame);
  125. virtual void GetStackDefaultsFromContext(PCROSS_PLATFORM_CONTEXT Context,
  126. LPADDRESS64 Instr,
  127. LPADDRESS64 Stack,
  128. LPADDRESS64 Frame);
  129. virtual HRESULT GetScopeFrameRegister(ULONG Reg,
  130. PDEBUG_STACK_FRAME ScopeFrame,
  131. PULONG64 Value);
  132. virtual HRESULT SetScopeFrameRegister(ULONG Reg,
  133. PDEBUG_STACK_FRAME ScopeFrame,
  134. ULONG64 Value);
  135. virtual void SanitizeMemoryContext(PCROSS_PLATFORM_CONTEXT Context);
  136. virtual HRESULT GetExdiContext(IUnknown* Exdi,
  137. PEXDI_CONTEXT Context,
  138. EXDI_CONTEXT_TYPE CtxType);
  139. virtual HRESULT SetExdiContext(IUnknown* Exdi,
  140. PEXDI_CONTEXT Context,
  141. EXDI_CONTEXT_TYPE CtxType);
  142. virtual void ConvertExdiContextFromContext(PCROSS_PLATFORM_CONTEXT Context,
  143. PEXDI_CONTEXT ExdiContext,
  144. EXDI_CONTEXT_TYPE CtxType);
  145. virtual void ConvertExdiContextToContext(PEXDI_CONTEXT ExdiContext,
  146. EXDI_CONTEXT_TYPE CtxType,
  147. PCROSS_PLATFORM_CONTEXT Context);
  148. virtual void ConvertExdiContextToSegDescs(PEXDI_CONTEXT ExdiContext,
  149. EXDI_CONTEXT_TYPE CtxType,
  150. ULONG Start, ULONG Count,
  151. PDESCRIPTOR64 Descs);
  152. virtual void ConvertExdiContextFromSpecial
  153. (PCROSS_PLATFORM_KSPECIAL_REGISTERS Special,
  154. PEXDI_CONTEXT ExdiContext,
  155. EXDI_CONTEXT_TYPE CtxType);
  156. virtual void ConvertExdiContextToSpecial
  157. (PEXDI_CONTEXT ExdiContext,
  158. EXDI_CONTEXT_TYPE CtxType,
  159. PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  160. virtual int GetType(ULONG Reg);
  161. virtual HRESULT GetVal(ULONG Reg, REGVAL* Val);
  162. virtual HRESULT SetVal(ULONG Reg, REGVAL* Val);
  163. virtual void GetPC(PADDR Address);
  164. virtual void SetPC(PADDR Address);
  165. virtual void GetFP(PADDR Address);
  166. virtual void GetSP(PADDR Address);
  167. virtual ULONG64 GetArgReg(void);
  168. virtual ULONG64 GetRetReg(void);
  169. virtual ULONG GetSegRegNum(ULONG SegReg);
  170. virtual HRESULT GetSegRegDescriptor(ULONG SegReg, PDESCRIPTOR64 Desc);
  171. virtual void OutputAll(ULONG Mask, ULONG OutMask);
  172. virtual HRESULT SetAndOutputTrapFrame(ULONG64 TrapBase,
  173. PCROSS_PLATFORM_CONTEXT Context);
  174. virtual HRESULT SetAndOutputTaskSegment(ULONG64 TssBase,
  175. PCROSS_PLATFORM_CONTEXT Context,
  176. BOOL Extended);
  177. virtual TRACEMODE GetTraceMode(void);
  178. virtual void SetTraceMode(TRACEMODE Mode);
  179. virtual BOOL IsStepStatusSupported(ULONG Status);
  180. virtual void KdUpdateControlSet
  181. (PDBGKD_ANY_CONTROL_SET ControlSet);
  182. virtual ULONG ExecutingMachine(void);
  183. virtual HRESULT SetPageDirectory(ThreadInfo* Thread,
  184. ULONG Idx, ULONG64 PageDir,
  185. PULONG NextIdx);
  186. virtual HRESULT GetVirtualTranslationPhysicalOffsets
  187. (ThreadInfo* Thread, ULONG64 Virt, PULONG64 Offsets, ULONG OffsetsSize,
  188. PULONG Levels, PULONG PfIndex, PULONG64 LastVal);
  189. virtual HRESULT GetBaseTranslationVirtualOffset(PULONG64 Offset);
  190. virtual void DecodePte(ULONG64 Pte, PULONG64 PageFrameNumber,
  191. PULONG Flags);
  192. virtual HRESULT NewBreakpoint(DebugClient* Client,
  193. ULONG Type,
  194. ULONG Id,
  195. Breakpoint** RetBp);
  196. virtual void InsertThreadDataBreakpoints(void);
  197. virtual void RemoveThreadDataBreakpoints(void);
  198. virtual ULONG IsBreakpointOrStepException(PEXCEPTION_RECORD64 Record,
  199. ULONG FirstChance,
  200. PADDR BpAddr,
  201. PADDR RelAddr);
  202. virtual void PrintStackFrameAddressesTitle(ULONG Flags);
  203. virtual void PrintStackFrameAddresses(ULONG Flags,
  204. PDEBUG_STACK_FRAME StackFrame);
  205. virtual void PrintStackArgumentsTitle(ULONG Flags);
  206. virtual void PrintStackArguments(ULONG Flags,
  207. PDEBUG_STACK_FRAME StackFrame);
  208. virtual void PrintStackCallSiteTitle(ULONG Flags);
  209. virtual void PrintStackCallSite(ULONG Flags,
  210. PDEBUG_STACK_FRAME StackFrame,
  211. PSYMBOL_INFO SiteSymbol,
  212. PSTR SymName,
  213. DWORD64 Displacement);
  214. virtual void PrintStackFrameMemoryUsage(PDEBUG_STACK_FRAME CurFrame,
  215. PDEBUG_STACK_FRAME PrevFrame);
  216. virtual void OutputFunctionEntry(PVOID RawEntry);
  217. virtual HRESULT ReadKernelProcessorId
  218. (ULONG Processor, PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id);
  219. virtual HRESULT GetAlternateTriageDumpDataRanges(ULONG64 PrcbBase,
  220. ULONG64 ThreadBase,
  221. PADDR_RANGE Ranges);
  222. // X86MachineInfo.
  223. protected:
  224. BOOL m_SupportsBranchTrace;
  225. BOOL m_ResetBranchTrace;
  226. void KdGetSpecialRegistersFromContext(void);
  227. void KdSetSpecialRegistersInContext(void);
  228. ULONG GetIntReg(ULONG regnum);
  229. PULONG64 GetMmxRegSlot(ULONG regnum);
  230. void GetMmxReg(ULONG regnum, REGVAL *val);
  231. void GetFloatReg(ULONG regnum, REGVAL *val);
  232. };
  233. //
  234. // X86 register names that are reused in other places.
  235. //
  236. extern char g_Gs[];
  237. extern char g_Fs[];
  238. extern char g_Es[];
  239. extern char g_Ds[];
  240. extern char g_Edi[];
  241. extern char g_Esi[];
  242. extern char g_Ebx[];
  243. extern char g_Edx[];
  244. extern char g_Ecx[];
  245. extern char g_Eax[];
  246. extern char g_Ebp[];
  247. extern char g_Eip[];
  248. extern char g_Cs[];
  249. extern char g_Efl[];
  250. extern char g_Esp[];
  251. extern char g_Ss[];
  252. extern char g_Dr0[];
  253. extern char g_Dr1[];
  254. extern char g_Dr2[];
  255. extern char g_Dr3[];
  256. extern char g_Dr6[];
  257. extern char g_Dr7[];
  258. extern char g_Cr0[];
  259. extern char g_Cr2[];
  260. extern char g_Cr3[];
  261. extern char g_Cr4[];
  262. extern char g_Gdtr[];
  263. extern char g_Gdtl[];
  264. extern char g_Idtr[];
  265. extern char g_Idtl[];
  266. extern char g_Tr[];
  267. extern char g_Ldtr[];
  268. extern char g_Di[];
  269. extern char g_Si[];
  270. extern char g_Bx[];
  271. extern char g_Dx[];
  272. extern char g_Cx[];
  273. extern char g_Ax[];
  274. extern char g_Bp[];
  275. extern char g_Ip[];
  276. extern char g_Fl[];
  277. extern char g_Sp[];
  278. extern char g_Bl[];
  279. extern char g_Dl[];
  280. extern char g_Cl[];
  281. extern char g_Al[];
  282. extern char g_Bh[];
  283. extern char g_Dh[];
  284. extern char g_Ch[];
  285. extern char g_Ah[];
  286. extern char g_Iopl[];
  287. extern char g_Of[];
  288. extern char g_Df[];
  289. extern char g_If[];
  290. extern char g_Tf[];
  291. extern char g_Sf[];
  292. extern char g_Zf[];
  293. extern char g_Af[];
  294. extern char g_Pf[];
  295. extern char g_Cf[];
  296. extern char g_Vip[];
  297. extern char g_Vif[];
  298. extern char g_Fpcw[];
  299. extern char g_Fpsw[];
  300. extern char g_Fptw[];
  301. extern char g_St0[];
  302. extern char g_St1[];
  303. extern char g_St2[];
  304. extern char g_St3[];
  305. extern char g_St4[];
  306. extern char g_St5[];
  307. extern char g_St6[];
  308. extern char g_St7[];
  309. extern char g_Mm0[];
  310. extern char g_Mm1[];
  311. extern char g_Mm2[];
  312. extern char g_Mm3[];
  313. extern char g_Mm4[];
  314. extern char g_Mm5[];
  315. extern char g_Mm6[];
  316. extern char g_Mm7[];
  317. extern char g_Mxcsr[];
  318. extern char g_Xmm0[];
  319. extern char g_Xmm1[];
  320. extern char g_Xmm2[];
  321. extern char g_Xmm3[];
  322. extern char g_Xmm4[];
  323. extern char g_Xmm5[];
  324. extern char g_Xmm6[];
  325. extern char g_Xmm7[];
  326. //----------------------------------------------------------------------------
  327. //
  328. // This class handles the case of X86 instructions executing natively
  329. // on an IA64 processor. It operates just as the X86 machine does
  330. // except that:
  331. // Context state is retrieved and set through the
  332. // IA64 register state as defined in the X86-on-IA64 support.
  333. //
  334. // Implementation is in the IA64 code.
  335. //
  336. //----------------------------------------------------------------------------
  337. class X86OnIa64MachineInfo : public X86MachineInfo
  338. {
  339. public:
  340. X86OnIa64MachineInfo(TargetInfo* Target);
  341. virtual HRESULT UdGetContextState(ULONG State);
  342. virtual HRESULT UdSetContext(void);
  343. virtual HRESULT KdGetContextState(ULONG State);
  344. virtual HRESULT KdSetContext(void);
  345. virtual HRESULT GetSegRegDescriptor(ULONG SegReg, PDESCRIPTOR64 Desc);
  346. virtual HRESULT NewBreakpoint(DebugClient* Client,
  347. ULONG Type,
  348. ULONG Id,
  349. Breakpoint** RetBp);
  350. virtual ULONG IsBreakpointOrStepException(PEXCEPTION_RECORD64 Record,
  351. ULONG FirstChance,
  352. PADDR BpAddr,
  353. PADDR RelAddr);
  354. private:
  355. void X86ContextToIa64(PX86_NT5_CONTEXT X86Context,
  356. PIA64_CONTEXT Ia64Context);
  357. void Ia64ContextToX86(PIA64_CONTEXT Ia64Context,
  358. PX86_NT5_CONTEXT X86Context);
  359. };
  360. //----------------------------------------------------------------------------
  361. //
  362. // This class handles the case of IA32 instructions executing
  363. // on an AMD64 processor. It operates just as the X86 machine does
  364. // except that:
  365. // Context state is retrieved and set through the
  366. // AMD64 register state as defined in the IA32-on-AMD64 support.
  367. //
  368. // Implementation is in the AMD64 code.
  369. //
  370. //----------------------------------------------------------------------------
  371. class X86OnAmd64MachineInfo : public X86MachineInfo
  372. {
  373. public:
  374. X86OnAmd64MachineInfo(TargetInfo* Target);
  375. virtual HRESULT UdGetContextState(ULONG State);
  376. virtual HRESULT UdSetContext(void);
  377. virtual HRESULT KdGetContextState(ULONG State);
  378. virtual HRESULT KdSetContext(void);
  379. virtual HRESULT GetSegRegDescriptor(ULONG SegReg, PDESCRIPTOR64 Desc);
  380. private:
  381. void X86ContextToAmd64(PX86_NT5_CONTEXT X86Context,
  382. PAMD64_CONTEXT Amd64Context);
  383. void Amd64ContextToX86(PAMD64_CONTEXT Amd64Context,
  384. PX86_NT5_CONTEXT X86Context);
  385. };
  386. #endif // #ifndef __I386_MACH_HPP__