Bochs VBE Extensions: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
m →‎Setting display resolution and bit depth: - added some information on max res's
added some information, removing some todos as I did the tests
Line 1: Line 1:
{{In Progress}}
{{In Progress}}
The [[Bochs]] VGA BIOS supports, to an extent, the VBE specification. Since Bochs only emulates a VGA card down to the hardware level (and a Cirrus graphics card if you enable it, but that is not tied in with the Bochs VBE extensions), it emulates very simple graphics hardware that the VBE BIOS can drive. The advantage of this is that if you are running your OS in Bochs (or Qemu, which uses the Bochs VGA BIOS), you can use this emulated hardware to directly set video modes without using VBE (which would require real mode or v86).
The [[Bochs]] VGA BIOS supports, to an extent, the VBE specification. Since Bochs only emulates a VGA card down to the hardware level (and a Cirrus graphics card if you enable it, but that is not tied in with the Bochs VBE extensions), it emulates very simple graphics hardware that the VBE BIOS can drive. The advantage of this is that if you are running your OS in Bochs (or QEMU, which uses the Bochs VGA BIOS), you can use this emulated hardware to directly set video modes without using VBE (which would require real mode or v86).


== Overview ==
== Overview ==
The Bochs emulated graphics hardware (henceforth called BGA for Bochs Graphics Adaptor) is accessed via two 16-bit IO-ports. The first one is an index port, the second one a data port (comparable to how the VGA handles its sets of registers). Via these ports it is possible to enable or disable the VBE extensions, change the screen resolution and bit depth, and manage a larger virtual screen. There are five versions of the BGA (0xB0C0 through 0xB0C4), but if you use the latest version of Bochs you only need to concern yourself with the latest one (0xB0C4).
The Bochs emulated graphics hardware (henceforth called BGA for Bochs Graphics Adaptor) is accessed via two 16-bit IO-ports. The first one is an index port, the second one a data port (comparable to how the VGA handles its sets of registers). Via these ports it is possible to enable or disable the VBE extensions, change the screen resolution and bit depth, and manage a larger virtual screen. There are five versions of the BGA (0xB0C0 through 0xB0C4), but if you use the latest version of Bochs you only need to concern yourself with the latest one (0xB0C4). QEMU (with the -std-vga command line argument) also use the latest version.


The Bochs sources define in vga.h, located in the subdirectory iodev/, a number of defines that are useful for programming the BGA. The names of these defines all start with VBE_DISPI. They are used in the sections below, with their numerical value between parentheses.
The Bochs sources define in vga.h, located in the subdirectory iodev/, a number of defines that are useful for programming the BGA. The names of these defines all start with VBE_DISPI. They are used in the sections below, with their numerical value between parentheses.
Line 15: Line 15:
* 0xB0C4 - [TODO: check and describe]
* 0xB0C4 - [TODO: check and describe]
[TODO: if and when 4BPP modes are supported]
[TODO: if and when 4BPP modes are supported]
[TODO: if and when VGA attribute controller (AC) is supported]


== Programming the BGA ==
== Programming the BGA ==
Line 41: Line 42:


