首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在切换到保护模式之前在引导加载程序中测试端口0x64?

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

Stack Overflow用户
提问于 2014-01-12 19:02:35
回答 1查看 3.4K关注 0票数 8

在我的麻省理工学院操作系统课程(686)中,我发现了一些我不懂的代码。我试图理解引导/引导中的指令inb $0x64, %al,我的理解是它从数据端口0x64读取一个字节到AL,什么是端口0x64?什么设备或机制,它是测试忙?我对代码中的评论感到困惑吗?这句话的意思是什么,指的是什么?

代码语言:javascript
复制
# 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
EN

回答 1

Stack Overflow用户

发布于 2015-11-23 02:43:19

什么是0x64端口?

端口0x64是键盘控制器的IO端口。

键盘控制器有两个端口0x64和0x60。

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

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

什么设备或机制,它是测试忙?我对代码中的评论感到困惑吗?这句话的意思是什么,指的是什么?

这里的代码使CPU轮询PS/2键盘控制器来查看它是否繁忙。

代码语言:javascript
复制
inb     $0x64,%al               # Get status

上述指令读取长度为8位的PS/2控制器的状态寄存器。具体来说,它正在尝试读取输入缓冲区-位1的状态。

代码语言:javascript
复制
testb   $0x2,%al                # Busy?

从前一个inb指令返回的字节在这里进行测试。在这里,将检查输入缓冲区的状态,以查看它是完整的还是空的-位1(0x2)。

代码语言:javascript
复制
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?

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21078932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档