Page 1 of 1

troubles with reading HDD using ports

Posted: Fri Jul 26, 2002 11:00 pm
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