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.

465 lines
8.8 KiB

  1. title "ix ioaccess"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; ixioacc.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; Procedures to correctly touch I/O registers.
  13. ;
  14. ; Author:
  15. ;
  16. ; Bryan Willman (bryanwi) 16 May 1990
  17. ;
  18. ; Environment:
  19. ;
  20. ; User or Kernel, although privledge (IOPL) may be required.
  21. ;
  22. ; Revision History:
  23. ;
  24. ;--
  25. .386p
  26. .xlist
  27. include hal386.inc
  28. include callconv.inc ; calling convention macros
  29. .list
  30. _TEXT$00 SEGMENT DWORD PUBLIC 'CODE'
  31. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  32. ;++
  33. ;
  34. ; I/O port space read and write functions.
  35. ;
  36. ; These have to be actual functions on the 386, because we need
  37. ; to use assembler, but cannot return a value if we inline it.
  38. ;
  39. ; This set of functions manipulates I/O registers in PORT space.
  40. ; (Uses x86 in and out instructions)
  41. ;
  42. ; WARNING: Port addresses must always be in the range 0 to 64K, because
  43. ; that's the range the hardware understands.
  44. ;
  45. ;--
  46. ;++
  47. ;
  48. ; UCHAR
  49. ; READ_PORT_UCHAR(
  50. ; PUCHAR Port
  51. ; )
  52. ;
  53. ; Arguments:
  54. ; (esp+4) = Port
  55. ;
  56. ; Returns:
  57. ; Value in Port.
  58. ;
  59. ;--
  60. cPublicProc _READ_PORT_UCHAR ,1
  61. cPublicFpo 1, 0
  62. xor eax, eax ; Eliminate partial stall on return to caller
  63. mov edx,[esp+4] ; (dx) = Port
  64. in al,dx
  65. stdRET _READ_PORT_UCHAR
  66. stdENDP _READ_PORT_UCHAR
  67. ;++
  68. ;
  69. ; USHORT
  70. ; READ_PORT_USHORT(
  71. ; PUSHORT Port
  72. ; )
  73. ;
  74. ; Arguments:
  75. ; (esp+4) = Port
  76. ;
  77. ; Returns:
  78. ; Value in Port.
  79. ;
  80. ;--
  81. cPublicProc _READ_PORT_USHORT ,1
  82. cPublicFpo 1, 0
  83. xor eax, eax ; Eliminate partial stall on return to caller
  84. mov edx,[esp+4] ; (dx) = Port
  85. in ax,dx
  86. stdRET _READ_PORT_USHORT
  87. stdENDP _READ_PORT_USHORT
  88. ;++
  89. ;
  90. ; ULONG
  91. ; READ_PORT_ULONG(
  92. ; PULONG Port
  93. ; )
  94. ;
  95. ; Arguments:
  96. ; (esp+4) = Port
  97. ;
  98. ; Returns:
  99. ; Value in Port.
  100. ;
  101. ;--
  102. cPublicProc _READ_PORT_ULONG ,1
  103. cPublicFpo 1, 0
  104. mov edx,[esp+4] ; (dx) = Port
  105. in eax,dx
  106. stdRET _READ_PORT_ULONG
  107. stdENDP _READ_PORT_ULONG
  108. ;++
  109. ;
  110. ; VOID
  111. ; READ_PORT_BUFFER_UCHAR(
  112. ; PUCHAR Port,
  113. ; PUCHAR Buffer,
  114. ; ULONG Count
  115. ; )
  116. ;
  117. ; Arguments:
  118. ; (esp+4) = Port
  119. ; (esp+8) = Buffer address
  120. ; (esp+12) = Count
  121. ;
  122. ;--
  123. cPublicProc _READ_PORT_BUFFER_UCHAR ,3
  124. cPublicFpo 3, 0
  125. mov eax, edi ; Save edi
  126. mov edx,[esp+4] ; (dx) = Port
  127. mov edi,[esp+8] ; (edi) = buffer
  128. mov ecx,[esp+12] ; (ecx) = transfer count
  129. rep insb
  130. mov edi, eax
  131. stdRET _READ_PORT_BUFFER_UCHAR
  132. stdENDP _READ_PORT_BUFFER_UCHAR
  133. ;++
  134. ;
  135. ; VOID
  136. ; READ_PORT_BUFFER_USHORT(
  137. ; PUSHORT Port,
  138. ; PUSHORT Buffer,
  139. ; ULONG Count
  140. ; )
  141. ;
  142. ; Arguments:
  143. ; (esp+4) = Port
  144. ; (esp+8) = Buffer address
  145. ; (esp+12) = Count
  146. ;
  147. ;--
  148. cPublicProc _READ_PORT_BUFFER_USHORT ,3
  149. cPublicFpo 3, 0
  150. mov eax, edi ; Save edi
  151. mov edx,[esp+4] ; (dx) = Port
  152. mov edi,[esp+8] ; (edi) = buffer
  153. mov ecx,[esp+12] ; (ecx) = transfer count
  154. rep insw
  155. mov edi, eax
  156. stdRET _READ_PORT_BUFFER_USHORT
  157. stdENDP _READ_PORT_BUFFER_USHORT
  158. ;++
  159. ;
  160. ; VOID
  161. ; READ_PORT_BUFFER_ULONG(
  162. ; PULONG Port,
  163. ; PULONG Buffer,
  164. ; ULONG Count
  165. ; )
  166. ;
  167. ; Arguments:
  168. ; (esp+4) = Port
  169. ; (esp+8) = Buffer address
  170. ; (esp+12) = Count
  171. ;
  172. ;--
  173. cPublicProc _READ_PORT_BUFFER_ULONG ,3
  174. cPublicFpo 3, 0
  175. mov eax, edi ; Save edi
  176. mov edx,[esp+4] ; (dx) = Port
  177. mov edi,[esp+8] ; (edi) = buffer
  178. mov ecx,[esp+12] ; (ecx) = transfer count
  179. rep insd
  180. mov edi, eax
  181. stdRET _READ_PORT_BUFFER_ULONG
  182. stdENDP _READ_PORT_BUFFER_ULONG
  183. ;++
  184. ;
  185. ; VOID
  186. ; WRITE_PORT_UCHAR(
  187. ; PUCHAR Port,
  188. ; UCHAR Value
  189. ; )
  190. ;
  191. ; Arguments:
  192. ; (esp+4) = Port
  193. ; (esp+8) = Value
  194. ;
  195. ;--
  196. cPublicProc _WRITE_PORT_UCHAR ,2
  197. cPublicFpo 2, 0
  198. mov edx,[esp+4] ; (dx) = Port
  199. mov al,[esp+8] ; (al) = Value
  200. out dx,al
  201. stdRET _WRITE_PORT_UCHAR
  202. stdENDP _WRITE_PORT_UCHAR
  203. ;++
  204. ;
  205. ; VOID
  206. ; WRITE_PORT_USHORT(
  207. ; PUSHORT Port,
  208. ; USHORT Value
  209. ; )
  210. ;
  211. ; Arguments:
  212. ; (esp+4) = Port
  213. ; (esp+8) = Value
  214. ;
  215. ;--
  216. cPublicProc _WRITE_PORT_USHORT ,2
  217. cPublicFpo 2, 0
  218. mov edx,[esp+4] ; (dx) = Port
  219. mov eax,[esp+8] ; (ax) = Value
  220. out dx,ax
  221. stdRET _WRITE_PORT_USHORT
  222. stdENDP _WRITE_PORT_USHORT
  223. ;++
  224. ;
  225. ; VOID
  226. ; WRITE_PORT_ULONG(
  227. ; PULONG Port,
  228. ; ULONG Value
  229. ; )
  230. ;
  231. ; Arguments:
  232. ; (esp+4) = Port
  233. ; (esp+8) = Value
  234. ;
  235. ;--
  236. cPublicProc _WRITE_PORT_ULONG ,2
  237. cPublicFpo 2, 0
  238. mov edx,[esp+4] ; (dx) = Port
  239. mov eax,[esp+8] ; (eax) = Value
  240. out dx,eax
  241. stdRET _WRITE_PORT_ULONG
  242. stdENDP _WRITE_PORT_ULONG
  243. ;++
  244. ;
  245. ; VOID
  246. ; HalpIoDelay (
  247. ; VOID
  248. ; )
  249. ;
  250. ; Arguments:
  251. ; None
  252. ;
  253. ; Notes: Used to program the DMA controller. There exist some legacy parts that require
  254. ; a delay after write. The chip recognizes the jmp $+2 sequence and flushes internal
  255. ; buffers.
  256. ;
  257. ;--
  258. cPublicFastCall HalpIoDelay,0
  259. jmp $+2
  260. jmp $+2 ;Stall for IO out
  261. fstRET HalpIoDelay
  262. fstENDP HalpIoDelay
  263. ;++
  264. ;
  265. ; VOID
  266. ; WRITE_PORT_BUFFER_UCHAR(
  267. ; PUCHAR Port,
  268. ; PUCHAR Buffer,
  269. ; ULONG Count
  270. ; )
  271. ;
  272. ; Arguments:
  273. ; (esp+4) = Port
  274. ; (esp+8) = Buffer address
  275. ; (esp+12) = Count
  276. ;
  277. ;--
  278. cPublicProc _WRITE_PORT_BUFFER_UCHAR ,3
  279. cPublicFpo 3, 0
  280. mov eax,esi ; Save esi
  281. mov edx,[esp+4] ; (dx) = Port
  282. mov esi,[esp+8] ; (esi) = buffer
  283. mov ecx,[esp+12] ; (ecx) = transfer count
  284. rep outsb
  285. mov esi,eax
  286. stdRET _WRITE_PORT_BUFFER_UCHAR
  287. stdENDP _WRITE_PORT_BUFFER_UCHAR
  288. ;++
  289. ;
  290. ; VOID
  291. ; WRITE_PORT_BUFFER_USHORT(
  292. ; PUSHORT Port,
  293. ; PUSHORT Buffer,
  294. ; ULONG Count
  295. ; )
  296. ;
  297. ; Arguments:
  298. ; (esp+4) = Port
  299. ; (esp+8) = Buffer address
  300. ; (esp+12) = Count
  301. ;
  302. ;--
  303. cPublicProc _WRITE_PORT_BUFFER_USHORT ,3
  304. cPublicFpo 3, 0
  305. mov eax,esi ; Save esi
  306. mov edx,[esp+4] ; (dx) = Port
  307. mov esi,[esp+8] ; (esi) = buffer
  308. mov ecx,[esp+12] ; (ecx) = transfer count
  309. rep outsw
  310. mov esi,eax
  311. stdRET _WRITE_PORT_BUFFER_USHORT
  312. stdENDP _WRITE_PORT_BUFFER_USHORT
  313. ;++
  314. ;
  315. ; VOID
  316. ; WRITE_PORT_BUFFER_ULONG(
  317. ; PULONG Port,
  318. ; PULONG Buffer,
  319. ; ULONG Count
  320. ; )
  321. ;
  322. ; Arguments:
  323. ; (esp+4) = Port
  324. ; (esp+8) = Buffer address
  325. ; (esp+12) = Count
  326. ;
  327. ;--
  328. cPublicProc _WRITE_PORT_BUFFER_ULONG ,3
  329. cPublicFpo 3, 0
  330. mov eax,esi ; Save esi
  331. mov edx,[esp+4] ; (dx) = Port
  332. mov esi,[esp+8] ; (esi) = buffer
  333. mov ecx,[esp+12] ; (ecx) = transfer count
  334. rep outsd
  335. mov esi,eax
  336. stdRET _WRITE_PORT_BUFFER_ULONG
  337. stdENDP _WRITE_PORT_BUFFER_ULONG
  338. .586p
  339. ;++
  340. ;ULONGLONG
  341. ;FASTCALL
  342. ;RDMSR(
  343. ; IN ULONG MsrAddress
  344. ; )
  345. ; Routine Description:
  346. ; This function reads an MSR
  347. ;
  348. ; Arguments:
  349. ; Msr: The address of MSR to be read
  350. ;
  351. ; Return Value:
  352. ; Returns the low 32 bit of MSR in eax and high 32 bits of MSR in edx
  353. ;
  354. ;--
  355. cPublicFastCall RDMSR,1
  356. rdmsr
  357. fstRET RDMSR
  358. fstENDP RDMSR
  359. ;++
  360. ;
  361. ;VOID
  362. ;WRMSR(
  363. ; IN ULONG MsrAddress,
  364. ; IN ULONGLONG MsrValue
  365. ; )
  366. ; Routine Description:
  367. ; This function writes an MSR
  368. ;
  369. ; Arguments:
  370. ; Msr: The address of MSR to be written
  371. ; Data: The value to be written to the MSR register
  372. ;
  373. ; Return Value:
  374. ; None
  375. ;
  376. ;--
  377. cPublicProc _WRMSR,3
  378. mov ecx, [esp + 4] ; MsrAddress
  379. mov eax, [esp + 8] ; Low 32 bits of MsrValue
  380. mov edx, [esp + 12] ; High 32 bits of MsrValue
  381. wrmsr
  382. stdRET _WRMSR
  383. stdENDP _WRMSR
  384. _TEXT$00 ends
  385. end