I am currently struggling with VESA graphics.
I am switching to VESA using this assembly code below
Note: At this point I am still in 16 bit real-mode
Note 2: video_info is a label in the 32 bit area of my code. there should be no issues, since it is correctly initialized by the code below
#Set VESA Mode
mov $0x4f02, %ax
movw $0x4118, %bx
int $0x10
mov %ds, %ax # Set up the extra segment
mov %ax, %es # with the data segment
#Get VESA Info
mov $(video_info-_start),%di
mov $0x4f01, %ax
mov %bx, %cx
int $0x10
# enable A20 line
inb $0x92, %al
orb $2, %al
outb %al, $0x92
# Load GDT
lgdt (gdt_init-_start)
# Enter protected mode
mov %cr0, %eax
or $1, %eax
mov %eax, %cr0
After setting the mode, %ax is 0x4f
After this code, I switch to 32 bit real mode, then I jump to my kernel main written in C
I dont think that its important, but my gdt looks like this:
.word 0,0,0,0 # seg 0 - null
.word 0xffff, 0x0000, 0x9a00, 0x00cf # seg 1 - kernel code
.word 0xffff, 0x0000, 0x9200, 0x00cf # seg 2 - kernel data
I tried to render some pixels to the screen.
The pixels are rendered, however, their color doesnt seem to be right.
After debugging the VESA Information I got the following details:
PhysBasePtr = 0xfd000000
BitsPerPixel = 24
Red/Green/Bluemasksize = 8
RedfieldPosition = 16
GreenfieldPosition = 8
BluefieldPosition = 0
Also, this returns true: ModeAttributes & (1 << 7)
That indicates that the framebuffer is linear
However, when i try this:
uint8_t* v = 0xfd000000
v[2] = 0x00; //Red
v[1] = 0x00; //Green
v[0] = 0xff; //Blue
The desired pixel is not blue but black
When I inspect the memory at 0xfd000000 the value is correct, but the pixel color is not
I am currently using qemu for emulation
The command I am using for running the Kernel is
qemu-system-x86_64 -drive format=raw,file=floppy.img -vga std -monitor stdio
I already tried changing some offsets from the physbase address but nothing seems to work for me.
I tried different -monitor and -vga options in qemu, none work for me apparently
Also, i tried running some other kernels I found on github (e.g dthain/basekernel) and trying around a bit, none of them seem to display the colors correctly for me.
I am using a RTX 3050 (idk if its important lmao)
Maybe the problem is WSL/Qemu related?
Any ideas why this is not working?
FearXenon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.