x86.pp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1997-2004 by the Free Pascal development team
  5. Some x86 specific stuff. Has to be fixed still for *BSD
  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 x86;
  13. interface
  14. Uses BaseUnix;
  15. function ReadPortB (Port : Longint): Byte;
  16. function ReadPortW (Port : Longint): Word;
  17. function ReadPortL (Port : Longint): Longint;
  18. Procedure ReadPort (Port : Longint; Var Value : Byte);
  19. Procedure ReadPort (Port : Longint; Var Value : Longint);
  20. Procedure ReadPort (Port : Longint; Var Value : Word);
  21. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  22. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  23. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  24. Procedure WritePort (Port : Longint; Value : Byte);
  25. Procedure WritePort (Port : Longint; Value : Longint);
  26. Procedure WritePort (Port : Longint; Value : Word);
  27. Procedure WritePortB (Port : Longint; Value : Byte);
  28. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  29. Procedure WritePortL (Port : Longint; Value : Longint);
  30. Procedure WritePortW (Port : Longint; Value : Word);
  31. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  32. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  33. Function fpIOperm (From,Num : Cardinal; Value : cint) : cint;
  34. Function fpIoPL(Level : cint) : cint;
  35. implementation
  36. {$ASMMODE ATT}
  37. Uses Syscall;
  38. Procedure WritePort (Port : Longint; Value : Byte);
  39. {
  40. Writes 'Value' to port 'Port'
  41. }
  42. begin
  43. asm
  44. movl port,%edx
  45. movb value,%al
  46. outb %al,%dx
  47. end ['EAX','EDX'];
  48. end;
  49. Procedure WritePort (Port : Longint; Value : Word);
  50. {
  51. Writes 'Value' to port 'Port'
  52. }
  53. begin
  54. asm
  55. movl port,%edx
  56. movw value,%ax
  57. outw %ax,%dx
  58. end ['EAX','EDX'];
  59. end;
  60. Procedure WritePort (Port : Longint; Value : Longint);
  61. {
  62. Writes 'Value' to port 'Port'
  63. }
  64. begin
  65. asm
  66. movl port,%edx
  67. movl value,%eax
  68. outl %eax,%dx
  69. end ['EAX','EDX'];
  70. end;
  71. Procedure WritePortB (Port : Longint; Value : Byte);
  72. {
  73. Writes 'Value' to port 'Port'
  74. }
  75. begin
  76. asm
  77. movl port,%edx
  78. movb value,%al
  79. outb %al,%dx
  80. end ['EAX','EDX'];
  81. end;
  82. Procedure WritePortW (Port : Longint; Value : Word);
  83. {
  84. Writes 'Value' to port 'Port'
  85. }
  86. begin
  87. asm
  88. movl port,%edx
  89. movw value,%ax
  90. outw %ax,%dx
  91. end ['EAX','EDX'];
  92. end;
  93. Procedure WritePortL (Port : Longint; Value : Longint);
  94. {
  95. Writes 'Value' to port 'Port'
  96. }
  97. begin
  98. asm
  99. movl port,%edx
  100. movl value,%eax
  101. outl %eax,%dx
  102. end ['EAX','EDX'];
  103. end;
  104. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  105. {
  106. Writes 'Count' longints from 'Buf' to Port
  107. }
  108. begin
  109. asm
  110. movl count,%ecx
  111. movl buf,%esi
  112. movl port,%edx
  113. cld
  114. rep
  115. outsl
  116. end ['ECX','ESI','EDX'];
  117. end;
  118. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  119. {
  120. Writes 'Count' words from 'Buf' to Port
  121. }
  122. begin
  123. asm
  124. movl count,%ecx
  125. movl buf,%esi
  126. movl port,%edx
  127. cld
  128. rep
  129. outsw
  130. end ['ECX','ESI','EDX'];
  131. end;
  132. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  133. {
  134. Writes 'Count' bytes from 'Buf' to Port
  135. }
  136. begin
  137. asm
  138. movl count,%ecx
  139. movl buf,%esi
  140. movl port,%edx
  141. cld
  142. rep
  143. outsb
  144. end ['ECX','ESI','EDX'];
  145. end;
  146. Procedure ReadPort (Port : Longint; Var Value : Byte);
  147. {
  148. Reads 'Value' from port 'Port'
  149. }
  150. begin
  151. asm
  152. movl port,%edx
  153. inb %dx,%al
  154. movl value,%edx
  155. movb %al,(%edx)
  156. end ['EAX','EDX'];
  157. end;
  158. Procedure ReadPort (Port : Longint; Var Value : Word);
  159. {
  160. Reads 'Value' from port 'Port'
  161. }
  162. begin
  163. asm
  164. movl port,%edx
  165. inw %dx,%ax
  166. movl value,%edx
  167. movw %ax,(%edx)
  168. end ['EAX','EDX'];
  169. end;
  170. Procedure ReadPort (Port : Longint; Var Value : Longint);
  171. {
  172. Reads 'Value' from port 'Port'
  173. }
  174. begin
  175. asm
  176. movl port,%edx
  177. inl %dx,%eax
  178. movl value,%edx
  179. movl %eax,(%edx)
  180. end ['EAX','EDX'];
  181. end;
  182. function ReadPortB (Port : Longint): Byte; assembler;
  183. {
  184. Reads a byte from port 'Port'
  185. }
  186. asm
  187. xorl %eax,%eax
  188. movl port,%edx
  189. inb %dx,%al
  190. end ['EAX','EDX'];
  191. function ReadPortW (Port : Longint): Word; assembler;
  192. {
  193. Reads a word from port 'Port'
  194. }
  195. asm
  196. xorl %eax,%eax
  197. movl port,%edx
  198. inw %dx,%ax
  199. end ['EAX','EDX'];
  200. function ReadPortL (Port : Longint): LongInt; assembler;
  201. {
  202. Reads a LongInt from port 'Port'
  203. }
  204. asm
  205. movl port,%edx
  206. inl %dx,%eax
  207. end ['EAX','EDX'];
  208. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  209. {
  210. Reads 'Count' longints from port 'Port' to 'Buf'.
  211. }
  212. begin
  213. asm
  214. movl count,%ecx
  215. movl buf,%edi
  216. movl port,%edx
  217. cld
  218. rep
  219. insl
  220. end ['ECX','EDI','EDX'];
  221. end;
  222. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  223. {
  224. Reads 'Count' words from port 'Port' to 'Buf'.
  225. }
  226. begin
  227. asm
  228. movl count,%ecx
  229. movl buf,%edi
  230. movl port,%edx
  231. cld
  232. rep
  233. insw
  234. end ['ECX','EDI','EDX'];
  235. end;
  236. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  237. {
  238. Reads 'Count' bytes from port 'Port' to 'Buf'.
  239. }
  240. begin
  241. asm
  242. movl count,%ecx
  243. movl buf,%edi
  244. movl port,%edx
  245. cld
  246. rep
  247. insb
  248. end ['ECX','EDI','EDX'];
  249. end;
  250. Function fpIOperm (From,Num : Cardinal; Value : cint) : cint;
  251. {
  252. Set permissions on NUM ports starting with port FROM to VALUE
  253. this works ONLY as root.
  254. }
  255. begin
  256. fpIOPerm:=do_Syscall(Syscall_nr_ioperm,TSysParam(From),TSysParam(Num),TSysParam(Value));
  257. end;
  258. Function fpIoPL(Level : cint) : cint;
  259. begin
  260. fpIOPL:=do_Syscall(Syscall_nr_iopl,TSysParam(Level));
  261. end;
  262. end.
  263. {
  264. $Log$
  265. Revision 1.3 2004-04-12 10:31:58 marco
  266. * ioperm/iopl added from linuxold. Untested but will probably work
  267. }