[SOLVED] VBE 2: Change bank without v86 or real mode

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.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

[SOLVED] VBE 2: Change bank without v86 or real mode

Post by Karlosoft »

Hi! I've a new question. Yesterday I've started writing a VESA 2 driver for my os. The problem is that i can put only 640*34 rows pixel, more or less. Then I have to change the bank with this code (when i'm still in real mode)

Code: Select all

mov ax, 0x4f05
mov bx,0x0
mov dx,0x1 ;Number of bank
int 10h
It's possible make something similar (perhaps with a VESA function) without INT 0x10, and so without switch back to real mode?
Last edited by Karlosoft on Fri Aug 21, 2009 7:46 am, edited 1 time in total.
dak91
Member
Member
Posts: 43
Joined: Thu Mar 12, 2009 3:27 am
Location: Sardegna (IT)

Re: VBE 2: Change bank without v86 or real mode

Post by dak91 »

manonthemoon
Member
Member
Posts: 65
Joined: Sat Jul 04, 2009 9:39 pm

Re: VBE 2: Change bank without v86 or real mode

Post by manonthemoon »

Drawing In Protected Mode has some details. Basically, there's no easy way to do anything with VESA outside v86 mode or real mode.

However, there is a solution to your problem. Select a screen mode that doesn't use banking. When you use command AX=0x4F01 to get mode info, look for one that offers a "linear frame buffer". Then you can access all of the video RAM at once without switching banks.
Don't bother. It's just a long discussion about the fact that you can't run BIOS code in protected mode.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Karlosoft »

An other question
This is the code on the wiki.

Code: Select all

struct vbeControllerInfo {
   char signature[4];             // == "VESA"
   short version;                 // == 0x0300 for VBE 3.0
   short oemString[2];            // isa vbeFarPtr
   unsigned char capabilities[4];
   short videomodes[2];           // isa vbeFarPtr
   short totalMemory;             // as # of 64KB blocks
};

Why it isn't this?

Code: Select all

struct vbeControllerInfo {
   char signature[3];             // == "VESA"
   short version;                 // == 0x0300 for VBE 3.0
   short oemString[1];            // isa vbeFarPtr
   unsigned char capabilities[3];
   short videomodes[1];           // isa vbeFarPtr
   short totalMemory;             // as # of 64KB blocks
};
Why signature is 5 bytes long if there are only 4 charachter? The \0 isn't needed, It isn't so?
manonthemoon
Member
Member
Posts: 65
Joined: Sat Jul 04, 2009 9:39 pm

Re: VBE 2: Change bank without v86 or real mode

Post by manonthemoon »

Karlosoft wrote: Why signature is 5 bytes long if there are only 4 charachter? The \0 isn't needed, It isn't so?
The signature is not 5 bytes long. char signature[4] means there are four bytes. The null isn't needed in this case.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Dex »

User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Karlosoft »

There are the result of the search.... I'm being crazy XD
I've tried with VBE2 as label, with VESA.... nothing the values aren't right

Tomorrow I'll try the Dexos' source :)
Attachments
Immagine2.JPG
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Brendan »

Hi,
Karlosoft wrote:It's possible make something similar (perhaps with a VESA function) without INT 0x10, and so without switch back to real mode?
Yes (sort of).

For VBE 2.0 there's "Function 0Ah - Return VBE Protected Mode Interface", where the protected mode interface can be used to access functions 05h (display window control), 07h (get/set display start) and 09h (get/set palette data). This function is required so it should be supported by all VBE 2 video cards (but "should be supported" is never quite the same as "definitely will be supported").

For VBE 3 "Function 0Ah" became optional, and a new protected mode interface was invented. This new protected mode interface is also optional, and I don't think many VBE 3 video cards support the new interface or the older interface (mostly, for VBE 3 they assume you'll be using LFB instead).

Also, older VBE video cards (e.g. VBE 1.0, VBE 1.2) didn't support LFB or protected mode interfaces, so the only way to support high resolution video modes is with real mode (or virtual8086 mode, or emulation) and bank switching.

Basically, for a full featured VBE driver you might end up doing something like:

Code: Select all

    if(VBE version 2 or later) {
        if(LFB supported for this video mode) return USE_LFB;
        if(VBE2 protected mode interface is supported) return USE_VBE2_INTERFACE;
        if(VBE version 3 or later) {
            if(VBE3 protected mode interface is supported) return USE_VBE3_INTERFACE;
        }
    } else {
        if(size of pixel data is less than the size of one window) {
            if(windowA is writable) return USE_WINDOW_A;
            if(windowB is writable) return USE_WINDOW_B;
        } else {
            return UNUSABLE_MODE;
        }
    }
