troubles with reading HDD using ports

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Eugene

troubles with reading HDD using ports

Post by Eugene »

char *read_dev() {
    int cnt = 0;

    while((in( CMD_PORT ) & 0xc0) != READY_STAT);
    
    bzero ( buffer, SECTOR_SIZE);
    out(DRV_AND_HEAD_PORT,0xa0);
    wait();
    out(SECTOR_COUNT_PORT,0x01);
    wait();
    out(SECTOR_NUM_PORT,0x01);
    wait();
    out(CYL_LOW_PORT,0x00);
    wait();
    out(CYL_HIGH_PORT,0x00);
    wait();
    out(CMD_PORT,0x20);
    asm(""::"c"(SECTOR_IN_WORDS),"d"(DATA_PORT),"D"(buffer));
    asm("rep insw");

return buffer;
}

i use this code to read MBR from my ide hdd. when i run this code under bochs - everything is good, but in real - i get random data time from time in "buffer".


where is problem?
ps: i use 0xbf during reprogramming PIC and empty handler for hdd IRQ. i thing this doesn't matter for my problem.

if possible - answer to asm(dog)uinc.ru
Post Reply