Draw pixel x86_64 long 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
nasirus1983
Posts: 1
Joined: Sat Sep 07, 2019 10:23 pm

Draw pixel x86_64 long mode

Post by nasirus1983 »

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.
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: Draw pixel x86_64 long mode

Post by M2004 »

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
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Draw pixel x86_64 long mode

Post by bzt »

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
Octocontrabass
Member
Member
Posts: 5581
Joined: Mon Mar 25, 2013 7:01 pm

Re: Draw pixel x86_64 long mode

Post by Octocontrabass »

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.
loonie
Posts: 7
Joined: Sat Jul 06, 2019 3:24 pm

Re: Draw pixel x86_64 long mode

Post by loonie »

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!
Post Reply