Page 1 of 1

[Solved] AHCI - Enabling port interrupts causes hanging

Posted: Tue Dec 24, 2024 2:35 pm
by haroldmann
Hello,

I am following the instructions in https://wiki.osdev.org/AHCI. So far I have been able to get basic reading and writing from disk set up.

Now I am following the checklist at the end to set up interrupts. I've found when setting PxIE.DHRE or PxIE.PSE, execution stops completely and I have no idea why. Setting any other interrupt bit does not cause this to happen. Disabling paging before setting the register didn't help either.

PCI Bus mastering and interrupts are enabled.
Interrupts are enabled in the GHC register.
HBA and port memory have been memory mapped with caching disabled.
The HBA and port has been reset before trying to set the register.

Has anyone else encountered this problem? Does anyone know what might be going on? The AHCI code is attached, if more is needed let me know. Any help is appreciated.

As an example:

Code: Select all

kprintf("One\n");
mem->ports[port].ie = PxIE_TFEE | PxIE_HDRE;
kprintf("Two\n");
This will cause "One" to be printed, "Two" will not print.

Re: AHCI - Enabling port interrupts causes hanging

Posted: Thu Dec 26, 2024 4:48 pm
by Octocontrabass
Have you tried using a debugger to see what the CPU is doing when it hangs?

Re: AHCI - Enabling port interrupts causes hanging

Posted: Fri Dec 27, 2024 2:34 pm
by haroldmann
I'm using GDB with QEMU i386. I moved the instruction that sets the port interrupts to its own function (ahci_dothing) and set a breakpoint there. It hangs after it returns. Here's what I got from the assembly readout. I attached screenshots, I'm not sure what would be causing problems here.

Re: AHCI - Enabling port interrupts causes hanging

Posted: Fri Dec 27, 2024 2:59 pm
by Octocontrabass
It sounds like an interrupt is occurring, but as far as I know you should see the debugger step into your interrupt handler when an interrupt occurs.

Unless maybe there's a problem with your interrupt handlers too? Running QEMU with "-d int" should give you an idea of what's going on.

You can also try using QEMU's trace log to see what the emulated AHCI controller thinks is happening.

Re: AHCI - Enabling port interrupts causes hanging

Posted: Fri Dec 27, 2024 11:22 pm
by haroldmann
Thanks for the reply. I'll look into it and report back.

Re: AHCI - Enabling port interrupts causes hanging

Posted: Tue Jan 07, 2025 7:56 pm
by haroldmann
I figured it out.

The AHCI interrupt line is connected to the PIC. When the interrupt fires the PIC changes the interrupt number. I forgot about this detail. After registering the AHCI IRQ to number 0x2B, my IRQ got called and it worked.

The hanging was caused by the interrupt not being acknowledged (some bit in HBA memory not being set, I forget which one). After clearing the interrupt, the interrupt would fire again immediately, causing the "hanging".

Thanks for recommending the -d option. I would not have figured this out otherwise.