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 u16 nbcols = GET_BDA(video_cols);
142 u16 address = (GET_BDA(video_pagesize) * cp.page
143 + (cp.x + cp.y * nbcols) * 2);
145 stdvga_set_cursor_pos(address / 2);
148 static struct cursorpos
149 get_cursor_pos(u8 page)
152 // special case - use current page
153 page = GET_BDA(video_page);
155 struct cursorpos cp = { 0, 0, 0xfe };
158 // FIXME should handle VGA 14/16 lines
159 u16 xy = GET_BDA(cursor_pos[page]);
160 struct cursorpos cp = {xy, xy>>8, page};
165 set_active_page(u8 page)
171 struct vgamode_s *vmode_g = get_current_mode();
175 // Get pos curs pos for the right page
176 struct cursorpos cp = get_cursor_pos(page);
178 // Calculate memory address of start of page
179 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
180 u16 address = GET_BDA(video_pagesize) * page;
181 stdvga_set_active_page(memmodel == MM_TEXT ? address / 2 : address);
183 // And change the BIOS page
184 SET_BDA(video_pagestart, address);
185 SET_BDA(video_page, page);
187 dprintf(1, "Set active page %02x address %04x\n", page, address);
189 // Display the cursor, now the page is active
194 set_scan_lines(u8 lines)
196 stdvga_set_scan_lines(lines);
198 set_cursor_shape(0x06, 0x07);
200 set_cursor_shape(lines - 4, lines - 3);
201 SET_BDA(char_height, lines);
202 u16 vde = stdvga_get_vde();
203 u8 rows = vde / lines;
204 SET_BDA(video_rows, rows - 1);
205 u16 cols = GET_BDA(video_cols);
206 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
210 /****************************************************************
212 ****************************************************************/
214 // Scroll the screen one line. This function is designed to be called
215 // tail-recursive to reduce stack usage.
217 scroll_one(u16 nbrows, u16 nbcols, u8 page)
219 struct cursorpos ul = {0, 0, page};
220 struct cursorpos lr = {nbcols-1, nbrows-1, page};
221 vgafb_scroll(1, -1, ul, lr);
224 // Write a character to the screen at a given position. Implement
225 // special characters and scroll the screen if necessary.
227 write_teletype(struct cursorpos *pcp, struct carattr ca)
229 struct cursorpos cp = *pcp;
231 // Get the dimensions
232 u16 nbrows = GET_BDA(video_rows) + 1;
233 u16 nbcols = GET_BDA(video_cols);
251 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
252 vgafb_write_char(cp, dummyca);
254 } while (cp.x < nbcols && cp.x % 8);
257 vgafb_write_char(cp, ca);
261 // Do we need to wrap ?
262 if (cp.x == nbcols) {
266 // Do we need to scroll ?
274 scroll_one(nbrows, nbcols, cp.page);
277 // Write out a buffer of alternating characters and attributes.
279 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
282 u8 car = GET_FARVAR(seg, *offset_far);
284 u8 attr = GET_FARVAR(seg, *offset_far);
287 struct carattr ca = {car, attr, 1};
288 write_teletype(pcp, ca);
292 // Write out a buffer of characters.
294 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
297 u8 car = GET_FARVAR(seg, *offset_far);
300 struct carattr ca = {car, attr, 1};
301 write_teletype(pcp, ca);
306 /****************************************************************
307 * Save and restore bda state
308 ****************************************************************/
311 save_bda_state(u16 seg, struct saveBDAstate *info)
313 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
314 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
315 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
316 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
317 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
318 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
319 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
320 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
321 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
322 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
325 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
326 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
327 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
329 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
330 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
334 restore_bda_state(u16 seg, struct saveBDAstate *info)
336 u16 mode = GET_FARVAR(seg, info->video_mode);
337 SET_BDA(video_mode, mode);
338 SET_BDA(vbe_mode, mode);
339 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
340 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
341 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
342 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
343 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
344 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
345 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
346 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
347 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
349 for (i = 0; i < 8; i++)
350 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
351 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
352 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
354 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
355 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
359 /****************************************************************
361 ****************************************************************/
364 get_current_mode(void)
366 return vgahw_find_mode(GET_BDA(vbe_mode) & ~MF_VBEFLAGS);
369 // Setup BDA after a mode switch.
371 vga_set_mode(int mode, int flags)
373 dprintf(1, "set VGA mode %x\n", mode);
374 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
376 return VBE_RETURN_STATUS_FAILED;
378 int ret = vgahw_set_mode(vmode_g, flags);
383 int width = GET_GLOBAL(vmode_g->width);
384 int height = GET_GLOBAL(vmode_g->height);
385 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
386 int cheight = GET_GLOBAL(vmode_g->cheight);
388 SET_BDA(video_mode, mode);
390 SET_BDA(video_mode, 0xff);
391 SET_BDA(vbe_mode, mode | (flags & MF_VBEFLAGS));
392 if (memmodel == MM_TEXT) {
393 SET_BDA(video_cols, width);
394 SET_BDA(video_rows, height-1);
395 SET_BDA(cursor_type, 0x0607);
397 int cwidth = GET_GLOBAL(vmode_g->cwidth);
398 SET_BDA(video_cols, width / cwidth);
399 SET_BDA(video_rows, (height / cheight) - 1);
400 SET_BDA(cursor_type, 0x0000);
402 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
403 SET_BDA(crtc_address, stdvga_get_crtc());
404 SET_BDA(char_height, cheight);
405 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
406 SET_BDA(video_switches, 0xF9);
407 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
410 SET_BDA(cursor_pos[i], 0x0000);
411 SET_BDA(video_pagestart, 0x0000);
412 SET_BDA(video_page, 0x00);
414 // FIXME We nearly have the good tables. to be reworked
415 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
416 SET_BDA(video_savetable
417 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
420 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
421 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
423 // Set the ints 0x1F and 0x43
424 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
428 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
431 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
434 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
442 /****************************************************************
444 ****************************************************************/
447 handle_1000(struct bregs *regs)
449 int mode = regs->al & 0x7f;
459 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
461 flags |= MF_NOCLEARMEM;
463 vga_set_mode(mode, flags);
467 handle_1001(struct bregs *regs)
469 set_cursor_shape(regs->ch, regs->cl);
473 handle_1002(struct bregs *regs)
475 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
480 handle_1003(struct bregs *regs)
482 regs->cx = get_cursor_shape(regs->bh);
483 struct cursorpos cp = get_cursor_pos(regs->bh);
488 // Read light pen pos (unimplemented)
490 handle_1004(struct bregs *regs)
493 regs->ax = regs->bx = regs->cx = regs->dx = 0;
497 handle_1005(struct bregs *regs)
499 set_active_page(regs->al);
503 verify_scroll(struct bregs *regs, int dir)
505 u8 page = GET_BDA(video_page);
506 struct cursorpos ul = {regs->cl, regs->ch, page};
507 struct cursorpos lr = {regs->dl, regs->dh, page};
509 u16 nbrows = GET_BDA(video_rows) + 1;
512 u16 nbcols = GET_BDA(video_cols);
516 if (ul.x > lr.x || ul.y > lr.y)
519 u16 nblines = regs->al;
520 if (!nblines || nblines > lr.y - ul.y + 1)
521 nblines = lr.y - ul.y + 1;
523 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
527 handle_1006(struct bregs *regs)
529 verify_scroll(regs, 1);
533 handle_1007(struct bregs *regs)
535 verify_scroll(regs, -1);
539 handle_1008(struct bregs *regs)
541 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
547 write_chars(u8 page, struct carattr ca, u16 count)
549 struct cursorpos cp = get_cursor_pos(page);
551 vgafb_write_char(cp, ca);
557 handle_1009(struct bregs *regs)
559 struct carattr ca = {regs->al, regs->bl, 1};
560 write_chars(regs->bh, ca, regs->cx);
564 handle_100a(struct bregs *regs)
566 struct carattr ca = {regs->al, regs->bl, 0};
567 write_chars(regs->bh, ca, regs->cx);
572 handle_100b00(struct bregs *regs)
574 stdvga_set_border_color(regs->bl);
578 handle_100b01(struct bregs *regs)
580 stdvga_set_palette(regs->bl);
584 handle_100bXX(struct bregs *regs)
590 handle_100b(struct bregs *regs)
593 case 0x00: handle_100b00(regs); break;
594 case 0x01: handle_100b01(regs); break;
595 default: handle_100bXX(regs); break;
601 handle_100c(struct bregs *regs)
603 // XXX - page (regs->bh) is unused
604 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
608 handle_100d(struct bregs *regs)
610 // XXX - page (regs->bh) is unused
611 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
615 handle_100e(struct bregs *regs)
617 // Ralf Brown Interrupt list is WRONG on bh(page)
618 // We do output only on the current page !
619 struct carattr ca = {regs->al, regs->bl, 0};
620 struct cursorpos cp = get_cursor_pos(0xff);
621 write_teletype(&cp, ca);
626 handle_100f(struct bregs *regs)
628 regs->bh = GET_BDA(video_page);
629 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
630 regs->ah = GET_BDA(video_cols);
635 handle_101000(struct bregs *regs)
639 stdvga_attr_write(regs->bl, regs->bh);
643 handle_101001(struct bregs *regs)
645 stdvga_set_overscan_border_color(regs->bh);
649 handle_101002(struct bregs *regs)
651 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
655 handle_101003(struct bregs *regs)
657 stdvga_toggle_intensity(regs->bl);
661 handle_101007(struct bregs *regs)
665 regs->bh = stdvga_attr_read(regs->bl);
669 handle_101008(struct bregs *regs)
671 regs->bh = stdvga_get_overscan_border_color();
675 handle_101009(struct bregs *regs)
677 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
681 handle_101010(struct bregs *regs)
683 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
684 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
688 handle_101012(struct bregs *regs)
690 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
694 handle_101013(struct bregs *regs)
696 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
700 handle_101015(struct bregs *regs)
703 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
710 handle_101017(struct bregs *regs)
712 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
716 handle_101018(struct bregs *regs)
718 stdvga_pelmask_write(regs->bl);
722 handle_101019(struct bregs *regs)
724 regs->bl = stdvga_pelmask_read();
728 handle_10101a(struct bregs *regs)
730 stdvga_read_video_dac_state(®s->bl, ®s->bh);
734 handle_10101b(struct bregs *regs)
736 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
740 handle_1010XX(struct bregs *regs)
746 handle_1010(struct bregs *regs)
749 case 0x00: handle_101000(regs); break;
750 case 0x01: handle_101001(regs); break;
751 case 0x02: handle_101002(regs); break;
752 case 0x03: handle_101003(regs); break;
753 case 0x07: handle_101007(regs); break;
754 case 0x08: handle_101008(regs); break;
755 case 0x09: handle_101009(regs); break;
756 case 0x10: handle_101010(regs); break;
757 case 0x12: handle_101012(regs); break;
758 case 0x13: handle_101013(regs); break;
759 case 0x15: handle_101015(regs); break;
760 case 0x17: handle_101017(regs); break;
761 case 0x18: handle_101018(regs); break;
762 case 0x19: handle_101019(regs); break;
763 case 0x1a: handle_10101a(regs); break;
764 case 0x1b: handle_10101b(regs); break;
765 default: handle_1010XX(regs); break;
771 handle_101100(struct bregs *regs)
773 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
774 , regs->dx, regs->bl, regs->bh);
778 handle_101101(struct bregs *regs)
780 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
784 handle_101102(struct bregs *regs)
786 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
790 handle_101103(struct bregs *regs)
792 stdvga_set_text_block_specifier(regs->bl);
796 handle_101104(struct bregs *regs)
798 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
802 handle_101110(struct bregs *regs)
804 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
805 , regs->dx, regs->bl, regs->bh);
806 set_scan_lines(regs->bh);
810 handle_101111(struct bregs *regs)
812 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
817 handle_101112(struct bregs *regs)
819 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
824 handle_101114(struct bregs *regs)
826 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
831 handle_101130(struct bregs *regs)
835 struct segoff_s so = GET_IVT(0x1f);
837 regs->bp = so.offset;
841 struct segoff_s so = GET_IVT(0x43);
843 regs->bp = so.offset;
847 regs->es = get_global_seg();
848 regs->bp = (u32)vgafont14;
851 regs->es = get_global_seg();
852 regs->bp = (u32)vgafont8;
855 regs->es = get_global_seg();
856 regs->bp = (u32)vgafont8 + 128 * 8;
859 regs->es = get_global_seg();
860 regs->bp = (u32)vgafont14alt;
863 regs->es = get_global_seg();
864 regs->bp = (u32)vgafont16;
867 regs->es = get_global_seg();
868 regs->bp = (u32)vgafont16alt;
871 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
874 // Set byte/char of on screen font
875 regs->cx = GET_BDA(char_height) & 0xff;
877 // Set Highest char row
878 regs->dx = GET_BDA(video_rows);
882 handle_1011XX(struct bregs *regs)
888 handle_1011(struct bregs *regs)
891 case 0x00: handle_101100(regs); break;
892 case 0x01: handle_101101(regs); break;
893 case 0x02: handle_101102(regs); break;
894 case 0x03: handle_101103(regs); break;
895 case 0x04: handle_101104(regs); break;
896 case 0x10: handle_101110(regs); break;
897 case 0x11: handle_101111(regs); break;
898 case 0x12: handle_101112(regs); break;
899 case 0x14: handle_101114(regs); break;
900 case 0x30: handle_101130(regs); break;
901 default: handle_1011XX(regs); break;
907 handle_101210(struct bregs *regs)
909 u16 crtc_addr = GET_BDA(crtc_address);
910 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
914 regs->cx = GET_BDA(video_switches) & 0x0f;
918 handle_101230(struct bregs *regs)
920 u8 mctl = GET_BDA(modeset_ctl);
921 u8 vswt = GET_BDA(video_switches);
925 mctl = (mctl & ~0x10) | 0x80;
926 vswt = (vswt & ~0x0f) | 0x08;
931 vswt = (vswt & ~0x0f) | 0x09;
935 mctl = (mctl & ~0x80) | 0x10;
936 vswt = (vswt & ~0x0f) | 0x09;
939 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
942 SET_BDA(modeset_ctl, mctl);
943 SET_BDA(video_switches, vswt);
948 handle_101231(struct bregs *regs)
950 u8 v = (regs->al & 0x01) << 3;
951 u8 mctl = GET_BDA(video_ctl) & ~0x08;
952 SET_BDA(video_ctl, mctl | v);
957 handle_101232(struct bregs *regs)
959 stdvga_enable_video_addressing(regs->al);
964 handle_101233(struct bregs *regs)
966 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
967 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
968 SET_BDA(modeset_ctl, v | v2);
973 handle_101234(struct bregs *regs)
975 u8 v = (regs->al & 0x01) ^ 0x01;
976 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
977 SET_BDA(modeset_ctl, v | v2);
982 handle_101235(struct bregs *regs)
989 handle_101236(struct bregs *regs)
996 handle_1012XX(struct bregs *regs)
1002 handle_1012(struct bregs *regs)
1004 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
1010 case 0x10: handle_101210(regs); break;
1011 case 0x30: handle_101230(regs); break;
1012 case 0x31: handle_101231(regs); break;
1013 case 0x32: handle_101232(regs); break;
1014 case 0x33: handle_101233(regs); break;
1015 case 0x34: handle_101234(regs); break;
1016 case 0x35: handle_101235(regs); break;
1017 case 0x36: handle_101236(regs); break;
1018 default: handle_1012XX(regs); break;
1024 static void noinline
1025 handle_1013(struct bregs *regs)
1027 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1028 // if row=0xff special case : use current cursor position
1030 cp = get_cursor_pos(cp.page);
1033 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1035 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1043 handle_101a00(struct bregs *regs)
1045 regs->bx = GET_BDA(dcc_index);
1050 handle_101a01(struct bregs *regs)
1052 SET_BDA(dcc_index, regs->bl);
1053 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1058 handle_101aXX(struct bregs *regs)
1064 handle_101a(struct bregs *regs)
1067 case 0x00: handle_101a00(regs); break;
1068 case 0x01: handle_101a01(regs); break;
1069 default: handle_101aXX(regs); break;
1074 static u8 static_functionality[0x10] VAR16 = {
1075 /* 0 */ 0xff, // All modes supported #1
1076 /* 1 */ 0xe0, // All modes supported #2
1077 /* 2 */ 0x0f, // All modes supported #3
1078 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1079 /* 7 */ 0x07, // 200, 350, 400 scan lines
1080 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1081 /* 9 */ 0x08, // total number of charset blocks in text mode
1082 /* a */ 0xe7, // Change to add new functions
1083 /* b */ 0x0c, // Change to add new functions
1084 /* c */ 0x00, // reserved
1085 /* d */ 0x00, // reserved
1086 /* e */ 0x00, // Change to add new functions
1087 /* f */ 0x00 // reserved
1091 struct segoff_s static_functionality;
1111 handle_101b(struct bregs *regs)
1114 struct funcInfo *info = (void*)(regs->di+0);
1115 memset_far(seg, info, 0, sizeof(*info));
1116 // Address of static functionality table
1117 SET_FARVAR(seg, info->static_functionality
1118 , SEGOFF(get_global_seg(), (u32)static_functionality));
1120 // Hard coded copy from BIOS area. Should it be cleaner ?
1121 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1122 , sizeof(info->bda_0x49));
1123 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1124 , sizeof(info->bda_0x84));
1126 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1127 SET_FARVAR(seg, info->colors, 16);
1128 SET_FARVAR(seg, info->pages, 8);
1129 SET_FARVAR(seg, info->scan_lines, 2);
1130 SET_FARVAR(seg, info->video_mem, 3);
1136 handle_101c00(struct bregs *regs)
1138 u16 flags = regs->cx;
1141 size += sizeof(struct saveVideoHardware);
1143 size += sizeof(struct saveBDAstate);
1145 size += sizeof(struct saveDACcolors);
1151 handle_101c01(struct bregs *regs)
1153 u16 flags = regs->cx;
1155 void *data = (void*)(regs->bx+0);
1157 stdvga_save_state(seg, data);
1158 data += sizeof(struct saveVideoHardware);
1161 save_bda_state(seg, data);
1162 data += sizeof(struct saveBDAstate);
1165 stdvga_save_dac_state(seg, data);
1170 handle_101c02(struct bregs *regs)
1172 u16 flags = regs->cx;
1174 void *data = (void*)(regs->bx+0);
1176 stdvga_restore_state(seg, data);
1177 data += sizeof(struct saveVideoHardware);
1180 restore_bda_state(seg, data);
1181 data += sizeof(struct saveBDAstate);
1184 stdvga_restore_dac_state(seg, data);
1189 handle_101cXX(struct bregs *regs)
1195 handle_101c(struct bregs *regs)
1198 case 0x00: handle_101c00(regs); break;
1199 case 0x01: handle_101c01(regs); break;
1200 case 0x02: handle_101c02(regs); break;
1201 default: handle_101cXX(regs); break;
1206 handle_10XX(struct bregs *regs)
1211 // INT 10h Video Support Service Entry Point
1213 handle_10(struct bregs *regs)
1215 debug_enter(regs, DEBUG_VGA_10);
1217 case 0x00: handle_1000(regs); break;
1218 case 0x01: handle_1001(regs); break;
1219 case 0x02: handle_1002(regs); break;
1220 case 0x03: handle_1003(regs); break;
1221 case 0x04: handle_1004(regs); break;
1222 case 0x05: handle_1005(regs); break;
1223 case 0x06: handle_1006(regs); break;
1224 case 0x07: handle_1007(regs); break;
1225 case 0x08: handle_1008(regs); break;
1226 case 0x09: handle_1009(regs); break;
1227 case 0x0a: handle_100a(regs); break;
1228 case 0x0b: handle_100b(regs); break;
1229 case 0x0c: handle_100c(regs); break;
1230 case 0x0d: handle_100d(regs); break;
1231 case 0x0e: handle_100e(regs); break;
1232 case 0x0f: handle_100f(regs); break;
1233 case 0x10: handle_1010(regs); break;
1234 case 0x11: handle_1011(regs); break;
1235 case 0x12: handle_1012(regs); break;
1236 case 0x13: handle_1013(regs); break;
1237 case 0x1a: handle_101a(regs); break;
1238 case 0x1b: handle_101b(regs); break;
1239 case 0x1c: handle_101c(regs); break;
1240 case 0x4f: handle_104f(regs); break;
1241 default: handle_10XX(regs); break;
1246 /****************************************************************
1248 ****************************************************************/
1251 init_bios_area(void)
1253 // init detected hardware BIOS Area
1254 // set 80x25 color (not clear from RBIL but usual)
1255 u16 eqf = GET_BDA(equipment_list_flags);
1256 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1258 // Just for the first int10 find its children
1260 // the default char height
1261 SET_BDA(char_height, 0x10);
1264 SET_BDA(video_ctl, 0x60);
1266 // Set the basic screen we have
1267 SET_BDA(video_switches, 0xf9);
1269 // Set the basic modeset options
1270 SET_BDA(modeset_ctl, 0x51);
1272 // Set the default MSR
1273 SET_BDA(video_msr, 0x09);
1276 int VgaBDF VAR16 = -1;
1279 vga_post(struct bregs *regs)
1281 debug_enter(regs, DEBUG_VGA_POST);
1283 if (CONFIG_VGA_PCI) {
1285 if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
1286 && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
1287 SET_VGA(VgaBDF, bdf);
1290 int ret = vgahw_init();
1292 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1298 SET_VGA(video_save_pointer_table.videoparam
1299 , SEGOFF(get_global_seg(), (u32)video_param_table));
1300 stdvga_build_video_param();
1302 extern void entry_10(void);
1303 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1305 // XXX - clear screen and display info
1308 extern u8 _rom_header_size, _rom_header_checksum;
1309 SET_VGA(_rom_header_checksum, 0);
1310 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1311 SET_VGA(_rom_header_checksum, sum);