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
11 // * refactor redundant code into sub-functions
12 // * See if there is a method to the in/out stuff that can be encapsulated.
13 // * remove "biosfn" prefixes
14 // * verify all funcs static
16 // * convert vbe/clext code
18 #include "bregs.h" // struct bregs
19 #include "biosvar.h" // GET_BDA
20 #include "util.h" // memset
21 #include "vgatables.h" // find_vga_entry
25 #define CONFIG_CIRRUS 0
28 #define DEBUG_VGA_POST 1
29 #define DEBUG_VGA_10 3
31 #define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
34 call16_vgaint(u32 eax, u32 ebx)
46 biosfn_perform_gray_scale_summing(u16 start, u16 count)
48 vgahw_screen_disable();
50 for (i = start; i < start+count; i++) {
52 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
54 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
55 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
59 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
61 vgahw_screen_enable();
65 biosfn_set_cursor_shape(u8 CH, u8 CL)
70 u16 curs = (CH << 8) + CL;
71 SET_BDA(cursor_type, curs);
73 u8 modeset_ctl = GET_BDA(modeset_ctl);
74 u16 cheight = GET_BDA(char_height);
75 if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
77 CH = ((CH + 1) * cheight / 8) - 1;
79 CH = ((CL + 1) * cheight / 8) - 2;
80 CL = ((CL + 1) * cheight / 8) - 1;
82 vgahw_set_cursor_shape(CH, CL);
86 biosfn_get_cursor_shape(u8 page)
90 // FIXME should handle VGA 14/16 lines
91 return GET_BDA(cursor_type);
95 set_cursor_pos(struct cursorpos cp)
97 // Should not happen...
102 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
104 // Set the hardware cursor
105 u8 current = GET_BDA(video_page);
106 if (cp.page != current)
109 // Get the dimensions
110 u16 nbcols = GET_BDA(video_cols);
111 u16 nbrows = GET_BDA(video_rows) + 1;
113 // Calculate the address knowing nbcols nbrows and page num
114 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
115 + cp.x + cp.y * nbcols);
117 vgahw_set_cursor_pos(address);
120 static struct cursorpos
121 get_cursor_pos(u8 page)
124 // special case - use current page
125 page = GET_BDA(video_page);
127 struct cursorpos cp = { 0, 0, 0xfe };
130 // FIXME should handle VGA 14/16 lines
131 u16 xy = GET_BDA(cursor_pos[page]);
132 struct cursorpos cp = {xy, xy>>8, page};
137 biosfn_set_active_page(u8 page)
143 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
147 // Get pos curs pos for the right page
148 struct cursorpos cp = get_cursor_pos(page);
151 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
152 // Get the dimensions
153 u16 nbcols = GET_BDA(video_cols);
154 u16 nbrows = GET_BDA(video_rows) + 1;
156 // Calculate the address knowing nbcols nbrows and page num
157 address = SCREEN_MEM_START(nbcols, nbrows, page);
158 SET_BDA(video_pagestart, address);
161 address = SCREEN_IO_START(nbcols, nbrows, page);
163 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
164 address = page * GET_GLOBAL(vparam_g->slength);
167 vgahw_set_active_page(address);
169 // And change the BIOS page
170 SET_BDA(video_page, page);
172 dprintf(1, "Set active page %02x address %04x\n", page, address);
174 // Display the cursor, now the page is active
178 // Scroll the screen one line. This function is designed to be called
179 // tail-recursive to reduce stack usage.
181 scroll_one(u16 nbrows, u16 nbcols, u8 page)
183 struct cursorpos ul = {0, 0, page};
184 struct cursorpos lr = {nbcols-1, nbrows-1, page};
185 vgafb_scroll(1, -1, ul, lr);
188 // Write a character to the screen at a given position. Implement
189 // special characters and scroll the screen if necessary.
191 write_teletype(struct cursorpos *pcp, struct carattr ca)
193 struct cursorpos cp = *pcp;
195 // Get the dimensions
196 u16 nbrows = GET_BDA(video_rows) + 1;
197 u16 nbcols = GET_BDA(video_cols);
215 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
216 vgafb_write_char(cp, dummyca);
218 } while (cp.x < nbcols && cp.x % 8);
221 vgafb_write_char(cp, ca);
225 // Do we need to wrap ?
226 if (cp.x == nbcols) {
230 // Do we need to scroll ?
238 scroll_one(nbrows, nbcols, cp.page);
241 // Write out a buffer of alternating characters and attributes.
243 write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
246 u8 car = GET_FARVAR(seg, *offset_far);
248 u8 attr = GET_FARVAR(seg, *offset_far);
251 struct carattr ca = {car, attr, 1};
252 write_teletype(pcp, ca);
256 // Write out a buffer of characters.
258 write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
261 u8 car = GET_FARVAR(seg, *offset_far);
264 struct carattr ca = {car, attr, 1};
265 write_teletype(pcp, ca);
270 set_scan_lines(u8 lines)
272 vgahw_set_scan_lines(lines);
274 biosfn_set_cursor_shape(0x06, 0x07);
276 biosfn_set_cursor_shape(lines - 4, lines - 3);
277 SET_BDA(char_height, lines);
278 u16 vde = vgahw_get_vde();
279 u8 rows = vde / lines;
280 SET_BDA(video_rows, rows - 1);
281 u16 cols = GET_BDA(video_cols);
282 SET_BDA(video_pagesize, rows * cols * 2);
286 biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
288 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
289 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
290 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
291 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
292 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
293 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
294 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
295 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
296 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
297 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
300 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
301 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
302 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
304 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
305 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
309 biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
311 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
312 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
313 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
314 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
315 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
316 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
317 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
318 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
319 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
320 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
322 for (i = 0; i < 8; i++)
323 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
324 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
325 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
327 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
328 , GET_FARVAR(seg, info->font0_off));
329 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
330 , GET_FARVAR(seg, info->font1_off));
334 /****************************************************************
336 ****************************************************************/
340 handle_1000(struct bregs *regs)
342 u8 noclearmem = regs->al & 0x80;
343 u8 mode = regs->al & 0x7f;
354 cirrus_set_video_mode(mode);
357 if (vbe_has_vbe_display())
358 dispi_set_enable(VBE_DISPI_DISABLED);
360 // find the entry in the video modes
361 struct vgamode_s *vmode_g = find_vga_entry(mode);
362 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
366 // Read the bios mode set control
367 u8 modeset_ctl = GET_BDA(modeset_ctl);
369 // Then we know the number of lines
372 // if palette loading (bit 3 of modeset ctl = 0)
373 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
374 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
376 // From which palette
377 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
378 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
380 // Always 256*3 values
381 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
383 for (i = palsize; i < 0x0100; i++) {
384 static u8 rgb[3] VAR16;
385 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
388 if ((modeset_ctl & 0x02) == 0x02)
389 biosfn_perform_gray_scale_summing(0x00, 0x100);
392 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
393 vgahw_set_mode(vparam_g);
395 if (noclearmem == 0x00)
396 clear_screen(vmode_g);
398 // Set CRTC address VGA or MDA
399 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
400 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
401 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
404 u16 cheight = GET_GLOBAL(vparam_g->cheight);
405 SET_BDA(video_mode, mode);
406 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
407 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
408 SET_BDA(crtc_address, crtc_addr);
409 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
410 SET_BDA(char_height, cheight);
411 SET_BDA(video_ctl, (0x60 | noclearmem));
412 SET_BDA(video_switches, 0xF9);
413 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
415 // FIXME We nearly have the good tables. to be reworked
416 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
417 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
418 SET_BDA(video_savetable_seg, get_global_seg());
421 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
422 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
425 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
426 biosfn_set_cursor_shape(0x06, 0x07);
427 // Set cursor pos for page 0..7
429 for (i = 0; i < 8; i++) {
430 struct cursorpos cp = {0, 0, i};
435 biosfn_set_active_page(0x00);
437 // Write the fonts in memory
438 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
439 call16_vgaint(0x1104, 0);
440 call16_vgaint(0x1103, 0);
442 // Set the ints 0x1F and 0x43
443 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
447 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
450 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
453 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
459 handle_1001(struct bregs *regs)
461 biosfn_set_cursor_shape(regs->ch, regs->cl);
465 handle_1002(struct bregs *regs)
467 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
472 handle_1003(struct bregs *regs)
474 regs->cx = biosfn_get_cursor_shape(regs->bh);
475 struct cursorpos cp = get_cursor_pos(regs->bh);
480 // Read light pen pos (unimplemented)
482 handle_1004(struct bregs *regs)
485 regs->ax = regs->bx = regs->cx = regs->dx = 0;
489 handle_1005(struct bregs *regs)
491 biosfn_set_active_page(regs->al);
495 verify_scroll(struct bregs *regs, int dir)
497 u8 page = GET_BDA(video_page);
498 struct cursorpos ul = {regs->cl, regs->ch, page};
499 struct cursorpos lr = {regs->dl, regs->dh, page};
501 u16 nbrows = GET_BDA(video_rows) + 1;
504 u16 nbcols = GET_BDA(video_cols);
508 if (ul.x > lr.x || ul.y > lr.y)
511 u16 nblines = regs->al;
512 if (!nblines || nblines > lr.y - ul.y + 1)
513 nblines = lr.y - ul.y + 1;
515 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
519 handle_1006(struct bregs *regs)
521 verify_scroll(regs, 1);
525 handle_1007(struct bregs *regs)
527 verify_scroll(regs, -1);
531 handle_1008(struct bregs *regs)
533 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
539 write_chars(u8 page, struct carattr ca, u16 count)
541 struct cursorpos cp = get_cursor_pos(page);
543 vgafb_write_char(cp, ca);
549 handle_1009(struct bregs *regs)
551 struct carattr ca = {regs->al, regs->bl, 1};
552 write_chars(regs->bh, ca, regs->cx);
556 handle_100a(struct bregs *regs)
558 struct carattr ca = {regs->al, regs->bl, 0};
559 write_chars(regs->bh, ca, regs->cx);
564 handle_100b00(struct bregs *regs)
566 vgahw_set_border_color(regs->bl);
570 handle_100b01(struct bregs *regs)
572 vgahw_set_palette(regs->bl);
576 handle_100bXX(struct bregs *regs)
582 handle_100b(struct bregs *regs)
585 case 0x00: handle_100b00(regs); break;
586 case 0x01: handle_100b01(regs); break;
587 default: handle_100bXX(regs); break;
593 handle_100c(struct bregs *regs)
596 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
600 handle_100d(struct bregs *regs)
603 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, ®s->ax);
607 handle_100e(struct bregs *regs)
609 // Ralf Brown Interrupt list is WRONG on bh(page)
610 // We do output only on the current page !
611 struct carattr ca = {regs->al, regs->bl, 0};
612 struct cursorpos cp = get_cursor_pos(0xff);
613 write_teletype(&cp, ca);
618 handle_100f(struct bregs *regs)
620 regs->bh = GET_BDA(video_page);
621 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
622 regs->ah = GET_BDA(video_cols);
627 handle_101000(struct bregs *regs)
631 vgahw_set_single_palette_reg(regs->bl, regs->bh);
635 handle_101001(struct bregs *regs)
637 vgahw_set_overscan_border_color(regs->bh);
641 handle_101002(struct bregs *regs)
643 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
647 handle_101003(struct bregs *regs)
649 vgahw_toggle_intensity(regs->bl);
653 handle_101007(struct bregs *regs)
657 regs->bh = vgahw_get_single_palette_reg(regs->bl);
661 handle_101008(struct bregs *regs)
663 regs->bh = vgahw_get_overscan_border_color(regs);
667 handle_101009(struct bregs *regs)
669 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
673 handle_101010(struct bregs *regs)
675 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
676 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
680 handle_101012(struct bregs *regs)
682 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
686 handle_101013(struct bregs *regs)
688 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
692 handle_101015(struct bregs *regs)
695 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
702 handle_101017(struct bregs *regs)
704 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
708 handle_101018(struct bregs *regs)
710 vgahw_set_pel_mask(regs->bl);
714 handle_101019(struct bregs *regs)
716 regs->bl = vgahw_get_pel_mask();
720 handle_10101a(struct bregs *regs)
722 vgahw_read_video_dac_state(®s->bl, ®s->bh);
726 handle_10101b(struct bregs *regs)
728 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
732 handle_1010XX(struct bregs *regs)
738 handle_1010(struct bregs *regs)
741 case 0x00: handle_101000(regs); break;
742 case 0x01: handle_101001(regs); break;
743 case 0x02: handle_101002(regs); break;
744 case 0x03: handle_101003(regs); break;
745 case 0x07: handle_101007(regs); break;
746 case 0x08: handle_101008(regs); break;
747 case 0x09: handle_101009(regs); break;
748 case 0x10: handle_101010(regs); break;
749 case 0x12: handle_101012(regs); break;
750 case 0x13: handle_101013(regs); break;
751 case 0x15: handle_101015(regs); break;
752 case 0x17: handle_101017(regs); break;
753 case 0x18: handle_101018(regs); break;
754 case 0x19: handle_101019(regs); break;
755 case 0x1a: handle_10101a(regs); break;
756 case 0x1b: handle_10101b(regs); break;
757 default: handle_1010XX(regs); break;
763 handle_101100(struct bregs *regs)
765 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
766 , regs->dx, regs->bl, regs->bh);
770 handle_101101(struct bregs *regs)
772 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
776 handle_101102(struct bregs *regs)
778 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
782 handle_101103(struct bregs *regs)
784 vgahw_set_text_block_specifier(regs->bl);
788 handle_101104(struct bregs *regs)
790 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
794 handle_101110(struct bregs *regs)
796 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
797 , regs->dx, regs->bl, regs->bh);
798 set_scan_lines(regs->bh);
802 handle_101111(struct bregs *regs)
804 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
809 handle_101112(struct bregs *regs)
811 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
816 handle_101114(struct bregs *regs)
818 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
823 handle_101130(struct bregs *regs)
827 u32 segoff = GET_IVT(0x1f).segoff;
828 regs->es = segoff >> 16;
833 u32 segoff = GET_IVT(0x43).segoff;
834 regs->es = segoff >> 16;
839 regs->es = get_global_seg();
840 regs->bp = (u32)vgafont14;
843 regs->es = get_global_seg();
844 regs->bp = (u32)vgafont8;
847 regs->es = get_global_seg();
848 regs->bp = (u32)vgafont8 + 128 * 8;
851 regs->es = get_global_seg();
852 regs->bp = (u32)vgafont14alt;
855 regs->es = get_global_seg();
856 regs->bp = (u32)vgafont16;
859 regs->es = get_global_seg();
860 regs->bp = (u32)vgafont16alt;
863 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
866 // Set byte/char of on screen font
867 regs->cx = GET_BDA(char_height) & 0xff;
869 // Set Highest char row
870 regs->dx = GET_BDA(video_rows);
874 handle_1011XX(struct bregs *regs)
880 handle_1011(struct bregs *regs)
883 case 0x00: handle_101100(regs); break;
884 case 0x01: handle_101101(regs); break;
885 case 0x02: handle_101102(regs); break;
886 case 0x03: handle_101103(regs); break;
887 case 0x04: handle_101104(regs); break;
888 case 0x10: handle_101110(regs); break;
889 case 0x11: handle_101111(regs); break;
890 case 0x12: handle_101112(regs); break;
891 case 0x14: handle_101114(regs); break;
892 case 0x30: handle_101130(regs); break;
893 default: handle_1011XX(regs); break;
899 handle_101210(struct bregs *regs)
901 u16 crtc_addr = GET_BDA(crtc_address);
902 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
906 regs->cx = GET_BDA(video_switches) & 0x0f;
910 handle_101230(struct bregs *regs)
912 u8 mctl = GET_BDA(modeset_ctl);
913 u8 vswt = GET_BDA(video_switches);
917 mctl = (mctl & ~0x10) | 0x80;
918 vswt = (vswt & ~0x0f) | 0x08;
923 vswt = (vswt & ~0x0f) | 0x09;
927 mctl = (mctl & ~0x80) | 0x10;
928 vswt = (vswt & ~0x0f) | 0x09;
931 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
934 SET_BDA(modeset_ctl, mctl);
935 SET_BDA(video_switches, vswt);
940 handle_101231(struct bregs *regs)
942 u8 v = (regs->al & 0x01) << 3;
943 u8 mctl = GET_BDA(video_ctl) & ~0x08;
944 SET_BDA(video_ctl, mctl | v);
949 handle_101232(struct bregs *regs)
951 vgahw_enable_video_addressing(regs->al);
956 handle_101233(struct bregs *regs)
958 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
959 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
960 SET_BDA(modeset_ctl, v | v2);
965 handle_101234(struct bregs *regs)
967 u8 v = (regs->al & 0x01) ^ 0x01;
968 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
969 SET_BDA(modeset_ctl, v | v2);
974 handle_101235(struct bregs *regs)
981 handle_101236(struct bregs *regs)
988 handle_1012XX(struct bregs *regs)
994 handle_1012(struct bregs *regs)
997 case 0x10: handle_101210(regs); break;
998 case 0x30: handle_101230(regs); break;
999 case 0x31: handle_101231(regs); break;
1000 case 0x32: handle_101232(regs); break;
1001 case 0x33: handle_101233(regs); break;
1002 case 0x34: handle_101234(regs); break;
1003 case 0x35: handle_101235(regs); break;
1004 case 0x36: handle_101236(regs); break;
1005 default: handle_1012XX(regs); break;
1008 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1013 static void noinline
1014 handle_1013(struct bregs *regs)
1016 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1017 // if row=0xff special case : use current cursor position
1019 cp = get_cursor_pos(cp.page);
1022 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1024 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1032 handle_101a00(struct bregs *regs)
1034 regs->bx = GET_BDA(dcc_index);
1039 handle_101a01(struct bregs *regs)
1041 SET_BDA(dcc_index, regs->bl);
1042 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1047 handle_101aXX(struct bregs *regs)
1053 handle_101a(struct bregs *regs)
1056 case 0x00: handle_101a00(regs); break;
1057 case 0x01: handle_101a01(regs); break;
1058 default: handle_101aXX(regs); break;
1064 u16 static_functionality_off;
1065 u16 static_functionality_seg;
1085 handle_101b(struct bregs *regs)
1088 struct funcInfo *info = (void*)(regs->di+0);
1089 memset_far(seg, info, 0, sizeof(*info));
1090 // Address of static functionality table
1091 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1092 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1094 // Hard coded copy from BIOS area. Should it be cleaner ?
1095 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1096 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1098 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1099 SET_FARVAR(seg, info->colors, 16);
1100 SET_FARVAR(seg, info->pages, 8);
1101 SET_FARVAR(seg, info->scan_lines, 2);
1102 SET_FARVAR(seg, info->video_mem, 3);
1108 handle_101c00(struct bregs *regs)
1110 u16 flags = regs->cx;
1113 size += sizeof(struct saveVideoHardware);
1115 size += sizeof(struct saveBDAstate);
1117 size += sizeof(struct saveDACcolors);
1123 handle_101c01(struct bregs *regs)
1125 u16 flags = regs->cx;
1127 void *data = (void*)(regs->bx+0);
1129 vgahw_save_state(seg, data);
1130 data += sizeof(struct saveVideoHardware);
1133 biosfn_save_bda_state(seg, data);
1134 data += sizeof(struct saveBDAstate);
1137 vgahw_save_dac_state(seg, data);
1142 handle_101c02(struct bregs *regs)
1144 u16 flags = regs->cx;
1146 void *data = (void*)(regs->bx+0);
1148 vgahw_restore_state(seg, data);
1149 data += sizeof(struct saveVideoHardware);
1152 biosfn_restore_bda_state(seg, data);
1153 data += sizeof(struct saveBDAstate);
1156 vgahw_restore_dac_state(seg, data);
1161 handle_101cXX(struct bregs *regs)
1167 handle_101c(struct bregs *regs)
1170 case 0x00: handle_101c00(regs); break;
1171 case 0x01: handle_101c01(regs); break;
1172 case 0x02: handle_101c02(regs); break;
1173 default: handle_101cXX(regs); break;
1179 handle_104f00(struct bregs *regs)
1181 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1182 // XXX - OR cirrus_vesa_00h
1186 handle_104f01(struct bregs *regs)
1188 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1189 // XXX - OR cirrus_vesa_01h
1193 handle_104f02(struct bregs *regs)
1195 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1196 // XXX - OR cirrus_vesa_02h
1200 handle_104f03(struct bregs *regs)
1202 // XXX - vbe_biosfn_return_current_mode
1203 // XXX - OR cirrus_vesa_03h
1207 handle_104f04(struct bregs *regs)
1209 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1213 handle_104f05(struct bregs *regs)
1215 // XXX - vbe_biosfn_display_window_control
1216 // XXX - OR cirrus_vesa_05h
1220 handle_104f06(struct bregs *regs)
1222 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1223 // XXX - OR cirrus_vesa_06h
1227 handle_104f07(struct bregs *regs)
1229 // XXX - vbe_biosfn_set_get_display_start
1230 // XXX - OR cirrus_vesa_07h
1234 handle_104f08(struct bregs *regs)
1236 // XXX - vbe_biosfn_set_get_dac_palette_format
1240 handle_104f0a(struct bregs *regs)
1242 // XXX - vbe_biosfn_return_protected_mode_interface
1246 handle_104fXX(struct bregs *regs)
1253 handle_104f(struct bregs *regs)
1255 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
1256 handle_104fXX(regs);
1261 case 0x00: handle_104f00(regs); break;
1262 case 0x01: handle_104f01(regs); break;
1263 case 0x02: handle_104f02(regs); break;
1264 case 0x03: handle_104f03(regs); break;
1265 case 0x04: handle_104f04(regs); break;
1266 case 0x05: handle_104f05(regs); break;
1267 case 0x06: handle_104f06(regs); break;
1268 case 0x07: handle_104f07(regs); break;
1269 case 0x08: handle_104f08(regs); break;
1270 case 0x0a: handle_104f0a(regs); break;
1271 default: handle_104fXX(regs); break;
1277 handle_10XX(struct bregs *regs)
1282 // INT 10h Video Support Service Entry Point
1284 handle_10(struct bregs *regs)
1286 debug_enter(regs, DEBUG_VGA_10);
1288 case 0x00: handle_1000(regs); break;
1289 case 0x01: handle_1001(regs); break;
1290 case 0x02: handle_1002(regs); break;
1291 case 0x03: handle_1003(regs); break;
1292 case 0x04: handle_1004(regs); break;
1293 case 0x05: handle_1005(regs); break;
1294 case 0x06: handle_1006(regs); break;
1295 case 0x07: handle_1007(regs); break;
1296 case 0x08: handle_1008(regs); break;
1297 case 0x09: handle_1009(regs); break;
1298 case 0x0a: handle_100a(regs); break;
1299 case 0x0b: handle_100b(regs); break;
1300 case 0x0c: handle_100c(regs); break;
1301 case 0x0d: handle_100d(regs); break;
1302 case 0x0e: handle_100e(regs); break;
1303 case 0x0f: handle_100f(regs); break;
1304 case 0x10: handle_1010(regs); break;
1305 case 0x11: handle_1011(regs); break;
1306 case 0x12: handle_1012(regs); break;
1307 case 0x13: handle_1013(regs); break;
1308 case 0x1a: handle_101a(regs); break;
1309 case 0x1b: handle_101b(regs); break;
1310 case 0x1c: handle_101c(regs); break;
1311 case 0x4f: handle_104f(regs); break;
1312 default: handle_10XX(regs); break;
1317 /****************************************************************
1319 ****************************************************************/
1324 // init detected hardware BIOS Area
1325 // set 80x25 color (not clear from RBIL but usual)
1326 u16 eqf = GET_BDA(equipment_list_flags);
1327 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1329 // Just for the first int10 find its children
1331 // the default char height
1332 SET_BDA(char_height, 0x10);
1335 SET_BDA(video_ctl, 0x60);
1337 // Set the basic screen we have
1338 SET_BDA(video_switches, 0xf9);
1340 // Set the basic modeset options
1341 SET_BDA(modeset_ctl, 0x51);
1343 // Set the default MSR
1344 SET_BDA(video_msr, 0x09);
1348 vga_post(struct bregs *regs)
1350 debug_enter(regs, DEBUG_VGA_POST);
1359 extern void entry_10(void);
1360 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
1365 // XXX - clear screen and display info
1368 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
1369 SET_VGA(video_save_pointer_table[1], get_global_seg());
1372 extern u8 _rom_header_size, _rom_header_checksum;
1373 SET_VGA(_rom_header_checksum, 0);
1374 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
1375 SET_VGA(_rom_header_checksum, sum);