How do I set a graphics mode

From OSDev.wiki
Revision as of 08:34, 20 April 2009 by Combuster (talk | contribs) (Created faq entry)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Each video card you find in a PC comes with a piece of code that allows it to be initialized, the video BIOS. This bios is expected to run in Real Mode, and as long as you are, you can access all the functions directly by calling int 0x10 with the right values in the registers. If your kernel is based on a tutorial, you can not do this, because for practically all tutorials, you are in protected mode, and not in real mode.

Almost all video cards have two interfaces, one VGA interface for low resolutions, and the VESA VBE interface for higher resolutions. Alternatively, you can write your own code to directly deal with the graphics hardware.


In Protected Mode or Long Mode, the BIOS interface is not directly accessible. A number of approaches can be used to still use it. They all work by setting or simulating real mode and calling the interrupt that way.

  • Drop back to real mode, then call the BIOS. The easiest solution, but also the most ugly. Be careful to restore everything to real-mode values when you do.
  • Use Virtual 8086 Mode. The most common good solution for protected mode. This way you can run the BIOS from a virtual machine style environment, thus maintaining control over the process. Virtual 8086 mode is however not available from Long Mode.
  • Write/use an emulator. The slowest and most intensive approach, but has the advantage that it will work under any condition, including long mode and other platforms.


The alternative approach is to not use the BIOS at all:

  • Write or reuse a VGA driver. This gives you all low resolution modes on practically all hardware, and is easier to do than setting up a virtual machine of any sort.
  • Write a driver for each graphics card. Only recommended if you have more than one life to waste.