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 ****************************************************************/
66 // Return the bits per pixel in system memory for a given mode.
68 vga_bpp(struct vgamode_s *vmode_g)
70 switch (GET_GLOBAL(vmode_g->memmodel)) {
76 u8 depth = GET_GLOBAL(vmode_g->depth);
78 return ALIGN(depth, 8);
83 calc_page_size(u8 memmodel, u16 width, u16 height)
87 return ALIGN(width * height * 2, 2*1024);
91 return ALIGN(width * height / 8, 8*1024);
96 set_cursor_shape(u8 start, u8 end)
101 u16 curs = (start << 8) + end;
102 SET_BDA(cursor_type, curs);
104 u8 modeset_ctl = GET_BDA(modeset_ctl);
105 u16 cheight = GET_BDA(char_height);
106 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
107 if (end != (start + 1))
108 start = ((start + 1) * cheight / 8) - 1;
110 start = ((end + 1) * cheight / 8) - 2;
111 end = ((end + 1) * cheight / 8) - 1;
113 stdvga_set_cursor_shape(start, end);
117 get_cursor_shape(u8 page)
121 // FIXME should handle VGA 14/16 lines
122 return GET_BDA(cursor_type);
126 set_cursor_pos(struct cursorpos cp)
128 // Should not happen...
133 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
135 // Set the hardware cursor
136 u8 current = GET_BDA(video_page);
137 if (cp.page != current)
140 // Calculate the memory address
141 int address = (GET_BDA(video_pagesize) * cp.page
142 + (cp.x + cp.y * GET_BDA(video_cols)) * 2);
143 stdvga_set_cursor_pos(address);
146 static struct cursorpos
147 get_cursor_pos(u8 page)
150 // special case - use current page
151 page = GET_BDA(video_page);
153 struct cursorpos cp = { 0, 0, 0xfe };
156 // FIXME should handle VGA 14/16 lines
157 u16 xy = GET_BDA(cursor_pos[page]);
158 struct cursorpos cp = {xy, xy>>8, page};
163 set_active_page(u8 page)
169 struct vgamode_s *vmode_g = get_current_mode();
173 // Get pos curs pos for the right page
174 struct cursorpos cp = get_cursor_pos(page);
176 // Calculate memory address of start of page
177 int address = GET_BDA(video_pagesize) * page;
178 vgahw_set_displaystart(vmode_g, address);
180 // And change the BIOS page
181 SET_BDA(video_pagestart, address);
182 SET_BDA(video_page, page);
184 dprintf(1, "Set active page %02x address %04x\n", page, address);
186 // Display the cursor, now the page is active
191 set_scan_lines(u8 lines)
193 stdvga_set_scan_lines(lines);
195 set_cursor_shape(0x06, 0x07);
197 set_cursor_shape(lines - 4, lines - 3);
198 SET_BDA(char_height, lines);
199 u16 vde = stdvga_get_vde();
200 u8 rows = vde / lines;
201 SET_BDA(video_rows, rows - 1);
202 u16 cols = GET_BDA(video_cols);
203 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
207 /****************************************************************
209 ****************************************************************/
211 // Scroll the screen one line. This function is designed to be called
212 // tail-recursive to reduce stack usage.
214 scroll_one(u16 nbrows, u16 nbcols, u8 page)
216 struct cursorpos ul = {0, 0, page};
217 struct cursorpos lr = {nbcols-1, nbrows-1, page};
218 vgafb_scroll(1, -1, ul, lr);
221 // Write a character to the screen at a given position. Implement
222 // special characters and scroll the screen if necessary.
224 write_teletype(struct cursorpos *pcp, struct carattr ca)
226 struct cursorpos cp = *pcp;
228 // Get the dimensions
229 u16 nbrows = GET_BDA(video_rows) + 1;
230 u16 nbcols = GET_BDA(video_cols);
248 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
249 vgafb_write_char(cp, dummyca);
251 } while (cp.x < nbcols && cp.x % 8);
254 vgafb_write_char(cp, ca);
258 // Do we need to wrap ?
259 if (cp.x == nbcols) {
263 // Do we need to scroll ?
271 scroll_one(nbrows, nbcols, cp.page);
274 // Write out a buffer of alternating characters and attributes.
276 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
279 u8 car = GET_FARVAR(seg, *offset_far);
281 u8 attr = GET_FARVAR(seg, *offset_far);
284 struct carattr ca = {car, attr, 1};
285 write_teletype(pcp, ca);
289 // Write out a buffer of characters.
291 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
294 u8 car = GET_FARVAR(seg, *offset_far);
297 struct carattr ca = {car, attr, 1};
298 write_teletype(pcp, ca);
303 /****************************************************************
304 * Save and restore bda state
305 ****************************************************************/
308 save_bda_state(u16 seg, struct saveBDAstate *info)
310 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
311 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
312 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
313 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
314 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
315 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
316 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
317 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
318 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
319 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
322 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
323 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
324 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
326 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
327 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
331 restore_bda_state(u16 seg, struct saveBDAstate *info)
333 u16 mode = GET_FARVAR(seg, info->video_mode);
334 SET_BDA(video_mode, mode);
335 SET_BDA(vbe_mode, mode);
336 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
337 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
338 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
339 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
340 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
341 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
342 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
343 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
344 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
346 for (i = 0; i < 8; i++)
347 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
348 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
349 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
351 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
352 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
356 /****************************************************************
358 ****************************************************************/
361 get_current_mode(void)
363 return vgahw_find_mode(GET_BDA(vbe_mode) & ~MF_VBEFLAGS);
366 // Setup BDA after a mode switch.
368 vga_set_mode(int mode, int flags)
370 dprintf(1, "set VGA mode %x\n", mode);
371 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
373 return VBE_RETURN_STATUS_FAILED;
375 int ret = vgahw_set_mode(vmode_g, flags);
380 int width = GET_GLOBAL(vmode_g->width);
381 int height = GET_GLOBAL(vmode_g->height);
382 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
383 int cheight = GET_GLOBAL(vmode_g->cheight);
385 SET_BDA(video_mode, mode);
387 SET_BDA(video_mode, 0xff);
388 SET_BDA(vbe_mode, mode | (flags & MF_VBEFLAGS));
389 if (memmodel == MM_TEXT) {
390 SET_BDA(video_cols, width);
391 SET_BDA(video_rows, height-1);
392 SET_BDA(cursor_type, 0x0607);
394 int cwidth = GET_GLOBAL(vmode_g->cwidth);
395 SET_BDA(video_cols, width / cwidth);
396 SET_BDA(video_rows, (height / cheight) - 1);
397 SET_BDA(cursor_type, 0x0000);
399 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
400 SET_BDA(crtc_address, stdvga_get_crtc());
401 SET_BDA(char_height, cheight);
402 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
403 SET_BDA(video_switches, 0xF9);
404 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
407 SET_BDA(cursor_pos[i], 0x0000);
408 SET_BDA(video_pagestart, 0x0000);
409 SET_BDA(video_page, 0x00);
411 // FIXME We nearly have the good tables. to be reworked
412 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
413 SET_BDA(video_savetable
414 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
417 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
418 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
420 // Set the ints 0x1F and 0x43
421 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
425 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
428 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
431 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
439 /****************************************************************
441 ****************************************************************/
444 handle_1000(struct bregs *regs)
446 int mode = regs->al & 0x7f;
456 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
458 flags |= MF_NOCLEARMEM;
460 vga_set_mode(mode, flags);
464 handle_1001(struct bregs *regs)
466 set_cursor_shape(regs->ch, regs->cl);
470 handle_1002(struct bregs *regs)
472 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
477 handle_1003(struct bregs *regs)
479 regs->cx = get_cursor_shape(regs->bh);
480 struct cursorpos cp = get_cursor_pos(regs->bh);
485 // Read light pen pos (unimplemented)
487 handle_1004(struct bregs *regs)
490 regs->ax = regs->bx = regs->cx = regs->dx = 0;
494 handle_1005(struct bregs *regs)
496 set_active_page(regs->al);
500 verify_scroll(struct bregs *regs, int dir)
502 u8 page = GET_BDA(video_page);
503 struct cursorpos ul = {regs->cl, regs->ch, page};
504 struct cursorpos lr = {regs->dl, regs->dh, page};
506 u16 nbrows = GET_BDA(video_rows) + 1;
509 u16 nbcols = GET_BDA(video_cols);
513 if (ul.x > lr.x || ul.y > lr.y)
516 u16 nblines = regs->al;
517 if (!nblines || nblines > lr.y - ul.y + 1)
518 nblines = lr.y - ul.y + 1;
520 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
524 handle_1006(struct bregs *regs)
526 verify_scroll(regs, 1);
530 handle_1007(struct bregs *regs)
532 verify_scroll(regs, -1);
536 handle_1008(struct bregs *regs)
538 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
544 write_chars(u8 page, struct carattr ca, u16 count)
546 struct cursorpos cp = get_cursor_pos(page);
548 vgafb_write_char(cp, ca);
554 handle_1009(struct bregs *regs)
556 struct carattr ca = {regs->al, regs->bl, 1};
557 write_chars(regs->bh, ca, regs->cx);
561 handle_100a(struct bregs *regs)
563 struct carattr ca = {regs->al, regs->bl, 0};
564 write_chars(regs->bh, ca, regs->cx);
569 handle_100b00(struct bregs *regs)
571 stdvga_set_border_color(regs->bl);
575 handle_100b01(struct bregs *regs)
577 stdvga_set_palette(regs->bl);
581 handle_100bXX(struct bregs *regs)
587 handle_100b(struct bregs *regs)
590 case 0x00: handle_100b00(regs); break;
591 case 0x01: handle_100b01(regs); break;
592 default: handle_100bXX(regs); break;
598 handle_100c(struct bregs *regs)
600 // XXX - page (regs->bh) is unused
601 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
605 handle_100d(struct bregs *regs)
607 // XXX - page (regs->bh) is unused
608 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
612 handle_100e(struct bregs *regs)
614 // Ralf Brown Interrupt list is WRONG on bh(page)
615 // We do output only on the current page !
616 struct carattr ca = {regs->al, regs->bl, 0};
617 struct cursorpos cp = get_cursor_pos(0xff);
618 write_teletype(&cp, ca);
623 handle_100f(struct bregs *regs)
625 regs->bh = GET_BDA(video_page);
626 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
627 regs->ah = GET_BDA(video_cols);
632 handle_101000(struct bregs *regs)
636 stdvga_attr_write(regs->bl, regs->bh);
640 handle_101001(struct bregs *regs)
642 stdvga_set_overscan_border_color(regs->bh);
646 handle_101002(struct bregs *regs)
648 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
652 handle_101003(struct bregs *regs)
654 stdvga_toggle_intensity(regs->bl);
658 handle_101007(struct bregs *regs)
662 regs->bh = stdvga_attr_read(regs->bl);
666 handle_101008(struct bregs *regs)
668 regs->bh = stdvga_get_overscan_border_color();
672 handle_101009(struct bregs *regs)
674 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
678 handle_101010(struct bregs *regs)
680 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
681 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
685 handle_101012(struct bregs *regs)
687 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
691 handle_101013(struct bregs *regs)
693 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
697 handle_101015(struct bregs *regs)
700 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
707 handle_101017(struct bregs *regs)
709 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
713 handle_101018(struct bregs *regs)
715 stdvga_pelmask_write(regs->bl);
719 handle_101019(struct bregs *regs)
721 regs->bl = stdvga_pelmask_read();
725 handle_10101a(struct bregs *regs)
727 stdvga_read_video_dac_state(®s->bl, ®s->bh);
731 handle_10101b(struct bregs *regs)
733 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
737 handle_1010XX(struct bregs *regs)
743 handle_1010(struct bregs *regs)
746 case 0x00: handle_101000(regs); break;
747 case 0x01: handle_101001(regs); break;
748 case 0x02: handle_101002(regs); break;
749 case 0x03: handle_101003(regs); break;
750 case 0x07: handle_101007(regs); break;
751 case 0x08: handle_101008(regs); break;
752 case 0x09: handle_101009(regs); break;
753 case 0x10: handle_101010(regs); break;
754 case 0x12: handle_101012(regs); break;
755 case 0x13: handle_101013(regs); break;
756 case 0x15: handle_101015(regs); break;
757 case 0x17: handle_101017(regs); break;
758 case 0x18: handle_101018(regs); break;
759 case 0x19: handle_101019(regs); break;
760 case 0x1a: handle_10101a(regs); break;
761 case 0x1b: handle_10101b(regs); break;
762 default: handle_1010XX(regs); break;
768 handle_101100(struct bregs *regs)
770 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
771 , regs->dx, regs->bl, regs->bh);
775 handle_101101(struct bregs *regs)
777 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
781 handle_101102(struct bregs *regs)
783 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
787 handle_101103(struct bregs *regs)
789 stdvga_set_text_block_specifier(regs->bl);
793 handle_101104(struct bregs *regs)
795 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
799 handle_101110(struct bregs *regs)
801 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
802 , regs->dx, regs->bl, regs->bh);
803 set_scan_lines(regs->bh);
807 handle_101111(struct bregs *regs)
809 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
814 handle_101112(struct bregs *regs)
816 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
821 handle_101114(struct bregs *regs)
823 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
828 handle_101130(struct bregs *regs)
832 struct segoff_s so = GET_IVT(0x1f);
834 regs->bp = so.offset;
838 struct segoff_s so = GET_IVT(0x43);
840 regs->bp = so.offset;
844 regs->es = get_global_seg();
845 regs->bp = (u32)vgafont14;
848 regs->es = get_global_seg();
849 regs->bp = (u32)vgafont8;
852 regs->es = get_global_seg();
853 regs->bp = (u32)vgafont8 + 128 * 8;
856 regs->es = get_global_seg();
857 regs->bp = (u32)vgafont14alt;
860 regs->es = get_global_seg();
861 regs->bp = (u32)vgafont16;
864 regs->es = get_global_seg();
865 regs->bp = (u32)vgafont16alt;
868 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
871 // Set byte/char of on screen font
872 regs->cx = GET_BDA(char_height) & 0xff;
874 // Set Highest char row
875 regs->dx = GET_BDA(video_rows);
879 handle_1011XX(struct bregs *regs)
885 handle_1011(struct bregs *regs)
888 case 0x00: handle_101100(regs); break;
889 case 0x01: handle_101101(regs); break;
890 case 0x02: handle_101102(regs); break;
891 case 0x03: handle_101103(regs); break;
892 case 0x04: handle_101104(regs); break;
893 case 0x10: handle_101110(regs); break;
894 case 0x11: handle_101111(regs); break;
895 case 0x12: handle_101112(regs); break;
896 case 0x14: handle_101114(regs); break;
897 case 0x30: handle_101130(regs); break;
898 default: handle_1011XX(regs); break;
904 handle_101210(struct bregs *regs)
906 u16 crtc_addr = GET_BDA(crtc_address);
907 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
911 regs->cx = GET_BDA(video_switches) & 0x0f;
915 handle_101230(struct bregs *regs)
917 u8 mctl = GET_BDA(modeset_ctl);
918 u8 vswt = GET_BDA(video_switches);
922 mctl = (mctl & ~0x10) | 0x80;
923 vswt = (vswt & ~0x0f) | 0x08;
928 vswt = (vswt & ~0x0f) | 0x09;
932 mctl = (mctl & ~0x80) | 0x10;
933 vswt = (vswt & ~0x0f) | 0x09;
936 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
939 SET_BDA(modeset_ctl, mctl);
940 SET_BDA(video_switches, vswt);
945 handle_101231(struct bregs *regs)
947 u8 v = (regs->al & 0x01) << 3;
948 u8 mctl = GET_BDA(video_ctl) & ~0x08;
949 SET_BDA(video_ctl, mctl | v);
954 handle_101232(struct bregs *regs)
956 stdvga_enable_video_addressing(regs->al);
961 handle_101233(struct bregs *regs)
963 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
964 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
965 SET_BDA(modeset_ctl, v | v2);
970 handle_101234(struct bregs *regs)
972 u8 v = (regs->al & 0x01) ^ 0x01;
973 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
974 SET_BDA(modeset_ctl, v | v2);
979 handle_101235(struct bregs *regs)
986 handle_101236(struct bregs *regs)
993 handle_1012XX(struct bregs *regs)
999 handle_1012(struct bregs *regs)
1001 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
1007 case 0x10: handle_101210(regs); break;
1008 case 0x30: handle_101230(regs); break;
1009 case 0x31: handle_101231(regs); break;
1010 case 0x32: handle_101232(regs); break;
1011 case 0x33: handle_101233(regs); break;
1012 case 0x34: handle_101234(regs); break;
1013 case 0x35: handle_101235(regs); break;
1014 case 0x36: handle_101236(regs); break;
1015 default: handle_1012XX(regs); break;
1021 static void noinline
1022 handle_1013(struct bregs *regs)
1024 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1025 // if row=0xff special case : use current cursor position
1027 cp = get_cursor_pos(cp.page);
1030 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1032 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1040 handle_101a00(struct bregs *regs)
1042 regs->bx = GET_BDA(dcc_index);
1047 handle_101a01(struct bregs *regs)
1049 SET_BDA(dcc_index, regs->bl);
1050 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1055 handle_101aXX(struct bregs *regs)
1061 handle_101a(struct bregs *regs)
1064 case 0x00: handle_101a00(regs); break;
1065 case 0x01: handle_101a01(regs); break;
1066 default: handle_101aXX(regs); break;
1071 static u8 static_functionality[0x10] VAR16 = {
1072 /* 0 */ 0xff, // All modes supported #1
1073 /* 1 */ 0xe0, // All modes supported #2
1074 /* 2 */ 0x0f, // All modes supported #3
1075 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1076 /* 7 */ 0x07, // 200, 350, 400 scan lines
1077 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1078 /* 9 */ 0x08, // total number of charset blocks in text mode
1079 /* a */ 0xe7, // Change to add new functions
1080 /* b */ 0x0c, // Change to add new functions
1081 /* c */ 0x00, // reserved
1082 /* d */ 0x00, // reserved
1083 /* e */ 0x00, // Change to add new functions
1084 /* f */ 0x00 // reserved
1088 struct segoff_s static_functionality;
1108 handle_101b(struct bregs *regs)
1111 struct funcInfo *info = (void*)(regs->di+0);
1112 memset_far(seg, info, 0, sizeof(*info));
1113 // Address of static functionality table
1114 SET_FARVAR(seg, info->static_functionality
1115 , SEGOFF(get_global_seg(), (u32)static_functionality));
1117 // Hard coded copy from BIOS area. Should it be cleaner ?
1118 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1119 , sizeof(info->bda_0x49));
1120 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1121 , sizeof(info->bda_0x84));
1123 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1124 SET_FARVAR(seg, info->colors, 16);
1125 SET_FARVAR(seg, info->pages, 8);
1126 SET_FARVAR(seg, info->scan_lines, 2);
1127 SET_FARVAR(seg, info->video_mem, 3);
1133 handle_101c00(struct bregs *regs)
1135 u16 flags = regs->cx;
1138 size += sizeof(struct saveVideoHardware);
1140 size += sizeof(struct saveBDAstate);
1142 size += sizeof(struct saveDACcolors);
1148 handle_101c01(struct bregs *regs)
1150 u16 flags = regs->cx;
1152 void *data = (void*)(regs->bx+0);
1154 stdvga_save_state(seg, data);
1155 data += sizeof(struct saveVideoHardware);
1158 save_bda_state(seg, data);
1159 data += sizeof(struct saveBDAstate);
1162 stdvga_save_dac_state(seg, data);
1167 handle_101c02(struct bregs *regs)
1169 u16 flags = regs->cx;
1171 void *data = (void*)(regs->bx+0);
1173 stdvga_restore_state(seg, data);
1174 data += sizeof(struct saveVideoHardware);
1177 restore_bda_state(seg, data);
1178 data += sizeof(struct saveBDAstate);
1181 stdvga_restore_dac_state(seg, data);
1186 handle_101cXX(struct bregs *regs)
1192 handle_101c(struct bregs *regs)
1195 case 0x00: handle_101c00(regs); break;
1196 case 0x01: handle_101c01(regs); break;
1197 case 0x02: handle_101c02(regs); break;
1198 default: handle_101cXX(regs); break;
1203 handle_10XX(struct bregs *regs)
1208 // INT 10h Video Support Service Entry Point
1210 handle_10(struct bregs *regs)
1212 debug_enter(regs, DEBUG_VGA_10);
1214 case 0x00: handle_1000(regs); break;
1215 case 0x01: handle_1001(regs); break;
1216 case 0x02: handle_1002(regs); break;
1217 case 0x03: handle_1003(regs); break;
1218 case 0x04: handle_1004(regs); break;
1219 case 0x05: handle_1005(regs); break;
1220 case 0x06: handle_1006(regs); break;
1221 case 0x07: handle_1007(regs); break;
1222 case 0x08: handle_1008(regs); break;
1223 case 0x09: handle_1009(regs); break;
1224 case 0x0a: handle_100a(regs); break;
1225 case 0x0b: handle_100b(regs); break;
1226 case 0x0c: handle_100c(regs); break;
1227 case 0x0d: handle_100d(regs); break;
1228 case 0x0e: handle_100e(regs); break;
1229 case 0x0f: handle_100f(regs); break;
1230 case 0x10: handle_1010(regs); break;
1231 case 0x11: handle_1011(regs); break;
1232 case 0x12: handle_1012(regs); break;
1233 case 0x13: handle_1013(regs); break;
1234 case 0x1a: handle_101a(regs); break;
1235 case 0x1b: handle_101b(regs); break;
1236 case 0x1c: handle_101c(regs); break;
1237 case 0x4f: handle_104f(regs); break;
1238 default: handle_10XX(regs); break;
1243 /****************************************************************
1245 ****************************************************************/
1248 init_bios_area(void)
1250 // init detected hardware BIOS Area
1251 // set 80x25 color (not clear from RBIL but usual)
1252 u16 eqf = GET_BDA(equipment_list_flags);
1253 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1255 // Just for the first int10 find its children
1257 // the default char height
1258 SET_BDA(char_height, 0x10);
1261 SET_BDA(video_ctl, 0x60);
1263 // Set the basic screen we have
1264 SET_BDA(video_switches, 0xf9);
1266 // Set the basic modeset options
1267 SET_BDA(modeset_ctl, 0x51);
1269 // Set the default MSR
1270 SET_BDA(video_msr, 0x09);
1273 int VgaBDF VAR16 = -1;
1276 vga_post(struct bregs *regs)
1278 debug_enter(regs, DEBUG_VGA_POST);
1280 if (CONFIG_VGA_PCI) {
1282 if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
1283 && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
1284 SET_VGA(VgaBDF, bdf);
1287 int ret = vgahw_init();
1289 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1295 SET_VGA(video_save_pointer_table.videoparam
1296 , SEGOFF(get_global_seg(), (u32)video_param_table));
1297 stdvga_build_video_param();
1299 extern void entry_10(void);
1300 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1302 // XXX - clear screen and display info
1305 extern u8 _rom_header_size, _rom_header_checksum;
1306 SET_VGA(_rom_header_checksum, 0);
1307 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1308 SET_VGA(_rom_header_checksum, sum);