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" // find_vga_entry
18 #include "optionroms.h" // struct pci_data
19 #include "config.h" // CONFIG_*
20 #include "stdvga.h" // stdvga_set_mode
21 #include "geodelx.h" // geodelx_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 set_cursor_shape(u8 start, u8 end)
57 u16 curs = (start << 8) + end;
58 SET_BDA(cursor_type, curs);
60 u8 modeset_ctl = GET_BDA(modeset_ctl);
61 u16 cheight = GET_BDA(char_height);
62 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
63 if (end != (start + 1))
64 start = ((start + 1) * cheight / 8) - 1;
66 start = ((end + 1) * cheight / 8) - 2;
67 end = ((end + 1) * cheight / 8) - 1;
69 stdvga_set_cursor_shape(start, end);
73 get_cursor_shape(u8 page)
77 // FIXME should handle VGA 14/16 lines
78 return GET_BDA(cursor_type);
82 set_cursor_pos(struct cursorpos cp)
84 // Should not happen...
89 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
91 // Set the hardware cursor
92 u8 current = GET_BDA(video_page);
93 if (cp.page != current)
97 u16 nbcols = GET_BDA(video_cols);
98 u16 nbrows = GET_BDA(video_rows) + 1;
100 // Calculate the address knowing nbcols nbrows and page num
101 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
102 + cp.x + cp.y * nbcols);
104 stdvga_set_cursor_pos(address);
107 static struct cursorpos
108 get_cursor_pos(u8 page)
111 // special case - use current page
112 page = GET_BDA(video_page);
114 struct cursorpos cp = { 0, 0, 0xfe };
117 // FIXME should handle VGA 14/16 lines
118 u16 xy = GET_BDA(cursor_pos[page]);
119 struct cursorpos cp = {xy, xy>>8, page};
124 set_active_page(u8 page)
130 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
134 // Get pos curs pos for the right page
135 struct cursorpos cp = get_cursor_pos(page);
138 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
139 // Get the dimensions
140 u16 nbcols = GET_BDA(video_cols);
141 u16 nbrows = GET_BDA(video_rows) + 1;
143 // Calculate the address knowing nbcols nbrows and page num
144 address = SCREEN_MEM_START(nbcols, nbrows, page);
145 SET_BDA(video_pagestart, address);
148 address = SCREEN_IO_START(nbcols, nbrows, page);
150 address = page * GET_GLOBAL(vmode_g->slength);
153 stdvga_set_active_page(address);
155 // And change the BIOS page
156 SET_BDA(video_page, page);
158 dprintf(1, "Set active page %02x address %04x\n", page, address);
160 // Display the cursor, now the page is active
165 set_scan_lines(u8 lines)
167 stdvga_set_scan_lines(lines);
169 set_cursor_shape(0x06, 0x07);
171 set_cursor_shape(lines - 4, lines - 3);
172 SET_BDA(char_height, lines);
173 u16 vde = stdvga_get_vde();
174 u8 rows = vde / lines;
175 SET_BDA(video_rows, rows - 1);
176 u16 cols = GET_BDA(video_cols);
177 SET_BDA(video_pagesize, rows * cols * 2);
181 /****************************************************************
183 ****************************************************************/
185 // Scroll the screen one line. This function is designed to be called
186 // tail-recursive to reduce stack usage.
188 scroll_one(u16 nbrows, u16 nbcols, u8 page)
190 struct cursorpos ul = {0, 0, page};
191 struct cursorpos lr = {nbcols-1, nbrows-1, page};
192 vgafb_scroll(1, -1, ul, lr);
195 // Write a character to the screen at a given position. Implement
196 // special characters and scroll the screen if necessary.
198 write_teletype(struct cursorpos *pcp, struct carattr ca)
200 struct cursorpos cp = *pcp;
202 // Get the dimensions
203 u16 nbrows = GET_BDA(video_rows) + 1;
204 u16 nbcols = GET_BDA(video_cols);
222 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
223 vgafb_write_char(cp, dummyca);
225 } while (cp.x < nbcols && cp.x % 8);
228 vgafb_write_char(cp, ca);
232 // Do we need to wrap ?
233 if (cp.x == nbcols) {
237 // Do we need to scroll ?
245 scroll_one(nbrows, nbcols, cp.page);
248 // Write out a buffer of alternating characters and attributes.
250 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
253 u8 car = GET_FARVAR(seg, *offset_far);
255 u8 attr = GET_FARVAR(seg, *offset_far);
258 struct carattr ca = {car, attr, 1};
259 write_teletype(pcp, ca);
263 // Write out a buffer of characters.
265 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
268 u8 car = GET_FARVAR(seg, *offset_far);
271 struct carattr ca = {car, attr, 1};
272 write_teletype(pcp, ca);
277 /****************************************************************
278 * Save and restore bda state
279 ****************************************************************/
282 save_bda_state(u16 seg, struct saveBDAstate *info)
284 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
285 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
286 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
287 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
288 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
289 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
290 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
291 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
292 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
293 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
296 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
297 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
298 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
300 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
301 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
305 restore_bda_state(u16 seg, struct saveBDAstate *info)
307 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
308 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
309 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
310 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
311 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
312 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
313 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
314 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
315 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
316 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
318 for (i = 0; i < 8; i++)
319 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
320 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
321 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
323 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
324 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
327 // Setup BDA after a mode switch.
329 modeswitch_set_bda(int mode, int flags, struct vgamode_s *vmode_g)
332 u16 cheight = GET_GLOBAL(vmode_g->cheight);
333 SET_BDA(video_mode, mode);
334 SET_BDA(video_cols, GET_GLOBAL(vmode_g->twidth));
335 SET_BDA(video_pagesize, GET_GLOBAL(vmode_g->slength));
336 SET_BDA(crtc_address, stdvga_get_crtc());
337 SET_BDA(video_rows, GET_GLOBAL(vmode_g->theight)-1);
338 SET_BDA(char_height, cheight);
339 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
340 SET_BDA(video_switches, 0xF9);
341 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
342 SET_BDA(cursor_type, GET_GLOBAL(vmode_g->memmodel) & TEXT ? 0x0607 : 0x0000);
345 SET_BDA(cursor_pos[i], 0x0000);
346 SET_BDA(video_pagestart, 0x0000);
347 SET_BDA(video_page, 0x00);
349 // FIXME We nearly have the good tables. to be reworked
350 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
351 SET_BDA(video_savetable
352 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
355 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
356 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
358 // Set the ints 0x1F and 0x43
359 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
363 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
366 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
369 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
375 /****************************************************************
377 ****************************************************************/
380 handle_1000(struct bregs *regs)
382 int mode = regs->al & 0x7f;
392 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
394 flags |= MF_NOCLEARMEM;
396 vgahw_set_mode(mode, flags);
400 handle_1001(struct bregs *regs)
402 set_cursor_shape(regs->ch, regs->cl);
406 handle_1002(struct bregs *regs)
408 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
413 handle_1003(struct bregs *regs)
415 regs->cx = get_cursor_shape(regs->bh);
416 struct cursorpos cp = get_cursor_pos(regs->bh);
421 // Read light pen pos (unimplemented)
423 handle_1004(struct bregs *regs)
426 regs->ax = regs->bx = regs->cx = regs->dx = 0;
430 handle_1005(struct bregs *regs)
432 set_active_page(regs->al);
436 verify_scroll(struct bregs *regs, int dir)
438 u8 page = GET_BDA(video_page);
439 struct cursorpos ul = {regs->cl, regs->ch, page};
440 struct cursorpos lr = {regs->dl, regs->dh, page};
442 u16 nbrows = GET_BDA(video_rows) + 1;
445 u16 nbcols = GET_BDA(video_cols);
449 if (ul.x > lr.x || ul.y > lr.y)
452 u16 nblines = regs->al;
453 if (!nblines || nblines > lr.y - ul.y + 1)
454 nblines = lr.y - ul.y + 1;
456 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
460 handle_1006(struct bregs *regs)
462 verify_scroll(regs, 1);
466 handle_1007(struct bregs *regs)
468 verify_scroll(regs, -1);
472 handle_1008(struct bregs *regs)
474 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
480 write_chars(u8 page, struct carattr ca, u16 count)
482 struct cursorpos cp = get_cursor_pos(page);
484 vgafb_write_char(cp, ca);
490 handle_1009(struct bregs *regs)
492 struct carattr ca = {regs->al, regs->bl, 1};
493 write_chars(regs->bh, ca, regs->cx);
497 handle_100a(struct bregs *regs)
499 struct carattr ca = {regs->al, regs->bl, 0};
500 write_chars(regs->bh, ca, regs->cx);
505 handle_100b00(struct bregs *regs)
507 stdvga_set_border_color(regs->bl);
511 handle_100b01(struct bregs *regs)
513 stdvga_set_palette(regs->bl);
517 handle_100bXX(struct bregs *regs)
523 handle_100b(struct bregs *regs)
526 case 0x00: handle_100b00(regs); break;
527 case 0x01: handle_100b01(regs); break;
528 default: handle_100bXX(regs); break;
534 handle_100c(struct bregs *regs)
536 // XXX - page (regs->bh) is unused
537 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
541 handle_100d(struct bregs *regs)
543 // XXX - page (regs->bh) is unused
544 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
548 handle_100e(struct bregs *regs)
550 // Ralf Brown Interrupt list is WRONG on bh(page)
551 // We do output only on the current page !
552 struct carattr ca = {regs->al, regs->bl, 0};
553 struct cursorpos cp = get_cursor_pos(0xff);
554 write_teletype(&cp, ca);
559 handle_100f(struct bregs *regs)
561 regs->bh = GET_BDA(video_page);
562 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
563 regs->ah = GET_BDA(video_cols);
568 handle_101000(struct bregs *regs)
572 stdvga_set_single_palette_reg(regs->bl, regs->bh);
576 handle_101001(struct bregs *regs)
578 stdvga_set_overscan_border_color(regs->bh);
582 handle_101002(struct bregs *regs)
584 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
588 handle_101003(struct bregs *regs)
590 stdvga_toggle_intensity(regs->bl);
594 handle_101007(struct bregs *regs)
598 regs->bh = stdvga_get_single_palette_reg(regs->bl);
602 handle_101008(struct bregs *regs)
604 regs->bh = stdvga_get_overscan_border_color();
608 handle_101009(struct bregs *regs)
610 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
614 handle_101010(struct bregs *regs)
616 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
617 stdvga_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
621 handle_101012(struct bregs *regs)
623 stdvga_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
627 handle_101013(struct bregs *regs)
629 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
633 handle_101015(struct bregs *regs)
636 stdvga_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
643 handle_101017(struct bregs *regs)
645 stdvga_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
649 handle_101018(struct bregs *regs)
651 stdvga_set_pel_mask(regs->bl);
655 handle_101019(struct bregs *regs)
657 regs->bl = stdvga_get_pel_mask();
661 handle_10101a(struct bregs *regs)
663 stdvga_read_video_dac_state(®s->bl, ®s->bh);
667 handle_10101b(struct bregs *regs)
669 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
673 handle_1010XX(struct bregs *regs)
679 handle_1010(struct bregs *regs)
682 case 0x00: handle_101000(regs); break;
683 case 0x01: handle_101001(regs); break;
684 case 0x02: handle_101002(regs); break;
685 case 0x03: handle_101003(regs); break;
686 case 0x07: handle_101007(regs); break;
687 case 0x08: handle_101008(regs); break;
688 case 0x09: handle_101009(regs); break;
689 case 0x10: handle_101010(regs); break;
690 case 0x12: handle_101012(regs); break;
691 case 0x13: handle_101013(regs); break;
692 case 0x15: handle_101015(regs); break;
693 case 0x17: handle_101017(regs); break;
694 case 0x18: handle_101018(regs); break;
695 case 0x19: handle_101019(regs); break;
696 case 0x1a: handle_10101a(regs); break;
697 case 0x1b: handle_10101b(regs); break;
698 default: handle_1010XX(regs); break;
704 handle_101100(struct bregs *regs)
706 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
707 , regs->dx, regs->bl, regs->bh);
711 handle_101101(struct bregs *regs)
713 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
717 handle_101102(struct bregs *regs)
719 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
723 handle_101103(struct bregs *regs)
725 stdvga_set_text_block_specifier(regs->bl);
729 handle_101104(struct bregs *regs)
731 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
735 handle_101110(struct bregs *regs)
737 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
738 , regs->dx, regs->bl, regs->bh);
739 set_scan_lines(regs->bh);
743 handle_101111(struct bregs *regs)
745 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
750 handle_101112(struct bregs *regs)
752 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
757 handle_101114(struct bregs *regs)
759 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
764 handle_101130(struct bregs *regs)
768 struct segoff_s so = GET_IVT(0x1f);
770 regs->bp = so.offset;
774 struct segoff_s so = GET_IVT(0x43);
776 regs->bp = so.offset;
780 regs->es = get_global_seg();
781 regs->bp = (u32)vgafont14;
784 regs->es = get_global_seg();
785 regs->bp = (u32)vgafont8;
788 regs->es = get_global_seg();
789 regs->bp = (u32)vgafont8 + 128 * 8;
792 regs->es = get_global_seg();
793 regs->bp = (u32)vgafont14alt;
796 regs->es = get_global_seg();
797 regs->bp = (u32)vgafont16;
800 regs->es = get_global_seg();
801 regs->bp = (u32)vgafont16alt;
804 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
807 // Set byte/char of on screen font
808 regs->cx = GET_BDA(char_height) & 0xff;
810 // Set Highest char row
811 regs->dx = GET_BDA(video_rows);
815 handle_1011XX(struct bregs *regs)
821 handle_1011(struct bregs *regs)
824 case 0x00: handle_101100(regs); break;
825 case 0x01: handle_101101(regs); break;
826 case 0x02: handle_101102(regs); break;
827 case 0x03: handle_101103(regs); break;
828 case 0x04: handle_101104(regs); break;
829 case 0x10: handle_101110(regs); break;
830 case 0x11: handle_101111(regs); break;
831 case 0x12: handle_101112(regs); break;
832 case 0x14: handle_101114(regs); break;
833 case 0x30: handle_101130(regs); break;
834 default: handle_1011XX(regs); break;
840 handle_101210(struct bregs *regs)
842 u16 crtc_addr = GET_BDA(crtc_address);
843 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
847 regs->cx = GET_BDA(video_switches) & 0x0f;
851 handle_101230(struct bregs *regs)
853 u8 mctl = GET_BDA(modeset_ctl);
854 u8 vswt = GET_BDA(video_switches);
858 mctl = (mctl & ~0x10) | 0x80;
859 vswt = (vswt & ~0x0f) | 0x08;
864 vswt = (vswt & ~0x0f) | 0x09;
868 mctl = (mctl & ~0x80) | 0x10;
869 vswt = (vswt & ~0x0f) | 0x09;
872 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
875 SET_BDA(modeset_ctl, mctl);
876 SET_BDA(video_switches, vswt);
881 handle_101231(struct bregs *regs)
883 u8 v = (regs->al & 0x01) << 3;
884 u8 mctl = GET_BDA(video_ctl) & ~0x08;
885 SET_BDA(video_ctl, mctl | v);
890 handle_101232(struct bregs *regs)
892 stdvga_enable_video_addressing(regs->al);
897 handle_101233(struct bregs *regs)
899 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
900 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
901 SET_BDA(modeset_ctl, v | v2);
906 handle_101234(struct bregs *regs)
908 u8 v = (regs->al & 0x01) ^ 0x01;
909 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
910 SET_BDA(modeset_ctl, v | v2);
915 handle_101235(struct bregs *regs)
922 handle_101236(struct bregs *regs)
929 handle_1012XX(struct bregs *regs)
935 handle_1012(struct bregs *regs)
938 case 0x10: handle_101210(regs); break;
939 case 0x30: handle_101230(regs); break;
940 case 0x31: handle_101231(regs); break;
941 case 0x32: handle_101232(regs); break;
942 case 0x33: handle_101233(regs); break;
943 case 0x34: handle_101234(regs); break;
944 case 0x35: handle_101235(regs); break;
945 case 0x36: handle_101236(regs); break;
946 default: handle_1012XX(regs); break;
949 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
955 handle_1013(struct bregs *regs)
957 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
958 // if row=0xff special case : use current cursor position
960 cp = get_cursor_pos(cp.page);
963 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
965 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
973 handle_101a00(struct bregs *regs)
975 regs->bx = GET_BDA(dcc_index);
980 handle_101a01(struct bregs *regs)
982 SET_BDA(dcc_index, regs->bl);
983 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
988 handle_101aXX(struct bregs *regs)
994 handle_101a(struct bregs *regs)
997 case 0x00: handle_101a00(regs); break;
998 case 0x01: handle_101a01(regs); break;
999 default: handle_101aXX(regs); break;
1005 struct segoff_s static_functionality;
1025 handle_101b(struct bregs *regs)
1028 struct funcInfo *info = (void*)(regs->di+0);
1029 memset_far(seg, info, 0, sizeof(*info));
1030 // Address of static functionality table
1031 SET_FARVAR(seg, info->static_functionality
1032 , SEGOFF(get_global_seg(), (u32)static_functionality));
1034 // Hard coded copy from BIOS area. Should it be cleaner ?
1035 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1036 , sizeof(info->bda_0x49));
1037 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1038 , sizeof(info->bda_0x84));
1040 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1041 SET_FARVAR(seg, info->colors, 16);
1042 SET_FARVAR(seg, info->pages, 8);
1043 SET_FARVAR(seg, info->scan_lines, 2);
1044 SET_FARVAR(seg, info->video_mem, 3);
1050 handle_101c00(struct bregs *regs)
1052 u16 flags = regs->cx;
1055 size += sizeof(struct saveVideoHardware);
1057 size += sizeof(struct saveBDAstate);
1059 size += sizeof(struct saveDACcolors);
1065 handle_101c01(struct bregs *regs)
1067 u16 flags = regs->cx;
1069 void *data = (void*)(regs->bx+0);
1071 stdvga_save_state(seg, data);
1072 data += sizeof(struct saveVideoHardware);
1075 save_bda_state(seg, data);
1076 data += sizeof(struct saveBDAstate);
1079 stdvga_save_dac_state(seg, data);
1084 handle_101c02(struct bregs *regs)
1086 u16 flags = regs->cx;
1088 void *data = (void*)(regs->bx+0);
1090 stdvga_restore_state(seg, data);
1091 data += sizeof(struct saveVideoHardware);
1094 restore_bda_state(seg, data);
1095 data += sizeof(struct saveBDAstate);
1098 stdvga_restore_dac_state(seg, data);
1103 handle_101cXX(struct bregs *regs)
1109 handle_101c(struct bregs *regs)
1112 case 0x00: handle_101c00(regs); break;
1113 case 0x01: handle_101c01(regs); break;
1114 case 0x02: handle_101c02(regs); break;
1115 default: handle_101cXX(regs); break;
1120 handle_10XX(struct bregs *regs)
1125 // INT 10h Video Support Service Entry Point
1127 handle_10(struct bregs *regs)
1129 debug_enter(regs, DEBUG_VGA_10);
1131 case 0x00: handle_1000(regs); break;
1132 case 0x01: handle_1001(regs); break;
1133 case 0x02: handle_1002(regs); break;
1134 case 0x03: handle_1003(regs); break;
1135 case 0x04: handle_1004(regs); break;
1136 case 0x05: handle_1005(regs); break;
1137 case 0x06: handle_1006(regs); break;
1138 case 0x07: handle_1007(regs); break;
1139 case 0x08: handle_1008(regs); break;
1140 case 0x09: handle_1009(regs); break;
1141 case 0x0a: handle_100a(regs); break;
1142 case 0x0b: handle_100b(regs); break;
1143 case 0x0c: handle_100c(regs); break;
1144 case 0x0d: handle_100d(regs); break;
1145 case 0x0e: handle_100e(regs); break;
1146 case 0x0f: handle_100f(regs); break;
1147 case 0x10: handle_1010(regs); break;
1148 case 0x11: handle_1011(regs); break;
1149 case 0x12: handle_1012(regs); break;
1150 case 0x13: handle_1013(regs); break;
1151 case 0x1a: handle_101a(regs); break;
1152 case 0x1b: handle_101b(regs); break;
1153 case 0x1c: handle_101c(regs); break;
1154 case 0x4f: handle_104f(regs); break;
1155 default: handle_10XX(regs); break;
1160 /****************************************************************
1162 ****************************************************************/
1165 init_bios_area(void)
1167 // init detected hardware BIOS Area
1168 // set 80x25 color (not clear from RBIL but usual)
1169 u16 eqf = GET_BDA(equipment_list_flags);
1170 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1172 // Just for the first int10 find its children
1174 // the default char height
1175 SET_BDA(char_height, 0x10);
1178 SET_BDA(video_ctl, 0x60);
1180 // Set the basic screen we have
1181 SET_BDA(video_switches, 0xf9);
1183 // Set the basic modeset options
1184 SET_BDA(modeset_ctl, 0x51);
1186 // Set the default MSR
1187 SET_BDA(video_msr, 0x09);
1193 vga_post(struct bregs *regs)
1195 debug_enter(regs, DEBUG_VGA_POST);
1197 SET_VGA(VgaBDF, regs->ax);
1199 int ret = vgahw_init();
1201 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1207 build_video_param();
1209 extern void entry_10(void);
1210 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1212 // XXX - clear screen and display info
1215 extern u8 _rom_header_size, _rom_header_checksum;
1216 SET_VGA(_rom_header_checksum, 0);
1217 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1218 SET_VGA(_rom_header_checksum, sum);