OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 10:08 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Drawing in 32bit colour modes in protected & long mode
PostPosted: Fri Jan 27, 2017 12:30 pm 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
I am making a protected mode OS (I will probably also want to do long mode in the future) and I want to draw a pixel in 24 or 32bit colour modes. I would like to know if it is a good idea to switch to unreal mode. If so, how could I do it? Are there any other options? I am quite new to making OSes but I have a lot of experience with C. I am using the standard gcc compiler. Also, is it possible to do HDMI instead of VGA?


Top
 Profile  
 
 Post subject: Re: Drawing in 32bit colour modes in protected & long mode
PostPosted: Fri Jan 27, 2017 12:46 pm 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
Switching to 16-bit mode is, I would say, a last resort. I would only do that if you had no other choice.

If you are in 32 or 64 bit mode, drawing pixels to the screen is fairly easy.

What is not easy in 32/64 bit mode is switching from text mode to graphics mode. If you can do that with GRUB or in your custom 16-bit boot loader, that would be the recommended approach.

So, switch to your desired graphics mode when booting, before you switch to 32-bit/64-bit mode, and do everything else without going back to 16-bit mode, if at all possible.

HDMI is handled automatically by the video card. You shouldn't have to do anything special to get HDMI to work.

Once you are in 32/64-bit mode, you simply find the address of the video card frame buffer, and start changing memory address values, and the pixels will appear on the screen.

Details are on the wiki page here: Drawing In Protected Mode

Let us know if you have any questions or run into any problems.

Good luck.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: Drawing in 32bit colour modes in protected & long mode
PostPosted: Sat Jan 28, 2017 5:04 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
Thanks so much!!! :D But I tried to change the grub .cfg file with "set gfxmode = 1024x768x32", but it didn't work though.

EDIT:
I found out that you can't have spaces between the gfxmode and the =. But now GRUB is in the right resolution but my OS does not keep it while booting. I did try gfxpayload=keep, but I can't seem to manage to get it work.

_________________
AQUA OS: https://obiwac.wordpress.com/aqua-os/


Top
 Profile  
 
 Post subject: Re: Drawing in 32bit colour modes in protected & long mode
PostPosted: Sat Feb 04, 2017 4:46 pm 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
You can actually do this:

Code:
section .text
   align 4
   
   dd 0x1BADB002
   dd 0x04
   dd -(0x1BADB002 + 0x04)
   
   dd 0 ; skip some flags
   dd 0
   dd 0
   dd 0
   dd 0
   
   dd 0 ; sets it to graphical mode
   dd 800 ; sets the width
   dd 600 ; sets the height
   dd 32 ; sets the bits per pixel


and before calling main function just add
Code:
push ebx
.

And in the grub .cfg you just need to add set
Code:
set gfxmode=800x600x32
.
Plotting the pixels is easy:

- Go to the grub command line (with c)
- Type
Code:
lspci -i

- Under VGA controller, take the 8 last digits of the hexadecimal string, and that's your memory pointer for plotting pixels.

Hope this helped anyone!

_________________
AQUA OS: https://obiwac.wordpress.com/aqua-os/


Top
 Profile  
 
 Post subject: Re: Drawing in 32bit colour modes in protected & long mode
PostPosted: Sat Feb 04, 2017 5:07 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
obiwac wrote:
Plotting the pixels is easy:

- Go to the grub command line (with c)
- Type
Code:
lspci -i

- Under VGA controller, take the 8 last digits of the hexadecimal string, and that's your memory pointer for plotting pixels.

Hope this helped anyone!

This won't help anyone. You should never hard-code the pointer to the physical frame buffer, because it is different on each PC and on most emulators. For example, Bochs and VirtualBox have the frame buffer at 0xE0000000. QEMU has it at 0xFD000000. My laptop has it at 0xD0000000 and my two test PCs at 0xE4000000.
Instead, GRUB passes you a "VBE mode information structure" which is documented in the VBE specs. That structure contains a reliable pointer to the physical frame buffer that would work on all VBE-compatible PCs.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: Drawing in 32bit colour modes in protected & long mode
PostPosted: Sun Apr 30, 2017 6:52 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
Just wanted to complete this post:

http://forum.osdev.org/viewtopic.php?f=1&t=31700

_________________
AQUA OS: https://obiwac.wordpress.com/aqua-os/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 161 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