📄 sim_dev.c
字号:
{
simFileIO(pSimSock, SIM_ITEM_DEV_SIZE_IN_SECTORS, i, FALSE, (void*)(&pSim[i].dwDevSizeInSectors));
simFileIO(pSimSock, SIM_ITEM_TOTAL_DEV_SIZE_IN_SECTORS, i, FALSE, (void*)(&pSim[i].dwTotalDevSizeInSectors));
simFileIO(pSimSock, SIM_ITEM_IPL_MODE, i, FALSE, (void*)(&pSim[i].wIPLMode));
simFileIO(pSimSock, SIM_ITEM_ETFFS_SIZE, i, FALSE, (void*)(&pSim[i].dwEtffsSize));
simFileIO(pSimSock, SIM_ITEM_ETFFS_CODE, i, FALSE, (void*)(&pSim[i].bEtffsCode));
simFileIO(pSimSock, SIM_ITEM_DRIVE_PARAMS, i, FALSE, (void*)(&pSim[i].driveParameters));
simFileIO(pSimSock, SIM_ITEM_DEV_INFO, i, FALSE, (void*)(&diskOnChipDeviceInfo[i]));
simFileIO(pSimSock, SIM_ITEM_PARTITIONS, i, FALSE, (void*)(&pSim[i].partitions));
simFileIO(pSimSock, SIM_ITEM_DISK_ATTRIBUTES, i, FALSE, (void*)(&pSim[i].diskAttributes));
}
}
#endif /*DOCH_MEMMAP_FILE*/
}/* new device created */
else /* get device info from file */
{
pSimSock->pSimFile = fopen( (char*) bSimFileName, "r+b");
if( pSimSock->pSimFile==NULL )
return DOCH_AdapterNotFound;
simFileIO(pSimSock, SIM_ITEM_ID_STRING, 0, TRUE, (void*)tempBuf);
/* read slave present indication */
simFileIO(pSimSock, SIM_ITEM_SLAVE_PRESENT, 0, TRUE, (void*)&(pSimSock->bSlavePresent));
/* read device configuration registers */
simFileIO(pSimSock, SIM_ITEM_CONFIG_REGS, 0, TRUE, (void*)&(pSimSock->config_regs));
if( pSimSock->bSlavePresent==FALSE )
pSim[1].dwDevSizeInSectors = 0;
/* read both devices */
for( bDev=0; bDev<ATA_MAX_NUM_OF_DEVICES; pSimSock->bSlavePresent==FALSE ? bDev+=2 : bDev++ )
{
#ifdef DOCH_MEMMAP_FILE
if(bDev == 1)
{
status = (DOCH_Error)fseek( simSocket.pSimFile,
sizeof(SIMULTOR_IDENTIFY_STRING) + sizeof(pSimSock->bSlavePresent) + sizeof(pSimSock->config_regs) + gDev0SimDeviceSizeOnFile,
SEEK_SET);
if(status != DOCH_OK)
return DOCH_GeneralFailure;
}
#endif /*DOCH_MEMMAP_FILE*/
/* read simulated device length */
simFileIO(pSimSock, SIM_ITEM_DEV_SIZE_IN_SECTORS, bDev, TRUE, (void*)(&pSim[bDev].dwDevSizeInSectors));
/*Update size on file*/
if(bDev==0)
gDev0SimDeviceSizeOnFile = (gSimDeviceSizeOnFile + (pSim[0].dwDevSizeInSectors << DOCH_SECTOR_SIZE_BITS));
else
gDev1SimDeviceSizeOnFile = (gSimDeviceSizeOnFile + (pSim[1].dwDevSizeInSectors << DOCH_SECTOR_SIZE_BITS));
simFileIO(pSimSock, SIM_ITEM_TOTAL_DEV_SIZE_IN_SECTORS, bDev, TRUE, (void*)(&pSim[bDev].dwTotalDevSizeInSectors));
/* read IPL mode */
simFileIO(pSimSock, SIM_ITEM_IPL_MODE, bDev, TRUE, (void*)(&pSim[bDev].wIPLMode));
/* read ETFFS Size */
fread( (void*)&(pSim[bDev].dwXIPMaxSize), 1, sizeof(pSim[bDev].dwXIPMaxSize), pSimSock->pSimFile );
/* read ETFFS Size */
simFileIO(pSimSock, SIM_ITEM_ETFFS_SIZE, bDev, TRUE, (void*)(&pSim[bDev].dwEtffsSize));
/* read ETFFS Code */
simFileIO(pSimSock, SIM_ITEM_ETFFS_CODE, bDev, TRUE, (void*)(&pSim[bDev].bEtffsCode));
/* read drive parameters */
simFileIO(pSimSock, SIM_ITEM_DRIVE_PARAMS, bDev, TRUE, (void*)(&pSim[bDev].driveParameters));
/* read device info */
simFileIO(pSimSock, SIM_ITEM_DEV_INFO, bDev, TRUE, (void*)(&diskOnChipDeviceInfo[bDev]));
/* If requested size is different from read size (unformatted capacity)
jump to "createNewSimFile"*/
if( (dwMasterSizeInSectors!=0)&&/*user asked for specific size*/
(((bDev == 0) && (diskOnChipDeviceInfo[bDev].dwUnformattedCapacity != dwMasterSizeInSectors)) ||
((bDev == 1) && (diskOnChipDeviceInfo[bDev].dwUnformattedCapacity != dwSlaveSizeInSectors))))
goto createNewSimFile;
/* read partitions parameters */
simFileIO(pSimSock, SIM_ITEM_PARTITIONS, bDev, TRUE, (void*)(&pSim[bDev].partitions));
tempDevSelect = simSocket.selDevNum;
simSocket.selDevNum = bDev;
unAuthenticatePartitions(&pSim[bDev]);
simSocket.selDevNum = tempDevSelect;
/* read disk attributes */
simFileIO(pSimSock, SIM_ITEM_DISK_ATTRIBUTES, bDev, TRUE, (void*)(&pSim[bDev].diskAttributes));
#ifdef DOCH_MEMMAP_FILE
status = DOCH_OK;
#else /*DOCH_MEMMAP_FILE*/
/* allocate storage buffer */
pSim[bDev].bStorage = (FLByte*)DOCH_MALLOC(pSim[bDev].dwDevSizeInSectors << DOCH_SECTOR_SIZE_BITS);
if( pSim[bDev].bStorage == NULL )
{
status = DOCH_NotEnoughMemory;
}
else /* allocation OK */
{
/* read data */
szReadLen = fread( (void*)(pSim[bDev].bStorage), 1,
(pSim[bDev].dwDevSizeInSectors << DOCH_SECTOR_SIZE_BITS), pSimSock->pSimFile );
if( szReadLen==(pSim[bDev].dwDevSizeInSectors << DOCH_SECTOR_SIZE_BITS) )
{
if( (bDev==1) || (pSim[1].dwDevSizeInSectors==0) )
status = DOCH_OK; /* every things OK */
}
else
{
DOCH_FREE( pSim[bDev].bStorage ); /* free allocated buffer */
pSim[bDev].bStorage = NULL;
}
}
#endif/*DOCH_MEMMAP_FILE*/
}/* for master and slave devices */
initVarious(FALSE);
}
if( status!=DOCH_OK )
{
/* allocated buffer for master device may still valid if failed happened on slave device */
if( pSim[0].bStorage != NULL )
DOCH_FREE( pSim[bDev].bStorage );
fclose( pSimSock->pSimFile );
}
else
{
/* initVarious();*/
/* init registers to the regular state after loading */
pSimSock->out_regs.bStatusCommand |= DOCH_READY;
pSimSock->out_regs.bAltStatusControl = pSimSock->out_regs.bStatusCommand;
}
#ifdef DOCH_MEMMAP_FILE
fclose( pSimSock->pSimFile );
pSimSock->pSimFile = fopen( (char*) pSimFileName, "r+b");
if(pSimSock->pSimFile == NULL)
return DOCH_DriveNotAvailable;
#endif /*DOCH_MEMMAP_FILE*/
gDev0SimDeviceSizeOnFile = (gSimDeviceSizeOnFile + (pSim[0].dwDevSizeInSectors << DOCH_SECTOR_SIZE_BITS));
gDev1SimDeviceSizeOnFile = (gSimDeviceSizeOnFile + (pSim[1].dwDevSizeInSectors << DOCH_SECTOR_SIZE_BITS));
return status;
}/*SimRegDeviceFromFile()*/
#endif /*DOCH_RAM_SIMULATION*/
/*Retrieve pointer to beginning of actual partition in storage*/
/*===========================================================*/
void* choosePartition(DOCH_SimSocket* simSocket, FLByte partNum)
{
DOCH_SimDevice* simDev = getSimDev(simSocket->selDevNum);
FLSNative offset = simDev->partitions[partNum].dwOffset;
return ((void*)(simDev->bStorage + offset));
}
/*Set initial values for ATA out registers*/
/*========================================*/
FLSNative initSimRegisters( void )
{
/*ATA registers*/
simSocket.out_regs.bStatusCommand |= DOCH_READY;
simSocket.out_regs.bAltStatusControl = simSocket.out_regs.bStatusCommand;
/*Host configuration registers*/
simSocket.config_regs.wChipID1 = DOCH_SIM_CHIPID1;
simSocket.config_regs.wChipID2 = DOCH_SIM_CHIPID2;
simSocket.config_regs.wIPLCtrl = DOCH_IPL_WRITE_READY;
simSocket.xferMode = DOCH_DATA_MODE_SINGLE;
#ifdef DOCH_MEMMAP_FILE
{
if(simFileIO(&simSocket, SIM_ITEM_CONFIG_REGS, 0, FALSE, (void*)&(simSocket.config_regs)))
return -1;
}
#endif /*DOCH_MEMMAP_FILE*/
return DOCH_OK;
}
static void simBuildGeometry(FLDword capacity, FLDword FAR2 *cylinders,
FLDword FAR2 *heads, FLDword FAR2 *sectors)
{
FLDword temp;
FLDword orgCapacity = capacity;
START_BUILD_GEOMETRY_ROUTINE:
*cylinders = 1024; /* Set number of cylinders to max value */
*heads = 16L; /* Max out number of heads */
temp = (*cylinders) * (*heads); /* Compute divisor for heads */
*sectors = capacity / temp; /* Compute value for sectors per track */
while (*sectors > 0x3f ){ /* While number of sectors too big */
*heads *= 2; /* use one more head */
temp = (*cylinders) * (*heads); /* Recompute divisor for heads */
*sectors = capacity / temp; /* Recompute sectors per track */
}
if (capacity % temp) { /* If no remainder, done! */
(*sectors)++; /* Else, increment number of sectors */
temp = (*cylinders) * (*sectors); /* Compute divisor for heads */
*heads = capacity / temp; /* Compute value for heads */
if (capacity % temp) { /* If no remainder, done! */
(*heads)++; /* Else, increment number of heads */
temp = (*heads) * (*sectors); /* Compute divisor for cylinders */
*cylinders = (FLDword)(capacity / temp); /* Compute number of cylinders */
}
}
/* Make sure some free sectors are left between C*H*S and TL sectors */
if(orgCapacity == (*sectors) * (*heads) * (*cylinders))
{
capacity--;
goto START_BUILD_GEOMETRY_ROUTINE;
}
}
/*Initialize IDENTIFY COMMAND data structure*/
/*==========================================*/
FLSNative initDriveParameters(FLByte numOfDevices)
{
register int i;
DOCH_SimDevice* simDev;
FLSByte serialNum[] = {'N','o',' ','S','e','r','i','l',' ','N','u','m', '\0'};
FLSByte firmwareRev[] = {'S','i','m', '\0'};
FLSByte modelNum[] = {'M','-','S','i','s','t','e','m','s',' ','S','i','m', '\0'};
FLNative simCapcaityInSectors = 0;
FLDword currentCapacityInSectors = 0;
FLDword c,h,s;
tffsset(&simSocket.device[0].driveParameters, 0, sizeof(simDev->driveParameters));
tffsset(&simSocket.device[1].driveParameters, 0, sizeof(simDev->driveParameters));
for(i=0; i<numOfDevices; i++)
{
simDev = &simSocket.device[i];
/*Capcaity*/
/*--------*/
#ifdef DOCH_RAM_SIMULATION
simCapcaityInSectors = (FLDword)((DOCH_SIM_CAPACITY >> DOCH_SECTOR_SIZE_BITS) * DOCH_SIM_CAPACITY_PERCENTAGE);
#endif /* DOCH_RAM_SIMULATION */
#ifdef DOCH_FILE_SIMULATION
simCapcaityInSectors = dwSimLength[i];
#endif /*DOCH_FILE_SIMULATION*/
simDev->driveParameters.wTotalNumberOfSectorsLow = (FLWord)(simCapcaityInSectors);
simDev->driveParameters.wTotalNumberOfSectorsHigh = (simCapcaityInSectors >> 16);
/*CHS*/
/*---*/
simBuildGeometry( simCapcaityInSectors,
(FLDword FAR2 *)&(c),
(FLDword FAR2 *)&(h),
(FLDword FAR2 *)&(s));
currentCapacityInSectors = c*h*s;
simDev->driveParameters.wDefaultNumberOfCylinders = (FLWord)c;
simDev->driveParameters.wCurrentNumberOfCylinders = simDev->driveParameters.wDefaultNumberOfCylinders;
simDev->driveParameters.wCurrentNumberOfHeads = (FLWord)h;
simDev->driveParameters.wCurrentSectorPerTrack = (FLWord)s;
simDev->driveParameters.wCurrentCapacityInSectorsLow = (FLWord)currentCapacityInSectors;
simDev->driveParameters.wCurrentCapacityInSectorsHigh = (FLWord)(currentCapacityInSectors>>16);
simDev->driveParameters.wDefaultSectorsPerTrack = DOCH_SIM_DEFAULT_SECTORS_PER_TRACK;
simDev->driveParameters.wDefaultNumberOfHeads = DOCH_SIM_DEFAULT_NUM_OF_HEADS;
/*Security*/
/*--------*/
simDev->driveParameters.wSecurityStatus = SECURITY_SUPPORTED |
SECURITY_ENCHANCED_ERASE_SUPPORTED;
/*MULTI*/
/*-----*/
simDev->driveParameters.bMultipleSectorCurrentNumber = 1;
simDev->driveParameters.bMaxSectorsPerMulti = 1;
simDev->driveParameters.bMultipleSectorSettingValid = 0;
/*General Configuration*/
/*---------------------*/
simDev->driveParameters.wGeneralConfiguration = GENERAL_CONFIG_NON_REMOVABLE_DRIVE;
simDev->driveParameters.wSpecificConfiguration = 0xC837;
/*Capabilities*/
/*------------*/
simDev->driveParameters.wCapabilities = CAPABILITY_MUST | /*49*/
CAPABILITY_IORDY_SUPPORTED |
CAPABILITY_STANDBY_TIMER_AS_IN_STANDARD |
CAPABILITY_IORDY_CAN_BE_DISABLED;
simDev->driveParameters.wCapabilities2 = CAPABILITY2_MUST; /*ata-4*/
/*DMA*/
/*---*/
simDev->driveParameters.bMultiwordDMASelected = 0;
simDev->driveParameters.bMultiwordDMASupported = 0;
simDev->driveParameters.wMinDMACycleTimePerWord = 0;
simDev->driveParameters.wRecommndedMinDMACycleTimePerWord = 0;
/*PIO*/
/*---*/
simDev->driveParameters.bPIOTransferTiming = 2;
simDev->driveParameters.bAdvancedPIOsupported = ADVANCED_PIO_3_SUPPORTED | ADVANCED_PIO_4_SUPPORTED;
simDev->driveParameters.wMinPIOCycleTimeWithoutFlowControl = 120;
simDev->driveParameters.wMinPIOCycleTimeWithIORDY = 240;
/*Supported commands*/
/*------------------*/
simDev->driveParameters.wCommandSetsupported1 = SUPPORTS1_SMART |
SUPPORTS1_SECURITY |
SUPPORTS1_POWER_MANAGEMENT |
SUPPORTS1_WRITE_CACHE |
/*SUPPORTS1_HOST_PROTECTED_AREA_FEATURE | - not yet*/
/*SUPPORTS1_LOOK_AHEAD | - we could support it in SET FEATURES*/
SUPPORTS1_WRITE_BUFFER |
SUPPORTS1_READ_BUFFER |
SUPPORTS1_NOP;
simDev->driveParameters.wCommandSetsupported2 = SUPPORTS2_MUST | SUPPORTS2_DOWNLOAD_MICROCODE;
simDev->driveParameters.wCommandSetFeatureExtension = CMDSET_EXTENSION_MUST; /*84 ata-4*/
simDev->driveParameters.wCommandSetFeatureEnabled1 = simDev->driveParameters.wCommandSetsupported1; /*ata-4*/
simDev->driveParameters.wCommandSetFeatureEnabled2 = SUPPORTS2_DOWNLOAD_MICROCODE; /*86 ata-4*/
simDev->driveParameters.wCommandSetFeatureDefault = CMDSET_EXTENSION_MUST ; /*ata-4*/
simDev->driveParameters.wWordSupported = FIELDS54_58_VALID | FIELDS64_70_VALID;
/*Version*/
/*-------*/
simDev->driveParameters.wMajorVersionNumber = SUPPORTS_ATA_2 | SUPPORTS_ATA_3 | SUPPORTS_ATA_4;
simDev->driveParameters.wMinorVersionNumber = ATA_ATAPI4_PUBLISHED;
/*Misc*/
/*----*/
tffscpy(&simDev->driveParameters.bSerialNumber[0], serialNum, sizeof(serialNum));
tffscpy(&simDev->driveParameters.bFirmwareRevision[0], firmwareRev, sizeof(firmwareRev));
tffscpy(&simDev->driveParameters.bModelNumber[0], modelNum, sizeof(modelNum));
/* set default IPL mode */
simDev->wIPLMode = (DOCH_IPL_MODE_ADDRESS_SHIFT_IN_AFFECT | DOCH_IPL_MODE_8KB_WINDOW | DOCH_IPL_MODE_PAGED_RAM);
simDev->wXIPTestMode = 0;
simDev->dwXIPMaxSize = 0;
simDev->dwEtffsSize = 0;
}
#ifdef DOCH_MEMMAP_FILE
for(i=0; i<numOfDevices; i++)
{
simDev = &simSocket.device[i];
if(simFileIO(&simSocket, SIM_ITEM_DRIVE_PARAMS, (FLByte)i, FALSE, (void*)&(simDev->driveParameters)))
return -1;
}
#endif /*DOCH_MEMMAP_FILE*/
return DOCH_OK;
}
FLSNative initVarious(FLBoolean fNewDev)
{
FLByte bPart, bDev;
DOCH_SimDevice* simDev;
FLByte digits = 0;
FLDword totalCapacity;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -