OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Aug 16, 2022 4:34 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: VESA modes array malformed
PostPosted: Sat May 08, 2021 3:39 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 180
Location: Italy
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

_________________
Greetings, Bonfra.


Top
 Profile  
 
 Post subject: Re: VESA modes array malformed
PostPosted: Sat May 08, 2021 6:08 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 4027
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.


Top
 Profile  
 
 Post subject: Re: VESA modes array malformed
PostPosted: Sun May 09, 2021 1:35 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 180
Location: Italy
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.

_________________
Greetings, Bonfra.


Top
 Profile  
 
 Post subject: Re: VESA modes array malformed
PostPosted: Sun May 09, 2021 1:49 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 793
Fascinating.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: VESA modes array malformed
PostPosted: Sun May 09, 2021 10:52 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 180
Location: Italy
kzinti wrote:
Fascinating.

?


Top
 Profile  
 
 Post subject: Re: VESA modes array malformed
PostPosted: Sun May 09, 2021 2:21 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 19, 2020 1:08 pm
Posts: 180
Location: Italy
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

_________________
Greetings, Bonfra.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], justinvoss, PetalBot [Bot], SemrushBot [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group