OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 6:27 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 88 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Wed Dec 11, 2013 10:59 pm 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
On qemu, you can quite easily add '-vga std' and use the BochsGA emulation (see the wiki). On real hardware, either drop to real mode very early in your code, or use a VM8086 hypervisor to run the bios (or write a native driver, but those are quite fun)

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


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

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
thepowersgang wrote:
On qemu, you can quite easily add '-vga std' and use the BochsGA emulation (see the wiki). On real hardware, either drop to real mode very early in your code, or use a VM8086 hypervisor to run the bios (or write a native driver, but those are quite fun)



I tried all qemu's vga emulations but it just gives me that error.
For VM86 I need to have a working user space. changing back to real mode to set some flags and call interrupts and change back to pmode is something trickey and I cant use it because I use GRUB as bootloader.
So I try to arrive to user mode as soon as I can to use a VM86 to enable graphics :D


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

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
MadZarx wrote:
I tried all qemu's vga emulations but it just gives me that error.


I didn't mean that it will make qemu support mutliboot's graphics fields, but it will allow you to write a very simple modesetting graphics driver.
Bochs_VBE_Extensions

VM8086 isn't that complex, but it does almost require a stable multitasking system.

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


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

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Is this method usable on real hardware? I mean the bochs VBE
Yet I'm working on a physical memory manager. few (But time consuming) steps are remaining to get the user mode :D
WoW then I can use VM86 :D :mrgreen: :mrgreen:


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

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

MadZarx wrote:
I want this resolution because the font gets smaller in higher resolutions.


What if one user has a tiny ("14 inch") monitor and needs large characters, and another user has a huge ("46 inch") monitor and needs small characters? What if one user has a "4:3" monitor and needs tall thin characters, and another user has a "16:10" monitor and needs wider/shorter characters?

