kdp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. kdp.h
  5. Abstract:
  6. This header contains internal definitions for the kernel debugging
  7. subsystem.
  8. Author:
  9. Evan Green 10-Aug-2012
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. //
  18. // Periodically check for incoming data when flying through single steps.
  19. //
  20. #define DEBUG_PERIODIC_BREAK_CHECK_MASK 0x1FF
  21. //
  22. // --------------------------------------------------------------------- Macros
  23. //
  24. #define KD_ASSERT_ONCE(_Expression) \
  25. if ((KdAsserted == FALSE) && (!(_Expression))) { \
  26. KdAsserted = TRUE; \
  27. KdBreak(); \
  28. } \
  29. //
  30. // Define these trace macros to something to debug KD (I/O port out, video
  31. // print, alternate UART, etc). See the KD_TRACE_EVENT and
  32. // KD_DEVICE_TRACE_EVENT for possible values.
  33. //
  34. #define KD_TRACE(_KdTraceEvent)
  35. #define KD_DEVICE_TRACE(_KdDeviceTraceEvent)
  36. //
  37. // ------------------------------------------------------ Data Type Definitions
  38. //
  39. /*++
  40. Structure Description:
  41. This structure describes a module state change notification.
  42. Members:
  43. Module - Supplies a pointer to the module that is being loaded or unloaded.
  44. Loading - Supplies a flag indicating whether the module is loading (TRUE)
  45. or unloading.
  46. --*/
  47. typedef struct _MODULE_CHANGE_NOTIFICATION {
  48. PDEBUG_MODULE Module;
  49. BOOL Loading;
  50. } MODULE_CHANGE_NOTIFICATION, *PMODULE_CHANGE_NOTIFICATION;
  51. typedef enum _KD_TRACE_EVENT {
  52. KdTraceExit,
  53. KdTraceInExceptionHandler,
  54. KdTraceDebuggingEnabled,
  55. KdTraceLockAcquired,
  56. KdTracePollBailing,
  57. KdTraceClearedSingleStep,
  58. KdTraceWaitingForFrozenProcessors,
  59. KdTraceProcessorsFrozen,
  60. KdTraceReceiveFailure,
  61. KdTraceProcessingCommand,
  62. KdTraceConnecting,
  63. KdTraceConnectBailing,
  64. KdTracePrinting,
  65. KdTraceSendingProfilingData,
  66. KdTraceModuleChange,
  67. KdTraceCheckSingleStep,
  68. KdTraceCommittingToBreak,
  69. KdTraceBailingUnconnected,
  70. KdTraceTransmitFailure,
  71. KdTraceThawingProcessors,
  72. } KD_TRACE_EVENT, *PKD_TRACE_EVENT;
  73. typedef enum _KD_DEVICE_TRACE_EVENT {
  74. KdDeviceTraceDisconnected,
  75. KdDeviceTraceResetting,
  76. KdDeviceTraceResetFailed,
  77. KdDeviceTraceResetComplete,
  78. KdDeviceTraceTransmitting,
  79. KdDeviceTraceTransmitFailed,
  80. KdDeviceTraceTransmitComplete,
  81. KdDeviceTraceReceiving,
  82. KdDeviceTraceReceiveFailed,
  83. KdDeviceTraceReceiveComplete,
  84. KdDeviceTraceGettingStatus,
  85. KdDeviceTraceGetStatusFailed,
  86. KdDeviceTraceGetStatusHasData,
  87. KdDeviceTraceGetStatusEmpty,
  88. KdDeviceTraceDisconnecting,
  89. } KD_DEVICE_TRACE_EVENT, *PKD_DEVICE_TRACE_EVENT;
  90. //
  91. // -------------------------------------------------------------------- Globals
  92. //
  93. //
  94. // Access some of the executive's variables directly. Though function calls are
  95. // available, using them makes those functions undebuggable.
  96. //
  97. extern volatile ULONG KeActiveProcessorCount;
  98. //
  99. // Variable used for one-time assertions.
  100. //
  101. extern BOOL KdAsserted;
  102. //
  103. // Store the machine architecture.
  104. //
  105. extern ULONG KdMachineType;
  106. //
  107. // Store a variable indicating whether freeze request are maskable interrupts
  108. // or NMIs.
  109. //
  110. extern BOOL KdFreezesAreMaskable;
  111. //
  112. // -------------------------------------------------------- Function Prototypes
  113. //
  114. KSTATUS
  115. KdpUsbGetHandoffData (
  116. PDEBUG_HANDOFF_DATA Data
  117. );
  118. /*++
  119. Routine Description:
  120. This routine returns a pointer to the handoff data the USB driver needs to
  121. operate with a USB debug host controller.
  122. Arguments:
  123. Data - Supplies a pointer where a pointer to the handoff data is returned.
  124. Return Value:
  125. STATUS_SUCCESS on success.
  126. STATUS_NO_ELIGIBLE_DEVICES if there is no USB debug device.
  127. --*/
  128. ULONG
  129. KdpValidateMemoryAccess (
  130. PVOID Address,
  131. ULONG Length,
  132. PBOOL Writable
  133. );
  134. /*++
  135. Routine Description:
  136. This routine validates that access to a specified location in memory will
  137. not cause a page fault.
  138. Arguments:
  139. Address - Supplies the virtual address of the memory that will be read or
  140. written.
  141. Length - Supplies how many bytes at that location the caller would like to
  142. read or write.
  143. Writable - Supplies an optional pointer that receives a boolean indicating
  144. whether or not the memory range is mapped writable.
  145. Return Value:
  146. Returns the number of bytes from the beginning of the address that are
  147. accessible. If the memory is completely available, the return value will be
  148. equal to the Length parameter. If the memory is completely paged out, 0
  149. will be returned.
  150. --*/
  151. VOID
  152. KdpModifyAddressMapping (
  153. PVOID Address,
  154. BOOL Writable,
  155. PBOOL WasWritable
  156. );
  157. /*++
  158. Routine Description:
  159. This routine modifies the mapping properties for the page that contains the
  160. given address.
  161. Arguments:
  162. Address - Supplies the virtual address of the memory whose mapping
  163. properties are to be changed.
  164. Writable - Supplies a boolean indicating whether or not to make the page
  165. containing the address writable (TRUE) or read-only (FALSE).
  166. WasWritable - Supplies a pointer that receives a boolean indicating whether
  167. or not the page was writable (TRUE) or read-only (FALSE) before any
  168. modifications.
  169. Return Value:
  170. None.
  171. --*/
  172. VOID
  173. KdpInitializeDebuggingHardware (
  174. VOID
  175. );
  176. /*++
  177. Routine Description:
  178. This routine initializes any architecture dependent debugging hardware.
  179. Arguments:
  180. None.
  181. Return Value:
  182. None.
  183. --*/
  184. VOID
  185. KdpBreak (
  186. VOID
  187. );
  188. /*++
  189. Routine Description:
  190. This routine causes a break into the debugger.
  191. Arguments:
  192. None.
  193. Return Value:
  194. None.
  195. --*/
  196. VOID
  197. KdpInternalPrint (
  198. PSTR Format,
  199. ...
  200. );
  201. /*++
  202. Routine Description:
  203. This routine prints to the debug client window. This routine can only be
  204. called from *inside* the debug exception handler.
  205. Arguments:
  206. Format - Supplies the printf-style format string.
  207. ... - Supplies additional values as dictated by the format.
  208. Return Value:
  209. None.
  210. --*/
  211. VOID
  212. KdpClearSingleStepMode (
  213. PULONG Exception,
  214. PTRAP_FRAME TrapFrame,
  215. PVOID *PreviousSingleStepAddress
  216. );
  217. /*++
  218. Routine Description:
  219. This routine turns off single step mode.
  220. Arguments:
  221. Exception - Supplies the type of exception that this function is handling.
  222. TrapFrame - Supplies a pointer to the state of the machine immediately
  223. before the debug exception occurred. Also returns the possibly modified
  224. machine state.
  225. PreviousSingleStepAddress - Supplies a pointer where the address the
  226. single step breakpoint was set will be returned, if a software-based
  227. single step mechanism is in use.
  228. Return Value:
  229. None.
  230. --*/
  231. VOID
  232. KdpSetSingleStepMode (
  233. ULONG Exception,
  234. PTRAP_FRAME TrapFrame,
  235. PVOID SingleStepAddress
  236. );
  237. /*++
  238. Routine Description:
  239. This routine turns on single step mode.
  240. Arguments:
  241. Exception - Supplies the type of exception that this function is handling.
  242. TrapFrame - Supplies a pointer to the state of the machine immediately
  243. before the debug exception occurred. Also returns the possibly modified
  244. machine state.
  245. SingleStepAddress - Supplies an optional pointer where the breakpoint
  246. should be set. This is only used by software based single step
  247. mechanisms to restore a previously unset single step breakpoint. If
  248. this is NULL, then the next instruction will be calculated from the
  249. current trap frame.
  250. Return Value:
  251. None.
  252. --*/
  253. VOID
  254. KdpInvalidateInstructionCache (
  255. VOID
  256. );
  257. /*++
  258. Routine Description:
  259. This routine invalidates the instruction cache to PoU inner shareable.
  260. Arguments:
  261. None.
  262. Return Value:
  263. None.
  264. --*/
  265. VOID
  266. KdpCleanMemory (
  267. PVOID Address
  268. );
  269. /*++
  270. Routine Description:
  271. This routine cleans memory modified by the kernel debugger, flushing it
  272. out of the instruciton and data caches.
  273. Arguments:
  274. Address - Supplies the address whose associated cache line will be
  275. cleaned.
  276. Return Value:
  277. None.
  278. --*/
  279. PVOID
  280. KdpGetInstructionPointer (
  281. PTRAP_FRAME TrapFrame
  282. );
  283. /*++
  284. Routine Description:
  285. This routine returns the instruction pointer in the trap frame.
  286. Arguments:
  287. TrapFrame - Supplies a pointer to the state of the machine immediately
  288. before the debug exception occurred.
  289. Return Value:
  290. Returns the current instruction pointer.
  291. --*/
  292. PVOID
  293. KdpGetInstructionPointerAddress (
  294. PTRAP_FRAME TrapFrame
  295. );
  296. /*++
  297. Routine Description:
  298. This routine returns the memory address corresponding to the current
  299. instruction pointer.
  300. Arguments:
  301. TrapFrame - Supplies a pointer to the state of the machine immediately
  302. before the debug exception occurred.
  303. Return Value:
  304. Returns the current instruction pointer address.
  305. --*/
  306. VOID
  307. KdpGetRegisters (
  308. PTRAP_FRAME TrapFrame,
  309. PVOID Registers
  310. );
  311. /*++
  312. Routine Description:
  313. This routine writes the register values from the trap frame into the
  314. debugger packet.
  315. Arguments:
  316. TrapFrame - Supplies a pointer to the current processor state.
  317. Registers - Supplies a pointer where the register values will be written in
  318. for the debugger. For x86, this is a pointer to an
  319. X86_GENERAL_REGISTERS structure.
  320. Return Value:
  321. None.
  322. --*/
  323. ULONG
  324. KdpGetErrorCode (
  325. ULONG Exception,
  326. PTRAP_FRAME TrapFrame
  327. );
  328. /*++
  329. Routine Description:
  330. This routine gets the error code out of the trap frame.
  331. Arguments:
  332. Exception - Supplies the exception that generated the error code.
  333. TrapFrame - Supplies a pointer to the current processor state.
  334. Return Value:
  335. Returns the error code, or 0 if there was no error code.
  336. --*/
  337. VOID
  338. KdpSetRegisters (
  339. PTRAP_FRAME TrapFrame,
  340. PVOID Registers
  341. );
  342. /*++
  343. Routine Description:
  344. This routine writes the register values from the debugger to the trap
  345. frame.
  346. Arguments:
  347. TrapFrame - Supplies a pointer to the current processor state.
  348. Registers - Supplies a pointer to the new register values to use.
  349. Return Value:
  350. None.
  351. --*/
  352. BOOL
  353. KdpIsFunctionReturning (
  354. PTRAP_FRAME TrapFrame
  355. );
  356. /*++
  357. Routine Description:
  358. This routine will determine if the current instruction (the instruction
  359. about to get executed) is going to return from the current function.
  360. Arguments:
  361. TrapFrame - Supplies a pointer to the current machine state.
  362. Return Value:
  363. Returns TRUE if the function is about to return, or FALSE if this is not
  364. a return instruction.
  365. --*/
  366. VOID
  367. KdpGetSpecialRegisters (
  368. PSPECIAL_REGISTERS_UNION SpecialRegisters
  369. );
  370. /*++
  371. Routine Description:
  372. This routine retrieves the special registers from the current processor.
  373. Arguments:
  374. SpecialRegisters - Supplies a pointer where the contents of the special
  375. registers will be returned.
  376. Return Value:
  377. None.
  378. --*/
  379. VOID
  380. KdpSetSpecialRegisters (
  381. PSPECIAL_REGISTERS_UNION OriginalRegisters,
  382. PSPECIAL_REGISTERS_UNION NewRegisters
  383. );
  384. /*++
  385. Routine Description:
  386. This routine sets the special registers from the current processor.
  387. Arguments:
  388. OriginalRegisters - Supplies a pointer to the current special register
  389. context.
  390. NewRegisters - Supplies a pointer to the values to write. Only values
  391. different from the original registers will actually be written.
  392. Return Value:
  393. None.
  394. --*/
  395. ULONG
  396. KdpAtomicCompareExchange32 (
  397. volatile ULONG *Address,
  398. ULONG ExchangeValue,
  399. ULONG CompareValue
  400. );
  401. /*++
  402. Routine Description:
  403. This routine atomically compares memory at the given address with a value
  404. and exchanges it with another value if they are equal.
  405. Arguments:
  406. Address - Supplies the address of the value to compare and potentially
  407. exchange.
  408. ExchangeValue - Supplies the value to write to Address if the comparison
  409. returns equality.
  410. CompareValue - Supplies the value to compare against.
  411. Return Value:
  412. Returns the original value at the given address.
  413. --*/
  414. ULONG
  415. KdpAtomicAdd32 (
  416. volatile ULONG *Address,
  417. ULONG Increment
  418. );
  419. /*++
  420. Routine Description:
  421. This routine atomically adds the given amount to a 32-bit variable.
  422. Arguments:
  423. Address - Supplies the address of the value to atomically add to.
  424. Increment - Supplies the amount to add.
  425. Return Value:
  426. Returns the value before the atomic addition was performed.
  427. --*/
  428. VOID
  429. KdpDisableInterrupts (
  430. VOID
  431. );
  432. /*++
  433. Routine Description:
  434. This routine disables all interrupts on the current processor.
  435. Arguments:
  436. None.
  437. Return Value:
  438. None.
  439. --*/