Code: Select all
void HDD_read_sector(long long addr, unsigned char drive, unsigned char* buffer){
//Send two NULL(0x00)bytes to port 0x1F1
outb(0x1F1, 0x00);
outb(0x1F2, 0x00);
outb(0x1F3, (unsigned char)(addr >> 24));
outb(0x1F4, (unsigned char)(addr >> 32));
outb(0x1F5, (unsigned char)(addr >> 40));
outb(0x1F1, 0x00);
outb(0x1F2, 0x01);
outb(0x1F3, (unsigned char)addr);
outb(0x1F4, (unsigned char)(addr >> 8));
outb(0x1F5, (unsigned char)(addr >> 16));
outb(0x1F6, 0x40 | (drive << 4));
outb(0x1F7, 0x24);
//Wait until the drive is ready
unsigned short tmpword;
int idx = 0;
while(!(inb(0x1F7) & 0x08)){k_xy_printf("R", 24, 0, 0x17);}
for(idx = 0; idx < 256; idx++){
tmpword = inw(0x1F0);
buffer[idx * 2] = (unsigned char)tmpword;
buffer[idx * 2 + 1] = (unsigned char)(tmpword >> 8);
}
}
void HDD_write_sector(long long addr, unsigned char drive, unsigned char* buffer){
//Send two NULL(0x00)bytes to port 0x1F1
outb(0x1F1, 0x00);
outb(0x1F2, 0x00);
outb(0x1F3, (unsigned char)(addr >> 24));
outb(0x1F4, (unsigned char)(addr >> 32));
outb(0x1F5, (unsigned char)(addr >> 40));
outb(0x1F1, 0x00);
outb(0x1F2, 0x01);
outb(0x1F3, (unsigned char)addr);
outb(0x1F4, (unsigned char)(addr >> 8));
outb(0x1F5, (unsigned char)(addr >> 16));
outb(0x1F6, 0x40 | (drive << 4));
outb(0x1F7, 0x24);
//Wait until the drive is ready
unsigned short tmpword;
int idx = 0;
while(!(inb(0x1F7) & 0x08)){k_xy_printf("W", 24, 0, 0x17);}
for (idx = 0; idx < 256; idx++){
tmpword = buffer[8 + idx * 2] | (buffer[8 + idx * 2 + 1] << 8);
outw(0x1F0, tmpword);
}
}
P.D: Im reading this.