CMOS: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
→‎Getting Current Date and Time from RTC: Fix range column lacking leading space for rows below header
m Bot: Replace deprecated source tag with syntaxhighlight
 
(10 intermediate revisions by 7 users not shown)
Line 1:
"CMOS" is a tiny bit of very low power static memory that lives on the same chip as the Real-Time Clock (RTC). It
It was introduced to IBM PC AT in 1984 which used Motorola MC146818A RTC.
is fairly convenient to actually think of the RTC as being "part" of CMOS.
 
CMOS (and the Real-Time Clock) can only be accessed through IO Ports 0x70 and 0x71. The function of the CMOS
memory is to store 50 (or 114) bytes of "Setup" information for the BIOS while the computer is turned off --
Line 36 ⟶ 37:
as follows:
 
* <tt>outb (0x70, (NMI_disable_bit << 7) | (selected CMOS register number));</tt>
 
Once a register is selected, you either read the value of that register on Port 0x71 (with inb or an equivalent
function), or you write a new value to that register -- also on Port 0x71 (with outb, for example):
 
* <tt>val_8bit = inb (0x71);</tt>
 
Note1: Reading or writing Port 0x71 seems to default the "selected register" back to 0xD. So you need to
Line 152 ⟶ 153:
=== Weekday Register ===
 
The RTC chip is able to keep track of the current day of the week. All it does is increment its "Weekday" register at midnight and reset it to zero1 if itthe reachesincremented value would go above 7[https://groups.google.com/d/msg/alt.os.development/qPxWHKC48rw/yjAt-c8IAQAJ]. Unfortunately there is no guarantee that this register was ever set correctly by anything (including when the user changes the time and date using the BIOS configuration screen). It is entirely unreliable and should not be used.
 
The correct way to determine the current day of the week is to calculate it from the date (see [http://en.wikipedia.org/wiki/Weekday_determination the article on Wikipedia] for details of this calculation).
Line 206 ⟶ 207:
 
=== Reading from the CMOS ===
<sourcesyntaxhighlight lang="c">
ReadFromCMOS (unsigned char array [])
{
Line 228 ⟶ 229:
}
}
</syntaxhighlight>
</source>
 
=== Writing to the CMOS ===
<sourcesyntaxhighlight lang="c">
WriteTOCMOS(unsigned char array[])
{
Line 251 ⟶ 252:
}
}
</syntaxhighlight>
</source>
 
=== Reading All RTC Time and Date Registers ===
<sourcesyntaxhighlight lang="c">
#define CURRENT_YEAR 20142023 // Change this each year!
 
int century_register = 0x00; // Set by ACPI table parsing code if possible
Line 363 ⟶ 364:
}
}
</syntaxhighlight>
</source>
 
== See Also ==
* [[RTC]]
 
== External Links ==
* [https://web.archive.org/web/20111209041013/http://www-ivs.cs.uni-magdeburg.de/~zbrog/asm/cmos.html Old CMOS Map]
* [http://www.bioscentral.com/misc/cmosmap.htm Better CMOS Map]
* [http://bitsavers.trailing-edge.com/pdf/ibm/pc/at/1502494_PC_AT_Technical_Reference_Mar84.pdf IBM PC AT Technical Reference]
* [http://web.stanford.edu/class/cs140/projects/pintos/specs/mc146818a.pdf MC146818A REAL-TIME CLOCK PLUS RAM (RTC)]
* [http://www.bitsavers.org/pdf/ibm/pc/ps2/PS2_Model_50_Technical_Reference_May88.pdf IBM PS/2 Technical Reference]
* [https://www.singlix.com/trdos/archive/pdf_archive/real-time-clock-nmi-enable-paper.pdf Intel Application Note: Accessing the Real Time Clock Registers and NMI Enable Bit]
 
[[Category:X86]]