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.

420 lines
18 KiB

  1. // shadow IVT
  2. // logs and then branches to the original vector code at KiIvtBase
  3. //
  4. #include "ksia64.h"
  5. // For Conditional Interrupt Logging
  6. #define KiVhptTransVectorBit 0
  7. #define KiInstTlbVectorBit 1
  8. #define KiDataTlbVectorBit 2
  9. #define KiAltInstTlbVectorBit 3
  10. #define KiAltDataTlbVectorBit 4
  11. #define KiNestedTlbVectorBit 5
  12. #define KiInstKeyMissVectorBit 6
  13. #define KiDataKeyMissVectorBit 7
  14. #define KiDirtyBitVectorBit 8
  15. #define KiInstAccessBitVectorBit 9
  16. #define KiDataAccessBitVectorBit 10
  17. #define KiBreakVectorBit 11
  18. #define KiExternalInterruptVectorBit 12
  19. #define KiPageNotPresentVectorBit 13
  20. #define KiKeyPermVectorBit 14
  21. #define KiInstAccessRightsVectorBit 15
  22. #define KiDataAccessRightsVectorBit 16
  23. #define KiGeneralExceptionsVectorBit 17
  24. #define KiDisabledFpRegisterVectorBit 18
  25. #define KiNatConsumptionVectorBit 19
  26. #define KiSpeculationVectorBit 20
  27. #define KiDebugFaultVectorBit 21
  28. #define KiUnalignedFaultVectorBit 22
  29. #define KiFloatFaultVectorBit 23
  30. #define KiFloatTrapVectorBit 24
  31. #define KiLowerPrivilegeVectorBit 25
  32. #define KiTakenBranchVectorBit 26
  33. #define KiSingleStepVectorBit 27
  34. #define KiIA32ExceptionVectorBit 28
  35. #define KiIA32InterceptionVectorBit 29
  36. #define KiIA32InterruptionVectorBit 30
  37. // #define UserSystemcallBit 61
  38. // #define ExternalInterruptBit 62
  39. // #define ContextSwitchBit 63
  40. // reserve bit 13 in ConfigFlag to indicate which IVT to use
  41. #define DISABLE_TRACE_LOG 13
  42. .file "ivtilog.s"
  43. .explicit
  44. .global KiVectorLogMask
  45. #define VECTOR_ENTRY(Offset, Name, Extra0) \
  46. .##global Name; \
  47. .##type Name,@function; \
  48. .##org Offset; \
  49. .##global Name##ILog; \
  50. .##proc Name##ILog; \
  51. \
  52. Name##ILog:: ;\
  53. mov h30 = pr ;\
  54. mov h27 = gp ;\
  55. ;; ;\
  56. movl gp = _gp ;\
  57. ;; ;\
  58. add h28 = @gprel(KiVectorLogMask), gp ;\
  59. ;; ;\
  60. ld8 h29 = [h28] ;\
  61. ;; ;\
  62. mov gp = h27 ;\
  63. ;; ;\
  64. tbit.z pt1 = h29, Name##Bit ;\
  65. (pt1) br.cond.sptk Name##ILogEnd ;\
  66. ;; ;\
  67. \
  68. mov h28 = cr.iip ;\
  69. movl h25 = KiPcr+PcInterruptionCount ;\
  70. ;; ;\
  71. mov h29 = cr.ipsr ;\
  72. ld4.nt1 h26 = [h25] ;\
  73. mov h24 = MAX_NUMBER_OF_IHISTORY_RECORDS - 1 ;\
  74. ;; ;\
  75. add h27 = 1, h26 ;\
  76. and h26 = h24, h26 ;\
  77. add h24 = 0x1000-PcInterruptionCount, h25 ;\
  78. ;; ;\
  79. st4.nta [h25] = h27 ;\
  80. shl h26 = h26, 5 ;\
  81. ;; ;\
  82. add h27 = h26, h24 ;\
  83. mov h31 = (Offset >> 8) ;\
  84. ;; ;\
  85. st8 [h27] = h31, 8 ;\
  86. ;; ;\
  87. st8 [h27] = h28, 8 ;\
  88. mov h31 = Extra0 ;\
  89. ;; ;\
  90. st8 [h27] = h29, 8 ;\
  91. ;; ;\
  92. st8 [h27] = h31; ;\
  93. \
  94. Name##ILogEnd:: ;\
  95. \
  96. mov pr = h30, -1 ;\
  97. br.sptk Name
  98. #define VECTOR_EXIT(Name) \
  99. .##endp Name##ILog
  100. #define VECTOR_ENTRY_HB_DUMP(Offset, Name, Extra0) \
  101. .##global Name; \
  102. .##type Name,@function; \
  103. .##org Offset; \
  104. .##global Name##ILog; \
  105. .##proc Name##ILog; \
  106. \
  107. Name##ILog:: \
  108. /* h30 = pr */ ;\
  109. /* b0 = Name##ILogStart */ ;\
  110. /* h29 = cpuid3 */ ;\
  111. /* h28 = b0 */ ;\
  112. { .mmi ;\
  113. mov ar.k1 = h24 ;\
  114. mov ar.k2 = h25 ;\
  115. nop.i 0 ;\
  116. } ;\
  117. { .mmi ;\
  118. mov ar.k4 = h27 ;\
  119. mov ar.k5 = h28 ;\
  120. nop.i 0 ;\
  121. } ;\
  122. { .mii ;\
  123. mov h29 = 3 ;\
  124. mov h30 = pr ;\
  125. mov h28 = b0;; ;\
  126. } ;\
  127. { .mli ;\
  128. mov h29 = cpuid[h29] ;\
  129. movl h31 = Name##ILogStart;; ;\
  130. } ;\
  131. { .mii ;\
  132. mov h26 = 675 ;\
  133. mov b0 = h31 /* set return address */ ;\
  134. extr.u h24 = h29, 24, 8 ;; ;\
  135. } ;\
  136. { .mib ;\
  137. nop.m 0 ;\
  138. cmp.ne pt0 = 7, h24 ;\
  139. (pt0) br.cond.spnt Name##ILogStart ;\
  140. } ;\
  141. { .mmi ;\
  142. mov h27 = msr[h26] ;; ;\
  143. nop.m 0 ;\
  144. tbit.nz pt2 = r27, 8 /* skip if HB is disabled */ ;\
  145. } ;\
  146. { .mib ;\
  147. nop.m 0 ;\
  148. dep h27 = 1, r27, 8, 1 /* disable HB */ ;\
  149. (pt2) br.cond.spnt Name##ILogStart ;; ;\
  150. } ;\
  151. { .mib ;\
  152. mov msr[h26] = h27 ;\
  153. nop.i 0 ;\
  154. br.sptk KiDumpHistoryBuffer ;\
  155. } ;\
  156. ;\
  157. Name##ILogStart:: ;\
  158. { .mli ;\
  159. mov h27 = gp ;\
  160. movl h31 = Name##ILogEnd ;; ;\
  161. } ;\
  162. { .mli ;\
  163. nop.m 0 ;\
  164. movl gp = _gp ;; ;\
  165. } ;\
  166. { .mmi ;\
  167. add h25 = @gprel(KiVectorLogMask), gp ;; ;\
  168. ld8 h25 = [h25] ;\
  169. mov b0 = r31 ;\
  170. } ;\
  171. { .mmi ;\
  172. mov h29 = (Offset >> 8) ;\
  173. mov h31 = Extra0 ;\
  174. mov gp = h27 ;; ;\
  175. } ;\
  176. { .mib ;\
  177. nop.m 0 ;\
  178. tbit.nz pt1 = h25, Name##Bit ;\
  179. (pt1) br.sptk KiLogInterruptEvent ;; ;\
  180. } ;\
  181. Name##ILogEnd:: ;\
  182. { .mii ;\
  183. nop.m 0 ;\
  184. mov b0 = h28 ;\
  185. mov pr = h30, -1 ;\
  186. } ;\
  187. { .mib ;\
  188. nop.m 0 ;\
  189. nop.i 0 ;\
  190. br.sptk Name ;; ;\
  191. }
  192. .section .drectve, "MI", "progbits"
  193. string "-section:.ivtilog,,align=0x8000"
  194. .section .ivtilog = "ax", "progbits"
  195. KiIvtBaseILog:: // symbol for start of shadow IVT
  196. VECTOR_ENTRY(0x0000, KiVhptTransVector, cr.ifa)
  197. VECTOR_EXIT(KiVhptTransVector)
  198. VECTOR_ENTRY(0x0400, KiInstTlbVector, cr.iipa)
  199. VECTOR_EXIT(KiInstTlbVector)
  200. VECTOR_ENTRY(0x0800, KiDataTlbVector, cr.ifa)
  201. VECTOR_EXIT(KiDataTlbVector)
  202. VECTOR_ENTRY(0x0c00, KiAltInstTlbVector, cr.iipa)
  203. VECTOR_EXIT(KiAltInstTlbVector)
  204. VECTOR_ENTRY(0x1000, KiAltDataTlbVector, cr.ifa)
  205. VECTOR_EXIT(KiAltDataTlbVector)
  206. VECTOR_ENTRY(0x1400, KiNestedTlbVector, cr.ifa)
  207. VECTOR_EXIT(KiNestedTlbVector)
  208. VECTOR_ENTRY(0x1800, KiInstKeyMissVector, cr.iipa)
  209. VECTOR_EXIT(KiInstKeyMissVector)
  210. VECTOR_ENTRY(0x1c00, KiDataKeyMissVector, cr.ifa)
  211. VECTOR_EXIT(KiDataKeyMissVector)
  212. VECTOR_ENTRY(0x2000, KiDirtyBitVector, cr.ifa)
  213. VECTOR_EXIT(KiDirtyBitVector)
  214. VECTOR_ENTRY(0x2400, KiInstAccessBitVector, cr.iipa)
  215. VECTOR_EXIT(KiInstAccessBitVector)
  216. VECTOR_ENTRY(0x2800, KiDataAccessBitVector, cr.ifa)
  217. VECTOR_EXIT(KiDataAccessBitVector)
  218. VECTOR_ENTRY(0x2C00, KiBreakVector, cr.iim)
  219. VECTOR_EXIT(KiBreakVector)
  220. VECTOR_ENTRY(0x3000, KiExternalInterruptVector, r0)
  221. VECTOR_EXIT(KiExternalInterruptVector)
  222. VECTOR_ENTRY(0x5000, KiPageNotPresentVector, cr.ifa)
  223. VECTOR_EXIT(KiPageNotPresentVector)
  224. VECTOR_ENTRY(0x5100, KiKeyPermVector, cr.ifa)
  225. VECTOR_EXIT(KiKeyPermVector)
  226. VECTOR_ENTRY(0x5200, KiInstAccessRightsVector, cr.iipa)
  227. VECTOR_EXIT(KiInstAccessRightsVector)
  228. VECTOR_ENTRY(0x5300, KiDataAccessRightsVector, cr.ifa)
  229. VECTOR_EXIT(KiDataAccessRightsVector)
  230. VECTOR_ENTRY_HB_DUMP(0x5400, KiGeneralExceptionsVector, cr.isr)
  231. // VECTOR_ENTRY(0x5400, KiGeneralExceptionsVector, cr.isr)
  232. VECTOR_EXIT(KiGeneralExceptionsVector)
  233. VECTOR_ENTRY(0x5500, KiDisabledFpRegisterVector, cr.isr)
  234. VECTOR_EXIT(KiDisabledFpRegisterVector)
  235. VECTOR_ENTRY(0x5600, KiNatConsumptionVector, cr.isr)
  236. VECTOR_EXIT(KiNatConsumptionVector)
  237. VECTOR_ENTRY(0x5700, KiSpeculationVector, cr.iim)
  238. VECTOR_EXIT(KiSpeculationVector)
  239. VECTOR_ENTRY(0x5900, KiDebugFaultVector, cr.isr)
  240. VECTOR_EXIT(KiDebugFaultVector)
  241. VECTOR_ENTRY(0x5a00, KiUnalignedFaultVector, cr.ifa)
  242. VECTOR_EXIT(KiUnalignedFaultVector)
  243. VECTOR_ENTRY(0x5c00, KiFloatFaultVector, cr.isr)
  244. VECTOR_EXIT(KiFloatFaultVector)
  245. VECTOR_ENTRY(0x5d00, KiFloatTrapVector, cr.isr)
  246. VECTOR_EXIT(KiFloatTrapVector)
  247. VECTOR_ENTRY(0x5e00, KiLowerPrivilegeVector, cr.iipa)
  248. VECTOR_EXIT(KiLowerPrivilegeVector)
  249. VECTOR_ENTRY(0x5f00, KiTakenBranchVector, cr.iipa)
  250. VECTOR_EXIT(KiTakenBranchVector)
  251. VECTOR_ENTRY(0x6000, KiSingleStepVector, cr.iipa)
  252. VECTOR_EXIT(KiSingleStepVector)
  253. VECTOR_ENTRY(0x6900, KiIA32ExceptionVector, r0)
  254. VECTOR_EXIT(KiIA32ExceptionVector)
  255. VECTOR_ENTRY(0x6a00, KiIA32InterceptionVector, r0)
  256. VECTOR_EXIT(KiIA32InterceptionVector)
  257. VECTOR_ENTRY(0x6b00, KiIA32InterruptionVector, r0)
  258. VECTOR_EXIT(KiIA32InterruptionVector)
  259. .org 0x7ff0
  260. { .mii
  261. break.m 0
  262. break.i 0
  263. break.i 0}
  264. .text
  265. .global KiIvtBaseILog
  266. LEAF_ENTRY (KiSwitchToLogVector)
  267. movl t0 = KiIvtBaseILog
  268. ;;
  269. mov cr.iva = t0 // switch IVT to no log IVT
  270. ;;
  271. srlz.i
  272. LEAF_RETURN
  273. LEAF_EXIT (KiSwitchToLogVector)
  274. LEAF_ENTRY (KiDumpHistoryBuffer)
  275. mov h25 = 681
  276. movl h31 = KiPcr+ProcessorControlRegisterLength + 8
  277. mov h24 = 680
  278. movl h29 = KiPcr+ProcessorControlRegisterLength ;
  279. ;;
  280. .reg.val h24, 680
  281. mov h26 = msr[h24]
  282. .reg.val h25, 681
  283. mov h27 = msr[h25]
  284. add h24 = 2, h24
  285. ;;
  286. st8 [h29] = h26, 16
  287. st8 [h31] = h27, 16
  288. add h25 = 2, h25
  289. ;;
  290. .reg.val h24, 682
  291. mov h26 = msr[h24]
  292. .reg.val h25, 683
  293. mov h27 = msr[h25]
  294. add h24 = 2, h24
  295. ;;
  296. st8 [h29] = h26, 16
  297. st8 [h31] = h27, 16
  298. add h25 = 2, h25
  299. ;;
  300. .reg.val h24, 684
  301. mov h26 = msr[h24]
  302. .reg.val h24, 685
  303. mov h27 = msr[h25]
  304. add h24 = 2, h24
  305. ;;
  306. st8 [h29] = h26, 16
  307. st8 [h31] = h27, 16
  308. add h25 = 2, h25
  309. ;;
  310. .reg.val h24, 686
  311. mov h26 = msr[h24]
  312. .reg.val h25, 687
  313. mov h27 = msr[h25]
  314. mov h24 = 674
  315. ;;
  316. st8 [h29] = h26
  317. st8 [h31] = h27, 8
  318. ;;
  319. mov h25 = msr[h24]
  320. mov h26 = 675
  321. ;;
  322. st8 [h31] = h25
  323. mov h27 = msr[h26]
  324. ;;
  325. dep h27 = 0, r27, 8, 1 // enable HB
  326. ;;
  327. mov msr[h26] = h27
  328. br.sptk b0
  329. LEAF_EXIT (KiDumpHistoryBuffer)
  330. //
  331. // save it to the IH buffer
  332. //
  333. LEAF_ENTRY (KiLogInterruptEvent)
  334. // h29 Offset
  335. // h31 Extra
  336. // h28,h30 should not be used
  337. movl h25 = KiPcr+PcInterruptionCount
  338. ;;
  339. ld4.nt1 h26 = [h25]
  340. mov h24 = MAX_NUMBER_OF_IHISTORY_RECORDS - 1
  341. ;;
  342. add h27 = 1, h26
  343. and h26 = h24, h26
  344. add h24 = 0x1000-PcInterruptionCount, h25
  345. ;;
  346. st4.nta [h25] = h27
  347. shl h26 = h26, 5
  348. ;;
  349. add h27 = h26, h24
  350. mov h24 = cr.iip
  351. ;;
  352. mov h25 = cr.ipsr
  353. st8 [h27] = h29, 8 // Log Offset with h29
  354. ;;
  355. st8 [h27] = h24, 8 // Log IIP
  356. ;;
  357. st8 [h27] = h25, 8 // Log IPSR
  358. ;;
  359. st8 [h27] = h31 // Log Extra with h31
  360. br.sptk b0
  361. LEAF_EXIT (KiLogInterruptEvent)