ports.pas 4.6 KB

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