在我的麻省理工学院OS课程(686)中,我发现了一些代码,我试图理解boot / boot.S中的指令 inb $0x64, %al
. 我的理解是它从数据端口0x64读取一个字节到AL,什么是端口0x64?它忙于测试哪种设备或机制?我对代码忙的评论感到困惑?评论意味着什么,它指的是什么?
# Enable A20:
# For fascinating historical reasons (related to the fact that
# the earliest 8086-based PCs could only address 1MB of physical memory
# and subsequent 80286-based PCs wanted to retain maximum compatibility),
# physical address line 20 is tied to low when the machine boots.
# Obviously this a bit of a drag for us, especially when trying to
# address memory above 1MB. This code undoes this.
seta20.1: inb $0x64,%al # Get status
testb $0x2,%al # Busy?
jnz seta20.1 # Yes
movb $0xd1,%al # Command: Write
outb %al,$0x64 # output port
seta20.2: inb $0x64,%al # Get status
testb $0x2,%al # Busy?
jnz seta20.2 # Yes
movb $0xdf,%al # Enable
outb %al,$0x60 # A20
1 回答
端口0x64是键盘控制器的IO端口 .
键盘控制器有两个端口0x64和0x60 .
端口0x64(命令端口)用于向键盘控制器(PS / 2)发送命令 .
端口0x60(数据端口)用于向/从PS / 2(键盘)控制器或PS / 2设备本身发送数据 .
这里的代码使CPU轮询PS / 2键盘控制器以查看它是否正忙 .
上述指令读取PS / 2控制器的状态寄存器,其长度为8位 . 具体来说,它试图读取输入缓冲区的状态 - 位1 .
在此处测试从前一个inb指令返回的字节 . 这里检查输入缓冲区的状态以查看它是满还是空 - 位1(0x2) .
Syntax of x86 assembly code以上主题详细介绍了此处提到的端口0x64和0x60 .
以下链接还详细讨论了IO端口的使用方式 . How are I/O port addresses and data sent?