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
25 #define DEBUG_VGA_POST 1
26 #define DEBUG_VGA_10 3
28 // Standard Video Save Pointer Table
29 struct VideoSavePointer_s {
30 struct segoff_s videoparam;
31 struct segoff_s paramdynamicsave;
32 struct segoff_s textcharset;
33 struct segoff_s graphcharset;
34 struct segoff_s secsavepointer;
38 static struct VideoSavePointer_s video_save_pointer_table VAR16;
40 struct VideoParam_s video_param_table[29] VAR16;
43 /****************************************************************
45 ****************************************************************/
46 #if CONFIG_VGA_PCI == 1
47 struct pci_data rom_pci_data VAR16VISIBLE = {
48 .signature = PCI_ROM_SIGNATURE,
49 .vendor = CONFIG_VGA_VID,
50 .device = CONFIG_VGA_DID,
54 .type = PCIROM_CODETYPE_X86,
59 /****************************************************************
61 ****************************************************************/
64 calc_page_size(u8 memmodel, u16 width, u16 height)
68 return ALIGN(width * height * 2, 2*1024);
72 return ALIGN(width * height / 8, 8*1024);
77 set_cursor_shape(u8 start, u8 end)
82 u16 curs = (start << 8) + end;
83 SET_BDA(cursor_type, curs);
85 u8 modeset_ctl = GET_BDA(modeset_ctl);
86 u16 cheight = GET_BDA(char_height);
87 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
88 if (end != (start + 1))
89 start = ((start + 1) * cheight / 8) - 1;
91 start = ((end + 1) * cheight / 8) - 2;
92 end = ((end + 1) * cheight / 8) - 1;
94 stdvga_set_cursor_shape(start, end);
98 get_cursor_shape(u8 page)
102 // FIXME should handle VGA 14/16 lines
103 return GET_BDA(cursor_type);
107 set_cursor_pos(struct cursorpos cp)
109 // Should not happen...
114 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
116 // Set the hardware cursor
117 u8 current = GET_BDA(video_page);
118 if (cp.page != current)
121 // Calculate the memory address
122 u16 nbcols = GET_BDA(video_cols);
123 u16 address = (GET_BDA(video_pagesize) * cp.page
124 + (cp.x + cp.y * nbcols) * 2);
126 stdvga_set_cursor_pos(address / 2);
129 static struct cursorpos
130 get_cursor_pos(u8 page)
133 // special case - use current page
134 page = GET_BDA(video_page);
136 struct cursorpos cp = { 0, 0, 0xfe };
139 // FIXME should handle VGA 14/16 lines
140 u16 xy = GET_BDA(cursor_pos[page]);
141 struct cursorpos cp = {xy, xy>>8, page};
146 set_active_page(u8 page)
152 struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
156 // Get pos curs pos for the right page
157 struct cursorpos cp = get_cursor_pos(page);
159 // Calculate memory address of start of page
160 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
161 u16 address = GET_BDA(video_pagesize) * page;
162 stdvga_set_active_page(memmodel == MM_TEXT ? address / 2 : address);
164 // And change the BIOS page
165 SET_BDA(video_pagestart, address);
166 SET_BDA(video_page, page);
168 dprintf(1, "Set active page %02x address %04x\n", page, address);
170 // Display the cursor, now the page is active
175 set_scan_lines(u8 lines)
177 stdvga_set_scan_lines(lines);
179 set_cursor_shape(0x06, 0x07);
181 set_cursor_shape(lines - 4, lines - 3);
182 SET_BDA(char_height, lines);
183 u16 vde = stdvga_get_vde();
184 u8 rows = vde / lines;
185 SET_BDA(video_rows, rows - 1);
186 u16 cols = GET_BDA(video_cols);
187 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
191 /****************************************************************
193 ****************************************************************/
195 // Scroll the screen one line. This function is designed to be called
196 // tail-recursive to reduce stack usage.
198 scroll_one(u16 nbrows, u16 nbcols, u8 page)
200 struct cursorpos ul = {0, 0, page};
201 struct cursorpos lr = {nbcols-1, nbrows-1, page};
202 vgafb_scroll(1, -1, ul, lr);
205 // Write a character to the screen at a given position. Implement
206 // special characters and scroll the screen if necessary.
208 write_teletype(struct cursorpos *pcp, struct carattr ca)
210 struct cursorpos cp = *pcp;
212 // Get the dimensions
213 u16 nbrows = GET_BDA(video_rows) + 1;
214 u16 nbcols = GET_BDA(video_cols);
232 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
233 vgafb_write_char(cp, dummyca);
235 } while (cp.x < nbcols && cp.x % 8);
238 vgafb_write_char(cp, ca);
242 // Do we need to wrap ?
243 if (cp.x == nbcols) {
247 // Do we need to scroll ?
255 scroll_one(nbrows, nbcols, cp.page);
258 // Write out a buffer of alternating characters and attributes.
260 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
263 u8 car = GET_FARVAR(seg, *offset_far);
265 u8 attr = GET_FARVAR(seg, *offset_far);
268 struct carattr ca = {car, attr, 1};
269 write_teletype(pcp, ca);
273 // Write out a buffer of characters.
275 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
278 u8 car = GET_FARVAR(seg, *offset_far);
281 struct carattr ca = {car, attr, 1};
282 write_teletype(pcp, ca);
287 /****************************************************************
288 * Save and restore bda state
289 ****************************************************************/
292 save_bda_state(u16 seg, struct saveBDAstate *info)
294 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
295 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
296 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
297 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
298 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
299 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
300 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
301 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
302 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
303 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
306 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
307 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
308 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
310 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
311 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
315 restore_bda_state(u16 seg, struct saveBDAstate *info)
317 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
318 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
319 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
320 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
321 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
322 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
323 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
324 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
325 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
326 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
328 for (i = 0; i < 8; i++)
329 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
330 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
331 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
333 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
334 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
337 // Setup BDA after a mode switch.
339 modeswitch_set_bda(int mode, int flags, struct vgamode_s *vmode_g)
342 int width = GET_GLOBAL(vmode_g->width);
343 int height = GET_GLOBAL(vmode_g->height);
344 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
345 int cheight = GET_GLOBAL(vmode_g->cheight);
346 SET_BDA(video_mode, mode);
347 if (memmodel == MM_TEXT) {
348 SET_BDA(video_cols, width);
349 SET_BDA(video_rows, height-1);
350 SET_BDA(cursor_type, 0x0607);
352 int cwidth = GET_GLOBAL(vmode_g->cwidth);
353 SET_BDA(video_cols, width / cwidth);
354 SET_BDA(video_rows, (height / cheight) - 1);
355 SET_BDA(cursor_type, 0x0000);
357 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
358 SET_BDA(crtc_address, stdvga_get_crtc());
359 SET_BDA(char_height, cheight);
360 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
361 SET_BDA(video_switches, 0xF9);
362 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
365 SET_BDA(cursor_pos[i], 0x0000);
366 SET_BDA(video_pagestart, 0x0000);
367 SET_BDA(video_page, 0x00);
369 // FIXME We nearly have the good tables. to be reworked
370 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
371 SET_BDA(video_savetable
372 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
375 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
376 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
378 // Set the ints 0x1F and 0x43
379 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
383 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
386 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
389 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
395 /****************************************************************
397 ****************************************************************/
400 handle_1000(struct bregs *regs)
402 int mode = regs->al & 0x7f;
412 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
414 flags |= MF_NOCLEARMEM;
416 vgahw_set_mode(mode, flags);
420 handle_1001(struct bregs *regs)
422 set_cursor_shape(regs->ch, regs->cl);
426 handle_1002(struct bregs *regs)
428 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
433 handle_1003(struct bregs *regs)
435 regs->cx = get_cursor_shape(regs->bh);
436 struct cursorpos cp = get_cursor_pos(regs->bh);
441 // Read light pen pos (unimplemented)
443 handle_1004(struct bregs *regs)
446 regs->ax = regs->bx = regs->cx = regs->dx = 0;
450 handle_1005(struct bregs *regs)
452 set_active_page(regs->al);
456 verify_scroll(struct bregs *regs, int dir)
458 u8 page = GET_BDA(video_page);
459 struct cursorpos ul = {regs->cl, regs->ch, page};
460 struct cursorpos lr = {regs->dl, regs->dh, page};
462 u16 nbrows = GET_BDA(video_rows) + 1;
465 u16 nbcols = GET_BDA(video_cols);
469 if (ul.x > lr.x || ul.y > lr.y)
472 u16 nblines = regs->al;
473 if (!nblines || nblines > lr.y - ul.y + 1)
474 nblines = lr.y - ul.y + 1;
476 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
480 handle_1006(struct bregs *regs)
482 verify_scroll(regs, 1);
486 handle_1007(struct bregs *regs)
488 verify_scroll(regs, -1);
492 handle_1008(struct bregs *regs)
494 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
500 write_chars(u8 page, struct carattr ca, u16 count)
502 struct cursorpos cp = get_cursor_pos(page);
504 vgafb_write_char(cp, ca);
510 handle_1009(struct bregs *regs)
512 struct carattr ca = {regs->al, regs->bl, 1};
513 write_chars(regs->bh, ca, regs->cx);
517 handle_100a(struct bregs *regs)
519 struct carattr ca = {regs->al, regs->bl, 0};
520 write_chars(regs->bh, ca, regs->cx);
525 handle_100b00(struct bregs *regs)
527 stdvga_set_border_color(regs->bl);
531 handle_100b01(struct bregs *regs)
533 stdvga_set_palette(regs->bl);
537 handle_100bXX(struct bregs *regs)
543 handle_100b(struct bregs *regs)
546 case 0x00: handle_100b00(regs); break;
547 case 0x01: handle_100b01(regs); break;
548 default: handle_100bXX(regs); break;
554 handle_100c(struct bregs *regs)
556 // XXX - page (regs->bh) is unused
557 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
561 handle_100d(struct bregs *regs)
563 // XXX - page (regs->bh) is unused
564 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
568 handle_100e(struct bregs *regs)
570 // Ralf Brown Interrupt list is WRONG on bh(page)
571 // We do output only on the current page !
572 struct carattr ca = {regs->al, regs->bl, 0};
573 struct cursorpos cp = get_cursor_pos(0xff);
574 write_teletype(&cp, ca);
579 handle_100f(struct bregs *regs)
581 regs->bh = GET_BDA(video_page);
582 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
583 regs->ah = GET_BDA(video_cols);
588 handle_101000(struct bregs *regs)
592 stdvga_attr_write(regs->bl, regs->bh);
596 handle_101001(struct bregs *regs)
598 stdvga_set_overscan_border_color(regs->bh);
602 handle_101002(struct bregs *regs)
604 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
608 handle_101003(struct bregs *regs)
610 stdvga_toggle_intensity(regs->bl);
614 handle_101007(struct bregs *regs)
618 regs->bh = stdvga_attr_read(regs->bl);
622 handle_101008(struct bregs *regs)
624 regs->bh = stdvga_get_overscan_border_color();
628 handle_101009(struct bregs *regs)
630 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
634 handle_101010(struct bregs *regs)
636 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
637 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
641 handle_101012(struct bregs *regs)
643 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
647 handle_101013(struct bregs *regs)
649 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
653 handle_101015(struct bregs *regs)
656 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
663 handle_101017(struct bregs *regs)
665 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
669 handle_101018(struct bregs *regs)
671 stdvga_pelmask_write(regs->bl);
675 handle_101019(struct bregs *regs)
677 regs->bl = stdvga_pelmask_read();
681 handle_10101a(struct bregs *regs)
683 stdvga_read_video_dac_state(®s->bl, ®s->bh);
687 handle_10101b(struct bregs *regs)
689 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
693 handle_1010XX(struct bregs *regs)
699 handle_1010(struct bregs *regs)
702 case 0x00: handle_101000(regs); break;
703 case 0x01: handle_101001(regs); break;
704 case 0x02: handle_101002(regs); break;
705 case 0x03: handle_101003(regs); break;
706 case 0x07: handle_101007(regs); break;
707 case 0x08: handle_101008(regs); break;
708 case 0x09: handle_101009(regs); break;
709 case 0x10: handle_101010(regs); break;
710 case 0x12: handle_101012(regs); break;
711 case 0x13: handle_101013(regs); break;
712 case 0x15: handle_101015(regs); break;
713 case 0x17: handle_101017(regs); break;
714 case 0x18: handle_101018(regs); break;
715 case 0x19: handle_101019(regs); break;
716 case 0x1a: handle_10101a(regs); break;
717 case 0x1b: handle_10101b(regs); break;
718 default: handle_1010XX(regs); break;
724 handle_101100(struct bregs *regs)
726 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
727 , regs->dx, regs->bl, regs->bh);
731 handle_101101(struct bregs *regs)
733 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
737 handle_101102(struct bregs *regs)
739 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
743 handle_101103(struct bregs *regs)
745 stdvga_set_text_block_specifier(regs->bl);
749 handle_101104(struct bregs *regs)
751 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
755 handle_101110(struct bregs *regs)
757 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
758 , regs->dx, regs->bl, regs->bh);
759 set_scan_lines(regs->bh);
763 handle_101111(struct bregs *regs)
765 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
770 handle_101112(struct bregs *regs)
772 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
777 handle_101114(struct bregs *regs)
779 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
784 handle_101130(struct bregs *regs)
788 struct segoff_s so = GET_IVT(0x1f);
790 regs->bp = so.offset;
794 struct segoff_s so = GET_IVT(0x43);
796 regs->bp = so.offset;
800 regs->es = get_global_seg();
801 regs->bp = (u32)vgafont14;
804 regs->es = get_global_seg();
805 regs->bp = (u32)vgafont8;
808 regs->es = get_global_seg();
809 regs->bp = (u32)vgafont8 + 128 * 8;
812 regs->es = get_global_seg();
813 regs->bp = (u32)vgafont14alt;
816 regs->es = get_global_seg();
817 regs->bp = (u32)vgafont16;
820 regs->es = get_global_seg();
821 regs->bp = (u32)vgafont16alt;
824 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
827 // Set byte/char of on screen font
828 regs->cx = GET_BDA(char_height) & 0xff;
830 // Set Highest char row
831 regs->dx = GET_BDA(video_rows);
835 handle_1011XX(struct bregs *regs)
841 handle_1011(struct bregs *regs)
844 case 0x00: handle_101100(regs); break;
845 case 0x01: handle_101101(regs); break;
846 case 0x02: handle_101102(regs); break;
847 case 0x03: handle_101103(regs); break;
848 case 0x04: handle_101104(regs); break;
849 case 0x10: handle_101110(regs); break;
850 case 0x11: handle_101111(regs); break;
851 case 0x12: handle_101112(regs); break;
852 case 0x14: handle_101114(regs); break;
853 case 0x30: handle_101130(regs); break;
854 default: handle_1011XX(regs); break;
860 handle_101210(struct bregs *regs)
862 u16 crtc_addr = GET_BDA(crtc_address);
863 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
867 regs->cx = GET_BDA(video_switches) & 0x0f;
871 handle_101230(struct bregs *regs)
873 u8 mctl = GET_BDA(modeset_ctl);
874 u8 vswt = GET_BDA(video_switches);
878 mctl = (mctl & ~0x10) | 0x80;
879 vswt = (vswt & ~0x0f) | 0x08;
884 vswt = (vswt & ~0x0f) | 0x09;
888 mctl = (mctl & ~0x80) | 0x10;
889 vswt = (vswt & ~0x0f) | 0x09;
892 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
895 SET_BDA(modeset_ctl, mctl);
896 SET_BDA(video_switches, vswt);
901 handle_101231(struct bregs *regs)
903 u8 v = (regs->al & 0x01) << 3;
904 u8 mctl = GET_BDA(video_ctl) & ~0x08;
905 SET_BDA(video_ctl, mctl | v);
910 handle_101232(struct bregs *regs)
912 stdvga_enable_video_addressing(regs->al);
917 handle_101233(struct bregs *regs)
919 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
920 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
921 SET_BDA(modeset_ctl, v | v2);
926 handle_101234(struct bregs *regs)
928 u8 v = (regs->al & 0x01) ^ 0x01;
929 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
930 SET_BDA(modeset_ctl, v | v2);
935 handle_101235(struct bregs *regs)
942 handle_101236(struct bregs *regs)
949 handle_1012XX(struct bregs *regs)
955 handle_1012(struct bregs *regs)
957 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
963 case 0x10: handle_101210(regs); break;
964 case 0x30: handle_101230(regs); break;
965 case 0x31: handle_101231(regs); break;
966 case 0x32: handle_101232(regs); break;
967 case 0x33: handle_101233(regs); break;
968 case 0x34: handle_101234(regs); break;
969 case 0x35: handle_101235(regs); break;
970 case 0x36: handle_101236(regs); break;
971 default: handle_1012XX(regs); break;
978 handle_1013(struct bregs *regs)
980 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
981 // if row=0xff special case : use current cursor position
983 cp = get_cursor_pos(cp.page);
986 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
988 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
996 handle_101a00(struct bregs *regs)
998 regs->bx = GET_BDA(dcc_index);
1003 handle_101a01(struct bregs *regs)
1005 SET_BDA(dcc_index, regs->bl);
1006 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1011 handle_101aXX(struct bregs *regs)
1017 handle_101a(struct bregs *regs)
1020 case 0x00: handle_101a00(regs); break;
1021 case 0x01: handle_101a01(regs); break;
1022 default: handle_101aXX(regs); break;
1027 static u8 static_functionality[0x10] VAR16 = {
1028 /* 0 */ 0xff, // All modes supported #1
1029 /* 1 */ 0xe0, // All modes supported #2
1030 /* 2 */ 0x0f, // All modes supported #3
1031 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1032 /* 7 */ 0x07, // 200, 350, 400 scan lines
1033 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1034 /* 9 */ 0x08, // total number of charset blocks in text mode
1035 /* a */ 0xe7, // Change to add new functions
1036 /* b */ 0x0c, // Change to add new functions
1037 /* c */ 0x00, // reserved
1038 /* d */ 0x00, // reserved
1039 /* e */ 0x00, // Change to add new functions
1040 /* f */ 0x00 // reserved
1044 struct segoff_s static_functionality;
1064 handle_101b(struct bregs *regs)
1067 struct funcInfo *info = (void*)(regs->di+0);
1068 memset_far(seg, info, 0, sizeof(*info));
1069 // Address of static functionality table
1070 SET_FARVAR(seg, info->static_functionality
1071 , SEGOFF(get_global_seg(), (u32)static_functionality));
1073 // Hard coded copy from BIOS area. Should it be cleaner ?
1074 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1075 , sizeof(info->bda_0x49));
1076 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1077 , sizeof(info->bda_0x84));
1079 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1080 SET_FARVAR(seg, info->colors, 16);
1081 SET_FARVAR(seg, info->pages, 8);
1082 SET_FARVAR(seg, info->scan_lines, 2);
1083 SET_FARVAR(seg, info->video_mem, 3);
1089 handle_101c00(struct bregs *regs)
1091 u16 flags = regs->cx;
1094 size += sizeof(struct saveVideoHardware);
1096 size += sizeof(struct saveBDAstate);
1098 size += sizeof(struct saveDACcolors);
1104 handle_101c01(struct bregs *regs)
1106 u16 flags = regs->cx;
1108 void *data = (void*)(regs->bx+0);
1110 stdvga_save_state(seg, data);
1111 data += sizeof(struct saveVideoHardware);
1114 save_bda_state(seg, data);
1115 data += sizeof(struct saveBDAstate);
1118 stdvga_save_dac_state(seg, data);
1123 handle_101c02(struct bregs *regs)
1125 u16 flags = regs->cx;
1127 void *data = (void*)(regs->bx+0);
1129 stdvga_restore_state(seg, data);
1130 data += sizeof(struct saveVideoHardware);
1133 restore_bda_state(seg, data);
1134 data += sizeof(struct saveBDAstate);
1137 stdvga_restore_dac_state(seg, data);
1142 handle_101cXX(struct bregs *regs)
1148 handle_101c(struct bregs *regs)
1151 case 0x00: handle_101c00(regs); break;
1152 case 0x01: handle_101c01(regs); break;
1153 case 0x02: handle_101c02(regs); break;
1154 default: handle_101cXX(regs); break;
1159 handle_10XX(struct bregs *regs)
1164 // INT 10h Video Support Service Entry Point
1166 handle_10(struct bregs *regs)
1168 debug_enter(regs, DEBUG_VGA_10);
1170 case 0x00: handle_1000(regs); break;
1171 case 0x01: handle_1001(regs); break;
1172 case 0x02: handle_1002(regs); break;
1173 case 0x03: handle_1003(regs); break;
1174 case 0x04: handle_1004(regs); break;
1175 case 0x05: handle_1005(regs); break;
1176 case 0x06: handle_1006(regs); break;
1177 case 0x07: handle_1007(regs); break;
1178 case 0x08: handle_1008(regs); break;
1179 case 0x09: handle_1009(regs); break;
1180 case 0x0a: handle_100a(regs); break;
1181 case 0x0b: handle_100b(regs); break;
1182 case 0x0c: handle_100c(regs); break;
1183 case 0x0d: handle_100d(regs); break;
1184 case 0x0e: handle_100e(regs); break;
1185 case 0x0f: handle_100f(regs); break;
1186 case 0x10: handle_1010(regs); break;
1187 case 0x11: handle_1011(regs); break;
1188 case 0x12: handle_1012(regs); break;
1189 case 0x13: handle_1013(regs); break;
1190 case 0x1a: handle_101a(regs); break;
1191 case 0x1b: handle_101b(regs); break;
1192 case 0x1c: handle_101c(regs); break;
1193 case 0x4f: handle_104f(regs); break;
1194 default: handle_10XX(regs); break;
1199 /****************************************************************
1201 ****************************************************************/
1204 init_bios_area(void)
1206 // init detected hardware BIOS Area
1207 // set 80x25 color (not clear from RBIL but usual)
1208 u16 eqf = GET_BDA(equipment_list_flags);
1209 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1211 // Just for the first int10 find its children
1213 // the default char height
1214 SET_BDA(char_height, 0x10);
1217 SET_BDA(video_ctl, 0x60);
1219 // Set the basic screen we have
1220 SET_BDA(video_switches, 0xf9);
1222 // Set the basic modeset options
1223 SET_BDA(modeset_ctl, 0x51);
1225 // Set the default MSR
1226 SET_BDA(video_msr, 0x09);
1232 vga_post(struct bregs *regs)
1234 debug_enter(regs, DEBUG_VGA_POST);
1236 SET_VGA(VgaBDF, regs->ax);
1238 int ret = vgahw_init();
1240 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1246 SET_VGA(video_save_pointer_table.videoparam
1247 , SEGOFF(get_global_seg(), (u32)video_param_table));
1248 stdvga_build_video_param();
1250 extern void entry_10(void);
1251 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1253 // XXX - clear screen and display info
1256 extern u8 _rom_header_size, _rom_header_checksum;
1257 SET_VGA(_rom_header_checksum, 0);
1258 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1259 SET_VGA(_rom_header_checksum, sum);