Running a VBE Bios or VESA Bios?

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.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Running a VBE Bios or VESA Bios?

Post by PearOs »

Ok so I have read a few times about a myth that I never could quite understand. So I came here to ask you guys. :D Alright. So I would like to have high res graphics, I don't really want to write graphic specific drivers because it's a massive pain and a massive time consumer. So I read about the possibility of emulating, or writing a 16bit virtual machine to run in my Protected Mode operating system, and then run the VBE Bios in that. Though, what I don't understand is, where can I find the VBE Bios that will be ran, and how does that work? I mean I am in Protected Mode so how does running the VBE Bios in a 16bit emulator allow me to call VBE Bios calls?


Thanks,


Matt
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Running a VBE Bios or VESA Bios?

Post by Nessphoro »

Well your emulator knows what the BIOS is doing and can forward the commands to the real hardware. Your emulator can figure out what to execute by looking at the IVT.
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Running a VBE Bios or VESA Bios?

Post by Nessphoro »

I don't really understand your issue.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Running a VBE Bios or VESA Bios?

Post by PearOs »

Nessphoro wrote:I don't really understand your issue.
Basically I want to write a 8086 Emulator to access real mode BIOS interrupts. What I am wondering and trying to understand is how a Real Mode Emulator running in Protected Mode allows BIOS interrupts. Is this because the BIOS code running in the Emulator for example when you call Int10h is called, the code behind that interrupt is ran in the Emulator right?

Thanks, Matt


I'm trying to access the VBE in Protected mode by writing an Emulator.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Running a VBE Bios or VESA Bios?

Post by Brendan »

Hi,
PearOs wrote:Basically I want to write a 8086 Emulator to access real mode BIOS interrupts. What I am wondering and trying to understand is how a Real Mode Emulator running in Protected Mode allows BIOS interrupts. Is this because the BIOS code running in the Emulator for example when you call Int10h is called, the code behind that interrupt is ran in the Emulator right?
If the emulator emulates the BIOS/VBE code's instructions but reads/writes to real physical addresses and IO ports, then any devices (that respond to reads/writes to those real physical addresses and IO ports) won't know the difference. In that way you can (in theory) run BIOS/VBE code, including software interrupts and IRQ handlers.

However; the BIOS/VBE code makes assumptions about the state of hardware, and the hardware's state must match
the assumptions that BIOS/VBE code makes for those reads/writes to real physical addresses and IO ports to work correctly. For a simple example; if you reconfigure the PIC chips like you should, then any BIOS code that accesses the PIC chip/s will get all confused and broken. To fix that you could also emulate the PIC chips, so that you can reconfigure the real PIC chips and emulate fake PIC chips to satisfy the BIOS. The same applies to any hardware that you touch (e.g. emulate any/all hardware that you've reconfigured, to keep the BIOS/VBE happy).

Of course a decent OS will take full control of all hardware (including reconfiguring PIC chips, reserving the right to change PCI configuration space for any/all devices, using all RAM for whatever it likes, etc); and an OS that isn't crap will also be designed to support UEFI one day (where there's no guarantee that any hardware was ever in the state that VBE code expects and no guarantee that the video card itself actually has a ROM containing VBE). For these reasons it's far better to set a high resolution video mode during boot using whatever services the firmware provides (VBE for BIOS, and UGA or GOP for UEFI), before the OS starts doing its job (e.g. before the OS takes control of the computer and starts reconfiguring everything to suit itself). In this case you have no need for a large, complex/unstable, slow and ugly emulator to execute code that may or may not exist.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Running a VBE Bios or VESA Bios?

Post by Antti »

I think that using BIOS services after entering Protected Mode/Long Mode is a bad idea. It should be a one-way street. Use all necessary services while you are still in Real Mode when the boot loader runs. Like setting the VBE video mode. Going back to Real Mode should be avoided at any cost.

All the Virtual 8086 Mode / Emulator hacks should be avoided as well. Newer versions of VBE support an interface that can be used in Protected Mode and using that would be lightly less wrong. However, it is not elegant to use BIOS services while the OS runs.

