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!"
90 .ascii
"VBE Bios $Id$"
95 // FIXME: for each new mode add a statement here
96 // at least until dynamic list creation is working
99 .word VBE_VESA_MODE_640X400X8
100 .word VBE_VESA_MODE_640X480X8
101 .word VBE_VESA_MODE_800X600X4
102 .word VBE_VESA_MODE_800X600X8
103 .word VBE_VESA_MODE_1024X768X8
104 .word VBE_VESA_MODE_640X480X1555
105 .word VBE_VESA_MODE_640X480X565
106 .word VBE_VESA_MODE_640X480X888
107 .word VBE_VESA_MODE_800X600X1555
108 .word VBE_VESA_MODE_800X600X565
109 .word VBE_VESA_MODE_800X600X888
110 .word VBE_VESA_MODE_1024X768X1555
111 .word VBE_VESA_MODE_1024X768X565
112 .word VBE_VESA_MODE_1024X768X888
113 .word VBE_OWN_MODE_640X480X8888
114 .word VBE_OWN_MODE_800X600X8888
115 .word VBE_OWN_MODE_1024X768X8888
116 .word VBE_OWN_MODE_320X200X8
117 .word VBE_VESA_MODE_END_OF_LIST
123 #define PANIC_PORT 0x501
127 ;; the HALT macro is called with the line number of the HALT call
.
128 ;; The line number is then sent to the PANIC_PORT
, causing Bochs to
129 ;; print a BX_PANIC message
. This will normally halt the simulation
130 ;; with a message such as
"BIOS panic at rombios.c, line 4091".
131 ;; However
, users can choose to make panics non
-fatal
and continue.
137 ; DISPI ioport functions
141 mov dx
, # VBE_DISPI_IOPORT_INDEX
142 mov ax
, # VBE_DISPI_INDEX_ID
144 mov dx
, # VBE_DISPI_IOPORT_DATA
152 mov dx
, # VBE_DISPI_IOPORT_INDEX
153 mov ax
, # VBE_DISPI_INDEX_ID
156 mov dx
, # VBE_DISPI_IOPORT_DATA
162 static void dispi_set_xres(xres
)
165 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_XRES
);
166 outw(VBE_DISPI_IOPORT_DATA
,xres
);
169 static void dispi_set_yres(yres
)
172 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_YRES
);
173 outw(VBE_DISPI_IOPORT_DATA
,yres
);
176 static void dispi_set_bpp(bpp
)
179 outw(VBE_DISPI_IOPORT_INDEX
,VBE_DISPI_INDEX_BPP
);
180 outw(VBE_DISPI_IOPORT_DATA
,bpp
);
184 ; AL
= bits per pixel
/ AH
= bytes per pixel
187 mov dx
, # VBE_DISPI_IOPORT_INDEX
188 mov ax
, # VBE_DISPI_INDEX_BPP
190 mov dx
, # VBE_DISPI_IOPORT_DATA
204 call dispi_get_enable
206 or ax
, # VBE_DISPI_GETCAPS
207 call _dispi_set_enable
208 mov dx
, # VBE_DISPI_IOPORT_INDEX
209 mov ax
, # VBE_DISPI_INDEX_BPP
211 mov dx
, # VBE_DISPI_IOPORT_DATA
215 call _dispi_set_enable
224 mov dx
, # VBE_DISPI_IOPORT_INDEX
225 mov ax
, # VBE_DISPI_INDEX_ENABLE
228 mov dx
, # VBE_DISPI_IOPORT_DATA
235 mov dx
, # VBE_DISPI_IOPORT_INDEX
236 mov ax
, # VBE_DISPI_INDEX_ENABLE
238 mov dx
, # VBE_DISPI_IOPORT_DATA
248 mov dx
, # VBE_DISPI_IOPORT_INDEX
249 mov ax
, # VBE_DISPI_INDEX_BANK
252 mov dx
, # VBE_DISPI_IOPORT_DATA
259 mov dx
, # VBE_DISPI_IOPORT_INDEX
260 mov ax
, # VBE_DISPI_INDEX_BANK
262 mov dx
, # VBE_DISPI_IOPORT_DATA
268 static void dispi_set_bank_farcall()
272 je dispi_set_bank_farcall_get
274 jnz dispi_set_bank_farcall_error
276 mov ax
,# VBE_DISPI_INDEX_BANK
277 mov dx
,# VBE_DISPI_IOPORT_INDEX
280 mov dx
,# VBE_DISPI_IOPORT_DATA
283 dispi_set_bank_farcall_get
:
284 mov ax
,# VBE_DISPI_INDEX_BANK
285 mov dx
,# VBE_DISPI_IOPORT_INDEX
287 mov dx
,# VBE_DISPI_IOPORT_DATA
291 dispi_set_bank_farcall_error
:
301 mov dx
, # VBE_DISPI_IOPORT_INDEX
302 mov ax
, # VBE_DISPI_INDEX_X_OFFSET
305 mov dx
, # VBE_DISPI_IOPORT_DATA
312 mov dx
, # VBE_DISPI_IOPORT_INDEX
313 mov ax
, # VBE_DISPI_INDEX_X_OFFSET
315 mov dx
, # VBE_DISPI_IOPORT_DATA
323 mov dx
, # VBE_DISPI_IOPORT_INDEX
324 mov ax
, # VBE_DISPI_INDEX_Y_OFFSET
327 mov dx
, # VBE_DISPI_IOPORT_DATA
334 mov dx
, # VBE_DISPI_IOPORT_INDEX
335 mov ax
, # VBE_DISPI_INDEX_Y_OFFSET
337 mov dx
, # VBE_DISPI_IOPORT_DATA
342 dispi_set_virt_width
:
345 mov dx
, # VBE_DISPI_IOPORT_INDEX
346 mov ax
, # VBE_DISPI_INDEX_VIRT_WIDTH
349 mov dx
, # VBE_DISPI_IOPORT_DATA
354 dispi_get_virt_width
:
356 mov dx
, # VBE_DISPI_IOPORT_INDEX
357 mov ax
, # VBE_DISPI_INDEX_VIRT_WIDTH
359 mov dx
, # VBE_DISPI_IOPORT_DATA
364 dispi_get_virt_height
:
366 mov dx
, # VBE_DISPI_IOPORT_INDEX
367 mov ax
, # VBE_DISPI_INDEX_VIRT_HEIGHT
369 mov dx
, # VBE_DISPI_IOPORT_DATA
376 // ModeInfo helper function
377 static ModeInfoListItem
* mode_info_find_mode(mode
, using_lfb
)
378 Bit16u mode
; Boolean using_lfb
;
380 ModeInfoListItem
*cur_info
=&mode_info_list
;
382 while (cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
)
384 if (cur_info
->mode
== mode
)
390 else if (cur_info
->info
.ModeAttributes
& VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE
)
410 ; Has VBE display
- Returns
true if VBE display detected
412 _vbe_has_vbe_display
:
415 mov ax
, # BIOSMEM_SEG
417 mov bx
, # BIOSMEM_VBE_FLAG
425 ; VBE Init
- Initialise the Vesa Bios Extension Code
426 ; This function does a sanity check on the host side display code interface
.
429 mov ax
, # VBE_DISPI_ID0
432 cmp ax
, # VBE_DISPI_ID0
436 mov ax
, # BIOSMEM_SEG
438 mov bx
, # BIOSMEM_VBE_FLAG
443 mov ax
, # VBE_DISPI_ID3
446 mov bx
, #msg_vbe_init
453 ; VBE Display Info
- Display information on screen about the VBE
456 call _vbe_has_vbe_display
461 mov si
, #_vbebios_info_string
466 mov si
, #_no_vbebios_info_string
470 /** Function 00h - Return VBE Controller Information
474 * ES:DI = Pointer to buffer in which to place VbeInfoBlock structure
475 * (VbeSignature should be VBE2 when VBE 2.0 information is desired and
476 * the info block is 512 bytes in size)
478 * AX = VBE Return Status
481 void vbe_biosfn_return_controller_information(AX
, ES
, DI
)
482 Bit16u
*AX
;Bit16u ES
;Bit16u DI
;
485 VbeInfoBlock vbe_info_block
;
491 ModeInfoListItem
*cur_info
=&mode_info_list
;
493 status
= read_word(ss
, AX
);
496 printf("VBE vbe_biosfn_return_vbe_info ES%x DI%x AX%x\n",ES
,DI
,status
);
500 #ifdef VBE2_NO_VESA_CHECK
502 // get vbe_info_block into local variable
503 memcpyb(ss
, &vbe_info_block
, ES
, DI
, sizeof(vbe_info_block
));
505 // check for VBE2 signature
506 if (((vbe_info_block
.VbeSignature
[0] == 'V') &&
507 (vbe_info_block
.VbeSignature
[1] == 'B') &&
508 (vbe_info_block
.VbeSignature
[2] == 'E') &&
509 (vbe_info_block
.VbeSignature
[3] == '2')) ||
511 ((vbe_info_block
.VbeSignature
[0] == 'V') &&
512 (vbe_info_block
.VbeSignature
[1] == 'E') &&
513 (vbe_info_block
.VbeSignature
[2] == 'S') &&
514 (vbe_info_block
.VbeSignature
[3] == 'A')) )
518 printf("VBE correct VESA/VBE2 signature found\n");
524 vbe_info_block
.VbeSignature
[0] = 'V';
525 vbe_info_block
.VbeSignature
[1] = 'E';
526 vbe_info_block
.VbeSignature
[2] = 'S';
527 vbe_info_block
.VbeSignature
[3] = 'A';
529 // VBE Version supported
530 vbe_info_block
.VbeVersion
= 0x0200;
533 vbe_info_block
.OemStringPtr_Seg
= 0xc000;
534 vbe_info_block
.OemStringPtr_Off
= &vbebios_copyright
;
537 vbe_info_block
.Capabilities
[0] = VBE_CAPABILITY_8BIT_DAC
;
538 vbe_info_block
.Capabilities
[1] = 0;
539 vbe_info_block
.Capabilities
[2] = 0;
540 vbe_info_block
.Capabilities
[3] = 0;
543 // VBE Video Mode Pointer (dynamicly generated from the mode_info_list)
544 vbe_info_block
.VideoModePtr_Seg
= ES
;
545 vbe_info_block
.VideoModePtr_Off
= DI
+ 34;
547 // VBE Video Mode Pointer (staticly in rom)
548 vbe_info_block
.VideoModePtr_Seg
= 0xc000;
549 vbe_info_block
.VideoModePtr_Off
= &vbebios_mode_list
;
552 // VBE Total Memory (in 64b blocks)
553 vbe_info_block
.TotalMemory
= VBE_TOTAL_VIDEO_MEMORY_DIV_64K
;
558 vbe_info_block
.OemSoftwareRev
= VBE_OEM_SOFTWARE_REV
;
559 vbe_info_block
.OemVendorNamePtr_Seg
= 0xc000;
560 vbe_info_block
.OemVendorNamePtr_Off
= &vbebios_vendor_name
;
561 vbe_info_block
.OemProductNamePtr_Seg
= 0xc000;
562 vbe_info_block
.OemProductNamePtr_Off
= &vbebios_product_name
;
563 vbe_info_block
.OemProductRevPtr_Seg
= 0xc000;
564 vbe_info_block
.OemProductRevPtr_Off
= &vbebios_product_revision
;
566 // copy updates in vbe_info_block back
567 memcpyb(ES
, DI
, ss
, &vbe_info_block
, sizeof(vbe_info_block
));
571 // copy updates in vbe_info_block back (VBE 1.x compatibility)
572 memcpyb(ES
, DI
, ss
, &vbe_info_block
, 256);
578 if (cur_info
->info
.BitsPerPixel
<= dispi_get_max_bpp()) {
580 printf("VBE found mode %x => %x\n", cur_info
->mode
,cur_mode
);
582 write_word(ES
, DI
+ cur_ptr
, cur_info
->mode
);
587 } while (cur_info
->mode
!= VBE_VESA_MODE_END_OF_LIST
);
589 // Add vesa mode list terminator
590 write_word(ES
, DI
+ cur_ptr
, cur_info
->mode
);
595 write_word(ss
, AX
, result
);
599 /** Function 01h - Return VBE Mode Information
604 * ES:DI = Pointer to buffer in which to place ModeInfoBlock structure
606 * AX = VBE Return Status
609 void vbe_biosfn_return_mode_information(AX
, CX
, ES
, DI
)
610 Bit16u
*AX
;Bit16u CX
; Bit16u ES
;Bit16u DI
;
612 Bit16u result
=0x0100;
615 ModeInfoListItem
*cur_info
;
619 printf("VBE vbe_biosfn_return_mode_information ES%x DI%x CX%x\n",ES
,DI
,CX
);
622 using_lfb
=((CX
& VBE_MODE_LINEAR_FRAME_BUFFER
) == VBE_MODE_LINEAR_FRAME_BUFFER
);
626 cur_info
= mode_info_find_mode(CX
, using_lfb
, &cur_info
);
631 printf("VBE found mode %x\n",CX
);
633 memsetb(ss
, &info
, 0, sizeof(ModeInfoBlock
));
634 memcpyb(ss
, &info
, 0xc000, &(cur_info
->info
), sizeof(ModeInfoBlockCompact
));
635 if (info
.WinAAttributes
& VBE_WINDOW_ATTRIBUTE_RELOCATABLE
) {
636 info
.WinFuncPtr
= 0xC0000000UL
;
637 *(Bit16u
*)&(info
.WinFuncPtr
) = (Bit16u
)(dispi_set_bank_farcall
);
645 printf("VBE *NOT* found mode %x\n",CX
);
652 // copy updates in mode_info_block back
653 memcpyb(ES
, DI
, ss
, &info
, sizeof(info
));
656 write_word(ss
, AX
, result
);
659 /** Function 02h - Set VBE Mode
663 * BX = Desired Mode to set
664 * ES:DI = Pointer to CRTCInfoBlock structure
666 * AX = VBE Return Status
669 void vbe_biosfn_set_mode(AX
, BX
, ES
, DI
)
670 Bit16u
*AX
;Bit16u BX
; Bit16u ES
;Bit16u DI
;
672 Bit16u ss
= get_SS();
674 ModeInfoListItem
*cur_info
;
679 using_lfb
=((BX
& VBE_MODE_LINEAR_FRAME_BUFFER
) == VBE_MODE_LINEAR_FRAME_BUFFER
);
680 lfb_flag
=using_lfb
?VBE_DISPI_LFB_ENABLED
:0;
681 no_clear
=((BX
& VBE_MODE_PRESERVE_DISPLAY_MEMORY
) == VBE_MODE_PRESERVE_DISPLAY_MEMORY
)?VBE_DISPI_NOCLEARMEM
:0;
685 //result=read_word(ss,AX);
687 // check for non vesa mode
688 if (BX
<VBE_MODE_VESA_DEFINED
)
692 dispi_set_enable(VBE_DISPI_DISABLED
);
693 // call the vgabios in order to set the video mode
694 // this allows for going back to textmode with a VBE call (some applications expect that to work)
697 biosfn_set_video_mode(mode
);
701 cur_info
= mode_info_find_mode(BX
, using_lfb
, &cur_info
);
706 printf("VBE found mode %x, setting:\n", BX
);
707 printf("\txres%x yres%x bpp%x\n",
708 cur_info
->info
.XResolution
,
709 cur_info
->info
.YResolution
,
710 cur_info
->info
.BitsPerPixel
);
713 // first disable current mode (when switching between vesa modi)
714 dispi_set_enable(VBE_DISPI_DISABLED
);
716 if (cur_info
->mode
== VBE_VESA_MODE_800X600X4
)
718 biosfn_set_video_mode(0x6a);
721 dispi_set_xres(cur_info
->info
.XResolution
);
722 dispi_set_yres(cur_info
->info
.YResolution
);
723 dispi_set_bpp(cur_info
->info
.BitsPerPixel
);
725 dispi_set_enable(VBE_DISPI_ENABLED
| no_clear
| lfb_flag
);
727 write_word(BIOSMEM_SEG
,BIOSMEM_VBE_MODE
,BX
);
728 write_byte(BIOSMEM_SEG
,BIOSMEM_VIDEO_CTL
,(0x60 | no_clear
));
735 printf("VBE *NOT* found mode %x\n" , BX
);
739 // FIXME: redirect non VBE modi to normal VGA bios operation
740 // (switch back to VGA mode
745 write_word(ss
, AX
, result
);
748 /** Function 03h - Return Current VBE Mode
753 * AX = VBE Return Status
754 * BX = Current VBE Mode
758 vbe_biosfn_return_current_mode
:
760 mov ax
, # BIOSMEM_SEG
762 call dispi_get_enable
763 and ax
, # VBE_DISPI_ENABLED
765 mov bx
, # BIOSMEM_VBE_MODE
770 mov bx
, # BIOSMEM_CURRENT_MODE
781 /** Function 04h - Save/Restore State
785 * DL = 00h Return Save/Restore State buffer size
788 * CX = Requested states
789 * ES:BX = Pointer to buffer (if DL <> 00h)
791 * AX = VBE Return Status
792 * BX = Number of 64-byte blocks to hold the state buffer (if DL=00h)
795 void vbe_biosfn_save_restore_state(AX
, DL
, CX
, ES
, BX
)
800 /** Function 05h - Display Window Control
804 * (16-bit) BH = 00h Set memory window
805 * = 01h Get memory window
809 * DX = Window number in video memory in window
810 * granularity units (Set Memory Window only)
812 * If this function is called while in a linear frame buffer mode,
813 * this function must fail with completion code AH=03h
816 * AX = VBE Return Status
817 * DX = Window number in window granularity units
818 * (Get Memory Window only)
821 vbe_biosfn_display_window_control
:
825 je get_display_window
826 jb set_display_window
848 /** Function 06h - Set/Get Logical Scan Line Length
852 * BL = 00h Set Scan Line Length in Pixels
853 * = 01h Get Scan Line Length
854 * = 02h Set Scan Line Length in Bytes
855 * = 03h Get Maximum Scan Line Length
856 * CX = If BL=00h Desired Width in Pixels
857 * If BL=02h Desired Width in Bytes
858 * (Ignored for Get Functions)
861 * AX = VBE Return Status
862 * BX = Bytes Per Scan Line
863 * CX = Actual Pixels Per Scan Line
864 * (truncated to nearest complete pixel)
865 * DX = Maximum Number of Scan Lines
868 vbe_biosfn_set_get_logical_scan_line_length
:
871 je get_logical_scan_line_length
873 je set_logical_scan_line_bytes
874 jb set_logical_scan_line_pixels
877 set_logical_scan_line_bytes
:
885 set_logical_scan_line_pixels
:
886 call dispi_set_virt_width
887 get_logical_scan_line_length
:
891 call dispi_get_virt_width
895 call dispi_get_virt_height
902 /** Function 07h - Set/Get Display Start
906 * BH = 00h Reserved and must be 00h
907 * BL = 00h Set Display Start
908 * = 01h Get Display Start
909 * = 02h Schedule Display Start (Alternate)
910 * = 03h Schedule Stereoscopic Display Start
911 * = 04h Get Scheduled Display Start Status
912 * = 05h Enable Stereoscopic Mode
913 * = 06h Disable Stereoscopic Mode
914 * = 80h Set Display Start during Vertical Retrace
915 * = 82h Set Display Start during Vertical Retrace (Alternate)
916 * = 83h Set Stereoscopic Display Start during Vertical Retrace
917 * ECX = If BL=02h/82h Display Start Address in bytes
918 * If BL=03h/83h Left Image Start Address in bytes
919 * EDX = If BL=03h/83h Right Image Start Address in bytes
920 * CX = If BL=00h/80h First Displayed Pixel In Scan Line
921 * DX = If BL=00h/80h First Displayed Scan Line
924 * AX = VBE Return Status
925 * BH = If BL=01h Reserved and will be 0
926 * CX = If BL=01h First Displayed Pixel In Scan Line
927 * If BL=04h 0 if flip has not occurred, not 0 if it has
928 * DX = If BL=01h First Displayed Scan Line
931 * BH = 00h Reserved and must be 00h
932 * BL = 00h Set Display Start
933 * = 80h Set Display Start during Vertical Retrace
934 * CX = Bits 0-15 of display start address
935 * DX = Bits 16-31 of display start address
936 * ES = Selector for memory mapped registers
939 vbe_biosfn_set_get_display_start
:
949 call dispi_set_x_offset
951 call dispi_set_y_offset
955 call dispi_get_x_offset
957 call dispi_get_y_offset
965 /** Function 08h - Set/Get Dac Palette Format
969 * BL = 00h set DAC palette width
970 * = 01h get DAC palette width
971 * BH = If BL=00h: desired number of bits per primary color
973 * AX = VBE Return Status
974 * BH = current number of bits per primary color (06h = standard VGA)
977 vbe_biosfn_set_get_dac_palette_format
:
979 je get_dac_palette_format
980 jb set_dac_palette_format
983 set_dac_palette_format
:
984 call dispi_get_enable
988 jne vbe_08_unsupported
989 or ax
, # VBE_DISPI_8BIT_DAC
992 and ax
, #~ VBE_DISPI_8BIT_DAC
994 call _dispi_set_enable
995 get_dac_palette_format
:
997 call dispi_get_enable
998 and ax
, # VBE_DISPI_8BIT_DAC
1010 /** Function 09h - Set/Get Palette Data
1015 * AX = VBE Return Status
1017 * FIXME: incomplete API description, Input & Output
1019 void vbe_biosfn_set_get_palette_data(AX
)
1023 /** Function 0Ah - Return VBE Protected Mode Interface
1028 * AX = VBE Return Status
1030 * FIXME: incomplete API description, Input & Output
1032 void vbe_biosfn_return_protected_mode_interface(AX
)