VBE Questions

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.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

VBE Questions

Post by PearOs »

Hey guys, so I have been reading and I think supporting VBE would be a really good idea. Only problem is I have a few concerns and questions that I can't seem to find answers to. So I came here as you guys have a very friendly community and are very knowledgeable. Anyways, so I know VBE has a VBE Bios which you use to call and setup VBE support. However, I am running in Long Mode, and I know a lot of Operating Systems that as far as I can tell are using only Protected Mode and are able to have VBE support. I thought these BIOS calls could only be called if you were in real mode? I read something about using a virtual bios in Long Mode/Protected Mode in order to use VBE or something like that. I would prefer not to switch from long mode and real mode if I can help it, so how would I go about doing this in Long Mode? Thanks guys, Matt
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: VBE Questions

Post by Kazinsal »

You can't do VBE stuff from within long mode.

In protected mode, you can either drop back to real mode or use virtual 8086 mode to "emulate" some of the real mode memory bits.

In long mode, you can't use virtual 8086 mode, so you'd have to drop back to compatibility mode, drop to protected mode, and then drop to real mode.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: VBE Questions

Post by PearOs »

Blacklight wrote:You can't do VBE stuff from within long mode.

In protected mode, you can either drop back to real mode or use virtual 8086 mode to "emulate" some of the real mode memory bits.

In long mode, you can't use virtual 8086 mode, so you'd have to drop back to compatibility mode, drop to protected mode, and then drop to real mode.
Ok makes sense, so is there any graphics modes that I can program in Long Mode that are either accelerated by the graphics card, or standard that have a high res vs using VGA? XGA if I am wrong I believe uses IOPorts to control, which could be done in Long Mode. Though I don't know enough about it and documentation is limited. Thanks, Matt

In the worst case I can write drivers for graphics cards individually but the only problem with that is most of them are proprietary and have no documentation other than looking at Linux or Xorg, but even then I have no idea how some of those work.
freecrac
Member
Member
Posts: 69
Joined: Thu Sep 20, 2012 5:11 am
Location: germany hamburg

Re: VBE Questions

Post by freecrac »

