blob: ba07584fd722d7bc4c378669670014cbbf5f04f4 [file] [log] [blame]
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001// VGA bios implementation
2//
3// Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2001-2008 the LGPL VGABios developers Team
5//
6// This file may be distributed under the terms of the GNU LGPLv3 license.
7
8
9// TODO:
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040010// * review correctness of converted asm by comparing with RBIL
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040011//
Kevin O'Connor6ace78f2009-05-14 19:24:49 -040012// * convert vbe/clext code
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040013
14#include "bregs.h" // struct bregs
15#include "biosvar.h" // GET_BDA
16#include "util.h" // memset
Kevin O'Connorc0c7df62009-05-17 18:11:33 -040017#include "vgatables.h" // find_vga_entry
Julian Pidancet7c6509c2011-12-19 05:07:55 +000018#include "optionroms.h" // struct pci_data
19#include "config.h" // CONFIG_*
Julian Pidancet87879e22011-12-19 05:08:00 +000020#include "vbe.h" // vbe_*
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040021
22// XXX
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040023#define DEBUG_VGA_POST 1
24#define DEBUG_VGA_10 3
25
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040026
Julian Pidancet7c6509c2011-12-19 05:07:55 +000027/****************************************************************
28 * PCI Data
29 ****************************************************************/
30#if CONFIG_VGA_PCI == 1
31struct pci_data rom_pci_data VAR16VISIBLE = {
32 .signature = PCI_ROM_SIGNATURE,
33 .vendor = CONFIG_VGA_VID,
34 .device = CONFIG_VGA_DID,
35 .dlen = 0x18,
36 .class_hi = 0x300,
37 .irevision = 1,
38 .type = PCIROM_CODETYPE_X86,
39 .indicator = 0x80,
40};
41#endif
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040042
43/****************************************************************
44 * Helper functions
45 ****************************************************************/
46
Kevin O'Connor217f2bc2009-05-31 00:46:47 -040047static inline void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040048call16_vgaint(u32 eax, u32 ebx)
49{
50 asm volatile(
51 "int $0x10\n"
52 "cli\n"
53 "cld"
54 :
55 : "a"(eax), "b"(ebx)
56 : "cc", "memory");
57}
58
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040059static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040060perform_gray_scale_summing(u16 start, u16 count)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040061{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040062 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040063 int i;
64 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040065 u8 rgb[3];
66 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040067
68 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040069 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040070 if (intensity > 0x3f)
71 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040072
Kevin O'Connora0ecb052009-05-18 23:34:00 -040073 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040074 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040075 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040076}
77
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040078static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040079set_cursor_shape(u8 start, u8 end)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040080{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040081 start &= 0x3f;
82 end &= 0x1f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040083
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040084 u16 curs = (start << 8) + end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040085 SET_BDA(cursor_type, curs);
86
Kevin O'Connordd2be772009-05-16 15:41:23 -040087 u8 modeset_ctl = GET_BDA(modeset_ctl);
88 u16 cheight = GET_BDA(char_height);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040089 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
90 if (end != (start + 1))
91 start = ((start + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040092 else
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040093 start = ((end + 1) * cheight / 8) - 2;
94 end = ((end + 1) * cheight / 8) - 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040095 }
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040096 vgahw_set_cursor_shape(start, end);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040097}
98
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040099static u16
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400100get_cursor_shape(u8 page)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400101{
102 if (page > 7)
103 return 0;
104 // FIXME should handle VGA 14/16 lines
105 return GET_BDA(cursor_type);
106}
107
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400108static void
Kevin O'Connor918b1562009-05-25 11:05:18 -0400109set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400110{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400111 // Should not happen...
Kevin O'Connor918b1562009-05-25 11:05:18 -0400112 if (cp.page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400113 return;
114
115 // Bios cursor pos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400116 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400117
118 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400119 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400120 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400121 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400122
Kevin O'Connordd2be772009-05-16 15:41:23 -0400123 // Get the dimensions
124 u16 nbcols = GET_BDA(video_cols);
125 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400126
Kevin O'Connordd2be772009-05-16 15:41:23 -0400127 // Calculate the address knowing nbcols nbrows and page num
Kevin O'Connor918b1562009-05-25 11:05:18 -0400128 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
129 + cp.x + cp.y * nbcols);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400130
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400131 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400132}
133
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400134static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400135get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400136{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400137 if (page == 0xff)
138 // special case - use current page
139 page = GET_BDA(video_page);
140 if (page > 7) {
141 struct cursorpos cp = { 0, 0, 0xfe };
142 return cp;
143 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400144 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400145 u16 xy = GET_BDA(cursor_pos[page]);
146 struct cursorpos cp = {xy, xy>>8, page};
147 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400148}
149
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400150static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400151set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400152{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400153 if (page > 7)
154 return;
155
156 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400157 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
158 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400159 return;
160
161 // Get pos curs pos for the right page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400162 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400163
Kevin O'Connordd2be772009-05-16 15:41:23 -0400164 u16 address;
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400165 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400166 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400167 u16 nbcols = GET_BDA(video_cols);
168 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400169
170 // Calculate the address knowing nbcols nbrows and page num
171 address = SCREEN_MEM_START(nbcols, nbrows, page);
172 SET_BDA(video_pagestart, address);
173
174 // Start address
175 address = SCREEN_IO_START(nbcols, nbrows, page);
176 } else {
Kevin O'Connor87233e92011-12-23 21:40:34 -0500177 address = page * GET_GLOBAL(vmode_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400178 }
179
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400180 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400181
182 // And change the BIOS page
183 SET_BDA(video_page, page);
184
Kevin O'Connora12c2152009-05-13 22:06:16 -0400185 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400186
187 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400188 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400189}
190
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400191static void
192set_scan_lines(u8 lines)
193{
194 vgahw_set_scan_lines(lines);
195 if (lines == 8)
196 set_cursor_shape(0x06, 0x07);
197 else
198 set_cursor_shape(lines - 4, lines - 3);
199 SET_BDA(char_height, lines);
200 u16 vde = vgahw_get_vde();
201 u8 rows = vde / lines;
202 SET_BDA(video_rows, rows - 1);
203 u16 cols = GET_BDA(video_cols);
204 SET_BDA(video_pagesize, rows * cols * 2);
205}
206
207
208/****************************************************************
209 * Character writing
210 ****************************************************************/
211
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400212// Scroll the screen one line. This function is designed to be called
213// tail-recursive to reduce stack usage.
214static void noinline
215scroll_one(u16 nbrows, u16 nbcols, u8 page)
Kevin O'Connor09262412009-05-25 11:44:11 -0400216{
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400217 struct cursorpos ul = {0, 0, page};
218 struct cursorpos lr = {nbcols-1, nbrows-1, page};
219 vgafb_scroll(1, -1, ul, lr);
220}
221
222// Write a character to the screen at a given position. Implement
223// special characters and scroll the screen if necessary.
224static void
225write_teletype(struct cursorpos *pcp, struct carattr ca)
226{
227 struct cursorpos cp = *pcp;
228
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400229 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400230 u16 nbrows = GET_BDA(video_rows) + 1;
231 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400232
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400233 switch (ca.car) {
234 case 7:
235 //FIXME should beep
236 break;
237 case 8:
238 if (cp.x > 0)
239 cp.x--;
240 break;
241 case '\r':
242 cp.x = 0;
243 break;
244 case '\n':
245 cp.y++;
246 break;
247 case '\t':
248 do {
249 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
250 vgafb_write_char(cp, dummyca);
251 cp.x++;
252 } while (cp.x < nbcols && cp.x % 8);
253 break;
254 default:
255 vgafb_write_char(cp, ca);
256 cp.x++;
257 }
258
Kevin O'Connor82221b22009-05-26 00:20:40 -0400259 // Do we need to wrap ?
260 if (cp.x == nbcols) {
261 cp.x = 0;
262 cp.y++;
263 }
264 // Do we need to scroll ?
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400265 if (cp.y < nbrows) {
266 *pcp = cp;
267 return;
Kevin O'Connor82221b22009-05-26 00:20:40 -0400268 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400269 // Scroll screen
270 cp.y--;
271 *pcp = cp;
272 scroll_one(nbrows, nbcols, cp.page);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400273}
274
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400275// Write out a buffer of alternating characters and attributes.
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400276static void
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400277write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400278{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400279 while (count--) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400280 u8 car = GET_FARVAR(seg, *offset_far);
281 offset_far++;
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400282 u8 attr = GET_FARVAR(seg, *offset_far);
283 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400284
Kevin O'Connor09262412009-05-25 11:44:11 -0400285 struct carattr ca = {car, attr, 1};
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400286 write_teletype(pcp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400287 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400288}
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400289
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400290// Write out a buffer of characters.
291static void
292write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
293{
294 while (count--) {
295 u8 car = GET_FARVAR(seg, *offset_far);
296 offset_far++;
297
298 struct carattr ca = {car, attr, 1};
299 write_teletype(pcp, ca);
300 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400301}
302
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400303
304/****************************************************************
305 * Save and restore bda state
306 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400307
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400308static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400309save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400310{
Kevin O'Connorca668642009-05-21 23:06:08 -0400311 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
312 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
313 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
314 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
315 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
316 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
317 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
318 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
319 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
320 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
321 u16 i;
322 for (i=0; i<8; i++)
323 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
324 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
325 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
326 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400327 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
328 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400329}
330
Kevin O'Connorca668642009-05-21 23:06:08 -0400331static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400332restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400333{
Kevin O'Connorca668642009-05-21 23:06:08 -0400334 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
335 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
336 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
337 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
338 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
339 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
340 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
341 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
342 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
343 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
344 u16 i;
345 for (i = 0; i < 8; i++)
346 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
347 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
348 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
349 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400350 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
351 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400352}
353
354
355/****************************************************************
356 * VGA int 10 handler
357 ****************************************************************/
358
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400359// set video mode
Julian Pidancet87879e22011-12-19 05:08:00 +0000360void
361vga_set_mode(u8 mode, u8 noclearmem)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400362{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400363 // find the entry in the video modes
364 struct vgamode_s *vmode_g = find_vga_entry(mode);
365 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
366 if (!vmode_g)
367 return;
368
369 // Read the bios mode set control
370 u8 modeset_ctl = GET_BDA(modeset_ctl);
371
372 // Then we know the number of lines
373// FIXME
374
375 // if palette loading (bit 3 of modeset ctl = 0)
376 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
377 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
378
379 // From which palette
380 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
381 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
382
383 // Always 256*3 values
384 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
385 u16 i;
386 for (i = palsize; i < 0x0100; i++) {
387 static u8 rgb[3] VAR16;
388 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
389 }
390
391 if ((modeset_ctl & 0x02) == 0x02)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400392 perform_gray_scale_summing(0x00, 0x100);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400393 }
394
Kevin O'Connor87233e92011-12-23 21:40:34 -0500395 vgahw_set_mode(vmode_g);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400396
397 if (noclearmem == 0x00)
398 clear_screen(vmode_g);
399
400 // Set CRTC address VGA or MDA
401 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
402 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
403 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
404
405 // Set the BIOS mem
Kevin O'Connor87233e92011-12-23 21:40:34 -0500406 u16 cheight = GET_GLOBAL(vmode_g->cheight);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400407 SET_BDA(video_mode, mode);
Kevin O'Connor87233e92011-12-23 21:40:34 -0500408 SET_BDA(video_cols, GET_GLOBAL(vmode_g->twidth));
409 SET_BDA(video_pagesize, GET_GLOBAL(vmode_g->slength));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400410 SET_BDA(crtc_address, crtc_addr);
Kevin O'Connor87233e92011-12-23 21:40:34 -0500411 SET_BDA(video_rows, GET_GLOBAL(vmode_g->theight)-1);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400412 SET_BDA(char_height, cheight);
413 SET_BDA(video_ctl, (0x60 | noclearmem));
414 SET_BDA(video_switches, 0xF9);
415 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
416
417 // FIXME We nearly have the good tables. to be reworked
418 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
Kevin O'Connor9f985422009-09-09 11:34:39 -0400419 SET_BDA(video_savetable
Kevin O'Connor815e4472011-12-21 09:05:32 -0500420 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400421
422 // FIXME
423 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
424 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
425
426 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400427 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400428 set_cursor_shape(0x06, 0x07);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400429 // Set cursor pos for page 0..7
430 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400431 for (i = 0; i < 8; i++) {
432 struct cursorpos cp = {0, 0, i};
433 set_cursor_pos(cp);
434 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400435
436 // Set active page 0
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400437 set_active_page(0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400438
439 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400440 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400441 call16_vgaint(0x1104, 0);
442 call16_vgaint(0x1103, 0);
443 }
444 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400445 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400446
447 switch (cheight) {
448 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400449 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400450 break;
451 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400452 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400453 break;
454 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400455 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400456 break;
457 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400458}
459
460static void
Julian Pidancet87879e22011-12-19 05:08:00 +0000461handle_1000(struct bregs *regs)
462{
463 u8 noclearmem = regs->al & 0x80;
464 u8 mode = regs->al & 0x7f;
465
466 // Set regs->al
467 if (mode > 7)
468 regs->al = 0x20;
469 else if (mode == 6)
470 regs->al = 0x3f;
471 else
472 regs->al = 0x30;
473
Kevin O'Connore48a5372011-12-20 23:56:14 -0500474 if (CONFIG_VGA_CIRRUS) {
475 int ret = cirrus_set_video_mode(mode, noclearmem);
476 if (ret)
477 return;
478 }
Julian Pidancet87879e22011-12-19 05:08:00 +0000479
480 if (vbe_enabled())
481 vbe_hires_enable(0);
482
483 vga_set_mode(mode, noclearmem);
484}
485
486static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400487handle_1001(struct bregs *regs)
488{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400489 set_cursor_shape(regs->ch, regs->cl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400490}
491
492static void
493handle_1002(struct bregs *regs)
494{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400495 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
496 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400497}
498
499static void
500handle_1003(struct bregs *regs)
501{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400502 regs->cx = get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400503 struct cursorpos cp = get_cursor_pos(regs->bh);
504 regs->dl = cp.x;
505 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400506}
507
508// Read light pen pos (unimplemented)
509static void
510handle_1004(struct bregs *regs)
511{
512 debug_stub(regs);
513 regs->ax = regs->bx = regs->cx = regs->dx = 0;
514}
515
516static void
517handle_1005(struct bregs *regs)
518{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400519 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400520}
521
522static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400523verify_scroll(struct bregs *regs, int dir)
524{
525 u8 page = GET_BDA(video_page);
526 struct cursorpos ul = {regs->cl, regs->ch, page};
527 struct cursorpos lr = {regs->dl, regs->dh, page};
528
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400529 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400530 if (lr.y >= nbrows)
531 lr.y = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400532 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400533 if (lr.x >= nbcols)
534 lr.x = nbcols - 1;
535
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400536 if (ul.x > lr.x || ul.y > lr.y)
537 return;
538
539 u16 nblines = regs->al;
540 if (!nblines || nblines > lr.y - ul.y + 1)
541 nblines = lr.y - ul.y + 1;
542
543 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400544}
545
546static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400547handle_1006(struct bregs *regs)
548{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400549 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400550}
551
552static void
553handle_1007(struct bregs *regs)
554{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400555 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400556}
557
558static void
559handle_1008(struct bregs *regs)
560{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400561 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400562 regs->al = ca.car;
563 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400564}
565
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400566static void noinline
Kevin O'Connord3b38152009-05-26 00:05:37 -0400567write_chars(u8 page, struct carattr ca, u16 count)
568{
569 struct cursorpos cp = get_cursor_pos(page);
570 while (count--) {
571 vgafb_write_char(cp, ca);
572 cp.x++;
573 }
574}
575
576static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400577handle_1009(struct bregs *regs)
578{
Kevin O'Connor09262412009-05-25 11:44:11 -0400579 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400580 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400581}
582
583static void
584handle_100a(struct bregs *regs)
585{
Kevin O'Connor09262412009-05-25 11:44:11 -0400586 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400587 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400588}
589
590
591static void
592handle_100b00(struct bregs *regs)
593{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400594 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400595}
596
597static void
598handle_100b01(struct bregs *regs)
599{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400600 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400601}
602
603static void
604handle_100bXX(struct bregs *regs)
605{
606 debug_stub(regs);
607}
608
609static void
610handle_100b(struct bregs *regs)
611{
612 switch (regs->bh) {
613 case 0x00: handle_100b00(regs); break;
614 case 0x01: handle_100b01(regs); break;
615 default: handle_100bXX(regs); break;
616 }
617}
618
619
620static void
621handle_100c(struct bregs *regs)
622{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400623 // XXX - page (regs->bh) is unused
624 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400625}
626
627static void
628handle_100d(struct bregs *regs)
629{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400630 // XXX - page (regs->bh) is unused
631 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400632}
633
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400634static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400635handle_100e(struct bregs *regs)
636{
637 // Ralf Brown Interrupt list is WRONG on bh(page)
638 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400639 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400640 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400641 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400642 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400643}
644
645static void
646handle_100f(struct bregs *regs)
647{
Kevin O'Connore7132042009-05-25 00:10:35 -0400648 regs->bh = GET_BDA(video_page);
649 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
650 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400651}
652
653
654static void
655handle_101000(struct bregs *regs)
656{
657 if (regs->bl > 0x14)
658 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400659 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400660}
661
662static void
663handle_101001(struct bregs *regs)
664{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400665 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400666}
667
668static void
669handle_101002(struct bregs *regs)
670{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400671 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400672}
673
674static void
675handle_101003(struct bregs *regs)
676{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400677 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400678}
679
680static void
681handle_101007(struct bregs *regs)
682{
683 if (regs->bl > 0x14)
684 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400685 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400686}
687
688static void
689handle_101008(struct bregs *regs)
690{
Kevin O'Connor3862b2d2010-01-03 17:53:58 -0500691 regs->bh = vgahw_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400692}
693
694static void
695handle_101009(struct bregs *regs)
696{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400697 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400698}
699
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400700static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400701handle_101010(struct bregs *regs)
702{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400703 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
704 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400705}
706
707static void
708handle_101012(struct bregs *regs)
709{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400710 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400711}
712
713static void
714handle_101013(struct bregs *regs)
715{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400716 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400717}
718
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400719static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400720handle_101015(struct bregs *regs)
721{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400722 u8 rgb[3];
723 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
724 regs->dh = rgb[0];
725 regs->ch = rgb[1];
726 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400727}
728
729static void
730handle_101017(struct bregs *regs)
731{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400732 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400733}
734
735static void
736handle_101018(struct bregs *regs)
737{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400738 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400739}
740
741static void
742handle_101019(struct bregs *regs)
743{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400744 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400745}
746
747static void
748handle_10101a(struct bregs *regs)
749{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400750 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400751}
752
753static void
754handle_10101b(struct bregs *regs)
755{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400756 perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400757}
758
759static void
760handle_1010XX(struct bregs *regs)
761{
762 debug_stub(regs);
763}
764
765static void
766handle_1010(struct bregs *regs)
767{
768 switch (regs->al) {
769 case 0x00: handle_101000(regs); break;
770 case 0x01: handle_101001(regs); break;
771 case 0x02: handle_101002(regs); break;
772 case 0x03: handle_101003(regs); break;
773 case 0x07: handle_101007(regs); break;
774 case 0x08: handle_101008(regs); break;
775 case 0x09: handle_101009(regs); break;
776 case 0x10: handle_101010(regs); break;
777 case 0x12: handle_101012(regs); break;
778 case 0x13: handle_101013(regs); break;
779 case 0x15: handle_101015(regs); break;
780 case 0x17: handle_101017(regs); break;
781 case 0x18: handle_101018(regs); break;
782 case 0x19: handle_101019(regs); break;
783 case 0x1a: handle_10101a(regs); break;
784 case 0x1b: handle_10101b(regs); break;
785 default: handle_1010XX(regs); break;
786 }
787}
788
789
790static void
791handle_101100(struct bregs *regs)
792{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400793 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
794 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400795}
796
797static void
798handle_101101(struct bregs *regs)
799{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400800 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400801}
802
803static void
804handle_101102(struct bregs *regs)
805{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400806 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400807}
808
809static void
810handle_101103(struct bregs *regs)
811{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400812 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400813}
814
815static void
816handle_101104(struct bregs *regs)
817{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400818 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400819}
820
821static void
822handle_101110(struct bregs *regs)
823{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400824 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
825 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400826 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400827}
828
829static void
830handle_101111(struct bregs *regs)
831{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400832 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400833 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400834}
835
836static void
837handle_101112(struct bregs *regs)
838{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400839 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400840 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400841}
842
843static void
844handle_101114(struct bregs *regs)
845{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400846 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400847 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400848}
849
850static void
851handle_101130(struct bregs *regs)
852{
Kevin O'Connore7132042009-05-25 00:10:35 -0400853 switch (regs->bh) {
854 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500855 struct segoff_s so = GET_IVT(0x1f);
856 regs->es = so.seg;
857 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400858 break;
859 }
860 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500861 struct segoff_s so = GET_IVT(0x43);
862 regs->es = so.seg;
863 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400864 break;
865 }
866 case 0x02:
867 regs->es = get_global_seg();
868 regs->bp = (u32)vgafont14;
869 break;
870 case 0x03:
871 regs->es = get_global_seg();
872 regs->bp = (u32)vgafont8;
873 break;
874 case 0x04:
875 regs->es = get_global_seg();
876 regs->bp = (u32)vgafont8 + 128 * 8;
877 break;
878 case 0x05:
879 regs->es = get_global_seg();
880 regs->bp = (u32)vgafont14alt;
881 break;
882 case 0x06:
883 regs->es = get_global_seg();
884 regs->bp = (u32)vgafont16;
885 break;
886 case 0x07:
887 regs->es = get_global_seg();
888 regs->bp = (u32)vgafont16alt;
889 break;
890 default:
891 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
892 return;
893 }
894 // Set byte/char of on screen font
895 regs->cx = GET_BDA(char_height) & 0xff;
896
897 // Set Highest char row
898 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400899}
900
901static void
902handle_1011XX(struct bregs *regs)
903{
904 debug_stub(regs);
905}
906
907static void
908handle_1011(struct bregs *regs)
909{
910 switch (regs->al) {
911 case 0x00: handle_101100(regs); break;
912 case 0x01: handle_101101(regs); break;
913 case 0x02: handle_101102(regs); break;
914 case 0x03: handle_101103(regs); break;
915 case 0x04: handle_101104(regs); break;
916 case 0x10: handle_101110(regs); break;
917 case 0x11: handle_101111(regs); break;
918 case 0x12: handle_101112(regs); break;
919 case 0x14: handle_101114(regs); break;
920 case 0x30: handle_101130(regs); break;
921 default: handle_1011XX(regs); break;
922 }
923}
924
925
926static void
927handle_101210(struct bregs *regs)
928{
Kevin O'Connore7132042009-05-25 00:10:35 -0400929 u16 crtc_addr = GET_BDA(crtc_address);
930 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
931 regs->bx = 0x0103;
932 else
933 regs->bx = 0x0003;
934 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400935}
936
937static void
938handle_101230(struct bregs *regs)
939{
Kevin O'Connore7132042009-05-25 00:10:35 -0400940 u8 mctl = GET_BDA(modeset_ctl);
941 u8 vswt = GET_BDA(video_switches);
942 switch (regs->al) {
943 case 0x00:
944 // 200 lines
945 mctl = (mctl & ~0x10) | 0x80;
946 vswt = (vswt & ~0x0f) | 0x08;
947 break;
948 case 0x01:
949 // 350 lines
950 mctl &= ~0x90;
951 vswt = (vswt & ~0x0f) | 0x09;
952 break;
953 case 0x02:
954 // 400 lines
955 mctl = (mctl & ~0x80) | 0x10;
956 vswt = (vswt & ~0x0f) | 0x09;
957 break;
958 default:
959 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
960 break;
961 }
962 SET_BDA(modeset_ctl, mctl);
963 SET_BDA(video_switches, vswt);
964 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400965}
966
967static void
968handle_101231(struct bregs *regs)
969{
Kevin O'Connore7132042009-05-25 00:10:35 -0400970 u8 v = (regs->al & 0x01) << 3;
971 u8 mctl = GET_BDA(video_ctl) & ~0x08;
972 SET_BDA(video_ctl, mctl | v);
973 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400974}
975
976static void
977handle_101232(struct bregs *regs)
978{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400979 vgahw_enable_video_addressing(regs->al);
980 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400981}
982
983static void
984handle_101233(struct bregs *regs)
985{
Kevin O'Connore7132042009-05-25 00:10:35 -0400986 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
987 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
988 SET_BDA(modeset_ctl, v | v2);
989 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400990}
991
992static void
993handle_101234(struct bregs *regs)
994{
Kevin O'Connore7132042009-05-25 00:10:35 -0400995 u8 v = (regs->al & 0x01) ^ 0x01;
996 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
997 SET_BDA(modeset_ctl, v | v2);
998 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400999}
1000
1001static void
1002handle_101235(struct bregs *regs)
1003{
1004 debug_stub(regs);
1005 regs->al = 0x12;
1006}
1007
1008static void
1009handle_101236(struct bregs *regs)
1010{
1011 debug_stub(regs);
1012 regs->al = 0x12;
1013}
1014
1015static void
1016handle_1012XX(struct bregs *regs)
1017{
1018 debug_stub(regs);
1019}
1020
1021static void
1022handle_1012(struct bregs *regs)
1023{
1024 switch (regs->bl) {
1025 case 0x10: handle_101210(regs); break;
1026 case 0x30: handle_101230(regs); break;
1027 case 0x31: handle_101231(regs); break;
1028 case 0x32: handle_101232(regs); break;
1029 case 0x33: handle_101233(regs); break;
1030 case 0x34: handle_101234(regs); break;
1031 case 0x35: handle_101235(regs); break;
1032 case 0x36: handle_101236(regs); break;
1033 default: handle_1012XX(regs); break;
1034 }
1035
1036 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1037}
1038
1039
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001040// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -04001041static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001042handle_1013(struct bregs *regs)
1043{
Kevin O'Connor918b1562009-05-25 11:05:18 -04001044 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -04001045 // if row=0xff special case : use current cursor position
1046 if (cp.y == 0xff)
1047 cp = get_cursor_pos(cp.page);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001048 u8 flag = regs->al;
1049 if (flag & 2)
1050 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1051 else
1052 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1053
1054 if (flag & 1)
1055 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001056}
1057
1058
1059static void
1060handle_101a00(struct bregs *regs)
1061{
Kevin O'Connore7132042009-05-25 00:10:35 -04001062 regs->bx = GET_BDA(dcc_index);
1063 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001064}
1065
1066static void
1067handle_101a01(struct bregs *regs)
1068{
Kevin O'Connore7132042009-05-25 00:10:35 -04001069 SET_BDA(dcc_index, regs->bl);
1070 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1071 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001072}
1073
1074static void
1075handle_101aXX(struct bregs *regs)
1076{
1077 debug_stub(regs);
1078}
1079
1080static void
1081handle_101a(struct bregs *regs)
1082{
1083 switch (regs->al) {
1084 case 0x00: handle_101a00(regs); break;
1085 case 0x01: handle_101a01(regs); break;
1086 default: handle_101aXX(regs); break;
1087 }
1088}
1089
1090
Kevin O'Connorca668642009-05-21 23:06:08 -04001091struct funcInfo {
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001092 struct segoff_s static_functionality;
Kevin O'Connorca668642009-05-21 23:06:08 -04001093 u8 bda_0x49[30];
1094 u8 bda_0x84[3];
1095 u8 dcc_index;
1096 u8 dcc_alt;
1097 u16 colors;
1098 u8 pages;
1099 u8 scan_lines;
1100 u8 primary_char;
1101 u8 secondar_char;
1102 u8 misc;
1103 u8 non_vga_mode;
1104 u8 reserved_2f[2];
1105 u8 video_mem;
1106 u8 save_flags;
1107 u8 disp_info;
1108 u8 reserved_34[12];
1109};
1110
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001111static void
1112handle_101b(struct bregs *regs)
1113{
Kevin O'Connorca668642009-05-21 23:06:08 -04001114 u16 seg = regs->es;
1115 struct funcInfo *info = (void*)(regs->di+0);
1116 memset_far(seg, info, 0, sizeof(*info));
1117 // Address of static functionality table
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001118 SET_FARVAR(seg, info->static_functionality
1119 , SEGOFF(get_global_seg(), (u32)static_functionality));
Kevin O'Connorca668642009-05-21 23:06:08 -04001120
1121 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001122 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1123 , sizeof(info->bda_0x49));
1124 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1125 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001126
1127 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1128 SET_FARVAR(seg, info->colors, 16);
1129 SET_FARVAR(seg, info->pages, 8);
1130 SET_FARVAR(seg, info->scan_lines, 2);
1131 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001132 regs->al = 0x1B;
1133}
1134
1135
1136static void
1137handle_101c00(struct bregs *regs)
1138{
Kevin O'Connorca668642009-05-21 23:06:08 -04001139 u16 flags = regs->cx;
1140 u16 size = 0;
1141 if (flags & 1)
1142 size += sizeof(struct saveVideoHardware);
1143 if (flags & 2)
1144 size += sizeof(struct saveBDAstate);
1145 if (flags & 4)
1146 size += sizeof(struct saveDACcolors);
1147 regs->bx = size;
1148 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001149}
1150
1151static void
1152handle_101c01(struct bregs *regs)
1153{
Kevin O'Connorca668642009-05-21 23:06:08 -04001154 u16 flags = regs->cx;
1155 u16 seg = regs->es;
1156 void *data = (void*)(regs->bx+0);
1157 if (flags & 1) {
1158 vgahw_save_state(seg, data);
1159 data += sizeof(struct saveVideoHardware);
1160 }
1161 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001162 save_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001163 data += sizeof(struct saveBDAstate);
1164 }
1165 if (flags & 4)
1166 vgahw_save_dac_state(seg, data);
1167 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001168}
1169
1170static void
1171handle_101c02(struct bregs *regs)
1172{
Kevin O'Connorca668642009-05-21 23:06:08 -04001173 u16 flags = regs->cx;
1174 u16 seg = regs->es;
1175 void *data = (void*)(regs->bx+0);
1176 if (flags & 1) {
1177 vgahw_restore_state(seg, data);
1178 data += sizeof(struct saveVideoHardware);
1179 }
1180 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001181 restore_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001182 data += sizeof(struct saveBDAstate);
1183 }
1184 if (flags & 4)
1185 vgahw_restore_dac_state(seg, data);
1186 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001187}
1188
1189static void
1190handle_101cXX(struct bregs *regs)
1191{
1192 debug_stub(regs);
1193}
1194
1195static void
1196handle_101c(struct bregs *regs)
1197{
1198 switch (regs->al) {
1199 case 0x00: handle_101c00(regs); break;
1200 case 0x01: handle_101c01(regs); break;
1201 case 0x02: handle_101c02(regs); break;
1202 default: handle_101cXX(regs); break;
1203 }
1204}
1205
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001206static void
1207handle_104f00(struct bregs *regs)
1208{
Julian Pidancet87879e22011-12-19 05:08:00 +00001209 u16 seg = regs->es;
1210 struct vbe_info *info = (void*)(regs->di+0);
1211
1212 if (GET_FARVAR(seg, info->signature) == VBE2_SIGNATURE) {
1213 dprintf(4, "Get VBE Controller: VBE2 Signature found\n");
1214 } else if (GET_FARVAR(seg, info->signature) == VESA_SIGNATURE) {
1215 dprintf(4, "Get VBE Controller: VESA Signature found\n");
1216 } else {
1217 dprintf(4, "Get VBE Controller: Invalid Signature\n");
1218 }
1219
1220 memset_far(seg, info, 0, sizeof(*info));
1221
1222 SET_FARVAR(seg, info->signature, VESA_SIGNATURE);
1223
1224 SET_FARVAR(seg, info->version, 0x0200);
1225
1226 SET_FARVAR(seg, info->oem_string,
1227 SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING));
1228 SET_FARVAR(seg, info->capabilities[0], 0x1); /* 8BIT DAC */
1229
1230 /* We generate our mode list in the reserved field of the info block */
1231 SET_FARVAR(seg, info->video_mode, SEGOFF(seg, regs->di + 34));
1232
1233 /* Total memory (in 64 blocks) */
1234 SET_FARVAR(seg, info->total_memory, vbe_total_mem());
1235
1236 SET_FARVAR(seg, info->oem_vendor_string,
1237 SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING));
1238 SET_FARVAR(seg, info->oem_product_string,
1239 SEGOFF(get_global_seg(), (u32)VBE_PRODUCT_STRING));
1240 SET_FARVAR(seg, info->oem_revision_string,
1241 SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING));
1242
1243 /* Fill list of modes */
1244 vbe_list_modes(seg, regs->di + 32);
1245
1246 regs->al = regs->ah; /* 0x4F, Function supported */
1247 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001248}
1249
1250static void
1251handle_104f01(struct bregs *regs)
1252{
Julian Pidancet87879e22011-12-19 05:08:00 +00001253 u16 seg = regs->es;
1254 struct vbe_mode_info *info = (void*)(regs->di+0);
1255 u16 mode = regs->cx;
1256 struct vbe_modeinfo modeinfo;
1257 int rc;
1258
1259 dprintf(1, "VBE mode info request: %x\n", mode);
1260
1261 rc = vbe_mode_info(mode, &modeinfo);
1262 if (rc) {
1263 dprintf(1, "VBE mode %x not found\n", mode);
1264 regs->ax = 0x100;
1265 return;
1266 }
1267
1268 u16 mode_attr = VBE_MODE_ATTRIBUTE_SUPPORTED |
1269 VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE |
1270 VBE_MODE_ATTRIBUTE_COLOR_MODE |
1271 VBE_MODE_ATTRIBUTE_GRAPHICS_MODE;
1272 if (modeinfo.depth == 4)
1273 mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT;
1274 else
1275 mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE;
1276 SET_FARVAR(seg, info->mode_attributes, mode_attr);
1277 SET_FARVAR(seg, info->winA_attributes,
1278 VBE_WINDOW_ATTRIBUTE_RELOCATABLE |
1279 VBE_WINDOW_ATTRIBUTE_READABLE |
1280 VBE_WINDOW_ATTRIBUTE_WRITEABLE);
1281 SET_FARVAR(seg, info->winB_attributes, 0);
1282 SET_FARVAR(seg, info->win_granularity, 64); /* Bank size 64K */
1283 SET_FARVAR(seg, info->win_size, 64); /* Bank size 64K */
1284 SET_FARVAR(seg, info->winA_seg, 0xA000);
1285 SET_FARVAR(seg, info->winB_seg, 0x0);
1286 SET_FARVAR(seg, info->win_func_ptr, 0x0);
1287 SET_FARVAR(seg, info->bytes_per_scanline, modeinfo.linesize);
1288 SET_FARVAR(seg, info->xres, modeinfo.width);
1289 SET_FARVAR(seg, info->yres, modeinfo.height);
1290 SET_FARVAR(seg, info->xcharsize, 8);
1291 SET_FARVAR(seg, info->ycharsize, 16);
1292 if (modeinfo.depth == 4)
1293 SET_FARVAR(seg, info->planes, 4);
1294 else
1295 SET_FARVAR(seg, info->planes, 1);
1296 SET_FARVAR(seg, info->bits_per_pixel, modeinfo.depth);
1297 SET_FARVAR(seg, info->banks,
1298 (modeinfo.linesize * modeinfo.height + 65535) / 65536);
1299 if (modeinfo.depth == 4)
1300 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PLANAR);
1301 else if (modeinfo.depth == 8)
1302 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PACKED_PIXEL);
1303 else
1304 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_DIRECT_COLOR);
1305 SET_FARVAR(seg, info->bank_size, 0);
1306 u32 pages = modeinfo.vram_size / (modeinfo.height * modeinfo.linesize);
1307 if (modeinfo.depth == 4)
1308 SET_FARVAR(seg, info->pages, (pages / 4) - 1);
1309 else
1310 SET_FARVAR(seg, info->pages, pages - 1);
1311 SET_FARVAR(seg, info->reserved0, 1);
1312
1313 u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
1314
1315 switch (modeinfo.depth) {
1316 case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5;
1317 b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break;
1318 case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5;
1319 b_size = 5; b_pos = 0; a_size = 0; a_pos = 0; break;
1320 case 24: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
1321 b_size = 8; b_pos = 0; a_size = 0; a_pos = 0; break;
1322 case 32: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
1323 b_size = 8; b_pos = 0; a_size = 8; a_pos = 24; break;
1324 default: r_size = 0; r_pos = 0; g_size = 0; g_pos = 0;
1325 b_size = 0; b_pos = 0; a_size = 0; a_pos = 0; break;
1326 }
1327
1328 SET_FARVAR(seg, info->red_size, r_size);
1329 SET_FARVAR(seg, info->red_pos, r_pos);
1330 SET_FARVAR(seg, info->green_size, g_size);
1331 SET_FARVAR(seg, info->green_pos, g_pos);
1332 SET_FARVAR(seg, info->blue_size, b_size);
1333 SET_FARVAR(seg, info->blue_pos, b_pos);
1334 SET_FARVAR(seg, info->alpha_size, a_size);
1335 SET_FARVAR(seg, info->alpha_pos, a_pos);
1336
1337 if (modeinfo.depth == 32)
1338 SET_FARVAR(seg, info->directcolor_info,
1339 VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE);
1340 else
1341 SET_FARVAR(seg, info->directcolor_info, 0);
1342
1343 if (modeinfo.depth > 4)
1344 SET_FARVAR(seg, info->phys_base, modeinfo.phys_base);
1345 else
1346 SET_FARVAR(seg, info->phys_base, 0);
1347
1348 SET_FARVAR(seg, info->reserved1, 0);
1349 SET_FARVAR(seg, info->reserved2, 0);
1350 SET_FARVAR(seg, info->linear_bytes_per_scanline, modeinfo.linesize);
1351 SET_FARVAR(seg, info->bank_pages, 0);
1352 SET_FARVAR(seg, info->linear_pages, 0);
1353 SET_FARVAR(seg, info->linear_red_size, r_size);
1354 SET_FARVAR(seg, info->linear_red_pos, r_pos);
1355 SET_FARVAR(seg, info->linear_green_size, g_size);
1356 SET_FARVAR(seg, info->linear_green_pos, g_pos);
1357 SET_FARVAR(seg, info->linear_blue_size, b_size);
1358 SET_FARVAR(seg, info->linear_blue_pos, b_pos);
1359 SET_FARVAR(seg, info->linear_alpha_size, a_size);
1360 SET_FARVAR(seg, info->linear_alpha_pos, a_pos);
1361 SET_FARVAR(seg, info->pixclock_max, 0);
1362
1363 regs->al = regs->ah; /* 0x4F, Function supported */
1364 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001365}
1366
1367static void
1368handle_104f02(struct bregs *regs)
1369{
Julian Pidancet87879e22011-12-19 05:08:00 +00001370 //u16 seg = regs->es;
1371 //struct vbe_crtc_info *crtc_info = (void*)(regs->di+0);
1372 u16 mode = regs->bx;
1373 struct vbe_modeinfo modeinfo;
1374 int rc;
1375
1376 dprintf(1, "VBE mode set: %x\n", mode);
1377
1378 if (mode < 0x100) { /* VGA */
1379 dprintf(1, "set VGA mode %x\n", mode);
1380
1381 vbe_hires_enable(0);
1382 vga_set_mode(mode, 0);
1383 } else { /* VBE */
1384 rc = vbe_mode_info(mode & 0x1ff, &modeinfo);
1385 if (rc) {
1386 dprintf(1, "VBE mode %x not found\n", mode & 0x1ff);
1387 regs->ax = 0x100;
1388 return;
1389 }
1390 vbe_hires_enable(1);
1391 vbe_set_mode(mode & 0x1ff, &modeinfo);
1392
1393 if (mode & 0x4000) {
1394 /* Linear frame buffer */
1395 /* XXX: ??? */
1396 }
1397 if (!(mode & 0x8000)) {
1398 vbe_clear_scr();
1399 }
1400 }
1401
1402 regs->al = regs->ah; /* 0x4F, Function supported */
1403 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001404}
1405
1406static void
1407handle_104f03(struct bregs *regs)
1408{
Julian Pidancet87879e22011-12-19 05:08:00 +00001409 if (!vbe_hires_enabled()) {
1410 regs->bx = GET_BDA(video_mode);
1411 } else {
1412 regs->bx = vbe_curr_mode();
1413 }
1414
1415 dprintf(1, "VBE current mode=%x\n", regs->bx);
1416
1417 regs->al = regs->ah; /* 0x4F, Function supported */
1418 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001419}
1420
1421static void
1422handle_104f04(struct bregs *regs)
1423{
Julian Pidancet87879e22011-12-19 05:08:00 +00001424 debug_enter(regs, DEBUG_VGA_10);
1425 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001426}
1427
1428static void
1429handle_104f05(struct bregs *regs)
1430{
Julian Pidancet87879e22011-12-19 05:08:00 +00001431 debug_enter(regs, DEBUG_VGA_10);
1432 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001433}
1434
1435static void
1436handle_104f06(struct bregs *regs)
1437{
Julian Pidancet87879e22011-12-19 05:08:00 +00001438 debug_enter(regs, DEBUG_VGA_10);
1439 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001440}
1441
1442static void
1443handle_104f07(struct bregs *regs)
1444{
Julian Pidancet87879e22011-12-19 05:08:00 +00001445 debug_enter(regs, DEBUG_VGA_10);
1446 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001447}
1448
1449static void
1450handle_104f08(struct bregs *regs)
1451{
Julian Pidancet87879e22011-12-19 05:08:00 +00001452 debug_enter(regs, DEBUG_VGA_10);
1453 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001454}
1455
1456static void
1457handle_104f0a(struct bregs *regs)
1458{
Julian Pidancet87879e22011-12-19 05:08:00 +00001459 debug_enter(regs, DEBUG_VGA_10);
1460 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001461}
1462
1463static void
1464handle_104fXX(struct bregs *regs)
1465{
1466 debug_stub(regs);
1467 regs->ax = 0x0100;
1468}
1469
1470static void
1471handle_104f(struct bregs *regs)
1472{
Julian Pidancet87879e22011-12-19 05:08:00 +00001473 if (!vbe_enabled()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001474 handle_104fXX(regs);
1475 return;
1476 }
1477
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001478 switch (regs->al) {
1479 case 0x00: handle_104f00(regs); break;
1480 case 0x01: handle_104f01(regs); break;
1481 case 0x02: handle_104f02(regs); break;
1482 case 0x03: handle_104f03(regs); break;
1483 case 0x04: handle_104f04(regs); break;
1484 case 0x05: handle_104f05(regs); break;
1485 case 0x06: handle_104f06(regs); break;
1486 case 0x07: handle_104f07(regs); break;
1487 case 0x08: handle_104f08(regs); break;
1488 case 0x0a: handle_104f0a(regs); break;
1489 default: handle_104fXX(regs); break;
1490 }
1491}
1492
1493
1494static void
1495handle_10XX(struct bregs *regs)
1496{
1497 debug_stub(regs);
1498}
1499
1500// INT 10h Video Support Service Entry Point
1501void VISIBLE16
1502handle_10(struct bregs *regs)
1503{
1504 debug_enter(regs, DEBUG_VGA_10);
1505 switch (regs->ah) {
1506 case 0x00: handle_1000(regs); break;
1507 case 0x01: handle_1001(regs); break;
1508 case 0x02: handle_1002(regs); break;
1509 case 0x03: handle_1003(regs); break;
1510 case 0x04: handle_1004(regs); break;
1511 case 0x05: handle_1005(regs); break;
1512 case 0x06: handle_1006(regs); break;
1513 case 0x07: handle_1007(regs); break;
1514 case 0x08: handle_1008(regs); break;
1515 case 0x09: handle_1009(regs); break;
1516 case 0x0a: handle_100a(regs); break;
1517 case 0x0b: handle_100b(regs); break;
1518 case 0x0c: handle_100c(regs); break;
1519 case 0x0d: handle_100d(regs); break;
1520 case 0x0e: handle_100e(regs); break;
1521 case 0x0f: handle_100f(regs); break;
1522 case 0x10: handle_1010(regs); break;
1523 case 0x11: handle_1011(regs); break;
1524 case 0x12: handle_1012(regs); break;
1525 case 0x13: handle_1013(regs); break;
1526 case 0x1a: handle_101a(regs); break;
1527 case 0x1b: handle_101b(regs); break;
1528 case 0x1c: handle_101c(regs); break;
1529 case 0x4f: handle_104f(regs); break;
1530 default: handle_10XX(regs); break;
1531 }
1532}
1533
1534
1535/****************************************************************
1536 * VGA post
1537 ****************************************************************/
1538
1539static void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -05001540init_bios_area(void)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001541{
1542 // init detected hardware BIOS Area
1543 // set 80x25 color (not clear from RBIL but usual)
1544 u16 eqf = GET_BDA(equipment_list_flags);
1545 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1546
1547 // Just for the first int10 find its children
1548
1549 // the default char height
1550 SET_BDA(char_height, 0x10);
1551
1552 // Clear the screen
1553 SET_BDA(video_ctl, 0x60);
1554
1555 // Set the basic screen we have
1556 SET_BDA(video_switches, 0xf9);
1557
1558 // Set the basic modeset options
1559 SET_BDA(modeset_ctl, 0x51);
1560
1561 // Set the default MSR
1562 SET_BDA(video_msr, 0x09);
1563}
1564
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001565void VISIBLE16
1566vga_post(struct bregs *regs)
1567{
1568 debug_enter(regs, DEBUG_VGA_POST);
1569
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001570 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001571
1572 init_bios_area();
1573
Julian Pidancet87879e22011-12-19 05:08:00 +00001574 vbe_init(regs->ah, regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001575
1576 extern void entry_10(void);
Kevin O'Connor9f985422009-09-09 11:34:39 -04001577 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001578
Julian Pidancet677631f2011-12-19 05:07:53 +00001579 if (CONFIG_VGA_CIRRUS)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001580 cirrus_init();
1581
1582 // XXX - clear screen and display info
1583
Kevin O'Connorf3760372011-12-23 22:41:08 -05001584 build_video_param();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001585
1586 // Fixup checksum
1587 extern u8 _rom_header_size, _rom_header_checksum;
1588 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001589 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001590 SET_VGA(_rom_header_checksum, sum);
1591}