Page 1 of 1

help,stumbling on APIC learning.

Posted: Tue Apr 13, 2010 2:55 pm
by supperchao
:lol: Hello!everyone,i'm a newbie around OS dev and hardware , i'm have been confused on this so much : how does those irqs resides in IOAPIC(any tables?),and is there somehow something relationships between the both. My questions stem from the following windows driver snippet. i'm so sorroy for the chinese comments. I commented those lines in which i can't figure out:

Code: Select all

// 搜索IOAPIC获得键盘中断,或者设置这个值。
// Description:
//lookup IOAPIC to grab keyboard interrupt.

P2C_U8 p2cSeachOrSetIrq1(P2C_U8 new_ch)
{
    // 选择寄存器。选择寄存器虽然是32位的寄存器,但是只使用
    // 低8位,其他的位都被保留。
 P2C_U8 *io_reg_sel;

    // 窗口寄存器,用来读写被选择寄存器选择的值,是32位的。
 P2C_U32 *io_win;
 P2C_U32 ch,ch1;

    // 定义一个物理地址,这个地址为0xfec00000。正是IOAPIC
    // 寄存器组在Windows上的开始地址
 PHYSICAL_ADDRESS phys ;
 PVOID paddr;
 RtlZeroMemory(&phys,sizeof(PHYSICAL_ADDRESS));
 phys.u.LowPart = 0xfec00000;

    // 物理地址是不能直接读写的。MmMapIoSpace把物理地址映射
    // 为系统空间的虚拟地址。0x14是这片空间的长度。
 paddr = MmMapIoSpace(phys, 0x14, MmNonCached);

    // 如果映射失败了就返回0.
 if (!MmIsAddressValid(paddr))
  return 0;

    // 选择寄存器的偏移为0
 io_reg_sel = (P2C_U8 *)paddr;
    // 窗口寄存器的偏移为0x10.
 io_win = (P2C_U32 *)((P2C_U8 *)(paddr) + 0x10);

    // 选择第0x12,刚好是irq1的项
   //here, why select 0x12 into i/o select register,why  irq1(keyboard interrupt) corresponds   to the index 0x12

 *io_reg_sel = 0x12;
 ch = *io_win;  //vector?

    // 如果new_ch不为0,我们就设置新值。并返回旧值。
    if(new_ch != 0)
    { //here,two line bitwise operations,i don't understand what's the meaning of  at all
        ch1 = *io_win;
        ch1 &= 0xffffff00;
        ch1 |= (P2C_U32)new_ch;
        *io_win = ch1;
        KdPrint(("p2cSeachOrSetIrq1: set %2x to irq1.\r\n",(P2C_U8)new_ch));
    }

    // 窗口寄存器里读出的值是32位的,但是我们只需要
    // 一个字节就可以了。这个字节就是中断向量的值。
    // 一会我们要修改这个值。
    ch &= 0xff;
 MmUnmapIoSpace(paddr, 0x14);
    KdPrint(("p2cSeachOrSetIrq1: the old vec of irq1 is %2x.\r\n",(P2C_U8)ch));
 return (P2C_U8)ch;
}
than all you! :D

Re: help,stumbling on APIC learning.

Posted: Tue Apr 13, 2010 3:36 pm
by Gigasoft
Each redirection entry occupies two registers starting at 0x10. Therefore, entry 1 is at 0x12. However, not all systems have ISA IRQ 1 connected to IO APIC pin 1.

On ACPI systems, each ISA IRQ corresponds to the same numbered pin on the IO APIC whose Global System Interrupt base is 0. So, ISA IRQ number equals the GSI number.

Re: help,stumbling on APIC learning.

Posted: Wed Apr 14, 2010 1:18 am
by supperchao
[quote="Gigasoft"]Each redirection entry occupies two registers starting at 0x10. Therefore, entry 1 is at 0x12.[quote]
:) :) ,
Hello ....
1.I understand this superficially and literally above, could you describe this subject more in detail and make me a full knowledge.

2. The following bitwise operations. what's the ues for?

Code: Select all

    // 如果new_ch不为0,我们就设置新值。并返回旧值。
    if(new_ch != 0)
    { //here,two line bitwise operations,i don't understand what's the meaning of  at all
        ch1 = *io_win;
        ch1 &= 0xffffff00;
        ch1 |= (P2C_U32)new_ch;
        *io_win = ch1;
        KdPrint(("p2cSeachOrSetIrq1: set %2x to irq1.\r\n",(P2C_U8)new_ch));
    }
  
thank everyone in advance!!

Re: help,stumbling on APIC learning.

Posted: Wed Apr 14, 2010 2:06 am
by Love4Boobies
supperchao wrote:1.I understand this superficially and literally above, could you describe this subject more in detail and make me a full knowledge.
IOAPIC
2. The following bitwise operations. what's the ues for?
Masking out the LSB of *io_win.