Page 1 of 1

[SOLVED]Read CD-ROM by ATAPI failed....

Posted: Sat Dec 21, 2013 9:56 pm
by windows8
A few days ago,I tried to read data from CD-ROM by ATAPI.
I was not using IRQs,just poll (wait for DRQ set).It's successful!!!
Now I try to wait for IRQ arrives. I failed.

Code: Select all

   requestIRQ(14,&ideIRQPrimary);
   requestIRQ(15,&ideIRQSecondary); 
   /*I had written a timer interrupt,so this code should have no problems.*/

   ideOutb(IDE_PRIMARY  ,IDE_REG_CONTROL,IDE_ENABLE_IRQ);
   ideOutb(IDE_SECONDARY,IDE_REG_CONTROL,IDE_ENABLE_IRQ);

Code: Select all

   const u8 primary = device->primary;
   const u8 master = device->master;
   u8 cmd[12] = {0xa8 /*READ (12).*/,0,0,0,0,0,0,0,0,0,0,0};
      /*SCSI Command.*/

   ideWaitReady(primary);
   ideOutb(primary,IDE_REG_DEV_SEL,master << 4);
   for(int i = 0;i < 4;++i) /*A little delay.*/
     ideInb(primary,IDE_REG_CONTROL);
   ideOutb(primary,IDE_REG_FEATURES,0x0); /*PIO Mode.*/
   ideOutb(primary,IDE_REG_LBA1,(ATAPI_SECTOR_SIZE & 0xff)); 
   ideOutb(primary,IDE_REG_LBA2,((ATAPI_SECTOR_SIZE >> 8)) & 0xff);
   ideOutb(primary,IDE_REG_COMMAND,IDE_CMD_PACKET);

   if(ideWaitInterrupt(device))
      return -1; /*Return if error.*/
/*If I use 'ideWaitDRQ(primary)' instead of 'ideWaitInterrupt(device)',it's successful.*/
/*But if not,ideWaitInterrupt never returns. IRQ never arrivers,why?*/

Code: Select all


/*Do other things.*/

My IRQ handlers:

Code: Select all

static int ideIRQPrimary(IRQRegisters *reg,void *data)
{
   printk("IDE IRQ arrives!\n"); 
   
/*It is a test,I know that IRQ never arrives through it.*/

Code: Select all

/*So this code below never runs.*/
   u8 status = ideInb(IDE_PRIMARY,IDE_REG_STATUS);
   if(!data)
      return 0;
   IDEInterruptWait *wait = (IDEInterruptWait *)data;
   if(wait->primary != IDE_PRIMARY)
      return 0;
   wait->status = status;
   wakeUpTask(wait->task);
   return 0;
}
The wiki says "Then wait for another IRQ. You cannot poll." (http://wiki.osdev.org/ATAPI)
But I poll successfully and fail to wait for an IRQ.What's the reason???
Thanks.

Re: Read CD-ROM by ATAPI failed....

Posted: Sun Dec 22, 2013 12:39 am
by windows8
Solved!!
The wiki may make a mistake.

When we read ATAPI device,we should do this:
1.Set some registers:
a. device => master << 4
b. control => 0 (Enable Interrupts) or 2 (Disable Interrupts)
c. lba2 << 8 + lba1 => ATAPI Sector Size (2048)
d. features => 0 (PIO)
2.Send a command: PACKET COMMAND (0xa0)
3.Now poll for DRQ set,can not wait for irq!!!! (QEMU VirtualBox didn't make any irqs!!)
The wiki says "Wait for an IRQ, or poll for BSY to clear and DRQ to set."

4.Send a SCSI command to data register.
5.Now wait for irqs or poll.
The wiki says "Then wait for another IRQ. You cannot poll."

6.Read data from data register.
7.Wait for another irq. (If control register is 2,just do nothing.)

Am I right? Why does the wiki say so?

Re: Read CD-ROM by ATAPI failed....

Posted: Sun Dec 22, 2013 2:40 am
by dansmahajan
Actually irq fires,do following things to be sure
1. check whether interrupt are enabled
2. print a statement whenever a interrupt fire ie in your interrupt handler(common to all interrupts) function

Re: Read CD-ROM by ATAPI failed....

Posted: Sun Dec 22, 2013 3:38 am
by windows8
dansmahajan wrote:Actually irq fires,do following things to be sure
1. check whether interrupt are enabled
2. print a statement whenever a interrupt fire ie in your interrupt handler(common to all interrupts) function
Thanks for your reply.I have solved it.
See my reply above.