home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu / 2008-06-02_hobbes.nmsu.edu.zip / dos / Usb4pas.zip / PCI.PAS < prev    next >
Pascal/Delphi Source File  |  1999-01-25  |  5KB  |  199 lines

  1. { ************************************************************************ }
  2. { PCI.PAS:  PCI BIOS Routines by Dieter R. Pawelczak <dieterp@bigfoot.de>  }
  3. { ======================================================================== }
  4. {                                                                          }
  5. {              Unit to detect PCI-Devices and to read/write to             }
  6. {              its configuration registers                                 }
  7. {                                                                          }
  8. { (c) 1998 by Dieter Pawelczak, <dieterp@bigfoot.de>                       }
  9. { This is public domain Software - selling this software is prohibeted!    }
  10. {                                                                          }
  11. { ************************************************************************ }
  12.  
  13. {$G+}
  14.  
  15.  
  16. unit PCI;
  17. interface
  18.  
  19. function detectPCIBios:boolean;
  20. function detectPCIdevice(DeviceID:Word;VendorID:Word;VAR BusNumber:Byte;VAR FunctionNumber:Byte):boolean;
  21. function readPCIRegisterByte(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var result:byte):boolean;
  22. function readPCIRegisterWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var result:Word):boolean;
  23. function readPCIRegisterDWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var result:longint):boolean;
  24. function writePCIRegisterByte(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;input:byte):boolean;
  25. function writePCIRegisterWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;input:word):boolean;
  26. function writePCIRegisterDWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;input:longint):boolean;
  27.  
  28. implementation
  29.  
  30. function detectPCIBios:boolean;assembler;
  31. asm
  32.     mov ax,0b101h
  33.     int 1ah
  34.     jc @nopcibios
  35.     mov ax,1
  36.     ret
  37.   @nopcibios:
  38.     xor ax,ax
  39.     ret
  40. end;
  41.  
  42. function detectPCIdevice(DeviceID:Word;VendorID:Word;VAR BusNumber:Byte;VAR FunctionNumber:Byte):boolean;
  43. var found:boolean;
  44.     bn:byte;
  45.     fn:byte;
  46. begin
  47.   bn:=0;fn:=0;
  48.   found:=false;
  49.   asm
  50.     db 66h;pusha
  51.     mov cx,DeviceID
  52.     mov dx,VendorID
  53.     mov ax,0b102h
  54.     xor si,si
  55.     int 1ah
  56.     jc @nodevice
  57.     mov found,true
  58.     mov bn,BH
  59.     mov fn,BL
  60.   @nodevice:
  61.     db 66h;popa
  62.   end;
  63.   BusNumber:=bn;FunctionNumber:=fn;
  64.   detectPCIdevice:=found;
  65. end;
  66.  
  67. function readPCIRegisterByte(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var result:byte):boolean;
  68. var okay:boolean;
  69.     res:byte;
  70. begin
  71.   okay:=false;
  72.   res:=0;
  73.   asm
  74.     db 66h; pusha
  75.     mov AX,0B108h
  76.     mov BH,busNumber
  77.     mov BL,functionNumber
  78.     mov DI,RegisterNumber
  79.     int 1Ah
  80.     jc @noaction
  81.     mov res,cl
  82.     mov okay,true
  83.   @noaction:
  84.     db 66h; popa
  85.   end;
  86.   result:=res;
  87.   readPCIRegisterByte:=okay;
  88. end;
  89.  
  90. function readPCIRegisterWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var result:Word):boolean;
  91. var okay:boolean;
  92.     res:word;
  93. begin
  94.   okay:=false;
  95.   res:=0;
  96.   asm
  97.     db 66h; pusha
  98.     mov AX,0B109h
  99.     mov BH,busNumber
  100.     mov BL,functionNumber
  101.     mov DI,RegisterNumber
  102.     int 1Ah
  103.     jc @noaction
  104.     mov res,cx
  105.     mov okay,true
  106.   @noaction:
  107.     db 66h; popa
  108.   end;
  109.   result:=res;
  110.   readPCIRegisterWord:=okay;
  111. end;
  112.  
  113. function readPCIRegisterDWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;var result:longint):boolean;
  114. var okay:boolean;
  115.     res:longint;
  116. begin
  117.   okay:=false;
  118.   res:=0;
  119.   asm
  120.     db 66h; pusha
  121.     mov AX,0B10ah
  122.     mov BH,busNumber
  123.     mov BL,functionNumber
  124.     mov DI,RegisterNumber
  125.     int 1Ah
  126.     jc @noaction
  127.     db 66h; mov word ptr res,cx { MOV RES, ECX }
  128.     mov okay,true
  129.   @noaction:
  130.     db 66h; popa
  131.   end;
  132.   result:=res;
  133.   readPCIRegisterDword:=okay;
  134. end;
  135.  
  136. function writePCIRegisterByte(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;input:byte):boolean;
  137. var okay:boolean;
  138. begin
  139.   okay:=false;
  140.   asm
  141.     db 66h; pusha
  142.     mov AX,0B10bh
  143.     mov BH,busNumber
  144.     mov BL,functionNumber
  145.     mov DI,RegisterNumber
  146.     mov CL,input
  147.     int 1Ah
  148.     jc @noaction
  149.     mov okay,true
  150.   @noaction:
  151.     db 66h; popa
  152.   end;
  153.   writePCIRegisterByte:=okay;
  154. end;
  155.  
  156. function writePCIRegisterWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;input:word):boolean;
  157. var okay:boolean;
  158. begin
  159.   okay:=false;
  160.   asm
  161.     db 66h; pusha
  162.     mov AX,0B10ch
  163.     mov BH,busNumber
  164.     mov BL,functionNumber
  165.     mov DI,RegisterNumber
  166.     mov CX,input
  167.     int 1Ah
  168.     jc @noaction
  169.     mov okay,true
  170.   @noaction:
  171.     db 66h; popa
  172.   end;
  173.   writePCIRegisterWord:=okay;
  174. end;
  175.  
  176. function writePCIRegisterDWord(RegisterNumber:word;BusNumber:Byte;FunctionNumber:Byte;input:longint):boolean;
  177. var okay:boolean;
  178.     res:byte;
  179. begin
  180.   okay:=false;
  181.   res:=0;
  182.   asm
  183.     db 66h; pusha
  184.     mov AX,0B10dh
  185.     mov BH,busNumber
  186.     mov BL,functionNumber
  187.     mov DI,RegisterNumber
  188.     db 66h; mov CX, word ptr input
  189.     int 1Ah
  190.     jc @noaction
  191.     mov okay,true
  192.   @noaction:
  193.     db 66h; popa
  194.   end;
  195.   writePCIRegisterDWord:=okay;
  196. end;
  197.  
  198. end.
  199.