Page 1 of 3

Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 12:32 pm
by rdos
I think I will start on this now that I've solved the USB-issues. In order to be able to boot from UEFI, I first must remove the reliance my VBE driver has on the real BIOS.

One way to do this would be to take some emulator BIOS and run it in an emulator, but I find this both slow and overkill. I don't think the VBE requires many of the fancy BIOS functions. Thus, I instead plan to run a virtual BIOS in VM86-mode.

If I implement the card-detection & startup procedure that the BIOS normally does at boot, and set all interrupts to go to a dummy interrupt handler that contains an "int 3", I can figure out what really is needed. Then I should probably also initialize the BDA to something reasonable.

Somebody should already have done this, but I guess the big OSes either use the emulator approach, or has non-open source code.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 1:00 pm
by Antti
This does not sound very good. Why do you want to have such an unrealiable hack? It will not work very long. Use Graphics Output Protocol (GOP) or write native drivers.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 1:25 pm
by Owen
You'll find the (ratsnest) of code which implements VBE on both PC+BIOS and NonPC at the int10 section of the XOrg source

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 1:26 pm
by rdos
Antti wrote:This does not sound very good. Why do you want to have such an unrealiable hack? It will not work very long. Use Graphics Output Protocol (GOP) or write native drivers.
I need it in order to be able to boot from UEFI, since my current code depends on it. In addition to that, I want to avoid GOP as long as possible, and hope that video cards will continue to support VBE even in the absence of a BIOS which can enable it.

In fact, I don't see how GOP could work with a random video-card without some kind of code in the video card, which I suspect is the VBE interface today. I don't think that GOP will provide native drivers for every imaginable video-card. It might in laptops, but not in stationary computers that can use an external video-card.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 1:58 pm
by Owen
GOP works the same way VBE does. That is, the card provides the driver in an option ROM!

Just, this time the driver is a UEFI driver rather than a VBE one.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 2:22 pm
by PearOs
rdos wrote:I think I will start on this now that I've solved the USB-issues. In order to be able to boot from UEFI, I first must remove the reliance my VBE driver has on the real BIOS.

One way to do this would be to take some emulator BIOS and run it in an emulator, but I find this both slow and overkill. I don't think the VBE requires many of the fancy BIOS functions. Thus, I instead plan to run a virtual BIOS in VM86-mode.

If I implement the card-detection & startup procedure that the BIOS normally does at boot, and set all interrupts to go to a dummy interrupt handler that contains an "int 3", I can figure out what really is needed. Then I should probably also initialize the BDA to something reasonable.

Somebody should already have done this, but I guess the big OSes either use the emulator approach, or has non-open source code.

Edit: Wait Nvm, your trying to use UEFI. In that case your only hope is an emulator..

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 3:59 pm
by rdos
On my Sony Vaio portable, it works with an empty int 15 handler. The video initialization routine (0xC000:0x0003) calls the int 15 handler with AH=5F a couple of times (which I return unsupported function for), and then gives up. When I call the video mode change, nothing else happens, and it works very well. Will test on some other computers as well to see if it is as simple as that. :)

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 4:05 pm
by rdos
PearOs wrote:
rdos wrote:I think I will start on this now that I've solved the USB-issues. In order to be able to boot from UEFI, I first must remove the reliance my VBE driver has on the real BIOS.

One way to do this would be to take some emulator BIOS and run it in an emulator, but I find this both slow and overkill. I don't think the VBE requires many of the fancy BIOS functions. Thus, I instead plan to run a virtual BIOS in VM86-mode.

If I implement the card-detection & startup procedure that the BIOS normally does at boot, and set all interrupts to go to a dummy interrupt handler that contains an "int 3", I can figure out what really is needed. Then I should probably also initialize the BDA to something reasonable.

Somebody should already have done this, but I guess the big OSes either use the emulator approach, or has non-open source code.
Edit: Wait Nvm, your trying to use UEFI. In that case your only hope is an emulator..
Not so. I map the first page in VM86 mode to default interrupt vectors + a dummy int 15 + a zeroed BDA. Then I provide a BIOS which only calls the video initialization entry-point (C000:0003), and returns.
After that I call int 0x10 with AL=3 to set video mode to text. I do this before PCI initialization. UEFI can do nothing about this as long as there is a video BIOS at C000. UEFI is only software, and thus must initialize the video BIOS itself, which I then redo to my own preferences.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 4:06 pm
by PearOs
rdos wrote:
PearOs wrote:
rdos wrote:I think I will start on this now that I've solved the USB-issues. In order to be able to boot from UEFI, I first must remove the reliance my VBE driver has on the real BIOS.

One way to do this would be to take some emulator BIOS and run it in an emulator, but I find this both slow and overkill. I don't think the VBE requires many of the fancy BIOS functions. Thus, I instead plan to run a virtual BIOS in VM86-mode.

If I implement the card-detection & startup procedure that the BIOS normally does at boot, and set all interrupts to go to a dummy interrupt handler that contains an "int 3", I can figure out what really is needed. Then I should probably also initialize the BDA to something reasonable.

Somebody should already have done this, but I guess the big OSes either use the emulator approach, or has non-open source code.
Edit: Wait Nvm, your trying to use UEFI. In that case your only hope is an emulator..
Not so. I map the first page in VM86 mode to default interrupt vectors + a dummy int 15 + a zeroed BDA. Then I provide a BIOS which only calls the video initialization entry-point (C000:0003), and returns.
After that I call int 0x10 with AL=3 to set video mode to text. I do this before PCI initialization. UEFI can do nothing about this as long as there is a video BIOS at C000. UEFI is only software, and thus must initialize the video BIOS itself, which I then redo to my own preferences.
Interesting. I will have to remember that when I attempt UEFI some day.. *shudder*

Edit: But wait, one Video Bios doesn't work with every board does it?

Thanks, Matt

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 4:20 pm
by Owen
Repeating what I said earlier: the graphics card provides the video BIOS. It also provides the video UEFI.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 4:48 pm
by rdos
Owen wrote:Repeating what I said earlier: the graphics card provides the video BIOS. It also provides the video UEFI.
Possible. However, if you plug in the video card in a stationary PC in some PCI-slot, then the systems UEFI has no idea about the card, and the card thus cannot provide the GOP. The only thing it provides is a VBE BIOS. Which means the systems UEFI must use VBE to provide GOP.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 4:51 pm
by rdos
Confirmed that this also works on another laptop with an Intel Atom processor. Seems like most modern video BIOS doesn't use anything else than int 15, AH=5F in their initialization code, which makes it very easy to put them in VBE-mode. On older PCs it doesn't matter as those have no UEFI, and thus has to be booted with BIOS, and then the usual VBE driver which uses the real BIOS is more suitable.

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 5:33 pm
by devsau
I was going to make a new thread, but I saw this thread floating at the top and since my question is slightly related I figured why not just ask here.

Question is, anyone know if I can use the uefi setmode services for GOP to get the same resolution that my card offers using vesa/vbe?

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 5:37 pm
by rdos
Adding an error return for int 15, AH=4E, and I can run on two stationary AMD-based computers as well, one of them at least 5 years old. It seems like this is a working concept, and no emulator is needed. The virtual BIOS is only some 50 bytes long :)

Re: Emulating BIOS for VBE

Posted: Thu Dec 26, 2013 5:39 pm
by rdos
devsau wrote: Question is, anyone know if I can use the uefi setmode services for GOP to get the same resolution that my card offers using vesa/vbe?
I don't know, but I suspect the answer should be "yes". At least I don't think GOP will offer more resolutions than VBE, especially if GOP gathers information from VBE.