Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change BIOS settings using the C language

Tags:

c

I was wondering if there is any way for me to write a C program to change the amount of memory that is being shared between RAM and a GFX card, or in general how do I contact the BIOS settings?

like image 806
codemax Avatar asked Nov 21 '09 07:11

codemax


2 Answers

You can access the BIOS settings via I/O port 70h and 71h. (Some chipsets also have an extended CMOS at 72/73 or similar.)

What OS are you using? If you are running Windows, you won't be able to do port I/O directly from an application, you'll have to write a kernel mode driver, or use a third-party toolkit like WinIO. Under Linux, you can use /dev/nvram to get at the CMOS settings. (Assuming the Linux nvram driver has support for your chipset. Otherwise use /dev/port.)

Once you get at the CMOS bits, the next task will be figuring out which location in CMOS corresponds to the Video Memory Setting.

Here is a (woefully incomplete) map of CMOS memory locations: http://ivs.cs.uni-magdeburg.de/~zbrog/asm/cmos.html

The map of CMOS locations is extremely specific to the motherboard, BIOS, and BIOS rev. (The CMOS map can change between BIOS revs as new menu options are added/removed.) Maybe your motherboard vendor can provide you with a CMOS map. They have the tools to generate such a map (it is part of the BIOS compilation process), but they may not be willing to share it.

Without a map, there are other methods to determine which bits in CMOS represent the Video Memory Size. Try dumping the CMOS settings with various memory sizes and figure out which bits change.

Some other details:

  1. Outside of a few "standard" CMOS bits, most of them are extremely platform dependent, I hope you weren't planning on making a general-purpose application out of this.

  2. There are checksums at certain offsets in CMOS. After you change the CMOS value, you will have to fix up the checksum to reflect the changes.

  3. Once you change the setting, it won't take effect to the next reboot (when the BIOS reads the CMOS settings and initializes the chipset).

  4. Is this an Intel chipset? Intel graphics cores have a magic feature called Dynamic Video Memory Technology (DVMT) which tweaks video memory usage based on how graphics-intensive the running application is. http://www.intel.com/support/graphics/sb/cs-010488.htm I'm not sure if other chipset vendors have a similar technology.

  5. Throw all of this out the window on a modern UEFI system, which typically uses a nonvolatile storage partition in the BIOS flash chip for the settings. (Some CMOS locations are populated for legacy compatibility on a UEFI system.)

like image 169
myron-semack Avatar answered Oct 05 '22 23:10

myron-semack


Short answer: No.

Long answer: Don't mess with user's BIOS. There's a reason why there are no APIs or the like to do it. My computer, my settings.

like image 29
danielkza Avatar answered Oct 05 '22 23:10

danielkza