void Init_IDE() { int errorCode; while (In_Byte(IDE_STATUS_REGISTER) != 0x50); if (ideDebug) Print("About to run drive Diagnosis\n"); Out_Byte(IDE_COMMAND_REGISTER, IDE_COMMAND_DIAGNOSTIC); while (!(In_Byte(IDE_STATUS_REGISTER) & IDE_STATUS_DRIVE_READY)); errorCode = In_Byte(IDE_ERROR_REGISTER); readDriveConfig(0); if (errorCode & 0x80) { numDrives = 1; } else { numDrives = 2; readDriveConfig(1); } }
void Init_IDE(void) { int errorCode; Print("Initializing IDE controller...\n"); /* Reset the controller and drives */ Out_Byte(IDE_DEVICE_CONTROL_REGISTER, IDE_DCR_NOINTERRUPT | IDE_DCR_RESET); Micro_Delay(100); Out_Byte(IDE_DEVICE_CONTROL_REGISTER, IDE_DCR_NOINTERRUPT); /* * FIXME: This code doesn't work on Bochs 2.0. * while ((In_Byte(IDE_STATUS_REGISTER) & IDE_STATUS_DRIVE_READY) == 0) * ; */ /* This code does work on Bochs 2.0. */ while (In_Byte(IDE_STATUS_REGISTER) & IDE_STATUS_DRIVE_BUSY) ; if(ideDebug) Print("About to run drive Diagnosis\n"); Out_Byte(IDE_COMMAND_REGISTER, IDE_COMMAND_DIAGNOSTIC); while (In_Byte(IDE_STATUS_REGISTER) & IDE_STATUS_DRIVE_BUSY) ; errorCode = In_Byte(IDE_ERROR_REGISTER); if(ideDebug > 1) Print("ide: ide error register = %x\n", errorCode); /* Probe and register drives */ int i; for(i = 0; i < IDE_MAX_DRIVES; i++) { if(readDriveConfig(i) == 0) ++numDrives; } if(ideDebug) Print("Found %d IDE drives\n", numDrives); /* Start request thread */ if(numDrives > 0) Start_Kernel_Thread(IDE_Request_Thread, 0, PRIORITY_NORMAL, true, "{IDE}"); }