VESA modes array malformed

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
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

VESA modes array malformed

Post 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
Regards, Bonfra.
Octocontrabass
Member
Member
Posts: 5418
Joined: Mon Mar 25, 2013 7:01 pm

Re: VESA modes array malformed

Post 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.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: VESA modes array malformed

Post 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.
Regards, Bonfra.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: VESA modes array malformed

Post by kzinti »

Fascinating.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: VESA modes array malformed

Post by Bonfra »

kzinti wrote:Fascinating.
?
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: VESA modes array malformed

Post 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
Regards, Bonfra.
Post Reply