1
0

ioport.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. ioport.S
  5. Abstract:
  6. This module implements assembly-based I/O port access routines for the
  7. x86 platform.
  8. Author:
  9. Evan Green 7-Aug-2013
  10. Environment:
  11. Boot
  12. --*/
  13. ##
  14. ## ------------------------------------------------------------------- Includes
  15. ##
  16. #include <minoca/kernel/x86.inc>
  17. ##
  18. ## -------------------------------------------------------------------- Macros
  19. ##
  20. ##
  21. ## ---------------------------------------------------------------- Definitions
  22. ##
  23. ##
  24. ## -------------------------------------------------------------------- Globals
  25. ##
  26. ##
  27. ## ----------------------------------------------------------------------- Code
  28. ##
  29. ##
  30. ## .text specifies that this code belongs in the executable section.
  31. ##
  32. ## .code32 specifies that this is 32-bit protected mode code.
  33. ##
  34. .text
  35. .code32
  36. ##
  37. ## UINT8
  38. ## EfiIoPortIn8 (
  39. ## UINT16 Address
  40. ## )
  41. ##
  42. /*++
  43. Routine Description:
  44. This routine performs an 8-bit read from the given I/O port.
  45. Arguments:
  46. Address - Supplies the address to read from.
  47. Return Value:
  48. Returns the value at that address.
  49. --*/
  50. FUNCTION(EfiIoPortIn8)
  51. movl 4(%esp), %edx # Get the I/O port.
  52. xorl %eax, %eax # Clear the high bits.
  53. inb %dx, %al # Perform the I/O port read.
  54. nop # Rest a touch.
  55. ret # Return.
  56. END_FUNCTION(EfiIoPortIn8)
  57. ##
  58. ## UINT16
  59. ## EfiIoPortIn16 (
  60. ## UINT16 Address
  61. ## )
  62. ##
  63. /*++
  64. Routine Description:
  65. This routine performs a 16-bit read from the given I/O port.
  66. Arguments:
  67. Address - Supplies the address to read from.
  68. Return Value:
  69. Returns the value at that address.
  70. --*/
  71. FUNCTION(EfiIoPortIn16)
  72. movl 4(%esp), %edx # Get the I/O port.
  73. xorl %eax, %eax # Clear the high bits.
  74. inw %dx, %ax # Perform the I/O port read.
  75. nop # Rest a touch.
  76. ret # Return.
  77. END_FUNCTION(EfiIoPortIn16)
  78. ##
  79. ## UINT32
  80. ## EfiIoPortIn32 (
  81. ## UINT16 Address
  82. ## )
  83. ##
  84. /*++
  85. Routine Description:
  86. This routine performs a 32-bit read from the given I/O port.
  87. Arguments:
  88. Address - Supplies the address to read from.
  89. Return Value:
  90. Returns the value at that address.
  91. --*/
  92. FUNCTION(EfiIoPortIn32)
  93. movl 4(%esp), %edx # Get the I/O port.
  94. inl %dx, %eax # Perform the I/O port read.
  95. nop # Rest a touch.
  96. ret # Return.
  97. END_FUNCTION(EfiIoPortIn32)
  98. ##
  99. ## VOID
  100. ## EfiIoPortOut8 (
  101. ## UINT16 Address,
  102. ## UINT8 Value
  103. ## )
  104. ##
  105. /*++
  106. Routine Description:
  107. This routine performs an 8-bit write to the given I/O port.
  108. Arguments:
  109. Address - Supplies the address to write to.
  110. Value - Supplies the value to write.
  111. Return Value:
  112. None.
  113. --*/
  114. FUNCTION(EfiIoPortOut8)
  115. movl 4(%esp), %edx # Get the I/O port.
  116. movl 8(%esp), %eax # Get the value.
  117. outb %al, %dx # Perform the I/O port write.
  118. nop # Rest a touch.
  119. ret # Return.
  120. END_FUNCTION(EfiIoPortOut8)
  121. ##
  122. ## VOID
  123. ## EfiIoPortOut16 (
  124. ## UINT16 Address,
  125. ## UINT16 Value
  126. ## )
  127. ##
  128. /*++
  129. Routine Description:
  130. This routine performs a 16-bit write to the given I/O port.
  131. Arguments:
  132. Address - Supplies the address to write to.
  133. Value - Supplies the value to write.
  134. Return Value:
  135. None.
  136. --*/
  137. FUNCTION(EfiIoPortOut16)
  138. movl 4(%esp), %edx # Get the I/O port.
  139. movl 8(%esp), %eax # Get the value.
  140. outw %ax, %dx # Perform the I/O port write.
  141. nop # Rest a touch.
  142. ret # Return.
  143. END_FUNCTION(EfiIoPortOut16)
  144. ##
  145. ## VOID
  146. ## EfiIoPortOut32 (
  147. ## UINT16 Address,
  148. ## UINT32 Value
  149. ## )
  150. ##
  151. /*++
  152. Routine Description:
  153. This routine performs a 32-bit write to the given I/O port.
  154. Arguments:
  155. Address - Supplies the address to write to.
  156. Value - Supplies the value to write.
  157. Return Value:
  158. None.
  159. --*/
  160. FUNCTION(EfiIoPortOut32)
  161. movl 4(%esp), %edx # Get the I/O port.
  162. movl 8(%esp), %eax # Get the value.
  163. outl %eax, %dx # Perform the I/O port write.
  164. nop # Rest a touch.
  165. ret # Return.
  166. END_FUNCTION(EfiIoPortOut32)
  167. ##
  168. ## --------------------------------------------------------- Internal Functions
  169. ##