CMOS

From OSDev.wiki
Revision as of 21:18, 20 April 2009 by osdev>Imate900 (reorganized sections for examples, sorry about last edit)
Jump to navigation Jump to search

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.

Examples

All these examples use Intel-style assembly.

Reading from the CMOS

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;
   }
}

Writing to the CMOS

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