ports.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. {$IFNDEF FPC_DOTTEDUNITS}
  22. unit Ports;
  23. {$ENDIF FPC_DOTTEDUNITS}
  24. { This unit uses classes so ObjFpc mode is required. }
  25. {$Mode ObjFpc}
  26. interface
  27. type
  28. TPort = class
  29. protected
  30. procedure WritePort (P: word; Data: byte);
  31. function ReadPort (P: word): byte;
  32. public
  33. property PP [W: word]: byte read readport write writeport; default;
  34. end;
  35. TPortW = class
  36. protected
  37. procedure WritePort (P: word; Data: word);
  38. function ReadPort (P: word): word;
  39. public
  40. property PP [W: word]: word read readport write writeport; default;
  41. end;
  42. TPortL = class
  43. protected
  44. procedure WritePort (P: word; Data: longint);
  45. function ReadPort (P: word): longint;
  46. public
  47. property PP [W: word]: longint read readport write writeport; default;
  48. end;
  49. { Non-instantiated vars. As yet, they don't have to be instantiated,
  50. because neither member variables nor virtual methods are accessed }
  51. var
  52. Port, PortB: TPort;
  53. PortW: TPortW;
  54. PortL: TPortL;
  55. implementation
  56. {Import syscall to call it nicely from assembler procedures.}
  57. procedure syscall; external name '___SYSCALL';
  58. {$WARNING Still using EMX - has to be updated once native linking available!}
  59. {$AsmMode ATT}
  60. procedure TPort.WritePort (P: word; Data: byte); assembler;
  61. asm
  62. xorl %ecx, %ecx
  63. {$IFDEF REGCALL}
  64. movw %ax, %cx
  65. pushl %edx
  66. pushl %ecx
  67. {$ELSE REGCALL}
  68. movw P, %cx
  69. {$ENDIF REGCALL}
  70. movl %ecx, %edx
  71. movw $0x7F12, %ax
  72. call syscall
  73. {$IFDEF REGCALL}
  74. popl %edx
  75. popl %eax
  76. {$ELSE REGCALL}
  77. movw P, %dx
  78. movb Data, %al
  79. {$ENDIF REGCALL}
  80. outb %al, %dx
  81. end {['eax', 'ecx', 'edx']};
  82. function TPort.ReadPort (P: word): byte; assembler;
  83. asm
  84. xorl %ecx, %ecx
  85. {$IFDEF REGCALL}
  86. movw %ax, %cx
  87. {$ELSE REGCALL}
  88. movw P, %cx
  89. pushl %ecx
  90. {$ENDIF REGCALL}
  91. movl %ecx, %edx
  92. movw $0x7F12, %ax
  93. call syscall
  94. {$IFDEF REGCALL}
  95. popl %edx
  96. {$ELSE REGCALL}
  97. movw P, %dx
  98. {$ENDIF REGCALL}
  99. inb %dx, %al
  100. end {['eax', 'ecx', 'edx']};
  101. procedure TPortW.WritePort (P: word; Data : word); assembler;
  102. asm
  103. xorl %ecx, %ecx
  104. {$IFDEF REGCALL}
  105. movw %ax, %cx
  106. pushl %edx
  107. pushl %ecx
  108. {$ELSE REGCALL}
  109. movw P, %cx
  110. {$ENDIF REGCALL}
  111. movl %ecx, %edx
  112. movw $0x7F12, %ax
  113. call syscall
  114. {$IFDEF REGCALL}
  115. popl %edx
  116. popl %eax
  117. {$ELSE REGCALL}
  118. movw P, %dx
  119. movw Data, %ax
  120. {$ENDIF REGCALL}
  121. outw %ax, %dx
  122. end {['eax', 'ecx', 'edx']};
  123. function TPortW.ReadPort (P: word): word; assembler;
  124. asm
  125. xorl %ecx, %ecx
  126. {$IFDEF REGCALL}
  127. movw %ax, %cx
  128. pushl %ecx
  129. {$ELSE REGCALL}
  130. movw P, %cx
  131. {$ENDIF REGCALL}
  132. movl %ecx, %edx
  133. movw $0x7F12, %ax
  134. call syscall
  135. {$IFDEF REGCALL}
  136. popl %edx
  137. {$ELSE REGCALL}
  138. movw P, %dx
  139. {$ENDIF REGCALL}
  140. inw %dx, %ax
  141. end {['eax', 'ecx', 'edx']};
  142. procedure TPortL.WritePort (P: word; Data: longint); assembler;
  143. asm
  144. xorl %ecx, %ecx
  145. {$IFDEF REGCALL}
  146. movw %ax, %cx
  147. pushl %edx
  148. pushl %ecx
  149. {$ELSE REGCALL}
  150. movw P, %cx
  151. {$ENDIF REGCALL}
  152. movl %ecx, %edx
  153. movw $0x7F12, %ax
  154. call syscall
  155. {$IFDEF REGCALL}
  156. popl %edx
  157. popl %eax
  158. {$ELSE REGCALL}
  159. movw P, %dx
  160. movl Data, %eax
  161. {$ENDIF REGCALL}
  162. outl %eax, %dx
  163. end {['eax', 'ecx', 'edx']};
  164. function TPortL.ReadPort (P: word): longint; assembler;
  165. asm
  166. xorl %ecx, %ecx
  167. {$IFDEF REGCALL}
  168. movw %ax, %cx
  169. pushl %ecx
  170. {$ELSE REGCALL}
  171. movw P, %cx
  172. {$ENDIF REGCALL}
  173. movl %ecx, %edx
  174. movw $0x7F12, %ax
  175. call syscall
  176. {$IFDEF REGCALL}
  177. popl %edx
  178. {$ELSE REGCALL}
  179. movw P, %dx
  180. {$ENDIF REGCALL}
  181. inl %dx, %eax
  182. end {['eax', 'ecx', 'edx']};
  183. end.