Draw pixel x86_64 long mode
Page 1 of 1

Author:  nasirus1983 [ Sat Sep 07, 2019 10:25 pm ]
Post subject:  Draw pixel x86_64 long mode

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.

Author:  M2004 [ Sun Sep 08, 2019 2:47 am ]
Post subject:  Re: Draw pixel x86_64 long mode

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


Author:  bzt [ Sun Sep 08, 2019 7:15 am ]
Post subject:  Re: Draw pixel x86_64 long mode


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).


Author:  Octocontrabass [ Sun Sep 08, 2019 8:23 am ]
Post subject:  Re: Draw pixel x86_64 long mode

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.

Author:  loonie [ Tue Sep 10, 2019 1:20 pm ]
Post subject:  Re: Draw pixel x86_64 long mode

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!

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group