1 // ============================================================================================
3 // Copyright (C) 2002 Jeroen Janssen
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // ============================================================================================
21 // This VBE is part of the VGA Bios specific to the plex86/bochs Emulated VGA card.
22 // You can NOT drive any physical vga card with it.
24 // ============================================================================================
26 // This VBE Bios is based on information taken from :
27 // - VESA BIOS EXTENSION (VBE) Core Functions Standard Version 3.0 located at www.vesa.org
29 // ============================================================================================
33 // enable LFB support (depends upon bochs-vbe-lfb patch)
36 // disable VESA/VBE2 check in vbe info
37 //#define VBE2_NO_VESA_CHECK
39 // dynamicly generate a mode_info list
42 // enable unsupported modi in the mode_info list (ie >8bpp)
43 //#define LIST_UNSUPPORTED_MODI
47 #include "vbetables.h"
50 // The current OEM Software Revision of this VBE Bios
51 #define VBE_OEM_SOFTWARE_REV 0x0002;
53 #define VBEInfoData ((VbeInfoBlock *) 0)
55 extern char vbebios_copyright
;
56 extern char vbebios_vendor_name
;
57 extern char vbebios_product_name
;
58 extern char vbebios_product_revision
;
60 // FIXME: find out why we cannot use the dynamic list generation (due to a bug somewhere)
64 extern Bit16u vbebios_mode_list
;
68 // FIXME: 'merge' these (c) etc strings with the vgabios.c strings?
70 .ascii
"Bochs/Plex86 VBE(C) 2002 Jeroen Janssen <japj@darius.demon.nl>"
74 .ascii
"Bochs/Plex86 Developers"
77 _vbebios_product_name
:
78 .ascii
"Bochs/Plex86 VBE Adapter"
81 _vbebios_product_revision
:
86 .ascii
"Bochs VBE Display Adapter enabled"
91 _no_vbebios_info_string
:
92 .ascii
"NO Bochs VBE Support available!"
99 // FIXME: for each new mode add a statement here
100 // at least until dynamic list creation is working
103 #ifdef LIST_UNSUPPORTED_MODI
104 .word VBE_VESA_MODE_640X480X565
105 .word VBE_VESA_MODE_640X480X565
+ 0x4000
106 .word VBE_VESA_MODE_800X600X565
107 .word VBE_VESA_MODE_800X600X565
+ 0x4000
108 .word VBE_VESA_MODE_640X480X888
109 .word VBE_VESA_MODE_640X480X888
+ 0x4000
110 .word VBE_VESA_MODE_800X600X888
111 .word VBE_VESA_MODE_800X600X888
+ 0x4000
112 .word VBE_OWN_MODE_800X600X8888
113 .word VBE_OWN_MODE_800X600X8888
+ 0x4000
114 .word VBE_OWN_MODE_1024X768X8888
115 .word VBE_OWN_MODE_1024X768X8888
+ 0x4000
118 .word VBE_OWN_MODE_320X200X8
119 .word VBE_VESA_MODE_640X400X8
120 .word VBE_VESA_MODE_640X400X8
+ 0x4000
121 .word VBE_VESA_MODE_640X480X8
122 .word VBE_VESA_MODE_640X480X8
+ 0x4000
123 .word VBE_VESA_MODE_800X600X8
124 .word VBE_VESA_MODE_800X600X8
+ 0x4000
125 .word VBE_VESA_MODE_1024X768X8
126 .word VBE_VESA_MODE_1024X768X8
+ 0x4000
127 .word VBE_VESA_MODE_END_OF_LIST
133 #define PANIC_PORT 0x501
137 ;; the HALT macro is called with the line number of the HALT call
.
138 ;; The line number is then sent to the PANIC_PORT
, causing Bochs to
139 ;; print a BX_PANIC message
. This will normally halt the simulation
140 ;; with a message such as
"BIOS panic at rombios.c, line 4091".
141 ;; However
, users can choose to make panics non
-fatal
and continue.
148 // DISPI ioport functions
149 // FIXME: what if no VBE host side code?
150 static Bit16u
dispi_get_id()
152 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_ID
);
153 return inw(VBE_DISPI_IOPORT_DATA
);
156 static void dispi_set_id(id
)
159 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_ID
);
160 outw(VBE_DISPI_IOPORT_DATA
,id
);
163 static void dispi_set_xres(xres
)
166 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_XRES
);
167 outw(VBE_DISPI_IOPORT_DATA
,xres
);
170 static void dispi_set_yres(yres
)
173 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_YRES
);
174 outw(VBE_DISPI_IOPORT_DATA
,yres
);
177 static void dispi_set_bpp(bpp
)
180 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_BPP
);
181 outw(VBE_DISPI_IOPORT_DATA
,bpp
);
184 void dispi_set_enable(enable
)
187 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_ENABLE
);
188 outw(VBE_DISPI_IOPORT_DATA
,enable
);
191 static void dispi_set_bank(bank
)
194 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_BANK
);
195 outw(VBE_DISPI_IOPORT_DATA
,bank
);
198 static void dispi_set_x_offset(offset
)
201 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_X_OFFSET
);
202 outw(VBE_DISPI_IOPORT_DATA
,offset
);
205 static Bit16u
dispi_get_x_offset()
207 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_X_OFFSET
);
208 return inw(VBE_DISPI_IOPORT_DATA
);
211 static void dispi_set_y_offset(offset
)
214 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_Y_OFFSET
);
215 outw(VBE_DISPI_IOPORT_DATA
,offset
);
218 static Bit16u
dispi_get_y_offset()
220 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_Y_OFFSET
);
221 return inw(VBE_DISPI_IOPORT_DATA
);
224 static void dispi_set_virt_width(width
)
227 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_VIRT_WIDTH
);
228 outw(VBE_DISPI_IOPORT_DATA
,width
);
231 static Bit16u
dispi_get_virt_width()
233 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_VIRT_WIDTH
);
234 return inw(VBE_DISPI_IOPORT_DATA
);
237 static void dispi_set_virt_height(height)
240 outw(VBE_DISPI_IOPORT_INDEX,VBE_DISPI_INDEX_VIRT_HEIGHT);
241 outw(VBE_DISPI_IOPORT_DATA,height);
244 static Bit16u
dispi_get_virt_height()
246 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_VIRT_HEIGHT
);
247 return inw(VBE_DISPI_IOPORT_DATA
);
251 // ModeInfo helper function
252 static ModeInfoListItem
* mode_info_find_mode(mode
)
255 ModeInfoListItem
*cur_info
=&mode_info_list
;
257 while (cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
)
259 if (cur_info
->mode
== mode
)
270 /** Has VBE display - Returns true if VBE display detected
273 Boolean
vbe_has_vbe_display()
275 dispi_set_id(VBE_DISPI_ID1
);
277 return (dispi_get_id()==VBE_DISPI_ID1
);
280 /** VBE Init - Initialise the Vesa Bios Extension Code
282 * This function does a sanity check on the host side display code interface.
288 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_ID
);
289 outw(VBE_DISPI_IOPORT_DATA
,VBE_DISPI_ID0
);
291 dispi_id
=inw(VBE_DISPI_IOPORT_DATA
);
293 if (dispi_id
!=VBE_DISPI_ID0
)
295 //FIXME this results in a 'rombios.c' line panic, but it's actually a 'vbe.c' panic
301 printf("VBE Bios $Id$\n");
305 /** VBE Display Info - Display information on screen about the VBE
307 void vbe_display_info()
309 // Check for VBE display extension in Bochs
310 if (vbe_has_vbe_display())
315 mov si
,#_vbebios_info_string
324 mov si
,#_no_vbebios_info_string
331 /** Function 00h - Return VBE Controller Information
335 * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
336 * (VbeSignature should be VBE2 when VBE 2.0 information is desired and
337 * the info block is 512 bytes in size)
339 * AX = VBE Return Status
342 void vbe_biosfn_return_controller_information(AX
, ES
, DI
)
343 Bit16u
*AX
;Bit16u ES
;Bit16u DI
;
346 VbeInfoBlock vbe_info_block
;
351 Bit16u
*video_mode_list
;
354 ModeInfoListItem
*cur_info
=&mode_info_list
;
356 status
= read_word(ss
, AX
);
359 printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES
,DI
,status
);
363 #ifdef VBE2_NO_VESA_CHECK
365 // get vbe_info_block into local variable
366 memcpyb(ss
, &vbe_info_block
, ES
, DI
, sizeof(vbe_info_block
));
368 // check for VBE2 signature
369 if (((vbe_info_block
.VbeSignature
[0] == 'V') &&
370 (vbe_info_block
.VbeSignature
[1] == 'B') &&
371 (vbe_info_block
.VbeSignature
[2] == 'E') &&
372 (vbe_info_block
.VbeSignature
[3] == '2')) ||
374 ((vbe_info_block
.VbeSignature
[0] == 'V') &&
375 (vbe_info_block
.VbeSignature
[1] == 'E') &&
376 (vbe_info_block
.VbeSignature
[2] == 'S') &&
377 (vbe_info_block
.VbeSignature
[3] == 'A')) )
381 printf("VBE correct VESA/VBE2 signature found\n");
387 vbe_info_block
.VbeSignature
[0] = 'V';
388 vbe_info_block
.VbeSignature
[1] = 'E';
389 vbe_info_block
.VbeSignature
[2] = 'S';
390 vbe_info_block
.VbeSignature
[3] = 'A';
392 // VBE Version supported
393 vbe_info_block
.VbeVersion
= 0x0200;
396 vbe_info_block
.OemStringPtr_Seg
= 0xc000;
397 vbe_info_block
.OemStringPtr_Off
= &vbebios_copyright
;
400 vbe_info_block
.Capabilities
[0] = 0;
401 vbe_info_block
.Capabilities
[1] = 0;
402 vbe_info_block
.Capabilities
[2] = 0;
403 vbe_info_block
.Capabilities
[3] = 0;
406 // FIXME: This doesn't work correctly somehow?
407 // VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
408 vbe_info_block
.VideoModePtr_Seg
= ES
;//0xc000;
409 vbe_info_block
.VideoModePtr_Off
= DI
+ 34;//&(VBEInfoData->Reserved);//&vbebios_mode_list;
411 // VBE Video Mode Pointer (staticly in rom)
412 vbe_info_block
.VideoModePtr_Seg
= 0xc000;
413 vbe_info_block
.VideoModePtr_Off
= &vbebios_mode_list
;
419 // video_mode_list=(Bit16u*)&(vbe_info_block.Reserved);
424 printf("VBE found mode %x => %x\n", cur_info
->mode
,cur_mode
);
426 // *video_mode_list=cur_info->mode;
427 vbe_info_block
.Reserved
[cur_mode
] = cur_info
->mode
;
432 } while (cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
);
434 // Add vesa mode list terminator
435 vbe_info_block
.Reserved
[cur_mode
] = VBE_VESA_MODE_END_OF_LIST
;
440 // VBE Total Memory (in 64b blocks)
441 vbe_info_block
.TotalMemory
= VBE_TOTAL_VIDEO_MEMORY_DIV_64K
;
444 vbe_info_block
.OemSoftwareRev
= VBE_OEM_SOFTWARE_REV
;
445 vbe_info_block
.OemVendorNamePtr_Seg
= 0xc000;
446 vbe_info_block
.OemVendorNamePtr_Off
= &vbebios_vendor_name
;
447 vbe_info_block
.OemProductNamePtr_Seg
= 0xc000;
448 vbe_info_block
.OemProductNamePtr_Off
= &vbebios_product_name
;
449 vbe_info_block
.OemProductRevPtr_Seg
= 0xc000;
450 vbe_info_block
.OemProductRevPtr_Off
= &vbebios_product_revision
;
452 // copy updates in vbe_info_block back
453 memcpyb(ES
, DI
, ss
, &vbe_info_block
, sizeof(vbe_info_block
));
457 // copy updates in vbe_info_block back (VBE 1.x compatibility)
458 memcpyb(ES
, DI
, ss
, &vbe_info_block
, 256);
463 write_word(ss
, AX
, result
);
467 /** Function 01h - Return VBE Mode Information
472 * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
474 * AX = VBE Return Status
477 void vbe_biosfn_return_mode_information(AX
, CX
, ES
, DI
)
478 Bit16u
*AX
;Bit16u CX
; Bit16u ES
;Bit16u DI
;
480 Bit16u result
=0x0100;
483 ModeInfoListItem
*cur_info
=&mode_info_list
;
487 printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES
,DI
,CX
);
490 while ((cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
) && (!found
))
492 if (cur_info
->mode
== CX
)
505 printf("VBE found mode %x\n",CX
);
507 memsetb(ss
, &info
, 0, sizeof(ModeInfoBlock
));
508 memcpyb(ss
, &info
, 0xc000, &(cur_info
->info
), sizeof(ModeInfoBlockCompact
));
515 printf("VBE *NOT* found mode %x\n",CX
);
522 // copy updates in mode_info_block back
523 memcpyb(ES
, DI
, ss
, &info
, sizeof(info
));
526 write_word(ss
, AX
, result
);
529 /** Function 02h - Set VBE Mode
533 * BX = Desired Mode to set
534 * ES:DI = Pointer to CRTCInfoBlock structure
536 * AX = VBE Return Status
539 void vbe_biosfn_set_mode(AX
, BX
, ES
, DI
)
540 Bit16u
*AX
;Bit16u BX
; Bit16u ES
;Bit16u DI
;
542 Bit16u ss
= get_SS();
544 ModeInfoListItem
*cur_info
= &mode_info_list
;
548 using_lfb
=((BX
& VBE_MODE_LINEAR_FRAME_BUFFER
) == VBE_MODE_LINEAR_FRAME_BUFFER
);
552 //result=read_word(ss,AX);
554 // check for non vesa mode
555 if (BX
<VBE_MODE_VESA_DEFINED
)
559 dispi_set_enable(VBE_DISPI_DISABLED
);
560 // call the vgabios in order to set the video mode
561 // this allows for going back to textmode with a VBE call (some applications expect that to work)
564 biosfn_set_video_mode(mode
);
568 while ((cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
) && (!found
))
570 if (cur_info
->mode
== BX
)
582 printf("VBE found mode %x, setting:\n", BX
);
583 printf("\txres%x yres%x bpp%x\n",
584 cur_info
->info
.XResolution
,
585 cur_info
->info
.YResolution
,
586 cur_info
->info
.BitsPerPixel
);
588 // FIXME: this is here so we can do some testing
589 // at least until bochs host side display is up & running
590 // (we're using the 'standard' 320x200x256 vga mode as if it
593 if (cur_info
->info
.BitsPerPixel
== 8)
595 // we have a 8bpp mode, preparing to set it
597 // first disable current mode (when switching between vesa modi)
598 dispi_set_enable(VBE_DISPI_DISABLED
);
600 dispi_set_xres(cur_info
->info
.XResolution
);
601 dispi_set_yres(cur_info
->info
.YResolution
);
602 dispi_set_bpp(VBE_DISPI_BPP_8
);
604 dispi_set_enable(VBE_DISPI_ENABLED
);
606 // FIXME: store current mode in CMOS
611 //FIXME: new resolutions will need special code (per bpp)
616 printf("VBE *NOT* found mode %x\n" , BX
);
620 // FIXME: redirect non VBE modi to normal VGA bios operation
621 // (switch back to VGA mode
626 write_word(ss
, AX
, result
);
629 /** Function 03h - Return Current VBE Mode
634 * AX = VBE Return Status
635 * BX = Current VBE Mode
638 void vbe_biosfn_return_current_mode(AX
, BX
)
639 Bit16u
*AX
;Bit16u
*BX
;
643 // FIXME: get current mode from CMOS reg?
646 printf("VBE vbe_biosfn_return_current_mode\n");
649 write_word(ss
, AX
, 0x4f);
650 write_word(ss
, BX
, 0x3);
654 /** Function 04h - Save/Restore State
658 * DL = 00h Return Save/Restore State buffer size
661 * CX = Requested states
662 * ES:BX = Pointer to buffer (if DL <> 00h)
664 * AX = VBE Return Status
665 * BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
668 void vbe_biosfn_save_restore_state(AX
, DL
, CX
, ES
, BX
)
673 /** Function 05h - Display Window Control
677 * (16-bit) BH = 00h Set memory window
678 * = 01h Get memory window
682 * DX = Window number in video memory in window
683 * granularity units (Set Memory Window only)
685 * If this function is called while in a linear frame buffer mode,
686 * this function must fail with completion code AH=03h
689 * AX = VBE Return Status
690 * DX = Window number in window granularity units
691 * (Get Memory Window only)
693 void vbe_biosfn_display_window_control(AX
,BX
,DX
)
694 Bit16u
*AX
;Bit16u BX
;Bit16u
*DX
;
696 Bit16u ss
= get_SS();
697 Bit16u window
= read_word(ss
, DX
);
701 dispi_set_bank(window
);
706 /** Function 06h - Set/Get Logical Scan Line Length
710 * BL = 00h Set Scan Line Length in Pixels
711 * = 01h Get Scan Line Length
712 * = 02h Set Scan Line Length in Bytes
713 * = 03h Get Maximum Scan Line Length
714 * CX = If BL=00h Desired Width in Pixels
715 * If BL=02h Desired Width in Bytes
716 * (Ignored for Get Functions)
719 * AX = VBE Return Status
720 * BX = Bytes Per Scan Line
721 * CX = Actual Pixels Per Scan Line
722 * (truncated to nearest complete pixel)
723 * DX = Maximum Number of Scan Lines
725 void vbe_biosfn_set_get_logical_scan_line_length(AX
,BX
,CX
,DX
)
726 Bit16u
*AX
;Bit16u
*BX
;Bit16u
*DX
;Bit16u
*DX
;
730 Bit16u width
= read_word(ss
, CX
);
731 Bit16u cmd
= read_word(ss
, BX
);
734 if ( ((cmd
& 0xff) == 0x00) || ((cmd
& 0xff) == 0x02) )
736 // set scan line lenght in pixels(0x00) or bytes (0x00)
740 dispi_set_virt_width(width
);
741 new_width
=dispi_get_virt_width();
742 new_height
=dispi_get_virt_height();
744 if (new_width
!=width
)
747 printf("* VBE width adjusted\n");
750 // notify width adjusted
758 // FIXME: adjust for higher bpp (in bytes)
759 write_word(ss
,BX
,new_width
);
760 write_word(ss
,CX
,new_width
);
761 write_word(ss
,DX
,new_height
);
764 write_word(ss
, AX
, result
);
768 /** Function 07h - Set/Get Display Start
772 * BH = 00h Reserved and must be 00h
773 * BL = 00h Set Display Start
774 * = 01h Get Display Start
775 * = 02h Schedule Display Start (Alternate)
776 * = 03h Schedule Stereoscopic Display Start
777 * = 04h Get Scheduled Display Start Status
778 * = 05h Enable Stereoscopic Mode
779 * = 06h Disable Stereoscopic Mode
780 * = 80h Set Display Start during Vertical Retrace
781 * = 82h Set Display Start during Vertical Retrace (Alternate)
782 * = 83h Set Stereoscopic Display Start during Vertical Retrace
783 * ECX = If BL=02h/82h Display Start Address in bytes
784 * If BL=03h/83h Left Image Start Address in bytes
785 * EDX = If BL=03h/83h Right Image Start Address in bytes
786 * CX = If BL=00h/80h First Displayed Pixel In Scan Line
787 * DX = If BL=00h/80h First Displayed Scan Line
790 * AX = VBE Return Status
791 * BH = If BL=01h Reserved and will be 0
792 * CX = If BL=01h First Displayed Pixel In Scan Line
793 * If BL=04h 0 if flip has not occurred, not 0 if it has
794 * DX = If BL=01h First Displayed Scan Line
797 * BH = 00h Reserved and must be 00h
798 * BL = 00h Set Display Start
799 * = 80h Set Display Start during Vertical Retrace
800 * CX = Bits 0-15 of display start address
801 * DX = Bits 16-31 of display start address
802 * ES = Selector for memory mapped registers
804 void vbe_biosfn_set_get_display_start(AX
,BX
,CX
,DX
)
805 Bit16u
*AX
;Bit16u BX
;Bit16u CX
;Bit16u DX
;
810 // printf("VBE vbe_biosfn_set_get_display_start\n");
813 // check for set display start
814 if ((GET_BL()==0x00) || (GET_BL()==0x80))
816 // 0x80 is during vertical retrace - is also used by sdd vbetest during multibuffering
818 // printf("VBE vbe_biosfn_set_get_display_start CX%x DX%x\n",CX,DX);
821 dispi_set_x_offset(CX
);
822 dispi_set_y_offset(DX
);
826 write_word(ss
, AX
, result
);
830 /** Function 08h - Set/Get Dac Palette Format
835 * AX = VBE Return Status
837 * FIXME: incomplete API description, Input & Output
839 void vbe_biosfn_set_get_dac_palette_format(AX
)
844 /** Function 09h - Set/Get Palette Data
849 * AX = VBE Return Status
851 * FIXME: incomplete API description, Input & Output
853 void vbe_biosfn_set_get_palette_data(AX
)
857 /** Function 0Ah - Return VBE Protected Mode Interface
862 * AX = VBE Return Status
864 * FIXME: incomplete API description, Input & Output
866 void vbe_biosfn_return_protected_mode_interface(AX
)