gpt4 book ai didi

assembly - 为什么在切换到保护模式之前在引导加载程序中测试端口 0x64?

转载 作者:行者123 更新时间:2023-12-04 14:45:34 25 4
gpt4 key购买 nike

在我的 MIT OS 类(class) (686) 中,我发现了一些我不明白的代码。我试图理解指令 inb $0x64, %al在 boot/boot.S.
我的理解是它从数据端口 0x64 读取一个字节到 AL,什么是端口 0x64?它正在测试哪种设备或机制是否繁忙?我对代码 Busy 中的注释感到困惑?评论是什么意思,它指的是什么?

# 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

最佳答案

What is port 0x64?



端口 0x64 是键盘 Controller 的 IO 端口。

键盘 Controller 有两个端口 0x64 和 0x60。

端口 0x64(命令端口)用于向键盘 Controller (PS/2)发送命令。

端口 0x60(数据端口)用于向/从 PS/2(键盘) Controller 或 PS/2 设备本身发送数据。

Which device or mechanism is it testing for busy? I'm confused about the comment in the code Busy? What does the comment mean and what does it refer to?



这里的代码让 CPU 轮询 PS/2 键盘 Controller ,看它是否忙。
inb     $0x64,%al               # Get status

上述指令读取PS/2 Controller 的8位长的状态寄存器。具体来说,它试图读取输入缓冲区的状态 - 位 1。
testb   $0x2,%al                # Busy?

此处测试从前一条 inb 指令返回的字节。这里检查输入缓冲区的状态以查看它是满还是空 - 位 1(0x2)。
Status Register - PS/2 Controller
Bit Meaning
0 Output buffer status (0 = empty, 1 = full) (must be set before attempting to read data from IO port 0x60)

1 Input buffer status (0 = empty, 1 = full) (must be clear before attempting to write data to IO port 0x60 or IO port 0x64)

2 System Flag - Meant to be cleared on reset and set by firmware (via. PS/2 Controller Configuration Byte) if the system passes self tests (POST)

3 Command/data (0 = data written to input buffer is data for PS/2 device, 1 = data written to input buffer is data for PS/2 controller command)

4 Unknown (chipset specific) - May be "keyboard lock" (more likely unused on modern systems)

5 Unknown (chipset specific) - May be "receive time-out" or "second PS/2 port output buffer full"

6 Time-out error (0 = no error, 1 = time-out error)

7 Parity error (0 = no error, 1 = parity error)

Syntax of x86 assembly code
上述线程详细解释了此处引用的端口 0x64 和 0x60。

下面的链接还详细讨论了如何使用 IO 端口。
How are I/O port addresses and data sent?

关于assembly - 为什么在切换到保护模式之前在引导加载程序中测试端口 0x64?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21078932/

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