[Answered]How to detect Virtual Box (OS Level)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
WeirdEdEdison
Posts: 5
Joined: Sat Feb 22, 2014 6:42 am

Re: How to detect Virtual Box (OS Level)

Post by WeirdEdEdison »

Well, Bochs Graphics Adapter uses the BGRA pixel format in true color modes. So simply swap blue and red channel in the original putpixel.

http://wiki.osdev.org/BGA
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to detect Virtual Box (OS Level)

Post by BrightLight »

WeirdEdEdison wrote:Well, Bochs Graphics Adapter uses the BGRA pixel format in true color modes. So simply swap blue and red channel in the original putpixel.

http://wiki.osdev.org/BGA
Wrong. Bochs Graphics Adapter uses RGBA in 32-bit modes. I didn't look through the code, but something is wrong with it because it uses RGBA.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
WeirdEdEdison
Posts: 5
Joined: Sat Feb 22, 2014 6:42 am

Re: How to detect Virtual Box (OS Level)

Post by WeirdEdEdison »

omarrx024 wrote:Wrong. Bochs Graphics Adapter uses RGBA in 32-bit modes. I didn't look through the code, but something is wrong with it because it uses RGBA.
Well, that's what the OSDev Wiki says:
In 24 BPP each pixel is 3 bytes. There is one byte for each component. The colour components is blue first, then green, then red.
Image

In 32 BPP each pixel is 4 bytes and easiest accessed as longwords (32 bits). The fourth byte is ignored. The colour components is layout like in 24 BPP. Accessing pixels as longwords the colour should be defined as 0x00RRGGBB.
Image
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to detect Virtual Box (OS Level)

Post by BrightLight »

WeirdEdEdison wrote:In 32 BPP each pixel is 4 bytes and easiest accessed as longwords (32 bits). The fourth byte is ignored. The colour components is layout like in 24 BPP. Accessing pixels as longwords the colour should be defined as 0x00RRGGBB.
Image
Well, you should keep in mind that x86 is a little-endian architecture. The value 0x00RRGGBB will be layed out in memory as BB, GG, RR, 00. That doesn't mean Bochs uses BGRA; it uses RGBA.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: [Answered]How to detect Virtual Box (OS Level)

Post by onlyonemac »

Remember also that there are many more variations in real PC hardware out there than there are emulators, so being able to detect and work with many different hardware configurations rather than trying to distinguishing between three emulators specifically might be a more appropriate approach.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
WeirdEdEdison
Posts: 5
Joined: Sat Feb 22, 2014 6:42 am

Re: How to detect Virtual Box (OS Level)

Post by WeirdEdEdison »

omarrx024 wrote:
WeirdEdEdison wrote:In 32 BPP each pixel is 4 bytes and easiest accessed as longwords (32 bits). The fourth byte is ignored. The colour components is layout like in 24 BPP. Accessing pixels as longwords the colour should be defined as 0x00RRGGBB.
Image
Well, you should keep in mind that x86 is a little-endian architecture. The value 0x00RRGGBB will be layed out in memory as BB, GG, RR, 00. That doesn't mean Bochs uses BGRA; it uses RGBA.
What? That's the definition of BGRA. Blue channel first, then green, then red, then alpha (which is ignored by BGA, so it's actually BGRX). RGBA pixel format would have the red channel first, then green, then blue, then alpha.

That said, I second onlyonemac's thought. You should design your code to able to deal with a variety of pixel formats (and other hardware specifics) in the long run. You could still implement fast paths for specific formats anyway.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: [Answered]How to detect Virtual Box (OS Level)

Post by ~ »

You can take advantage of VESA since it has services to return the frame buffer address and other data for each video mode, so you could query each video mode.

You could then emulate the BIOS and thus use VESA either by using V86, writing an emulator or using an x86 emulator engine like x86emu or the one from Bochs.

See it to see how to get VESA information:
http://forum.osdev.org/viewtopic.php?f=2&t=30186

x86emu source code (for 64-bit mode or if you want to use software emulation for the BIOS -in a separate process- instead of V86):
http://devel.archefire.org/en/tmp/x86emu.zip
Post Reply