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.

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