ports.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. {$calling StdCall}
  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. {$AsmMode ATT}
  59. procedure TPort.WritePort (P: word; Data: byte); assembler;
  60. asm
  61. xorl %ecx, %ecx
  62. movw P, %cx
  63. movl %ecx, %edx
  64. movw $0x7F12, %ax
  65. call syscall
  66. movw P, %dx
  67. movb Data, %al
  68. outb %al, %dx
  69. end {['eax', 'ecx', 'edx']};
  70. function TPort.ReadPort (P: word): byte; assembler;
  71. asm
  72. xorl %ecx, %ecx
  73. movw P, %cx
  74. movl %ecx, %edx
  75. movw $0x7F12, %ax
  76. call syscall
  77. movw P, %dx
  78. inb %dx, %al
  79. end {['eax', 'ecx', 'edx']};
  80. procedure TPortW.WritePort (P: word; Data : word); assembler;
  81. asm
  82. xorl %ecx, %ecx
  83. movw P, %cx
  84. movl %ecx, %edx
  85. movw $0x7F12, %ax
  86. call syscall
  87. movw P, %dx
  88. movw Data, %ax
  89. outw %ax, %dx
  90. end {['eax', 'ecx', 'edx']};
  91. function TPortW.ReadPort (P: word): word; assembler;
  92. asm
  93. xorl %ecx, %ecx
  94. movw P, %cx
  95. movl %ecx, %edx
  96. movw $0x7F12, %ax
  97. call syscall
  98. movw P, %dx
  99. inw %dx, %ax
  100. end {['eax', 'ecx', 'edx']};
  101. procedure TPortL.WritePort (P: word; Data: longint); assembler;
  102. asm
  103. xorl %ecx, %ecx
  104. movw P, %cx
  105. movl %ecx, %edx
  106. movw $0x7F12, %ax
  107. call syscall
  108. movw P, %dx
  109. movl Data, %eax
  110. outl %eax, %dx
  111. end {['eax', 'ecx', 'edx']};
  112. function TPortL.ReadPort (P: word): longint; assembler;
  113. asm
  114. xorl %ecx, %ecx
  115. movw P, %cx
  116. movl %ecx, %edx
  117. movw $0x7F12, %ax
  118. call syscall
  119. movw P, %dx
  120. inl %dx, %eax
  121. end {['eax', 'ecx', 'edx']};
  122. end.
  123. {
  124. $Log$
  125. Revision 1.5 2003-12-04 21:22:38 peter
  126. * regcall updates (untested)
  127. Revision 1.4 2003/10/18 16:58:39 hajny
  128. * stdcall fixes again
  129. Revision 1.3 2003/10/07 21:26:35 hajny
  130. * stdcall fixes and asm routines cleanup
  131. Revision 1.2 2002/09/07 16:01:25 peter
  132. * old logs removed and tabs fixed
  133. }