PearOs wrote:
Blacklight wrote:Ok makes sense, so is there any graphics modes that I can program in Long Mode that are either accelerated by the graphics card, or standard that have a high res vs using VGA?
Starting with VBE2 we have to use the vbe-modenumbers that comes within our vesa bios of our card.
Here are some vbe-modenumbers of different cards:
  • -------------------------------------
    ATI 9800 PRO VESA Modi 128 MB
    -------------------------------------
    4 8 15 16 24 32 Matrix
    -------------------------------------
    109 132 x 25
    10A 132 x 43
    130 132 x 44
    182 10D 10E 10F 120 320 x 200
    192 193 194 195 196 320 x 240
    1A2 1A3 1A4 1A5 1A6 400 x 300
    1B2 1B3 1B4 1B5 1B6 512 x 384
    1C2 1C3 1C4 1C5 1C6 640 x 350
    100 183 184 185 186 640 x 400
    101 110 111 112 121 640 x 480
    102 103 113 114 115 122 800 x 600
    104 105 106 107 108 123 1024 x 768
    107 119 11A 11B 124 1280 x 1024

    -------------------------------------
    ATI X800 PRO VESA MODI 256 MB
    -------------------------------------
    4 8 15 16 24 32 Matrix
    -------------------------------------
    109 132 x 25
    10A 132 x 34
    130 132 x 44
    10D 10F 320 x 200
    193 194 196 320 x 240
    1B3 1B4 1B6 512 x 384
    1C3 1C4 1C6 640 x 350
    100 184 186 640 x 400
    101 110 112 640 x 480
    133 134 136 720 x 400
    103 113 115 800 x 600
    105 116 118 1024 x 768
    153 154 156 1152 x 864
    107 119 11B 1280 x 1024
    143 144 146 1400 x 1050
    173 174 176 1600 x 1200
    1D3 1D4 1D6 1856 x 1392
    1E3 1E4 1E6 1920 x 1440

    -------------------------------------
    NVIDIA GF 4 Ti4200 VESA Modi 64 MB
    -------------------------------------
    4 8 15 16 24 32 Matrix
    -------------------------------------
    108 80 x 60
    109 132 x 25
    10A 132 x 43
    10B 132 x 50
    10C 132 x 60
    130 10E 10F 320 x 200
    134 135 136 320 x 240
    131 132 133 320 x 400
    100 13D 13E 640 x 400
    101 111 112 640 x 480
    102 103 114 115 800 x 600
    104 105 117 118 1024 x 768
    106 107 11A 1280 x 1024
    147 148 1400 x 1050
    145 146 1600 x 1200

    -------------------------------------
    NVIDIA GF 6800 GT VESA Modi 256 MB
    4 8 15 16 24 32 Matrix
    -------------------------------------
    130 10E 10F 320 x 200
    134 135 136 320 x 240
    131 132 133 320 x 400
    100 13D 13E 640 x 400
    101 111 112 640 x 480
    102 103 114 115 800 x 600
    104 105 117 118 1024 x 768
    106 107 11A 11B 1280 x 1024
    145 146 1600 x 1200
    147 148 1400 x 1050
    152 2048 x 1536
    -------------------------------------
    Vesamodi Colorfull GTX295
    -------------------------------------
    0100 X=0280 Y=0190 8Bit
    0101 X=0280 Y=01E0 8Bit
    0102 X=0320 Y=0258 4Bit
    0103 X=0320 Y=0258 8Bit
    0104 X=0400 Y=0300 4Bit
    0105 X=0400 Y=0300 8Bit
    0106 X=0500 Y=0400 4Bit
    0107 X=0500 Y=0400 8Bit
    010E X=0140 Y=00C8 10Bit
    010F X=0140 Y=00C8 20Bit
    0111 X=0280 Y=01E0 10Bit
    0112 X=0280 Y=01E0 20Bit
    0114 X=0320 Y=0258 10Bit
    0115 X=0320 Y=0258 20Bit
    0117 X=0400 Y=0300 10Bit
    0118 X=0400 Y=0300 20Bit
    011A X=0500 Y=0400 10Bit
    011B X=0500 Y=0400 20Bit
    0130 X=0140 Y=00C8 8Bit
    0131 X=0140 Y=0190 8Bit
    0132 X=0140 Y=0190 10Bit
    0133 X=0140 Y=0190 20Bit
    0134 X=0140 Y=00F0 8Bit
    0135 X=0140 Y=00F0 10Bit
    0136 X=0140 Y=00F0 20Bit
    013D X=0280 Y=0190 10Bit
    013E X=0280 Y=0190 20Bit
    0145 X=0640 Y=04B0 8Bit
    0146 X=0640 Y=04B0 10Bit
    014A X=0640 Y=04B0 20Bit
    0160 X=0500 Y=0320 8Bit
    0161 X=0500 Y=0320 20Bit
    0162 X=0300 Y=01E0 8Bit
    017B X=0500 Y=02D0 20Bit
    017C X=0780 Y=04B0 8Bit
    017D X=0780 Y=04B0 20Bit

    -------------------------------------
    Vesa Modeliste der Sapphire 7950:
    -------------------------------------
    Vesamode,XRes,YRes,Bits per Pixel,Adresse des Framebuffer
    -------------------------------------
    0100 640x400x8 C0000000
    0101 640x480x8 C0000000
    0103 800x600x8 C0000000
    0105 1024x768x8 C0000000
    0107 1280x1024x8 C0000000
    0110 640x480x16 C0000000
    0111 640x480x16 C0000000
    0113 800x600x16 C0000000
    0114 800x600x16 C0000000
    0116 1024x768x16 C0000000
    0117 1024x768x16 C0000000
    0119 1280x1024x16 C0000000
    011A 1280x1024x16 C0000000
    010D 320x200x16 C0000000
    010E 320x200x16 C0000000
    0120 320x200x32 C0000000
    0193 320x240x8 C0000000
    0195 320x240x16 C0000000
    0196 320x240x32 C0000000
    01B3 512x384x8 C0000000
    01B5 512x384x16 C0000000
    01B6 512x384x32 C0000000
    01C3 640x350x8 C0000000
    01C5 640x350x16 C0000000
    01C6 640x350x32 C0000000
    0133 720x400x8 C0000000
    0135 720x400x16 C0000000
    0136 720x400x32 C0000000
    0153 1152x864x8 C0000000
    0155 1152x864x16 C0000000
    0156 1152x864x32 C0000000
    0163 1280x960x8 C0000000
    0165 1280x960x16 C0000000
    0166 1280x960x32 C0000000
    0121 640x480x32 C0000000
    0122 800x600x32 C0000000
    0123 1024x768x32 C0000000
    0124 1280x1024x32 C0000000
    0143 1400x1050x8 C0000000
    0145 1400x1050x16 C0000000
    0146 1400x1050x32 C0000000
    0173 1600x1200x8 C0000000
    0175 1600x1200x16 C0000000
    0176 1600x1200x32 C0000000
    0183 1792x1344x8 C0000000
    0185 1792x1344x16 C0000000
    0186 1792x1344x32 C0000000
    01D3 1856x1392x8 C0000000
    01D5 1856x1392x16 C0000000
    01D6 1856x1392x32 C0000000
    01E3 1920x1440x8 C0000000
    01E5 1920x1440x16 C0000000
    01E6 1920x1440x32 C0000000
    01D1 1920x1200x8 C0000000 (fit the native resolution of my 28" LCD aspect ratio 16:10)
    01D2 1920x1200x16 C0000000 (fit the native resolution of my 28" LCD aspect ratio 16:10)
    01D4 1920x1200x32 C0000000 (fit the native resolution of my 28" LCD aspect ratio 16:10)
After we have properly switched to a vbe-mode that provide to use the LFB we can simply fill the LFB with any content.
The adress of the LFB can be get from the modeinfo function.
XGA if I am wrong I believe uses IOPorts to control, which could be done in Long Mode. Though I don't know enough about it and documentation is limited. Thanks, Matt

In the worst case I can write drivers for graphics cards individually but the only problem with that is most of them are proprietary and have no documentation other than looking at Linux or Xorg, but even then I have no idea how some of those work.
Most information about the VBE can be found in the puplic ducument "vbe3.pdf" from vesa.org(register and/or login). Additional there are some copy of the vbe3.pdf in the web.

Some information about Accelerator Functions of a Driver for that can be found in the "VBE-AF07.pdf"
The VBE/AF device driver is defined as an operating system portable, 32 bit protected mode
device driver, which can be loaded under any 32 bit operating system. The same VBE/AF driver
can be used for high performance full screen graphics under any operating system, provided a
few operating system specific functions are provided. Currently VBE/AF is targeted towards
supporting MSDOS, Windows 3.1, Windows 95, OS/2 and UNIX.
....
VBE/AF provides routines for high performance polygon rendering functions, which includes
flat topped/bottomed trapezoid filling, triangle filling and quadrilateral filling routines.
Dirk
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: VBE Questions

Post by PearOs »

Wow Dirk, thanks for all the info. So I looked through VBE3.pdf and I found some really useful information. But here's where things get tricky. I want to support higher resolutions. I don't really mind if its done with VBE or something else. But what is the fastest way to support fast higher resoultion graphics in long mode without writing drivers for every graphics card and without using VGA? Or is this impossible? Thanks, Matt


Well I have been doing lot's of reading. And I find most homebrewed operating systems are using VESA mode by setting the mode before they enter protected mode. So I guess my question would be, how do I setup VESA in real mode, set the mode ect.. and then in Protected Mode Get/Set Pixels and other things? Thanks guys, this is a huge learning curve for me. I know VGA pretty well but I have never ventured past it.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: VBE Questions

Post by Love4Boobies »

Blacklight wrote:In long mode, you can't use virtual 8086 mode, so you'd have to drop back to compatibility mode, drop to protected mode, and then drop to real mode.
First of all, if you're going to switch to protected mode, why not set up a virtual 8086 mode task instead of dropping to real mode? Secondly, you don't need to go through protected mode when switching between real and long modes.

Anyway, the most common solution is to write a little 8086 emulator or VM and use that to access the VBE interfaces. This will result in less overhead.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: VBE Questions

Post by PearOs »

Ok thanks, so if I were to write a 8086 emulator, how does that access VBE or VESA? Sorry for my lack of understanding. I would assume it runs some sort of BIOS image or 16bit code so that I can call BIOS functions? Thanks, Matt

Also, could someone point me to some documentation or tutorials on writing a 8086 emulator? Thanks
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: VBE Questions

Post by dozniak »

PearOs wrote:Also, could someone point me to some documentation or tutorials on writing a 8086 emulator? Thanks
Our renowned wiki links to this from the Virtual 8086 Mode page - http://gitorious.org/x86emu/
You can google from there on.
Learn to read.
freecrac
Member
Member
Posts: 69
Joined: Thu Sep 20, 2012 5:11 am
Location: germany hamburg

Re: VBE Questions

Post by freecrac »

PearOs wrote:Wow Dirk, thanks for all the info. So I looked through VBE3.pdf and I found some really useful information. But here's where things get tricky. I want to support higher resolutions. I don't really mind if its done with VBE or something else. But what is the fastest way to support fast higher resoultion graphics in long mode without writing drivers for every graphics card and without using VGA? Or is this impossible? Thanks, Matt


Well I have been doing lot's of reading. And I find most homebrewed operating systems are using VESA mode by setting the mode before they enter protected mode. So I guess my question would be, how do I setup VESA in real mode, set the mode ect.. and then in Protected Mode Get/Set Pixels and other things? Thanks guys, this is a huge learning curve for me. I know VGA pretty well but I have never ventured past it.
I try to explain the most importend thinks about the VBE.
We are starting in the RM or V86-Mode, or maybe in the 16 bit big-realmode/unrealmode with vbe function 4F00h (in the AX-register) of the int 10h for to get the VBE-info in a buffer of 512 bytes (ES:DI must be points to the buffer).
Then we check if this function is suported and if we become the value of 4Fh back in AX, or non if it fails.

The next step is to check the major number of our VBE version(VBE_Info_Buffer+5) if it is number 2 or 3, or a lesser number.
With the VBE version number 2 and number 3 we can get the pointer(offset, segment) of the list of VBE-modenumbers in the VBE_Info_Buffer+0Eh = contains the pointer to the modelist, not the modelist itself. (Maybe the modelist is nearby also inside of the VBE_Info_Buffer). The modelist ends with a word of "0FFFFh".

The next step is to get each modenumber from the modelist for to use this number by number to get the mode information of each number/mode with the funcion 4F01h in an additional "mode_info:buffer" of 256 bytes. (+checking if we become back 4Fh in AX.) (ES:DI must be points to the buffer.)

Now we have to check some parameter inside of this mode_info:buffer, for to find the resolution we are looking for.
Mode_info:buffer+12h contains a word of the max horizontal resolution, Mode_info:buffer+14h contains a word of the vertical resolution, Mode_info:buffer+19h contains the amoung of bits for each pixel, the highest bit of the byte in Mode_info:buffer+0 is set if the linear access is supported, Mode_info:buffer+28h contains the 32bit address of the LFB, or contains zeros if non LFB is possible in this mode. (Hint: The scanlines of the screen are maybe longer as the horizontal resolution, so we have to use the word of the Mode_info:buffer+10h for to calculate the address of a pixel. and not the word in the Mode_info:buffer+12h.)

...

If we found the VBE modenumber 3, then it is possible to set a VBE-mode with our own CRT-parameter for to become a higher refreshrate, otherwise we become only the default 60hz refreshrate. For to use a higher refreshrate it would be wise for to check the capacity of our monitor before. Therefore we can get the EDID(monitor information) from the DDC(a special line for to transmit those infos) by using function 4F15h of the int 10h. Calling with BL=0 we can check if the function is aviable and if we become 4Fh back in AX. (Hint: older BNC-monitor-cable with only five lines do not have a DDC.)

Then we can get the EDID with BL=1 with function 4F15h in a new buffer of 128 bytes.
Inside of the EDID-buffer we can search for a "Text-identifier" of the value dword "0FD000000h" in EDID_buffer+36h, or in EDID_buffer+48h, or in EDID_buffer+5Ah, or in EDID_buffer+6Ch. If we found a "Text-identifier", then we can adding to this adress 6 bytes for to get the max HZ in a byte and if we are adding 8 bytes to this address of the "Text-identifier", then we can get the max KHZ of the monitor.

The next step for to become a higher refreschrate is to get the pixelclock for our CRT-parameter (using funktion 4F0Bh) for to recalculate the refreschrate with this pixelclock that we become back and with the other paramter of our CRT-parameter-block (RefreshRate=Pixelclock/(HTotal*Vtotal)).

Example of a CRTC-parameter-block for the resolution of 1024x768 with 100 hz refreshrate using a CRT-monitor with a capacity of max. 96 khz and max. 160 hz like a lot of 19" CRT-monitors provide.

Code: Select all

CRTC    DW 1456                        ; Horizontal Total       in Pixel
HORIANF DW 1122                        ; Horizontal  Sync-Start in Pixel
HORIEND DW 216                         ; Horizontal  Sync-End   in Pixel
VERTOTA DW 814                         ; Vertical   Total       in Lines
VERTANF DW 768                         ; Vertical    Sync-Start in Lines
VERTEND DW 42                          ; Vertical    Sync-End   in Lines
DOIFLAG DB 04h                         ; Flag (interlaced,doubleScan,polarity)
PIXCLOC DD 118309000                   ; Pixel clock in hz (Hint: We have to get the "normalized" pixelclock from our bios and this value can be different.)
REFRATE DW 10000                       ; Refresh-Rate in 0.01 hz (Hint: We have to recalculatad the HZ-value together with the "normalized" pixelclock.)
;---------------------
        DB 40 dup (0)
;--------------------------------------
More puplic documents from vesa.org:
EEDIDguideV1.pdf
EEDIDverifGuideRa.pdf

For to become those CRT-parameters we can use a small DOS application with the name VBEHz.com inside of a zip-archiv.
http://www.pcworld.com/product/1048351/vbehz.html
Additional there is also a "MODELIST.COM" inside, for to see which modes your BIOS or VESA driver supports.
...

At last we set the VBE-mode with function 4F02h with a modenumber+4000h for to use the LFB and optional with modenumber+800h for to use own CRT-parameter and with ES:DI points to our CRT-block.

After we have set our VBE-mode, then we can switch to the 32 PM, or to the 64 bit mode and we can start to fill the LFB with our content.

...

I have written a small 16 bit DOS-application in assembler(MASM/Intel-syntax) only using the 16 bit bigrealmode for to show how to use a VBE 3 bios with a resolution of 1024x768x32 @100 hz refresrate together with the VBE hardware triple buffering (function 4F07h of the int 10h) for to move some larger objects across the screen without to become a flickering screen or a tearing. I programm it with a geforce 4(agp with 64 MB) und with a 19" CRT from Samsung and a 19" CRT from SAMTRON (both CRTs provide 96khz/160hz capacity) together with a AMD 32 bit "Palomino"- CPU "1800+" @1533 mhz for a sockel "A" mainboard. (My newer 28" LCD monitor with 60hz refreshrate ignore the CRT-parameter and switch only to 1024x768 @60 hz.)
http://www.alice-dsl.net/freecracmaps/Tool/Neutrip.zip

Dirk
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: VBE Questions

Post by PearOs »

Dirk you are my new best friend. This is amazing. Thank you for the amazing info! I have a few questions. So before we enter long mode we get the VBE version, find our mode, set it and then enter long mode. Now my only question is, how do I work with the LFB in long mode? Like where is the LFB located? How do I find it? What's it's formatting for setting/getting pixels. I assume since I'm in long mode there is no hardware acceleration for clearing the screen, ect.. Thanks Matt
freecrac
Member
Member
Posts: 69
Joined: Thu Sep 20, 2012 5:11 am
Location: germany hamburg

Re: VBE Questions

Post by freecrac »

PearOs wrote:Dirk you are my new best friend. This is amazing. Thank you for the amazing info! I have a few questions. So before we enter long mode we get the VBE version, find our mode, set it and then enter long mode. Now my only question is, how do I work with the LFB in long mode? Like where is the LFB located? How do I find it? What's it's formatting for setting/getting pixels. I assume since I'm in long mode there is no hardware acceleration for clearing the screen, ect.. Thanks Matt
Sorry, i never try to use the long mode. And i also have to learn it before.
I think it is importend to read the documentation from Intel and from AMD step by step.

But i found another demo using the longmode.
http://cs.usfca.edu/~cruse/cs630/try64bit.s

And if i understand the 64 bit code inside, then it use the traditional vram base-address 0f 0xB8000 for to write to the textscreen.
So i think the 32 bit address from the LFB that we can get from the mode_info_buffer+28h can also be used with the longmode.

Dirk
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: VBE Questions

Post by PearOs »

Ok thanks Dirk. I am currently running in Long Mode and everything works just fine, I can use the textscreen and stuff. But I think I may try to implement a method for going from Long Mode to Real mode and then back, setting up everything, and keeping things like my interrupts and paging in line. Which is really easy since the GDT, IDT and Page Tables are already stored and setup in my long mode envirement, it would be easy as just simply going to real mode, and then once I get in long mode just loading the GDT and IDT again, and reloading my paging if needed. So ill see if I can get a demo of that working for VBE support so that in long mode, I could call Get Modes for example and it would boot into real mode, grab the mode info, store it into some sort of area of memory ill make for returns, and then come back to long mode and resume what it was previously doing. Thanks, Matt
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: VBE Questions

Post by rdos »

Aside from setting up video mode at boot, and using emulators, it is possible (and more convenient) to switch to protected mode (and then to V86 mode) rather than real mode to make VBE calls. The protected mode code could use PAE paging and thus could run in a similar environment as long mode, and doesn't need to disable interrupts and similar (only setup bimodal interrupt handlers).
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: VBE Questions

Post by PearOs »

That's a good point RDos, maybe ill try that approach. What would be really cool is to have a 8086 emulator in long mode and I think just load a VBE Bios and execute its code. I think that's what someone above was talking about doing. But there's only two problems. I don't know enough about 8086, which I can find info on, and the other is that I don't have a VBE Bios image anywhere. Now aside from going from long mode to protected mode and back to work with the VBE and VESA Bios. Do you think the speed would relatively fast? Or would I have huge speed issues? Thanks, Matt
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: VBE Questions

Post by PearOs »

You know, there's one thing I don't understand. Its obvious that Windows Xp for example is running in protected mode. But I have a desktop that needed a graphics card driver, and didn't have one installed. So the only resolution available was 800x600 which I mean isn't too bad. But how can Windows achieve this? I mean if I only had 800x600 I really wouldn't mind, but how can they support that without any drivers for my card? Maybe a generic driver? And if so could I write the same thing in my Os? Where would I find info on it? Thanks guys, Matt
Post Reply