Of course the protected mode interfaces are both ugly, so most people don't support them (including me). Most computers have video cards that support LFB now anyway (and there's something about 640 * 480 * 16 colours that gives an OS a pleasant "retro" look ;) )...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Karlosoft »

Well I've correct the bugs, now it find and print the right values for every mode. However i'd like support the Protected Interface. I need to store the ES and DI values. Is a good idea write them in a ram area and than do a search from kernel?
Last edited by Karlosoft on Tue Aug 18, 2009 2:15 pm, edited 1 time in total.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Karlosoft »

I've write this code to save the current es:di and than look for the struct. The problem is that the mov istructions doesn't work

Code: Select all

;The struct in .bbs section
struc VESA_REG
	.VESA_REG_LABEL resd 1
	.VESA_ES resw 1
	.VESA_DI resw 1

endstruc	

;code code code code....

;The object
VESADATA:
	istruc VESA_REG
		at VESA_REG.VESA_REG_LABEL, dd 'ESDI'
		at VESA_REG.VESA_ES, dw 0                              ;If i set a value it work
		at VESA_REG.VESA_DI, dw 0
	iend

	mov [VESADATA+VESA_REG.VESA_ES], es                  ;With mov i the value doesn't change
	mov [VESADATA+VESA_REG.VESA_DI], di
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Brendan »

Hi,

Code: Select all

;The struct in .bbs section
struc VESA_REG
	.VESA_REG_LABEL resd 1
	.VESA_ES resw 1
	.VESA_DI resw 1
endstruc
This defines a structure, but the structure doesn't exist anywhere (and doesn't exist in the ".bss" section). Mostly it does the same as:

Code: Select all

%define VESA_REG.VESA_REG_LABEL     0
%define VESA_REG.VESA_ES            4
%define VESA_REG.VESA_DI            6
%define VESA_REG_size               8

Code: Select all

;The object
VESADATA:
	istruc VESA_REG
		at VESA_REG.VESA_REG_LABEL, dd 'ESDI'
		at VESA_REG.VESA_ES, dw 0                              ;If i set a value it work
		at VESA_REG.VESA_DI, dw 0
	iend
This code creates an instance of the structure, probably in your ".text" section. This is also probably what is going wrong, because the CPU sees these data bytes and things they're instructions, and crashes. Basically, your code ends up being:

Code: Select all

VESADATA:
        dd 'ESDI'           ;Crash when this is executed by the CPU
        dw 0
        dw 0

	mov [VESADATA+4], es
	mov [VESADATA+6], di
The simple solution is probably to create the instance of the structure in the ".data" section:

Code: Select all

;The object
    section .data

VESADATA:
	istruc VESA_REG
		at VESA_REG.VESA_REG_LABEL, dd 'ESDI'
		at VESA_REG.VESA_ES, dw 0                              ;If i set a value it work
		at VESA_REG.VESA_DI, dw 0
	iend
    section .text

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Karlosoft »

I'm not able to change the values in the field than the initialision. Stange strange strange....

EDIT: I found the solution ;) it works well and i can endly use the 05h routine. Thanks everyones for the help ^_^
Now i've the location expressed in segment:offset notation. I've changed it in a phisical address (my GDT is flat). Now if I add the 0x5 function offset to the address, can I call the routine?
Attachments
Now it works
Now it works
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by tantrikwizard »

Brendan wrote:<snip>...For VBE 2.0 there's "Function 0Ah - Return VBE Protected Mode Interface"...<snip>
Be careful with these if you're using BOCHS, they weren't working properly last time I tested them.
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Karlosoft »

I'm testing it on a real platform :). I've used Virtualbox only to do this screenshot :)
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: VBE 2: Change bank without v86 or real mode

Post by Dex »

You can also do this to make realmode and pmode addressing the same
Done in realmode at boot up, when setting you GDT.

Code: Select all

	xor   ebx,ebx
	mov   bx,ds						    
	shl   ebx,4						    
	mov   eax,ebx
	mov   [sys_code_1 + 2],ax				     
	mov   [sys_data_1 + 2],ax
	mov   [Real_code_1 + 2],ax				     
	mov   [Real_data_1 + 2],ax
	shr   eax,16
	mov   [sys_code_1 + 4],al
	mov   [sys_data_1 + 4],al
	mov   [Real_code_1 + 4],al
	mov   [Real_data_1 + 4],al
	mov   [sys_code_1 + 7],ah
	mov   [sys_data_1 + 7],ah
	mov   [Real_code_1 + 7],ah
	mov   [Real_data_1 + 7],ah
	add   ebx,gdt						  
	mov   [gdtr + 2],ebx
Post Reply