[英]BIOS reads twice from different port to the same register in a row
我是新來的。 在嘗試弄清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讀取呢?
謝謝!
IO端口0x70是“ CMOS / RTC索引寄存器”,而IO端口0x71是“ CMOS / RTC數據寄存器”。 要訪問CMOS中的內容,您應該先設置索引,然后對數據寄存器進行讀/寫。
對於某些RTC芯片,如果設置索引並且不對數據寄存器進行讀寫操作,則該芯片將處於不確定狀態。 這意味着,如果要為以后設置索引,則必須從數據寄存器中讀取數據,以免在現在和以后之間出現“未定義狀態”。
換一種說法; 讀取的值無關緊要-讀取會產生副作用,而副作用才是重要的。
端口0x70
和0x71
是CMOS寄存器 。
我在此主題上找到的最佳列表來自BOCHS模擬器 。
根據此列表,代碼如下:
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線路設置為活動狀態。 最后三行實現了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
讀取為)確實沒有其他目的,因此可以忽略其結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.