This is just my point of view. Of course, people are allowed to create a modern Real Mode OS: an OS that runs in Protected Mode but is like a Real Mode OS.

EDIT: I wrote this before Brendan's post but I was too slow. Due to this, better reasoning was already available above.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Running a VBE Bios or VESA Bios?

Post by Combuster »

Of course the most elegant solution would be to have drivers for everything. Sadly, that's not an option for everyone except m$ either :wink:

Therefore, concessions.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Running a VBE Bios or VESA Bios?

Post by Antti »

Combuster wrote:Of course the most elegant solution would be to have drivers for everything
You would still be able to use the video mode you set earlier. I think it is a good compromise for hobby OSs.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Running a VBE Bios or VESA Bios?

Post by PearOs »

Wow thanks for all the replies guys. So I guess I have two options then.

1. In Real Mode set the Graphics Mode and then manipulate the screen in Protected Mode.
2. Make a 8086 Emulator and hopefully emulate the VBE Bios.

I love to program for operating systems. So I guess trying both would be a good learning experiment. So where can I find the VBE Bios that the Emulator would run?

Now off to the second part. I guess I can try the first option. Though my bootloader sticks me in Protected Mode automatically. I am using isolinux. So I guess go back to real mode and then protected mode? Even then how do I set a mode, and then manipulate pixels in Protected Mode? Are there any good code examples of this?

Another question, has there ever been an Open Source OS that has successfully used the VBE Bios in an Emulator in their OS?

Thanks Guys,

Matt
madanra
Member
Member
Posts: 149
Joined: Mon Sep 07, 2009 12:01 pm

Re: Running a VBE Bios or VESA Bios?

Post by madanra »

You can find the VBE BIOS by looking up where int 0x10 points to in the interrupt table.

Returning to real mode might work - though if isolinux has changed any hardware configuration, there could well be problems; switching back to real mode isn't generally recommended. Ideally any video mode changes would be done before switching to protected mode. GRUB allows you to specify what resolution you want in the multiboot header, so if you're able to use GRUB instead of isolinux then that's an easy way to do it.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Running a VBE Bios or VESA Bios?

Post by Owen »

One thing of note is that X.Org contains support for running a VESA BIOS on non-PC platforms.

Most VESA BIOSes don't have any real dependencies on the system BIOS.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Running a VBE Bios or VESA Bios?

Post by PearOs »

madanra wrote:You can find the VBE BIOS by looking up where int 0x10 points to in the interrupt table.

Returning to real mode might work - though if isolinux has changed any hardware configuration, there could well be problems; switching back to real mode isn't generally recommended. Ideally any video mode changes would be done before switching to protected mode. GRUB allows you to specify what resolution you want in the multiboot header, so if you're able to use GRUB instead of isolinux then that's an easy way to do it.
I agree. Ok so that's a good start. Now since I am in protected mode, sorry if this sounds noobish. I have never really done this before, isn't INT 10h remapped because I setup my own table so that I could get interrupts working. Or is it still intact somehow? Thanks, Matt
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Running a VBE Bios or VESA Bios?

Post by PearOs »

Owen wrote:One thing of note is that X.Org contains support for running a VESA BIOS on non-PC platforms.

Most VESA BIOSes don't have any real dependencies on the system BIOS.

Interesting, if you could point me to where that's located that would be really useful. I am curious as to how they are doing that, most likely emulating. Thanks, Matt
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Running a VBE Bios or VESA Bios?

Post by Combuster »

It's called libx86emu
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
madanra
Member
Member
Posts: 149
Joined: Mon Sep 07, 2009 12:01 pm

Re: Running a VBE Bios or VESA Bios?

Post by madanra »

PearOs wrote:I have never really done this before, isn't INT 10h remapped because I setup my own table so that I could get interrupts working. Or is it still intact somehow?
The real mode Interrupt Vector Table (IVT) is stored in the first 1KB of RAM, so you can look it up there, as long as neither isolinux nor your OS has overwritten that part of RAM.
Post Reply