i have been trying to create a disk partition for my mini operating system I don't know what and where is the problem .I couldn’t get it writing and reading hardisk partition information ...i am using GRUB for loading my OS is there some thing which is connected with GRUB that protect me not to write partition information on the first sector of the hardisk ,and also do i need to initiate IRQ request for reading and writing a hardisk how can i do that...
Here is a function that read and writes to/from the hardisk
void hd_rw(unsigned int lba, unsigned int com, unsigned int sects_to_access, void *buf) {
unsigned int cyl = lba/(HD0.head * HD0.sect);
unsigned int head = (lba%(HD0.head*HD0.sect))/HD0.sect;
unsigned int sect = (lba%(HD0.head*HD0.sect))%HD0.sect+1;
while ((inb(HD_PORT_STATUS)&0xc0)!=0x40);
outb(0x00,HD_PORT_ERROR);
outb(sects_to_access, HD_PORT_SECT_COUNT);
outb(sect, HD_PORT_SECT_NUM);
outb(cyl>>8, HD_PORT_CYL_LOW);
outb(cyl>>16, HD_PORT_CYL_HIGH);
outb(0xE0 | (0xA0 << 4) | ((head >> 24) & 0x0F),HD_PORT_DRV_HEAD);
outb(com,HD_PORT_COMMAND);
while (!(inb(HD_PORT_STATUS) & 0x08)) {}
if (com == HD_READ){
insl(HD_PORT_DATA, buf, sects_to_access<<7);
puts("read\n");
}
else if (com == HD_WRITE)
{
outsl(buf, sects_to_access<<7,HD_PORT_DATA);
puts("written\n");
}
}
error on hardisk read and write functions
Please read the forum rules:
http://www.osdev.org/phpBB2/viewtopic.php?t=16944
http://www.osdev.org/phpBB2/viewtopic.php?t=16944
wonde, there are many errors in your "driver" code. The way you output the cylinder high and low bytes is very wrong. The byte you are sending to select the head is very wrong. You are not stopping to read the BSY and DRQ flags between each sector of data -- this is very wrong.
I think you should start by using the LBA function, rather than the CHS function, because your CHS calculations look bad. Please begin by reading the wiki article on using ATA:
http://www.osdev.org/wiki/ATA_PIO_Mode
I think you should start by using the LBA function, rather than the CHS function, because your CHS calculations look bad. Please begin by reading the wiki article on using ATA:
http://www.osdev.org/wiki/ATA_PIO_Mode