VBE from protected mode with vm86
Posted: Wed Jul 07, 2010 11:06 am
Hello everybody,
I want to implement a small VBE driver which changes video modes and draws into framebuffer from protected mode.
For all the BIOS legacy stuff, I want to use the VM86 mode.
As far as I read howtos and sample code I already understand how this mode works and what I need to do to set it up.
What I don't get yet is, how I'm able to call INTO the BIOS. Calling out of the BIOS (at least from sight of the running realmode program) is easy. Run your INT as you would do in real mode and then emulate it in protected mode.
So, normally I have a DOS Program, load it, set up the VM86 Environment and let it run. As soon as an INT instruction, port I/O or stuff like that happens a GPF Exception occurs. I catch the exception, emulate the desired behaviour and return back into the execution of the DOS Code. So far, so good.
But what about the other direction? When I want to query all video modes from VBE in protected mode, it is my obligation to execute the BIOS code which is responsible for this. In realmode, you would execute an interrupt and the handler inside the BIOS is executed.
Now, with VM86, I somehow need to trap into the this handler of the BIOS by myself to run this code. How is this done? Do I need to look them up in the IVT from the BIOS and then modify the vm86 stack to jump there?
Also, let's assume I don't have a realmode program I want to run but only call the realmode BIOS routines from protected mode. What about this? Find the entrypoint of the desired interrupt handler in the IVT of the BIOS, modify the environment to land at this interrupt handler and then, after the handler executed and "ireted", I terminate this fake environment again?
Another question is, how does the BIOS code then configure the graphics adapter? Is it done with port I/O? I think so.
But which ports are accessed? I need to set up the iopriv bitmask somehow.
This is insane, just for switching video modes...
edit:
Yes, I know that there is a patched GRUB for this. I don't want to use it.
I could also switch back to unreal mode just after I got loaded from GRUB. I don't want to do this either.
I want to be able to control the video card whenever I want to. Not just directly after boot and then never again in the running software.
Also it looks kinda hacky to me if I need to change my startup code to change a video mode. There are computers without VGA and just a serial line. How should I handle this? One big ifdef to compile different code? Or perhaps parsing the whole kernel commandline to know wether I need to do the switch in such an early boot stage? No, thank you...
I want to implement a small VBE driver which changes video modes and draws into framebuffer from protected mode.
For all the BIOS legacy stuff, I want to use the VM86 mode.
As far as I read howtos and sample code I already understand how this mode works and what I need to do to set it up.
What I don't get yet is, how I'm able to call INTO the BIOS. Calling out of the BIOS (at least from sight of the running realmode program) is easy. Run your INT as you would do in real mode and then emulate it in protected mode.
So, normally I have a DOS Program, load it, set up the VM86 Environment and let it run. As soon as an INT instruction, port I/O or stuff like that happens a GPF Exception occurs. I catch the exception, emulate the desired behaviour and return back into the execution of the DOS Code. So far, so good.
But what about the other direction? When I want to query all video modes from VBE in protected mode, it is my obligation to execute the BIOS code which is responsible for this. In realmode, you would execute an interrupt and the handler inside the BIOS is executed.
Now, with VM86, I somehow need to trap into the this handler of the BIOS by myself to run this code. How is this done? Do I need to look them up in the IVT from the BIOS and then modify the vm86 stack to jump there?
Also, let's assume I don't have a realmode program I want to run but only call the realmode BIOS routines from protected mode. What about this? Find the entrypoint of the desired interrupt handler in the IVT of the BIOS, modify the environment to land at this interrupt handler and then, after the handler executed and "ireted", I terminate this fake environment again?
Another question is, how does the BIOS code then configure the graphics adapter? Is it done with port I/O? I think so.
But which ports are accessed? I need to set up the iopriv bitmask somehow.
This is insane, just for switching video modes...
edit:
Yes, I know that there is a patched GRUB for this. I don't want to use it.
I could also switch back to unreal mode just after I got loaded from GRUB. I don't want to do this either.
I want to be able to control the video card whenever I want to. Not just directly after boot and then never again in the running software.
Also it looks kinda hacky to me if I need to change my startup code to change a video mode. There are computers without VGA and just a serial line. How should I handle this? One big ifdef to compile different code? Or perhaps parsing the whole kernel commandline to know wether I need to do the switch in such an early boot stage? No, thank you...