1 // VGA bios implementation
3 // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2001-2008 the LGPL VGABios developers Team
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
10 // * review correctness of converted asm by comparing with RBIL
12 // * convert vbe/clext code
14 #include "bregs.h" // struct bregs
15 #include "biosvar.h" // GET_BDA
16 #include "util.h" // memset
17 #include "vgabios.h" // calc_page_size
18 #include "optionroms.h" // struct pci_data
19 #include "config.h" // CONFIG_*
20 #include "stdvga.h" // stdvga_set_cursor_shape
21 #include "clext.h" // clext_1012
22 #include "vgahw.h" // vgahw_set_mode
23 #include "vbe.h" // VBE_RETURN_STATUS_FAILED
24 #include "pci.h" // pci_config_readw
25 #include "pci_regs.h" // PCI_VENDOR_ID
28 #define DEBUG_VGA_POST 1
29 #define DEBUG_VGA_10 3
31 // Standard Video Save Pointer Table
32 struct VideoSavePointer_s {
33 struct segoff_s videoparam;
34 struct segoff_s paramdynamicsave;
35 struct segoff_s textcharset;
36 struct segoff_s graphcharset;
37 struct segoff_s secsavepointer;
41 static struct VideoSavePointer_s video_save_pointer_table VAR16;
43 struct VideoParam_s video_param_table[29] VAR16;
46 /****************************************************************
48 ****************************************************************/
49 #if CONFIG_VGA_PCI == 1
50 struct pci_data rom_pci_data VAR16VISIBLE = {
51 .signature = PCI_ROM_SIGNATURE,
52 .vendor = CONFIG_VGA_VID,
53 .device = CONFIG_VGA_DID,
57 .type = PCIROM_CODETYPE_X86,
62 /****************************************************************
64 ****************************************************************/
67 calc_page_size(u8 memmodel, u16 width, u16 height)
71 return ALIGN(width * height * 2, 2*1024);
75 return ALIGN(width * height / 8, 8*1024);
80 set_cursor_shape(u8 start, u8 end)
85 u16 curs = (start << 8) + end;
86 SET_BDA(cursor_type, curs);
88 u8 modeset_ctl = GET_BDA(modeset_ctl);
89 u16 cheight = GET_BDA(char_height);
90 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
91 if (end != (start + 1))
92 start = ((start + 1) * cheight / 8) - 1;
94 start = ((end + 1) * cheight / 8) - 2;
95 end = ((end + 1) * cheight / 8) - 1;
97 stdvga_set_cursor_shape(start, end);
101 get_cursor_shape(u8 page)
105 // FIXME should handle VGA 14/16 lines
106 return GET_BDA(cursor_type);
110 set_cursor_pos(struct cursorpos cp)
112 // Should not happen...
117 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
119 // Set the hardware cursor
120 u8 current = GET_BDA(video_page);
121 if (cp.page != current)
124 // Calculate the memory address
125 u16 nbcols = GET_BDA(video_cols);
126 u16 address = (GET_BDA(video_pagesize) * cp.page
127 + (cp.x + cp.y * nbcols) * 2);
129 stdvga_set_cursor_pos(address / 2);
132 static struct cursorpos
133 get_cursor_pos(u8 page)
136 // special case - use current page
137 page = GET_BDA(video_page);
139 struct cursorpos cp = { 0, 0, 0xfe };
142 // FIXME should handle VGA 14/16 lines
143 u16 xy = GET_BDA(cursor_pos[page]);
144 struct cursorpos cp = {xy, xy>>8, page};
149 set_active_page(u8 page)
155 struct vgamode_s *vmode_g = get_current_mode();
159 // Get pos curs pos for the right page
160 struct cursorpos cp = get_cursor_pos(page);
162 // Calculate memory address of start of page
163 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
164 u16 address = GET_BDA(video_pagesize) * page;
165 stdvga_set_active_page(memmodel == MM_TEXT ? address / 2 : address);
167 // And change the BIOS page
168 SET_BDA(video_pagestart, address);
169 SET_BDA(video_page, page);
171 dprintf(1, "Set active page %02x address %04x\n", page, address);
173 // Display the cursor, now the page is active
178 set_scan_lines(u8 lines)
180 stdvga_set_scan_lines(lines);
182 set_cursor_shape(0x06, 0x07);
184 set_cursor_shape(lines - 4, lines - 3);
185 SET_BDA(char_height, lines);
186 u16 vde = stdvga_get_vde();
187 u8 rows = vde / lines;
188 SET_BDA(video_rows, rows - 1);
189 u16 cols = GET_BDA(video_cols);
190 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
194 /****************************************************************
196 ****************************************************************/
198 // Scroll the screen one line. This function is designed to be called
199 // tail-recursive to reduce stack usage.
201 scroll_one(u16 nbrows, u16 nbcols, u8 page)
203 struct cursorpos ul = {0, 0, page};
204 struct cursorpos lr = {nbcols-1, nbrows-1, page};
205 vgafb_scroll(1, -1, ul, lr);
208 // Write a character to the screen at a given position. Implement
209 // special characters and scroll the screen if necessary.
211 write_teletype(struct cursorpos *pcp, struct carattr ca)
213 struct cursorpos cp = *pcp;
215 // Get the dimensions
216 u16 nbrows = GET_BDA(video_rows) + 1;
217 u16 nbcols = GET_BDA(video_cols);
235 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
236 vgafb_write_char(cp, dummyca);
238 } while (cp.x < nbcols && cp.x % 8);
241 vgafb_write_char(cp, ca);
245 // Do we need to wrap ?
246 if (cp.x == nbcols) {
250 // Do we need to scroll ?
258 scroll_one(nbrows, nbcols, cp.page);
261 // Write out a buffer of alternating characters and attributes.
263 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
266 u8 car = GET_FARVAR(seg, *offset_far);
268 u8 attr = GET_FARVAR(seg, *offset_far);
271 struct carattr ca = {car, attr, 1};
272 write_teletype(pcp, ca);
276 // Write out a buffer of characters.
278 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
281 u8 car = GET_FARVAR(seg, *offset_far);
284 struct carattr ca = {car, attr, 1};
285 write_teletype(pcp, ca);
290 /****************************************************************
291 * Save and restore bda state
292 ****************************************************************/
295 save_bda_state(u16 seg, struct saveBDAstate *info)
297 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
298 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
299 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
300 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
301 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
302 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
303 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
304 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
305 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
306 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
309 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
310 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
311 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
313 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
314 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
318 restore_bda_state(u16 seg, struct saveBDAstate *info)
320 u16 mode = GET_FARVAR(seg, info->video_mode);
321 SET_BDA(video_mode, mode);
322 SET_BDA(vbe_mode, mode);
323 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
324 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
325 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
326 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
327 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
328 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
329 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
330 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
331 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
333 for (i = 0; i < 8; i++)
334 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
335 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
336 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
338 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
339 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
343 /****************************************************************
345 ****************************************************************/
348 get_current_mode(void)
350 return vgahw_find_mode(GET_BDA(vbe_mode) & ~MF_VBEFLAGS);
353 // Setup BDA after a mode switch.
355 vga_set_mode(int mode, int flags)
357 dprintf(1, "set VGA mode %x\n", mode);
358 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
360 return VBE_RETURN_STATUS_FAILED;
362 int ret = vgahw_set_mode(vmode_g, flags);
367 int width = GET_GLOBAL(vmode_g->width);
368 int height = GET_GLOBAL(vmode_g->height);
369 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
370 int cheight = GET_GLOBAL(vmode_g->cheight);
372 SET_BDA(video_mode, mode);
374 SET_BDA(video_mode, 0xff);
375 SET_BDA(vbe_mode, mode | (flags & MF_VBEFLAGS));
376 if (memmodel == MM_TEXT) {
377 SET_BDA(video_cols, width);
378 SET_BDA(video_rows, height-1);
379 SET_BDA(cursor_type, 0x0607);
381 int cwidth = GET_GLOBAL(vmode_g->cwidth);
382 SET_BDA(video_cols, width / cwidth);
383 SET_BDA(video_rows, (height / cheight) - 1);
384 SET_BDA(cursor_type, 0x0000);
386 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
387 SET_BDA(crtc_address, stdvga_get_crtc());
388 SET_BDA(char_height, cheight);
389 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
390 SET_BDA(video_switches, 0xF9);
391 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
394 SET_BDA(cursor_pos[i], 0x0000);
395 SET_BDA(video_pagestart, 0x0000);
396 SET_BDA(video_page, 0x00);
398 // FIXME We nearly have the good tables. to be reworked
399 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
400 SET_BDA(video_savetable
401 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
404 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
405 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
407 // Set the ints 0x1F and 0x43
408 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
412 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
415 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
418 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
426 /****************************************************************
428 ****************************************************************/
431 handle_1000(struct bregs *regs)
433 int mode = regs->al & 0x7f;
443 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
445 flags |= MF_NOCLEARMEM;
447 vga_set_mode(mode, flags);
451 handle_1001(struct bregs *regs)
453 set_cursor_shape(regs->ch, regs->cl);
457 handle_1002(struct bregs *regs)
459 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
464 handle_1003(struct bregs *regs)
466 regs->cx = get_cursor_shape(regs->bh);
467 struct cursorpos cp = get_cursor_pos(regs->bh);
472 // Read light pen pos (unimplemented)
474 handle_1004(struct bregs *regs)
477 regs->ax = regs->bx = regs->cx = regs->dx = 0;
481 handle_1005(struct bregs *regs)
483 set_active_page(regs->al);
487 verify_scroll(struct bregs *regs, int dir)
489 u8 page = GET_BDA(video_page);
490 struct cursorpos ul = {regs->cl, regs->ch, page};
491 struct cursorpos lr = {regs->dl, regs->dh, page};
493 u16 nbrows = GET_BDA(video_rows) + 1;
496 u16 nbcols = GET_BDA(video_cols);
500 if (ul.x > lr.x || ul.y > lr.y)
503 u16 nblines = regs->al;
504 if (!nblines || nblines > lr.y - ul.y + 1)
505 nblines = lr.y - ul.y + 1;
507 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
511 handle_1006(struct bregs *regs)
513 verify_scroll(regs, 1);
517 handle_1007(struct bregs *regs)
519 verify_scroll(regs, -1);
523 handle_1008(struct bregs *regs)
525 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
531 write_chars(u8 page, struct carattr ca, u16 count)
533 struct cursorpos cp = get_cursor_pos(page);
535 vgafb_write_char(cp, ca);
541 handle_1009(struct bregs *regs)
543 struct carattr ca = {regs->al, regs->bl, 1};
544 write_chars(regs->bh, ca, regs->cx);
548 handle_100a(struct bregs *regs)
550 struct carattr ca = {regs->al, regs->bl, 0};
551 write_chars(regs->bh, ca, regs->cx);
556 handle_100b00(struct bregs *regs)
558 stdvga_set_border_color(regs->bl);
562 handle_100b01(struct bregs *regs)
564 stdvga_set_palette(regs->bl);
568 handle_100bXX(struct bregs *regs)
574 handle_100b(struct bregs *regs)
577 case 0x00: handle_100b00(regs); break;
578 case 0x01: handle_100b01(regs); break;
579 default: handle_100bXX(regs); break;
585 handle_100c(struct bregs *regs)
587 // XXX - page (regs->bh) is unused
588 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
592 handle_100d(struct bregs *regs)
594 // XXX - page (regs->bh) is unused
595 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
599 handle_100e(struct bregs *regs)
601 // Ralf Brown Interrupt list is WRONG on bh(page)
602 // We do output only on the current page !
603 struct carattr ca = {regs->al, regs->bl, 0};
604 struct cursorpos cp = get_cursor_pos(0xff);
605 write_teletype(&cp, ca);
610 handle_100f(struct bregs *regs)
612 regs->bh = GET_BDA(video_page);
613 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
614 regs->ah = GET_BDA(video_cols);
619 handle_101000(struct bregs *regs)
623 stdvga_attr_write(regs->bl, regs->bh);
627 handle_101001(struct bregs *regs)
629 stdvga_set_overscan_border_color(regs->bh);
633 handle_101002(struct bregs *regs)
635 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
639 handle_101003(struct bregs *regs)
641 stdvga_toggle_intensity(regs->bl);
645 handle_101007(struct bregs *regs)
649 regs->bh = stdvga_attr_read(regs->bl);
653 handle_101008(struct bregs *regs)
655 regs->bh = stdvga_get_overscan_border_color();
659 handle_101009(struct bregs *regs)
661 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
665 handle_101010(struct bregs *regs)
667 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
668 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
672 handle_101012(struct bregs *regs)
674 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
678 handle_101013(struct bregs *regs)
680 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
684 handle_101015(struct bregs *regs)
687 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
694 handle_101017(struct bregs *regs)
696 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
700 handle_101018(struct bregs *regs)
702 stdvga_pelmask_write(regs->bl);
706 handle_101019(struct bregs *regs)
708 regs->bl = stdvga_pelmask_read();
712 handle_10101a(struct bregs *regs)
714 stdvga_read_video_dac_state(®s->bl, ®s->bh);
718 handle_10101b(struct bregs *regs)
720 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
724 handle_1010XX(struct bregs *regs)
730 handle_1010(struct bregs *regs)
733 case 0x00: handle_101000(regs); break;
734 case 0x01: handle_101001(regs); break;
735 case 0x02: handle_101002(regs); break;
736 case 0x03: handle_101003(regs); break;
737 case 0x07: handle_101007(regs); break;
738 case 0x08: handle_101008(regs); break;
739 case 0x09: handle_101009(regs); break;
740 case 0x10: handle_101010(regs); break;
741 case 0x12: handle_101012(regs); break;
742 case 0x13: handle_101013(regs); break;
743 case 0x15: handle_101015(regs); break;
744 case 0x17: handle_101017(regs); break;
745 case 0x18: handle_101018(regs); break;
746 case 0x19: handle_101019(regs); break;
747 case 0x1a: handle_10101a(regs); break;
748 case 0x1b: handle_10101b(regs); break;
749 default: handle_1010XX(regs); break;
755 handle_101100(struct bregs *regs)
757 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
758 , regs->dx, regs->bl, regs->bh);
762 handle_101101(struct bregs *regs)
764 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
768 handle_101102(struct bregs *regs)
770 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
774 handle_101103(struct bregs *regs)
776 stdvga_set_text_block_specifier(regs->bl);
780 handle_101104(struct bregs *regs)
782 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
786 handle_101110(struct bregs *regs)
788 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
789 , regs->dx, regs->bl, regs->bh);
790 set_scan_lines(regs->bh);
794 handle_101111(struct bregs *regs)
796 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
801 handle_101112(struct bregs *regs)
803 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
808 handle_101114(struct bregs *regs)
810 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
815 handle_101130(struct bregs *regs)
819 struct segoff_s so = GET_IVT(0x1f);
821 regs->bp = so.offset;
825 struct segoff_s so = GET_IVT(0x43);
827 regs->bp = so.offset;
831 regs->es = get_global_seg();
832 regs->bp = (u32)vgafont14;
835 regs->es = get_global_seg();
836 regs->bp = (u32)vgafont8;
839 regs->es = get_global_seg();
840 regs->bp = (u32)vgafont8 + 128 * 8;
843 regs->es = get_global_seg();
844 regs->bp = (u32)vgafont14alt;
847 regs->es = get_global_seg();
848 regs->bp = (u32)vgafont16;
851 regs->es = get_global_seg();
852 regs->bp = (u32)vgafont16alt;
855 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
858 // Set byte/char of on screen font
859 regs->cx = GET_BDA(char_height) & 0xff;
861 // Set Highest char row
862 regs->dx = GET_BDA(video_rows);
866 handle_1011XX(struct bregs *regs)
872 handle_1011(struct bregs *regs)
875 case 0x00: handle_101100(regs); break;
876 case 0x01: handle_101101(regs); break;
877 case 0x02: handle_101102(regs); break;
878 case 0x03: handle_101103(regs); break;
879 case 0x04: handle_101104(regs); break;
880 case 0x10: handle_101110(regs); break;
881 case 0x11: handle_101111(regs); break;
882 case 0x12: handle_101112(regs); break;
883 case 0x14: handle_101114(regs); break;
884 case 0x30: handle_101130(regs); break;
885 default: handle_1011XX(regs); break;
891 handle_101210(struct bregs *regs)
893 u16 crtc_addr = GET_BDA(crtc_address);
894 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
898 regs->cx = GET_BDA(video_switches) & 0x0f;
902 handle_101230(struct bregs *regs)
904 u8 mctl = GET_BDA(modeset_ctl);
905 u8 vswt = GET_BDA(video_switches);
909 mctl = (mctl & ~0x10) | 0x80;
910 vswt = (vswt & ~0x0f) | 0x08;
915 vswt = (vswt & ~0x0f) | 0x09;
919 mctl = (mctl & ~0x80) | 0x10;
920 vswt = (vswt & ~0x0f) | 0x09;
923 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
926 SET_BDA(modeset_ctl, mctl);
927 SET_BDA(video_switches, vswt);
932 handle_101231(struct bregs *regs)
934 u8 v = (regs->al & 0x01) << 3;
935 u8 mctl = GET_BDA(video_ctl) & ~0x08;
936 SET_BDA(video_ctl, mctl | v);
941 handle_101232(struct bregs *regs)
943 stdvga_enable_video_addressing(regs->al);
948 handle_101233(struct bregs *regs)
950 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
951 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
952 SET_BDA(modeset_ctl, v | v2);
957 handle_101234(struct bregs *regs)
959 u8 v = (regs->al & 0x01) ^ 0x01;
960 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
961 SET_BDA(modeset_ctl, v | v2);
966 handle_101235(struct bregs *regs)
973 handle_101236(struct bregs *regs)
980 handle_1012XX(struct bregs *regs)
986 handle_1012(struct bregs *regs)
988 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
994 case 0x10: handle_101210(regs); break;
995 case 0x30: handle_101230(regs); break;
996 case 0x31: handle_101231(regs); break;
997 case 0x32: handle_101232(regs); break;
998 case 0x33: handle_101233(regs); break;
999 case 0x34: handle_101234(regs); break;
1000 case 0x35: handle_101235(regs); break;
1001 case 0x36: handle_101236(regs); break;
1002 default: handle_1012XX(regs); break;
1008 static void noinline
1009 handle_1013(struct bregs *regs)
1011 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1012 // if row=0xff special case : use current cursor position
1014 cp = get_cursor_pos(cp.page);
1017 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1019 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1027 handle_101a00(struct bregs *regs)
1029 regs->bx = GET_BDA(dcc_index);
1034 handle_101a01(struct bregs *regs)
1036 SET_BDA(dcc_index, regs->bl);
1037 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1042 handle_101aXX(struct bregs *regs)
1048 handle_101a(struct bregs *regs)
1051 case 0x00: handle_101a00(regs); break;
1052 case 0x01: handle_101a01(regs); break;
1053 default: handle_101aXX(regs); break;
1058 static u8 static_functionality[0x10] VAR16 = {
1059 /* 0 */ 0xff, // All modes supported #1
1060 /* 1 */ 0xe0, // All modes supported #2
1061 /* 2 */ 0x0f, // All modes supported #3
1062 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1063 /* 7 */ 0x07, // 200, 350, 400 scan lines
1064 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1065 /* 9 */ 0x08, // total number of charset blocks in text mode
1066 /* a */ 0xe7, // Change to add new functions
1067 /* b */ 0x0c, // Change to add new functions
1068 /* c */ 0x00, // reserved
1069 /* d */ 0x00, // reserved
1070 /* e */ 0x00, // Change to add new functions
1071 /* f */ 0x00 // reserved
1075 struct segoff_s static_functionality;
1095 handle_101b(struct bregs *regs)
1098 struct funcInfo *info = (void*)(regs->di+0);
1099 memset_far(seg, info, 0, sizeof(*info));
1100 // Address of static functionality table
1101 SET_FARVAR(seg, info->static_functionality
1102 , SEGOFF(get_global_seg(), (u32)static_functionality));
1104 // Hard coded copy from BIOS area. Should it be cleaner ?
1105 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1106 , sizeof(info->bda_0x49));
1107 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1108 , sizeof(info->bda_0x84));
1110 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1111 SET_FARVAR(seg, info->colors, 16);
1112 SET_FARVAR(seg, info->pages, 8);
1113 SET_FARVAR(seg, info->scan_lines, 2);
1114 SET_FARVAR(seg, info->video_mem, 3);
1120 handle_101c00(struct bregs *regs)
1122 u16 flags = regs->cx;
1125 size += sizeof(struct saveVideoHardware);
1127 size += sizeof(struct saveBDAstate);
1129 size += sizeof(struct saveDACcolors);
1135 handle_101c01(struct bregs *regs)
1137 u16 flags = regs->cx;
1139 void *data = (void*)(regs->bx+0);
1141 stdvga_save_state(seg, data);
1142 data += sizeof(struct saveVideoHardware);
1145 save_bda_state(seg, data);
1146 data += sizeof(struct saveBDAstate);
1149 stdvga_save_dac_state(seg, data);
1154 handle_101c02(struct bregs *regs)
1156 u16 flags = regs->cx;
1158 void *data = (void*)(regs->bx+0);
1160 stdvga_restore_state(seg, data);
1161 data += sizeof(struct saveVideoHardware);
1164 restore_bda_state(seg, data);
1165 data += sizeof(struct saveBDAstate);
1168 stdvga_restore_dac_state(seg, data);
1173 handle_101cXX(struct bregs *regs)
1179 handle_101c(struct bregs *regs)
1182 case 0x00: handle_101c00(regs); break;
1183 case 0x01: handle_101c01(regs); break;
1184 case 0x02: handle_101c02(regs); break;
1185 default: handle_101cXX(regs); break;
1190 handle_10XX(struct bregs *regs)
1195 // INT 10h Video Support Service Entry Point
1197 handle_10(struct bregs *regs)
1199 debug_enter(regs, DEBUG_VGA_10);
1201 case 0x00: handle_1000(regs); break;
1202 case 0x01: handle_1001(regs); break;
1203 case 0x02: handle_1002(regs); break;
1204 case 0x03: handle_1003(regs); break;
1205 case 0x04: handle_1004(regs); break;
1206 case 0x05: handle_1005(regs); break;
1207 case 0x06: handle_1006(regs); break;
1208 case 0x07: handle_1007(regs); break;
1209 case 0x08: handle_1008(regs); break;
1210 case 0x09: handle_1009(regs); break;
1211 case 0x0a: handle_100a(regs); break;
1212 case 0x0b: handle_100b(regs); break;
1213 case 0x0c: handle_100c(regs); break;
1214 case 0x0d: handle_100d(regs); break;
1215 case 0x0e: handle_100e(regs); break;
1216 case 0x0f: handle_100f(regs); break;
1217 case 0x10: handle_1010(regs); break;
1218 case 0x11: handle_1011(regs); break;
1219 case 0x12: handle_1012(regs); break;
1220 case 0x13: handle_1013(regs); break;
1221 case 0x1a: handle_101a(regs); break;
1222 case 0x1b: handle_101b(regs); break;
1223 case 0x1c: handle_101c(regs); break;
1224 case 0x4f: handle_104f(regs); break;
1225 default: handle_10XX(regs); break;
1230 /****************************************************************
1232 ****************************************************************/
1235 init_bios_area(void)
1237 // init detected hardware BIOS Area
1238 // set 80x25 color (not clear from RBIL but usual)
1239 u16 eqf = GET_BDA(equipment_list_flags);
1240 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1242 // Just for the first int10 find its children
1244 // the default char height
1245 SET_BDA(char_height, 0x10);
1248 SET_BDA(video_ctl, 0x60);
1250 // Set the basic screen we have
1251 SET_BDA(video_switches, 0xf9);
1253 // Set the basic modeset options
1254 SET_BDA(modeset_ctl, 0x51);
1256 // Set the default MSR
1257 SET_BDA(video_msr, 0x09);
1260 int VgaBDF VAR16 = -1;
1263 vga_post(struct bregs *regs)
1265 debug_enter(regs, DEBUG_VGA_POST);
1267 if (CONFIG_VGA_PCI) {
1269 if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
1270 && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
1271 SET_VGA(VgaBDF, bdf);
1274 int ret = vgahw_init();
1276 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1282 SET_VGA(video_save_pointer_table.videoparam
1283 , SEGOFF(get_global_seg(), (u32)video_param_table));
1284 stdvga_build_video_param();
1286 extern void entry_10(void);
1287 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1289 // XXX - clear screen and display info
1292 extern u8 _rom_header_size, _rom_header_checksum;
1293 SET_VGA(_rom_header_checksum, 0);
1294 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1295 SET_VGA(_rom_header_checksum, sum);