OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Sep 19, 2019 5:09 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 88 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 8:30 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Hello everyone
I'm struggling to enable high res graphics on early startup without V86 emulator. I have searched on forums and they said I can do it by switching back to real mode or do it in the bootloader. But I'm using grub as bootloader and I saw on some forums that they said grub has some modules for initializing VBE. I seached for grub modules and saw there are some modules named vbe, video and gfx. So can anyone tell me how to use these modules to setup VBE and draw pixels on screen or set and get supported screen resolutions and change them please?

I dont want that ugly 16 color 80x25 Text mode screen. I want to write my own colorful text gui :P


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 9:29 am 
Offline

Joined: Mon Oct 14, 2013 3:53 pm
Posts: 10
If your kernel is multiboot-compliant, you can simply extend your multiboot header to specify a graphics mode for GRUB to switch into:

Code:
.set ALIGN,    1 << 0
.set MEMINFO,  1 << 1
.set VIDINFO,  1 << 2
.set FLAGS,    ALIGN | MEMINFO | VIDINFO
.set MAGIC,    0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)

.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.long 0, 0, 0, 0, 0
.long 0 # 0 = set graphics mode
.long 1024, 768, 32 # Width, height, depth

(See this file for some more detailed explanations)

You will probably also need to access the multiboot structure that GRUB gives you a pointer to in EBX (it's a physical address!) to get the VBE info structure, in which you can locate where in memory (physical, again, so you'll need to map this to your virtual address space) the linear framebuffer is. From there, if you have either 16bpp or 32bpp modes, it's as simple as writing an RGB value to that memory location.

I also wrote a framebuffer console, here, which may be of interest to you.


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 10:13 am 
Offline
Member
Member

Joined: Mon Jan 07, 2013 10:38 am
Posts: 62
Quote:
If your kernel is multiboot-compliant, you can simply extend your multiboot header to specify a graphics mode for GRUB to switch into:


this doesn't work with legacy grub


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 11:03 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
@dansmahajan I'm using GRUB2. I know that, GRUB legacy needs a patch for this. But I don't know how to use that module in GRUB2

@tristanseifert my kernel is multiboot-compliant. I want to ask if you allow me to see and use some pieces of your svga.c and fb_console.c codes. They are the exact thing I have allways been looking for :D
And 1 other question. If I setup an ISO image of my kernel with GRUB as bootloader, how should I tell it to use VGA or SVGA modules and what screen resolution should it setup VBE with?

And one last question. Should I detect the framebuffer offset or its allways at 0xD0000000 or the VBE info tells me where is it?


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 11:36 am 
Offline
Member
Member

Joined: Mon Jan 07, 2013 10:38 am
Posts: 62
Quote:
And 1 other question. If I setup an ISO image of my kernel with GRUB as bootloader, how should I tell it to use VGA or SVGA modules and what screen resolution should it setup VBE with?


@tristanseifert has already explained this..look at the last

Code:
.long 0, 0, 0, 0, 0
.long 0 # 0 = set graphics mode
.long 1024, 768, 32 # Width, height, depth


Quote:
If your kernel is multiboot-compliant, you can simply extend your multiboot header to specify a graphics mode for GRUB to switch into:

Code:
.set ALIGN, 1 << 0
.set MEMINFO, 1 << 1
.set VIDINFO, 1 << 2
.set FLAGS, ALIGN | MEMINFO | VIDINFO
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)

.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.long 0, 0, 0, 0, 0
.long 0 # 0 = set graphics mode
.long 1024, 768, 32 # Width, height, depth

(See this file for some more detailed explanations)

You will probably also need to access the multiboot structure that GRUB gives you a pointer to in EBX (it's a physical address!) to get the VBE info structure, in which you can locate where in memory (physical, again, so you'll need to map this to your virtual address space) the linear framebuffer is. From there, if you have either 16bpp or 32bpp modes, it's as simple as writing an RGB value to that memory location.


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 12:28 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
So there should be no special parameters or other stuff when creating the iso image with grub. Right?
Then how can I change the resolution later?


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 12:53 pm 
Offline

Joined: Mon Oct 14, 2013 3:53 pm
Posts: 10
MadZarx wrote:
So there should be no special parameters or other stuff when creating the iso image with grub. Right?
Then how can I change the resolution later?


You would use the VBE graphics BIOS calls. You could drop back into real mode, use V8086 mode and write a BIOS monitor to let you access other BIOS functions.


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 1:50 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
tristanseifert wrote:
You would use the VBE graphics BIOS calls. You could drop back into real mode, use V8086 mode and write a BIOS monitor to let you access other BIOS functions.


Yeah. Thanks alot for your help. Now I can have my own fonts and gui.
Thank you guys so much


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Tue Dec 10, 2013 11:48 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

