Page 1 of 1

VESA modes array malformed

Posted: Sat May 08, 2021 3:39 pm
by Bonfra
I'm following Omar's VESA tutorial to change VESA mode in my bootloader.
I've retrieved the 512 bytes info block from the bios with int 10h/AX=0x4F00 and I'm sure this worked since the signature field of this block is correctly set to "VESA".
After inspecting the retuned data I noticed that the amount of KBs of available video memory is set to zero, a bit awkward but not yet a problem.
There is a field that the tutorial calls video_modes which is a pointer in segment:offset to the array of available video modes (terminated by 0xFFFF). I writed some code to iterate that array but I read really weird values... I don't think what I'm reading is correct.
This is my code:

Code: Select all

SetVbeMode:

    mov al, 'V'
    mov [Mem.VESA.Info], al
    mov al, 'B'
    mov [Mem.VESA.Info + 1], al
    mov al, 'E'
    mov [Mem.VESA.Info + 2], al
    mov al, '2'
    mov [Mem.VESA.Info + 3], al

    push es                 ; preserve es
	mov ax, 0x4F00			; get VBE BIOS info (es:di address)
	mov di, Mem.VESA.Info
	int 0x10
	pop es                  ; restore ES

    cmp ax, 0x004F          ; BIOS doesn't support VBE?
	jne .error

    mov ax, word[Mem.VESA.Info + 18]
	mov [.offset], ax
	mov ax, word[Mem.VESA.Info + 18 + 2]
	mov [.segment], ax

    mov ax, [.segment]
	mov ds, ax
	mov si, [.offset]

.find_mode:
    cld
    lodsw
    cmp ax, 0xFFFF
    je .error

    push 16
    push ax
    call _printw
	jmp .find_mode

.done:
    clc
    ret

.error:
    hlt
    jmp $
    stc
    ret
Is there something wrong with it that you can find?
PS:
I don't think this is relevant but i test my code using QEMU and i run it with this line:

Code: Select all

qemu-system-x86_64 -M q35 -m 512M -hda BonsOS.img -no-reboot -no-shutdown -S -gdb tcp::9000

Re: VESA modes array malformed

Posted: Sat May 08, 2021 6:08 pm
by Octocontrabass
Bonfra wrote:

Code: Select all

    mov ax, [.segment]
	mov ds, ax
	mov si, [.offset]
You move a new value into DS and then you try to access memory using the previous value of DS.

Re: VESA modes array malformed

Posted: Sun May 09, 2021 1:35 am
by Bonfra
Octocontrabass wrote: You move a new value into DS and then you try to access memory using the previous value of DS.
Right, I tried to modify the original code from the tutorial since it also didn't work but I messed up. This is the original code.

Code: Select all

SetVbeMode:

    mov al, 'V'
    mov [Mem.VESA.Info], al
    mov al, 'B'
    mov [Mem.VESA.Info + 1], al
    mov al, 'E'
    mov [Mem.VESA.Info + 2], al
    mov al, '2'
    mov [Mem.VESA.Info + 3], al

    push es                 ; preserve es
	mov ax, 0x4F00			; get VBE BIOS info (es:di address)
	mov di, Mem.VESA.Info
	int 0x10
	pop es                  ; restore ES

    cmp ax, 0x004F          ; BIOS doesn't support VBE?
	jne .error

    mov ax, word[Mem.VESA.Info + 18]
	mov [.offset], ax
	mov ax, word[Mem.VESA.Info + 18 + 2]
	mov [.segment], ax

    mov ax, [.segment]
	mov fs, ax
	mov si, [.offset]

.find_mode:
    mov dx, [fs:si]     ; retrive data from fs:si
    add si, 2           ; increase si to point to the next value
    mov [.offset], si   ; save si value
	mov [.mode], dx     ; save retrieved data
    mov ax, 0           ; reset fs to 0
	mov fs, ax

    cmp word [.mode], 0xFFFF
    je .error

    push 16 ; base
    push word [.mode]
    call _printw

.next_mode:
    mov ax, [.segment]  ; prepare segment for the next query
	mov fs, ax
	mov si, [.offset]  ; prepare offset for the next query
	jmp .find_mode

.done:
    clc
    ret

.error:
    hlt
    jmp $
    stc
    ret

.segment    dw 0
.offset     dw 0
.mode       dw 0
But also this one does not work... same weird values pop out.

Re: VESA modes array malformed

Posted: Sun May 09, 2021 1:49 am
by kzinti
Fascinating.

Re: VESA modes array malformed

Posted: Sun May 09, 2021 10:52 am
by Bonfra
kzinti wrote:Fascinating.
?

Re: VESA modes array malformed

Posted: Sun May 09, 2021 2:21 pm
by Bonfra
It's actually kinda embarrassing... I was reading at index 18 of the info retrieved by the BIOS call, instead, the pointer of the video modes was at index 14... it works now