I am new to assembly. While trying to figure out what the BIOS does, I use the gdb to trace it. However, I found something really strange to me.
The code segment is this:
[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
I wonder why the BIOS reads from port 0x71 and 0x92 in a row. Will the second instruction cover the value read from port 0x71? Then why does it read from port 0x71?
Thank you!
IO port 0x70 is the "CMOS/RTC index register", and IO port 0x71 is the "CMOS/RTC data register". To access something in CMOS you're supposed to set the index then read/write to the data register.
For some RTC chips, if you set the index and don't read or write to the data register the chip is left in an undefined state. This means that if you want to set an index for later you have to read from the data register to avoid "undefined state" between now and later.
In other words; the value that was read isn't relevant - reading causes a side-effect, and it's the side-effect that matters.