Page 2 of 3
Re:Hard Disk query
Posted: Sun Jan 25, 2004 3:37 pm
by Pype.Clicker
Neo wrote:
just wanted to know does the Execeute Diagnostic fire an IRQ?
according to the above-providen link, section 9.10 (execute device diagnostic protocol), an IRQ will be issued if the nIRQ bit is cleared in the controller registers. Otherwise, you should wait 2ms and then check the status ...
Re:Hard Disk query
Posted: Sun Jan 25, 2004 5:47 pm
by Perica
..
Re:Hard Disk query
Posted: Sun Jan 25, 2004 6:04 pm
by Tim
ATA and ATAPI are the official names for what started as IDE and Enhanced IDE. ATA generally refers to hard disks, while ATAPI refers to CD and DVD readers and writers.
http://www.t13.org/ is the official web site of the T13 committee, who decide what goes into each new ATA/ATAPI spec.
http://www.ata-atapi.com/ is a useful site with information on how to actually program these devices, with some useful source code and discussion that goes deeper than what's in the spec.
Re:Hard Disk query
Posted: Sun Feb 01, 2004 11:28 pm
by Neo
just thought i'd add this piece of info. I had cleared nIEN(enabled HDC ints) before the "Exceute Diagnostic" command but received no INT from the HDC. After reading the doc sec 9.10 i just added a delay(just to test) and to my surprise the ISR was called. Now I'm not sure why this happened i think it was because i had called another "Identify Drive" function right after the "Execute Diagnostic" and the HDC had to respond to this before the completion of the "Execute Diagnostic" function. SO if this is right I hope it helps anyone programming the HDC.
btw the "identify drive" caused an older 20GB drive(old BIOS also) to "hang" the system when i tried it out. Any comments on this?
Also how does Linux use the HDD's? LBA or CHS mode?
Re:Hard Disk query
Posted: Mon Feb 02, 2004 4:37 am
by ASHLEY4
Hi
The delay is part of the ATA spec. I am also doing a ATA/ATAPI driver, i have found many quercks with differant sys, for instance i have about 10 pc's all differant specs, i have written a unit that detects the address of all the hard drives and the cd drives on the pc, this code worked fine on 9 of them, but faild to detect a master cd drive on the 10th one, the only way to over come this problem is to put quite a large delay, i dont know why this is differant from the others.
Another problem was that most of the code i had writen was writen as small com files which could be tested from a com file boot loader , i got them all working, but had to do a lot of work to get them working in pmode :'(
Some of the code is run at bootup other when in pmode.
PS: One of the things to make sure of is in your IRQ code make sure you cancel the IRQ, there are two codes for this one used for the lower IRQs keyboard ect and one for the higher make sure that you use the higher one .
ASHLEY4
Re:Hard Disk query
Posted: Mon Feb 02, 2004 6:30 am
by Pype.Clicker
Neo wrote:
After reading the doc sec 9.10 i just added a delay(just to test) and to my surprise the ISR was called.
what exactly do you mean by "adding a delay" ? You're expected to *wait* for the interrupt anyway ...
Now I'm not sure why this happened i think it was because i had called another "Identify Drive" function right after the "Execute Diagnostic" and the HDC had to respond to this before the completion of the "Execute Diagnostic" function.
Are you issueing two commands (ExecDiag and then IdDrive) one after the other and expecting the disk to reply to them in sequence ? this is not the way hardware usually works (well, not with ATA, at least). You should not issue a new command before the previous command completed. The exception is if you send a RESET command between the two, in which case you shouldn't expect to get the result of the first one ...
Also how does Linux use the HDD's? LBA or CHS mode?
afaik, it uses LBA, unless the drive reported no LBA support ...
Re:Hard Disk query
Posted: Mon Feb 02, 2004 1:18 pm
by Neo
PS: One of the things to make sure of is in your IRQ code make sure you cancel the IRQ, there are two codes for this one used for the lower IRQs keyboard ect and one for the higher make sure that you use the higher one .
are you referring to the PICs? and sending the EOI to them? i am doing both.
what exactly do you mean by "adding a delay" ? You're expected to *wait* for the interrupt anyway ...
@Pype I was waiting for the interrupt but it was never called. thats when i tried the delay and got it working? I cant understand why the handler wasn't called beofre that?
Re:Hard Disk query
Posted: Mon Feb 02, 2004 3:33 pm
by Pype.Clicker
just to be sure ... did you unmasked the ATA interrupt properly on the PIC (iirc, you should clear the bit 2 of the master PIC's mask to receive the cascaded interrupts and the bit 6 of the slave PIC's mask, as primary ATA controller is bound to IRQ 14) ?
Re:Hard Disk query
Posted: Fri Feb 06, 2004 12:53 pm
by Neo
I just thought i'd post my code here to see if you can find anything wrong with it. The variable hdc_flag is changed in the Handler to NULL but the handler never gets called after this command so the function loops infinitely.
Here's the code
Code: Select all
void execute_diagnostic(void)
{
BUSY_wait();
outb(HDD_BASE+DRV_HEAD,0xA0);
hdc_flag= HDC_DIAGNOSE;
EnableHDC_int();
DRDY_wait();
outb(HDD_BASE+CMD,EXEC_DIAGNOSTIC);
while(hdc_flag!=NULL);
}
the BUSY_wait() ,EnableHDC_int() and DRDY_wait() functions are here
Code: Select all
_BUSY_wait:
push dx
push ax
mov dx,HDD_BASE+STATUS
.cont: in al,dx
bt ax,7
jc .cont
pop ax
pop dx
retn
Code: Select all
_EnableHDC_int:
push dx
push ax
mov dx,CTRL_REG
in al,dx
and al,0xFD
out dx,al
pop ax
pop dx
retn
Code: Select all
_DRDY_wait:
push dx
push ax
mov dx,HDD_BASE+STATUS
.cont in al,dx
bt ax,6
jnc .cont
pop ax
pop dx
retn
@Pype btw i've unmasked all IRQ's ie sent 0 to both MASTER and SLAVE.
Re:Hard Disk query
Posted: Sat Feb 07, 2004 11:09 am
by Neo
I just realised that this works on the real hardware but not in BOCHS now i'm wondering is there some bug in BOCHS? Does anyone here have any experience with ATA code that runs fine in BOCHS or do you use something else?
btw I use BOCHS 2.0.2 and was wondering if you have to give it any additional parameters right now i only use this
Code: Select all
ata0-master: type=disk,path="c.img", cylinders=20, heads=16, spt=63
ata0-slave: type=disk,path="hdd.img", cylinders=20, heads=16, spt=63
Re:Hard Disk query
Posted: Sun Feb 08, 2004 9:25 am
by Pype.Clicker
i have faced some strange behaviours with BOCHS and ATA drives, indeed, especially when no ATA0 controller were defined. make sure you read properly the configuration files for *your* version of BOCHS for this stuff seems to be subject to frequent changes ...
Re:Hard Disk query
Posted: Sun Feb 08, 2004 11:19 am
by Neo
The BOCHS line i posted above are from my BOCHS 2.0.2 manual. And still they dont work. Well I'm going to write this error off as a BOCHS bug.
btw any BOCHS devers here please take note of this.
Re:Hard Disk query
Posted: Tue Feb 17, 2004 9:59 am
by Pype.Clicker
any news ? did it finally work ?
Re:Hard Disk query
Posted: Tue Feb 17, 2004 11:20 am
by Neo
well i'm sort of doing somethin else at this time :-\ and have kept this aside. But yeah the thing works on real hardware and not in BOCHS of course i was a firm believer in the fact that if my program was 100% right in BOCHS then it would run on most hardware but after this well...... :-\
Re:Hard Disk query
Posted: Wed Feb 18, 2004 2:12 am
by Pype.Clicker
maybe you could drop us an image to test in the 'OS test' section ... i have a small laptop that could be used to know if your driver is 100% on that hardware too (and i'm sure other people also have ;:)