home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / lib / gcc-lib / djgpp / 2.952 / units / ports.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  3.2 KB  |  113 lines

  1. {
  2. Access functions for I/O ports for GPC on an x86 platform. This unit
  3. is *not* portable. It works only on x86 platforms (tested under
  4. Linux and DJGPP). It is provided here only to serve as a replacement
  5. for BP's Port and PortW pseudo arrays.
  6.  
  7. Copyright (C) 1998-2001 Free Software Foundation, Inc.
  8.  
  9. Author: Frank Heckenbach <frank@pascal.gnu.de>
  10.  
  11. This file is part of GNU Pascal.
  12.  
  13. GNU Pascal is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2, or (at your option)
  16. any later version.
  17.  
  18. GNU Pascal is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with GNU Pascal; see the file COPYING. If not, write to the
  25. Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  26. 02111-1307, USA.
  27.  
  28. As a special exception, if you link this file with files compiled
  29. with a GNU compiler to produce an executable, this does not cause
  30. the resulting executable to be covered by the GNU General Public
  31. License. This exception does not however invalidate any other
  32. reasons why the executable file might be covered by the GNU General
  33. Public License.
  34. }
  35.  
  36. {$gnu-pascal,B-,I-}
  37. {$ifndef __i386__}
  38. {$error The Ports unit is only for the x86 platform}
  39. {$endif}
  40.  
  41. unit Ports;
  42.  
  43. interface
  44.  
  45. { Port access functions }
  46. function  InPortB  (PortNumber : ShortWord) : Byte;
  47. function  InPortW  (PortNumber : ShortWord) : ShortWord;
  48. procedure OutPortB (PortNumber : ShortWord; aValue : Byte);
  49. procedure OutPortW (PortNumber, aValue : ShortWord);
  50.  
  51. { libc functions for getting access to the ports -- only for root
  52.   processes, of course -- and to give up root privileges after
  53.   getting access to the ports for setuid root programs. Dummies
  54.   under DJGPP. }
  55. function  IOPerm (From, Num : MedCard; On : Integer) : Integer; asmname 'ioperm';
  56. function  IOPL (Level : Integer) : Integer;                     asmname 'iopl';
  57. function  SetEUID (EUID : Integer) : Integer;                   asmname 'seteuid';
  58.  
  59. implementation
  60.  
  61. function InPortB (PortNumber : ShortWord) : Byte;
  62. var aValue : volatile Byte; (*@@*)
  63. begin
  64.   asm ('inb %%dx, %%al' : '=a' (aValue) : 'd' (PortNumber));
  65.   InPortB := aValue
  66. end;
  67.  
  68. function InPortW (PortNumber : ShortWord) : ShortWord;
  69. var aValue : volatile ShortWord; (*@@*)
  70. begin
  71.   asm ('inw %%dx, %%ax' : '=a' (aValue) : 'd' (PortNumber));
  72.   InPortW := aValue
  73. end;
  74.  
  75. procedure OutPortB (PortNumber : ShortWord; aValue : Byte);
  76. begin
  77.   asm ('outb %%al, %%dx' : : 'd' (PortNumber), 'a' (aValue))
  78. end;
  79.  
  80. procedure OutPortW (PortNumber, aValue : ShortWord);
  81. begin
  82.   asm ('outw %%ax, %%dx' : : 'd' (PortNumber), 'a' (aValue))
  83. end;
  84.  
  85. {$ifdef MSDOS}
  86.  
  87. function IOPerm (From, Num : MedCard; On : Integer) : Integer;
  88. var Dummy : Integer;
  89. begin
  90.   Dummy := From;
  91.   Dummy := Num;
  92.   Dummy := On;
  93.   IOPerm := 0
  94. end;
  95.  
  96. function IOPL (Level : Integer) : Integer;
  97. var Dummy : Integer;
  98. begin
  99.   Dummy := Level;
  100.   IOPL := 0
  101. end;
  102.  
  103. function SetEUID (EUID : Integer) : Integer;
  104. var Dummy : Integer;
  105. begin
  106.   Dummy := EUID;
  107.   SetEUID := 0
  108. end;
  109.  
  110. {$endif}
  111.  
  112. end.
  113.