我是装配新手。在尝试弄清楚BIOS的作用时,我使用 gdb 来跟踪它。但是,我发现了一些非常奇怪的东西 代码段是:
[f000:d129] 0xfd129: mov eax,0x8f
[f000:d12f] 0xfd12f: out 0x70,al
[f000:d131] 0xfd131: in al,0x71
[f000:d133] 0xfd133: in al,0x92
[f000:d135] 0xfd135: or al,0x2
[f000:d137] 0xfd137: out 0x92,al
我想知道为什么BIOS会从端口0x71和0x92连续读取。第二条指令是否覆盖从端口0x71读取的值?那为什么它从端口0x71读取?
谢谢!
答案 0 :(得分:4)
IO端口0x70是" CMOS / RTC索引寄存器",IO端口0x71是" CMOS / RTC数据寄存器"。要访问CMOS中的某些内容,您应该设置索引然后读/写数据寄存器。
对于某些RTC芯片,如果设置索引并且不读取或写入数据寄存器,则芯片处于未定义状态。这意味着如果您想为以后设置索引,则必须从数据寄存器中读取以避免"未定义状态"现在和以后之间。
换句话说;所阅读的价值并不相关 - 阅读会产生副作用,而且副作用也很重要。
答案 1 :(得分:2)
端口0x70
和0x71
是CMOS registers。
我在此主题is from the BOCHS emulator上找到的最佳列表 根据此列表,代码如下:
mov eax,0x8f ; sets 'NMI disabled ' and 'CMOS RAM index' = 64
out 0x70,al ; write
in al,0x71 ; any write to 0x70 should be followed by an action to 0x71 or the RTC wil be left in an unknown state.
in al,0x92 ; read PS/2 system control port A
or al,0x2 ; set BIT1 = indicates A20 active
out 0x92,al ; write PS/2 system control port A
因此,此代码会禁用NMI并将A20 line设置为活动状态。最后三行实现了Fast A20 Gate。
我想知道为什么BIOS从端口0x71和0x92连续读取
原因很简单就是
any write to 0070 should be followed by an action to 0071 or the RTC will be left in an unknown state.
因此,第一次读取(读取到in al,0x71
)除了确保这一点之外没有任何其他目的,因此可以忽略其结果。