ports.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. {$WARNING Still using EMX - has to be updated once native linking available!}
  57. {$AsmMode ATT}
  58. procedure TPort.WritePort (P: word; Data: byte); assembler;
  59. asm
  60. xorl %ecx, %ecx
  61. {$IFDEF REGCALL}
  62. movw %ax, %cx
  63. pushl %edx
  64. pushl %ecx
  65. {$ELSE REGCALL}
  66. movw P, %cx
  67. {$ENDIF REGCALL}
  68. movl %ecx, %edx
  69. movw $0x7F12, %ax
  70. call syscall
  71. {$IFDEF REGCALL}
  72. popl %edx
  73. popl %eax
  74. {$ELSE REGCALL}
  75. movw P, %dx
  76. movb Data, %al
  77. {$ENDIF REGCALL}
  78. outb %al, %dx
  79. end {['eax', 'ecx', 'edx']};
  80. function TPort.ReadPort (P: word): byte; assembler;
  81. asm
  82. xorl %ecx, %ecx
  83. {$IFDEF REGCALL}
  84. movw %ax, %cx
  85. {$ELSE REGCALL}
  86. movw P, %cx
  87. pushl %ecx
  88. {$ENDIF REGCALL}
  89. movl %ecx, %edx
  90. movw $0x7F12, %ax
  91. call syscall
  92. {$IFDEF REGCALL}
  93. popl %edx
  94. {$ELSE REGCALL}
  95. movw P, %dx
  96. {$ENDIF REGCALL}
  97. inb %dx, %al
  98. end {['eax', 'ecx', 'edx']};
  99. procedure TPortW.WritePort (P: word; Data : word); assembler;
  100. asm
  101. xorl %ecx, %ecx
  102. {$IFDEF REGCALL}
  103. movw %ax, %cx
  104. pushl %edx
  105. pushl %ecx
  106. {$ELSE REGCALL}
  107. movw P, %cx
  108. {$ENDIF REGCALL}
  109. movl %ecx, %edx
  110. movw $0x7F12, %ax
  111. call syscall
  112. {$IFDEF REGCALL}
  113. popl %edx
  114. popl %eax
  115. {$ELSE REGCALL}
  116. movw P, %dx
  117. movw Data, %ax
  118. {$ENDIF REGCALL}
  119. outw %ax, %dx
  120. end {['eax', 'ecx', 'edx']};
  121. function TPortW.ReadPort (P: word): word; assembler;
  122. asm
  123. xorl %ecx, %ecx
  124. {$IFDEF REGCALL}
  125. movw %ax, %cx
  126. pushl %ecx
  127. {$ELSE REGCALL}
  128. movw P, %cx
  129. {$ENDIF REGCALL}
  130. movl %ecx, %edx
  131. movw $0x7F12, %ax
  132. call syscall
  133. {$IFDEF REGCALL}
  134. popl %edx
  135. {$ELSE REGCALL}
  136. movw P, %dx
  137. {$ENDIF REGCALL}
  138. inw %dx, %ax
  139. end {['eax', 'ecx', 'edx']};
  140. procedure TPortL.WritePort (P: word; Data: longint); assembler;
  141. asm
  142. xorl %ecx, %ecx
  143. {$IFDEF REGCALL}
  144. movw %ax, %cx
  145. pushl %edx
  146. pushl %ecx
  147. {$ELSE REGCALL}
  148. movw P, %cx
  149. {$ENDIF REGCALL}
  150. movl %ecx, %edx
  151. movw $0x7F12, %ax
  152. call syscall
  153. {$IFDEF REGCALL}
  154. popl %edx
  155. popl %eax
  156. {$ELSE REGCALL}
  157. movw P, %dx
  158. movl Data, %eax
  159. {$ENDIF REGCALL}
  160. outl %eax, %dx
  161. end {['eax', 'ecx', 'edx']};
  162. function TPortL.ReadPort (P: word): longint; assembler;
  163. asm
  164. xorl %ecx, %ecx
  165. {$IFDEF REGCALL}
  166. movw %ax, %cx
  167. pushl %ecx
  168. {$ELSE REGCALL}
  169. movw P, %cx
  170. {$ENDIF REGCALL}
  171. movl %ecx, %edx
  172. movw $0x7F12, %ax
  173. call syscall
  174. {$IFDEF REGCALL}
  175. popl %edx
  176. {$ELSE REGCALL}
  177. movw P, %dx
  178. {$ENDIF REGCALL}
  179. inl %dx, %eax
  180. end {['eax', 'ecx', 'edx']};
  181. end.