ports.pas 3.5 KB

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