OSDev.org
https://forum.osdev.org/

VESA modes array malformed
https://forum.osdev.org/viewtopic.php?f=1&t=43502
Page 1 of 1

Author:  Bonfra [ Sat May 08, 2021 3:39 pm ]
Post subject:  VESA modes array malformed

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:
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:
qemu-system-x86_64 -M q35 -m 512M -hda BonsOS.img -no-reboot -no-shutdown -S -gdb tcp::9000

Author:  Octocontrabass [ Sat May 08, 2021 6:08 pm ]
Post subject:  Re: VESA modes array malformed

Bonfra wrote:
Code:
    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.

Author:  Bonfra [ Sun May 09, 2021 1:35 am ]
Post subject:  Re: VESA modes array malformed

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:
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.

Author:  kzinti [ Sun May 09, 2021 1:49 am ]
Post subject:  Re: VESA modes array malformed

Fascinating.

Author:  Bonfra [ Sun May 09, 2021 10:52 am ]
Post subject:  Re: VESA modes array malformed

kzinti wrote:
Fascinating.

?

Author:  Bonfra [ Sun May 09, 2021 2:21 pm ]
Post subject:  Re: VESA modes array malformed

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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/