CMOS

From OSDev.wiki
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.

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