blob: ee107043efe558d7eea9723d38f92b42d67d7521 [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'Connord113a992009-05-16 21:05:02 -040026#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040027
Julian Pidancet7c6509c2011-12-19 05:07:55 +000028/****************************************************************
29 * PCI Data
30 ****************************************************************/
31#if CONFIG_VGA_PCI == 1
32struct pci_data rom_pci_data VAR16VISIBLE = {
33 .signature = PCI_ROM_SIGNATURE,
34 .vendor = CONFIG_VGA_VID,
35 .device = CONFIG_VGA_DID,
36 .dlen = 0x18,
37 .class_hi = 0x300,
38 .irevision = 1,
39 .type = PCIROM_CODETYPE_X86,
40 .indicator = 0x80,
41};
42#endif
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040043
44/****************************************************************
45 * Helper functions
46 ****************************************************************/
47
Kevin O'Connor217f2bc2009-05-31 00:46:47 -040048static inline void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040049call16_vgaint(u32 eax, u32 ebx)
50{
51 asm volatile(
52 "int $0x10\n"
53 "cli\n"
54 "cld"
55 :
56 : "a"(eax), "b"(ebx)
57 : "cc", "memory");
58}
59
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040060static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040061perform_gray_scale_summing(u16 start, u16 count)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040062{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040063 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040064 int i;
65 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040066 u8 rgb[3];
67 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040068
69 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040070 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040071 if (intensity > 0x3f)
72 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040073
Kevin O'Connora0ecb052009-05-18 23:34:00 -040074 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040075 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040076 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040077}
78
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040079static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040080set_cursor_shape(u8 start, u8 end)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040081{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040082 start &= 0x3f;
83 end &= 0x1f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040084
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040085 u16 curs = (start << 8) + end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040086 SET_BDA(cursor_type, curs);
87
Kevin O'Connordd2be772009-05-16 15:41:23 -040088 u8 modeset_ctl = GET_BDA(modeset_ctl);
89 u16 cheight = GET_BDA(char_height);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040090 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
91 if (end != (start + 1))
92 start = ((start + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040093 else
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040094 start = ((end + 1) * cheight / 8) - 2;
95 end = ((end + 1) * cheight / 8) - 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040096 }
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040097 vgahw_set_cursor_shape(start, end);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040098}
99
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400100static u16
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400101get_cursor_shape(u8 page)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400102{
103 if (page > 7)
104 return 0;
105 // FIXME should handle VGA 14/16 lines
106 return GET_BDA(cursor_type);
107}
108
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400109static void
Kevin O'Connor918b1562009-05-25 11:05:18 -0400110set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400111{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400112 // Should not happen...
Kevin O'Connor918b1562009-05-25 11:05:18 -0400113 if (cp.page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400114 return;
115
116 // Bios cursor pos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400117 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400118
119 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400120 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400121 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400122 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400123
Kevin O'Connordd2be772009-05-16 15:41:23 -0400124 // Get the dimensions
125 u16 nbcols = GET_BDA(video_cols);
126 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400127
Kevin O'Connordd2be772009-05-16 15:41:23 -0400128 // Calculate the address knowing nbcols nbrows and page num
Kevin O'Connor918b1562009-05-25 11:05:18 -0400129 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
130 + cp.x + cp.y * nbcols);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400131
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400132 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400133}
134
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400135static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400136get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400137{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400138 if (page == 0xff)
139 // special case - use current page
140 page = GET_BDA(video_page);
141 if (page > 7) {
142 struct cursorpos cp = { 0, 0, 0xfe };
143 return cp;
144 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400145 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400146 u16 xy = GET_BDA(cursor_pos[page]);
147 struct cursorpos cp = {xy, xy>>8, page};
148 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400149}
150
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400151static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400152set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400153{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400154 if (page > 7)
155 return;
156
157 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400158 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
159 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400160 return;
161
162 // Get pos curs pos for the right page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400163 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400164
Kevin O'Connordd2be772009-05-16 15:41:23 -0400165 u16 address;
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400166 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400167 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400168 u16 nbcols = GET_BDA(video_cols);
169 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400170
171 // Calculate the address knowing nbcols nbrows and page num
172 address = SCREEN_MEM_START(nbcols, nbrows, page);
173 SET_BDA(video_pagestart, address);
174
175 // Start address
176 address = SCREEN_IO_START(nbcols, nbrows, page);
177 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400178 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
179 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400180 }
181
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400182 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400183
184 // And change the BIOS page
185 SET_BDA(video_page, page);
186
Kevin O'Connora12c2152009-05-13 22:06:16 -0400187 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400188
189 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400190 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400191}
192
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400193static void
194set_scan_lines(u8 lines)
195{
196 vgahw_set_scan_lines(lines);
197 if (lines == 8)
198 set_cursor_shape(0x06, 0x07);
199 else
200 set_cursor_shape(lines - 4, lines - 3);
201 SET_BDA(char_height, lines);
202 u16 vde = vgahw_get_vde();
203 u8 rows = vde / lines;
204 SET_BDA(video_rows, rows - 1);
205 u16 cols = GET_BDA(video_cols);
206 SET_BDA(video_pagesize, rows * cols * 2);
207}
208
209
210/****************************************************************
211 * Character writing
212 ****************************************************************/
213
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400214// Scroll the screen one line. This function is designed to be called
215// tail-recursive to reduce stack usage.
216static void noinline
217scroll_one(u16 nbrows, u16 nbcols, u8 page)
Kevin O'Connor09262412009-05-25 11:44:11 -0400218{
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400219 struct cursorpos ul = {0, 0, page};
220 struct cursorpos lr = {nbcols-1, nbrows-1, page};
221 vgafb_scroll(1, -1, ul, lr);
222}
223
224// Write a character to the screen at a given position. Implement
225// special characters and scroll the screen if necessary.
226static void
227write_teletype(struct cursorpos *pcp, struct carattr ca)
228{
229 struct cursorpos cp = *pcp;
230
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400231 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400232 u16 nbrows = GET_BDA(video_rows) + 1;
233 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400234
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400235 switch (ca.car) {
236 case 7:
237 //FIXME should beep
238 break;
239 case 8:
240 if (cp.x > 0)
241 cp.x--;
242 break;
243 case '\r':
244 cp.x = 0;
245 break;
246 case '\n':
247 cp.y++;
248 break;
249 case '\t':
250 do {
251 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
252 vgafb_write_char(cp, dummyca);
253 cp.x++;
254 } while (cp.x < nbcols && cp.x % 8);
255 break;
256 default:
257 vgafb_write_char(cp, ca);
258 cp.x++;
259 }
260
Kevin O'Connor82221b22009-05-26 00:20:40 -0400261 // Do we need to wrap ?
262 if (cp.x == nbcols) {
263 cp.x = 0;
264 cp.y++;
265 }
266 // Do we need to scroll ?
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400267 if (cp.y < nbrows) {
268 *pcp = cp;
269 return;
Kevin O'Connor82221b22009-05-26 00:20:40 -0400270 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400271 // Scroll screen
272 cp.y--;
273 *pcp = cp;
274 scroll_one(nbrows, nbcols, cp.page);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400275}
276
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400277// Write out a buffer of alternating characters and attributes.
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400278static void
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400279write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400280{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400281 while (count--) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400282 u8 car = GET_FARVAR(seg, *offset_far);
283 offset_far++;
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400284 u8 attr = GET_FARVAR(seg, *offset_far);
285 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400286
Kevin O'Connor09262412009-05-25 11:44:11 -0400287 struct carattr ca = {car, attr, 1};
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400288 write_teletype(pcp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400289 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400290}
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400291
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400292// Write out a buffer of characters.
293static void
294write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
295{
296 while (count--) {
297 u8 car = GET_FARVAR(seg, *offset_far);
298 offset_far++;
299
300 struct carattr ca = {car, attr, 1};
301 write_teletype(pcp, ca);
302 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400303}
304
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400305
306/****************************************************************
307 * Save and restore bda state
308 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400309
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400310static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400311save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400312{
Kevin O'Connorca668642009-05-21 23:06:08 -0400313 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
314 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
315 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
316 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
317 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
318 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
319 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
320 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
321 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
322 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
323 u16 i;
324 for (i=0; i<8; i++)
325 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
326 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
327 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
328 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400329 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
330 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400331}
332
Kevin O'Connorca668642009-05-21 23:06:08 -0400333static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400334restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400335{
Kevin O'Connorca668642009-05-21 23:06:08 -0400336 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
337 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
338 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
339 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
340 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
341 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
342 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
343 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
344 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
345 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
346 u16 i;
347 for (i = 0; i < 8; i++)
348 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
349 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
350 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
351 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400352 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
353 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400354}
355
356
357/****************************************************************
358 * VGA int 10 handler
359 ****************************************************************/
360
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400361// set video mode
Julian Pidancet87879e22011-12-19 05:08:00 +0000362void
363vga_set_mode(u8 mode, u8 noclearmem)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400364{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400365 // find the entry in the video modes
366 struct vgamode_s *vmode_g = find_vga_entry(mode);
367 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
368 if (!vmode_g)
369 return;
370
371 // Read the bios mode set control
372 u8 modeset_ctl = GET_BDA(modeset_ctl);
373
374 // Then we know the number of lines
375// FIXME
376
377 // if palette loading (bit 3 of modeset ctl = 0)
378 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
379 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
380
381 // From which palette
382 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
383 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
384
385 // Always 256*3 values
386 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
387 u16 i;
388 for (i = palsize; i < 0x0100; i++) {
389 static u8 rgb[3] VAR16;
390 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
391 }
392
393 if ((modeset_ctl & 0x02) == 0x02)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400394 perform_gray_scale_summing(0x00, 0x100);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400395 }
396
397 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
398 vgahw_set_mode(vparam_g);
399
400 if (noclearmem == 0x00)
401 clear_screen(vmode_g);
402
403 // Set CRTC address VGA or MDA
404 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
405 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
406 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
407
408 // Set the BIOS mem
409 u16 cheight = GET_GLOBAL(vparam_g->cheight);
410 SET_BDA(video_mode, mode);
411 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
412 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
413 SET_BDA(crtc_address, crtc_addr);
414 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
415 SET_BDA(char_height, cheight);
416 SET_BDA(video_ctl, (0x60 | noclearmem));
417 SET_BDA(video_switches, 0xF9);
418 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
419
420 // FIXME We nearly have the good tables. to be reworked
421 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
Kevin O'Connor9f985422009-09-09 11:34:39 -0400422 SET_BDA(video_savetable
Kevin O'Connor815e4472011-12-21 09:05:32 -0500423 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400424
425 // FIXME
426 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
427 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
428
429 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400430 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400431 set_cursor_shape(0x06, 0x07);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400432 // Set cursor pos for page 0..7
433 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400434 for (i = 0; i < 8; i++) {
435 struct cursorpos cp = {0, 0, i};
436 set_cursor_pos(cp);
437 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400438
439 // Set active page 0
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400440 set_active_page(0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400441
442 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400443 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400444 call16_vgaint(0x1104, 0);
445 call16_vgaint(0x1103, 0);
446 }
447 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400448 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400449
450 switch (cheight) {
451 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400452 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400453 break;
454 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400455 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400456 break;
457 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400458 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400459 break;
460 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400461}
462
463static void
Julian Pidancet87879e22011-12-19 05:08:00 +0000464handle_1000(struct bregs *regs)
465{
466 u8 noclearmem = regs->al & 0x80;
467 u8 mode = regs->al & 0x7f;
468
469 // Set regs->al
470 if (mode > 7)
471 regs->al = 0x20;
472 else if (mode == 6)
473 regs->al = 0x3f;
474 else
475 regs->al = 0x30;
476
Kevin O'Connore48a5372011-12-20 23:56:14 -0500477 if (CONFIG_VGA_CIRRUS) {
478 int ret = cirrus_set_video_mode(mode, noclearmem);
479 if (ret)
480 return;
481 }
Julian Pidancet87879e22011-12-19 05:08:00 +0000482
483 if (vbe_enabled())
484 vbe_hires_enable(0);
485
486 vga_set_mode(mode, noclearmem);
487}
488
489static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400490handle_1001(struct bregs *regs)
491{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400492 set_cursor_shape(regs->ch, regs->cl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400493}
494
495static void
496handle_1002(struct bregs *regs)
497{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400498 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
499 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400500}
501
502static void
503handle_1003(struct bregs *regs)
504{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400505 regs->cx = get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400506 struct cursorpos cp = get_cursor_pos(regs->bh);
507 regs->dl = cp.x;
508 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400509}
510
511// Read light pen pos (unimplemented)
512static void
513handle_1004(struct bregs *regs)
514{
515 debug_stub(regs);
516 regs->ax = regs->bx = regs->cx = regs->dx = 0;
517}
518
519static void
520handle_1005(struct bregs *regs)
521{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400522 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400523}
524
525static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400526verify_scroll(struct bregs *regs, int dir)
527{
528 u8 page = GET_BDA(video_page);
529 struct cursorpos ul = {regs->cl, regs->ch, page};
530 struct cursorpos lr = {regs->dl, regs->dh, page};
531
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400532 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400533 if (lr.y >= nbrows)
534 lr.y = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400535 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400536 if (lr.x >= nbcols)
537 lr.x = nbcols - 1;
538
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400539 if (ul.x > lr.x || ul.y > lr.y)
540 return;
541
542 u16 nblines = regs->al;
543 if (!nblines || nblines > lr.y - ul.y + 1)
544 nblines = lr.y - ul.y + 1;
545
546 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400547}
548
549static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400550handle_1006(struct bregs *regs)
551{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400552 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400553}
554
555static void
556handle_1007(struct bregs *regs)
557{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400558 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400559}
560
561static void
562handle_1008(struct bregs *regs)
563{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400564 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400565 regs->al = ca.car;
566 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400567}
568
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400569static void noinline
Kevin O'Connord3b38152009-05-26 00:05:37 -0400570write_chars(u8 page, struct carattr ca, u16 count)
571{
572 struct cursorpos cp = get_cursor_pos(page);
573 while (count--) {
574 vgafb_write_char(cp, ca);
575 cp.x++;
576 }
577}
578
579static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400580handle_1009(struct bregs *regs)
581{
Kevin O'Connor09262412009-05-25 11:44:11 -0400582 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400583 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400584}
585
586static void
587handle_100a(struct bregs *regs)
588{
Kevin O'Connor09262412009-05-25 11:44:11 -0400589 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400590 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400591}
592
593
594static void
595handle_100b00(struct bregs *regs)
596{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400597 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400598}
599
600static void
601handle_100b01(struct bregs *regs)
602{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400603 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400604}
605
606static void
607handle_100bXX(struct bregs *regs)
608{
609 debug_stub(regs);
610}
611
612static void
613handle_100b(struct bregs *regs)
614{
615 switch (regs->bh) {
616 case 0x00: handle_100b00(regs); break;
617 case 0x01: handle_100b01(regs); break;
618 default: handle_100bXX(regs); break;
619 }
620}
621
622
623static void
624handle_100c(struct bregs *regs)
625{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400626 // XXX - page (regs->bh) is unused
627 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400628}
629
630static void
631handle_100d(struct bregs *regs)
632{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400633 // XXX - page (regs->bh) is unused
634 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400635}
636
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400637static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400638handle_100e(struct bregs *regs)
639{
640 // Ralf Brown Interrupt list is WRONG on bh(page)
641 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400642 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400643 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400644 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400645 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400646}
647
648static void
649handle_100f(struct bregs *regs)
650{
Kevin O'Connore7132042009-05-25 00:10:35 -0400651 regs->bh = GET_BDA(video_page);
652 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
653 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400654}
655
656
657static void
658handle_101000(struct bregs *regs)
659{
660 if (regs->bl > 0x14)
661 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400662 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400663}
664
665static void
666handle_101001(struct bregs *regs)
667{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400668 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400669}
670
671static void
672handle_101002(struct bregs *regs)
673{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400674 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400675}
676
677static void
678handle_101003(struct bregs *regs)
679{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400680 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400681}
682
683static void
684handle_101007(struct bregs *regs)
685{
686 if (regs->bl > 0x14)
687 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400688 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400689}
690
691static void
692handle_101008(struct bregs *regs)
693{
Kevin O'Connor3862b2d2010-01-03 17:53:58 -0500694 regs->bh = vgahw_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400695}
696
697static void
698handle_101009(struct bregs *regs)
699{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400700 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400701}
702
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400703static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400704handle_101010(struct bregs *regs)
705{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400706 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
707 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400708}
709
710static void
711handle_101012(struct bregs *regs)
712{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400713 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400714}
715
716static void
717handle_101013(struct bregs *regs)
718{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400719 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400720}
721
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400722static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400723handle_101015(struct bregs *regs)
724{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400725 u8 rgb[3];
726 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
727 regs->dh = rgb[0];
728 regs->ch = rgb[1];
729 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400730}
731
732static void
733handle_101017(struct bregs *regs)
734{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400735 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400736}
737
738static void
739handle_101018(struct bregs *regs)
740{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400741 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400742}
743
744static void
745handle_101019(struct bregs *regs)
746{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400747 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400748}
749
750static void
751handle_10101a(struct bregs *regs)
752{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400753 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400754}
755
756static void
757handle_10101b(struct bregs *regs)
758{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400759 perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400760}
761
762static void
763handle_1010XX(struct bregs *regs)
764{
765 debug_stub(regs);
766}
767
768static void
769handle_1010(struct bregs *regs)
770{
771 switch (regs->al) {
772 case 0x00: handle_101000(regs); break;
773 case 0x01: handle_101001(regs); break;
774 case 0x02: handle_101002(regs); break;
775 case 0x03: handle_101003(regs); break;
776 case 0x07: handle_101007(regs); break;
777 case 0x08: handle_101008(regs); break;
778 case 0x09: handle_101009(regs); break;
779 case 0x10: handle_101010(regs); break;
780 case 0x12: handle_101012(regs); break;
781 case 0x13: handle_101013(regs); break;
782 case 0x15: handle_101015(regs); break;
783 case 0x17: handle_101017(regs); break;
784 case 0x18: handle_101018(regs); break;
785 case 0x19: handle_101019(regs); break;
786 case 0x1a: handle_10101a(regs); break;
787 case 0x1b: handle_10101b(regs); break;
788 default: handle_1010XX(regs); break;
789 }
790}
791
792
793static void
794handle_101100(struct bregs *regs)
795{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400796 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
797 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400798}
799
800static void
801handle_101101(struct bregs *regs)
802{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400803 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400804}
805
806static void
807handle_101102(struct bregs *regs)
808{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400809 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400810}
811
812static void
813handle_101103(struct bregs *regs)
814{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400815 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400816}
817
818static void
819handle_101104(struct bregs *regs)
820{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400821 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400822}
823
824static void
825handle_101110(struct bregs *regs)
826{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400827 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
828 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400829 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400830}
831
832static void
833handle_101111(struct bregs *regs)
834{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400835 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400836 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400837}
838
839static void
840handle_101112(struct bregs *regs)
841{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400842 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400843 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400844}
845
846static void
847handle_101114(struct bregs *regs)
848{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400849 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400850 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400851}
852
853static void
854handle_101130(struct bregs *regs)
855{
Kevin O'Connore7132042009-05-25 00:10:35 -0400856 switch (regs->bh) {
857 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500858 struct segoff_s so = GET_IVT(0x1f);
859 regs->es = so.seg;
860 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400861 break;
862 }
863 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500864 struct segoff_s so = GET_IVT(0x43);
865 regs->es = so.seg;
866 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400867 break;
868 }
869 case 0x02:
870 regs->es = get_global_seg();
871 regs->bp = (u32)vgafont14;
872 break;
873 case 0x03:
874 regs->es = get_global_seg();
875 regs->bp = (u32)vgafont8;
876 break;
877 case 0x04:
878 regs->es = get_global_seg();
879 regs->bp = (u32)vgafont8 + 128 * 8;
880 break;
881 case 0x05:
882 regs->es = get_global_seg();
883 regs->bp = (u32)vgafont14alt;
884 break;
885 case 0x06:
886 regs->es = get_global_seg();
887 regs->bp = (u32)vgafont16;
888 break;
889 case 0x07:
890 regs->es = get_global_seg();
891 regs->bp = (u32)vgafont16alt;
892 break;
893 default:
894 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
895 return;
896 }
897 // Set byte/char of on screen font
898 regs->cx = GET_BDA(char_height) & 0xff;
899
900 // Set Highest char row
901 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400902}
903
904static void
905handle_1011XX(struct bregs *regs)
906{
907 debug_stub(regs);
908}
909
910static void
911handle_1011(struct bregs *regs)
912{
913 switch (regs->al) {
914 case 0x00: handle_101100(regs); break;
915 case 0x01: handle_101101(regs); break;
916 case 0x02: handle_101102(regs); break;
917 case 0x03: handle_101103(regs); break;
918 case 0x04: handle_101104(regs); break;
919 case 0x10: handle_101110(regs); break;
920 case 0x11: handle_101111(regs); break;
921 case 0x12: handle_101112(regs); break;
922 case 0x14: handle_101114(regs); break;
923 case 0x30: handle_101130(regs); break;
924 default: handle_1011XX(regs); break;
925 }
926}
927
928
929static void
930handle_101210(struct bregs *regs)
931{
Kevin O'Connore7132042009-05-25 00:10:35 -0400932 u16 crtc_addr = GET_BDA(crtc_address);
933 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
934 regs->bx = 0x0103;
935 else
936 regs->bx = 0x0003;
937 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400938}
939
940static void
941handle_101230(struct bregs *regs)
942{
Kevin O'Connore7132042009-05-25 00:10:35 -0400943 u8 mctl = GET_BDA(modeset_ctl);
944 u8 vswt = GET_BDA(video_switches);
945 switch (regs->al) {
946 case 0x00:
947 // 200 lines
948 mctl = (mctl & ~0x10) | 0x80;
949 vswt = (vswt & ~0x0f) | 0x08;
950 break;
951 case 0x01:
952 // 350 lines
953 mctl &= ~0x90;
954 vswt = (vswt & ~0x0f) | 0x09;
955 break;
956 case 0x02:
957 // 400 lines
958 mctl = (mctl & ~0x80) | 0x10;
959 vswt = (vswt & ~0x0f) | 0x09;
960 break;
961 default:
962 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
963 break;
964 }
965 SET_BDA(modeset_ctl, mctl);
966 SET_BDA(video_switches, vswt);
967 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400968}
969
970static void
971handle_101231(struct bregs *regs)
972{
Kevin O'Connore7132042009-05-25 00:10:35 -0400973 u8 v = (regs->al & 0x01) << 3;
974 u8 mctl = GET_BDA(video_ctl) & ~0x08;
975 SET_BDA(video_ctl, mctl | v);
976 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400977}
978
979static void
980handle_101232(struct bregs *regs)
981{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400982 vgahw_enable_video_addressing(regs->al);
983 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400984}
985
986static void
987handle_101233(struct bregs *regs)
988{
Kevin O'Connore7132042009-05-25 00:10:35 -0400989 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
990 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
991 SET_BDA(modeset_ctl, v | v2);
992 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400993}
994
995static void
996handle_101234(struct bregs *regs)
997{
Kevin O'Connore7132042009-05-25 00:10:35 -0400998 u8 v = (regs->al & 0x01) ^ 0x01;
999 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
1000 SET_BDA(modeset_ctl, v | v2);
1001 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001002}
1003
1004static void
1005handle_101235(struct bregs *regs)
1006{
1007 debug_stub(regs);
1008 regs->al = 0x12;
1009}
1010
1011static void
1012handle_101236(struct bregs *regs)
1013{
1014 debug_stub(regs);
1015 regs->al = 0x12;
1016}
1017
1018static void
1019handle_1012XX(struct bregs *regs)
1020{
1021 debug_stub(regs);
1022}
1023
1024static void
1025handle_1012(struct bregs *regs)
1026{
1027 switch (regs->bl) {
1028 case 0x10: handle_101210(regs); break;
1029 case 0x30: handle_101230(regs); break;
1030 case 0x31: handle_101231(regs); break;
1031 case 0x32: handle_101232(regs); break;
1032 case 0x33: handle_101233(regs); break;
1033 case 0x34: handle_101234(regs); break;
1034 case 0x35: handle_101235(regs); break;
1035 case 0x36: handle_101236(regs); break;
1036 default: handle_1012XX(regs); break;
1037 }
1038
1039 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1040}
1041
1042
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001043// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -04001044static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001045handle_1013(struct bregs *regs)
1046{
Kevin O'Connor918b1562009-05-25 11:05:18 -04001047 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -04001048 // if row=0xff special case : use current cursor position
1049 if (cp.y == 0xff)
1050 cp = get_cursor_pos(cp.page);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001051 u8 flag = regs->al;
1052 if (flag & 2)
1053 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1054 else
1055 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1056
1057 if (flag & 1)
1058 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001059}
1060
1061
1062static void
1063handle_101a00(struct bregs *regs)
1064{
Kevin O'Connore7132042009-05-25 00:10:35 -04001065 regs->bx = GET_BDA(dcc_index);
1066 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001067}
1068
1069static void
1070handle_101a01(struct bregs *regs)
1071{
Kevin O'Connore7132042009-05-25 00:10:35 -04001072 SET_BDA(dcc_index, regs->bl);
1073 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1074 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001075}
1076
1077static void
1078handle_101aXX(struct bregs *regs)
1079{
1080 debug_stub(regs);
1081}
1082
1083static void
1084handle_101a(struct bregs *regs)
1085{
1086 switch (regs->al) {
1087 case 0x00: handle_101a00(regs); break;
1088 case 0x01: handle_101a01(regs); break;
1089 default: handle_101aXX(regs); break;
1090 }
1091}
1092
1093
Kevin O'Connorca668642009-05-21 23:06:08 -04001094struct funcInfo {
1095 u16 static_functionality_off;
1096 u16 static_functionality_seg;
1097 u8 bda_0x49[30];
1098 u8 bda_0x84[3];
1099 u8 dcc_index;
1100 u8 dcc_alt;
1101 u16 colors;
1102 u8 pages;
1103 u8 scan_lines;
1104 u8 primary_char;
1105 u8 secondar_char;
1106 u8 misc;
1107 u8 non_vga_mode;
1108 u8 reserved_2f[2];
1109 u8 video_mem;
1110 u8 save_flags;
1111 u8 disp_info;
1112 u8 reserved_34[12];
1113};
1114
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001115static void
1116handle_101b(struct bregs *regs)
1117{
Kevin O'Connorca668642009-05-21 23:06:08 -04001118 u16 seg = regs->es;
1119 struct funcInfo *info = (void*)(regs->di+0);
1120 memset_far(seg, info, 0, sizeof(*info));
1121 // Address of static functionality table
1122 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1123 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1124
1125 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001126 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1127 , sizeof(info->bda_0x49));
1128 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1129 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001130
1131 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1132 SET_FARVAR(seg, info->colors, 16);
1133 SET_FARVAR(seg, info->pages, 8);
1134 SET_FARVAR(seg, info->scan_lines, 2);
1135 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001136 regs->al = 0x1B;
1137}
1138
1139
1140static void
1141handle_101c00(struct bregs *regs)
1142{
Kevin O'Connorca668642009-05-21 23:06:08 -04001143 u16 flags = regs->cx;
1144 u16 size = 0;
1145 if (flags & 1)
1146 size += sizeof(struct saveVideoHardware);
1147 if (flags & 2)
1148 size += sizeof(struct saveBDAstate);
1149 if (flags & 4)
1150 size += sizeof(struct saveDACcolors);
1151 regs->bx = size;
1152 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001153}
1154
1155static void
1156handle_101c01(struct bregs *regs)
1157{
Kevin O'Connorca668642009-05-21 23:06:08 -04001158 u16 flags = regs->cx;
1159 u16 seg = regs->es;
1160 void *data = (void*)(regs->bx+0);
1161 if (flags & 1) {
1162 vgahw_save_state(seg, data);
1163 data += sizeof(struct saveVideoHardware);
1164 }
1165 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001166 save_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001167 data += sizeof(struct saveBDAstate);
1168 }
1169 if (flags & 4)
1170 vgahw_save_dac_state(seg, data);
1171 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001172}
1173
1174static void
1175handle_101c02(struct bregs *regs)
1176{
Kevin O'Connorca668642009-05-21 23:06:08 -04001177 u16 flags = regs->cx;
1178 u16 seg = regs->es;
1179 void *data = (void*)(regs->bx+0);
1180 if (flags & 1) {
1181 vgahw_restore_state(seg, data);
1182 data += sizeof(struct saveVideoHardware);
1183 }
1184 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001185 restore_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001186 data += sizeof(struct saveBDAstate);
1187 }
1188 if (flags & 4)
1189 vgahw_restore_dac_state(seg, data);
1190 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001191}
1192
1193static void
1194handle_101cXX(struct bregs *regs)
1195{
1196 debug_stub(regs);
1197}
1198
1199static void
1200handle_101c(struct bregs *regs)
1201{
1202 switch (regs->al) {
1203 case 0x00: handle_101c00(regs); break;
1204 case 0x01: handle_101c01(regs); break;
1205 case 0x02: handle_101c02(regs); break;
1206 default: handle_101cXX(regs); break;
1207 }
1208}
1209
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001210static void
1211handle_104f00(struct bregs *regs)
1212{
Julian Pidancet87879e22011-12-19 05:08:00 +00001213 u16 seg = regs->es;
1214 struct vbe_info *info = (void*)(regs->di+0);
1215
1216 if (GET_FARVAR(seg, info->signature) == VBE2_SIGNATURE) {
1217 dprintf(4, "Get VBE Controller: VBE2 Signature found\n");
1218 } else if (GET_FARVAR(seg, info->signature) == VESA_SIGNATURE) {
1219 dprintf(4, "Get VBE Controller: VESA Signature found\n");
1220 } else {
1221 dprintf(4, "Get VBE Controller: Invalid Signature\n");
1222 }
1223
1224 memset_far(seg, info, 0, sizeof(*info));
1225
1226 SET_FARVAR(seg, info->signature, VESA_SIGNATURE);
1227
1228 SET_FARVAR(seg, info->version, 0x0200);
1229
1230 SET_FARVAR(seg, info->oem_string,
1231 SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING));
1232 SET_FARVAR(seg, info->capabilities[0], 0x1); /* 8BIT DAC */
1233
1234 /* We generate our mode list in the reserved field of the info block */
1235 SET_FARVAR(seg, info->video_mode, SEGOFF(seg, regs->di + 34));
1236
1237 /* Total memory (in 64 blocks) */
1238 SET_FARVAR(seg, info->total_memory, vbe_total_mem());
1239
1240 SET_FARVAR(seg, info->oem_vendor_string,
1241 SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING));
1242 SET_FARVAR(seg, info->oem_product_string,
1243 SEGOFF(get_global_seg(), (u32)VBE_PRODUCT_STRING));
1244 SET_FARVAR(seg, info->oem_revision_string,
1245 SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING));
1246
1247 /* Fill list of modes */
1248 vbe_list_modes(seg, regs->di + 32);
1249
1250 regs->al = regs->ah; /* 0x4F, Function supported */
1251 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001252}
1253
1254static void
1255handle_104f01(struct bregs *regs)
1256{
Julian Pidancet87879e22011-12-19 05:08:00 +00001257 u16 seg = regs->es;
1258 struct vbe_mode_info *info = (void*)(regs->di+0);
1259 u16 mode = regs->cx;
1260 struct vbe_modeinfo modeinfo;
1261 int rc;
1262
1263 dprintf(1, "VBE mode info request: %x\n", mode);
1264
1265 rc = vbe_mode_info(mode, &modeinfo);
1266 if (rc) {
1267 dprintf(1, "VBE mode %x not found\n", mode);
1268 regs->ax = 0x100;
1269 return;
1270 }
1271
1272 u16 mode_attr = VBE_MODE_ATTRIBUTE_SUPPORTED |
1273 VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE |
1274 VBE_MODE_ATTRIBUTE_COLOR_MODE |
1275 VBE_MODE_ATTRIBUTE_GRAPHICS_MODE;
1276 if (modeinfo.depth == 4)
1277 mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT;
1278 else
1279 mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE;
1280 SET_FARVAR(seg, info->mode_attributes, mode_attr);
1281 SET_FARVAR(seg, info->winA_attributes,
1282 VBE_WINDOW_ATTRIBUTE_RELOCATABLE |
1283 VBE_WINDOW_ATTRIBUTE_READABLE |
1284 VBE_WINDOW_ATTRIBUTE_WRITEABLE);
1285 SET_FARVAR(seg, info->winB_attributes, 0);
1286 SET_FARVAR(seg, info->win_granularity, 64); /* Bank size 64K */
1287 SET_FARVAR(seg, info->win_size, 64); /* Bank size 64K */
1288 SET_FARVAR(seg, info->winA_seg, 0xA000);
1289 SET_FARVAR(seg, info->winB_seg, 0x0);
1290 SET_FARVAR(seg, info->win_func_ptr, 0x0);
1291 SET_FARVAR(seg, info->bytes_per_scanline, modeinfo.linesize);
1292 SET_FARVAR(seg, info->xres, modeinfo.width);
1293 SET_FARVAR(seg, info->yres, modeinfo.height);
1294 SET_FARVAR(seg, info->xcharsize, 8);
1295 SET_FARVAR(seg, info->ycharsize, 16);
1296 if (modeinfo.depth == 4)
1297 SET_FARVAR(seg, info->planes, 4);
1298 else
1299 SET_FARVAR(seg, info->planes, 1);
1300 SET_FARVAR(seg, info->bits_per_pixel, modeinfo.depth);
1301 SET_FARVAR(seg, info->banks,
1302 (modeinfo.linesize * modeinfo.height + 65535) / 65536);
1303 if (modeinfo.depth == 4)
1304 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PLANAR);
1305 else if (modeinfo.depth == 8)
1306 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PACKED_PIXEL);
1307 else
1308 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_DIRECT_COLOR);
1309 SET_FARVAR(seg, info->bank_size, 0);
1310 u32 pages = modeinfo.vram_size / (modeinfo.height * modeinfo.linesize);
1311 if (modeinfo.depth == 4)
1312 SET_FARVAR(seg, info->pages, (pages / 4) - 1);
1313 else
1314 SET_FARVAR(seg, info->pages, pages - 1);
1315 SET_FARVAR(seg, info->reserved0, 1);
1316
1317 u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
1318
1319 switch (modeinfo.depth) {
1320 case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5;
1321 b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break;
1322 case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5;
1323 b_size = 5; b_pos = 0; a_size = 0; a_pos = 0; break;
1324 case 24: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
1325 b_size = 8; b_pos = 0; a_size = 0; a_pos = 0; break;
1326 case 32: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
1327 b_size = 8; b_pos = 0; a_size = 8; a_pos = 24; break;
1328 default: r_size = 0; r_pos = 0; g_size = 0; g_pos = 0;
1329 b_size = 0; b_pos = 0; a_size = 0; a_pos = 0; break;
1330 }
1331
1332 SET_FARVAR(seg, info->red_size, r_size);
1333 SET_FARVAR(seg, info->red_pos, r_pos);
1334 SET_FARVAR(seg, info->green_size, g_size);
1335 SET_FARVAR(seg, info->green_pos, g_pos);
1336 SET_FARVAR(seg, info->blue_size, b_size);
1337 SET_FARVAR(seg, info->blue_pos, b_pos);
1338 SET_FARVAR(seg, info->alpha_size, a_size);
1339 SET_FARVAR(seg, info->alpha_pos, a_pos);
1340
1341 if (modeinfo.depth == 32)
1342 SET_FARVAR(seg, info->directcolor_info,
1343 VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE);
1344 else
1345 SET_FARVAR(seg, info->directcolor_info, 0);
1346
1347 if (modeinfo.depth > 4)
1348 SET_FARVAR(seg, info->phys_base, modeinfo.phys_base);
1349 else
1350 SET_FARVAR(seg, info->phys_base, 0);
1351
1352 SET_FARVAR(seg, info->reserved1, 0);
1353 SET_FARVAR(seg, info->reserved2, 0);
1354 SET_FARVAR(seg, info->linear_bytes_per_scanline, modeinfo.linesize);
1355 SET_FARVAR(seg, info->bank_pages, 0);
1356 SET_FARVAR(seg, info->linear_pages, 0);
1357 SET_FARVAR(seg, info->linear_red_size, r_size);
1358 SET_FARVAR(seg, info->linear_red_pos, r_pos);
1359 SET_FARVAR(seg, info->linear_green_size, g_size);
1360 SET_FARVAR(seg, info->linear_green_pos, g_pos);
1361 SET_FARVAR(seg, info->linear_blue_size, b_size);
1362 SET_FARVAR(seg, info->linear_blue_pos, b_pos);
1363 SET_FARVAR(seg, info->linear_alpha_size, a_size);
1364 SET_FARVAR(seg, info->linear_alpha_pos, a_pos);
1365 SET_FARVAR(seg, info->pixclock_max, 0);
1366
1367 regs->al = regs->ah; /* 0x4F, Function supported */
1368 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001369}
1370
1371static void
1372handle_104f02(struct bregs *regs)
1373{
Julian Pidancet87879e22011-12-19 05:08:00 +00001374 //u16 seg = regs->es;
1375 //struct vbe_crtc_info *crtc_info = (void*)(regs->di+0);
1376 u16 mode = regs->bx;
1377 struct vbe_modeinfo modeinfo;
1378 int rc;
1379
1380 dprintf(1, "VBE mode set: %x\n", mode);
1381
1382 if (mode < 0x100) { /* VGA */
1383 dprintf(1, "set VGA mode %x\n", mode);
1384
1385 vbe_hires_enable(0);
1386 vga_set_mode(mode, 0);
1387 } else { /* VBE */
1388 rc = vbe_mode_info(mode & 0x1ff, &modeinfo);
1389 if (rc) {
1390 dprintf(1, "VBE mode %x not found\n", mode & 0x1ff);
1391 regs->ax = 0x100;
1392 return;
1393 }
1394 vbe_hires_enable(1);
1395 vbe_set_mode(mode & 0x1ff, &modeinfo);
1396
1397 if (mode & 0x4000) {
1398 /* Linear frame buffer */
1399 /* XXX: ??? */
1400 }
1401 if (!(mode & 0x8000)) {
1402 vbe_clear_scr();
1403 }
1404 }
1405
1406 regs->al = regs->ah; /* 0x4F, Function supported */
1407 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001408}
1409
1410static void
1411handle_104f03(struct bregs *regs)
1412{
Julian Pidancet87879e22011-12-19 05:08:00 +00001413 if (!vbe_hires_enabled()) {
1414 regs->bx = GET_BDA(video_mode);
1415 } else {
1416 regs->bx = vbe_curr_mode();
1417 }
1418
1419 dprintf(1, "VBE current mode=%x\n", regs->bx);
1420
1421 regs->al = regs->ah; /* 0x4F, Function supported */
1422 regs->ah = 0x0; /* 0x0, Function call successful */
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001423}
1424
1425static void
1426handle_104f04(struct bregs *regs)
1427{
Julian Pidancet87879e22011-12-19 05:08:00 +00001428 debug_enter(regs, DEBUG_VGA_10);
1429 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001430}
1431
1432static void
1433handle_104f05(struct bregs *regs)
1434{
Julian Pidancet87879e22011-12-19 05:08:00 +00001435 debug_enter(regs, DEBUG_VGA_10);
1436 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001437}
1438
1439static void
1440handle_104f06(struct bregs *regs)
1441{
Julian Pidancet87879e22011-12-19 05:08:00 +00001442 debug_enter(regs, DEBUG_VGA_10);
1443 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001444}
1445
1446static void
1447handle_104f07(struct bregs *regs)
1448{
Julian Pidancet87879e22011-12-19 05:08:00 +00001449 debug_enter(regs, DEBUG_VGA_10);
1450 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001451}
1452
1453static void
1454handle_104f08(struct bregs *regs)
1455{
Julian Pidancet87879e22011-12-19 05:08:00 +00001456 debug_enter(regs, DEBUG_VGA_10);
1457 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001458}
1459
1460static void
1461handle_104f0a(struct bregs *regs)
1462{
Julian Pidancet87879e22011-12-19 05:08:00 +00001463 debug_enter(regs, DEBUG_VGA_10);
1464 regs->ax = 0x0100;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001465}
1466
1467static void
1468handle_104fXX(struct bregs *regs)
1469{
1470 debug_stub(regs);
1471 regs->ax = 0x0100;
1472}
1473
1474static void
1475handle_104f(struct bregs *regs)
1476{
Julian Pidancet87879e22011-12-19 05:08:00 +00001477 if (!vbe_enabled()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001478 handle_104fXX(regs);
1479 return;
1480 }
1481
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001482 switch (regs->al) {
1483 case 0x00: handle_104f00(regs); break;
1484 case 0x01: handle_104f01(regs); break;
1485 case 0x02: handle_104f02(regs); break;
1486 case 0x03: handle_104f03(regs); break;
1487 case 0x04: handle_104f04(regs); break;
1488 case 0x05: handle_104f05(regs); break;
1489 case 0x06: handle_104f06(regs); break;
1490 case 0x07: handle_104f07(regs); break;
1491 case 0x08: handle_104f08(regs); break;
1492 case 0x0a: handle_104f0a(regs); break;
1493 default: handle_104fXX(regs); break;
1494 }
1495}
1496
1497
1498static void
1499handle_10XX(struct bregs *regs)
1500{
1501 debug_stub(regs);
1502}
1503
1504// INT 10h Video Support Service Entry Point
1505void VISIBLE16
1506handle_10(struct bregs *regs)
1507{
1508 debug_enter(regs, DEBUG_VGA_10);
1509 switch (regs->ah) {
1510 case 0x00: handle_1000(regs); break;
1511 case 0x01: handle_1001(regs); break;
1512 case 0x02: handle_1002(regs); break;
1513 case 0x03: handle_1003(regs); break;
1514 case 0x04: handle_1004(regs); break;
1515 case 0x05: handle_1005(regs); break;
1516 case 0x06: handle_1006(regs); break;
1517 case 0x07: handle_1007(regs); break;
1518 case 0x08: handle_1008(regs); break;
1519 case 0x09: handle_1009(regs); break;
1520 case 0x0a: handle_100a(regs); break;
1521 case 0x0b: handle_100b(regs); break;
1522 case 0x0c: handle_100c(regs); break;
1523 case 0x0d: handle_100d(regs); break;
1524 case 0x0e: handle_100e(regs); break;
1525 case 0x0f: handle_100f(regs); break;
1526 case 0x10: handle_1010(regs); break;
1527 case 0x11: handle_1011(regs); break;
1528 case 0x12: handle_1012(regs); break;
1529 case 0x13: handle_1013(regs); break;
1530 case 0x1a: handle_101a(regs); break;
1531 case 0x1b: handle_101b(regs); break;
1532 case 0x1c: handle_101c(regs); break;
1533 case 0x4f: handle_104f(regs); break;
1534 default: handle_10XX(regs); break;
1535 }
1536}
1537
1538
1539/****************************************************************
1540 * VGA post
1541 ****************************************************************/
1542
1543static void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -05001544init_bios_area(void)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001545{
1546 // init detected hardware BIOS Area
1547 // set 80x25 color (not clear from RBIL but usual)
1548 u16 eqf = GET_BDA(equipment_list_flags);
1549 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1550
1551 // Just for the first int10 find its children
1552
1553 // the default char height
1554 SET_BDA(char_height, 0x10);
1555
1556 // Clear the screen
1557 SET_BDA(video_ctl, 0x60);
1558
1559 // Set the basic screen we have
1560 SET_BDA(video_switches, 0xf9);
1561
1562 // Set the basic modeset options
1563 SET_BDA(modeset_ctl, 0x51);
1564
1565 // Set the default MSR
1566 SET_BDA(video_msr, 0x09);
1567}
1568
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001569void VISIBLE16
1570vga_post(struct bregs *regs)
1571{
1572 debug_enter(regs, DEBUG_VGA_POST);
1573
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001574 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001575
1576 init_bios_area();
1577
Julian Pidancet87879e22011-12-19 05:08:00 +00001578 vbe_init(regs->ah, regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001579
1580 extern void entry_10(void);
Kevin O'Connor9f985422009-09-09 11:34:39 -04001581 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001582
Julian Pidancet677631f2011-12-19 05:07:53 +00001583 if (CONFIG_VGA_CIRRUS)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001584 cirrus_init();
1585
1586 // XXX - clear screen and display info
1587
1588 // XXX: fill it
Kevin O'Connor815e4472011-12-21 09:05:32 -05001589 SET_VGA(video_save_pointer_table.videoparam
1590 , SEGOFF(get_global_seg(), (u32)video_param_table));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001591
1592 // Fixup checksum
1593 extern u8 _rom_header_size, _rom_header_checksum;
1594 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001595 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001596 SET_VGA(_rom_header_checksum, sum);
1597}