Read from disk - myOS
Posted: Sat Mar 16, 2019 2:08 pm
this is my disk driver code:
During my OS execution there is sometimes when my OS freeze becouse of reading some sector from disk...
How can i fix this probelm ? I use this function in my FS FAT32
Code: Select all
// function read data from disk info buffer and return if succeed
void read28(unsigned int lba, char* buffer, unsigned sector_count)
{
unsigned int offset = 0;
unsigned int i = 0;
// prepare the hard disk controller for reading (by specefic protocol - taken from ATA PIO Mode osDev)
out_byte(ATA_ERR_INFO_PORT, 0x00);
out_byte(ATA_SECTOR_COUNT_REGISTER_PORT, (unsigned char)sector_count); // sector count
out_byte(ATA_LBA_LOW_REGISTER_PORT, (unsigned char)lba); // Send the low 8 bits of the LBA
out_byte(ATA_LBA_MID_REGISTER_PORT, (unsigned char)(lba>>8)); // Send the mid 8 bits of the LBA
out_byte(ATA_LBA_HIGH_REGISTER_PORT, (unsigned char)(lba>>16)); // Send the high 8 bits of the LBA
out_byte(ATA_DRIVE_REGISTER_PORT, 0xE0 | 0x40 | ((lba>>24) & 0x0F)); // master drive + lba + high lba bits
out_byte(ATA_COMMAND_REGISTER_PORT, ATA_READ); // read command
// for every sector - read into buffer
while(sector_count--) {
ata_wait_for_rdy(ATA_REGULAR_STATUS_REGISTER_PORT); // Spun up
ata_wait_for_drq(ATA_REGULAR_STATUS_REGISTER_PORT); // Ready for transfer
for(i = 0;i < 256;i++)
{
// write data from disk into buffer
*( (unsigned short *)buffer + offset + i ) = in_word(ATA_DATA_REGISTER_PORT);
}
offset += 256;
}
}
During my OS execution there is sometimes when my OS freeze becouse of reading some sector from disk...
How can i fix this probelm ? I use this function in my FS FAT32