ports.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team.
  4. These files adds support for TP styled port accesses (port[],
  5. portw[] and portl[] constructs) using Delphi classes.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. (*
  13. Warning:
  14. 1) You have to enable port access in your CONFIG.SYS (IOPL directive),
  15. either globally (IOPL=YES), or just for particular application/-s with
  16. a need for port access (IOPL=app_name1, appname2, ...).
  17. 2) Once you access some port, access to this port is enabled all the time
  18. for all EMX applications until EMX.DLL is unloaded from memory (i.e.
  19. all applications using this library finish).
  20. *)
  21. unit Ports;
  22. { This unit uses classes so ObjFpc mode is required. }
  23. {$Mode ObjFpc}
  24. interface
  25. type
  26. TPort = class
  27. protected
  28. procedure WritePort (P: word; Data: byte);
  29. function ReadPort (P: word): byte;
  30. public
  31. property PP [W: word]: byte read readport write writeport; default;
  32. end;
  33. TPortW = class
  34. protected
  35. procedure WritePort (P: word; Data: word);
  36. function ReadPort (P: word): word;
  37. public
  38. property PP [W: word]: word read readport write writeport; default;
  39. end;
  40. TPortL = class
  41. protected
  42. procedure WritePort (P: word; Data: longint);
  43. function ReadPort (P: word): longint;
  44. public
  45. property PP [W: word]: longint read readport write writeport; default;
  46. end;
  47. { Non-instantiated vars. As yet, they don't have to be instantiated,
  48. because neither member variables nor virtual methods are accessed }
  49. var
  50. Port, PortB: TPort;
  51. PortW: TPortW;
  52. PortL: TPortL;
  53. implementation
  54. {Import syscall to call it nicely from assembler procedures.}
  55. procedure syscall; external name '___SYSCALL';
  56. {$AsmMode ATT}
  57. procedure TPort.WritePort (P: word; Data: byte); assembler;
  58. asm
  59. xorl %ecx, %ecx
  60. {$IFDEF REGCALL}
  61. movw %ax, %cx
  62. pushl %edx
  63. pushl %ecx
  64. {$ELSE REGCALL}
  65. movw P, %cx
  66. {$ENDIF REGCALL}
  67. movl %ecx, %edx
  68. movw $0x7F12, %ax
  69. call syscall
  70. {$IFDEF REGCALL}
  71. popl %edx
  72. popl %eax
  73. {$ELSE REGCALL}
  74. movw P, %dx
  75. movb Data, %al
  76. {$ENDIF REGCALL}
  77. outb %al, %dx
  78. end {['eax', 'ecx', 'edx']};
  79. function TPort.ReadPort (P: word): byte; assembler;
  80. asm
  81. xorl %ecx, %ecx
  82. {$IFDEF REGCALL}
  83. movw %ax, %cx
  84. {$ELSE REGCALL}
  85. movw P, %cx
  86. pushl %ecx
  87. {$ENDIF REGCALL}
  88. movl %ecx, %edx
  89. movw $0x7F12, %ax
  90. call syscall
  91. {$IFDEF REGCALL}
  92. popl %edx
  93. {$ELSE REGCALL}
  94. movw P, %dx
  95. {$ENDIF REGCALL}
  96. inb %dx, %al
  97. end {['eax', 'ecx', 'edx']};
  98. procedure TPortW.WritePort (P: word; Data : word); assembler;
  99. asm
  100. xorl %ecx, %ecx
  101. {$IFDEF REGCALL}
  102. movw %ax, %cx
  103. pushl %edx
  104. pushl %ecx
  105. {$ELSE REGCALL}
  106. movw P, %cx
  107. {$ENDIF REGCALL}
  108. movl %ecx, %edx
  109. movw $0x7F12, %ax
  110. call syscall
  111. {$IFDEF REGCALL}
  112. popl %edx
  113. popl %eax
  114. {$ELSE REGCALL}
  115. movw P, %dx
  116. movw Data, %ax
  117. {$ENDIF REGCALL}
  118. outw %ax, %dx
  119. end {['eax', 'ecx', 'edx']};
  120. function TPortW.ReadPort (P: word): word; assembler;
  121. asm
  122. xorl %ecx, %ecx
  123. {$IFDEF REGCALL}
  124. movw %ax, %cx
  125. pushl %ecx
  126. {$ELSE REGCALL}
  127. movw P, %cx
  128. {$ENDIF REGCALL}
  129. movl %ecx, %edx
  130. movw $0x7F12, %ax
  131. call syscall
  132. {$IFDEF REGCALL}
  133. popl %edx
  134. {$ELSE REGCALL}
  135. movw P, %dx
  136. {$ENDIF REGCALL}
  137. inw %dx, %ax
  138. end {['eax', 'ecx', 'edx']};
  139. procedure TPortL.WritePort (P: word; Data: longint); assembler;
  140. asm
  141. xorl %ecx, %ecx
  142. {$IFDEF REGCALL}
  143. movw %ax, %cx
  144. pushl %edx
  145. pushl %ecx
  146. {$ELSE REGCALL}
  147. movw P, %cx
  148. {$ENDIF REGCALL}
  149. movl %ecx, %edx
  150. movw $0x7F12, %ax
  151. call syscall
  152. {$IFDEF REGCALL}
  153. popl %edx
  154. popl %eax
  155. {$ELSE REGCALL}
  156. movw P, %dx
  157. movl Data, %eax
  158. {$ENDIF REGCALL}
  159. outl %eax, %dx
  160. end {['eax', 'ecx', 'edx']};
  161. function TPortL.ReadPort (P: word): longint; assembler;
  162. asm
  163. xorl %ecx, %ecx
  164. {$IFDEF REGCALL}
  165. movw %ax, %cx
  166. pushl %ecx
  167. {$ELSE REGCALL}
  168. movw P, %cx
  169. {$ENDIF REGCALL}
  170. movl %ecx, %edx
  171. movw $0x7F12, %ax
  172. call syscall
  173. {$IFDEF REGCALL}
  174. popl %edx
  175. {$ELSE REGCALL}
  176. movw P, %dx
  177. {$ENDIF REGCALL}
  178. inl %dx, %eax
  179. end {['eax', 'ecx', 'edx']};
  180. end.