Closed benpigchu closed 4 years ago
Here is what happened after this and #57
Before I start, I merged the rcore-os/driver-qemu
branch to get some bug fixed by @wangrunji0408
The first bug in this issue can be simply fixed by convert before add, see this . Also, this only happens on debug build.
After that, a second bug happens: we recieved a 0x01 interrupt after a ZX_SYS_pci_map_interrupt
syscall. After some logging I found it's using the MSI, which needs the kernel to allocate interrupt number for devices. So I look into the interrupt number allocating code, and ......
Look at the irq_start = (irq_cur & (irq_num - 1)) + irq_num;
line, it is absolutely wrong. There should be a !
before the (irq_num - 1)
. To be clear, I use %
instead of bit operation.
After that, here come the third bug: The allocted interrupt number is 0x27 (which is correct), but we recieved a 0x7 interrupt instead! Also, the code that set interrupt number set the 0x27 as interrupt number correctly!
So I found some article about the PCI MSI (https://example61560.wordpress.com/2016/06/30/pcipcie-%E6%80%BB%E7%BA%BF%E6%A6%82%E8%BF%B06/) and use the qemu -trace
to log all pci config operations. And what I see is:
103964@1592058745.690736:pci_cfg_write ich9-ahci 02:0 @0x8c <- 0x27
103964@1592058745.692715:pci_cfg_read ich9-ahci 02:0 @0x8c -> 0x27
103964@1592058745.693714:pci_cfg_write ich9-ahci 02:0 @0x8c <- 0x7
It is overrided by another thing. So I read the code after setting the interrupt number, and then......
This is not right. This field should in the Message Control field.
After fixing that, we get a page fault from the sysmem
driver.(I add some addition log to print it, see this )
It's hard to debug user process, but by reading the log, I know that this page fault happens after the virtual-console found a display device and request some memory from sysmem. So I disabled virtual-console as a workaround. (https://github.com/rcore-os/zCore/pull/57/commits/f87e2a5b3f6f4ebdc511bb433ed3886fb6541289)
After that, I tested the hard disk on PCI. See #57 . There are still some issue, but we can just merge it since doing nothing will not break the kernal know.
Call to sys_pci_init may panick due to overflow adding u8