ATA R/W problems.
Posted: Sat Oct 13, 2007 9:25 pm
Hey all,
When I run this code I get 2 page faults. Does somebody see what is wrong with it?
I cannot find the problem here . Maybe someone else does. Thank you for help.
Regards, Stephan J.R. van Schaik.
When I run this code I get 2 page faults. Does somebody see what is wrong with it?
Code: Select all
char* hd_read(unsigned int lba) {
unsigned char buffer[512] = {0};
char* result;
outportb(control + 1, 0x00);
outportb(control + 2, 0x01);
outportb(control + 3, (unsigned char)lba);
outportb(control + 4, (unsigned char)(lba >> 8));
outportb(control + 5, (unsigned char)(lba >> 16));
outportb(control + 6, 0xE0 | (0xA0 << 4) | ((lba >> 24) & 0x0F));
outportb(control + 7, 0x20);
while (!(inportb(control + 7) & 0x8));
int idx = 0;
unsigned short tmpword;
while (idx < 256) {
tmpword = inportw(control);
buffer[idx * 2] = (unsigned char)tmpword;
buffer[idx * 2 + 1] = (unsigned char)(tmpword >> 8);
idx++;
}
result = (char *)buffer;
return result;
}
void hd_write(unsigned int lba, char buffer[512]) {
outportb(control + 1, 0x00);
outportb(control + 2, 0x01);
outportb(control + 3, (unsigned char)lba);
outportb(control + 4, (unsigned char)(lba >> 8));
outportb(control + 5, (unsigned char)(lba >> 16));
outportb(control + 6, 0xE0 | (0xA0 << 4) | ((lba >> 24) & 0x0F));
outportb(control + 7, 0x30);
while (!(inportb(control + 7) & 0x8));
int idx = 0;
unsigned short tmpword;
while (idx < 256) {
tmpword = buffer[8 + idx * 2] | (buffer[8 + idx * 2 + 1] << 8);
outportw(control, tmpword);
idx++;
}
}
Code: Select all
hd_write(2, "This is a test.");
kprintf("%s", hd_read(2));
Regards, Stephan J.R. van Schaik.