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.

423 lines
8.9 KiB

  1. title "ioaccess"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; ioaccess.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 ks386.inc
  28. include callconv.inc ; calling convention macros
  29. .list
  30. _TEXT SEGMENT DWORD PUBLIC 'CODE'
  31. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  32. ;++
  33. ;
  34. ; I/O memory 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 MEMORY space.
  40. ; (Uses x86 mov instructions)
  41. ;
  42. ;--
  43. ;++
  44. ;
  45. ; UCHAR
  46. ; READ_REGISTER_UCHAR(
  47. ; PUCHAR Register
  48. ; )
  49. ;
  50. ; Memory space references will use lock prefix to force real access,
  51. ; flush through posted write buffers, and so forth.
  52. ;
  53. ; Arguments:
  54. ; (esp+4) = Register
  55. ;
  56. ; Returns:
  57. ; Value in register.
  58. ;
  59. ;--
  60. cPublicProc _READ_REGISTER_UCHAR ,1
  61. cPublicFpo 1,0
  62. mov edx,[esp+4] ; (edx) = Register
  63. mov al,[edx] ; (al) = byte, lock forces real access
  64. stdRET _READ_REGISTER_UCHAR
  65. stdENDP _READ_REGISTER_UCHAR
  66. ;++
  67. ;
  68. ; USHORT
  69. ; READ_REGISTER_USHORT(
  70. ; PUSHORT Register
  71. ; )
  72. ;
  73. ; Memory space references will use lock prefix to force real access,
  74. ; flush through posted write buffers, and so forth.
  75. ;
  76. ; Arguments:
  77. ; (esp+4) = Register
  78. ;
  79. ; Returns:
  80. ; Value in register.
  81. ;
  82. ;--
  83. cPublicProc _READ_REGISTER_USHORT ,1
  84. cPublicFpo 1,0
  85. mov edx,[esp+4] ; (edx) = Register
  86. mov ax,[edx] ; (ax) = word, lock forces real access
  87. stdRET _READ_REGISTER_USHORT
  88. stdENDP _READ_REGISTER_USHORT
  89. ;++
  90. ;
  91. ; ULONG
  92. ; READ_REGISTER_ULONG(
  93. ; PULONG Register
  94. ; )
  95. ;
  96. ; Memory space references will use lock prefix to force real access,
  97. ; flush through posted write buffers, and so forth.
  98. ;
  99. ; Arguments:
  100. ; (esp+4) = Register
  101. ;
  102. ; Returns:
  103. ; Value in register.
  104. ;
  105. ;--
  106. cPublicProc _READ_REGISTER_ULONG ,1
  107. cPublicFpo 1,0
  108. mov edx,[esp+4] ; (edx) = Register
  109. mov eax,[edx] ; (eax) = dword, lock forces real access
  110. stdRET _READ_REGISTER_ULONG
  111. stdENDP _READ_REGISTER_ULONG
  112. ;++
  113. ;
  114. ; VOID
  115. ; READ_REGISTER_BUFFER_UCHAR(
  116. ; PUCHAR Register,
  117. ; PUCHAR Buffer,
  118. ; ULONG Count
  119. ; )
  120. ;
  121. ; Arguments:
  122. ; (esp+4) = Register
  123. ; (esp+8) = Buffer address
  124. ; (esp+12) = Count
  125. ;
  126. ;--
  127. cPublicProc _READ_REGISTER_BUFFER_UCHAR ,3
  128. cPublicFpo 3,0
  129. mov eax, esi
  130. mov edx, edi ; Save esi, edi
  131. mov ecx,[esp+12] ; (ecx) = transfer count
  132. mov esi,[esp+4] ; (edx) = Register
  133. mov edi,[esp+8] ; (edi) = buffer
  134. rep movsb
  135. mov edi, edx
  136. mov esi, eax
  137. stdRET _READ_REGISTER_BUFFER_UCHAR
  138. stdENDP _READ_REGISTER_BUFFER_UCHAR
  139. ;++
  140. ;
  141. ; VOID
  142. ; READ_REGISTER_BUFFER_USHORT(
  143. ; PUSHORT Register,
  144. ; PUSHORT Buffer,
  145. ; ULONG Count
  146. ; )
  147. ;
  148. ; Arguments:
  149. ; (esp+4) = Register
  150. ; (esp+8) = Buffer address
  151. ; (esp+12) = Count
  152. ;
  153. ;--
  154. cPublicProc _READ_REGISTER_BUFFER_USHORT ,3
  155. cPublicFpo 3,0
  156. mov eax, esi
  157. mov edx, edi ; Save esi, edi
  158. mov ecx,[esp+12] ; (ecx) = transfer count
  159. mov esi,[esp+4] ; (edx) = Register
  160. mov edi,[esp+8] ; (edi) = buffer
  161. rep movsw
  162. mov edi, edx
  163. mov esi, eax
  164. stdRET _READ_REGISTER_BUFFER_USHORT
  165. stdENDP _READ_REGISTER_BUFFER_USHORT
  166. ;++
  167. ;
  168. ; VOID
  169. ; READ_REGISTER_BUFFER_ULONG(
  170. ; PULONG Register,
  171. ; PULONG Buffer,
  172. ; ULONG Count
  173. ; )
  174. ;
  175. ; Arguments:
  176. ; (esp+4) = Register
  177. ; (esp+8) = Buffer address
  178. ; (esp+12) = Count
  179. ;
  180. ;--
  181. cPublicProc _READ_REGISTER_BUFFER_ULONG ,3
  182. cPublicFpo 3,0
  183. mov eax, esi
  184. mov edx, edi ; Save esi, edi
  185. mov ecx,[esp+12] ; (ecx) = transfer count
  186. mov esi,[esp+4] ; (edx) = Register
  187. mov edi,[esp+8] ; (edi) = buffer
  188. rep movsd
  189. mov edi, edx
  190. mov esi, eax
  191. stdRET _READ_REGISTER_BUFFER_ULONG
  192. stdENDP _READ_REGISTER_BUFFER_ULONG
  193. ;++
  194. ;
  195. ; VOID
  196. ; WRITE_REGISTER_UCHAR(
  197. ; PUCHAR Register,
  198. ; UCHAR Value
  199. ; )
  200. ;
  201. ; Memory space references will use lock prefix to force real access,
  202. ; flush through posted write buffers, and so forth.
  203. ;
  204. ; Arguments:
  205. ; (esp+4) = Register
  206. ; (esp+8) = Value
  207. ;
  208. ;--
  209. cPublicProc _WRITE_REGISTER_UCHAR ,2
  210. cPublicFpo 2,0
  211. mov edx,[esp+4] ; (edx) = Register
  212. mov al,[esp+8] ; (al) = Value
  213. mov [edx],al ; do write
  214. lock or [esp+4],edx ; flush processors posted-write buffers
  215. stdRET _WRITE_REGISTER_UCHAR
  216. stdENDP _WRITE_REGISTER_UCHAR
  217. ;++
  218. ;
  219. ; VOID
  220. ; WRITE_REGISTER_USHORT(
  221. ; PUSHORT Register,
  222. ; USHORT Value
  223. ; )
  224. ;
  225. ; Memory space references will use lock prefix to force real access,
  226. ; flush through posted write buffers, and so forth.
  227. ;
  228. ; Arguments:
  229. ; (esp+4) = Register
  230. ; (esp+8) = Value
  231. ;
  232. ;--
  233. cPublicProc _WRITE_REGISTER_USHORT ,2
  234. cPublicFpo 2,0
  235. mov edx,[esp+4] ; (edx) = Register
  236. mov eax,[esp+8] ; (ax) = Value
  237. mov [edx],ax ; do write
  238. lock or [esp+4],edx ; flush processors posted-write buffers
  239. stdRET _WRITE_REGISTER_USHORT
  240. stdENDP _WRITE_REGISTER_USHORT
  241. ;++
  242. ;
  243. ; VOID
  244. ; WRITE_REGISTER_ULONG(
  245. ; PULONG Register,
  246. ; ULONG Value
  247. ; )
  248. ;
  249. ; Memory space references will use lock prefix to force real access,
  250. ; flush through posted write buffers, and so forth.
  251. ;
  252. ; Arguments:
  253. ; (esp+4) = Register
  254. ; (esp+8) = Value
  255. ;
  256. ;--
  257. cPublicProc _WRITE_REGISTER_ULONG ,2
  258. cPublicFpo 2,0
  259. mov edx,[esp+4] ; (edx) = Register
  260. mov eax,[esp+8] ; (eax) = Value
  261. mov [edx],eax ; do write
  262. lock or [esp+4],edx ; flush processors posted-write buffers
  263. stdRET _WRITE_REGISTER_ULONG
  264. stdENDP _WRITE_REGISTER_ULONG
  265. ;++
  266. ;
  267. ; VOID
  268. ; WRITE_REGISTER_BUFFER_UCHAR(
  269. ; PUCHAR Register,
  270. ; PUCHAR Buffer,
  271. ; ULONG Count
  272. ; )
  273. ;
  274. ; Arguments:
  275. ; (esp+4) = Register
  276. ; (esp+8) = Buffer address
  277. ; (esp+12) = Count
  278. ;
  279. ;--
  280. cPublicProc _WRITE_REGISTER_BUFFER_UCHAR ,3
  281. cPublicFpo 3,0
  282. mov eax, esi
  283. mov edx, edi ; Save esi, edi
  284. mov ecx,[esp+12] ; (ecx) = transfer count
  285. mov esi,[esp+8] ; (edi) = buffer
  286. mov edi,[esp+4] ; (edx) = Register
  287. rep movsb
  288. lock or [esp+4],ecx ; flush processors posted-write buffers
  289. mov edi, edx
  290. mov esi, eax
  291. stdRET _WRITE_REGISTER_BUFFER_UCHAR
  292. stdENDP _WRITE_REGISTER_BUFFER_UCHAR
  293. ;++
  294. ;
  295. ; VOID
  296. ; WRITE_REGISTER_BUFFER_USHORT(
  297. ; PUSHORT Register,
  298. ; PUSHORT Buffer,
  299. ; ULONG Count
  300. ; )
  301. ;
  302. ; Arguments:
  303. ; (esp+4) = Register
  304. ; (esp+8) = Buffer address
  305. ; (esp+12) = Count
  306. ;
  307. ;--
  308. cPublicProc _WRITE_REGISTER_BUFFER_USHORT ,3
  309. cPublicFpo 3,0
  310. mov eax, esi
  311. mov edx, edi ; Save esi, edi
  312. mov ecx,[esp+12] ; (ecx) = transfer count
  313. mov esi,[esp+8] ; (edi) = buffer
  314. mov edi,[esp+4] ; (edx) = Register
  315. rep movsw
  316. lock or [esp+4],ecx ; flush processors posted-write buffers
  317. mov edi, edx
  318. mov esi, eax
  319. stdRET _WRITE_REGISTER_BUFFER_USHORT
  320. stdENDP _WRITE_REGISTER_BUFFER_USHORT
  321. ;++
  322. ;
  323. ; VOID
  324. ; WRITE_REGISTER_BUFFER_ULONG(
  325. ; PULONG Register,
  326. ; PULONG Buffer,
  327. ; ULONG Count
  328. ; )
  329. ;
  330. ; Arguments:
  331. ; (esp+4) = Register
  332. ; (esp+8) = Buffer address
  333. ; (esp+12) = Count
  334. ;
  335. ;--
  336. cPublicProc _WRITE_REGISTER_BUFFER_ULONG ,3
  337. cPublicFpo 0, 3
  338. ;FPO ( 0, 3, 0, 0, 0, 0 )
  339. mov eax, esi
  340. mov edx, edi ; Save esi, edi
  341. mov ecx,[esp+12] ; (ecx) = transfer count
  342. mov esi,[esp+8] ; (edi) = buffer
  343. mov edi,[esp+4] ; (edx) = Register
  344. rep movsd
  345. lock or [esp+4],ecx ; flush processors posted-write buffers
  346. mov edi, edx
  347. mov esi, eax
  348. stdRET _WRITE_REGISTER_BUFFER_ULONG
  349. stdENDP _WRITE_REGISTER_BUFFER_ULONG
  350. _TEXT ends
  351. end