Setting VESA info from unreal mode

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.
Post Reply
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Setting VESA info from unreal mode

Post by AJ »

Hi,

Until now, all my kernel attempts have been TUI-only 80*25 with statically linked video "driver". I am now hoping to enter the world of VESA, with dynamically-loadable video drivers and am wondering how to do the switch.

I currently have a second-stage boot loader which takes over from GRUB, does a few things and then loads my kernel (which is loaded to RAM as a GRUB module). I think the easiest way to get VESA information and set the video mode may be to drop straight back to unreal mode and call the BIOS functions as required.

Not being an "official" Intel mode, I have never used or trusted unreal mode until now. Am I right in thinking I just disable PE, execute my 16-bit code, re-enable PE and I'm away, or is it more complex than that? Are there any pitfalls to avoid? I'm reading references from the old faq at the moment because I don't think the pages have been moved yet.

Cheers,
Adam
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

OK,

I just had a go at implementing this and the switch to and from unreal mode seems to work very well.

The problem is in the implementation :) . When I call 0x10, I get Bochs continually repeating:

Code: Select all

IRETD: Instruction pointer not within code segment limits
At this point, the BIOS seems to have set CS, DS and ES to 0, and ESP is 0xFFFF4, despite the fact that I set it to 0x2000 prior to calling the interrupt. I have left the Real Mode IVT in place and have not yet enabled paging - the system is pretty much in the state it was in when GRUB called my secondary boot loader.

Any help with voodoo mode much appreciated!

Cheers,
Adam
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

I written a demo to change vesa mode, by going to and from pmode to realmode.
Let me know if you want me to post it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi Dex,

If you wouldn't mind, that would be extremely useful.

After a few unreal mode attempts, I am looking at a more 'official' way of doing it and am investigating doing it with v86. Hopefully, if I see your way too, I can make a better design decision in the end.

Cheers,
Adam
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Setting VESA info from unreal mode

Post by Brendan »

Hi,
AJ wrote:Am I right in thinking I just disable PE, execute my 16-bit code, re-enable PE and I'm away, or is it more complex than that?
It's a little bit more complex than that - you need to load SS and CS with 16-bit protected mode segments first, then turn off protected mode.

If you don't, then the CPU may still think (for e.g.) that the stack uses a 32-bit default size, and that 16-bit pushes and pops should be aligned to a 4 byte boundary, so that that something like "push ax" becomes the equivelent of "sub sp,4; mov [ss:sp},ax" instead of "sub sp,2; mov [ss:sp},ax" (like it should be in real mode, with a 16-bit stack).

The full thing would go like this:
  • - load CS and SS with 16-bit protected mode segments (16-bit default operand and address size and 64 KB limit)
    - (optionally) load DS, ES, FS, GS with 16-bit protected mode segments (default size doesn't matter, but for true real mode you'd want 64 KB limits - skip this step for unreal mode)
    - disable protected mode in CR0
    - load real mode values into segment registers (e.g. so that DS = 0 instead of 0x020, CS = 0x2000 instead of 0x0018, etc)
    - enable IRQs
    - do the BIOS stuff
    - disable IRQs
    - load GDT (just in case)
    - enable protected mode
    - load segment registers
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.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Here you go http://www.dex4u.com/demos/DemoVesa.zip
NOTE: I was called "ASHLEY4" when i make it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Thanks for posting that Dex, but I'm getting a 404 at the moment - I'll try again later in case connectivity is on-and-off at the moment!

Thanks Brendan too - I'm looking at that now.

Cheers,
Adam
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Sorry thought you had got it, i have re-uploaded it, so just try again.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Cheers, got it!

Adam
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

I've just had a look through all the possible methods (and tried some implementation) and found that v86 is actually a lot easier than expected. I had thought that I would need full multitasking capabilities in my secondary boot loader in order for this to work, but it's actually nearly as easy as a couple of iret's!

The code provided by Dex still makes for informative reading, though. I may be able to post some basic VMM code when I have the full VBE calls working.

Cheers,
Adam
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

Thanks again for eveyone's help. I have just had a bit of time and have successfully plotted a single white pixel in the top corner of a 1024x768x16 screen! I never knew anyone could be so happy over a white spot :)

Next on the list - writing fonts to my new graphics mode screen!

Cheers,
Adam
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

AJ wrote:Next on the list - writing fonts to my new graphics mode screen!
Try sdl_picofont - I'm sure you can figure out how to get the fonts to display without SDL (or you might want to try implementing SDL for an added bonus :D).
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

AJ wrote:Hi,

Thanks again for eveyone's help. I have just had a bit of time and have successfully plotted a single white pixel in the top corner of a 1024x768x16 screen! I never knew anyone could be so happy over a white spot :)

Next on the list - writing fonts to my new graphics mode screen!

Cheers,
Adam
Cool 8), i know that happy feeling when your OS progress a step closer to your OS goal, them happy feeling are what keeps you going when things get tough.
So congratulations.

PS: For fonts you have a bit aray the size of font, eg simple basic 0
01110
10001
10001
01110
Test each bit if its a 0 move over one pixel, if its a 1 plot a pixal etc, when you come to the end of first row add screen with - with of font, for the next row until your finished.
This is just for basic vesa fonts.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

pcmattman wrote:Try sdl_picofont - I'm sure you can figure out how to get the fonts to display without SDL (or you might want to try implementing SDL for an added bonus :D).
Thanks for that. I tried implementing my own 8x8 font initially but it was a disaster - I have absolutely no artistic taled whatsoever! Adapting picofont made my console look so much better!

Adam
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

AJ wrote:
pcmattman wrote:Try sdl_picofont - I'm sure you can figure out how to get the fonts to display without SDL (or you might want to try implementing SDL for an added bonus :D).
Thanks for that. I tried implementing my own 8x8 font initially but it was a disaster - I have absolutely no artistic taled whatsoever! Adapting picofont made my console look so much better!
I learn from experience, so you benefit from that.

I have no idea how to do more complex fonts though (eg. TrueType fonts) - though it would be nice.
Post Reply