How to make sure rtl8139 is connected to the PIC in QEMU

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
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

How to make sure rtl8139 is connected to the PIC in QEMU

Post by kemosparc »

Hi,

I am writing a driver for rtl8139 network card for my os.

I cannot get the card to fire interrupts.

My question is how to make sure that the card is connected to PIC and if it is not how to connect it.

I am using qemu.

Thanks
Karim.
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by Jezze »

The irq number is found in the pci configuration space. If you dont recieve interrupts make sure that number is not masked in your pic code.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by kemosparc »

Yes,

I can read it from the pci configuration space.

It is IRQ Line 11 and and IRQ Pin 1.

I make sure to clear the mask through calling this function with the IRQ Number:

Code: Select all

void IRQ_clear_mask(unsigned char IRQline) {
    uint16_t port;
    uint8_t value;

    if(IRQline < 8) {
        port = PIC1_DATA;
    } else {
        port = PIC2_DATA;
        IRQline -= 8;
    }
    value = Ports::inportb(port) & ~(1 << IRQline);
    Ports::outportb(port, value);
}
Is that what you mean?

Thanks,
Karim.
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by kemosparc »

Hi,

Okay, what I have done is that I have compiled qemu with debug info and I have enabled debug inside the rtl8139.c file to see what is going on.


My packets get received by the card and it is copied to the rx buffer, and when I inspected the IntrMask and the IntrStatus of the device I found that their values are:

IntrMask: c07f
IntrStatus: 0001

The documentation at http://wiki.osdev.org/PCI says that bit 3 of the IntrStatus should be set for the interrupt to get fired. I don't know what is the reason for IntrStatus not to be set correctly, and when it should be set?


Any suggestions?

Thanks
Karim
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by bwat »

What interrupt mask and interrupt status registers are you talking about? In my Realtek 8139 driver I had the following:

Code: Select all

#define RL_ISR		0x003E		/* interrupt status register */

#define RL_ISR_RX_OK		0x0001
#define RL_ISR_RX_ERR		0x0002
You should be getting 1 on a good RX. I checked my mask and it gets programmed to 0xc07f, so I think you've received OK. My interrupt is 5 on the PIC.
Every universe of discourse has its logical structure --- S. K. Langer.
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by kemosparc »

I am talking about the IntrStatus and the IntrMask of the qemu.

The debug mode prints them on every packet receival

Thanks
Karim
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by kemosparc »

So Why do you think the interrupt does not fire?

Although PIT and the Keyboard fire their interrupts?

I have been working in this for the past 5 days, and I have traced the qemu as much as I can and I cannot know why the interrupt does not fire.

Any suggestions ?
Thanks
Karim
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by bwat »

kemosparc wrote:I have been working in this for the past 5 days, and I have traced the qemu as much as I can and I cannot know why the interrupt does not fire.
1) Five days is nothing!
2) I've never seen the source code for qemu but there's no doubt in my mind that if you stepped through the code you would eventually figure out why you weren't getting an interrupt. It's just a question of how badly you want to solve the problem.
Every universe of discourse has its logical structure --- S. K. Langer.
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by kemosparc »

I am kind of confused,

How to know if the hardware is configured with PIC or APIC?

Basically, the qemu fires the interrupt once, but it never reaches my handler hub, and it never fires again!!

Any help?
Thanks
Karim
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: How to make sure rtl8139 is connected to the PIC in QEMU

Post by kemosparc »

Another question,

Is there any special consisderation of my kernel runs in 64-bit Long mode?

Thanks
Karim
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

[SOLVED]How to make sure rtl8139 is connected to the PIC in

Post by kemosparc »

Okay,

Finally I discovered my problem.

The IRQ for the network card is IRQ 11 which is on PIC 2.

So I had to enable IRQ2 (unmask it) as it cascades the interrupts on PIC2.

Now the interrupt fires

Thanks
Karim..
Post Reply