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 "vgatables.h" // find_vga_entry
18 #include "optionroms.h" // struct pci_data
19 #include "config.h" // CONFIG_*
22 #define CONFIG_VGA_BOCHS 0
23 #define CONFIG_VGA_CIRRUS 0
26 #define DEBUG_VGA_POST 1
27 #define DEBUG_VGA_10 3
29 #define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
31 /****************************************************************
33 ****************************************************************/
34 #if CONFIG_VGA_PCI == 1
35 struct pci_data rom_pci_data VAR16VISIBLE = {
36 .signature = PCI_ROM_SIGNATURE,
37 .vendor = CONFIG_VGA_VID,
38 .device = CONFIG_VGA_DID,
42 .type = PCIROM_CODETYPE_X86,
47 /****************************************************************
49 ****************************************************************/
52 call16_vgaint(u32 eax, u32 ebx)
64 perform_gray_scale_summing(u16 start, u16 count)
66 vgahw_screen_disable();
68 for (i = start; i < start+count; i++) {
70 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
72 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
73 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
77 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
79 vgahw_screen_enable();
83 set_cursor_shape(u8 start, u8 end)
88 u16 curs = (start << 8) + end;
89 SET_BDA(cursor_type, curs);
91 u8 modeset_ctl = GET_BDA(modeset_ctl);
92 u16 cheight = GET_BDA(char_height);
93 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
94 if (end != (start + 1))
95 start = ((start + 1) * cheight / 8) - 1;
97 start = ((end + 1) * cheight / 8) - 2;
98 end = ((end + 1) * cheight / 8) - 1;
100 vgahw_set_cursor_shape(start, end);
104 get_cursor_shape(u8 page)
108 // FIXME should handle VGA 14/16 lines
109 return GET_BDA(cursor_type);
113 set_cursor_pos(struct cursorpos cp)
115 // Should not happen...
120 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
122 // Set the hardware cursor
123 u8 current = GET_BDA(video_page);
124 if (cp.page != current)
127 // Get the dimensions
128 u16 nbcols = GET_BDA(video_cols);
129 u16 nbrows = GET_BDA(video_rows) + 1;
131 // Calculate the address knowing nbcols nbrows and page num
132 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
133 + cp.x + cp.y * nbcols);
135 vgahw_set_cursor_pos(address);
138 static struct cursorpos
139 get_cursor_pos(u8 page)
142 // special case - use current page
143 page = GET_BDA(video_page);
145 struct cursorpos cp = { 0, 0, 0xfe };
148 // FIXME should handle VGA 14/16 lines
149 u16 xy = GET_BDA(cursor_pos[page]);
150 struct cursorpos cp = {xy, xy>>8, page};
155 set_active_page(u8 page)
161 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
165 // Get pos curs pos for the right page
166 struct cursorpos cp = get_cursor_pos(page);
169 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
170 // Get the dimensions
171 u16 nbcols = GET_BDA(video_cols);
172 u16 nbrows = GET_BDA(video_rows) + 1;
174 // Calculate the address knowing nbcols nbrows and page num
175 address = SCREEN_MEM_START(nbcols, nbrows, page);
176 SET_BDA(video_pagestart, address);
179 address = SCREEN_IO_START(nbcols, nbrows, page);
181 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
182 address = page * GET_GLOBAL(vparam_g->slength);
185 vgahw_set_active_page(address);
187 // And change the BIOS page
188 SET_BDA(video_page, page);
190 dprintf(1, "Set active page %02x address %04x\n", page, address);
192 // Display the cursor, now the page is active
197 set_scan_lines(u8 lines)
199 vgahw_set_scan_lines(lines);
201 set_cursor_shape(0x06, 0x07);
203 set_cursor_shape(lines - 4, lines - 3);
204 SET_BDA(char_height, lines);
205 u16 vde = vgahw_get_vde();
206 u8 rows = vde / lines;
207 SET_BDA(video_rows, rows - 1);
208 u16 cols = GET_BDA(video_cols);
209 SET_BDA(video_pagesize, rows * cols * 2);
213 /****************************************************************
215 ****************************************************************/
217 // Scroll the screen one line. This function is designed to be called
218 // tail-recursive to reduce stack usage.
220 scroll_one(u16 nbrows, u16 nbcols, u8 page)
222 struct cursorpos ul = {0, 0, page};
223 struct cursorpos lr = {nbcols-1, nbrows-1, page};
224 vgafb_scroll(1, -1, ul, lr);
227 // Write a character to the screen at a given position. Implement
228 // special characters and scroll the screen if necessary.
230 write_teletype(struct cursorpos *pcp, struct carattr ca)
232 struct cursorpos cp = *pcp;
234 // Get the dimensions
235 u16 nbrows = GET_BDA(video_rows) + 1;
236 u16 nbcols = GET_BDA(video_cols);
254 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
255 vgafb_write_char(cp, dummyca);
257 } while (cp.x < nbcols && cp.x % 8);
260 vgafb_write_char(cp, ca);
264 // Do we need to wrap ?
265 if (cp.x == nbcols) {
269 // Do we need to scroll ?
277 scroll_one(nbrows, nbcols, cp.page);
280 // Write out a buffer of alternating characters and attributes.
282 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
285 u8 car = GET_FARVAR(seg, *offset_far);
287 u8 attr = GET_FARVAR(seg, *offset_far);
290 struct carattr ca = {car, attr, 1};
291 write_teletype(pcp, ca);
295 // Write out a buffer of characters.
297 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
300 u8 car = GET_FARVAR(seg, *offset_far);
303 struct carattr ca = {car, attr, 1};
304 write_teletype(pcp, ca);
309 /****************************************************************
310 * Save and restore bda state
311 ****************************************************************/
314 save_bda_state(u16 seg, struct saveBDAstate *info)
316 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
317 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
318 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
319 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
320 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
321 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
322 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
323 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
324 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
325 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
328 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
329 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
330 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
332 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
333 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
337 restore_bda_state(u16 seg, struct saveBDAstate *info)
339 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
340 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
341 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
342 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
343 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
344 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
345 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
346 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
347 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
348 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
350 for (i = 0; i < 8; i++)
351 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
352 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
353 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
355 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
356 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
360 /****************************************************************
362 ****************************************************************/
366 handle_1000(struct bregs *regs)
368 u8 noclearmem = regs->al & 0x80;
369 u8 mode = regs->al & 0x7f;
379 if (CONFIG_VGA_CIRRUS)
380 cirrus_set_video_mode(mode);
382 if (CONFIG_VGA_BOCHS)
383 if (bochs_has_vbe_display())
384 dispi_set_enable(VBE_DISPI_DISABLED);
386 // find the entry in the video modes
387 struct vgamode_s *vmode_g = find_vga_entry(mode);
388 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
392 // Read the bios mode set control
393 u8 modeset_ctl = GET_BDA(modeset_ctl);
395 // Then we know the number of lines
398 // if palette loading (bit 3 of modeset ctl = 0)
399 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
400 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
402 // From which palette
403 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
404 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
406 // Always 256*3 values
407 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
409 for (i = palsize; i < 0x0100; i++) {
410 static u8 rgb[3] VAR16;
411 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
414 if ((modeset_ctl & 0x02) == 0x02)
415 perform_gray_scale_summing(0x00, 0x100);
418 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
419 vgahw_set_mode(vparam_g);
421 if (noclearmem == 0x00)
422 clear_screen(vmode_g);
424 // Set CRTC address VGA or MDA
425 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
426 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
427 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
430 u16 cheight = GET_GLOBAL(vparam_g->cheight);
431 SET_BDA(video_mode, mode);
432 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
433 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
434 SET_BDA(crtc_address, crtc_addr);
435 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
436 SET_BDA(char_height, cheight);
437 SET_BDA(video_ctl, (0x60 | noclearmem));
438 SET_BDA(video_switches, 0xF9);
439 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
441 // FIXME We nearly have the good tables. to be reworked
442 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
443 SET_BDA(video_savetable
444 , SEGOFF(get_global_seg(), (u32)video_save_pointer_table));
447 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
448 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
451 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
452 set_cursor_shape(0x06, 0x07);
453 // Set cursor pos for page 0..7
455 for (i = 0; i < 8; i++) {
456 struct cursorpos cp = {0, 0, i};
461 set_active_page(0x00);
463 // Write the fonts in memory
464 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
465 call16_vgaint(0x1104, 0);
466 call16_vgaint(0x1103, 0);
468 // Set the ints 0x1F and 0x43
469 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
473 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
476 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
479 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
485 handle_1001(struct bregs *regs)
487 set_cursor_shape(regs->ch, regs->cl);
491 handle_1002(struct bregs *regs)
493 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
498 handle_1003(struct bregs *regs)
500 regs->cx = get_cursor_shape(regs->bh);
501 struct cursorpos cp = get_cursor_pos(regs->bh);
506 // Read light pen pos (unimplemented)
508 handle_1004(struct bregs *regs)
511 regs->ax = regs->bx = regs->cx = regs->dx = 0;
515 handle_1005(struct bregs *regs)
517 set_active_page(regs->al);
521 verify_scroll(struct bregs *regs, int dir)
523 u8 page = GET_BDA(video_page);
524 struct cursorpos ul = {regs->cl, regs->ch, page};
525 struct cursorpos lr = {regs->dl, regs->dh, page};
527 u16 nbrows = GET_BDA(video_rows) + 1;
530 u16 nbcols = GET_BDA(video_cols);
534 if (ul.x > lr.x || ul.y > lr.y)
537 u16 nblines = regs->al;
538 if (!nblines || nblines > lr.y - ul.y + 1)
539 nblines = lr.y - ul.y + 1;
541 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
545 handle_1006(struct bregs *regs)
547 verify_scroll(regs, 1);
551 handle_1007(struct bregs *regs)
553 verify_scroll(regs, -1);
557 handle_1008(struct bregs *regs)
559 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
565 write_chars(u8 page, struct carattr ca, u16 count)
567 struct cursorpos cp = get_cursor_pos(page);
569 vgafb_write_char(cp, ca);
575 handle_1009(struct bregs *regs)
577 struct carattr ca = {regs->al, regs->bl, 1};
578 write_chars(regs->bh, ca, regs->cx);
582 handle_100a(struct bregs *regs)
584 struct carattr ca = {regs->al, regs->bl, 0};
585 write_chars(regs->bh, ca, regs->cx);
590 handle_100b00(struct bregs *regs)
592 vgahw_set_border_color(regs->bl);
596 handle_100b01(struct bregs *regs)
598 vgahw_set_palette(regs->bl);
602 handle_100bXX(struct bregs *regs)
608 handle_100b(struct bregs *regs)
611 case 0x00: handle_100b00(regs); break;
612 case 0x01: handle_100b01(regs); break;
613 default: handle_100bXX(regs); break;
619 handle_100c(struct bregs *regs)
621 // XXX - page (regs->bh) is unused
622 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
626 handle_100d(struct bregs *regs)
628 // XXX - page (regs->bh) is unused
629 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
633 handle_100e(struct bregs *regs)
635 // Ralf Brown Interrupt list is WRONG on bh(page)
636 // We do output only on the current page !
637 struct carattr ca = {regs->al, regs->bl, 0};
638 struct cursorpos cp = get_cursor_pos(0xff);
639 write_teletype(&cp, ca);
644 handle_100f(struct bregs *regs)
646 regs->bh = GET_BDA(video_page);
647 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
648 regs->ah = GET_BDA(video_cols);
653 handle_101000(struct bregs *regs)
657 vgahw_set_single_palette_reg(regs->bl, regs->bh);
661 handle_101001(struct bregs *regs)
663 vgahw_set_overscan_border_color(regs->bh);
667 handle_101002(struct bregs *regs)
669 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
673 handle_101003(struct bregs *regs)
675 vgahw_toggle_intensity(regs->bl);
679 handle_101007(struct bregs *regs)
683 regs->bh = vgahw_get_single_palette_reg(regs->bl);
687 handle_101008(struct bregs *regs)
689 regs->bh = vgahw_get_overscan_border_color();
693 handle_101009(struct bregs *regs)
695 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
699 handle_101010(struct bregs *regs)
701 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
702 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
706 handle_101012(struct bregs *regs)
708 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
712 handle_101013(struct bregs *regs)
714 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
718 handle_101015(struct bregs *regs)
721 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
728 handle_101017(struct bregs *regs)
730 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
734 handle_101018(struct bregs *regs)
736 vgahw_set_pel_mask(regs->bl);
740 handle_101019(struct bregs *regs)
742 regs->bl = vgahw_get_pel_mask();
746 handle_10101a(struct bregs *regs)
748 vgahw_read_video_dac_state(®s->bl, ®s->bh);
752 handle_10101b(struct bregs *regs)
754 perform_gray_scale_summing(regs->bx, regs->cx);
758 handle_1010XX(struct bregs *regs)
764 handle_1010(struct bregs *regs)
767 case 0x00: handle_101000(regs); break;
768 case 0x01: handle_101001(regs); break;
769 case 0x02: handle_101002(regs); break;
770 case 0x03: handle_101003(regs); break;
771 case 0x07: handle_101007(regs); break;
772 case 0x08: handle_101008(regs); break;
773 case 0x09: handle_101009(regs); break;
774 case 0x10: handle_101010(regs); break;
775 case 0x12: handle_101012(regs); break;
776 case 0x13: handle_101013(regs); break;
777 case 0x15: handle_101015(regs); break;
778 case 0x17: handle_101017(regs); break;
779 case 0x18: handle_101018(regs); break;
780 case 0x19: handle_101019(regs); break;
781 case 0x1a: handle_10101a(regs); break;
782 case 0x1b: handle_10101b(regs); break;
783 default: handle_1010XX(regs); break;
789 handle_101100(struct bregs *regs)
791 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
792 , regs->dx, regs->bl, regs->bh);
796 handle_101101(struct bregs *regs)
798 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
802 handle_101102(struct bregs *regs)
804 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
808 handle_101103(struct bregs *regs)
810 vgahw_set_text_block_specifier(regs->bl);
814 handle_101104(struct bregs *regs)
816 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
820 handle_101110(struct bregs *regs)
822 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
823 , regs->dx, regs->bl, regs->bh);
824 set_scan_lines(regs->bh);
828 handle_101111(struct bregs *regs)
830 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
835 handle_101112(struct bregs *regs)
837 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
842 handle_101114(struct bregs *regs)
844 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
849 handle_101130(struct bregs *regs)
853 struct segoff_s so = GET_IVT(0x1f);
855 regs->bp = so.offset;
859 struct segoff_s so = GET_IVT(0x43);
861 regs->bp = so.offset;
865 regs->es = get_global_seg();
866 regs->bp = (u32)vgafont14;
869 regs->es = get_global_seg();
870 regs->bp = (u32)vgafont8;
873 regs->es = get_global_seg();
874 regs->bp = (u32)vgafont8 + 128 * 8;
877 regs->es = get_global_seg();
878 regs->bp = (u32)vgafont14alt;
881 regs->es = get_global_seg();
882 regs->bp = (u32)vgafont16;
885 regs->es = get_global_seg();
886 regs->bp = (u32)vgafont16alt;
889 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
892 // Set byte/char of on screen font
893 regs->cx = GET_BDA(char_height) & 0xff;
895 // Set Highest char row
896 regs->dx = GET_BDA(video_rows);
900 handle_1011XX(struct bregs *regs)
906 handle_1011(struct bregs *regs)
909 case 0x00: handle_101100(regs); break;
910 case 0x01: handle_101101(regs); break;
911 case 0x02: handle_101102(regs); break;
912 case 0x03: handle_101103(regs); break;
913 case 0x04: handle_101104(regs); break;
914 case 0x10: handle_101110(regs); break;
915 case 0x11: handle_101111(regs); break;
916 case 0x12: handle_101112(regs); break;
917 case 0x14: handle_101114(regs); break;
918 case 0x30: handle_101130(regs); break;
919 default: handle_1011XX(regs); break;
925 handle_101210(struct bregs *regs)
927 u16 crtc_addr = GET_BDA(crtc_address);
928 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
932 regs->cx = GET_BDA(video_switches) & 0x0f;
936 handle_101230(struct bregs *regs)
938 u8 mctl = GET_BDA(modeset_ctl);
939 u8 vswt = GET_BDA(video_switches);
943 mctl = (mctl & ~0x10) | 0x80;
944 vswt = (vswt & ~0x0f) | 0x08;
949 vswt = (vswt & ~0x0f) | 0x09;
953 mctl = (mctl & ~0x80) | 0x10;
954 vswt = (vswt & ~0x0f) | 0x09;
957 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
960 SET_BDA(modeset_ctl, mctl);
961 SET_BDA(video_switches, vswt);
966 handle_101231(struct bregs *regs)
968 u8 v = (regs->al & 0x01) << 3;
969 u8 mctl = GET_BDA(video_ctl) & ~0x08;
970 SET_BDA(video_ctl, mctl | v);
975 handle_101232(struct bregs *regs)
977 vgahw_enable_video_addressing(regs->al);
982 handle_101233(struct bregs *regs)
984 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
985 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
986 SET_BDA(modeset_ctl, v | v2);
991 handle_101234(struct bregs *regs)
993 u8 v = (regs->al & 0x01) ^ 0x01;
994 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
995 SET_BDA(modeset_ctl, v | v2);
1000 handle_101235(struct bregs *regs)
1007 handle_101236(struct bregs *regs)
1014 handle_1012XX(struct bregs *regs)
1020 handle_1012(struct bregs *regs)
1023 case 0x10: handle_101210(regs); break;
1024 case 0x30: handle_101230(regs); break;
1025 case 0x31: handle_101231(regs); break;
1026 case 0x32: handle_101232(regs); break;
1027 case 0x33: handle_101233(regs); break;
1028 case 0x34: handle_101234(regs); break;
1029 case 0x35: handle_101235(regs); break;
1030 case 0x36: handle_101236(regs); break;
1031 default: handle_1012XX(regs); break;
1034 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1039 static void noinline
1040 handle_1013(struct bregs *regs)
1042 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1043 // if row=0xff special case : use current cursor position
1045 cp = get_cursor_pos(cp.page);
1048 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1050 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1058 handle_101a00(struct bregs *regs)
1060 regs->bx = GET_BDA(dcc_index);
1065 handle_101a01(struct bregs *regs)
1067 SET_BDA(dcc_index, regs->bl);
1068 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1073 handle_101aXX(struct bregs *regs)
1079 handle_101a(struct bregs *regs)
1082 case 0x00: handle_101a00(regs); break;
1083 case 0x01: handle_101a01(regs); break;
1084 default: handle_101aXX(regs); break;
1090 u16 static_functionality_off;
1091 u16 static_functionality_seg;
1111 handle_101b(struct bregs *regs)
1114 struct funcInfo *info = (void*)(regs->di+0);
1115 memset_far(seg, info, 0, sizeof(*info));
1116 // Address of static functionality table
1117 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1118 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1120 // Hard coded copy from BIOS area. Should it be cleaner ?
1121 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1122 , sizeof(info->bda_0x49));
1123 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1124 , sizeof(info->bda_0x84));
1126 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1127 SET_FARVAR(seg, info->colors, 16);
1128 SET_FARVAR(seg, info->pages, 8);
1129 SET_FARVAR(seg, info->scan_lines, 2);
1130 SET_FARVAR(seg, info->video_mem, 3);
1136 handle_101c00(struct bregs *regs)
1138 u16 flags = regs->cx;
1141 size += sizeof(struct saveVideoHardware);
1143 size += sizeof(struct saveBDAstate);
1145 size += sizeof(struct saveDACcolors);
1151 handle_101c01(struct bregs *regs)
1153 u16 flags = regs->cx;
1155 void *data = (void*)(regs->bx+0);
1157 vgahw_save_state(seg, data);
1158 data += sizeof(struct saveVideoHardware);
1161 save_bda_state(seg, data);
1162 data += sizeof(struct saveBDAstate);
1165 vgahw_save_dac_state(seg, data);
1170 handle_101c02(struct bregs *regs)
1172 u16 flags = regs->cx;
1174 void *data = (void*)(regs->bx+0);
1176 vgahw_restore_state(seg, data);
1177 data += sizeof(struct saveVideoHardware);
1180 restore_bda_state(seg, data);
1181 data += sizeof(struct saveBDAstate);
1184 vgahw_restore_dac_state(seg, data);
1189 handle_101cXX(struct bregs *regs)
1195 handle_101c(struct bregs *regs)
1198 case 0x00: handle_101c00(regs); break;
1199 case 0x01: handle_101c01(regs); break;
1200 case 0x02: handle_101c02(regs); break;
1201 default: handle_101cXX(regs); break;
1207 handle_104f00(struct bregs *regs)
1209 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1210 // XXX - OR cirrus_vesa_00h
1214 handle_104f01(struct bregs *regs)
1216 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1217 // XXX - OR cirrus_vesa_01h
1221 handle_104f02(struct bregs *regs)
1223 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1224 // XXX - OR cirrus_vesa_02h
1228 handle_104f03(struct bregs *regs)
1230 // XXX - vbe_biosfn_return_current_mode
1231 // XXX - OR cirrus_vesa_03h
1235 handle_104f04(struct bregs *regs)
1237 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1241 handle_104f05(struct bregs *regs)
1243 // XXX - vbe_biosfn_display_window_control
1244 // XXX - OR cirrus_vesa_05h
1248 handle_104f06(struct bregs *regs)
1250 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1251 // XXX - OR cirrus_vesa_06h
1255 handle_104f07(struct bregs *regs)
1257 // XXX - vbe_biosfn_set_get_display_start
1258 // XXX - OR cirrus_vesa_07h
1262 handle_104f08(struct bregs *regs)
1264 // XXX - vbe_biosfn_set_get_dac_palette_format
1268 handle_104f0a(struct bregs *regs)
1270 // XXX - vbe_biosfn_return_protected_mode_interface
1274 handle_104fXX(struct bregs *regs)
1281 handle_104f(struct bregs *regs)
1283 if (! CONFIG_VGA_BOCHS || !bochs_has_vbe_display()) {
1284 handle_104fXX(regs);
1289 case 0x00: handle_104f00(regs); break;
1290 case 0x01: handle_104f01(regs); break;
1291 case 0x02: handle_104f02(regs); break;
1292 case 0x03: handle_104f03(regs); break;
1293 case 0x04: handle_104f04(regs); break;
1294 case 0x05: handle_104f05(regs); break;
1295 case 0x06: handle_104f06(regs); break;
1296 case 0x07: handle_104f07(regs); break;
1297 case 0x08: handle_104f08(regs); break;
1298 case 0x0a: handle_104f0a(regs); break;
1299 default: handle_104fXX(regs); break;
1305 handle_10XX(struct bregs *regs)
1310 // INT 10h Video Support Service Entry Point
1312 handle_10(struct bregs *regs)
1314 debug_enter(regs, DEBUG_VGA_10);
1316 case 0x00: handle_1000(regs); break;
1317 case 0x01: handle_1001(regs); break;
1318 case 0x02: handle_1002(regs); break;
1319 case 0x03: handle_1003(regs); break;
1320 case 0x04: handle_1004(regs); break;
1321 case 0x05: handle_1005(regs); break;
1322 case 0x06: handle_1006(regs); break;
1323 case 0x07: handle_1007(regs); break;
1324 case 0x08: handle_1008(regs); break;
1325 case 0x09: handle_1009(regs); break;
1326 case 0x0a: handle_100a(regs); break;
1327 case 0x0b: handle_100b(regs); break;
1328 case 0x0c: handle_100c(regs); break;
1329 case 0x0d: handle_100d(regs); break;
1330 case 0x0e: handle_100e(regs); break;
1331 case 0x0f: handle_100f(regs); break;
1332 case 0x10: handle_1010(regs); break;
1333 case 0x11: handle_1011(regs); break;
1334 case 0x12: handle_1012(regs); break;
1335 case 0x13: handle_1013(regs); break;
1336 case 0x1a: handle_101a(regs); break;
1337 case 0x1b: handle_101b(regs); break;
1338 case 0x1c: handle_101c(regs); break;
1339 case 0x4f: handle_104f(regs); break;
1340 default: handle_10XX(regs); break;
1345 /****************************************************************
1347 ****************************************************************/
1350 init_bios_area(void)
1352 // init detected hardware BIOS Area
1353 // set 80x25 color (not clear from RBIL but usual)
1354 u16 eqf = GET_BDA(equipment_list_flags);
1355 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1357 // Just for the first int10 find its children
1359 // the default char height
1360 SET_BDA(char_height, 0x10);
1363 SET_BDA(video_ctl, 0x60);
1365 // Set the basic screen we have
1366 SET_BDA(video_switches, 0xf9);
1368 // Set the basic modeset options
1369 SET_BDA(modeset_ctl, 0x51);
1371 // Set the default MSR
1372 SET_BDA(video_msr, 0x09);
1376 vga_post(struct bregs *regs)
1378 debug_enter(regs, DEBUG_VGA_POST);
1384 if (CONFIG_VGA_BOCHS)
1387 extern void entry_10(void);
1388 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1390 if (CONFIG_VGA_CIRRUS)
1393 // XXX - clear screen and display info
1396 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
1397 SET_VGA(video_save_pointer_table[1], get_global_seg());
1400 extern u8 _rom_header_size, _rom_header_checksum;
1401 SET_VGA(_rom_header_checksum, 0);
1402 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1403 SET_VGA(_rom_header_checksum, sum);