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 "geodevga.h" // geodevga_init
22 #include "bochsvga.h" // bochsvga_init
23 #include "clext.h" // clext_init
24 #include "vgahw.h" // vgahw_set_mode
27 #define DEBUG_VGA_POST 1
28 #define DEBUG_VGA_10 3
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 calc_page_size(u8 memmodel, u16 width, u16 height)
56 return ALIGN(width * height * 2, 2*1024);
60 return ALIGN(width * height / 8, 8*1024);
65 set_cursor_shape(u8 start, u8 end)
70 u16 curs = (start << 8) + end;
71 SET_BDA(cursor_type, curs);
73 u8 modeset_ctl = GET_BDA(modeset_ctl);
74 u16 cheight = GET_BDA(char_height);
75 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
76 if (end != (start + 1))
77 start = ((start + 1) * cheight / 8) - 1;
79 start = ((end + 1) * cheight / 8) - 2;
80 end = ((end + 1) * cheight / 8) - 1;
82 stdvga_set_cursor_shape(start, end);
86 get_cursor_shape(u8 page)
90 // FIXME should handle VGA 14/16 lines
91 return GET_BDA(cursor_type);
95 set_cursor_pos(struct cursorpos cp)
97 // Should not happen...
102 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
104 // Set the hardware cursor
105 u8 current = GET_BDA(video_page);
106 if (cp.page != current)
109 // Calculate the memory address
110 u16 nbcols = GET_BDA(video_cols);
111 u16 address = (GET_BDA(video_pagesize) * cp.page
112 + (cp.x + cp.y * nbcols) * 2);
114 stdvga_set_cursor_pos(address / 2);
117 static struct cursorpos
118 get_cursor_pos(u8 page)
121 // special case - use current page
122 page = GET_BDA(video_page);
124 struct cursorpos cp = { 0, 0, 0xfe };
127 // FIXME should handle VGA 14/16 lines
128 u16 xy = GET_BDA(cursor_pos[page]);
129 struct cursorpos cp = {xy, xy>>8, page};
134 set_active_page(u8 page)
140 struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
144 // Get pos curs pos for the right page
145 struct cursorpos cp = get_cursor_pos(page);
147 // Calculate memory address of start of page
148 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
149 u16 address = GET_BDA(video_pagesize) * page;
150 stdvga_set_active_page(memmodel == MM_TEXT ? address / 2 : address);
152 // And change the BIOS page
153 SET_BDA(video_pagestart, address);
154 SET_BDA(video_page, page);
156 dprintf(1, "Set active page %02x address %04x\n", page, address);
158 // Display the cursor, now the page is active
163 set_scan_lines(u8 lines)
165 stdvga_set_scan_lines(lines);
167 set_cursor_shape(0x06, 0x07);
169 set_cursor_shape(lines - 4, lines - 3);
170 SET_BDA(char_height, lines);
171 u16 vde = stdvga_get_vde();
172 u8 rows = vde / lines;
173 SET_BDA(video_rows, rows - 1);
174 u16 cols = GET_BDA(video_cols);
175 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
179 /****************************************************************
181 ****************************************************************/
183 // Scroll the screen one line. This function is designed to be called
184 // tail-recursive to reduce stack usage.
186 scroll_one(u16 nbrows, u16 nbcols, u8 page)
188 struct cursorpos ul = {0, 0, page};
189 struct cursorpos lr = {nbcols-1, nbrows-1, page};
190 vgafb_scroll(1, -1, ul, lr);
193 // Write a character to the screen at a given position. Implement
194 // special characters and scroll the screen if necessary.
196 write_teletype(struct cursorpos *pcp, struct carattr ca)
198 struct cursorpos cp = *pcp;
200 // Get the dimensions
201 u16 nbrows = GET_BDA(video_rows) + 1;
202 u16 nbcols = GET_BDA(video_cols);
220 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
221 vgafb_write_char(cp, dummyca);
223 } while (cp.x < nbcols && cp.x % 8);
226 vgafb_write_char(cp, ca);
230 // Do we need to wrap ?
231 if (cp.x == nbcols) {
235 // Do we need to scroll ?
243 scroll_one(nbrows, nbcols, cp.page);
246 // Write out a buffer of alternating characters and attributes.
248 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
251 u8 car = GET_FARVAR(seg, *offset_far);
253 u8 attr = GET_FARVAR(seg, *offset_far);
256 struct carattr ca = {car, attr, 1};
257 write_teletype(pcp, ca);
261 // Write out a buffer of characters.
263 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
266 u8 car = GET_FARVAR(seg, *offset_far);
269 struct carattr ca = {car, attr, 1};
270 write_teletype(pcp, ca);
275 /****************************************************************
276 * Save and restore bda state
277 ****************************************************************/
280 save_bda_state(u16 seg, struct saveBDAstate *info)
282 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
283 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
284 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
285 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
286 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
287 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
288 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
289 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
290 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
291 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
294 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
295 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
296 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
298 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
299 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
303 restore_bda_state(u16 seg, struct saveBDAstate *info)
305 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
306 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
307 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
308 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
309 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
310 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
311 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
312 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
313 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
314 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
316 for (i = 0; i < 8; i++)
317 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
318 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
319 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
321 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
322 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
325 // Setup BDA after a mode switch.
327 modeswitch_set_bda(int mode, int flags, struct vgamode_s *vmode_g)
330 int width = GET_GLOBAL(vmode_g->width);
331 int height = GET_GLOBAL(vmode_g->height);
332 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
333 int cheight = GET_GLOBAL(vmode_g->cheight);
334 SET_BDA(video_mode, mode);
335 if (memmodel == MM_TEXT) {
336 SET_BDA(video_cols, width);
337 SET_BDA(video_rows, height-1);
338 SET_BDA(cursor_type, 0x0607);
340 int cwidth = GET_GLOBAL(vmode_g->cwidth);
341 SET_BDA(video_cols, width / cwidth);
342 SET_BDA(video_rows, (height / cheight) - 1);
343 SET_BDA(cursor_type, 0x0000);
345 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
346 SET_BDA(crtc_address, stdvga_get_crtc());
347 SET_BDA(char_height, cheight);
348 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
349 SET_BDA(video_switches, 0xF9);
350 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
353 SET_BDA(cursor_pos[i], 0x0000);
354 SET_BDA(video_pagestart, 0x0000);
355 SET_BDA(video_page, 0x00);
357 // FIXME We nearly have the good tables. to be reworked
358 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
359 SET_BDA(video_savetable
360 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
363 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
364 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
366 // Set the ints 0x1F and 0x43
367 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
371 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
374 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
377 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
383 /****************************************************************
385 ****************************************************************/
388 handle_1000(struct bregs *regs)
390 int mode = regs->al & 0x7f;
400 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
402 flags |= MF_NOCLEARMEM;
404 vgahw_set_mode(mode, flags);
408 handle_1001(struct bregs *regs)
410 set_cursor_shape(regs->ch, regs->cl);
414 handle_1002(struct bregs *regs)
416 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
421 handle_1003(struct bregs *regs)
423 regs->cx = get_cursor_shape(regs->bh);
424 struct cursorpos cp = get_cursor_pos(regs->bh);
429 // Read light pen pos (unimplemented)
431 handle_1004(struct bregs *regs)
434 regs->ax = regs->bx = regs->cx = regs->dx = 0;
438 handle_1005(struct bregs *regs)
440 set_active_page(regs->al);
444 verify_scroll(struct bregs *regs, int dir)
446 u8 page = GET_BDA(video_page);
447 struct cursorpos ul = {regs->cl, regs->ch, page};
448 struct cursorpos lr = {regs->dl, regs->dh, page};
450 u16 nbrows = GET_BDA(video_rows) + 1;
453 u16 nbcols = GET_BDA(video_cols);
457 if (ul.x > lr.x || ul.y > lr.y)
460 u16 nblines = regs->al;
461 if (!nblines || nblines > lr.y - ul.y + 1)
462 nblines = lr.y - ul.y + 1;
464 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
468 handle_1006(struct bregs *regs)
470 verify_scroll(regs, 1);
474 handle_1007(struct bregs *regs)
476 verify_scroll(regs, -1);
480 handle_1008(struct bregs *regs)
482 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
488 write_chars(u8 page, struct carattr ca, u16 count)
490 struct cursorpos cp = get_cursor_pos(page);
492 vgafb_write_char(cp, ca);
498 handle_1009(struct bregs *regs)
500 struct carattr ca = {regs->al, regs->bl, 1};
501 write_chars(regs->bh, ca, regs->cx);
505 handle_100a(struct bregs *regs)
507 struct carattr ca = {regs->al, regs->bl, 0};
508 write_chars(regs->bh, ca, regs->cx);
513 handle_100b00(struct bregs *regs)
515 stdvga_set_border_color(regs->bl);
519 handle_100b01(struct bregs *regs)
521 stdvga_set_palette(regs->bl);
525 handle_100bXX(struct bregs *regs)
531 handle_100b(struct bregs *regs)
534 case 0x00: handle_100b00(regs); break;
535 case 0x01: handle_100b01(regs); break;
536 default: handle_100bXX(regs); break;
542 handle_100c(struct bregs *regs)
544 // XXX - page (regs->bh) is unused
545 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
549 handle_100d(struct bregs *regs)
551 // XXX - page (regs->bh) is unused
552 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
556 handle_100e(struct bregs *regs)
558 // Ralf Brown Interrupt list is WRONG on bh(page)
559 // We do output only on the current page !
560 struct carattr ca = {regs->al, regs->bl, 0};
561 struct cursorpos cp = get_cursor_pos(0xff);
562 write_teletype(&cp, ca);
567 handle_100f(struct bregs *regs)
569 regs->bh = GET_BDA(video_page);
570 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
571 regs->ah = GET_BDA(video_cols);
576 handle_101000(struct bregs *regs)
580 stdvga_set_single_palette_reg(regs->bl, regs->bh);
584 handle_101001(struct bregs *regs)
586 stdvga_set_overscan_border_color(regs->bh);
590 handle_101002(struct bregs *regs)
592 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
596 handle_101003(struct bregs *regs)
598 stdvga_toggle_intensity(regs->bl);
602 handle_101007(struct bregs *regs)
606 regs->bh = stdvga_get_single_palette_reg(regs->bl);
610 handle_101008(struct bregs *regs)
612 regs->bh = stdvga_get_overscan_border_color();
616 handle_101009(struct bregs *regs)
618 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
622 handle_101010(struct bregs *regs)
624 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
625 stdvga_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
629 handle_101012(struct bregs *regs)
631 stdvga_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
635 handle_101013(struct bregs *regs)
637 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
641 handle_101015(struct bregs *regs)
644 stdvga_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
651 handle_101017(struct bregs *regs)
653 stdvga_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
657 handle_101018(struct bregs *regs)
659 stdvga_set_pel_mask(regs->bl);
663 handle_101019(struct bregs *regs)
665 regs->bl = stdvga_get_pel_mask();
669 handle_10101a(struct bregs *regs)
671 stdvga_read_video_dac_state(®s->bl, ®s->bh);
675 handle_10101b(struct bregs *regs)
677 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
681 handle_1010XX(struct bregs *regs)
687 handle_1010(struct bregs *regs)
690 case 0x00: handle_101000(regs); break;
691 case 0x01: handle_101001(regs); break;
692 case 0x02: handle_101002(regs); break;
693 case 0x03: handle_101003(regs); break;
694 case 0x07: handle_101007(regs); break;
695 case 0x08: handle_101008(regs); break;
696 case 0x09: handle_101009(regs); break;
697 case 0x10: handle_101010(regs); break;
698 case 0x12: handle_101012(regs); break;
699 case 0x13: handle_101013(regs); break;
700 case 0x15: handle_101015(regs); break;
701 case 0x17: handle_101017(regs); break;
702 case 0x18: handle_101018(regs); break;
703 case 0x19: handle_101019(regs); break;
704 case 0x1a: handle_10101a(regs); break;
705 case 0x1b: handle_10101b(regs); break;
706 default: handle_1010XX(regs); break;
712 handle_101100(struct bregs *regs)
714 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
715 , regs->dx, regs->bl, regs->bh);
719 handle_101101(struct bregs *regs)
721 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
725 handle_101102(struct bregs *regs)
727 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
731 handle_101103(struct bregs *regs)
733 stdvga_set_text_block_specifier(regs->bl);
737 handle_101104(struct bregs *regs)
739 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
743 handle_101110(struct bregs *regs)
745 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
746 , regs->dx, regs->bl, regs->bh);
747 set_scan_lines(regs->bh);
751 handle_101111(struct bregs *regs)
753 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
758 handle_101112(struct bregs *regs)
760 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
765 handle_101114(struct bregs *regs)
767 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
772 handle_101130(struct bregs *regs)
776 struct segoff_s so = GET_IVT(0x1f);
778 regs->bp = so.offset;
782 struct segoff_s so = GET_IVT(0x43);
784 regs->bp = so.offset;
788 regs->es = get_global_seg();
789 regs->bp = (u32)vgafont14;
792 regs->es = get_global_seg();
793 regs->bp = (u32)vgafont8;
796 regs->es = get_global_seg();
797 regs->bp = (u32)vgafont8 + 128 * 8;
800 regs->es = get_global_seg();
801 regs->bp = (u32)vgafont14alt;
804 regs->es = get_global_seg();
805 regs->bp = (u32)vgafont16;
808 regs->es = get_global_seg();
809 regs->bp = (u32)vgafont16alt;
812 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
815 // Set byte/char of on screen font
816 regs->cx = GET_BDA(char_height) & 0xff;
818 // Set Highest char row
819 regs->dx = GET_BDA(video_rows);
823 handle_1011XX(struct bregs *regs)
829 handle_1011(struct bregs *regs)
832 case 0x00: handle_101100(regs); break;
833 case 0x01: handle_101101(regs); break;
834 case 0x02: handle_101102(regs); break;
835 case 0x03: handle_101103(regs); break;
836 case 0x04: handle_101104(regs); break;
837 case 0x10: handle_101110(regs); break;
838 case 0x11: handle_101111(regs); break;
839 case 0x12: handle_101112(regs); break;
840 case 0x14: handle_101114(regs); break;
841 case 0x30: handle_101130(regs); break;
842 default: handle_1011XX(regs); break;
848 handle_101210(struct bregs *regs)
850 u16 crtc_addr = GET_BDA(crtc_address);
851 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
855 regs->cx = GET_BDA(video_switches) & 0x0f;
859 handle_101230(struct bregs *regs)
861 u8 mctl = GET_BDA(modeset_ctl);
862 u8 vswt = GET_BDA(video_switches);
866 mctl = (mctl & ~0x10) | 0x80;
867 vswt = (vswt & ~0x0f) | 0x08;
872 vswt = (vswt & ~0x0f) | 0x09;
876 mctl = (mctl & ~0x80) | 0x10;
877 vswt = (vswt & ~0x0f) | 0x09;
880 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
883 SET_BDA(modeset_ctl, mctl);
884 SET_BDA(video_switches, vswt);
889 handle_101231(struct bregs *regs)
891 u8 v = (regs->al & 0x01) << 3;
892 u8 mctl = GET_BDA(video_ctl) & ~0x08;
893 SET_BDA(video_ctl, mctl | v);
898 handle_101232(struct bregs *regs)
900 stdvga_enable_video_addressing(regs->al);
905 handle_101233(struct bregs *regs)
907 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
908 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
909 SET_BDA(modeset_ctl, v | v2);
914 handle_101234(struct bregs *regs)
916 u8 v = (regs->al & 0x01) ^ 0x01;
917 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
918 SET_BDA(modeset_ctl, v | v2);
923 handle_101235(struct bregs *regs)
930 handle_101236(struct bregs *regs)
937 handle_1012XX(struct bregs *regs)
943 handle_1012(struct bregs *regs)
946 case 0x10: handle_101210(regs); break;
947 case 0x30: handle_101230(regs); break;
948 case 0x31: handle_101231(regs); break;
949 case 0x32: handle_101232(regs); break;
950 case 0x33: handle_101233(regs); break;
951 case 0x34: handle_101234(regs); break;
952 case 0x35: handle_101235(regs); break;
953 case 0x36: handle_101236(regs); break;
954 default: handle_1012XX(regs); break;
957 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
963 handle_1013(struct bregs *regs)
965 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
966 // if row=0xff special case : use current cursor position
968 cp = get_cursor_pos(cp.page);
971 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
973 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
981 handle_101a00(struct bregs *regs)
983 regs->bx = GET_BDA(dcc_index);
988 handle_101a01(struct bregs *regs)
990 SET_BDA(dcc_index, regs->bl);
991 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
996 handle_101aXX(struct bregs *regs)
1002 handle_101a(struct bregs *regs)
1005 case 0x00: handle_101a00(regs); break;
1006 case 0x01: handle_101a01(regs); break;
1007 default: handle_101aXX(regs); break;
1013 struct segoff_s static_functionality;
1033 handle_101b(struct bregs *regs)
1036 struct funcInfo *info = (void*)(regs->di+0);
1037 memset_far(seg, info, 0, sizeof(*info));
1038 // Address of static functionality table
1039 SET_FARVAR(seg, info->static_functionality
1040 , SEGOFF(get_global_seg(), (u32)static_functionality));
1042 // Hard coded copy from BIOS area. Should it be cleaner ?
1043 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1044 , sizeof(info->bda_0x49));
1045 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1046 , sizeof(info->bda_0x84));
1048 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1049 SET_FARVAR(seg, info->colors, 16);
1050 SET_FARVAR(seg, info->pages, 8);
1051 SET_FARVAR(seg, info->scan_lines, 2);
1052 SET_FARVAR(seg, info->video_mem, 3);
1058 handle_101c00(struct bregs *regs)
1060 u16 flags = regs->cx;
1063 size += sizeof(struct saveVideoHardware);
1065 size += sizeof(struct saveBDAstate);
1067 size += sizeof(struct saveDACcolors);
1073 handle_101c01(struct bregs *regs)
1075 u16 flags = regs->cx;
1077 void *data = (void*)(regs->bx+0);
1079 stdvga_save_state(seg, data);
1080 data += sizeof(struct saveVideoHardware);
1083 save_bda_state(seg, data);
1084 data += sizeof(struct saveBDAstate);
1087 stdvga_save_dac_state(seg, data);
1092 handle_101c02(struct bregs *regs)
1094 u16 flags = regs->cx;
1096 void *data = (void*)(regs->bx+0);
1098 stdvga_restore_state(seg, data);
1099 data += sizeof(struct saveVideoHardware);
1102 restore_bda_state(seg, data);
1103 data += sizeof(struct saveBDAstate);
1106 stdvga_restore_dac_state(seg, data);
1111 handle_101cXX(struct bregs *regs)
1117 handle_101c(struct bregs *regs)
1120 case 0x00: handle_101c00(regs); break;
1121 case 0x01: handle_101c01(regs); break;
1122 case 0x02: handle_101c02(regs); break;
1123 default: handle_101cXX(regs); break;
1128 handle_10XX(struct bregs *regs)
1133 // INT 10h Video Support Service Entry Point
1135 handle_10(struct bregs *regs)
1137 debug_enter(regs, DEBUG_VGA_10);
1139 case 0x00: handle_1000(regs); break;
1140 case 0x01: handle_1001(regs); break;
1141 case 0x02: handle_1002(regs); break;
1142 case 0x03: handle_1003(regs); break;
1143 case 0x04: handle_1004(regs); break;
1144 case 0x05: handle_1005(regs); break;
1145 case 0x06: handle_1006(regs); break;
1146 case 0x07: handle_1007(regs); break;
1147 case 0x08: handle_1008(regs); break;
1148 case 0x09: handle_1009(regs); break;
1149 case 0x0a: handle_100a(regs); break;
1150 case 0x0b: handle_100b(regs); break;
1151 case 0x0c: handle_100c(regs); break;
1152 case 0x0d: handle_100d(regs); break;
1153 case 0x0e: handle_100e(regs); break;
1154 case 0x0f: handle_100f(regs); break;
1155 case 0x10: handle_1010(regs); break;
1156 case 0x11: handle_1011(regs); break;
1157 case 0x12: handle_1012(regs); break;
1158 case 0x13: handle_1013(regs); break;
1159 case 0x1a: handle_101a(regs); break;
1160 case 0x1b: handle_101b(regs); break;
1161 case 0x1c: handle_101c(regs); break;
1162 case 0x4f: handle_104f(regs); break;
1163 default: handle_10XX(regs); break;
1168 /****************************************************************
1170 ****************************************************************/
1173 init_bios_area(void)
1175 // init detected hardware BIOS Area
1176 // set 80x25 color (not clear from RBIL but usual)
1177 u16 eqf = GET_BDA(equipment_list_flags);
1178 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1180 // Just for the first int10 find its children
1182 // the default char height
1183 SET_BDA(char_height, 0x10);
1186 SET_BDA(video_ctl, 0x60);
1188 // Set the basic screen we have
1189 SET_BDA(video_switches, 0xf9);
1191 // Set the basic modeset options
1192 SET_BDA(modeset_ctl, 0x51);
1194 // Set the default MSR
1195 SET_BDA(video_msr, 0x09);
1201 vga_post(struct bregs *regs)
1203 debug_enter(regs, DEBUG_VGA_POST);
1205 SET_VGA(VgaBDF, regs->ax);
1207 int ret = vgahw_init();
1209 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1215 build_video_param();
1217 extern void entry_10(void);
1218 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1220 // XXX - clear screen and display info
1223 extern u8 _rom_header_size, _rom_header_checksum;
1224 SET_VGA(_rom_header_checksum, 0);
1225 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1226 SET_VGA(_rom_header_checksum, sum);