=== Setting display resolution and bit depth ===
=== Setting display resolution and bit depth ===
Most likely, setting the display resolution and bit depth is all you need. To do so, disable the VBE extensions (see above), write the X resolution, Y resolution and BPP to their respective registers (VBE_DISPI_INDEX_XRES (1), VBE_DISPI_INDEX_YRES (2) and VBE_DISPI_INDEX_BPP (3)) and enable the VBE extensions. Since the BGA is not real hardware, X and Y resolutions can be set at will up to a maximum horizontal resolution (depending on your version of Bochs) of either 1024 or 1600 (VBE_DISPI_MAX_XRES) and a maximum vertical resolution of either 768 or 1200 (VBE_DISPI_MAX_YRES) [TODO: check whether Bochs does a sanity check on width/height pairs and describe]. The bit depth needs to be one of the following [TODO: check what Bochs does with other values]:
Most likely, setting the display resolution and bit depth is all you need. To do so, disable the VBE extensions (see above), write the X resolution, Y resolution and BPP to their respective registers (VBE_DISPI_INDEX_XRES (1), VBE_DISPI_INDEX_YRES (2) and VBE_DISPI_INDEX_BPP (3)) and enable the VBE extensions. Since the BGA is not real hardware, X and Y resolutions can be set at will up to a maximum horizontal resolution (depending on your version of Bochs) of either 1024 or 1600 (VBE_DISPI_MAX_XRES) and a maximum vertical resolution of either 768 or 1200 (VBE_DISPI_MAX_YRES). It seems that both Bochs and QEMU can use about any resolutions with a few restrictions. In QEMU the X resolution must be divisible by 8. [TODO: Describe how Bochs handle different X resolutions. It can crash with segmentation fault on various X resolutions, so it is difficult to test]. The Y resolution can be any number from 1 to maximum in both Bochs and QEMU. The bit depth needs to be one of the following:
* VBE_DISPI_BPP_4 (0x04)
* VBE_DISPI_BPP_4 (0x04)
* VBE_DISPI_BPP_8 (0x08)
* VBE_DISPI_BPP_8 (0x08)
Line 49: Line 50:
* VBE_DISPI_BPP_32 (0x20)
* VBE_DISPI_BPP_32 (0x20)


If you try to set an invalid resolution (greater than the maximum or an irregular X resolution) or bit depth, usually nothing happens. The current video mode is preserved. In some cases Bochs will crash with a segmentation fault if you set an invalid X resolution, so only use standard ones. [TODO: Check latest CVS version of Bochs and search their bug tracker]. You can always read the current resolution and bit depth from their respective registers. When you have set a resolution it is a good idea to read it back and check whether your new resolution is really set. You should do that before you enable the BGA to minimize the chance of your emulator crashing. [TODO: Check what happens when the first resolution you set is invalid.]
For 24 BPP, the order of the colour components is blue first, then green, then red. [TODO: check for other BPP and describe]

=== Memory layout of video modes ===

For 24 BPP, the order of the colour components is blue first, then green, then red.

[I'm about to add info on the other modes. --[[User:Walling|Walling]] 05:57, 26 October 2008 (UTC)]


=== Using banked mode ===
=== Using banked mode ===
Line 55: Line 62:


=== Using a linear frame buffer (LFB) ===
=== Using a linear frame buffer (LFB) ===
When using a linear frame buffer, the BGA exposes all of the graphics memory in a linear fashion, starting at address 0xE0000000 (VBE_DISPI_LFB_PHYSICAL_ADDRESS). [TODO: check whether this also goes for 4 BPP modes] To enable the LFB, use the VBE_DISPI_LFB_ENABLED flag (0x40) when enabling the VBE extensions (so write a value of VBE_DISPI_INDEX_ENABLE | VBE_DISPI_LFB_ENABLED (0x41)). [TODO: check whether Bochs still exposes 0xA0000 for use, and if so whether banked mode still works]
When using a linear frame buffer, the BGA exposes all of the graphics memory in a linear fashion, starting at address 0xE0000000 (VBE_DISPI_LFB_PHYSICAL_ADDRESS). [TODO: check whether this also goes for 4 BPP modes] To enable the LFB, use the VBE_DISPI_LFB_ENABLED flag (0x40) when enabling the VBE extensions (so write a value of VBE_DISPI_INDEX_ENABLE | VBE_DISPI_LFB_ENABLED (0x41)).

QEMU does not pay attention to the VBE_DISPI_LFB_ENABLED flag. Both the linear frame buffer and memory bank are available at all times. Bochs pays attention to the flag. In LFB mode it ignores requests to change the bank and nothing happens when you write to the bank memory. In banked mode nothing happens when you write to the LFB memory.


=== Clearing display memory ===
=== Clearing display memory ===