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.

426 lines
7.1 KiB

  1. title "Misc. Support Routines"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; misca.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; Procedures to correctly touch I/O registers.
  13. ;
  14. ; Author:
  15. ;
  16. ; Shie-Lin Tzong (shielint) Dec-23-1991
  17. ;
  18. ; Environment:
  19. ;
  20. ; x86 real mode.
  21. ;
  22. ; Revision History:
  23. ;
  24. ;--
  25. .386p
  26. SIZE_OF_INT15_C0_BUFFER equ 10
  27. _TEXT SEGMENT PARA USE16 PUBLIC 'CODE'
  28. ASSUME CS: _TEXT, DS:NOTHING, SS:NOTHING
  29. ;++
  30. ;
  31. ; I/O port space read and write functions.
  32. ;
  33. ;--
  34. ;++
  35. ;
  36. ; UCHAR
  37. ; READ_PORT_UCHAR(
  38. ; PUCHAR Port
  39. ; )
  40. ;
  41. ; Arguments:
  42. ; (sp+2) = Port
  43. ;
  44. ; Returns:
  45. ; Value in Port.
  46. ;
  47. ;--
  48. public _READ_PORT_UCHAR
  49. _READ_PORT_UCHAR proc
  50. push bp
  51. mov bp, sp
  52. mov dx, [bp+4]
  53. in al,dx
  54. pop bp
  55. ret
  56. _READ_PORT_UCHAR endp
  57. ;++
  58. ;
  59. ; USHORT
  60. ; READ_PORT_USHORT(
  61. ; PUSHORT Port
  62. ; )
  63. ;
  64. ; Arguments:
  65. ; (sp+2) = Port
  66. ;
  67. ; Returns:
  68. ; Value in Port.
  69. ;
  70. ;--
  71. public _READ_PORT_USHORT
  72. _READ_PORT_USHORT proc
  73. push bp
  74. mov bp, sp
  75. mov dx,[bp+4] ; (dx) = Port
  76. in ax,dx
  77. pop bp
  78. ret
  79. _READ_PORT_USHORT endp
  80. ;++
  81. ;
  82. ; ULONG
  83. ; READ_PORT_ULONG(
  84. ; PUSHORT Port
  85. ; )
  86. ;
  87. ; Arguments:
  88. ; (sp+2) = Port
  89. ;
  90. ; Returns:
  91. ; Value in Port.
  92. ;
  93. ;--
  94. public _READ_PORT_ULONG
  95. _READ_PORT_ULONG proc
  96. push bp
  97. mov bp, sp
  98. mov dx,[bp+4] ; (dx) = Port
  99. in eax,dx ; eax = Value
  100. mov edx, eax
  101. shr edx, 16
  102. pop bp
  103. ret
  104. _READ_PORT_ULONG endp
  105. ;++
  106. ;
  107. ; VOID
  108. ; WRITE_PORT_UCHAR(
  109. ; PUCHAR Port,
  110. ; UCHAR Value
  111. ; )
  112. ;
  113. ; Arguments:
  114. ; (sp+2) = Port
  115. ; (sp+4) = Value
  116. ;
  117. ;--
  118. public _WRITE_PORT_UCHAR
  119. _WRITE_PORT_UCHAR proc
  120. push bp
  121. mov bp, sp
  122. mov dx,[bp+4] ; (dx) = Port
  123. mov al,[bp+6] ; (al) = Value
  124. out dx,al
  125. pop bp
  126. ret
  127. _WRITE_PORT_UCHAR endp
  128. ;++
  129. ;
  130. ; VOID
  131. ; WRITE_PORT_USHORT(
  132. ; PUSHORT Port,
  133. ; USHORT Value
  134. ; )
  135. ;
  136. ; Arguments:
  137. ; (sp+2) = Port
  138. ; (sp+4) = Value
  139. ;
  140. ;--
  141. public _WRITE_PORT_USHORT
  142. _WRITE_PORT_USHORT proc
  143. push bp
  144. mov bp, sp
  145. mov dx,[bp+4] ; (dx) = Port
  146. mov ax,[bp+6] ; (ax) = Value
  147. out dx,ax
  148. pop bp
  149. ret
  150. _WRITE_PORT_USHORT endp
  151. ;++
  152. ;
  153. ; VOID
  154. ; WRITE_PORT_ULONG(
  155. ; PUSHORT Port,
  156. ; ULONG Value
  157. ; )
  158. ;
  159. ; Arguments:
  160. ; (sp+2) = Port
  161. ; (sp+4) = Value (LSW)
  162. ; (sp+6) = Value (MSW)
  163. ;
  164. ;--
  165. public _WRITE_PORT_ULONG
  166. _WRITE_PORT_ULONG proc
  167. push bp
  168. mov bp, sp
  169. mov dx,[bp+4] ; (dx) = Port
  170. xor eax, eax
  171. mov ax,[bp+8] ; (ax) = Value MSW
  172. shl eax, 16
  173. mov ax,[bp+6] ; (ax) = Value LSW
  174. out dx,eax
  175. pop bp
  176. ret
  177. _WRITE_PORT_ULONG endp
  178. ;++
  179. ;
  180. ; VOID
  181. ; GetBiosSystemEnvironment(
  182. ; PUCHAR Buffer
  183. ; )
  184. ;
  185. ; Description:
  186. ;
  187. ; This function performs int 15h C0H function to get System
  188. ; Environment supplied by BIOS ROM.
  189. ;
  190. ; Arguments:
  191. ;
  192. ; Buffer - Supplies a pointer to a buffer to receive the BIOS
  193. ; System Environment. Caller must ensure that the buffer
  194. ; is big enough.
  195. ;
  196. ;--
  197. GbseBuffer equ [bp + 4]
  198. public _GetBiosSystemEnvironment
  199. _GetBiosSystemEnvironment proc near
  200. push bp
  201. mov bp, sp
  202. push bx
  203. push es
  204. push ds
  205. push si
  206. push di
  207. mov ah, 0c0h
  208. int 15h
  209. mov ax, es ; exchange es and ds
  210. mov cx, ds
  211. mov ds, ax
  212. mov es, cx
  213. mov si, bx ; [ds:si] -> ROM buffer (source)
  214. mov di, GbseBuffer ; [es:di] -> caller's buffer (destination)
  215. mov cx, SIZE_OF_INT15_C0_BUFFER
  216. rep movsb
  217. pop di
  218. pop si
  219. pop ds
  220. pop es
  221. pop bx
  222. mov sp, bp
  223. pop bp
  224. ret
  225. _GetBiosSystemEnvironment endp
  226. ;++
  227. ;
  228. ; BOOLEAN
  229. ; HwRomCompare(
  230. ; ULONG Source,
  231. ; ULONG Destination
  232. ; ULONG Size
  233. ; )
  234. ;
  235. ; Description:
  236. ;
  237. ; This function performs ROM comparison between the Source ROM
  238. ; block and Destination ROM block.
  239. ;
  240. ; Arguments:
  241. ;
  242. ; Source - Supplies the physical address of source ROM block.
  243. ;
  244. ; Destination - Supplies the physical address of destination ROM block.
  245. ;
  246. ; Size - The size of the comparison. Must be <= 64k.
  247. ;
  248. ; Return:
  249. ;
  250. ; 0 - if the contents of Source and destination are the same.
  251. ;
  252. ; != 0 if the contents are different.
  253. ;--
  254. HfSource equ [bp + 4]
  255. HfDestination equ [bp + 8]
  256. HfSize equ [bp + 12]
  257. public _HwRomCompare
  258. _HwRomCompare proc near
  259. push bp
  260. mov bp, sp
  261. push esi
  262. push edi
  263. push ds
  264. push es
  265. cld
  266. mov ecx, HfSize
  267. cmp ecx, 10000h
  268. ja HfNotTheSame
  269. mov eax, HfSource
  270. add eax, ecx
  271. cmp eax, 100000h
  272. ja short HfNotTheSame
  273. mov edx, HfDestination
  274. add edx, ecx
  275. cmp edx, 100000h
  276. ja short HfNotTheSame
  277. mov eax, HfSource
  278. shr eax, 4
  279. mov es, ax
  280. mov edi, HfSource
  281. and edi, 0fh
  282. mov eax, HfDestination
  283. shr eax, 4
  284. mov ds, ax
  285. mov esi, HfDestination
  286. and esi, 0fh
  287. shr ecx, 2
  288. repe cmpsd
  289. jnz short HfNotTheSame
  290. mov ax, 0
  291. jmp short HfExit
  292. HfNotTheSame:
  293. mov ax, 1
  294. HfExit:
  295. pop es
  296. pop ds
  297. pop edi
  298. pop esi
  299. pop bp
  300. ret
  301. _HwRomCompare endp
  302. ;++
  303. ;
  304. ; VOID
  305. ; HwGetKey(
  306. ; VOID
  307. ; )
  308. ;
  309. ; Description:
  310. ;
  311. ; This function waits for a key to be pressed.
  312. ;
  313. ; Arguments:
  314. ; None.
  315. ;
  316. ;--
  317. public _HwGetKey
  318. _HwGetkey proc
  319. mov ax,0100h
  320. int 16h
  321. mov ax,0
  322. jz short Hgk99
  323. ;
  324. ; Now we call BIOS again, this time to get the key from the keyboard buffer
  325. ;
  326. int 16h
  327. Hgk99:
  328. ret
  329. _HwGetKey endp
  330. ;++
  331. ;
  332. ; VOID
  333. ; HwPushKey(
  334. ; USHORT Key
  335. ; )
  336. ;
  337. ; Description:
  338. ;
  339. ; This function pushes a character and scan code to keyboard
  340. ; type-ahead buffer.
  341. ;
  342. ; Arguments:
  343. ;
  344. ; Key - Supplies the key to be push back.
  345. ; bit 0 - 7 : Character
  346. ; bit 8 - 15: Scan Code
  347. ;
  348. ;--
  349. public _HwPushKey
  350. _HwPushkey proc
  351. mov cx, [esp + 2] ; character and scan code
  352. mov ah, 05h
  353. int 16h
  354. ;
  355. ; I don't care if the function call is successful.
  356. ;
  357. ret
  358. _HwPushKey endp
  359. _TEXT ends
  360. end