src/os.cc
// Read and write functions to access PCI config.
Read and write functions to access PCI config.
Read and write functions to access PCI config .
uint32 OsLayer::PciRead(int fd, uint32 offset, int width) {
  union {
    uint32 l32;
    uint16 l16;
    uint8 l8;
  } datacast;
  datacast.l32 = 0;
  uint32 size = width / 8;
  sat_assert((width == 32) || (width == 16) || (width == 8));
  sat_assert(offset <= (256 - size));
  if (lseek(fd, offset, SEEK_SET) < 0) {
    logprintf(0, "Process Error: Can't seek %x\n", offset);
    return 0;
  }
  if (read(fd, &datacast, size) != static_cast<ssize_t>(size)) {
    logprintf(0, "Process Error: Can't read %x\n", offset);
    return 0;
  }
  switch (width) {
    case 8:
      sat_assert(&(datacast.l8) == reinterpret_cast<uint8*>(&datacast));
      return datacast.l8;
    case 16:
      sat_assert(&(datacast.l16) == reinterpret_cast<uint16*>(&datacast));
      return datacast.l16;
    case 32:
      return datacast.l32;
  }
  return 0;
}
uint32 OsLayer :: PciRead ( int fd , uint32 offset , int width ) { union { uint32 l32 ; uint16 l16 ; uint8 l8 ; } datacast ; datacast . l32 = 0 ; uint32 size = width / 8 ; sat_assert ( ( width == 32 ) || ( width == 16 ) || ( width == 8 ) ) ; sat_assert ( offset <= ( 256 - size ) ) ; if ( lseek ( fd , offset , SEEK_SET ) < 0 ) { logprintf ( 0 , " \n " , offset ) ; return 0 ; } if ( read ( fd , & datacast , size ) != static_cast < ssize_t > ( size ) ) { logprintf ( 0 , " \n " , offset ) ; return 0 ; } switch ( width ) { case 8 : sat_assert ( & ( datacast . l8 ) == reinterpret_cast < uint8 * > ( & datacast ) ) ; return datacast . l8 ; case 16 : sat_assert ( & ( datacast . l16 ) == reinterpret_cast < uint16 * > ( & datacast ) ) ; return datacast . l16 ; case 32 : return datacast . l32 ; } return 0 ; }
Read and write functions to access PCI config.
Read and write functions to access PCI config .
// Strict aliasing rules lawyers will cause data corruption // on cast pointers in some gccs. // Extract the data.