ata interrupt routines

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
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

ata interrupt routines

Post by blackoil »

Hi, all.

when I do a ata_read_sector(), the code stops at "hlt' instruction to wait for the sector data. If a keyboard interrupt occurs, then after keyboard iret, will PC be back to the ata "hlt" instruction?

Code: Select all

ata_read_sector:
{
...    // some inits.
hlt    // wait for the ata interrupt.
...    // get data.
}


kb_interrupt:
iret
ata_interrupt:
iret
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: ata interrupt routines

Post by bluemoon »

You should read the manual for the HLT instruction, the exact behavior is well documented.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: ata interrupt routines

Post by blackoil »

I use this hlt method, it works fine though, I can read/write sector data. But I am not 100% sure it is safe.
I test it in BOCHS, but I can't remember If I tried in real machine before, the test machine is broken now.

My thought is:
When stops at ata hlt instruction, if kb interrupt occurs, the cpu goes to kb interrupt routine, then back to ata hlt instruction with kb iret.
because kb interrupt has higher priority.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: ata interrupt routines

Post by Nable »

> My thought is:
"Assumption is the mother of all fsckups".

Just read the manual, because this is the case when giving exact answer is a bad thing (in context of learning).
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: ata interrupt routines

Post by blackoil »

I read the document, the document says the EIP points to the next instruction after HLT, whichever interrupt comes.
Of couse you can use classic method to deal with interruption routines.

I just want to try the "HLT" method here, if it does't work, how to explain the correct ata sector data, instead of garbage one.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: ata interrupt routines

Post by bluemoon »

If the manual is not clear enough, HLT will resume the core upon _any_ interrupt (and some other cases).
So, after HLT you need to check the cause (or validate ata status), you may not assume the core is awake due to something is read from ATA.
blackoil wrote:how to explain the correct ata sector data, instead of garbage one.
It work (in some case) does not mean it has no bug; say, if a timer interrupt happen at the right time you may get garbage.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: ata interrupt routines

Post by blackoil »

It looks like there's no ata IRQ asserted, HLT state is waked up by other IRQs, but the ata device finished the data.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: ata interrupt routines

Post by blackoil »

I found the cause: I set the wrong bits in secondary 8259PIC for ata devices, in REVERSE order.
It's verified with HLT instruction and only ATA IRQ enabled.
Post Reply