VESA LFB in long mode x86

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
User avatar
ZufaligeDaten
Posts: 5
Joined: Sun Dec 12, 2021 3:50 am
Contact:

VESA LFB in long mode x86

Post 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?
I can't wait until x86-s exists.
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: VESA LFB in long mode x86

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

Re: VESA LFB in long mode x86

Post 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.
rdos
Member
Member
Posts: 3296
Joined: Wed Oct 01, 2008 1:55 pm

Re: VESA LFB in long mode x86

Post 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.
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: VESA LFB in long mode x86

Post 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.
My OS is Perception.
User avatar
ZufaligeDaten
Posts: 5
Joined: Sun Dec 12, 2021 3:50 am
Contact:

Re: VESA LFB in long mode x86

Post 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).
I can't wait until x86-s exists.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: VESA LFB in long mode x86

Post 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.)
User avatar
ZufaligeDaten
Posts: 5
Joined: Sun Dec 12, 2021 3:50 am
Contact:

Re: VESA LFB in long mode x86

Post 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.
I can't wait until x86-s exists.
Post Reply