For multi-boot 1 (which is supported by GRUB, GRUB2, and a few other things); you can put the "preferred video mode" in your file's multiboot header. This "preferred video mode" is only a recommendation and the boot loader is free to ignore it or choose a similar video mode. For example, if kernel doesn't support 15-bpp modes at all and asks for "800*600 with 32 bits per pixel", then you might get 800*600 with 15 bits per pixel (there's no way to prevent the boot loader from choosing video modes you don't support). Also note that the code in most boot loaders is crap and won't (e.g.) use the monitor's EDID to ensure that the video mode you've requested is actually supported by the monitor; which means that even if you do get what you asked for it may be unusable.

For multi-boot 1, the specification says that the boot loader has to "leave the environment usable" but does not say what that environment might be, and there's no way to determine what the environment was. If you switch back to real mode and use BIOS functions then it will work if the boot loader was booted from a BIOS environment; but it will crash if the boot loader was booted from anything else (e.g. UEFI) and there's no way to prevent that.

Finally, for some cases (e.g. a decent UEFI system) the environment supports multiple monitors. Neither of these options will ever be able to support this.


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.


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Wed Dec 11, 2013 1:06 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Brendan wrote:
Hi,

For multi-boot 1 (which is supported by GRUB, GRUB2, and a few other things); you can put the "preferred video mode" in your file's multiboot header. This "preferred video mode" is only a recommendation and the boot loader is free to ignore it or choose a similar video mode. For example, if kernel doesn't support 15-bpp modes at all and asks for "800*600 with 32 bits per pixel", then you might get 800*600 with 15 bits per pixel (there's no way to prevent the boot loader from choosing video modes you don't support). Also note that the code in most boot loaders is crap and won't (e.g.) use the monitor's EDID to ensure that the video mode you've requested is actually supported by the monitor; which means that even if you do get what you asked for it may be unusable.

For multi-boot 1, the specification says that the boot loader has to "leave the environment usable" but does not say what that environment might be, and there's no way to determine what the environment was. If you switch back to real mode and use BIOS functions then it will work if the boot loader was booted from a BIOS environment; but it will crash if the boot loader was booted from anything else (e.g. UEFI) and there's no way to prevent that.

Finally, for some cases (e.g. a decent UEFI system) the environment supports multiple monitors. Neither of these options will ever be able to support this.


Cheers,

Brendan



So as you said, the kernel might be loaded with wrong bbp. So whats the best way to use graphics (If possible in early stages). I know I can use V86 mode but for that, It should be in user space and I haven't arrived to user space. One other choise is to switch back to real mode and call BIOS interrupts. But as you said I cannot do it if I use GRUB or other bootloaders. One last possible way is to write a vga driver. But I need at least the 800x640 resolution :(
So what is the best way to get it working??


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Wed Dec 11, 2013 2:55 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9284
Location: On the balcony, watching the Swedish Chef
MadZarx wrote:
I need at least the 800x640 resolution :(
Why exactly those sizes?

Quote:
So what is the best way to get it working??
Design how you want it to work in the end, then implement a subset of it that happens to work for just the cases you're interested in. Simply painting the screen red and stopping if the bit depth isn't 32 after grub is done with it will still mean you get a working environment on most hardware (and an obvious todo message otherwise).

_________________
"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 ]


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Wed Dec 11, 2013 4:56 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
I want this resolution because the font gets smaller in higher resolutions.
Sorry my English is a little weak and i didnt understand a part of your post. You meam if the screen gets painted in red, it means grub has give me the exact resolution? :O


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Wed Dec 11, 2013 3:21 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Guys when I want to use the graphics mode, the qemu gives me this error:
Code:
    qemu: multiboot knows VBE. We don't.

I have also used "-vga vmware" in qemu arguments but it gives me the same result.
I cant get the graphics working. But still I can use text mode :(

I have no idea that whats wrong with it but here is the multiboot code I use to enable VBE:
Code:
## the multiboot header
.set ALIGN,     1 << 0
.set MEMINFO,   1 << 1
.set VIDINFO,   1 << 2
.set FLAGS,     ALIGN | MEMINFO | VIDINFO
.set MAGIC,     0x1BADB002
.set CHECKSUM,  -(MAGIC + FLAGS)

.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
.long 0 # unused
.long 0 # .
.long 0 # .
.long 0 # .
.long 0 # unused
.long 0 # set graphics mode
.long 800 # screen witdh
.long 600 # screen height
.long 24 # bpp


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Wed Dec 11, 2013 3:29 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9284
Location: On the balcony, watching the Swedish Chef
qemu -kernel is ugly. It also doesn't work that way on real hardware. Therefore, don't use it.

_________________
"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 ]


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Wed Dec 11, 2013 4:01 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Combuster wrote:
qemu -kernel is ugly. It also doesn't work that way on real hardware. Therefore, don't use it.


You mean I shouldn't use -kernel argument? So what should I do to get the graphics working? I'm sure there's no problem with my code. I think qemu cant load it, maybe? :mrgreen:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 88 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group