home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 January / pcwk_01_1999.iso / Tajnepp / MCLK093 / PCI.CPP < prev    next >
C/C++ Source or Header  |  1997-04-02  |  3KB  |  125 lines

  1. #include<iostream.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4. #include<dos.h>
  5.  
  6. #include"pci.h"
  7.  
  8. extern int _argc;
  9. extern char **_argv;
  10.  
  11. bios_info_type *
  12. pci_bios_type::installation_check( void )
  13. {
  14.     return bios_info;         // Returns TABLE if PCI_BIOS detected
  15. }
  16.  
  17.  
  18. uchar
  19. pci_bios_type::find_device( pci_device_handle_type *pci_device )
  20. {
  21.     // Attempts to locate device specified in *pci_device
  22.     // Returns TRUE if successful, FALSE otherwise
  23.      union REGS reg;
  24.      uchar status=FALSE;
  25.  
  26.      reg.x.ax=0xB102;    // FIND_PCI_DEVICE
  27.      reg.x.cx= pci_device->device;
  28.      reg.x.dx= pci_device->vendor;
  29.      reg.x.si= pci_device->index;
  30.  
  31.      int86( PCI_INT, ®, ® );
  32.      if ( reg.h.ah == 0 )
  33.     {
  34.         status=TRUE;
  35.           pci_device->bus = reg.h.bh;
  36.           pci_device->f.byte = reg.h.bl;    // Function/device byte
  37.      }
  38.  
  39.      return status;
  40. }
  41.  
  42. uchar
  43. pci_bios_type::read_cbyte( const pci_device_handle_type pci_device,
  44.     const uint index, uchar *value )
  45. {
  46.      union REGS reg;
  47.      uchar status=FALSE;
  48.  
  49.      reg.x.ax=0xB108;    // READ_CONFIGURATION_BYTE (real-mode)
  50.      reg.h.bh= pci_device.bus;
  51.      reg.h.bl= pci_device.f.byte;
  52.      reg.x.di= index;
  53.  
  54.      int86( PCI_INT, ®, ® );
  55.      if ( reg.h.ah == 0 )
  56.      {
  57.         status=TRUE;
  58.           *value = reg.h.cl;
  59.      }
  60.  
  61.      return status;    // Returns BIOS code
  62.     // Returns BIOS code
  63. }
  64.  
  65. uchar
  66. pci_bios_type::write_cbyte( const pci_device_handle_type pci_device,
  67.     const uint index, const uchar value )
  68. {
  69.      union REGS reg;
  70.      uchar status=FALSE;
  71.  
  72.      reg.x.ax=0xB10B;    // WRITE_CONFIGURATION_BYTE (real-mode)
  73.      reg.h.bh= pci_device.bus;
  74.      reg.h.bl= pci_device.f.byte;
  75.      reg.x.di= index;
  76.      reg.h.cl= value;
  77.  
  78.      int86( PCI_INT, ®, ® );
  79.      if ( reg.h.ah == 0 )
  80.         status=TRUE;
  81.  
  82.      return status;    // Returns BIOS code
  83. }
  84.  
  85.  
  86. // Constructor initially calls BIOS for presence of PCI,
  87. // sets "installed" to TRUE or FALSE accordingly.  And loads
  88. // bios_info with pci_information returned by the BIOS call
  89. pci_bios_type::pci_bios_type( void )
  90. {
  91.      union REGS reg;
  92.      installed = FALSE;
  93.      bios_info = NULL;    // In case PCI_BIOS does not exist
  94.  
  95.      reg.x.ax= 0xB101;
  96.      int86( PCI_INT, ®, ® );
  97. //     cout << endl << "PCI bios NOT detected.";
  98.  
  99.      if ( reg.h.ah == 0 )
  100.      {
  101.          installed=TRUE;
  102.           bios_info = new bios_info_type;
  103. //          cout << endl << "PCI BIOS detected!" ;
  104.           bios_info->major_version = reg.h.bh;
  105.           bios_info->minor_version = reg.h.bl;
  106.           bios_info->last_bus = reg.h.cl;
  107.           bios_info->hardware_characteristics = reg.h.al;
  108. //          printf("\nVersion =  %02X.%02X", bios_info->major_version,
  109. //            bios_info->minor_version );
  110. //          printf("\nLast_bus=0x%02X ", bios_info->last_bus );
  111. //         printf("\nHardware=0x%02X ", bios_info->hardware_characteristics );
  112.     }
  113.  
  114. }
  115.  
  116.  
  117. // Destructor frees up memory used to store bios_info table
  118. pci_bios_type::~pci_bios_type()
  119. {
  120.     if ( bios_info != NULL )
  121.          delete bios_info;
  122. }
  123.  
  124.  
  125.