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 int address = GET_BDA(video_pagesize) * page;
180 vgahw_set_displaystart(vmode_g, address);
182 // And change the BIOS page
183 SET_BDA(video_pagestart, address);
184 SET_BDA(video_page, page);
186 dprintf(1, "Set active page %02x address %04x\n", page, address);
188 // Display the cursor, now the page is active
193 set_scan_lines(u8 lines)
195 stdvga_set_scan_lines(lines);
197 set_cursor_shape(0x06, 0x07);
199 set_cursor_shape(lines - 4, lines - 3);
200 SET_BDA(char_height, lines);
201 u16 vde = stdvga_get_vde();
202 u8 rows = vde / lines;
203 SET_BDA(video_rows, rows - 1);
204 u16 cols = GET_BDA(video_cols);
205 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
209 /****************************************************************
211 ****************************************************************/
213 // Scroll the screen one line. This function is designed to be called
214 // tail-recursive to reduce stack usage.
216 scroll_one(u16 nbrows, u16 nbcols, u8 page)
218 struct cursorpos ul = {0, 0, page};
219 struct cursorpos lr = {nbcols-1, nbrows-1, page};
220 vgafb_scroll(1, -1, ul, lr);
223 // Write a character to the screen at a given position. Implement
224 // special characters and scroll the screen if necessary.
226 write_teletype(struct cursorpos *pcp, struct carattr ca)
228 struct cursorpos cp = *pcp;
230 // Get the dimensions
231 u16 nbrows = GET_BDA(video_rows) + 1;
232 u16 nbcols = GET_BDA(video_cols);
250 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
251 vgafb_write_char(cp, dummyca);
253 } while (cp.x < nbcols && cp.x % 8);
256 vgafb_write_char(cp, ca);
260 // Do we need to wrap ?
261 if (cp.x == nbcols) {
265 // Do we need to scroll ?
273 scroll_one(nbrows, nbcols, cp.page);
276 // Write out a buffer of alternating characters and attributes.
278 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
281 u8 car = GET_FARVAR(seg, *offset_far);
283 u8 attr = GET_FARVAR(seg, *offset_far);
286 struct carattr ca = {car, attr, 1};
287 write_teletype(pcp, ca);
291 // Write out a buffer of characters.
293 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
296 u8 car = GET_FARVAR(seg, *offset_far);
299 struct carattr ca = {car, attr, 1};
300 write_teletype(pcp, ca);
305 /****************************************************************
306 * Save and restore bda state
307 ****************************************************************/
310 save_bda_state(u16 seg, struct saveBDAstate *info)
312 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
313 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
314 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
315 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
316 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
317 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
318 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
319 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
320 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
321 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
324 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
325 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
326 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
328 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
329 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
333 restore_bda_state(u16 seg, struct saveBDAstate *info)
335 u16 mode = GET_FARVAR(seg, info->video_mode);
336 SET_BDA(video_mode, mode);
337 SET_BDA(vbe_mode, mode);
338 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
339 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
340 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
341 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
342 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
343 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
344 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
345 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
346 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
348 for (i = 0; i < 8; i++)
349 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
350 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
351 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
353 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
354 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
358 /****************************************************************
360 ****************************************************************/
363 get_current_mode(void)
365 return vgahw_find_mode(GET_BDA(vbe_mode) & ~MF_VBEFLAGS);
368 // Setup BDA after a mode switch.
370 vga_set_mode(int mode, int flags)
372 dprintf(1, "set VGA mode %x\n", mode);
373 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
375 return VBE_RETURN_STATUS_FAILED;
377 int ret = vgahw_set_mode(vmode_g, flags);
382 int width = GET_GLOBAL(vmode_g->width);
383 int height = GET_GLOBAL(vmode_g->height);
384 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
385 int cheight = GET_GLOBAL(vmode_g->cheight);
387 SET_BDA(video_mode, mode);
389 SET_BDA(video_mode, 0xff);
390 SET_BDA(vbe_mode, mode | (flags & MF_VBEFLAGS));
391 if (memmodel == MM_TEXT) {
392 SET_BDA(video_cols, width);
393 SET_BDA(video_rows, height-1);
394 SET_BDA(cursor_type, 0x0607);
396 int cwidth = GET_GLOBAL(vmode_g->cwidth);
397 SET_BDA(video_cols, width / cwidth);
398 SET_BDA(video_rows, (height / cheight) - 1);
399 SET_BDA(cursor_type, 0x0000);
401 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
402 SET_BDA(crtc_address, stdvga_get_crtc());
403 SET_BDA(char_height, cheight);
404 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
405 SET_BDA(video_switches, 0xF9);
406 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
409 SET_BDA(cursor_pos[i], 0x0000);
410 SET_BDA(video_pagestart, 0x0000);
411 SET_BDA(video_page, 0x00);
413 // FIXME We nearly have the good tables. to be reworked
414 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
415 SET_BDA(video_savetable
416 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
419 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
420 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
422 // Set the ints 0x1F and 0x43
423 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
427 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
430 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
433 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
441 /****************************************************************
443 ****************************************************************/
446 handle_1000(struct bregs *regs)
448 int mode = regs->al & 0x7f;
458 int flags = GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM);
460 flags |= MF_NOCLEARMEM;
462 vga_set_mode(mode, flags);
466 handle_1001(struct bregs *regs)
468 set_cursor_shape(regs->ch, regs->cl);
472 handle_1002(struct bregs *regs)
474 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
479 handle_1003(struct bregs *regs)
481 regs->cx = get_cursor_shape(regs->bh);
482 struct cursorpos cp = get_cursor_pos(regs->bh);
487 // Read light pen pos (unimplemented)
489 handle_1004(struct bregs *regs)
492 regs->ax = regs->bx = regs->cx = regs->dx = 0;
496 handle_1005(struct bregs *regs)
498 set_active_page(regs->al);
502 verify_scroll(struct bregs *regs, int dir)
504 u8 page = GET_BDA(video_page);
505 struct cursorpos ul = {regs->cl, regs->ch, page};
506 struct cursorpos lr = {regs->dl, regs->dh, page};
508 u16 nbrows = GET_BDA(video_rows) + 1;
511 u16 nbcols = GET_BDA(video_cols);
515 if (ul.x > lr.x || ul.y > lr.y)
518 u16 nblines = regs->al;
519 if (!nblines || nblines > lr.y - ul.y + 1)
520 nblines = lr.y - ul.y + 1;
522 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
526 handle_1006(struct bregs *regs)
528 verify_scroll(regs, 1);
532 handle_1007(struct bregs *regs)
534 verify_scroll(regs, -1);
538 handle_1008(struct bregs *regs)
540 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
546 write_chars(u8 page, struct carattr ca, u16 count)
548 struct cursorpos cp = get_cursor_pos(page);
550 vgafb_write_char(cp, ca);
556 handle_1009(struct bregs *regs)
558 struct carattr ca = {regs->al, regs->bl, 1};
559 write_chars(regs->bh, ca, regs->cx);
563 handle_100a(struct bregs *regs)
565 struct carattr ca = {regs->al, regs->bl, 0};
566 write_chars(regs->bh, ca, regs->cx);
571 handle_100b00(struct bregs *regs)
573 stdvga_set_border_color(regs->bl);
577 handle_100b01(struct bregs *regs)
579 stdvga_set_palette(regs->bl);
583 handle_100bXX(struct bregs *regs)
589 handle_100b(struct bregs *regs)
592 case 0x00: handle_100b00(regs); break;
593 case 0x01: handle_100b01(regs); break;
594 default: handle_100bXX(regs); break;
600 handle_100c(struct bregs *regs)
602 // XXX - page (regs->bh) is unused
603 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
607 handle_100d(struct bregs *regs)
609 // XXX - page (regs->bh) is unused
610 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
614 handle_100e(struct bregs *regs)
616 // Ralf Brown Interrupt list is WRONG on bh(page)
617 // We do output only on the current page !
618 struct carattr ca = {regs->al, regs->bl, 0};
619 struct cursorpos cp = get_cursor_pos(0xff);
620 write_teletype(&cp, ca);
625 handle_100f(struct bregs *regs)
627 regs->bh = GET_BDA(video_page);
628 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
629 regs->ah = GET_BDA(video_cols);
634 handle_101000(struct bregs *regs)
638 stdvga_attr_write(regs->bl, regs->bh);
642 handle_101001(struct bregs *regs)
644 stdvga_set_overscan_border_color(regs->bh);
648 handle_101002(struct bregs *regs)
650 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
654 handle_101003(struct bregs *regs)
656 stdvga_toggle_intensity(regs->bl);
660 handle_101007(struct bregs *regs)
664 regs->bh = stdvga_attr_read(regs->bl);
668 handle_101008(struct bregs *regs)
670 regs->bh = stdvga_get_overscan_border_color();
674 handle_101009(struct bregs *regs)
676 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
680 handle_101010(struct bregs *regs)
682 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
683 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
687 handle_101012(struct bregs *regs)
689 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
693 handle_101013(struct bregs *regs)
695 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
699 handle_101015(struct bregs *regs)
702 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
709 handle_101017(struct bregs *regs)
711 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
715 handle_101018(struct bregs *regs)
717 stdvga_pelmask_write(regs->bl);
721 handle_101019(struct bregs *regs)
723 regs->bl = stdvga_pelmask_read();
727 handle_10101a(struct bregs *regs)
729 stdvga_read_video_dac_state(®s->bl, ®s->bh);
733 handle_10101b(struct bregs *regs)
735 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
739 handle_1010XX(struct bregs *regs)
745 handle_1010(struct bregs *regs)
748 case 0x00: handle_101000(regs); break;
749 case 0x01: handle_101001(regs); break;
750 case 0x02: handle_101002(regs); break;
751 case 0x03: handle_101003(regs); break;
752 case 0x07: handle_101007(regs); break;
753 case 0x08: handle_101008(regs); break;
754 case 0x09: handle_101009(regs); break;
755 case 0x10: handle_101010(regs); break;
756 case 0x12: handle_101012(regs); break;
757 case 0x13: handle_101013(regs); break;
758 case 0x15: handle_101015(regs); break;
759 case 0x17: handle_101017(regs); break;
760 case 0x18: handle_101018(regs); break;
761 case 0x19: handle_101019(regs); break;
762 case 0x1a: handle_10101a(regs); break;
763 case 0x1b: handle_10101b(regs); break;
764 default: handle_1010XX(regs); break;
770 handle_101100(struct bregs *regs)
772 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
773 , regs->dx, regs->bl, regs->bh);
777 handle_101101(struct bregs *regs)
779 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
783 handle_101102(struct bregs *regs)
785 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
789 handle_101103(struct bregs *regs)
791 stdvga_set_text_block_specifier(regs->bl);
795 handle_101104(struct bregs *regs)
797 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
801 handle_101110(struct bregs *regs)
803 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
804 , regs->dx, regs->bl, regs->bh);
805 set_scan_lines(regs->bh);
809 handle_101111(struct bregs *regs)
811 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
816 handle_101112(struct bregs *regs)
818 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
823 handle_101114(struct bregs *regs)
825 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
830 handle_101130(struct bregs *regs)
834 struct segoff_s so = GET_IVT(0x1f);
836 regs->bp = so.offset;
840 struct segoff_s so = GET_IVT(0x43);
842 regs->bp = so.offset;
846 regs->es = get_global_seg();
847 regs->bp = (u32)vgafont14;
850 regs->es = get_global_seg();
851 regs->bp = (u32)vgafont8;
854 regs->es = get_global_seg();
855 regs->bp = (u32)vgafont8 + 128 * 8;
858 regs->es = get_global_seg();
859 regs->bp = (u32)vgafont14alt;
862 regs->es = get_global_seg();
863 regs->bp = (u32)vgafont16;
866 regs->es = get_global_seg();
867 regs->bp = (u32)vgafont16alt;
870 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
873 // Set byte/char of on screen font
874 regs->cx = GET_BDA(char_height) & 0xff;
876 // Set Highest char row
877 regs->dx = GET_BDA(video_rows);
881 handle_1011XX(struct bregs *regs)
887 handle_1011(struct bregs *regs)
890 case 0x00: handle_101100(regs); break;
891 case 0x01: handle_101101(regs); break;
892 case 0x02: handle_101102(regs); break;
893 case 0x03: handle_101103(regs); break;
894 case 0x04: handle_101104(regs); break;
895 case 0x10: handle_101110(regs); break;
896 case 0x11: handle_101111(regs); break;
897 case 0x12: handle_101112(regs); break;
898 case 0x14: handle_101114(regs); break;
899 case 0x30: handle_101130(regs); break;
900 default: handle_1011XX(regs); break;
906 handle_101210(struct bregs *regs)
908 u16 crtc_addr = GET_BDA(crtc_address);
909 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
913 regs->cx = GET_BDA(video_switches) & 0x0f;
917 handle_101230(struct bregs *regs)
919 u8 mctl = GET_BDA(modeset_ctl);
920 u8 vswt = GET_BDA(video_switches);
924 mctl = (mctl & ~0x10) | 0x80;
925 vswt = (vswt & ~0x0f) | 0x08;
930 vswt = (vswt & ~0x0f) | 0x09;
934 mctl = (mctl & ~0x80) | 0x10;
935 vswt = (vswt & ~0x0f) | 0x09;
938 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
941 SET_BDA(modeset_ctl, mctl);
942 SET_BDA(video_switches, vswt);
947 handle_101231(struct bregs *regs)
949 u8 v = (regs->al & 0x01) << 3;
950 u8 mctl = GET_BDA(video_ctl) & ~0x08;
951 SET_BDA(video_ctl, mctl | v);
956 handle_101232(struct bregs *regs)
958 stdvga_enable_video_addressing(regs->al);
963 handle_101233(struct bregs *regs)
965 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
966 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
967 SET_BDA(modeset_ctl, v | v2);
972 handle_101234(struct bregs *regs)
974 u8 v = (regs->al & 0x01) ^ 0x01;
975 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
976 SET_BDA(modeset_ctl, v | v2);
981 handle_101235(struct bregs *regs)
988 handle_101236(struct bregs *regs)
995 handle_1012XX(struct bregs *regs)
1001 handle_1012(struct bregs *regs)
1003 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
1009 case 0x10: handle_101210(regs); break;
1010 case 0x30: handle_101230(regs); break;
1011 case 0x31: handle_101231(regs); break;
1012 case 0x32: handle_101232(regs); break;
1013 case 0x33: handle_101233(regs); break;
1014 case 0x34: handle_101234(regs); break;
1015 case 0x35: handle_101235(regs); break;
1016 case 0x36: handle_101236(regs); break;
1017 default: handle_1012XX(regs); break;
1023 static void noinline
1024 handle_1013(struct bregs *regs)
1026 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1027 // if row=0xff special case : use current cursor position
1029 cp = get_cursor_pos(cp.page);
1032 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1034 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1042 handle_101a00(struct bregs *regs)
1044 regs->bx = GET_BDA(dcc_index);
1049 handle_101a01(struct bregs *regs)
1051 SET_BDA(dcc_index, regs->bl);
1052 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1057 handle_101aXX(struct bregs *regs)
1063 handle_101a(struct bregs *regs)
1066 case 0x00: handle_101a00(regs); break;
1067 case 0x01: handle_101a01(regs); break;
1068 default: handle_101aXX(regs); break;
1073 static u8 static_functionality[0x10] VAR16 = {
1074 /* 0 */ 0xff, // All modes supported #1
1075 /* 1 */ 0xe0, // All modes supported #2
1076 /* 2 */ 0x0f, // All modes supported #3
1077 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1078 /* 7 */ 0x07, // 200, 350, 400 scan lines
1079 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1080 /* 9 */ 0x08, // total number of charset blocks in text mode
1081 /* a */ 0xe7, // Change to add new functions
1082 /* b */ 0x0c, // Change to add new functions
1083 /* c */ 0x00, // reserved
1084 /* d */ 0x00, // reserved
1085 /* e */ 0x00, // Change to add new functions
1086 /* f */ 0x00 // reserved
1090 struct segoff_s static_functionality;
1110 handle_101b(struct bregs *regs)
1113 struct funcInfo *info = (void*)(regs->di+0);
1114 memset_far(seg, info, 0, sizeof(*info));
1115 // Address of static functionality table
1116 SET_FARVAR(seg, info->static_functionality
1117 , SEGOFF(get_global_seg(), (u32)static_functionality));
1119 // Hard coded copy from BIOS area. Should it be cleaner ?
1120 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1121 , sizeof(info->bda_0x49));
1122 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1123 , sizeof(info->bda_0x84));
1125 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1126 SET_FARVAR(seg, info->colors, 16);
1127 SET_FARVAR(seg, info->pages, 8);
1128 SET_FARVAR(seg, info->scan_lines, 2);
1129 SET_FARVAR(seg, info->video_mem, 3);
1135 handle_101c00(struct bregs *regs)
1137 u16 flags = regs->cx;
1140 size += sizeof(struct saveVideoHardware);
1142 size += sizeof(struct saveBDAstate);
1144 size += sizeof(struct saveDACcolors);
1150 handle_101c01(struct bregs *regs)
1152 u16 flags = regs->cx;
1154 void *data = (void*)(regs->bx+0);
1156 stdvga_save_state(seg, data);
1157 data += sizeof(struct saveVideoHardware);
1160 save_bda_state(seg, data);
1161 data += sizeof(struct saveBDAstate);
1164 stdvga_save_dac_state(seg, data);
1169 handle_101c02(struct bregs *regs)
1171 u16 flags = regs->cx;
1173 void *data = (void*)(regs->bx+0);
1175 stdvga_restore_state(seg, data);
1176 data += sizeof(struct saveVideoHardware);
1179 restore_bda_state(seg, data);
1180 data += sizeof(struct saveBDAstate);
1183 stdvga_restore_dac_state(seg, data);
1188 handle_101cXX(struct bregs *regs)
1194 handle_101c(struct bregs *regs)
1197 case 0x00: handle_101c00(regs); break;
1198 case 0x01: handle_101c01(regs); break;
1199 case 0x02: handle_101c02(regs); break;
1200 default: handle_101cXX(regs); break;
1205 handle_10XX(struct bregs *regs)
1210 // INT 10h Video Support Service Entry Point
1212 handle_10(struct bregs *regs)
1214 debug_enter(regs, DEBUG_VGA_10);
1216 case 0x00: handle_1000(regs); break;
1217 case 0x01: handle_1001(regs); break;
1218 case 0x02: handle_1002(regs); break;
1219 case 0x03: handle_1003(regs); break;
1220 case 0x04: handle_1004(regs); break;
1221 case 0x05: handle_1005(regs); break;
1222 case 0x06: handle_1006(regs); break;
1223 case 0x07: handle_1007(regs); break;
1224 case 0x08: handle_1008(regs); break;
1225 case 0x09: handle_1009(regs); break;
1226 case 0x0a: handle_100a(regs); break;
1227 case 0x0b: handle_100b(regs); break;
1228 case 0x0c: handle_100c(regs); break;
1229 case 0x0d: handle_100d(regs); break;
1230 case 0x0e: handle_100e(regs); break;
1231 case 0x0f: handle_100f(regs); break;
1232 case 0x10: handle_1010(regs); break;
1233 case 0x11: handle_1011(regs); break;
1234 case 0x12: handle_1012(regs); break;
1235 case 0x13: handle_1013(regs); break;
1236 case 0x1a: handle_101a(regs); break;
1237 case 0x1b: handle_101b(regs); break;
1238 case 0x1c: handle_101c(regs); break;
1239 case 0x4f: handle_104f(regs); break;
1240 default: handle_10XX(regs); break;
1245 /****************************************************************
1247 ****************************************************************/
1250 init_bios_area(void)
1252 // init detected hardware BIOS Area
1253 // set 80x25 color (not clear from RBIL but usual)
1254 u16 eqf = GET_BDA(equipment_list_flags);
1255 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1257 // Just for the first int10 find its children
1259 // the default char height
1260 SET_BDA(char_height, 0x10);
1263 SET_BDA(video_ctl, 0x60);
1265 // Set the basic screen we have
1266 SET_BDA(video_switches, 0xf9);
1268 // Set the basic modeset options
1269 SET_BDA(modeset_ctl, 0x51);
1271 // Set the default MSR
1272 SET_BDA(video_msr, 0x09);
1275 int VgaBDF VAR16 = -1;
1278 vga_post(struct bregs *regs)
1280 debug_enter(regs, DEBUG_VGA_POST);
1282 if (CONFIG_VGA_PCI) {
1284 if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID
1285 && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID)
1286 SET_VGA(VgaBDF, bdf);
1289 int ret = vgahw_init();
1291 dprintf(1, "Failed to initialize VGA hardware. Exiting.\n");
1297 SET_VGA(video_save_pointer_table.videoparam
1298 , SEGOFF(get_global_seg(), (u32)video_param_table));
1299 stdvga_build_video_param();
1301 extern void entry_10(void);
1302 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
1304 // XXX - clear screen and display info
1307 extern u8 _rom_header_size, _rom_header_checksum;
1308 SET_VGA(_rom_header_checksum, 0);
1309 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1310 SET_VGA(_rom_header_checksum, sum);