OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:34 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Draw pixel x86_64 long mode
PostPosted: Sat Sep 07, 2019 10:25 pm 
Offline

Joined: Sat Sep 07, 2019 10:23 pm
Posts: 1
I'm trying to create simple kernel to learn a little. The problem is that I searched over google many topics related to and mostly I have found only a theory as an answer for my question.

To not post here a code etc. I've created a simple GitHub repo and put a working project.

The question is: I'm displaying Hello World and want to draw a pixel. How to do this ?

Here is link to source code: https://github.com/nasirus1983/learnLongMode

I've already created some assembly code with grub2 to enter long mode and also created hello world in C. Everything works, but right now I want to draw a pixel. As I said I haven't found practical answer for my question only theory or redirecting to OSDev Wiki which is very theoretical.


Top
 Profile  
 
 Post subject: Re: Draw pixel x86_64 long mode
PostPosted: Sun Sep 08, 2019 2:47 am 
Offline
Member
Member

Joined: Sun Mar 07, 2010 2:12 am
Posts: 65
Just quickly browsing your code.

You are using text mode which is pointed by address 0xb8000.

Assuming your text mode code works.
Most easiest way is to setup vga mode 0x13 instead of initial text mode
and change start address to 0xA0000.

Then write any color value you desire. After getting it to
work u might want to use vesa lfb graphic mode(s), which are
explained here: https://wiki.osdev.org/VESA_Video_Modes

Regards,
M2004


Top
 Profile  
 
 Post subject: Re: Draw pixel x86_64 long mode
PostPosted: Sun Sep 08, 2019 7:15 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Hi,

Check out my bootloader, which provides framebuffer for BIOS (VESA) and UEFI (GOP). The code that handles VESA is here (in Assembly).

Alternatively feel free to use my loader as-is and you can focus on your kernel.
The kernel receives a pointer and dimensions of the framebuffer and all you have to do to plot a pixel is writing to memory (see example kernel that prints "Hello World" on screen).

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Draw pixel x86_64 long mode
PostPosted: Sun Sep 08, 2019 8:23 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
nasirus1983 wrote:
with grub2

You can add the framebuffer tag to your multiboot2 header to specify that you would like a linear frame buffer for graphics output.

You can also use gfxpayload in your grub.cfg to choose the screen resolution without needing to build a different kernel for each one. Take a look at this thread for some examples.


Top
 Profile  
 
 Post subject: Re: Draw pixel x86_64 long mode
PostPosted: Tue Sep 10, 2019 1:20 pm 
Offline

Joined: Sat Jul 06, 2019 3:24 pm
Posts: 7
While enumaration VBE (VESA BIOS Extension) modes while you are in BIOS you get:
1) screen resolution: width & height in pixels (this is irrelevant in our situation)
2) bits per per pixel (please only consider 24 or 32 bitsPerPixel = bpp)
3) bpl = number of pixels in one line screen line which usually matches screen width but not required (this & screen width is independent)
4) 32bit LinearFrameBuffer address

Pixel must be placed at x1,y1 location
a) you multiply x1 by either 3(24bps) or 4(32bps) bytes
b) you multiply y1 by #3) = number of pixels in one line screen = bpl
c) then you add: a) + b) + 4)
d) you get an address when you write either 3 or 4 byte value, 0x00ffffff or 0xffffff is white, 0x0 is black

Maybe your problem is mapping 32bit LFB, I dont know. You can try protected mode instead of LongMode. In protected mode you don't need to use paging -thus no mapping.

Plus, text mode & graphics share potion of memory on real hardware - When you write to text mode -> you write to graphics mode.

On real hardware you need to use cache-disabled memory first. Get it working. Then switch to different memory type. Do not read from video card memory. Its messes with cache and its terribly slow. You can disable all cache using CRx register.

All of these tiny things can affect you success!


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

All times are UTC - 6 hours


Who is online

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