Page 1 of 1

Getting VBE framebuffer location returns 0x0000

Posted: Sun Sep 11, 2022 11:07 am
by Cyao
I've made a little piece of code to get me the location of the framebuffer of VBE 0x100 mode

Code: Select all

[ORG 0x7C00]
[BITS 16]

Main:
    mov di, 0xF000 ; just put the info here
    mov ax, 0x4F01 ;mode
    mov cx, 0x0100 ; video mode number
    int 0x10 ;call

    cmp ax, 0x004F
    jne error ;checks for error

    mov ah, 0x0E ; print mode

    mov al, [0xF000 + 0x28] ; 1st byte of the adress

    and al, 0xF0 ; print 1st char
    shr al, 4
    add al, 0x30
    int 0x10

    mov al, [0xF000 + 0x28]

    and al, 0x0F
    add al, 0x30
    int 0x10

    mov al, [0xF000 + 0x2A]

    and al, 0xF0
    shr al, 4
    add al, 0x30
    int 0x10

    mov al, [0xF000 + 0x2A]

    and al, 0x0F
    add al, 0x30
    int 0x10

error:
    jmp $

times 510 - ($-$$) db 0
dw 0xAA55
I think i made it all good, but on the screen it only displays "0000", am I doing something wrong?

Re: Getting VBE framebuffer location returns 0x0000

Posted: Sun Sep 11, 2022 1:59 pm
by Minoto
The segment registers aren't initialized in your code, so there's no guarantee that the information is stored (relative to es) at the same address you're attempting to read it from (relative to ds).

Your code also only prints two bytes of a four byte address, which is probably not what you intended.

Re: Getting VBE framebuffer location returns 0x0000

Posted: Mon Sep 12, 2022 8:57 am
by Cyao
Oh so I initialized the registers and I got the frambuffer adress is 0xFD000000 which seems a bit odd, but it works in 16 bit mode. but after switching to 64 bit mode, it dosent work :( Is there some way to get to know why? and is there some documentation of the framebuffer adresses?

Re: Getting VBE framebuffer location returns 0x0000

Posted: Mon Sep 12, 2022 10:42 am
by Octocontrabass
cyao1234 wrote:but after switching to 64 bit mode, it dosent work :( Is there some way to get to know why?
In 64-bit mode, paging is enabled. Do your page tables have an appropriate mapping for physical address 0xFD000000?
cyao1234 wrote:and is there some documentation of the framebuffer adresses?
What do you mean? On modern PCs, the firmware assigns physical addresses to PCI BARs before your OS boots, and the linear framebuffer address is derived from one of those BARs. The address can change depending on the hardware and firmware configuration.