CMOS: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(minor corrections, added notice about Microsoft Visual C++)
m (Reverted edits by Imate900 (Talk); changed back to last version by Jnc100)
Line 6: Line 6:


== Example Reading ==
== Example Reading ==
Example, showing how to read from the CMOS: (this example contains intel style [[assembly]] used in Microsoft Visual C++, not [[GAS]] which is used in [[GCC]])
Example, showing how to read from the CMOS: (this examples contains intel style [[assembly]], not [[GAS]] which is used in [[GCC]])


<pre>
<pre>
Line 37: Line 37:


== Example Writing ==
== Example Writing ==
Example showing how to write (still Intel-style syntax used in Microsoft Visual C++):
Example showing how to write:


<pre>
<pre>

Revision as of 20:38, 20 April 2009

All the required settings about FDD, HDD, timers, etc. are stored in a small capacity low powered memory called the CMOS. The CMOS (Complementary Metal Oxide Semiconductor) memory is 65 or 128 byte RAM which is powered by a battery on the motherboard.

Reading from and writing to the CMOS

To access CMOS RAM, the index address (0 to 7F hex) is output to port 70h, and the data is then read or written at port 71h.

Example Reading

Example, showing how to read from the CMOS: (this examples contains intel style assembly, not GAS which is used in GCC)

ReadFromCMOS (unsigned char array [])
{
   int index;
   unsigned char tvalue, bindex;

   for(index = 0; index < 128; index++)
   {
      char AL_ = (unsigned char) index;
      _asm
      {
         xor ax,ax       /* Clear accumulator*/
         cli             /* Disable interrupts*/
         mov al,AL_      /* Move index address*/
         out 0x70,al     /* Copy address to CMOS register*/
         nop
         nop
         nop             /* Wait a bit for response*/
         in al,0x71      /* Fetch 1 byte to al*/
         sti             /* Enable interrupts*/
         mov tvalue,al
       }

       array[index] = tvalue;
   }
}

Example Writing

Example showing how to write:

WriteTOCMOS(unsigned char array[])
{
   unsigned char index;

   for(index = 0; index < 128; index++)
   {
      unsigned char tvalue = array[index];
      _asm
      {
         xor ax,ax       /* zero register*/
         cli             /* Clear interrupts*/
         mov al,index    /* move index address*/
         mov ah,tvalue   /* copy value to ah*/
         out 0x70,al     /* copy address to CMOS register*/
         nop
         nop
         nop             /* Wait a bit */
         mov al,ah       /* move value to al*/
         out 0x71,al     /* write 1 byte to CMOS*/
         sti             /* Enable interrupts*/
      }
   }
}

See Also

CMOS Memory Map