assembly - 设置IRQ映射

标签 assembly x86 kernel osdev irq

我正在关注一些教程和引用资料,以尝试设置内核。我在教程中遇到了一些陌生的代码,根本没有解释它。我被告知的代码是将16 IRQs (0-15)映射到ISR位置32-47:

void irq_remap(void)
{
    outportb(0x20, 0x11);
    outportb(0xA0, 0x11);
    outportb(0x21, 0x20);
    outportb(0xA1, 0x28);
    outportb(0x21, 0x04);
    outportb(0xA1, 0x02);
    outportb(0x21, 0x01);
    outportb(0xA1, 0x01);
    outportb(0x21, 0x0);
    outportb(0xA1, 0x0);
}
outportb()的代码如下,但我已经清楚地知道了它的作用:
void outPortB(unsigned short port, unsigned char data)
{
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (port), "a" (data));
}

我应该提到这是在保护模式下的x86架构上。此源代码工作正常,我了解它的作用,但我不了解它的作用。有人可以向我解释这是怎么回事,以便在需要扩展此功能时我会知道我在做什么?

最佳答案

outb和类似内容,写入硬件IO端口。基本上,有两个与设备通信的主要选项。您可以将设备映射到内存或IO端口。

至于此代码的工作方式,我将为您注释:

ICW代表“初始化命令字”

outportb(0x20, 0x11); /* write ICW1 to PICM, we are gonna write commands to PICM */
outportb(0xA0, 0x11); /* write ICW1 to PICS, we are gonna write commands to PICS */

outportb(0x21, 0x20); /* remap PICM to 0x20 (32 decimal) */
outportb(0xA1, 0x28); /* remap PICS to 0x28 (40 decimal) */

outportb(0x21, 0x04); /* IRQ2 -> connection to slave */ 
outportb(0xA1, 0x02);

outportb(0x21, 0x01); /* write ICW4 to PICM, we are gonna write commands to PICM */
outportb(0xA1, 0x01); /* write ICW4 to PICS, we are gonna write commands to PICS */

outportb(0x21, 0x0); /* enable all IRQs on PICM */
outportb(0xA1, 0x0); /* enable all IRQs on PICS */

希望这可以帮助

欢迎来到OS开发人员世界:)我还建议您访问:http://forum.osdev.org/,对于新的业余OS开发人员来说,它是宝贵的资源。

关于assembly - 设置IRQ映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/282983/

相关文章:

android - 在 PXA270 设备上移植 Android 操作系统

c - 反汇编简单的 C 函数

c++ - 在 Visual Studio 中编写汇编和 C

c - 为什么同一程序中同一 C 循环的相同副本会花费明显但始终不同的时间来执行?

assembly - 在x86 8086 Assembly中生成0-9范围内的随机数

assembly - 开始学习汇编的好地方是什么?

windows - 与时间相关的中断在 Windows 中的汇编程序中不起作用?

assembly - 当您使用内存覆盖前缀但所有操作数都是寄存器时会发生什么?

linux - 从 Linux 内核中的路径获取 inode

linux - QEMU:/bin/sh: 无法访问 tty;作业控制关闭