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 // ============================================================================================
36 // disable VESA/VBE2 check in vbe info
37 //#define VBE2_NO_VESA_CHECK
39 // dynamicly generate a mode_info list
44 #include "vbetables.h"
47 // The current OEM Software Revision of this VBE Bios
48 #define VBE_OEM_SOFTWARE_REV 0x0002;
50 extern char vbebios_copyright
;
51 extern char vbebios_vendor_name
;
52 extern char vbebios_product_name
;
53 extern char vbebios_product_revision
;
56 extern Bit16u vbebios_mode_list
;
60 // FIXME: 'merge' these (c) etc strings with the vgabios.c strings?
62 .ascii
"Bochs/Plex86 VBE(C) 2003 http://savannah.nongnu.org/projects/vgabios/"
66 .ascii
"Bochs/Plex86 Developers"
69 _vbebios_product_name
:
70 .ascii
"Bochs/Plex86 VBE Adapter"
73 _vbebios_product_revision
:
78 .ascii
"Bochs VBE Display Adapter enabled"
83 _no_vbebios_info_string
:
84 .ascii
"NO Bochs VBE Support available!"
89 #if defined(USE_BX_INFO) || defined(DEBUG)
91 .ascii
"VBE Bios $Id$"
96 // FIXME: for each new mode add a statement here
97 // at least until dynamic list creation is working
100 .word VBE_VESA_MODE_640X400X8
101 .word VBE_VESA_MODE_640X480X8
102 .word VBE_VESA_MODE_800X600X4
103 .word VBE_VESA_MODE_800X600X8
104 .word VBE_VESA_MODE_1024X768X8
105 .word VBE_VESA_MODE_640X480X1555
106 .word VBE_VESA_MODE_640X480X565
107 .word VBE_VESA_MODE_640X480X888
108 .word VBE_VESA_MODE_800X600X1555
109 .word VBE_VESA_MODE_800X600X565
110 .word VBE_VESA_MODE_800X600X888
111 .word VBE_VESA_MODE_1024X768X1555
112 .word VBE_VESA_MODE_1024X768X565
113 .word VBE_VESA_MODE_1024X768X888
114 .word VBE_OWN_MODE_640X480X8888
115 .word VBE_OWN_MODE_800X600X8888
116 .word VBE_OWN_MODE_1024X768X8888
117 .word VBE_OWN_MODE_320X200X8
118 .word VBE_VESA_MODE_END_OF_LIST
122 dw vesa_pm_set_window
- vesa_pm_start
123 dw vesa_pm_set_display_strt
- vesa_pm_start
124 dw vesa_pm_unimplemented
- vesa_pm_start
133 vesa_pm_set_display_start
:
138 vesa_pm_unimplemented
:
144 ; DISPI ioport functions
148 mov dx
, # VBE_DISPI_IOPORT_INDEX
149 mov ax
, # VBE_DISPI_INDEX_ID
151 mov dx
, # VBE_DISPI_IOPORT_DATA
159 mov dx
, # VBE_DISPI_IOPORT_INDEX
160 mov ax
, # VBE_DISPI_INDEX_ID
163 mov dx
, # VBE_DISPI_IOPORT_DATA
169 static void dispi_set_xres(xres
)
178 mov dx
, # VBE_DISPI_IOPORT_INDEX
179 mov ax
, # VBE_DISPI_INDEX_XRES
181 mov dx
, # VBE_DISPI_IOPORT_DATA
197 call vga_set_virt_width
205 static void dispi_set_yres(yres
)
208 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_YRES
);
209 outw(VBE_DISPI_IOPORT_DATA
,yres
);
212 static void dispi_set_bpp(bpp
)
215 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_BPP
);
216 outw(VBE_DISPI_IOPORT_DATA
,bpp
);
220 ; AL
= bits per pixel
/ AH
= bytes per pixel
223 mov dx
, # VBE_DISPI_IOPORT_INDEX
224 mov ax
, # VBE_DISPI_INDEX_BPP
226 mov dx
, # VBE_DISPI_IOPORT_DATA
240 call dispi_get_enable
242 or ax
, # VBE_DISPI_GETCAPS
243 call _dispi_set_enable
244 mov dx
, # VBE_DISPI_IOPORT_INDEX
245 mov ax
, # VBE_DISPI_INDEX_BPP
247 mov dx
, # VBE_DISPI_IOPORT_DATA
251 call _dispi_set_enable
260 mov dx
, # VBE_DISPI_IOPORT_INDEX
261 mov ax
, # VBE_DISPI_INDEX_ENABLE
264 mov dx
, # VBE_DISPI_IOPORT_DATA
271 mov dx
, # VBE_DISPI_IOPORT_INDEX
272 mov ax
, # VBE_DISPI_INDEX_ENABLE
274 mov dx
, # VBE_DISPI_IOPORT_DATA
282 mov dx
, # VBE_DISPI_IOPORT_INDEX
283 mov ax
, # VBE_DISPI_INDEX_BANK
286 mov dx
, # VBE_DISPI_IOPORT_DATA
293 mov dx
, # VBE_DISPI_IOPORT_INDEX
294 mov ax
, # VBE_DISPI_INDEX_BANK
296 mov dx
, # VBE_DISPI_IOPORT_DATA
302 static void dispi_set_bank_farcall()
306 je dispi_set_bank_farcall_get
308 jnz dispi_set_bank_farcall_error
310 mov ax
,# VBE_DISPI_INDEX_BANK
311 mov dx
,# VBE_DISPI_IOPORT_INDEX
314 mov dx
,# VBE_DISPI_IOPORT_DATA
317 dispi_set_bank_farcall_get
:
318 mov ax
,# VBE_DISPI_INDEX_BANK
319 mov dx
,# VBE_DISPI_IOPORT_INDEX
321 mov dx
,# VBE_DISPI_IOPORT_DATA
325 dispi_set_bank_farcall_error
:
335 mov dx
, # VBE_DISPI_IOPORT_INDEX
336 mov ax
, # VBE_DISPI_INDEX_X_OFFSET
339 mov dx
, # VBE_DISPI_IOPORT_DATA
346 mov dx
, # VBE_DISPI_IOPORT_INDEX
347 mov ax
, # VBE_DISPI_INDEX_X_OFFSET
349 mov dx
, # VBE_DISPI_IOPORT_DATA
357 mov dx
, # VBE_DISPI_IOPORT_INDEX
358 mov ax
, # VBE_DISPI_INDEX_Y_OFFSET
361 mov dx
, # VBE_DISPI_IOPORT_DATA
368 mov dx
, # VBE_DISPI_IOPORT_INDEX
369 mov ax
, # VBE_DISPI_INDEX_Y_OFFSET
371 mov dx
, # VBE_DISPI_IOPORT_DATA
396 dispi_set_virt_width
:
397 call vga_set_virt_width
400 mov dx
, # VBE_DISPI_IOPORT_INDEX
401 mov ax
, # VBE_DISPI_INDEX_VIRT_WIDTH
404 mov dx
, # VBE_DISPI_IOPORT_DATA
409 dispi_get_virt_width
:
411 mov dx
, # VBE_DISPI_IOPORT_INDEX
412 mov ax
, # VBE_DISPI_INDEX_VIRT_WIDTH
414 mov dx
, # VBE_DISPI_IOPORT_DATA
419 dispi_get_virt_height
:
421 mov dx
, # VBE_DISPI_IOPORT_INDEX
422 mov ax
, # VBE_DISPI_INDEX_VIRT_HEIGHT
424 mov dx
, # VBE_DISPI_IOPORT_DATA
431 // ModeInfo helper function
432 static ModeInfoListItem
* mode_info_find_mode(mode
, using_lfb
)
433 Bit16u mode
; Boolean using_lfb
;
435 ModeInfoListItem
*cur_info
=&mode_info_list
;
437 while (cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
)
439 if (cur_info
->mode
== mode
)
445 else if (cur_info
->info
.ModeAttributes
& VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE
)
465 ; Has VBE display
- Returns
true if VBE display detected
467 _vbe_has_vbe_display
:
470 mov ax
, # BIOSMEM_SEG
472 mov bx
, # BIOSMEM_VBE_FLAG
480 ; VBE Init
- Initialise the Vesa Bios Extension Code
481 ; This function does a sanity check on the host side display code interface
.
484 mov ax
, # VBE_DISPI_ID0
487 cmp ax
, # VBE_DISPI_ID0
491 mov ax
, # BIOSMEM_SEG
493 mov bx
, # BIOSMEM_VBE_FLAG
498 mov ax
, # VBE_DISPI_ID3
501 #if defined(USE_BX_INFO) || defined(DEBUG)
502 mov bx
, #msg_vbe_init
510 ; VBE Display Info
- Display information on screen about the VBE
513 call _vbe_has_vbe_display
518 mov si
, #_vbebios_info_string
523 mov si
, #_no_vbebios_info_string
527 /** Function 00h - Return VBE Controller Information
531 * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
532 * (VbeSignature should be VBE2 when VBE 2.0 information is desired and
533 * the info block is 512 bytes in size)
535 * AX = VBE Return Status
538 void vbe_biosfn_return_controller_information(AX
, ES
, DI
)
539 Bit16u
*AX
;Bit16u ES
;Bit16u DI
;
542 VbeInfoBlock vbe_info_block
;
548 ModeInfoListItem
*cur_info
=&mode_info_list
;
550 status
= read_word(ss
, AX
);
553 printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES
,DI
,status
);
557 #ifdef VBE2_NO_VESA_CHECK
559 // get vbe_info_block into local variable
560 memcpyb(ss
, &vbe_info_block
, ES
, DI
, sizeof(vbe_info_block
));
562 // check for VBE2 signature
563 if (((vbe_info_block
.VbeSignature
[0] == 'V') &&
564 (vbe_info_block
.VbeSignature
[1] == 'B') &&
565 (vbe_info_block
.VbeSignature
[2] == 'E') &&
566 (vbe_info_block
.VbeSignature
[3] == '2')) ||
568 ((vbe_info_block
.VbeSignature
[0] == 'V') &&
569 (vbe_info_block
.VbeSignature
[1] == 'E') &&
570 (vbe_info_block
.VbeSignature
[2] == 'S') &&
571 (vbe_info_block
.VbeSignature
[3] == 'A')) )
575 printf("VBE correct VESA/VBE2 signature found\n");
581 vbe_info_block
.VbeSignature
[0] = 'V';
582 vbe_info_block
.VbeSignature
[1] = 'E';
583 vbe_info_block
.VbeSignature
[2] = 'S';
584 vbe_info_block
.VbeSignature
[3] = 'A';
586 // VBE Version supported
587 vbe_info_block
.VbeVersion
= 0x0200;
590 vbe_info_block
.OemStringPtr_Seg
= 0xc000;
591 vbe_info_block
.OemStringPtr_Off
= &vbebios_copyright
;
594 vbe_info_block
.Capabilities
[0] = VBE_CAPABILITY_8BIT_DAC
;
595 vbe_info_block
.Capabilities
[1] = 0;
596 vbe_info_block
.Capabilities
[2] = 0;
597 vbe_info_block
.Capabilities
[3] = 0;
600 // VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
601 vbe_info_block
.VideoModePtr_Seg
= ES
;
602 vbe_info_block
.VideoModePtr_Off
= DI
+ 34;
604 // VBE Video Mode Pointer (staticly in rom)
605 vbe_info_block
.VideoModePtr_Seg
= 0xc000;
606 vbe_info_block
.VideoModePtr_Off
= &vbebios_mode_list
;
609 // VBE Total Memory (in 64b blocks)
610 vbe_info_block
.TotalMemory
= VBE_TOTAL_VIDEO_MEMORY_DIV_64K
;
615 vbe_info_block
.OemSoftwareRev
= VBE_OEM_SOFTWARE_REV
;
616 vbe_info_block
.OemVendorNamePtr_Seg
= 0xc000;
617 vbe_info_block
.OemVendorNamePtr_Off
= &vbebios_vendor_name
;
618 vbe_info_block
.OemProductNamePtr_Seg
= 0xc000;
619 vbe_info_block
.OemProductNamePtr_Off
= &vbebios_product_name
;
620 vbe_info_block
.OemProductRevPtr_Seg
= 0xc000;
621 vbe_info_block
.OemProductRevPtr_Off
= &vbebios_product_revision
;
623 // copy updates in vbe_info_block back
624 memcpyb(ES
, DI
, ss
, &vbe_info_block
, sizeof(vbe_info_block
));
628 // copy updates in vbe_info_block back (VBE 1.x compatibility)
629 memcpyb(ES
, DI
, ss
, &vbe_info_block
, 256);
635 if (cur_info
->info
.BitsPerPixel
<= dispi_get_max_bpp()) {
637 printf("VBE found mode %x => %x\n", cur_info
->mode
,cur_mode
);
639 write_word(ES
, DI
+ cur_ptr
, cur_info
->mode
);
644 } while (cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
);
646 // Add vesa mode list terminator
647 write_word(ES
, DI
+ cur_ptr
, cur_info
->mode
);
652 write_word(ss
, AX
, result
);
656 /** Function 01h - Return VBE Mode Information
661 * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
663 * AX = VBE Return Status
666 void vbe_biosfn_return_mode_information(AX
, CX
, ES
, DI
)
667 Bit16u
*AX
;Bit16u CX
; Bit16u ES
;Bit16u DI
;
669 Bit16u result
=0x0100;
672 ModeInfoListItem
*cur_info
;
676 printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES
,DI
,CX
);
679 using_lfb
=((CX
& VBE_MODE_LINEAR_FRAME_BUFFER
) == VBE_MODE_LINEAR_FRAME_BUFFER
);
683 cur_info
= mode_info_find_mode(CX
, using_lfb
, &cur_info
);
688 printf("VBE found mode %x\n",CX
);
690 memsetb(ss
, &info
, 0, sizeof(ModeInfoBlock
));
691 memcpyb(ss
, &info
, 0xc000, &(cur_info
->info
), sizeof(ModeInfoBlockCompact
));
692 if (info
.WinAAttributes
& VBE_WINDOW_ATTRIBUTE_RELOCATABLE
) {
693 info
.WinFuncPtr
= 0xC0000000UL
;
694 *(Bit16u
*)&(info
.WinFuncPtr
) = (Bit16u
)(dispi_set_bank_farcall
);
702 printf("VBE *NOT* found mode %x\n",CX
);
709 // copy updates in mode_info_block back
710 memcpyb(ES
, DI
, ss
, &info
, sizeof(info
));
713 write_word(ss
, AX
, result
);
716 /** Function 02h - Set VBE Mode
720 * BX = Desired Mode to set
721 * ES:DI = Pointer to CRTCInfoBlock structure
723 * AX = VBE Return Status
726 void vbe_biosfn_set_mode(AX
, BX
, ES
, DI
)
727 Bit16u
*AX
;Bit16u BX
; Bit16u ES
;Bit16u DI
;
729 Bit16u ss
= get_SS();
731 ModeInfoListItem
*cur_info
;
736 using_lfb
=((BX
& VBE_MODE_LINEAR_FRAME_BUFFER
) == VBE_MODE_LINEAR_FRAME_BUFFER
);
737 lfb_flag
=using_lfb
?VBE_DISPI_LFB_ENABLED
:0;
738 no_clear
=((BX
& VBE_MODE_PRESERVE_DISPLAY_MEMORY
) == VBE_MODE_PRESERVE_DISPLAY_MEMORY
)?VBE_DISPI_NOCLEARMEM
:0;
742 //result=read_word(ss,AX);
744 // check for non vesa mode
745 if (BX
<VBE_MODE_VESA_DEFINED
)
749 dispi_set_enable(VBE_DISPI_DISABLED
);
750 // call the vgabios in order to set the video mode
751 // this allows for going back to textmode with a VBE call (some applications expect that to work)
754 biosfn_set_video_mode(mode
);
758 cur_info
= mode_info_find_mode(BX
, using_lfb
, &cur_info
);
763 printf("VBE found mode %x, setting:\n", BX
);
764 printf("\txres%x yres%x bpp%x\n",
765 cur_info
->info
.XResolution
,
766 cur_info
->info
.YResolution
,
767 cur_info
->info
.BitsPerPixel
);
770 // first disable current mode (when switching between vesa modi)
771 dispi_set_enable(VBE_DISPI_DISABLED
);
773 if (cur_info
->mode
== VBE_VESA_MODE_800X600X4
)
775 biosfn_set_video_mode(0x6a);
778 dispi_set_bpp(cur_info
->info
.BitsPerPixel
);
779 dispi_set_xres(cur_info
->info
.XResolution
);
780 dispi_set_yres(cur_info
->info
.YResolution
);
782 dispi_set_enable(VBE_DISPI_ENABLED
| no_clear
| lfb_flag
);
784 write_word(BIOSMEM_SEG
,BIOSMEM_VBE_MODE
,BX
);
785 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,(0x60 | no_clear
));
792 printf("VBE *NOT* found mode %x\n" , BX
);
796 // FIXME: redirect non VBE modi to normal VGA bios operation
797 // (switch back to VGA mode
802 write_word(ss
, AX
, result
);
805 /** Function 03h - Return Current VBE Mode
810 * AX = VBE Return Status
811 * BX = Current VBE Mode
815 vbe_biosfn_return_current_mode
:
817 mov ax
, # BIOSMEM_SEG
819 call dispi_get_enable
820 and ax
, # VBE_DISPI_ENABLED
822 mov bx
, # BIOSMEM_VBE_MODE
827 mov bx
, # BIOSMEM_CURRENT_MODE
838 /** Function 04h - Save/Restore State
842 * DL = 00h Return Save/Restore State buffer size
845 * CX = Requested states
846 * ES:BX = Pointer to buffer (if DL <> 00h)
848 * AX = VBE Return Status
849 * BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
852 void vbe_biosfn_save_restore_state(AX
, DL
, CX
, ES
, BX
)
857 /** Function 05h - Display Window Control
861 * (16-bit) BH = 00h Set memory window
862 * = 01h Get memory window
866 * DX = Window number in video memory in window
867 * granularity units (Set Memory Window only)
869 * If this function is called while in a linear frame buffer mode,
870 * this function must fail with completion code AH=03h
873 * AX = VBE Return Status
874 * DX = Window number in window granularity units
875 * (Get Memory Window only)
878 vbe_biosfn_display_window_control
:
882 je get_display_window
883 jb set_display_window
905 /** Function 06h - Set/Get Logical Scan Line Length
909 * BL = 00h Set Scan Line Length in Pixels
910 * = 01h Get Scan Line Length
911 * = 02h Set Scan Line Length in Bytes
912 * = 03h Get Maximum Scan Line Length
913 * CX = If BL=00h Desired Width in Pixels
914 * If BL=02h Desired Width in Bytes
915 * (Ignored for Get Functions)
918 * AX = VBE Return Status
919 * BX = Bytes Per Scan Line
920 * CX = Actual Pixels Per Scan Line
921 * (truncated to nearest complete pixel)
922 * DX = Maximum Number of Scan Lines
925 vbe_biosfn_set_get_logical_scan_line_length
:
928 je get_logical_scan_line_length
930 je set_logical_scan_line_bytes
931 jb set_logical_scan_line_pixels
934 set_logical_scan_line_bytes
:
942 set_logical_scan_line_pixels
:
943 call dispi_set_virt_width
944 get_logical_scan_line_length
:
948 call dispi_get_virt_width
952 call dispi_get_virt_height
959 /** Function 07h - Set/Get Display Start
963 * BH = 00h Reserved and must be 00h
964 * BL = 00h Set Display Start
965 * = 01h Get Display Start
966 * = 02h Schedule Display Start (Alternate)
967 * = 03h Schedule Stereoscopic Display Start
968 * = 04h Get Scheduled Display Start Status
969 * = 05h Enable Stereoscopic Mode
970 * = 06h Disable Stereoscopic Mode
971 * = 80h Set Display Start during Vertical Retrace
972 * = 82h Set Display Start during Vertical Retrace (Alternate)
973 * = 83h Set Stereoscopic Display Start during Vertical Retrace
974 * ECX = If BL=02h/82h Display Start Address in bytes
975 * If BL=03h/83h Left Image Start Address in bytes
976 * EDX = If BL=03h/83h Right Image Start Address in bytes
977 * CX = If BL=00h/80h First Displayed Pixel In Scan Line
978 * DX = If BL=00h/80h First Displayed Scan Line
981 * AX = VBE Return Status
982 * BH = If BL=01h Reserved and will be 0
983 * CX = If BL=01h First Displayed Pixel In Scan Line
984 * If BL=04h 0 if flip has not occurred, not 0 if it has
985 * DX = If BL=01h First Displayed Scan Line
988 * BH = 00h Reserved and must be 00h
989 * BL = 00h Set Display Start
990 * = 80h Set Display Start during Vertical Retrace
991 * CX = Bits 0-15 of display start address
992 * DX = Bits 16-31 of display start address
993 * ES = Selector for memory mapped registers
996 vbe_biosfn_set_get_display_start
:
1000 je get_display_start
1001 jb set_display_start
1006 call dispi_set_x_offset
1008 call dispi_set_y_offset
1012 call dispi_get_x_offset
1014 call dispi_get_y_offset
1022 /** Function 08h - Set/Get Dac Palette Format
1026 * BL = 00h set DAC palette width
1027 * = 01h get DAC palette width
1028 * BH = If BL=00h: desired number of bits per primary color
1030 * AX = VBE Return Status
1031 * BH = current number of bits per primary color (06h = standard VGA)
1034 vbe_biosfn_set_get_dac_palette_format
:
1036 je get_dac_palette_format
1037 jb set_dac_palette_format
1040 set_dac_palette_format
:
1041 call dispi_get_enable
1045 jne vbe_08_unsupported
1046 or ax
, # VBE_DISPI_8BIT_DAC
1049 and ax
, #~ VBE_DISPI_8BIT_DAC
1051 call _dispi_set_enable
1052 get_dac_palette_format
:
1054 call dispi_get_enable
1055 and ax
, # VBE_DISPI_8BIT_DAC
1067 /** Function 09h - Set/Get Palette Data
1072 * AX = VBE Return Status
1074 * FIXME: incomplete API description, Input & Output
1076 void vbe_biosfn_set_get_palette_data(AX
)
1080 /** Function 0Ah - Return VBE Protected Mode Interface
1081 * Input: AX = 4F0Ah VBE 2.0 Protected Mode Interface
1082 * BL = 00h Return protected mode table
1085 * Output: AX = Status
1086 * ES = Real Mode Segment of Table
1087 * DI = Offset of Table
1088 * CX = Length of Table including protected mode code
1089 * (for copying purposes)
1092 vbe_biosfn_return_protected_mode_interface
:
1097 mov di
, # vesa_pm_start
1098 mov cx
, # vesa_pm_end