1 // VGA bios implementation
3 // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2001-2008 the LGPL VGABios developers Team
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
10 // * review correctness of converted asm by comparing with RBIL
12 // * convert vbe/clext code
14 #include "bregs.h" // struct bregs
15 #include "biosvar.h" // GET_BDA
16 #include "util.h" // memset
17 #include "vgabios.h" // find_vga_entry
18 #include "optionroms.h" // struct pci_data
19 #include "config.h" // CONFIG_*
20 #include "geodelx.h" // geodelx_init
21 #include "bochsvga.h" // bochsvga_init
24 #define DEBUG_VGA_POST 1
25 #define DEBUG_VGA_10 3
28 /****************************************************************
30 ****************************************************************/
31 #if CONFIG_VGA_PCI == 1
32 struct pci_data rom_pci_data VAR16VISIBLE = {
33 .signature = PCI_ROM_SIGNATURE,
34 .vendor = CONFIG_VGA_VID,
35 .device = CONFIG_VGA_DID,
39 .type = PCIROM_CODETYPE_X86,
44 /****************************************************************
46 ****************************************************************/
49 call16_vgaint(u32 eax, u32 ebx)
61 perform_gray_scale_summing(u16 start, u16 count)
63 vgahw_screen_disable();
65 for (i = start; i < start+count; i++) {
67 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
69 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
70 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
74 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
76 vgahw_screen_enable();
80 set_cursor_shape(u8 start, u8 end)
85 u16 curs = (start << 8) + end;
86 SET_BDA(cursor_type, curs);
88 u8 modeset_ctl = GET_BDA(modeset_ctl);
89 u16 cheight = GET_BDA(char_height);
90 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
91 if (end != (start + 1))
92 start = ((start + 1) * cheight / 8) - 1;
94 start = ((end + 1) * cheight / 8) - 2;
95 end = ((end + 1) * cheight / 8) - 1;
97 vgahw_set_cursor_shape(start, end);
101 get_cursor_shape(u8 page)
105 // FIXME should handle VGA 14/16 lines
106 return GET_BDA(cursor_type);
110 set_cursor_pos(struct cursorpos cp)
112 // Should not happen...
117 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
119 // Set the hardware cursor
120 u8 current = GET_BDA(video_page);
121 if (cp.page != current)
124 // Get the dimensions
125 u16 nbcols = GET_BDA(video_cols);
126 u16 nbrows = GET_BDA(video_rows) + 1;
128 // Calculate the address knowing nbcols nbrows and page num
129 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
130 + cp.x + cp.y * nbcols);
132 vgahw_set_cursor_pos(address);
135 static struct cursorpos
136 get_cursor_pos(u8 page)
139 // special case - use current page
140 page = GET_BDA(video_page);
142 struct cursorpos cp = { 0, 0, 0xfe };
145 // FIXME should handle VGA 14/16 lines
146 u16 xy = GET_BDA(cursor_pos[page]);
147 struct cursorpos cp = {xy, xy>>8, page};
152 set_active_page(u8 page)
158 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
162 // Get pos curs pos for the right page
163 struct cursorpos cp = get_cursor_pos(page);
166 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
167 // Get the dimensions
168 u16 nbcols = GET_BDA(video_cols);
169 u16 nbrows = GET_BDA(video_rows) + 1;
171 // Calculate the address knowing nbcols nbrows and page num
172 address = SCREEN_MEM_START(nbcols, nbrows, page);
173 SET_BDA(video_pagestart, address);
176 address = SCREEN_IO_START(nbcols, nbrows, page);
178 address = page * GET_GLOBAL(vmode_g->slength);
181 vgahw_set_active_page(address);
183 // And change the BIOS page
184 SET_BDA(video_page, page);
186 dprintf(1, "Set active page %02x address %04x\n", page, address);
188 // Display the cursor, now the page is active
193 set_scan_lines(u8 lines)
195 vgahw_set_scan_lines(lines);
197 set_cursor_shape(0x06, 0x07);
199 set_cursor_shape(lines - 4, lines - 3);
200 SET_BDA(char_height, lines);
201 u16 vde = vgahw_get_vde();
202 u8 rows = vde / lines;
203 SET_BDA(video_rows, rows - 1);
204 u16 cols = GET_BDA(video_cols);
205 SET_BDA(video_pagesize, rows * cols * 2);
209 /****************************************************************
211 ****************************************************************/
213 // Scroll the screen one line. This function is designed to be called
214 // tail-recursive to reduce stack usage.
216 scroll_one(u16 nbrows, u16 nbcols, u8 page)
218 struct cursorpos ul = {0, 0, page};
219 struct cursorpos lr = {nbcols-1, nbrows-1, page};
220 vgafb_scroll(1, -1, ul, lr);
223 // Write a character to the screen at a given position. Implement
224 // special characters and scroll the screen if necessary.
226 write_teletype(struct cursorpos *pcp, struct carattr ca)
228 struct cursorpos cp = *pcp;
230 // Get the dimensions
231 u16 nbrows = GET_BDA(video_rows) + 1;
232 u16 nbcols = GET_BDA(video_cols);
250 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
251 vgafb_write_char(cp, dummyca);
253 } while (cp.x < nbcols && cp.x % 8);
256 vgafb_write_char(cp, ca);
260 // Do we need to wrap ?
261 if (cp.x == nbcols) {
265 // Do we need to scroll ?
273 scroll_one(nbrows, nbcols, cp.page);
276 // Write out a buffer of alternating characters and attributes.
278 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
281 u8 car = GET_FARVAR(seg, *offset_far);
283 u8 attr = GET_FARVAR(seg, *offset_far);
286 struct carattr ca = {car, attr, 1};
287 write_teletype(pcp, ca);
291 // Write out a buffer of characters.
293 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
296 u8 car = GET_FARVAR(seg, *offset_far);
299 struct carattr ca = {car, attr, 1};
300 write_teletype(pcp, ca);
305 /****************************************************************
306 * Save and restore bda state
307 ****************************************************************/
310 save_bda_state(u16 seg, struct saveBDAstate *info)
312 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
313 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
314 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
315 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
316 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
317 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
318 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
319 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
320 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
321 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
324 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
325 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
326 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
328 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
329 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
333 restore_bda_state(u16 seg, struct saveBDAstate *info)
335 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
336 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
337 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
338 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
339 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
340 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
341 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
342 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
343 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
344 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
346 for (i = 0; i < 8; i++)
347 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
348 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
349 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
351 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
352 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
356 /****************************************************************
358 ****************************************************************/
362 vga_set_mode(u8 mode, u8 noclearmem)
364 // find the entry in the video modes
365 struct vgamode_s *vmode_g = find_vga_entry(mode);
366 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
370 // Read the bios mode set control
371 u8 modeset_ctl = GET_BDA(modeset_ctl);
373 // Then we know the number of lines
376 // if palette loading (bit 3 of modeset ctl = 0)
377 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
378 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
380 // From which palette
381 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
382 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
384 // Always 256*3 values
385 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
387 for (i = palsize; i < 0x0100; i++) {
388 static u8 rgb[3] VAR16;
389 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
392 if ((modeset_ctl & 0x02) == 0x02)
393 perform_gray_scale_summing(0x00, 0x100);
396 vgahw_set_mode(vmode_g);
398 if (noclearmem == 0x00)
399 clear_screen(vmode_g);
401 // Set CRTC address VGA or MDA
402 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
403 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
404 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
407 u16 cheight = GET_GLOBAL(vmode_g->cheight);
408 SET_BDA(video_mode, mode);
409 SET_BDA(video_cols, GET_GLOBAL(vmode_g->twidth));
410 SET_BDA(video_pagesize, GET_GLOBAL(vmode_g->slength));
411 SET_BDA(crtc_address, crtc_addr);
412 SET_BDA(video_rows, GET_GLOBAL(vmode_g->theight)-1);
413 SET_BDA(char_height, cheight);
414 SET_BDA(video_ctl, (0x60 | noclearmem));
415 SET_BDA(video_switches, 0xF9);
416 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
418 // FIXME We nearly have the good tables. to be reworked
419 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
420 SET_BDA(video_savetable
421 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
424 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
425 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
428 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
429 set_cursor_shape(0x06, 0x07);
430 // Set cursor pos for page 0..7
432 for (i = 0; i < 8; i++) {
433 struct cursorpos cp = {0, 0, i};
438 set_active_page(0x00);
440 // Write the fonts in memory
441 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
442 call16_vgaint(0x1104, 0);
443 call16_vgaint(0x1103, 0);
445 // Set the ints 0x1F and 0x43
446 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
450 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
453 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
456 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
462 handle_1000(struct bregs *regs)
464 u8 noclearmem = regs->al & 0x80;
465 u8 mode = regs->al & 0x7f;
475 if (CONFIG_VGA_CIRRUS) {
476 int ret = cirrus_set_video_mode(mode, noclearmem);
481 if (bochsvga_enabled())
482 bochsvga_hires_enable(0);
484 vga_set_mode(mode, noclearmem);
488 handle_1001(struct bregs *regs)
490 set_cursor_shape(regs->ch, regs->cl);
494 handle_1002(struct bregs *regs)
496 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
501 handle_1003(struct bregs *regs)
503 regs->cx = get_cursor_shape(regs->bh);
504 struct cursorpos cp = get_cursor_pos(regs->bh);
509 // Read light pen pos (unimplemented)
511 handle_1004(struct bregs *regs)
514 regs->ax = regs->bx = regs->cx = regs->dx = 0;
518 handle_1005(struct bregs *regs)
520 set_active_page(regs->al);
524 verify_scroll(struct bregs *regs, int dir)
526 u8 page = GET_BDA(video_page);
527 struct cursorpos ul = {regs->cl, regs->ch, page};
528 struct cursorpos lr = {regs->dl, regs->dh, page};
530 u16 nbrows = GET_BDA(video_rows) + 1;
533 u16 nbcols = GET_BDA(video_cols);
537 if (ul.x > lr.x || ul.y > lr.y)
540 u16 nblines = regs->al;
541 if (!nblines || nblines > lr.y - ul.y + 1)
542 nblines = lr.y - ul.y + 1;
544 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
548 handle_1006(struct bregs *regs)
550 verify_scroll(regs, 1);
554 handle_1007(struct bregs *regs)
556 verify_scroll(regs, -1);
560 handle_1008(struct bregs *regs)
562 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
568 write_chars(u8 page, struct carattr ca, u16 count)
570 struct cursorpos cp = get_cursor_pos(page);
572 vgafb_write_char(cp, ca);
578 handle_1009(struct bregs *regs)
580 struct carattr ca = {regs->al, regs->bl, 1};
581 write_chars(regs->bh, ca, regs->cx);
585 handle_100a(struct bregs *regs)
587 struct carattr ca = {regs->al, regs->bl, 0};
588 write_chars(regs->bh, ca, regs->cx);
593 handle_100b00(struct bregs *regs)
595 vgahw_set_border_color(regs->bl);
599 handle_100b01(struct bregs *regs)
601 vgahw_set_palette(regs->bl);
605 handle_100bXX(struct bregs *regs)
611 handle_100b(struct bregs *regs)
614 case 0x00: handle_100b00(regs); break;
615 case 0x01: handle_100b01(regs); break;
616 default: handle_100bXX(regs); break;
622 handle_100c(struct bregs *regs)
624 // XXX - page (regs->bh) is unused
625 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
629 handle_100d(struct bregs *regs)
631 // XXX - page (regs->bh) is unused
632 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
636 handle_100e(struct bregs *regs)
638 // Ralf Brown Interrupt list is WRONG on bh(page)
639 // We do output only on the current page !
640 struct carattr ca = {regs->al, regs->bl, 0};
641 struct cursorpos cp = get_cursor_pos(0xff);
642 write_teletype(&cp, ca);
647 handle_100f(struct bregs *regs)
649 regs->bh = GET_BDA(video_page);
650 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
651 regs->ah = GET_BDA(video_cols);
656 handle_101000(struct bregs *regs)
660 vgahw_set_single_palette_reg(regs->bl, regs->bh);
664 handle_101001(struct bregs *regs)
666 vgahw_set_overscan_border_color(regs->bh);
670 handle_101002(struct bregs *regs)
672 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
676 handle_101003(struct bregs *regs)
678 vgahw_toggle_intensity(regs->bl);
682 handle_101007(struct bregs *regs)
686 regs->bh = vgahw_get_single_palette_reg(regs->bl);
690 handle_101008(struct bregs *regs)
692 regs->bh = vgahw_get_overscan_border_color();
696 handle_101009(struct bregs *regs)
698 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
702 handle_101010(struct bregs *regs)
704 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
705 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
709 handle_101012(struct bregs *regs)
711 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
715 handle_101013(struct bregs *regs)
717 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
721 handle_101015(struct bregs *regs)
724 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
731 handle_101017(struct bregs *regs)
733 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
737 handle_101018(struct bregs *regs)
739 vgahw_set_pel_mask(regs->bl);
743 handle_101019(struct bregs *regs)
745 regs->bl = vgahw_get_pel_mask();
749 handle_10101a(struct bregs *regs)
751 vgahw_read_video_dac_state(®s->bl, ®s->bh);
755 handle_10101b(struct bregs *regs)
757 perform_gray_scale_summing(regs->bx, regs->cx);
761 handle_1010XX(struct bregs *regs)
767 handle_1010(struct bregs *regs)
770 case 0x00: handle_101000(regs); break;
771 case 0x01: handle_101001(regs); break;
772 case 0x02: handle_101002(regs); break;
773 case 0x03: handle_101003(regs); break;
774 case 0x07: handle_101007(regs); break;
775 case 0x08: handle_101008(regs); break;
776 case 0x09: handle_101009(regs); break;
777 case 0x10: handle_101010(regs); break;
778 case 0x12: handle_101012(regs); break;
779 case 0x13: handle_101013(regs); break;
780 case 0x15: handle_101015(regs); break;
781 case 0x17: handle_101017(regs); break;
782 case 0x18: handle_101018(regs); break;
783 case 0x19: handle_101019(regs); break;
784 case 0x1a: handle_10101a(regs); break;
785 case 0x1b: handle_10101b(regs); break;
786 default: handle_1010XX(regs); break;
792 handle_101100(struct bregs *regs)
794 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
795 , regs->dx, regs->bl, regs->bh);
799 handle_101101(struct bregs *regs)
801 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
805 handle_101102(struct bregs *regs)
807 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
811 handle_101103(struct bregs *regs)
813 vgahw_set_text_block_specifier(regs->bl);
817 handle_101104(struct bregs *regs)
819 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
823 handle_101110(struct bregs *regs)
825 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
826 , regs->dx, regs->bl, regs->bh);
827 set_scan_lines(regs->bh);
831 handle_101111(struct bregs *regs)
833 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
838 handle_101112(struct bregs *regs)
840 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
845 handle_101114(struct bregs *regs)
847 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
852 handle_101130(struct bregs *regs)
856 struct segoff_s so = GET_IVT(0x1f);
858 regs->bp = so.offset;
862 struct segoff_s so = GET_IVT(0x43);
864 regs->bp = so.offset;
868 regs->es = get_global_seg();
869 regs->bp = (u32)vgafont14;
872 regs->es = get_global_seg();
873 regs->bp = (u32)vgafont8;
876 regs->es = get_global_seg();
877 regs->bp = (u32)vgafont8 + 128 * 8;
880 regs->es = get_global_seg();
881 regs->bp = (u32)vgafont14alt;
884 regs->es = get_global_seg();
885 regs->bp = (u32)vgafont16;
888 regs->es = get_global_seg();
889 regs->bp = (u32)vgafont16alt;
892 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
895 // Set byte/char of on screen font
896 regs->cx = GET_BDA(char_height) & 0xff;
898 // Set Highest char row
899 regs->dx = GET_BDA(video_rows);
903 handle_1011XX(struct bregs *regs)
909 handle_1011(struct bregs *regs)
912 case 0x00: handle_101100(regs); break;
913 case 0x01: handle_101101(regs); break;
914 case 0x02: handle_101102(regs); break;
915 case 0x03: handle_101103(regs); break;
916 case 0x04: handle_101104(regs); break;
917 case 0x10: handle_101110(regs); break;
918 case 0x11: handle_101111(regs); break;
919 case 0x12: handle_101112(regs); break;
920 case 0x14: handle_101114(regs); break;
921 case 0x30: handle_101130(regs); break;
922 default: handle_1011XX(regs); break;
928 handle_101210(struct bregs *regs)
930 u16 crtc_addr = GET_BDA(crtc_address);
931 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
935 regs->cx = GET_BDA(video_switches) & 0x0f;
939 handle_101230(struct bregs *regs)
941 u8 mctl = GET_BDA(modeset_ctl);
942 u8 vswt = GET_BDA(video_switches);
946 mctl = (mctl & ~0x10) | 0x80;
947 vswt = (vswt & ~0x0f) | 0x08;
952 vswt = (vswt & ~0x0f) | 0x09;
956 mctl = (mctl & ~0x80) | 0x10;
957 vswt = (vswt & ~0x0f) | 0x09;
960 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
963 SET_BDA(modeset_ctl, mctl);
964 SET_BDA(video_switches, vswt);
969 handle_101231(struct bregs *regs)
971 u8 v = (regs->al & 0x01) << 3;
972 u8 mctl = GET_BDA(video_ctl) & ~0x08;
973 SET_BDA(video_ctl, mctl | v);
978 handle_101232(struct bregs *regs)
980 vgahw_enable_video_addressing(regs->al);
985 handle_101233(struct bregs *regs)
987 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
988 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
989 SET_BDA(modeset_ctl, v | v2);
994 handle_101234(struct bregs *regs)
996 u8 v = (regs->al & 0x01) ^ 0x01;
997 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
998 SET_BDA(modeset_ctl, v | v2);
1003 handle_101235(struct bregs *regs)
1010 handle_101236(struct bregs *regs)
1017 handle_1012XX(struct bregs *regs)
1023 handle_1012(struct bregs *regs)
1026 case 0x10: handle_101210(regs); break;
1027 case 0x30: handle_101230(regs); break;
1028 case 0x31: handle_101231(regs); break;
1029 case 0x32: handle_101232(regs); break;
1030 case 0x33: handle_101233(regs); break;
1031 case 0x34: handle_101234(regs); break;
1032 case 0x35: handle_101235(regs); break;
1033 case 0x36: handle_101236(regs); break;
1034 default: handle_1012XX(regs); break;
1037 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1042 static void noinline
1043 handle_1013(struct bregs *regs)
1045 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1046 // if row=0xff special case : use current cursor position
1048 cp = get_cursor_pos(cp.page);
1051 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1053 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1061 handle_101a00(struct bregs *regs)
1063 regs->bx = GET_BDA(dcc_index);
1068 handle_101a01(struct bregs *regs)
1070 SET_BDA(dcc_index, regs->bl);
1071 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1076 handle_101aXX(struct bregs *regs)
1082 handle_101a(struct bregs *regs)
1085 case 0x00: handle_101a00(regs); break;
1086 case 0x01: handle_101a01(regs); break;
1087 default: handle_101aXX(regs); break;
1093 struct segoff_s static_functionality;
1113 handle_101b(struct bregs *regs)
1116 struct funcInfo *info = (void*)(regs->di+0);
1117 memset_far(seg, info, 0, sizeof(*info));
1118 // Address of static functionality table
1119 SET_FARVAR(seg, info->static_functionality
1120 , SEGOFF(get_global_seg(), (u32)static_functionality));
1122 // Hard coded copy from BIOS area. Should it be cleaner ?
1123 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1124 , sizeof(info->bda_0x49));
1125 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1126 , sizeof(info->bda_0x84));
1128 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1129 SET_FARVAR(seg, info->colors, 16);
1130 SET_FARVAR(seg, info->pages, 8);
1131 SET_FARVAR(seg, info->scan_lines, 2);
1132 SET_FARVAR(seg, info->video_mem, 3);
1138 handle_101c00(struct bregs *regs)
1140 u16 flags = regs->cx;
1143 size += sizeof(struct saveVideoHardware);
1145 size += sizeof(struct saveBDAstate);
1147 size += sizeof(struct saveDACcolors);
1153 handle_101c01(struct bregs *regs)
1155 u16 flags = regs->cx;
1157 void *data = (void*)(regs->bx+0);
1159 vgahw_save_state(seg, data);
1160 data += sizeof(struct saveVideoHardware);
1163 save_bda_state(seg, data);
1164 data += sizeof(struct saveBDAstate);
1167 vgahw_save_dac_state(seg, data);
1172 handle_101c02(struct bregs *regs)
1174 u16 flags = regs->cx;
1176 void *data = (void*)(regs->bx+0);
1178 vgahw_restore_state(seg, data);
1179 data += sizeof(struct saveVideoHardware);
1182 restore_bda_state(seg, data);
1183 data += sizeof(struct saveBDAstate);
1186 vgahw_restore_dac_state(seg, data);
1191 handle_101cXX(struct bregs *regs)
1197 handle_101c(struct bregs *regs)
1200 case 0x00: handle_101c00(regs); break;
1201 case 0x01: handle_101c01(regs); break;
1202 case 0x02: handle_101c02(regs); break;
1203 default: handle_101cXX(regs); break;
1208 handle_10XX(struct bregs *regs)
1213 // INT 10h Video Support Service Entry Point
1215 handle_10(struct bregs *regs)
1217 debug_enter(regs, DEBUG_VGA_10);
1219 case 0x00: handle_1000(regs); break;
1220 case 0x01: handle_1001(regs); break;
1221 case 0x02: handle_1002(regs); break;
1222 case 0x03: handle_1003(regs); break;
1223 case 0x04: handle_1004(regs); break;
1224 case 0x05: handle_1005(regs); break;
1225 case 0x06: handle_1006(regs); break;
1226 case 0x07: handle_1007(regs); break;
1227 case 0x08: handle_1008(regs); break;
1228 case 0x09: handle_1009(regs); break;
1229 case 0x0a: handle_100a(regs); break;
1230 case 0x0b: handle_100b(regs); break;
1231 case 0x0c: handle_100c(regs); break;
1232 case 0x0d: handle_100d(regs); break;
1233 case 0x0e: handle_100e(regs); break;
1234 case 0x0f: handle_100f(regs); break;
1235 case 0x10: handle_1010(regs); break;
1236 case 0x11: handle_1011(regs); break;
1237 case 0x12: handle_1012(regs); break;
1238 case 0x13: handle_1013(regs); break;
1239 case 0x1a: handle_101a(regs); break;
1240 case 0x1b: handle_101b(regs); break;
1241 case 0x1c: handle_101c(regs); break;
1242 case 0x4f: handle_104f(regs); break;
1243 default: handle_10XX(regs); break;
1248 /****************************************************************
1250 ****************************************************************/
1253 init_bios_area(void)
1255 // init detected hardware BIOS Area
1256 // set 80x25 color (not clear from RBIL but usual)
1257 u16 eqf = GET_BDA(equipment_list_flags);
1258 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1260 // Just for the first int10 find its children
1262 // the default char height
1263 SET_BDA(char_height, 0x10);
1266 SET_BDA(video_ctl, 0x60);
1268 // Set the basic screen we have
1269 SET_BDA(video_switches, 0xf9);
1271 // Set the basic modeset options
1272 SET_BDA(modeset_ctl, 0x51);
1274 // Set the default MSR
1275 SET_BDA(video_msr, 0x09);
1279 vga_post(struct bregs *regs)
1281 debug_enter(regs, DEBUG_VGA_POST);
1285 if (CONFIG_VGA_GEODELX)
1290 bochsvga_init(regs->ah, regs->al);
1292 extern void entry_10(void);
1293 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1295 if (CONFIG_VGA_CIRRUS)
1298 // XXX - clear screen and display info
1300 build_video_param();
1303 extern u8 _rom_header_size, _rom_header_checksum;
1304 SET_VGA(_rom_header_checksum, 0);
1305 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1306 SET_VGA(_rom_header_checksum, sum);