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" // calc_page_size
18 #include "optionroms.h" // struct pci_data
19 #include "config.h" // CONFIG_*
20 #include "stdvga.h" // stdvga_set_cursor_shape
21 #include "clext.h" // clext_1012
22 #include "vgahw.h" // vgahw_set_mode
23 #include "pci.h" // pci_config_readw
24 #include "pci_regs.h" // PCI_VENDOR_ID
27 #define DEBUG_VGA_POST 1
28 #define DEBUG_VGA_10 3
30 // Standard Video Save Pointer Table
31 struct VideoSavePointer_s {
32 struct segoff_s videoparam;
33 struct segoff_s paramdynamicsave;
34 struct segoff_s textcharset;
35 struct segoff_s graphcharset;
36 struct segoff_s secsavepointer;
40 static struct VideoSavePointer_s video_save_pointer_table VAR16;
42 struct VideoParam_s video_param_table[29] VAR16;
45 /****************************************************************
47 ****************************************************************/
48 #if CONFIG_VGA_PCI == 1
49 struct pci_data rom_pci_data VAR16VISIBLE = {
50 .signature = PCI_ROM_SIGNATURE,
51 .vendor = CONFIG_VGA_VID,
52 .device = CONFIG_VGA_DID,
56 .type = PCIROM_CODETYPE_X86,
61 /****************************************************************
63 ****************************************************************/
66 calc_page_size(u8 memmodel, u16 width, u16 height)
70 return ALIGN(width * height * 2, 2*1024);
74 return ALIGN(width * height / 8, 8*1024);
79 set_cursor_shape(u8 start, u8 end)
84 u16 curs = (start << 8) + end;
85 SET_BDA(cursor_type, curs);
87 u8 modeset_ctl = GET_BDA(modeset_ctl);
88 u16 cheight = GET_BDA(char_height);
89 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
90 if (end != (start + 1))
91 start = ((start + 1) * cheight / 8) - 1;
93 start = ((end + 1) * cheight / 8) - 2;
94 end = ((end + 1) * cheight / 8) - 1;
96 stdvga_set_cursor_shape(start, end);
100 get_cursor_shape(u8 page)
104 // FIXME should handle VGA 14/16 lines
105 return GET_BDA(cursor_type);
109 set_cursor_pos(struct cursorpos cp)
111 // Should not happen...
116 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
118 // Set the hardware cursor
119 u8 current = GET_BDA(video_page);
120 if (cp.page != current)
123 // Calculate the memory address
124 u16 nbcols = GET_BDA(video_cols);
125 u16 address = (GET_BDA(video_pagesize) * cp.page
126 + (cp.x + cp.y * nbcols) * 2);
128 stdvga_set_cursor_pos(address / 2);
131 static struct cursorpos
132 get_cursor_pos(u8 page)
135 // special case - use current page
136 page = GET_BDA(video_page);
138 struct cursorpos cp = { 0, 0, 0xfe };
141 // FIXME should handle VGA 14/16 lines
142 u16 xy = GET_BDA(cursor_pos[page]);
143 struct cursorpos cp = {xy, xy>>8, page};
148 set_active_page(u8 page)
154 struct vgamode_s *vmode_g = get_current_mode();
158 // Get pos curs pos for the right page
159 struct cursorpos cp = get_cursor_pos(page);
161 // Calculate memory address of start of page
162 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
163 u16 address = GET_BDA(video_pagesize) * page;
164 stdvga_set_active_page(memmodel == MM_TEXT ? address / 2 : address);
166 // And change the BIOS page
167 SET_BDA(video_pagestart, address);
168 SET_BDA(video_page, page);
170 dprintf(1, "Set active page %02x address %04x\n", page, address);
172 // Display the cursor, now the page is active
177 set_scan_lines(u8 lines)
179 stdvga_set_scan_lines(lines);
181 set_cursor_shape(0x06, 0x07);
183 set_cursor_shape(lines - 4, lines - 3);
184 SET_BDA(char_height, lines);
185 u16 vde = stdvga_get_vde();
186 u8 rows = vde / lines;
187 SET_BDA(video_rows, rows - 1);
188 u16 cols = GET_BDA(video_cols);
189 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
193 /****************************************************************
195 ****************************************************************/
197 // Scroll the screen one line. This function is designed to be called
198 // tail-recursive to reduce stack usage.
200 scroll_one(u16 nbrows, u16 nbcols, u8 page)
202 struct cursorpos ul = {0, 0, page};
203 struct cursorpos lr = {nbcols-1, nbrows-1, page};
204 vgafb_scroll(1, -1, ul, lr);
207 // Write a character to the screen at a given position. Implement
208 // special characters and scroll the screen if necessary.
210 write_teletype(struct cursorpos *pcp, struct carattr ca)
212 struct cursorpos cp = *pcp;
214 // Get the dimensions
215 u16 nbrows = GET_BDA(video_rows) + 1;
216 u16 nbcols = GET_BDA(video_cols);
234 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
235 vgafb_write_char(cp, dummyca);
237 } while (cp.x < nbcols && cp.x % 8);
240 vgafb_write_char(cp, ca);
244 // Do we need to wrap ?
245 if (cp.x == nbcols) {
249 // Do we need to scroll ?
257 scroll_one(nbrows, nbcols, cp.page);
260 // Write out a buffer of alternating characters and attributes.
262 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
265 u8 car = GET_FARVAR(seg, *offset_far);
267 u8 attr = GET_FARVAR(seg, *offset_far);
270 struct carattr ca = {car, attr, 1};
271 write_teletype(pcp, ca);
275 // Write out a buffer of characters.
277 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
280 u8 car = GET_FARVAR(seg, *offset_far);
283 struct carattr ca = {car, attr, 1};
284 write_teletype(pcp, ca);
289 /****************************************************************
290 * Save and restore bda state
291 ****************************************************************/
294 save_bda_state(u16 seg, struct saveBDAstate *info)
296 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
297 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
298 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
299 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
300 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
301 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
302 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
303 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
304 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
305 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
308 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
309 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
310 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
312 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
313 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
317 restore_bda_state(u16 seg, struct saveBDAstate *info)
319 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
320 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
321 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
322 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
323 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
324 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
325 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
326 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
327 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
328 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
330 for (i = 0; i < 8; i++)
331 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
332 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
333 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
335 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
336 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
340 /****************************************************************
342 ****************************************************************/
345 get_current_mode(void)
347 return vgahw_find_mode(GET_BDA(video_mode));
350 // Setup BDA after a mode switch.
352 modeswitch_set_bda(int mode, int flags, struct vgamode_s *vmode_g)
355 int width = GET_GLOBAL(vmode_g->width);
356 int height = GET_GLOBAL(vmode_g->height);
357 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
358 int cheight = GET_GLOBAL(vmode_g->cheight);
359 SET_BDA(video_mode, mode);
360 if (memmodel == MM_TEXT) {
361 SET_BDA(video_cols, width);
362 SET_BDA(video_rows, height-1);
363 SET_BDA(cursor_type, 0x0607);
365 int cwidth = GET_GLOBAL(vmode_g->cwidth);
366 SET_BDA(video_cols, width / cwidth);
367 SET_BDA(video_rows, (height / cheight) - 1);
368 SET_BDA(cursor_type, 0x0000);
370 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
371 SET_BDA(crtc_address, stdvga_get_crtc());
372 SET_BDA(char_height, cheight);
373 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
374 SET_BDA(video_switches, 0xF9);
375 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
378 SET_BDA(cursor_pos[i], 0x0000);
379 SET_BDA(video_pagestart, 0x0000);
380 SET_BDA(video_page, 0x00);
382 // FIXME We nearly have the good tables. to be reworked
383 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
384 SET_BDA(video_savetable
385 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
388 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
389 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
391 // Set the ints 0x1F and 0x43
392 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
396 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
399 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
402 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
408 /****************************************************************
410 ****************************************************************/
413 handle_1000(struct bregs *regs)
415 int mode = regs->al & 0x7f;
425 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
427 flags |= MF_NOCLEARMEM;
429 vgahw_set_mode(mode, flags);
433 handle_1001(struct bregs *regs)
435 set_cursor_shape(regs->ch, regs->cl);
439 handle_1002(struct bregs *regs)
441 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
446 handle_1003(struct bregs *regs)
448 regs->cx = get_cursor_shape(regs->bh);
449 struct cursorpos cp = get_cursor_pos(regs->bh);
454 // Read light pen pos (unimplemented)
456 handle_1004(struct bregs *regs)
459 regs->ax = regs->bx = regs->cx = regs->dx = 0;
463 handle_1005(struct bregs *regs)
465 set_active_page(regs->al);
469 verify_scroll(struct bregs *regs, int dir)
471 u8 page = GET_BDA(video_page);
472 struct cursorpos ul = {regs->cl, regs->ch, page};
473 struct cursorpos lr = {regs->dl, regs->dh, page};
475 u16 nbrows = GET_BDA(video_rows) + 1;
478 u16 nbcols = GET_BDA(video_cols);
482 if (ul.x > lr.x || ul.y > lr.y)
485 u16 nblines = regs->al;
486 if (!nblines || nblines > lr.y - ul.y + 1)
487 nblines = lr.y - ul.y + 1;
489 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
493 handle_1006(struct bregs *regs)
495 verify_scroll(regs, 1);
499 handle_1007(struct bregs *regs)
501 verify_scroll(regs, -1);
505 handle_1008(struct bregs *regs)
507 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
513 write_chars(u8 page, struct carattr ca, u16 count)
515 struct cursorpos cp = get_cursor_pos(page);
517 vgafb_write_char(cp, ca);
523 handle_1009(struct bregs *regs)
525 struct carattr ca = {regs->al, regs->bl, 1};
526 write_chars(regs->bh, ca, regs->cx);
530 handle_100a(struct bregs *regs)
532 struct carattr ca = {regs->al, regs->bl, 0};
533 write_chars(regs->bh, ca, regs->cx);
538 handle_100b00(struct bregs *regs)
540 stdvga_set_border_color(regs->bl);
544 handle_100b01(struct bregs *regs)
546 stdvga_set_palette(regs->bl);
550 handle_100bXX(struct bregs *regs)
556 handle_100b(struct bregs *regs)
559 case 0x00: handle_100b00(regs); break;
560 case 0x01: handle_100b01(regs); break;
561 default: handle_100bXX(regs); break;
567 handle_100c(struct bregs *regs)
569 // XXX - page (regs->bh) is unused
570 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
574 handle_100d(struct bregs *regs)
576 // XXX - page (regs->bh) is unused
577 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
581 handle_100e(struct bregs *regs)
583 // Ralf Brown Interrupt list is WRONG on bh(page)
584 // We do output only on the current page !
585 struct carattr ca = {regs->al, regs->bl, 0};
586 struct cursorpos cp = get_cursor_pos(0xff);
587 write_teletype(&cp, ca);
592 handle_100f(struct bregs *regs)
594 regs->bh = GET_BDA(video_page);
595 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
596 regs->ah = GET_BDA(video_cols);
601 handle_101000(struct bregs *regs)
605 stdvga_attr_write(regs->bl, regs->bh);
609 handle_101001(struct bregs *regs)
611 stdvga_set_overscan_border_color(regs->bh);
615 handle_101002(struct bregs *regs)
617 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
621 handle_101003(struct bregs *regs)
623 stdvga_toggle_intensity(regs->bl);
627 handle_101007(struct bregs *regs)
631 regs->bh = stdvga_attr_read(regs->bl);
635 handle_101008(struct bregs *regs)
637 regs->bh = stdvga_get_overscan_border_color();
641 handle_101009(struct bregs *regs)
643 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
647 handle_101010(struct bregs *regs)
649 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
650 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
654 handle_101012(struct bregs *regs)
656 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
660 handle_101013(struct bregs *regs)
662 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
666 handle_101015(struct bregs *regs)
669 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
676 handle_101017(struct bregs *regs)
678 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
682 handle_101018(struct bregs *regs)
684 stdvga_pelmask_write(regs->bl);
688 handle_101019(struct bregs *regs)
690 regs->bl = stdvga_pelmask_read();
694 handle_10101a(struct bregs *regs)
696 stdvga_read_video_dac_state(®s->bl, ®s->bh);
700 handle_10101b(struct bregs *regs)
702 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
706 handle_1010XX(struct bregs *regs)
712 handle_1010(struct bregs *regs)
715 case 0x00: handle_101000(regs); break;
716 case 0x01: handle_101001(regs); break;
717 case 0x02: handle_101002(regs); break;
718 case 0x03: handle_101003(regs); break;
719 case 0x07: handle_101007(regs); break;
720 case 0x08: handle_101008(regs); break;
721 case 0x09: handle_101009(regs); break;
722 case 0x10: handle_101010(regs); break;
723 case 0x12: handle_101012(regs); break;
724 case 0x13: handle_101013(regs); break;
725 case 0x15: handle_101015(regs); break;
726 case 0x17: handle_101017(regs); break;
727 case 0x18: handle_101018(regs); break;
728 case 0x19: handle_101019(regs); break;
729 case 0x1a: handle_10101a(regs); break;
730 case 0x1b: handle_10101b(regs); break;
731 default: handle_1010XX(regs); break;
737 handle_101100(struct bregs *regs)
739 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
740 , regs->dx, regs->bl, regs->bh);
744 handle_101101(struct bregs *regs)
746 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
750 handle_101102(struct bregs *regs)
752 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
756 handle_101103(struct bregs *regs)
758 stdvga_set_text_block_specifier(regs->bl);
762 handle_101104(struct bregs *regs)
764 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
768 handle_101110(struct bregs *regs)
770 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
771 , regs->dx, regs->bl, regs->bh);
772 set_scan_lines(regs->bh);
776 handle_101111(struct bregs *regs)
778 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
783 handle_101112(struct bregs *regs)
785 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
790 handle_101114(struct bregs *regs)
792 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
797 handle_101130(struct bregs *regs)
801 struct segoff_s so = GET_IVT(0x1f);
803 regs->bp = so.offset;
807 struct segoff_s so = GET_IVT(0x43);
809 regs->bp = so.offset;
813 regs->es = get_global_seg();
814 regs->bp = (u32)vgafont14;
817 regs->es = get_global_seg();
818 regs->bp = (u32)vgafont8;
821 regs->es = get_global_seg();
822 regs->bp = (u32)vgafont8 + 128 * 8;
825 regs->es = get_global_seg();
826 regs->bp = (u32)vgafont14alt;
829 regs->es = get_global_seg();
830 regs->bp = (u32)vgafont16;
833 regs->es = get_global_seg();
834 regs->bp = (u32)vgafont16alt;
837 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
840 // Set byte/char of on screen font
841 regs->cx = GET_BDA(char_height) & 0xff;
843 // Set Highest char row
844 regs->dx = GET_BDA(video_rows);
848 handle_1011XX(struct bregs *regs)
854 handle_1011(struct bregs *regs)
857 case 0x00: handle_101100(regs); break;
858 case 0x01: handle_101101(regs); break;
859 case 0x02: handle_101102(regs); break;
860 case 0x03: handle_101103(regs); break;
861 case 0x04: handle_101104(regs); break;
862 case 0x10: handle_101110(regs); break;
863 case 0x11: handle_101111(regs); break;
864 case 0x12: handle_101112(regs); break;
865 case 0x14: handle_101114(regs); break;
866 case 0x30: handle_101130(regs); break;
867 default: handle_1011XX(regs); break;
873 handle_101210(struct bregs *regs)
875 u16 crtc_addr = GET_BDA(crtc_address);
876 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
880 regs->cx = GET_BDA(video_switches) & 0x0f;
884 handle_101230(struct bregs *regs)
886 u8 mctl = GET_BDA(modeset_ctl);
887 u8 vswt = GET_BDA(video_switches);
891 mctl = (mctl & ~0x10) | 0x80;
892 vswt = (vswt & ~0x0f) | 0x08;
897 vswt = (vswt & ~0x0f) | 0x09;
901 mctl = (mctl & ~0x80) | 0x10;
902 vswt = (vswt & ~0x0f) | 0x09;
905 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
908 SET_BDA(modeset_ctl, mctl);
909 SET_BDA(video_switches, vswt);
914 handle_101231(struct bregs *regs)
916 u8 v = (regs->al & 0x01) << 3;
917 u8 mctl = GET_BDA(video_ctl) & ~0x08;
918 SET_BDA(video_ctl, mctl | v);
923 handle_101232(struct bregs *regs)
925 stdvga_enable_video_addressing(regs->al);
930 handle_101233(struct bregs *regs)
932 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
933 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
934 SET_BDA(modeset_ctl, v | v2);
939 handle_101234(struct bregs *regs)
941 u8 v = (regs->al & 0x01) ^ 0x01;
942 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
943 SET_BDA(modeset_ctl, v | v2);
948 handle_101235(struct bregs *regs)
955 handle_101236(struct bregs *regs)
962 handle_1012XX(struct bregs *regs)
968 handle_1012(struct bregs *regs)
970 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
976 case 0x10: handle_101210(regs); break;
977 case 0x30: handle_101230(regs); break;
978 case 0x31: handle_101231(regs); break;
979 case 0x32: handle_101232(regs); break;
980 case 0x33: handle_101233(regs); break;
981 case 0x34: handle_101234(regs); break;
982 case 0x35: handle_101235(regs); break;
983 case 0x36: handle_101236(regs); break;
984 default: handle_1012XX(regs); break;
991 handle_1013(struct bregs *regs)
993 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
994 // if row=0xff special case : use current cursor position
996 cp = get_cursor_pos(cp.page);
999 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1001 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1009 handle_101a00(struct bregs *regs)
1011 regs->bx = GET_BDA(dcc_index);
1016 handle_101a01(struct bregs *regs)
1018 SET_BDA(dcc_index, regs->bl);
1019 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1024 handle_101aXX(struct bregs *regs)
1030 handle_101a(struct bregs *regs)
1033 case 0x00: handle_101a00(regs); break;
1034 case 0x01: handle_101a01(regs); break;
1035 default: handle_101aXX(regs); break;
1040 static u8 static_functionality[0x10] VAR16 = {
1041 /* 0 */ 0xff, // All modes supported #1
1042 /* 1 */ 0xe0, // All modes supported #2
1043 /* 2 */ 0x0f, // All modes supported #3
1044 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1045 /* 7 */ 0x07, // 200, 350, 400 scan lines
1046 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1047 /* 9 */ 0x08, // total number of charset blocks in text mode
1048 /* a */ 0xe7, // Change to add new functions
1049 /* b */ 0x0c, // Change to add new functions
1050 /* c */ 0x00, // reserved
1051 /* d */ 0x00, // reserved
1052 /* e */ 0x00, // Change to add new functions
1053 /* f */ 0x00 // reserved
1057 struct segoff_s static_functionality;
1077 handle_101b(struct bregs *regs)
1080 struct funcInfo *info = (void*)(regs->di+0);
1081 memset_far(seg, info, 0, sizeof(*info));
1082 // Address of static functionality table
1083 SET_FARVAR(seg, info->static_functionality
1084 , SEGOFF(get_global_seg(), (u32)static_functionality));
1086 // Hard coded copy from BIOS area. Should it be cleaner ?
1087 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1088 , sizeof(info->bda_0x49));
1089 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1090 , sizeof(info->bda_0x84));
1092 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1093 SET_FARVAR(seg, info->colors, 16);
1094 SET_FARVAR(seg, info->pages, 8);
1095 SET_FARVAR(seg, info->scan_lines, 2);
1096 SET_FARVAR(seg, info->video_mem, 3);
1102 handle_101c00(struct bregs *regs)
1104 u16 flags = regs->cx;
1107 size += sizeof(struct saveVideoHardware);
1109 size += sizeof(struct saveBDAstate);
1111 size += sizeof(struct saveDACcolors);
1117 handle_101c01(struct bregs *regs)
1119 u16 flags = regs->cx;
1121 void *data = (void*)(regs->bx+0);
1123 stdvga_save_state(seg, data);
1124 data += sizeof(struct saveVideoHardware);
1127 save_bda_state(seg, data);
1128 data += sizeof(struct saveBDAstate);
1131 stdvga_save_dac_state(seg, data);
1136 handle_101c02(struct bregs *regs)
1138 u16 flags = regs->cx;
1140 void *data = (void*)(regs->bx+0);
1142 stdvga_restore_state(seg, data);
1143 data += sizeof(struct saveVideoHardware);
1146 restore_bda_state(seg, data);
1147 data += sizeof(struct saveBDAstate);
1150 stdvga_restore_dac_state(seg, data);
1155 handle_101cXX(struct bregs *regs)
1161 handle_101c(struct bregs *regs)
1164 case 0x00: handle_101c00(regs); break;
1165 case 0x01: handle_101c01(regs); break;
1166 case 0x02: handle_101c02(regs); break;
1167 default: handle_101cXX(regs); break;
1172 handle_10XX(struct bregs *regs)
1177 // INT 10h Video Support Service Entry Point
1179 handle_10(struct bregs *regs)
1181 debug_enter(regs, DEBUG_VGA_10);
1183 case 0x00: handle_1000(regs); break;
1184 case 0x01: handle_1001(regs); break;
1185 case 0x02: handle_1002(regs); break;
1186 case 0x03: handle_1003(regs); break;
1187 case 0x04: handle_1004(regs); break;
1188 case 0x05: handle_1005(regs); break;
1189 case 0x06: handle_1006(regs); break;
1190 case 0x07: handle_1007(regs); break;
1191 case 0x08: handle_1008(regs); break;
1192 case 0x09: handle_1009(regs); break;
1193 case 0x0a: handle_100a(regs); break;
1194 case 0x0b: handle_100b(regs); break;
1195 case 0x0c: handle_100c(regs); break;
1196 case 0x0d: handle_100d(regs); break;
1197 case 0x0e: handle_100e(regs); break;
1198 case 0x0f: handle_100f(regs); break;
1199 case 0x10: handle_1010(regs); break;
1200 case 0x11: handle_1011(regs); break;
1201 case 0x12: handle_1012(regs); break;
1202 case 0x13: handle_1013(regs); break;
1203 case 0x1a: handle_101a(regs); break;
1204 case 0x1b: handle_101b(regs); break;
1205 case 0x1c: handle_101c(regs); break;
1206 case 0x4f: handle_104f(regs); break;
1207 default: handle_10XX(regs); break;
1212 /****************************************************************
1214 ****************************************************************/
1217 init_bios_area(void)
1219 // init detected hardware BIOS Area
1220 // set 80x25 color (not clear from RBIL but usual)
1221 u16 eqf = GET_BDA(equipment_list_flags);
1222 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1224 // Just for the first int10 find its children
1226 // the default char height
1227 SET_BDA(char_height, 0x10);
1230 SET_BDA(video_ctl, 0x60);
1232 // Set the basic screen we have
1233 SET_BDA(video_switches, 0xf9);
1235 // Set the basic modeset options
1236 SET_BDA(modeset_ctl, 0x51);
1238 // Set the default MSR
1239 SET_BDA(video_msr, 0x09);
1242 int VgaBDF VAR16 = -1;
1245 vga_post(struct bregs *regs)
1247 debug_enter(regs, DEBUG_VGA_POST);
1249 if (CONFIG_VGA_PCI) {
1251 if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
1252 && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
1253 SET_VGA(VgaBDF, bdf);
1256 int ret = vgahw_init();
1258 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1264 SET_VGA(video_save_pointer_table.videoparam
1265 , SEGOFF(get_global_seg(), (u32)video_param_table));
1266 stdvga_build_video_param();
1268 extern void entry_10(void);
1269 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1271 // XXX - clear screen and display info
1274 extern u8 _rom_header_size, _rom_header_checksum;
1275 SET_VGA(_rom_header_checksum, 0);
1276 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1277 SET_VGA(_rom_header_checksum, sum);