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
29 /****************************************************************
31 ****************************************************************/
32 #if CONFIG_VGA_PCI == 1
33 struct pci_data rom_pci_data VAR16VISIBLE = {
34 .signature = PCI_ROM_SIGNATURE,
35 .vendor = CONFIG_VGA_VID,
36 .device = CONFIG_VGA_DID,
40 .type = PCIROM_CODETYPE_X86,
45 /****************************************************************
47 ****************************************************************/
50 calc_page_size(u8 memmodel, u16 width, u16 height)
54 return ALIGN(width * height * 2, 2*1024);
58 return ALIGN(width * height / 8, 8*1024);
63 set_cursor_shape(u8 start, u8 end)
68 u16 curs = (start << 8) + end;
69 SET_BDA(cursor_type, curs);
71 u8 modeset_ctl = GET_BDA(modeset_ctl);
72 u16 cheight = GET_BDA(char_height);
73 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
74 if (end != (start + 1))
75 start = ((start + 1) * cheight / 8) - 1;
77 start = ((end + 1) * cheight / 8) - 2;
78 end = ((end + 1) * cheight / 8) - 1;
80 stdvga_set_cursor_shape(start, end);
84 get_cursor_shape(u8 page)
88 // FIXME should handle VGA 14/16 lines
89 return GET_BDA(cursor_type);
93 set_cursor_pos(struct cursorpos cp)
95 // Should not happen...
100 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
102 // Set the hardware cursor
103 u8 current = GET_BDA(video_page);
104 if (cp.page != current)
107 // Calculate the memory address
108 u16 nbcols = GET_BDA(video_cols);
109 u16 address = (GET_BDA(video_pagesize) * cp.page
110 + (cp.x + cp.y * nbcols) * 2);
112 stdvga_set_cursor_pos(address / 2);
115 static struct cursorpos
116 get_cursor_pos(u8 page)
119 // special case - use current page
120 page = GET_BDA(video_page);
122 struct cursorpos cp = { 0, 0, 0xfe };
125 // FIXME should handle VGA 14/16 lines
126 u16 xy = GET_BDA(cursor_pos[page]);
127 struct cursorpos cp = {xy, xy>>8, page};
132 set_active_page(u8 page)
138 struct vgamode_s *vmode_g = vgahw_find_mode(GET_BDA(video_mode));
142 // Get pos curs pos for the right page
143 struct cursorpos cp = get_cursor_pos(page);
145 // Calculate memory address of start of page
146 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
147 u16 address = GET_BDA(video_pagesize) * page;
148 stdvga_set_active_page(memmodel == MM_TEXT ? address / 2 : address);
150 // And change the BIOS page
151 SET_BDA(video_pagestart, address);
152 SET_BDA(video_page, page);
154 dprintf(1, "Set active page %02x address %04x\n", page, address);
156 // Display the cursor, now the page is active
161 set_scan_lines(u8 lines)
163 stdvga_set_scan_lines(lines);
165 set_cursor_shape(0x06, 0x07);
167 set_cursor_shape(lines - 4, lines - 3);
168 SET_BDA(char_height, lines);
169 u16 vde = stdvga_get_vde();
170 u8 rows = vde / lines;
171 SET_BDA(video_rows, rows - 1);
172 u16 cols = GET_BDA(video_cols);
173 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
177 /****************************************************************
179 ****************************************************************/
181 // Scroll the screen one line. This function is designed to be called
182 // tail-recursive to reduce stack usage.
184 scroll_one(u16 nbrows, u16 nbcols, u8 page)
186 struct cursorpos ul = {0, 0, page};
187 struct cursorpos lr = {nbcols-1, nbrows-1, page};
188 vgafb_scroll(1, -1, ul, lr);
191 // Write a character to the screen at a given position. Implement
192 // special characters and scroll the screen if necessary.
194 write_teletype(struct cursorpos *pcp, struct carattr ca)
196 struct cursorpos cp = *pcp;
198 // Get the dimensions
199 u16 nbrows = GET_BDA(video_rows) + 1;
200 u16 nbcols = GET_BDA(video_cols);
218 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
219 vgafb_write_char(cp, dummyca);
221 } while (cp.x < nbcols && cp.x % 8);
224 vgafb_write_char(cp, ca);
228 // Do we need to wrap ?
229 if (cp.x == nbcols) {
233 // Do we need to scroll ?
241 scroll_one(nbrows, nbcols, cp.page);
244 // Write out a buffer of alternating characters and attributes.
246 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
249 u8 car = GET_FARVAR(seg, *offset_far);
251 u8 attr = GET_FARVAR(seg, *offset_far);
254 struct carattr ca = {car, attr, 1};
255 write_teletype(pcp, ca);
259 // Write out a buffer of characters.
261 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
264 u8 car = GET_FARVAR(seg, *offset_far);
267 struct carattr ca = {car, attr, 1};
268 write_teletype(pcp, ca);
273 /****************************************************************
274 * Save and restore bda state
275 ****************************************************************/
278 save_bda_state(u16 seg, struct saveBDAstate *info)
280 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
281 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
282 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
283 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
284 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
285 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
286 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
287 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
288 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
289 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
292 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
293 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
294 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
296 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
297 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
301 restore_bda_state(u16 seg, struct saveBDAstate *info)
303 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
304 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
305 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
306 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
307 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
308 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
309 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
310 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
311 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
312 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
314 for (i = 0; i < 8; i++)
315 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
316 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
317 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
319 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
320 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
323 // Setup BDA after a mode switch.
325 modeswitch_set_bda(int mode, int flags, struct vgamode_s *vmode_g)
328 int width = GET_GLOBAL(vmode_g->width);
329 int height = GET_GLOBAL(vmode_g->height);
330 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
331 int cheight = GET_GLOBAL(vmode_g->cheight);
332 SET_BDA(video_mode, mode);
333 if (memmodel == MM_TEXT) {
334 SET_BDA(video_cols, width);
335 SET_BDA(video_rows, height-1);
336 SET_BDA(cursor_type, 0x0607);
338 int cwidth = GET_GLOBAL(vmode_g->cwidth);
339 SET_BDA(video_cols, width / cwidth);
340 SET_BDA(video_rows, (height / cheight) - 1);
341 SET_BDA(cursor_type, 0x0000);
343 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
344 SET_BDA(crtc_address, stdvga_get_crtc());
345 SET_BDA(char_height, cheight);
346 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
347 SET_BDA(video_switches, 0xF9);
348 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
351 SET_BDA(cursor_pos[i], 0x0000);
352 SET_BDA(video_pagestart, 0x0000);
353 SET_BDA(video_page, 0x00);
355 // FIXME We nearly have the good tables. to be reworked
356 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
357 SET_BDA(video_savetable
358 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
361 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
362 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
364 // Set the ints 0x1F and 0x43
365 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
369 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
372 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
375 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
381 /****************************************************************
383 ****************************************************************/
386 handle_1000(struct bregs *regs)
388 int mode = regs->al & 0x7f;
398 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
400 flags |= MF_NOCLEARMEM;
402 vgahw_set_mode(mode, flags);
406 handle_1001(struct bregs *regs)
408 set_cursor_shape(regs->ch, regs->cl);
412 handle_1002(struct bregs *regs)
414 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
419 handle_1003(struct bregs *regs)
421 regs->cx = get_cursor_shape(regs->bh);
422 struct cursorpos cp = get_cursor_pos(regs->bh);
427 // Read light pen pos (unimplemented)
429 handle_1004(struct bregs *regs)
432 regs->ax = regs->bx = regs->cx = regs->dx = 0;
436 handle_1005(struct bregs *regs)
438 set_active_page(regs->al);
442 verify_scroll(struct bregs *regs, int dir)
444 u8 page = GET_BDA(video_page);
445 struct cursorpos ul = {regs->cl, regs->ch, page};
446 struct cursorpos lr = {regs->dl, regs->dh, page};
448 u16 nbrows = GET_BDA(video_rows) + 1;
451 u16 nbcols = GET_BDA(video_cols);
455 if (ul.x > lr.x || ul.y > lr.y)
458 u16 nblines = regs->al;
459 if (!nblines || nblines > lr.y - ul.y + 1)
460 nblines = lr.y - ul.y + 1;
462 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
466 handle_1006(struct bregs *regs)
468 verify_scroll(regs, 1);
472 handle_1007(struct bregs *regs)
474 verify_scroll(regs, -1);
478 handle_1008(struct bregs *regs)
480 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
486 write_chars(u8 page, struct carattr ca, u16 count)
488 struct cursorpos cp = get_cursor_pos(page);
490 vgafb_write_char(cp, ca);
496 handle_1009(struct bregs *regs)
498 struct carattr ca = {regs->al, regs->bl, 1};
499 write_chars(regs->bh, ca, regs->cx);
503 handle_100a(struct bregs *regs)
505 struct carattr ca = {regs->al, regs->bl, 0};
506 write_chars(regs->bh, ca, regs->cx);
511 handle_100b00(struct bregs *regs)
513 stdvga_set_border_color(regs->bl);
517 handle_100b01(struct bregs *regs)
519 stdvga_set_palette(regs->bl);
523 handle_100bXX(struct bregs *regs)
529 handle_100b(struct bregs *regs)
532 case 0x00: handle_100b00(regs); break;
533 case 0x01: handle_100b01(regs); break;
534 default: handle_100bXX(regs); break;
540 handle_100c(struct bregs *regs)
542 // XXX - page (regs->bh) is unused
543 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
547 handle_100d(struct bregs *regs)
549 // XXX - page (regs->bh) is unused
550 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
554 handle_100e(struct bregs *regs)
556 // Ralf Brown Interrupt list is WRONG on bh(page)
557 // We do output only on the current page !
558 struct carattr ca = {regs->al, regs->bl, 0};
559 struct cursorpos cp = get_cursor_pos(0xff);
560 write_teletype(&cp, ca);
565 handle_100f(struct bregs *regs)
567 regs->bh = GET_BDA(video_page);
568 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
569 regs->ah = GET_BDA(video_cols);
574 handle_101000(struct bregs *regs)
578 stdvga_set_single_palette_reg(regs->bl, regs->bh);
582 handle_101001(struct bregs *regs)
584 stdvga_set_overscan_border_color(regs->bh);
588 handle_101002(struct bregs *regs)
590 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
594 handle_101003(struct bregs *regs)
596 stdvga_toggle_intensity(regs->bl);
600 handle_101007(struct bregs *regs)
604 regs->bh = stdvga_get_single_palette_reg(regs->bl);
608 handle_101008(struct bregs *regs)
610 regs->bh = stdvga_get_overscan_border_color();
614 handle_101009(struct bregs *regs)
616 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
620 handle_101010(struct bregs *regs)
622 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
623 stdvga_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
627 handle_101012(struct bregs *regs)
629 stdvga_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
633 handle_101013(struct bregs *regs)
635 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
639 handle_101015(struct bregs *regs)
642 stdvga_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
649 handle_101017(struct bregs *regs)
651 stdvga_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
655 handle_101018(struct bregs *regs)
657 stdvga_set_pel_mask(regs->bl);
661 handle_101019(struct bregs *regs)
663 regs->bl = stdvga_get_pel_mask();
667 handle_10101a(struct bregs *regs)
669 stdvga_read_video_dac_state(®s->bl, ®s->bh);
673 handle_10101b(struct bregs *regs)
675 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
679 handle_1010XX(struct bregs *regs)
685 handle_1010(struct bregs *regs)
688 case 0x00: handle_101000(regs); break;
689 case 0x01: handle_101001(regs); break;
690 case 0x02: handle_101002(regs); break;
691 case 0x03: handle_101003(regs); break;
692 case 0x07: handle_101007(regs); break;
693 case 0x08: handle_101008(regs); break;
694 case 0x09: handle_101009(regs); break;
695 case 0x10: handle_101010(regs); break;
696 case 0x12: handle_101012(regs); break;
697 case 0x13: handle_101013(regs); break;
698 case 0x15: handle_101015(regs); break;
699 case 0x17: handle_101017(regs); break;
700 case 0x18: handle_101018(regs); break;
701 case 0x19: handle_101019(regs); break;
702 case 0x1a: handle_10101a(regs); break;
703 case 0x1b: handle_10101b(regs); break;
704 default: handle_1010XX(regs); break;
710 handle_101100(struct bregs *regs)
712 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
713 , regs->dx, regs->bl, regs->bh);
717 handle_101101(struct bregs *regs)
719 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
723 handle_101102(struct bregs *regs)
725 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
729 handle_101103(struct bregs *regs)
731 stdvga_set_text_block_specifier(regs->bl);
735 handle_101104(struct bregs *regs)
737 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
741 handle_101110(struct bregs *regs)
743 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
744 , regs->dx, regs->bl, regs->bh);
745 set_scan_lines(regs->bh);
749 handle_101111(struct bregs *regs)
751 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
756 handle_101112(struct bregs *regs)
758 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
763 handle_101114(struct bregs *regs)
765 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
770 handle_101130(struct bregs *regs)
774 struct segoff_s so = GET_IVT(0x1f);
776 regs->bp = so.offset;
780 struct segoff_s so = GET_IVT(0x43);
782 regs->bp = so.offset;
786 regs->es = get_global_seg();
787 regs->bp = (u32)vgafont14;
790 regs->es = get_global_seg();
791 regs->bp = (u32)vgafont8;
794 regs->es = get_global_seg();
795 regs->bp = (u32)vgafont8 + 128 * 8;
798 regs->es = get_global_seg();
799 regs->bp = (u32)vgafont14alt;
802 regs->es = get_global_seg();
803 regs->bp = (u32)vgafont16;
806 regs->es = get_global_seg();
807 regs->bp = (u32)vgafont16alt;
810 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
813 // Set byte/char of on screen font
814 regs->cx = GET_BDA(char_height) & 0xff;
816 // Set Highest char row
817 regs->dx = GET_BDA(video_rows);
821 handle_1011XX(struct bregs *regs)
827 handle_1011(struct bregs *regs)
830 case 0x00: handle_101100(regs); break;
831 case 0x01: handle_101101(regs); break;
832 case 0x02: handle_101102(regs); break;
833 case 0x03: handle_101103(regs); break;
834 case 0x04: handle_101104(regs); break;
835 case 0x10: handle_101110(regs); break;
836 case 0x11: handle_101111(regs); break;
837 case 0x12: handle_101112(regs); break;
838 case 0x14: handle_101114(regs); break;
839 case 0x30: handle_101130(regs); break;
840 default: handle_1011XX(regs); break;
846 handle_101210(struct bregs *regs)
848 u16 crtc_addr = GET_BDA(crtc_address);
849 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
853 regs->cx = GET_BDA(video_switches) & 0x0f;
857 handle_101230(struct bregs *regs)
859 u8 mctl = GET_BDA(modeset_ctl);
860 u8 vswt = GET_BDA(video_switches);
864 mctl = (mctl & ~0x10) | 0x80;
865 vswt = (vswt & ~0x0f) | 0x08;
870 vswt = (vswt & ~0x0f) | 0x09;
874 mctl = (mctl & ~0x80) | 0x10;
875 vswt = (vswt & ~0x0f) | 0x09;
878 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
881 SET_BDA(modeset_ctl, mctl);
882 SET_BDA(video_switches, vswt);
887 handle_101231(struct bregs *regs)
889 u8 v = (regs->al & 0x01) << 3;
890 u8 mctl = GET_BDA(video_ctl) & ~0x08;
891 SET_BDA(video_ctl, mctl | v);
896 handle_101232(struct bregs *regs)
898 stdvga_enable_video_addressing(regs->al);
903 handle_101233(struct bregs *regs)
905 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
906 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
907 SET_BDA(modeset_ctl, v | v2);
912 handle_101234(struct bregs *regs)
914 u8 v = (regs->al & 0x01) ^ 0x01;
915 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
916 SET_BDA(modeset_ctl, v | v2);
921 handle_101235(struct bregs *regs)
928 handle_101236(struct bregs *regs)
935 handle_1012XX(struct bregs *regs)
941 handle_1012(struct bregs *regs)
943 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
949 case 0x10: handle_101210(regs); break;
950 case 0x30: handle_101230(regs); break;
951 case 0x31: handle_101231(regs); break;
952 case 0x32: handle_101232(regs); break;
953 case 0x33: handle_101233(regs); break;
954 case 0x34: handle_101234(regs); break;
955 case 0x35: handle_101235(regs); break;
956 case 0x36: handle_101236(regs); break;
957 default: handle_1012XX(regs); break;
964 handle_1013(struct bregs *regs)
966 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
967 // if row=0xff special case : use current cursor position
969 cp = get_cursor_pos(cp.page);
972 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
974 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
982 handle_101a00(struct bregs *regs)
984 regs->bx = GET_BDA(dcc_index);
989 handle_101a01(struct bregs *regs)
991 SET_BDA(dcc_index, regs->bl);
992 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
997 handle_101aXX(struct bregs *regs)
1003 handle_101a(struct bregs *regs)
1006 case 0x00: handle_101a00(regs); break;
1007 case 0x01: handle_101a01(regs); break;
1008 default: handle_101aXX(regs); break;
1014 struct segoff_s static_functionality;
1034 handle_101b(struct bregs *regs)
1037 struct funcInfo *info = (void*)(regs->di+0);
1038 memset_far(seg, info, 0, sizeof(*info));
1039 // Address of static functionality table
1040 SET_FARVAR(seg, info->static_functionality
1041 , SEGOFF(get_global_seg(), (u32)static_functionality));
1043 // Hard coded copy from BIOS area. Should it be cleaner ?
1044 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1045 , sizeof(info->bda_0x49));
1046 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1047 , sizeof(info->bda_0x84));
1049 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1050 SET_FARVAR(seg, info->colors, 16);
1051 SET_FARVAR(seg, info->pages, 8);
1052 SET_FARVAR(seg, info->scan_lines, 2);
1053 SET_FARVAR(seg, info->video_mem, 3);
1059 handle_101c00(struct bregs *regs)
1061 u16 flags = regs->cx;
1064 size += sizeof(struct saveVideoHardware);
1066 size += sizeof(struct saveBDAstate);
1068 size += sizeof(struct saveDACcolors);
1074 handle_101c01(struct bregs *regs)
1076 u16 flags = regs->cx;
1078 void *data = (void*)(regs->bx+0);
1080 stdvga_save_state(seg, data);
1081 data += sizeof(struct saveVideoHardware);
1084 save_bda_state(seg, data);
1085 data += sizeof(struct saveBDAstate);
1088 stdvga_save_dac_state(seg, data);
1093 handle_101c02(struct bregs *regs)
1095 u16 flags = regs->cx;
1097 void *data = (void*)(regs->bx+0);
1099 stdvga_restore_state(seg, data);
1100 data += sizeof(struct saveVideoHardware);
1103 restore_bda_state(seg, data);
1104 data += sizeof(struct saveBDAstate);
1107 stdvga_restore_dac_state(seg, data);
1112 handle_101cXX(struct bregs *regs)
1118 handle_101c(struct bregs *regs)
1121 case 0x00: handle_101c00(regs); break;
1122 case 0x01: handle_101c01(regs); break;
1123 case 0x02: handle_101c02(regs); break;
1124 default: handle_101cXX(regs); break;
1129 handle_10XX(struct bregs *regs)
1134 // INT 10h Video Support Service Entry Point
1136 handle_10(struct bregs *regs)
1138 debug_enter(regs, DEBUG_VGA_10);
1140 case 0x00: handle_1000(regs); break;
1141 case 0x01: handle_1001(regs); break;
1142 case 0x02: handle_1002(regs); break;
1143 case 0x03: handle_1003(regs); break;
1144 case 0x04: handle_1004(regs); break;
1145 case 0x05: handle_1005(regs); break;
1146 case 0x06: handle_1006(regs); break;
1147 case 0x07: handle_1007(regs); break;
1148 case 0x08: handle_1008(regs); break;
1149 case 0x09: handle_1009(regs); break;
1150 case 0x0a: handle_100a(regs); break;
1151 case 0x0b: handle_100b(regs); break;
1152 case 0x0c: handle_100c(regs); break;
1153 case 0x0d: handle_100d(regs); break;
1154 case 0x0e: handle_100e(regs); break;
1155 case 0x0f: handle_100f(regs); break;
1156 case 0x10: handle_1010(regs); break;
1157 case 0x11: handle_1011(regs); break;
1158 case 0x12: handle_1012(regs); break;
1159 case 0x13: handle_1013(regs); break;
1160 case 0x1a: handle_101a(regs); break;
1161 case 0x1b: handle_101b(regs); break;
1162 case 0x1c: handle_101c(regs); break;
1163 case 0x4f: handle_104f(regs); break;
1164 default: handle_10XX(regs); break;
1169 /****************************************************************
1171 ****************************************************************/
1174 init_bios_area(void)
1176 // init detected hardware BIOS Area
1177 // set 80x25 color (not clear from RBIL but usual)
1178 u16 eqf = GET_BDA(equipment_list_flags);
1179 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1181 // Just for the first int10 find its children
1183 // the default char height
1184 SET_BDA(char_height, 0x10);
1187 SET_BDA(video_ctl, 0x60);
1189 // Set the basic screen we have
1190 SET_BDA(video_switches, 0xf9);
1192 // Set the basic modeset options
1193 SET_BDA(modeset_ctl, 0x51);
1195 // Set the default MSR
1196 SET_BDA(video_msr, 0x09);
1202 vga_post(struct bregs *regs)
1204 debug_enter(regs, DEBUG_VGA_POST);
1206 SET_VGA(VgaBDF, regs->ax);
1208 int ret = vgahw_init();
1210 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1216 build_video_param();
1218 extern void entry_10(void);
1219 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1221 // XXX - clear screen and display info
1224 extern u8 _rom_header_size, _rom_header_checksum;
1225 SET_VGA(_rom_header_checksum, 0);
1226 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1227 SET_VGA(_rom_header_checksum, sum);