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 "stdvga.h" // stdvga_screen_disable
21 #include "geodelx.h" // geodelx_init
22 #include "bochsvga.h" // bochsvga_init
25 #define DEBUG_VGA_POST 1
26 #define DEBUG_VGA_10 3
29 /****************************************************************
31 ****************************************************************/
32 #if CONFIG_VGA_PCI == 1
33 struct pci_data rom_pci_data VAR16VISIBLE = {
34 .signature = PCI_ROM_SIGNATURE,
35 .vendor = CONFIG_VGA_VID,
36 .device = CONFIG_VGA_DID,
40 .type = PCIROM_CODETYPE_X86,
45 /****************************************************************
47 ****************************************************************/
50 perform_gray_scale_summing(u16 start, u16 count)
52 stdvga_screen_disable();
54 for (i = start; i < start+count; i++) {
56 stdvga_get_dac_regs(GET_SEG(SS), rgb, i, 1);
58 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
59 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
63 stdvga_set_dac_regs(GET_SEG(SS), rgb, i, 1);
65 stdvga_screen_enable();
69 set_cursor_shape(u8 start, u8 end)
74 u16 curs = (start << 8) + end;
75 SET_BDA(cursor_type, curs);
77 u8 modeset_ctl = GET_BDA(modeset_ctl);
78 u16 cheight = GET_BDA(char_height);
79 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
80 if (end != (start + 1))
81 start = ((start + 1) * cheight / 8) - 1;
83 start = ((end + 1) * cheight / 8) - 2;
84 end = ((end + 1) * cheight / 8) - 1;
86 stdvga_set_cursor_shape(start, end);
90 get_cursor_shape(u8 page)
94 // FIXME should handle VGA 14/16 lines
95 return GET_BDA(cursor_type);
99 set_cursor_pos(struct cursorpos cp)
101 // Should not happen...
106 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
108 // Set the hardware cursor
109 u8 current = GET_BDA(video_page);
110 if (cp.page != current)
113 // Get the dimensions
114 u16 nbcols = GET_BDA(video_cols);
115 u16 nbrows = GET_BDA(video_rows) + 1;
117 // Calculate the address knowing nbcols nbrows and page num
118 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
119 + cp.x + cp.y * nbcols);
121 stdvga_set_cursor_pos(address);
124 static struct cursorpos
125 get_cursor_pos(u8 page)
128 // special case - use current page
129 page = GET_BDA(video_page);
131 struct cursorpos cp = { 0, 0, 0xfe };
134 // FIXME should handle VGA 14/16 lines
135 u16 xy = GET_BDA(cursor_pos[page]);
136 struct cursorpos cp = {xy, xy>>8, page};
141 set_active_page(u8 page)
147 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
151 // Get pos curs pos for the right page
152 struct cursorpos cp = get_cursor_pos(page);
155 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
156 // Get the dimensions
157 u16 nbcols = GET_BDA(video_cols);
158 u16 nbrows = GET_BDA(video_rows) + 1;
160 // Calculate the address knowing nbcols nbrows and page num
161 address = SCREEN_MEM_START(nbcols, nbrows, page);
162 SET_BDA(video_pagestart, address);
165 address = SCREEN_IO_START(nbcols, nbrows, page);
167 address = page * GET_GLOBAL(vmode_g->slength);
170 stdvga_set_active_page(address);
172 // And change the BIOS page
173 SET_BDA(video_page, page);
175 dprintf(1, "Set active page %02x address %04x\n", page, address);
177 // Display the cursor, now the page is active
182 set_scan_lines(u8 lines)
184 stdvga_set_scan_lines(lines);
186 set_cursor_shape(0x06, 0x07);
188 set_cursor_shape(lines - 4, lines - 3);
189 SET_BDA(char_height, lines);
190 u16 vde = stdvga_get_vde();
191 u8 rows = vde / lines;
192 SET_BDA(video_rows, rows - 1);
193 u16 cols = GET_BDA(video_cols);
194 SET_BDA(video_pagesize, rows * cols * 2);
198 /****************************************************************
200 ****************************************************************/
202 // Scroll the screen one line. This function is designed to be called
203 // tail-recursive to reduce stack usage.
205 scroll_one(u16 nbrows, u16 nbcols, u8 page)
207 struct cursorpos ul = {0, 0, page};
208 struct cursorpos lr = {nbcols-1, nbrows-1, page};
209 vgafb_scroll(1, -1, ul, lr);
212 // Write a character to the screen at a given position. Implement
213 // special characters and scroll the screen if necessary.
215 write_teletype(struct cursorpos *pcp, struct carattr ca)
217 struct cursorpos cp = *pcp;
219 // Get the dimensions
220 u16 nbrows = GET_BDA(video_rows) + 1;
221 u16 nbcols = GET_BDA(video_cols);
239 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
240 vgafb_write_char(cp, dummyca);
242 } while (cp.x < nbcols && cp.x % 8);
245 vgafb_write_char(cp, ca);
249 // Do we need to wrap ?
250 if (cp.x == nbcols) {
254 // Do we need to scroll ?
262 scroll_one(nbrows, nbcols, cp.page);
265 // Write out a buffer of alternating characters and attributes.
267 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
270 u8 car = GET_FARVAR(seg, *offset_far);
272 u8 attr = GET_FARVAR(seg, *offset_far);
275 struct carattr ca = {car, attr, 1};
276 write_teletype(pcp, ca);
280 // Write out a buffer of characters.
282 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
285 u8 car = GET_FARVAR(seg, *offset_far);
288 struct carattr ca = {car, attr, 1};
289 write_teletype(pcp, ca);
294 /****************************************************************
295 * Save and restore bda state
296 ****************************************************************/
299 save_bda_state(u16 seg, struct saveBDAstate *info)
301 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
302 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
303 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
304 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
305 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
306 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
307 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
308 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
309 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
310 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
313 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
314 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
315 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
317 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
318 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
322 restore_bda_state(u16 seg, struct saveBDAstate *info)
324 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
325 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
326 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
327 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
328 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
329 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
330 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
331 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
332 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
333 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
335 for (i = 0; i < 8; i++)
336 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
337 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
338 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
340 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
341 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
345 /****************************************************************
347 ****************************************************************/
351 vga_set_mode(u8 mode, u8 noclearmem)
353 // find the entry in the video modes
354 struct vgamode_s *vmode_g = find_vga_entry(mode);
355 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
359 // Read the bios mode set control
360 u8 modeset_ctl = GET_BDA(modeset_ctl);
362 // Then we know the number of lines
365 // if palette loading (bit 3 of modeset ctl = 0)
366 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
367 stdvga_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
369 // From which palette
370 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
371 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
373 // Always 256*3 values
374 stdvga_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
376 for (i = palsize; i < 0x0100; i++) {
377 static u8 rgb[3] VAR16;
378 stdvga_set_dac_regs(get_global_seg(), rgb, i, 1);
381 if ((modeset_ctl & 0x02) == 0x02)
382 perform_gray_scale_summing(0x00, 0x100);
385 stdvga_set_mode(vmode_g);
387 if (noclearmem == 0x00)
388 clear_screen(vmode_g);
390 // Set CRTC address VGA or MDA
391 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
392 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
393 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
396 u16 cheight = GET_GLOBAL(vmode_g->cheight);
397 SET_BDA(video_mode, mode);
398 SET_BDA(video_cols, GET_GLOBAL(vmode_g->twidth));
399 SET_BDA(video_pagesize, GET_GLOBAL(vmode_g->slength));
400 SET_BDA(crtc_address, crtc_addr);
401 SET_BDA(video_rows, GET_GLOBAL(vmode_g->theight)-1);
402 SET_BDA(char_height, cheight);
403 SET_BDA(video_ctl, (0x60 | noclearmem));
404 SET_BDA(video_switches, 0xF9);
405 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
407 // FIXME We nearly have the good tables. to be reworked
408 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
409 SET_BDA(video_savetable
410 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
413 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
414 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
417 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
418 set_cursor_shape(0x06, 0x07);
419 // Set cursor pos for page 0..7
421 for (i = 0; i < 8; i++) {
422 struct cursorpos cp = {0, 0, i};
427 set_active_page(0x00);
429 // Write the fonts in memory
430 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
431 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, 0, 16);
432 stdvga_set_text_block_specifier(0);
434 // Set the ints 0x1F and 0x43
435 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
439 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
442 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
445 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
451 handle_1000(struct bregs *regs)
453 u8 noclearmem = regs->al & 0x80;
454 u8 mode = regs->al & 0x7f;
464 if (CONFIG_VGA_CIRRUS) {
465 int ret = cirrus_set_video_mode(mode, noclearmem);
470 if (bochsvga_enabled())
471 bochsvga_hires_enable(0);
473 vga_set_mode(mode, noclearmem);
477 handle_1001(struct bregs *regs)
479 set_cursor_shape(regs->ch, regs->cl);
483 handle_1002(struct bregs *regs)
485 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
490 handle_1003(struct bregs *regs)
492 regs->cx = get_cursor_shape(regs->bh);
493 struct cursorpos cp = get_cursor_pos(regs->bh);
498 // Read light pen pos (unimplemented)
500 handle_1004(struct bregs *regs)
503 regs->ax = regs->bx = regs->cx = regs->dx = 0;
507 handle_1005(struct bregs *regs)
509 set_active_page(regs->al);
513 verify_scroll(struct bregs *regs, int dir)
515 u8 page = GET_BDA(video_page);
516 struct cursorpos ul = {regs->cl, regs->ch, page};
517 struct cursorpos lr = {regs->dl, regs->dh, page};
519 u16 nbrows = GET_BDA(video_rows) + 1;
522 u16 nbcols = GET_BDA(video_cols);
526 if (ul.x > lr.x || ul.y > lr.y)
529 u16 nblines = regs->al;
530 if (!nblines || nblines > lr.y - ul.y + 1)
531 nblines = lr.y - ul.y + 1;
533 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
537 handle_1006(struct bregs *regs)
539 verify_scroll(regs, 1);
543 handle_1007(struct bregs *regs)
545 verify_scroll(regs, -1);
549 handle_1008(struct bregs *regs)
551 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
557 write_chars(u8 page, struct carattr ca, u16 count)
559 struct cursorpos cp = get_cursor_pos(page);
561 vgafb_write_char(cp, ca);
567 handle_1009(struct bregs *regs)
569 struct carattr ca = {regs->al, regs->bl, 1};
570 write_chars(regs->bh, ca, regs->cx);
574 handle_100a(struct bregs *regs)
576 struct carattr ca = {regs->al, regs->bl, 0};
577 write_chars(regs->bh, ca, regs->cx);
582 handle_100b00(struct bregs *regs)
584 stdvga_set_border_color(regs->bl);
588 handle_100b01(struct bregs *regs)
590 stdvga_set_palette(regs->bl);
594 handle_100bXX(struct bregs *regs)
600 handle_100b(struct bregs *regs)
603 case 0x00: handle_100b00(regs); break;
604 case 0x01: handle_100b01(regs); break;
605 default: handle_100bXX(regs); break;
611 handle_100c(struct bregs *regs)
613 // XXX - page (regs->bh) is unused
614 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
618 handle_100d(struct bregs *regs)
620 // XXX - page (regs->bh) is unused
621 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
625 handle_100e(struct bregs *regs)
627 // Ralf Brown Interrupt list is WRONG on bh(page)
628 // We do output only on the current page !
629 struct carattr ca = {regs->al, regs->bl, 0};
630 struct cursorpos cp = get_cursor_pos(0xff);
631 write_teletype(&cp, ca);
636 handle_100f(struct bregs *regs)
638 regs->bh = GET_BDA(video_page);
639 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
640 regs->ah = GET_BDA(video_cols);
645 handle_101000(struct bregs *regs)
649 stdvga_set_single_palette_reg(regs->bl, regs->bh);
653 handle_101001(struct bregs *regs)
655 stdvga_set_overscan_border_color(regs->bh);
659 handle_101002(struct bregs *regs)
661 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
665 handle_101003(struct bregs *regs)
667 stdvga_toggle_intensity(regs->bl);
671 handle_101007(struct bregs *regs)
675 regs->bh = stdvga_get_single_palette_reg(regs->bl);
679 handle_101008(struct bregs *regs)
681 regs->bh = stdvga_get_overscan_border_color();
685 handle_101009(struct bregs *regs)
687 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
691 handle_101010(struct bregs *regs)
693 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
694 stdvga_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
698 handle_101012(struct bregs *regs)
700 stdvga_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
704 handle_101013(struct bregs *regs)
706 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
710 handle_101015(struct bregs *regs)
713 stdvga_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
720 handle_101017(struct bregs *regs)
722 stdvga_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
726 handle_101018(struct bregs *regs)
728 stdvga_set_pel_mask(regs->bl);
732 handle_101019(struct bregs *regs)
734 regs->bl = stdvga_get_pel_mask();
738 handle_10101a(struct bregs *regs)
740 stdvga_read_video_dac_state(®s->bl, ®s->bh);
744 handle_10101b(struct bregs *regs)
746 perform_gray_scale_summing(regs->bx, regs->cx);
750 handle_1010XX(struct bregs *regs)
756 handle_1010(struct bregs *regs)
759 case 0x00: handle_101000(regs); break;
760 case 0x01: handle_101001(regs); break;
761 case 0x02: handle_101002(regs); break;
762 case 0x03: handle_101003(regs); break;
763 case 0x07: handle_101007(regs); break;
764 case 0x08: handle_101008(regs); break;
765 case 0x09: handle_101009(regs); break;
766 case 0x10: handle_101010(regs); break;
767 case 0x12: handle_101012(regs); break;
768 case 0x13: handle_101013(regs); break;
769 case 0x15: handle_101015(regs); break;
770 case 0x17: handle_101017(regs); break;
771 case 0x18: handle_101018(regs); break;
772 case 0x19: handle_101019(regs); break;
773 case 0x1a: handle_10101a(regs); break;
774 case 0x1b: handle_10101b(regs); break;
775 default: handle_1010XX(regs); break;
781 handle_101100(struct bregs *regs)
783 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
784 , regs->dx, regs->bl, regs->bh);
788 handle_101101(struct bregs *regs)
790 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
794 handle_101102(struct bregs *regs)
796 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
800 handle_101103(struct bregs *regs)
802 stdvga_set_text_block_specifier(regs->bl);
806 handle_101104(struct bregs *regs)
808 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
812 handle_101110(struct bregs *regs)
814 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
815 , regs->dx, regs->bl, regs->bh);
816 set_scan_lines(regs->bh);
820 handle_101111(struct bregs *regs)
822 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
827 handle_101112(struct bregs *regs)
829 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
834 handle_101114(struct bregs *regs)
836 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
841 handle_101130(struct bregs *regs)
845 struct segoff_s so = GET_IVT(0x1f);
847 regs->bp = so.offset;
851 struct segoff_s so = GET_IVT(0x43);
853 regs->bp = so.offset;
857 regs->es = get_global_seg();
858 regs->bp = (u32)vgafont14;
861 regs->es = get_global_seg();
862 regs->bp = (u32)vgafont8;
865 regs->es = get_global_seg();
866 regs->bp = (u32)vgafont8 + 128 * 8;
869 regs->es = get_global_seg();
870 regs->bp = (u32)vgafont14alt;
873 regs->es = get_global_seg();
874 regs->bp = (u32)vgafont16;
877 regs->es = get_global_seg();
878 regs->bp = (u32)vgafont16alt;
881 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
884 // Set byte/char of on screen font
885 regs->cx = GET_BDA(char_height) & 0xff;
887 // Set Highest char row
888 regs->dx = GET_BDA(video_rows);
892 handle_1011XX(struct bregs *regs)
898 handle_1011(struct bregs *regs)
901 case 0x00: handle_101100(regs); break;
902 case 0x01: handle_101101(regs); break;
903 case 0x02: handle_101102(regs); break;
904 case 0x03: handle_101103(regs); break;
905 case 0x04: handle_101104(regs); break;
906 case 0x10: handle_101110(regs); break;
907 case 0x11: handle_101111(regs); break;
908 case 0x12: handle_101112(regs); break;
909 case 0x14: handle_101114(regs); break;
910 case 0x30: handle_101130(regs); break;
911 default: handle_1011XX(regs); break;
917 handle_101210(struct bregs *regs)
919 u16 crtc_addr = GET_BDA(crtc_address);
920 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
924 regs->cx = GET_BDA(video_switches) & 0x0f;
928 handle_101230(struct bregs *regs)
930 u8 mctl = GET_BDA(modeset_ctl);
931 u8 vswt = GET_BDA(video_switches);
935 mctl = (mctl & ~0x10) | 0x80;
936 vswt = (vswt & ~0x0f) | 0x08;
941 vswt = (vswt & ~0x0f) | 0x09;
945 mctl = (mctl & ~0x80) | 0x10;
946 vswt = (vswt & ~0x0f) | 0x09;
949 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
952 SET_BDA(modeset_ctl, mctl);
953 SET_BDA(video_switches, vswt);
958 handle_101231(struct bregs *regs)
960 u8 v = (regs->al & 0x01) << 3;
961 u8 mctl = GET_BDA(video_ctl) & ~0x08;
962 SET_BDA(video_ctl, mctl | v);
967 handle_101232(struct bregs *regs)
969 stdvga_enable_video_addressing(regs->al);
974 handle_101233(struct bregs *regs)
976 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
977 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
978 SET_BDA(modeset_ctl, v | v2);
983 handle_101234(struct bregs *regs)
985 u8 v = (regs->al & 0x01) ^ 0x01;
986 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
987 SET_BDA(modeset_ctl, v | v2);
992 handle_101235(struct bregs *regs)
999 handle_101236(struct bregs *regs)
1006 handle_1012XX(struct bregs *regs)
1012 handle_1012(struct bregs *regs)
1015 case 0x10: handle_101210(regs); break;
1016 case 0x30: handle_101230(regs); break;
1017 case 0x31: handle_101231(regs); break;
1018 case 0x32: handle_101232(regs); break;
1019 case 0x33: handle_101233(regs); break;
1020 case 0x34: handle_101234(regs); break;
1021 case 0x35: handle_101235(regs); break;
1022 case 0x36: handle_101236(regs); break;
1023 default: handle_1012XX(regs); break;
1026 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1031 static void noinline
1032 handle_1013(struct bregs *regs)
1034 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1035 // if row=0xff special case : use current cursor position
1037 cp = get_cursor_pos(cp.page);
1040 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1042 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1050 handle_101a00(struct bregs *regs)
1052 regs->bx = GET_BDA(dcc_index);
1057 handle_101a01(struct bregs *regs)
1059 SET_BDA(dcc_index, regs->bl);
1060 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1065 handle_101aXX(struct bregs *regs)
1071 handle_101a(struct bregs *regs)
1074 case 0x00: handle_101a00(regs); break;
1075 case 0x01: handle_101a01(regs); break;
1076 default: handle_101aXX(regs); break;
1082 struct segoff_s static_functionality;
1102 handle_101b(struct bregs *regs)
1105 struct funcInfo *info = (void*)(regs->di+0);
1106 memset_far(seg, info, 0, sizeof(*info));
1107 // Address of static functionality table
1108 SET_FARVAR(seg, info->static_functionality
1109 , SEGOFF(get_global_seg(), (u32)static_functionality));
1111 // Hard coded copy from BIOS area. Should it be cleaner ?
1112 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1113 , sizeof(info->bda_0x49));
1114 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1115 , sizeof(info->bda_0x84));
1117 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1118 SET_FARVAR(seg, info->colors, 16);
1119 SET_FARVAR(seg, info->pages, 8);
1120 SET_FARVAR(seg, info->scan_lines, 2);
1121 SET_FARVAR(seg, info->video_mem, 3);
1127 handle_101c00(struct bregs *regs)
1129 u16 flags = regs->cx;
1132 size += sizeof(struct saveVideoHardware);
1134 size += sizeof(struct saveBDAstate);
1136 size += sizeof(struct saveDACcolors);
1142 handle_101c01(struct bregs *regs)
1144 u16 flags = regs->cx;
1146 void *data = (void*)(regs->bx+0);
1148 stdvga_save_state(seg, data);
1149 data += sizeof(struct saveVideoHardware);
1152 save_bda_state(seg, data);
1153 data += sizeof(struct saveBDAstate);
1156 stdvga_save_dac_state(seg, data);
1161 handle_101c02(struct bregs *regs)
1163 u16 flags = regs->cx;
1165 void *data = (void*)(regs->bx+0);
1167 stdvga_restore_state(seg, data);
1168 data += sizeof(struct saveVideoHardware);
1171 restore_bda_state(seg, data);
1172 data += sizeof(struct saveBDAstate);
1175 stdvga_restore_dac_state(seg, data);
1180 handle_101cXX(struct bregs *regs)
1186 handle_101c(struct bregs *regs)
1189 case 0x00: handle_101c00(regs); break;
1190 case 0x01: handle_101c01(regs); break;
1191 case 0x02: handle_101c02(regs); break;
1192 default: handle_101cXX(regs); break;
1197 handle_10XX(struct bregs *regs)
1202 // INT 10h Video Support Service Entry Point
1204 handle_10(struct bregs *regs)
1206 debug_enter(regs, DEBUG_VGA_10);
1208 case 0x00: handle_1000(regs); break;
1209 case 0x01: handle_1001(regs); break;
1210 case 0x02: handle_1002(regs); break;
1211 case 0x03: handle_1003(regs); break;
1212 case 0x04: handle_1004(regs); break;
1213 case 0x05: handle_1005(regs); break;
1214 case 0x06: handle_1006(regs); break;
1215 case 0x07: handle_1007(regs); break;
1216 case 0x08: handle_1008(regs); break;
1217 case 0x09: handle_1009(regs); break;
1218 case 0x0a: handle_100a(regs); break;
1219 case 0x0b: handle_100b(regs); break;
1220 case 0x0c: handle_100c(regs); break;
1221 case 0x0d: handle_100d(regs); break;
1222 case 0x0e: handle_100e(regs); break;
1223 case 0x0f: handle_100f(regs); break;
1224 case 0x10: handle_1010(regs); break;
1225 case 0x11: handle_1011(regs); break;
1226 case 0x12: handle_1012(regs); break;
1227 case 0x13: handle_1013(regs); break;
1228 case 0x1a: handle_101a(regs); break;
1229 case 0x1b: handle_101b(regs); break;
1230 case 0x1c: handle_101c(regs); break;
1231 case 0x4f: handle_104f(regs); break;
1232 default: handle_10XX(regs); break;
1237 /****************************************************************
1239 ****************************************************************/
1242 init_bios_area(void)
1244 // init detected hardware BIOS Area
1245 // set 80x25 color (not clear from RBIL but usual)
1246 u16 eqf = GET_BDA(equipment_list_flags);
1247 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1249 // Just for the first int10 find its children
1251 // the default char height
1252 SET_BDA(char_height, 0x10);
1255 SET_BDA(video_ctl, 0x60);
1257 // Set the basic screen we have
1258 SET_BDA(video_switches, 0xf9);
1260 // Set the basic modeset options
1261 SET_BDA(modeset_ctl, 0x51);
1263 // Set the default MSR
1264 SET_BDA(video_msr, 0x09);
1268 vga_post(struct bregs *regs)
1270 debug_enter(regs, DEBUG_VGA_POST);
1274 if (CONFIG_VGA_GEODELX)
1279 bochsvga_init(regs->ah, regs->al);
1281 extern void entry_10(void);
1282 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1284 if (CONFIG_VGA_CIRRUS)
1287 // XXX - clear screen and display info
1289 build_video_param();
1292 extern u8 _rom_header_size, _rom_header_checksum;
1293 SET_VGA(_rom_header_checksum, 0);
1294 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1295 SET_VGA(_rom_header_checksum, sum);