gpt4 book ai didi

assembly - 设置IRQ映射

转载 作者:行者123 更新时间:2023-12-04 03:35:37 25 4
gpt4 key购买 nike

我正在关注一些教程和引用资料,以尝试设置内核。我在教程中遇到了一些陌生的代码,根本没有解释它。我被告知的代码是将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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com