The right way to do this is to set the video mode to "anything" (preferably the best resolution the monitor and video card support and/or the monitor's native resolution if possible); and then scale the font to suit both the size of the monitor and the resolution of the video mode to get the ideal width and height for characters in all cases. Note that the monitor can give you "EDID" information that says the physical width and height of the screen, which video modes the monitor supports and (e.g. for LCD monitors) the monitor's native resolution.

It also isn't too hard to "pre-scale" a bitmap font once during boot (and then use the already scaled font data after that with little/no impact on performance). For example, the last time I did it I started with "256*64, one bit per pixel" data (with run length encoding and some other tricks to reduce font data size) and scaled it to "x * y, 256-bit alpha per pixel" format that was actually used. This gave relatively good results (e.g. with recognisable small 5*6 characters and nice/smooth large characters).

MadZarx wrote:
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:


Normally, the firmware starts a boot loader (e.g. GRUB) and the boot loader starts your code (e.g. using multi-boot). Qemu has built-in support for starting multi-boot kernels directly with no boot loader, no file systems and no disk devices - the kernel just magically appears in RAM. Qemu's built in multi-boot support is nothing like how real computers work; and can be "differently compatible" with the multi-boot specification.


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: Thu Dec 12, 2013 12:17 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Brendan wrote:
What if one user has a tiny ("14 inch") monitor and needs large characters, and another user has a huge ("46 inch") monitor and needs small characters? What if one user has a "4:3" monitor and needs tall thin characters, and another user has a "16:10" monitor and needs wider/shorter characters?

At this early stage I just want to use a small resolution and my own font instead of default text mode fonts and its small resolution. But later, When everything is ready to use VM86, I will add support for more resolutions :D

Brendan wrote:
Note that the monitor can give you "EDID" information that says the physical width and height of the screen, which video modes the monitor supports and (e.g. for LCD monitors) the monitor's native resolution.

I think VBE gives me the EDID?

Brendan wrote:
It also isn't too hard to "pre-scale" a bitmap font once during boot (and then use the already scaled font data after that with little/no impact on performance).

I want to use raw binary font (Of course if I get the graphics working :D )

Brendan wrote:
For example, the last time I did it I started with "256*64, one bit per pixel" data (with run length encoding and some other tricks to reduce font data size) and scaled it to "x * y, 256-bit alpha per pixel" format that was actually used. This gave relatively good results (e.g. with recognisable small 5*6 characters and nice/smooth large characters).

Thats so cool. But doesnt that font format slow down the print performance? Making a x*y 32 bytes character may reduce the performance :O

Brendan wrote:
MadZarx wrote:
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:


Normally, the firmware starts a boot loader (e.g. GRUB) and the boot loader starts your code (e.g. using multi-boot). Qemu has built-in support for starting multi-boot kernels directly with no boot loader, no file systems and no disk devices - the kernel just magically appears in RAM. Qemu's built in multi-boot support is nothing like how real computers work; and can be "differently compatible" with the multi-boot specification.


Cheers,

Brendan

You mean qemu can even load the kernel binary itself? Even without that small assembly kernel loader?
But in this early stages I cant risk and run my OS on a real hardware. It may crash the system :O


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

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

MadZarx wrote:
Brendan wrote:
What if one user has a tiny ("14 inch") monitor and needs large characters, and another user has a huge ("46 inch") monitor and needs small characters? What if one user has a "4:3" monitor and needs tall thin characters, and another user has a "16:10" monitor and needs wider/shorter characters?

At this early stage I just want to use a small resolution and my own font instead of default text mode fonts and its small resolution. But later, When everything is ready to use VM86, I will add support for more resolutions :D


I tend to not bother with VM86 - it doesn't work reliably for UEFI systems; and means the OS has to care what sort of firmware/environment the boot loader booted from. Most people don't change resolutions unless they're playing 3D games, and most people won't be playing 3D games (due to performance problems) unless there's a native video driver, so there isn't really any need to switch video modes after boot (unless there's a native video driver). It's enough to set the best video mode you can during boot.

MadZarx wrote:
Brendan wrote:
Note that the monitor can give you "EDID" information that says the physical width and height of the screen, which video modes the monitor supports and (e.g. for LCD monitors) the monitor's native resolution.

I think VBE gives me the EDID?


Yes - getting the EDID is very easy. It's just "blocks of data" though, so you'll have to parse it to extract the information you need.

MadZarx wrote:
Brendan wrote:
For example, the last time I did it I started with "256*64, one bit per pixel" data (with run length encoding and some other tricks to reduce font data size) and scaled it to "x * y, 256-bit alpha per pixel" format that was actually used. This gave relatively good results (e.g. with recognisable small 5*6 characters and nice/smooth large characters).

Thats so cool. But doesnt that font format slow down the print performance? Making a x*y 32 bytes character may reduce the performance :O


It depends on how good your code is. For a basic 2D GUI (text, windows, menus, icons, etc) your code would/should still be fast enough to get acceptable performance when running on Bochs (which is much slower than real computers). It also depends on how much other stuff your code does. For example; if you add something like dithering (which can be expensive) then the cost of drawing text is going to be unnoticeable in comparison.

MadZarx wrote:
Brendan wrote:
You mean qemu can even load the kernel binary itself? Even without that small assembly kernel loader?
But in this early stages I cant risk and run my OS on a real hardware. It may crash the system :O


As long as you don't write to hard drives or modify CMOS it's extremely difficult to do any harm (even if your code does crash).

It's always a very good idea to test on as many different (real and emulated) computers as possible; because different computers are different. It's too easy to have bugs in your code that don't cause symptoms and don't get noticed on some systems (and cause massive problems on other systems), and also too easy to end up effected by hardware and firmware bugs that your code failed to work around.

You'll also find that none of the emulators support EDID (it's hard to give information about the monitor when there isn't a real monitor and it's just a window running in some OS's GUI).


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: Fri Dec 13, 2013 1:20 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
So as you said, VM86 is not supported in UEFI systems. So the only ways for me to get graphics is swiching back to real mode or ask grub to give me the vbe information and enable it. But I cant use the real mode to get the vbe working cuz im using grub. so the only way is to ask grub and as one of the friends said, grub may give me wrong information.
So what should I do to get exactly the thing I want?


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Sat Dec 14, 2013 2:28 am 
Offline
Member
Member
User avatar

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

MadZarx wrote:
So as you said, VM86 is not supported in UEFI systems.


Not quite. VM86 is supported in protected mode (and not supported in long mode) regardless of what the firmware is (BIOS or UEFI). VBE functions don't exist if the firmware is UEFI though, so for the "32-bit UEFI" case VM86 can be used but there's nothing to use it for.

For UEFI, there are a set of functions (called "boot services") provided by UEFI that can only be used during boot, that includes functions to get EDID and setup video modes (similar to VBE but different), where these functions are run in protected mode or long mode (depending on whether the firmware uses 32-bit or 64-bit UEFI). After the "exit boot services" UEFI function is called none of these UEFI functions can be used. GRUB calls the "exit boot services" UEFI function for you; so after your code is started by GRUB the UEFI functions for setting up video modes can't be used.

MadZarx wrote:
So the only ways for me to get graphics is swiching back to real mode or ask grub to give me the vbe information and enable it. But I cant use the real mode to get the vbe working cuz im using grub. so the only way is to ask grub and as one of the friends said, grub may give me wrong information. So what should I do to get exactly the thing I want?


There's only really 2 choices:
  • You learn to live with the problems/limitations of GRUB and forget about ever getting exactly what you want. This can include supporting "plain text" as a fall-back option, supporting all possible video modes, and still having "no working video" (because GRUB chose a video mode that the monitor doesn't support)
  • You write your own code that does exactly what you want. This can include not using GRUB at all (especially on UEFI systems).


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: [SOLVED] Qestions about VESA/VBE
PostPosted: Sat Dec 14, 2013 2:55 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
So I should start writing my own bootloader :( This is going to take a long time :|

Thank you so much Brendan for your help :D


Top
 Profile  
 
 Post subject: Re: [SOLVED] Qestions about VESA/VBE
PostPosted: Sat Dec 14, 2013 3:39 am 
Offline
Member
Member
User avatar

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

MadZarx wrote:
So I should start writing my own bootloader :( This is going to take a long time :|

Thank you so much Brendan for your help :D


In that case, I'd recommend planning for at least 5 different boot loaders:
  • One for BIOS hard disk (partitions, etc)
  • One for BIOS floppy disk (no partitions, BPB)
  • One for BIOS network boot/PXE
  • One for BIOS "no emulation El Torito CD-ROM"
  • One for 64-bit UEFI

Note: "planning for" doesn't necessarily mean "implementing now". For example, you could start with one boot loader and worry about the others much much later on.

I'd also recommend designing some sort of specification that describes the way the boot loader/s hand control to the next piece (the kernel?); so that the kernel knows what state the computer is in (which CPU mode, if A20 is enabled/disabled, if it can assume anything about any devices, etc) and how/where to get information from the boot loader (memory map, video mode details for one or more monitors, boot log, etc); so that the kernel does not need to care what the boot loader (or the firmware) actually was; and so that anyone (including you later on) can look at your OS's "boot loader specification" and implement more boot loaders for your kernel.


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: Sat Dec 14, 2013 11:03 am 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Wow so that would be so great. Btw should I write a separate bootloader for each kind of cpu or BIOS?
And one more question, is there a way to use 16 bit C in bootloader? Assembly is something hard to read and understand so it would be great if i could write the stage 2 of bootloader in C


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Sun Dec 15, 2013 4:58 am 
Offline
Member
Member
User avatar

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

MadZarx wrote:
Wow so that would be so great. Btw should I write a separate bootloader for each kind of cpu or BIOS?


You will need to write a separate bootloader for each different kind of CPU (e.g. 80x86, ARM, PowerPC, etc); but you won't need a separate bootloader for each different "sub-kind" (e.g. Intel 80x86, AMD 80x86, VIA 80x86, etc).

You will need a separate bootloader for each different kind of firmware (e.g. BIOS, UEFI, OpenFirmware, etc). In some cases (e.g. BIOS) you will also need a separate bootloader for each category of boot device, but in other cases (UEFI) a single bootloader covers all types of boot device.

MadZarx wrote:
And one more question, is there a way to use 16 bit C in bootloader? Assembly is something hard to read and understand so it would be great if i could write the stage 2 of bootloader in C


You probably can find a C compiler that is able to generate 16-bit code. None of the BIOS functions use C calling conventions though, so at a minimum you'd need assembly wrappers for them. Those wrappers could also switch from 32-bit to 16-bit and back (so that you can use 32-bit C); and those wrappers could be implemented in "stage 1" (allowing you to have a stage 2 that only contains 32-bit code, which uses an API provided by stage 1 to do the dirty work).


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: Sun Dec 15, 2013 1:34 pm 
Offline
Member
Member

Joined: Mon Apr 01, 2013 5:06 am
Posts: 85
Location: CMOS :D
Brendan wrote:
Hi,
You will need to write a separate bootloader for each different kind of CPU (e.g. 80x86, ARM, PowerPC, etc); but you won't need a separate bootloader for each different "sub-kind" (e.g. Intel 80x86, AMD 80x86, VIA 80x86, etc).

You will need a separate bootloader for each different kind of firmware (e.g. BIOS, UEFI, OpenFirmware, etc). In some cases (e.g. BIOS) you will also need a separate bootloader for each category of boot device, but in other cases (UEFI) a single bootloader covers all types of boot device.

So is there a way to write a portable bootloader that these frimwares can support? Or they have different interrupts and this is not possible?

Brendan wrote:
MadZarx wrote:
And one more question, is there a way to use 16 bit C in bootloader? Assembly is something hard to read and understand so it would be great if i could write the stage 2 of bootloader in C


You probably can find a C compiler that is able to generate 16-bit code. None of the BIOS functions use C calling conventions though, so at a minimum you'd need assembly wrappers for them. Those wrappers could also switch from 32-bit to 16-bit and back (so that you can use 32-bit C); and those wrappers could be implemented in "stage 1" (allowing you to have a stage 2 that only contains 32-bit code, which uses an API provided by stage 1 to do the dirty work).


Cheers,

Brendan

Aw switching from 32bit to 16bit and reverse is a dirty work to call a BIOS interrupt from C. Its better to write all of the bootloader in assembly :(


Top
 Profile  
 
 Post subject: Re: Qestions about VESA/VBE
PostPosted: Sun Dec 15, 2013 2:54 pm 
Offline
Member
Member

Joined: Tue Nov 08, 2011 11:35 am
Posts: 453
MadZarx wrote:
It's better to write all of the bootloader in assembly :(

IMHO, it's even better to use ready bootloaders and concentrate on things that are more interesting.
Are you sure that you want your own set of bootloaders?
Why don't you want to use, for example, GRUB or OS Boot Tools?


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: awik, Bing [Bot], iansjack, Majestic-12 [Bot], RayanMargham and 208 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