📄 testutil.cpp
字号:
if (temp.RevisionID != orig.RevisionID)
{
printf ("Bad config.RevisionID read/write/read. Was %04x. Should be %04x\n",
temp.RevisionID, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.ProgIf != orig.ProgIf)
{
printf ("Bad config.ProgIf read/write/read. Was %04x. Should be %04x\n",
temp.ProgIf, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.SubClass != orig.SubClass)
{
printf ("Bad config.SubClass read/write/read. Was %04x. Should be %04x\n",
temp.SubClass, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.BaseClass != orig.BaseClass)
{
printf ("Bad config.BaseClass read/write/read. Was %04x. Should be %04x\n",
temp.BaseClass, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.CardBusCISPtr != orig.CardBusCISPtr)
{
printf ("Bad config.CardBusCISPtr read/write/read. Was %04x. Should be %04x\n",
temp.CardBusCISPtr, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.SubsystemID != orig.SubsystemID)
{
printf ("Bad config.SubsystemID read/write/read. Was %04x. Should be %04x\n",
temp.SubsystemID, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.SubsystemVendorID != orig.SubsystemVendorID)
{
printf ("Bad config.SubsystemVendorID read/write/read. Was %04x. Should be %04x\n",
temp.SubsystemVendorID, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.MaximumLatency != orig.MaximumLatency)
{
printf ("Bad config.MaximumLatency read/write/read. Was %04x. Should be %04x\n",
temp.MaximumLatency, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.MinimumGrant != orig.MinimumGrant)
{
printf ("Bad config.MinimumGrant read/write/read. Was %04x. Should be %04x\n",
temp.MinimumGrant, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.InterruptPin != orig.InterruptPin)
{
printf ("Bad config.InterruptPin read/write/read. Was %04x. Should be %04x\n",
temp.InterruptPin, orig.VendorID);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
// Complement the complement (to restore the original). Write them back.
temp.Command = ~temp.Command;
temp.Status = ~temp.Status;
temp.LatencyTimer = ~temp.LatencyTimer;
temp.BaseAddresses[0] = ~temp.BaseAddresses[0];
temp.BaseAddresses[1] = ~temp.BaseAddresses[1];
temp.CacheLineSize = 0x08; // this is the only valid value
temp.InterruptLine = ~temp.InterruptLine;
comemSetPCIInfoL(&temp, comemID);
// Read them to confirm that they are restored.
returnStat = callGetPCIInfo(&temp, comemID);
printf ("Restored: Command=%04x Status=%04x Lat=%02x BAR0=%08x BAR1=%08x CacheLS=%02x IntLine=%02x\n",
temp.Command, temp.Status, temp.LatencyTimer, temp.BaseAddresses[0], temp.BaseAddresses[1],
temp.CacheLineSize, temp.InterruptLine);
_flushall();
// Check Config Regs.
if (temp.Command != orig.Command)
{
printf ("Bad config.Command read/write/read. Was %04x. Should be %04x\n",
temp.Command, orig.Command);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.Status != orig.Status) // Since config.Status is Read-only, better be correct.
{
printf ("Bad config.Status read/write/read. Was %04x. Should be %04x\n",
temp.Status, orig.Status);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.LatencyTimer != orig.LatencyTimer)
{
printf ("Bad config.LatencyTimer read/write/read. Was %02x. Should be %02x\n",
temp.LatencyTimer, orig.LatencyTimer);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.BaseAddresses[0] != orig.BaseAddresses[0])
{
printf ("Bad config.BaseAddresses[0] read/write/read. Was %08x. Should be %08x\n",
temp.BaseAddresses[0], orig.BaseAddresses[0]);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.BaseAddresses[1] != orig.BaseAddresses[1])
{
printf ("Bad config.BaseAddresses[1] read/write/read. Was %08x. Should be %08x\n",
temp.BaseAddresses[1], orig.BaseAddresses[1]);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.CacheLineSize != orig.CacheLineSize)
{
printf ("Bad config.CacheLineSize read/write/read. Was %02x. Should be %02x\n",
temp.CacheLineSize, orig.CacheLineSize);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
if (temp.InterruptLine != orig.InterruptLine)
{
printf ("Bad config.InterruptLine read/write/read. Was %02x. Should be %02x\n",
temp.InterruptLine, orig.InterruptLine);
_flushall();
returnCode = ERROR_CONFIG_REG_TEST;
}
return (returnCode);
}
void PrintBuf(PUCHAR pvBuf, DWORD addr, DWORD len)
{
DWORD i;
printf("Addr: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");
// if(!(addr%16)) // prime first line i.e. addr==0x0011 0010: ff
// printf("\n%04x: %s", addr-(addr%16), );
for(i=addr; i < (addr+len); i++)
{
if(!(i%16))
printf("\n%04x: %02x", i, *(pvBuf+(i-addr)));
else
printf(" %02x", *(pvBuf+(i-addr)));
}
printf("\n");
}
// A wrapper so we do error checking, but don't have to code it every time we call the VxD.
DWORD callReadEeprom (DWORD addr, unsigned char *blockptr, DWORD size, DWORD comemID)
{
DWORD returnCode;
printf ("Reading EEPROM contents...\n");
returnCode = readEepromL(addr, blockptr, size, comemID);
if (returnCode == NO_ERROR)
{
PrintBuf(blockptr, addr, size);
printf ("Read EEPROM contents complete\n");
}
else
{
printf ("Read EEPROM contents Failed\n");
}
return returnCode;
}
// A wrapper so we do error checking, but don't have to code it every time we call the VxD.
DWORD callWriteEeprom (DWORD addr, unsigned char *blockptr, DWORD size, DWORD comemID)
{
DWORD returnCode;
printf ("Writing EEPROM contents...\n");
returnCode = writeEepromL(addr, blockptr, size, comemID);
printf ("Write EEPROM contents complete\n");
if (returnCode != NO_ERROR)
{
reportErrorCodeL(returnCode, "while writing EEPROM.");
}
return returnCode;
}
#define EEPROMsize 0x78
void zeroEEPROM (DWORD comemID)
{
UCHAR temp[EEPROMsize];
for (int i = 0 ; i < EEPROMsize ; i++)
temp[i] = 0xFF ;
callWriteEeprom (0, &temp[0], EEPROMsize, comemID);
}
DWORD readEepromFunc(DWORD comemID)
{
DWORD returnCode;
UCHAR orig[EEPROMsize];
int errorCnt = 0;
printf ("EEPROM Reads can take up to 10 seconds.\n");
printf ("Please wait for read to complete.\n");
memset(orig, 0x0, sizeof(orig));
returnCode = callReadEeprom (0, &orig[0], EEPROMsize, comemID); // Read original contents.
if (returnCode != NO_ERROR) errorCnt++;
return(errorCnt);
}
void checkEEPROM (DWORD comemID)
{
DWORD returnCode;
UCHAR temp[EEPROMsize];
int nEepromContMatch = 1;
int errorCnt = 0;
DWORD dwReadMem[EEPROMsize];
// check to see if current contents match memory
memset(temp, 0x0, sizeof(temp));
returnCode = callReadEeprom (0, &temp[0], EEPROMsize, comemID); // Read contents.
if( (temp[0x40] != 0x37) || (temp[0x41] != 0x48) || (temp[0x42] != 0x37) || (temp[0x43] != 0x48) )
{ // don't report errors if eeprom was empty
printf("NOTE: EEPROM is Unprogrammed; Memory contents are set to defaults\n");
return;
}
printf("Checking to see if EEPROM contents transferred correctly to memory\n");
readLocal(comemID, dwReadMem, (DWORD)0x4FC, 1);
printf("LocalBusConfig=%02x%02x EEPROM=%02x%02x\n",
*((UCHAR*)dwReadMem+1), *((UCHAR*)dwReadMem+0), temp[0x6D], temp[0x6C]);
if(memcmp(&temp[0x6C], (UCHAR*)dwReadMem, 2))
nEepromContMatch = 0;
// check the stuff that is in config space in memory
PCI_CONFIG_HEADER_0 PciCfg;
returnCode = callGetPCIInfo(&PciCfg, comemID);
printf("VendorID=%04x EEPROM=%02x%02x\n", PciCfg.VendorID, temp[0x45], temp[0x44]);
if(PciCfg.VendorID != (temp[0x45]<<8)+temp[0x44])
nEepromContMatch = 0;
printf("DeviceID=%04x EEPROM=%02x%02x\n", PciCfg.DeviceID, temp[0x47], temp[0x46]);
if(PciCfg.DeviceID != (temp[0x47]<<8)+temp[0x46])
nEepromContMatch = 0;
//printf("VendorID=%04x ~VendorID=%04x\n", PciCfg.VendorID, (USHORT)~PciCfg.VendorID);
//printf("DeviceID=%04x ~DeviceID=%04x\n", PciCfg.DeviceID, (USHORT)~PciCfg.DeviceID);
printf("RevisionID=%02x EEPROM=%02x\n", PciCfg.RevisionID, temp[0x48]);
if(PciCfg.RevisionID != temp[0x48])
nEepromContMatch = 0;
printf("ProgIf=%02x EEPROM=%02x\n", PciCfg.ProgIf, temp[0x49]);
if(PciCfg.ProgIf != temp[0x49])
nEepromContMatch = 0;
printf("SubClass=%02x EEPROM=%02x\n", PciCfg.SubClass, temp[0x4A]);
if(PciCfg.SubClass != temp[0x4A])
nEepromContMatch = 0;
printf("BaseClass=%02x EEPROM=%02x\n", PciCfg.BaseClass, temp[0x4B]);
if(PciCfg.BaseClass != temp[0x4B])
nEepromContMatch = 0;
printf("SubsysVendorID=%04x EEPROM=%02x%02x\n", PciCfg.SubsystemVendorID, temp[0x4D], temp[0x4C]);
if(PciCfg.SubsystemVendorID != (temp[0x4D]<<8)+temp[0x4C])
nEepromContMatch = 0;
printf("SubsysDevID=%04x EEPROM=%02x%02x\n", PciCfg.SubsystemID, temp[0x4F], temp[0x4E]);
if(PciCfg.SubsystemID != (temp[0x4F]<<8)+temp[0x4E])
nEepromContMatch = 0;
printf("InterruptPin=%02x EEPROM=%02x\n", PciCfg.InterruptPin, temp[0x51]);
if(PciCfg.InterruptPin != (temp[0x51] & 0x7)) // Only bits [2-0] are implemented
nEepromContMatch = 0;
printf("MinimumGrant=%02x EEPROM=%02x\n", PciCfg.MinimumGrant, temp[0x52]);
if(PciCfg.MinimumGrant != temp[0x52])
nEepromContMatch = 0;
printf("MaximumLatency=%02x EEPROM=%02x\n", PciCfg.MaximumLatency, temp[0x53]);
if(PciCfg.MaximumLatency != temp[0x53])
nEepromContMatch = 0;
if(nEepromContMatch)
printf("OK: current EEPROM contents match what is in memory\n");
else
{
printf("WARNING: current EEPROM contents DO NOT match what is in memory\n");
printf("One of the following must be true:\n");
printf("1.) EEPROM has been programmed, but the target has not been reset.\n");
printf("2.) Memory initialization from EEPROM contents failed.\n");
}
}
// Init EEPROM
// Warning!!! Vendor ID and Device ID must be set to the defaults, else driver
// will not recognize device.
// Alternately, use your own VendorID and DeviceID, then follow instructions in FAQ
// to force driver to match up with your 'new device'.
void initEEPROM (DWORD comemID, USHORT m_usCBoxLocBusCfg, UCHAR m_ucResHold,
USHORT m_usVenID, USHORT m_usDevID, USHORT m_usSubSysVenID, USHORT m_usSubSysDevID,
USHORT m_usRevisionID, USHORT m_usMaxLat, USHORT m_usMinGnt, UINT m_uiClassCode, USHORT m_usIntPin)
{
DWORD returnCode;
unsigned char temp[EEPROMsize];
unsigned char temp1[EEPROMsize];
int nEepromContMatch = 1;
int errorCnt = 0;
// Default to zero...
for (int i = 0 ; i < EEPROMsize ; i++)
temp[i] = 0 ;
// ... then fill in the exceptions.
temp[0x40] = 0x37; // Pattern required for the 304x to recognize the EEPROM and use it to boot.
temp[0x41] = 0x48;
temp[0x42] = 0x37;
temp[0x43] = 0x48;
// See warning above!!!
// temp[0x44] = 0xbe; // VendorID
// temp[0x45] = 0x12;
temp[0x44] = (UCHAR)m_usVenID; // VendorID
temp[0x45] = m_usVenID >> 8;
// temp[0x46] = 0x42; // DeviceID
// temp[0x47] = 0x30;
temp[0x46] = (UCHAR)m_usDevID; // DeviceID
temp[0x47] = m_usDevID >> 8;;
// temp[0x48] = 0x01; // RevisionID
temp[0x48] = (UCHAR)m_usRevisionID; // RevisionID
// temp[0x49] = 0x01; // Class Code = I2O class, I2O subclass, interface = Interrupt
// temp[0x4a] = 0x00;
// temp[0x4b] = 0x0e;
temp[0x49] = (UCHAR)m_uiClassCode; // Class Code = I2O class, I2O subclass, interface = Interrupt
temp[0x4a] = (UCHAR)(m_uiClassCode >> 8);
temp[0x4b] = (UCHAR)(m_uiClassCode >> 16);
temp[0x4c] = (UCHAR)m_usSubSysVenID; // Subsystem Vendor ID
temp[0x4d] = m_usSubSysVenID >> 8;
temp[0x4e] = (UCHAR)m_usSubSysDevID; // Subsystem ID
temp[0x4f] = m_usSubSysDevID >> 8;
// temp[0x51] = 1; // SHK enable interrupts
temp[0x51] = (UCHAR)m_usIntPin; // Interrupt Pin
temp[0x52] = (UCHAR)m_usMinGnt; // MinGnt
temp[0x53] = (UCHAR)m_usMaxLat; // MaxLat
temp[0x6C] = (UCHAR)m_usCBoxLocBusCfg; // Local Bus Config
temp[0x6D] = m_usCBoxLocBusCfg >> 8;
temp[0x74] = m_ucResHold;
callWriteEeprom (0, &temp[0], EEPROMsize, comemID);
memset(temp1, 0x0, sizeof(temp1));
returnCode = callReadEeprom (0, &temp1[0], EEPROMsize, comemID); // Read contents.
for (i = 0 ; i < EEPROMsize ; i++)
if (temp[i] != temp1[i])
errorCnt++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -