Page 1 of 1

VESA LFB in long mode x86

Posted: Mon Apr 25, 2022 9:19 am
by ZufaligeDaten
I have never been able to get long mode and VESA LFB working together, when I try, qemu just dies, but in protected mode works fine, is it even possible for a VESA LFB to work in long mode? If so, How?

Re: VESA LFB in long mode x86

Posted: Mon Apr 25, 2022 12:59 pm
by Ethin
I'm pretty sure this isn't possible. I might be wrong but isn't VESA/VBE a real-mode/32-bit technology only?

Re: VESA LFB in long mode x86

Posted: Mon Apr 25, 2022 2:24 pm
by Octocontrabass
You can't call VBE in 64-bit mode, but you can use the linear framebuffer provided by VBE in 64-bit mode. In fact, the linear framebuffer works exactly the same in all CPU modes, and regardless of how you set it up (VBE, GOP, or native driver).

It sounds like you don't have an appropriate mapping in your page tables, causing a page fault, and you don't have working exception handlers, turning the page fault into a triple fault. You can add "-d int" (and maybe "-no-reboot") to your QEMU command line to see exactly what's causing the reboot.

Re: VESA LFB in long mode x86

Posted: Tue Apr 26, 2022 4:03 am
by rdos
Octocontrabass wrote:You can't call VBE in 64-bit mode, but you can use the linear framebuffer provided by VBE in 64-bit mode. In fact, the linear framebuffer works exactly the same in all CPU modes, and regardless of how you set it up (VBE, GOP, or native driver).
Right, except that EFI have a few more organizational modes that VBE lacks.

Re: VESA LFB in long mode x86

Posted: Tue Apr 26, 2022 8:06 am
by AndrewAPrice
I like to get the bootloader (GRUB) to enter the graphics mode for me, then read the location of the framebuffer, bit depth, and resolution from the multiboot info.

Re: VESA LFB in long mode x86

Posted: Wed Apr 27, 2022 2:40 pm
by ZufaligeDaten
Octocontrabass wrote:You can't call VBE in 64-bit mode, but you can use the linear framebuffer provided by VBE in 64-bit mode. In fact, the linear framebuffer works exactly the same in all CPU modes, and regardless of how you set it up (VBE, GOP, or native driver).

It sounds like you don't have an appropriate mapping in your page tables, causing a page fault, and you don't have working exception handlers, turning the page fault into a triple fault. You can add "-d int" (and maybe "-no-reboot") to your QEMU command line to see exactly what's causing the reboot.
So, It's a problem with my page table mapping? If so, then could that be related to the way I enter long mode? (Shown bellow, using osdev tutorial 'Setting Up Long Mode'). I've done some research but still don't understand page tables and that lot very well, so it would be great if someone could help.

Code: Select all

bits 32
	mov dword [lfb0], ebx
	mov edi, 0x1000
	mov cr3, edi
	xor eax, eax
	mov ecx, 4096
	rep stosd
	mov edi, cr3
	mov dword [edi], 0x2003
	add edi, 0x1000
	mov dword [edi], 0x3003
	add edi, 0x1000
	mov dword [edi], 0x4003
	add edi, 0x1000
	mov dword ebx, 0x00000003
	mov ecx, 512
	.setEntry:
		mov dword [edi], ebx
		add ebx, 0x1000
		add edi, 8
		loop .setEntry
	mov eax, cr4
	or eax, 1 << 5
	mov cr4, eax
	mov ecx, 0xc0000080
	rdmsr
	or eax, 1 << 8
	wrmsr
	mov eax, cr0
	or eax, 1 << 31
	mov cr0, eax
	lgdt [GDT.Pointer]
	jmp GDT.Code:LongMode
	[bits 64]
	LongMode:
	mov ebx, dword [lfb0]
	mov edi, dword [ebx+22]
Thanks in advance (if advance exists).

Re: VESA LFB in long mode x86

Posted: Wed Apr 27, 2022 7:39 pm
by Octocontrabass
ZufaligeDaten wrote:If so, then could that be related to the way I enter long mode? (Shown bellow, using osdev tutorial 'Setting Up Long Mode').
The tutorial's page tables only include identity mappings for the first two megabytes. Your framebuffer is almost certainly at a higher address, so you'll need to set up mappings for it in order to access it. (You don't have to identity-map your framebuffer.)

Re: VESA LFB in long mode x86

Posted: Wed Apr 27, 2022 11:56 pm
by ZufaligeDaten
Octocontrabass wrote:
ZufaligeDaten wrote:If so, then could that be related to the way I enter long mode? (Shown bellow, using osdev tutorial 'Setting Up Long Mode').
The tutorial's page tables only include identity mappings for the first two megabytes. Your framebuffer is almost certainly at a higher address, so you'll need to set up mappings for it in order to access it. (You don't have to identity-map your framebuffer.)
Thank you, that probably explains it.