ports.pp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {
  2. This file is part of the Free Pascal run time library.
  3. and implements some stuff for protected mode programming
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. These files adds support for TP styled port accesses
  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. unit ports;
  13. interface
  14. type
  15. tport = object
  16. procedure writeport(p : word;data : byte);
  17. function readport(p : word) : byte;
  18. property pp[w : word] : byte read readport write writeport;default;
  19. end;
  20. tportw = object
  21. procedure writeport(p : word;data : word);
  22. function readport(p : word) : word;
  23. property pp[w : word] : word read readport write writeport;default;
  24. end;
  25. tportl = object
  26. procedure writeport(p : word;data : longint);
  27. function readport(p : word) : longint;
  28. property pp[w : word] : longint read readport write writeport;default;
  29. end;
  30. var
  31. { we don't need to initialize port, because neither member
  32. variables nor virtual methods are accessed }
  33. port,
  34. portb : tport;
  35. portw : tportw;
  36. portl : tportl;
  37. const
  38. fpc_in_x86_inportb = fpc_in_cpu_first;
  39. fpc_in_x86_inportw = fpc_in_cpu_first+1;
  40. // fpc_in_x86_inportl = fpc_in_cpu_first+2;
  41. fpc_in_x86_outportb = fpc_in_cpu_first+3;
  42. fpc_in_x86_outportw = fpc_in_cpu_first+4;
  43. // fpc_in_x86_outportl = fpc_in_cpu_first+5;
  44. function inportb(port : word) : byte;[internproc:fpc_in_x86_inportb];
  45. function inportw(port : word) : word;[internproc:fpc_in_x86_inportw];
  46. //function inportl(port : word) : longint;[internproc:fpc_in_x86_inportl];
  47. procedure outportb(port : word;data : byte);[internproc:fpc_in_x86_outportb];
  48. procedure outportw(port : word;data : word);[internproc:fpc_in_x86_outportw];
  49. //procedure outportl(port : word;data : longint);[internproc:fpc_in_x86_outportl];
  50. implementation
  51. { to give easy port access like tp with port[] }
  52. procedure tport.writeport(p : word;data : byte);inline;
  53. begin
  54. outportb(p,data);
  55. end;
  56. function tport.readport(p : word) : byte;inline;
  57. begin
  58. readport:=inportb(p);
  59. end;
  60. procedure tportw.writeport(p : word;data : word);inline;
  61. begin
  62. outportw(p,data);
  63. end;
  64. function tportw.readport(p : word) : word;inline;
  65. begin
  66. readport:=inportw(p);
  67. end;
  68. {$asmcpu 80386}
  69. procedure tportl.writeport(p : word;data : longint);assembler;
  70. asm
  71. mov dx, p
  72. mov eax, data
  73. out dx, eax
  74. end;
  75. function tportl.readport(p : word) : longint;assembler;
  76. asm
  77. mov dx, p
  78. in eax, dx
  79. mov edx, eax
  80. shr edx, 16
  81. end;
  82. end.