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 = vgahw_find_mode(GET_BDA(video_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));
339 // Setup BDA after a mode switch.
341 modeswitch_set_bda(int mode, int flags, struct vgamode_s *vmode_g)
344 int width = GET_GLOBAL(vmode_g->width);
345 int height = GET_GLOBAL(vmode_g->height);
346 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
347 int cheight = GET_GLOBAL(vmode_g->cheight);
348 SET_BDA(video_mode, mode);
349 if (memmodel == MM_TEXT) {
350 SET_BDA(video_cols, width);
351 SET_BDA(video_rows, height-1);
352 SET_BDA(cursor_type, 0x0607);
354 int cwidth = GET_GLOBAL(vmode_g->cwidth);
355 SET_BDA(video_cols, width / cwidth);
356 SET_BDA(video_rows, (height / cheight) - 1);
357 SET_BDA(cursor_type, 0x0000);
359 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
360 SET_BDA(crtc_address, stdvga_get_crtc());
361 SET_BDA(char_height, cheight);
362 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
363 SET_BDA(video_switches, 0xF9);
364 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
367 SET_BDA(cursor_pos[i], 0x0000);
368 SET_BDA(video_pagestart, 0x0000);
369 SET_BDA(video_page, 0x00);
371 // FIXME We nearly have the good tables. to be reworked
372 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
373 SET_BDA(video_savetable
374 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
377 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
378 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
380 // Set the ints 0x1F and 0x43
381 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
385 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
388 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
391 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
397 /****************************************************************
399 ****************************************************************/
402 handle_1000(struct bregs *regs)
404 int mode = regs->al & 0x7f;
414 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
416 flags |= MF_NOCLEARMEM;
418 vgahw_set_mode(mode, flags);
422 handle_1001(struct bregs *regs)
424 set_cursor_shape(regs->ch, regs->cl);
428 handle_1002(struct bregs *regs)
430 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
435 handle_1003(struct bregs *regs)
437 regs->cx = get_cursor_shape(regs->bh);
438 struct cursorpos cp = get_cursor_pos(regs->bh);
443 // Read light pen pos (unimplemented)
445 handle_1004(struct bregs *regs)
448 regs->ax = regs->bx = regs->cx = regs->dx = 0;
452 handle_1005(struct bregs *regs)
454 set_active_page(regs->al);
458 verify_scroll(struct bregs *regs, int dir)
460 u8 page = GET_BDA(video_page);
461 struct cursorpos ul = {regs->cl, regs->ch, page};
462 struct cursorpos lr = {regs->dl, regs->dh, page};
464 u16 nbrows = GET_BDA(video_rows) + 1;
467 u16 nbcols = GET_BDA(video_cols);
471 if (ul.x > lr.x || ul.y > lr.y)
474 u16 nblines = regs->al;
475 if (!nblines || nblines > lr.y - ul.y + 1)
476 nblines = lr.y - ul.y + 1;
478 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
482 handle_1006(struct bregs *regs)
484 verify_scroll(regs, 1);
488 handle_1007(struct bregs *regs)
490 verify_scroll(regs, -1);
494 handle_1008(struct bregs *regs)
496 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
502 write_chars(u8 page, struct carattr ca, u16 count)
504 struct cursorpos cp = get_cursor_pos(page);
506 vgafb_write_char(cp, ca);
512 handle_1009(struct bregs *regs)
514 struct carattr ca = {regs->al, regs->bl, 1};
515 write_chars(regs->bh, ca, regs->cx);
519 handle_100a(struct bregs *regs)
521 struct carattr ca = {regs->al, regs->bl, 0};
522 write_chars(regs->bh, ca, regs->cx);
527 handle_100b00(struct bregs *regs)
529 stdvga_set_border_color(regs->bl);
533 handle_100b01(struct bregs *regs)
535 stdvga_set_palette(regs->bl);
539 handle_100bXX(struct bregs *regs)
545 handle_100b(struct bregs *regs)
548 case 0x00: handle_100b00(regs); break;
549 case 0x01: handle_100b01(regs); break;
550 default: handle_100bXX(regs); break;
556 handle_100c(struct bregs *regs)
558 // XXX - page (regs->bh) is unused
559 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
563 handle_100d(struct bregs *regs)
565 // XXX - page (regs->bh) is unused
566 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
570 handle_100e(struct bregs *regs)
572 // Ralf Brown Interrupt list is WRONG on bh(page)
573 // We do output only on the current page !
574 struct carattr ca = {regs->al, regs->bl, 0};
575 struct cursorpos cp = get_cursor_pos(0xff);
576 write_teletype(&cp, ca);
581 handle_100f(struct bregs *regs)
583 regs->bh = GET_BDA(video_page);
584 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
585 regs->ah = GET_BDA(video_cols);
590 handle_101000(struct bregs *regs)
594 stdvga_attr_write(regs->bl, regs->bh);
598 handle_101001(struct bregs *regs)
600 stdvga_set_overscan_border_color(regs->bh);
604 handle_101002(struct bregs *regs)
606 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
610 handle_101003(struct bregs *regs)
612 stdvga_toggle_intensity(regs->bl);
616 handle_101007(struct bregs *regs)
620 regs->bh = stdvga_attr_read(regs->bl);
624 handle_101008(struct bregs *regs)
626 regs->bh = stdvga_get_overscan_border_color();
630 handle_101009(struct bregs *regs)
632 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
636 handle_101010(struct bregs *regs)
638 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
639 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
643 handle_101012(struct bregs *regs)
645 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
649 handle_101013(struct bregs *regs)
651 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
655 handle_101015(struct bregs *regs)
658 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
665 handle_101017(struct bregs *regs)
667 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
671 handle_101018(struct bregs *regs)
673 stdvga_pelmask_write(regs->bl);
677 handle_101019(struct bregs *regs)
679 regs->bl = stdvga_pelmask_read();
683 handle_10101a(struct bregs *regs)
685 stdvga_read_video_dac_state(®s->bl, ®s->bh);
689 handle_10101b(struct bregs *regs)
691 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
695 handle_1010XX(struct bregs *regs)
701 handle_1010(struct bregs *regs)
704 case 0x00: handle_101000(regs); break;
705 case 0x01: handle_101001(regs); break;
706 case 0x02: handle_101002(regs); break;
707 case 0x03: handle_101003(regs); break;
708 case 0x07: handle_101007(regs); break;
709 case 0x08: handle_101008(regs); break;
710 case 0x09: handle_101009(regs); break;
711 case 0x10: handle_101010(regs); break;
712 case 0x12: handle_101012(regs); break;
713 case 0x13: handle_101013(regs); break;
714 case 0x15: handle_101015(regs); break;
715 case 0x17: handle_101017(regs); break;
716 case 0x18: handle_101018(regs); break;
717 case 0x19: handle_101019(regs); break;
718 case 0x1a: handle_10101a(regs); break;
719 case 0x1b: handle_10101b(regs); break;
720 default: handle_1010XX(regs); break;
726 handle_101100(struct bregs *regs)
728 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
729 , regs->dx, regs->bl, regs->bh);
733 handle_101101(struct bregs *regs)
735 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
739 handle_101102(struct bregs *regs)
741 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
745 handle_101103(struct bregs *regs)
747 stdvga_set_text_block_specifier(regs->bl);
751 handle_101104(struct bregs *regs)
753 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
757 handle_101110(struct bregs *regs)
759 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
760 , regs->dx, regs->bl, regs->bh);
761 set_scan_lines(regs->bh);
765 handle_101111(struct bregs *regs)
767 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
772 handle_101112(struct bregs *regs)
774 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
779 handle_101114(struct bregs *regs)
781 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
786 handle_101130(struct bregs *regs)
790 struct segoff_s so = GET_IVT(0x1f);
792 regs->bp = so.offset;
796 struct segoff_s so = GET_IVT(0x43);
798 regs->bp = so.offset;
802 regs->es = get_global_seg();
803 regs->bp = (u32)vgafont14;
806 regs->es = get_global_seg();
807 regs->bp = (u32)vgafont8;
810 regs->es = get_global_seg();
811 regs->bp = (u32)vgafont8 + 128 * 8;
814 regs->es = get_global_seg();
815 regs->bp = (u32)vgafont14alt;
818 regs->es = get_global_seg();
819 regs->bp = (u32)vgafont16;
822 regs->es = get_global_seg();
823 regs->bp = (u32)vgafont16alt;
826 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
829 // Set byte/char of on screen font
830 regs->cx = GET_BDA(char_height) & 0xff;
832 // Set Highest char row
833 regs->dx = GET_BDA(video_rows);
837 handle_1011XX(struct bregs *regs)
843 handle_1011(struct bregs *regs)
846 case 0x00: handle_101100(regs); break;
847 case 0x01: handle_101101(regs); break;
848 case 0x02: handle_101102(regs); break;
849 case 0x03: handle_101103(regs); break;
850 case 0x04: handle_101104(regs); break;
851 case 0x10: handle_101110(regs); break;
852 case 0x11: handle_101111(regs); break;
853 case 0x12: handle_101112(regs); break;
854 case 0x14: handle_101114(regs); break;
855 case 0x30: handle_101130(regs); break;
856 default: handle_1011XX(regs); break;
862 handle_101210(struct bregs *regs)
864 u16 crtc_addr = GET_BDA(crtc_address);
865 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
869 regs->cx = GET_BDA(video_switches) & 0x0f;
873 handle_101230(struct bregs *regs)
875 u8 mctl = GET_BDA(modeset_ctl);
876 u8 vswt = GET_BDA(video_switches);
880 mctl = (mctl & ~0x10) | 0x80;
881 vswt = (vswt & ~0x0f) | 0x08;
886 vswt = (vswt & ~0x0f) | 0x09;
890 mctl = (mctl & ~0x80) | 0x10;
891 vswt = (vswt & ~0x0f) | 0x09;
894 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
897 SET_BDA(modeset_ctl, mctl);
898 SET_BDA(video_switches, vswt);
903 handle_101231(struct bregs *regs)
905 u8 v = (regs->al & 0x01) << 3;
906 u8 mctl = GET_BDA(video_ctl) & ~0x08;
907 SET_BDA(video_ctl, mctl | v);
912 handle_101232(struct bregs *regs)
914 stdvga_enable_video_addressing(regs->al);
919 handle_101233(struct bregs *regs)
921 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
922 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
923 SET_BDA(modeset_ctl, v | v2);
928 handle_101234(struct bregs *regs)
930 u8 v = (regs->al & 0x01) ^ 0x01;
931 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
932 SET_BDA(modeset_ctl, v | v2);
937 handle_101235(struct bregs *regs)
944 handle_101236(struct bregs *regs)
951 handle_1012XX(struct bregs *regs)
957 handle_1012(struct bregs *regs)
959 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
965 case 0x10: handle_101210(regs); break;
966 case 0x30: handle_101230(regs); break;
967 case 0x31: handle_101231(regs); break;
968 case 0x32: handle_101232(regs); break;
969 case 0x33: handle_101233(regs); break;
970 case 0x34: handle_101234(regs); break;
971 case 0x35: handle_101235(regs); break;
972 case 0x36: handle_101236(regs); break;
973 default: handle_1012XX(regs); break;
980 handle_1013(struct bregs *regs)
982 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
983 // if row=0xff special case : use current cursor position
985 cp = get_cursor_pos(cp.page);
988 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
990 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
998 handle_101a00(struct bregs *regs)
1000 regs->bx = GET_BDA(dcc_index);
1005 handle_101a01(struct bregs *regs)
1007 SET_BDA(dcc_index, regs->bl);
1008 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1013 handle_101aXX(struct bregs *regs)
1019 handle_101a(struct bregs *regs)
1022 case 0x00: handle_101a00(regs); break;
1023 case 0x01: handle_101a01(regs); break;
1024 default: handle_101aXX(regs); break;
1029 static u8 static_functionality[0x10] VAR16 = {
1030 /* 0 */ 0xff, // All modes supported #1
1031 /* 1 */ 0xe0, // All modes supported #2
1032 /* 2 */ 0x0f, // All modes supported #3
1033 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1034 /* 7 */ 0x07, // 200, 350, 400 scan lines
1035 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1036 /* 9 */ 0x08, // total number of charset blocks in text mode
1037 /* a */ 0xe7, // Change to add new functions
1038 /* b */ 0x0c, // Change to add new functions
1039 /* c */ 0x00, // reserved
1040 /* d */ 0x00, // reserved
1041 /* e */ 0x00, // Change to add new functions
1042 /* f */ 0x00 // reserved
1046 struct segoff_s static_functionality;
1066 handle_101b(struct bregs *regs)
1069 struct funcInfo *info = (void*)(regs->di+0);
1070 memset_far(seg, info, 0, sizeof(*info));
1071 // Address of static functionality table
1072 SET_FARVAR(seg, info->static_functionality
1073 , SEGOFF(get_global_seg(), (u32)static_functionality));
1075 // Hard coded copy from BIOS area. Should it be cleaner ?
1076 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1077 , sizeof(info->bda_0x49));
1078 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1079 , sizeof(info->bda_0x84));
1081 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1082 SET_FARVAR(seg, info->colors, 16);
1083 SET_FARVAR(seg, info->pages, 8);
1084 SET_FARVAR(seg, info->scan_lines, 2);
1085 SET_FARVAR(seg, info->video_mem, 3);
1091 handle_101c00(struct bregs *regs)
1093 u16 flags = regs->cx;
1096 size += sizeof(struct saveVideoHardware);
1098 size += sizeof(struct saveBDAstate);
1100 size += sizeof(struct saveDACcolors);
1106 handle_101c01(struct bregs *regs)
1108 u16 flags = regs->cx;
1110 void *data = (void*)(regs->bx+0);
1112 stdvga_save_state(seg, data);
1113 data += sizeof(struct saveVideoHardware);
1116 save_bda_state(seg, data);
1117 data += sizeof(struct saveBDAstate);
1120 stdvga_save_dac_state(seg, data);
1125 handle_101c02(struct bregs *regs)
1127 u16 flags = regs->cx;
1129 void *data = (void*)(regs->bx+0);
1131 stdvga_restore_state(seg, data);
1132 data += sizeof(struct saveVideoHardware);
1135 restore_bda_state(seg, data);
1136 data += sizeof(struct saveBDAstate);
1139 stdvga_restore_dac_state(seg, data);
1144 handle_101cXX(struct bregs *regs)
1150 handle_101c(struct bregs *regs)
1153 case 0x00: handle_101c00(regs); break;
1154 case 0x01: handle_101c01(regs); break;
1155 case 0x02: handle_101c02(regs); break;
1156 default: handle_101cXX(regs); break;
1161 handle_10XX(struct bregs *regs)
1166 // INT 10h Video Support Service Entry Point
1168 handle_10(struct bregs *regs)
1170 debug_enter(regs, DEBUG_VGA_10);
1172 case 0x00: handle_1000(regs); break;
1173 case 0x01: handle_1001(regs); break;
1174 case 0x02: handle_1002(regs); break;
1175 case 0x03: handle_1003(regs); break;
1176 case 0x04: handle_1004(regs); break;
1177 case 0x05: handle_1005(regs); break;
1178 case 0x06: handle_1006(regs); break;
1179 case 0x07: handle_1007(regs); break;
1180 case 0x08: handle_1008(regs); break;
1181 case 0x09: handle_1009(regs); break;
1182 case 0x0a: handle_100a(regs); break;
1183 case 0x0b: handle_100b(regs); break;
1184 case 0x0c: handle_100c(regs); break;
1185 case 0x0d: handle_100d(regs); break;
1186 case 0x0e: handle_100e(regs); break;
1187 case 0x0f: handle_100f(regs); break;
1188 case 0x10: handle_1010(regs); break;
1189 case 0x11: handle_1011(regs); break;
1190 case 0x12: handle_1012(regs); break;
1191 case 0x13: handle_1013(regs); break;
1192 case 0x1a: handle_101a(regs); break;
1193 case 0x1b: handle_101b(regs); break;
1194 case 0x1c: handle_101c(regs); break;
1195 case 0x4f: handle_104f(regs); break;
1196 default: handle_10XX(regs); break;
1201 /****************************************************************
1203 ****************************************************************/
1206 init_bios_area(void)
1208 // init detected hardware BIOS Area
1209 // set 80x25 color (not clear from RBIL but usual)
1210 u16 eqf = GET_BDA(equipment_list_flags);
1211 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1213 // Just for the first int10 find its children
1215 // the default char height
1216 SET_BDA(char_height, 0x10);
1219 SET_BDA(video_ctl, 0x60);
1221 // Set the basic screen we have
1222 SET_BDA(video_switches, 0xf9);
1224 // Set the basic modeset options
1225 SET_BDA(modeset_ctl, 0x51);
1227 // Set the default MSR
1228 SET_BDA(video_msr, 0x09);
1231 int VgaBDF VAR16 = -1;
1234 vga_post(struct bregs *regs)
1236 debug_enter(regs, DEBUG_VGA_POST);
1238 if (CONFIG_VGA_PCI) {
1240 if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
1241 && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
1242 SET_VGA(VgaBDF, bdf);
1245 int ret = vgahw_init();
1247 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1253 SET_VGA(video_save_pointer_table.videoparam
1254 , SEGOFF(get_global_seg(), (u32)video_param_table));
1255 stdvga_build_video_param();
1257 extern void entry_10(void);
1258 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1260 // XXX - clear screen and display info
1263 extern u8 _rom_header_size, _rom_header_checksum;
1264 SET_VGA(_rom_header_checksum, 0);
1265 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1266 SET_VGA(_rom_header_checksum, sum);