blob: 6d06cd68d10663aaa1b72c5bdee194ba610d9e83 [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
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040018
19// XXX
20#define CONFIG_VBE 0
21#define CONFIG_CIRRUS 0
22
23// XXX
24#define DEBUG_VGA_POST 1
25#define DEBUG_VGA_10 3
26
Kevin O'Connord113a992009-05-16 21:05:02 -040027#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040028
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040029
30/****************************************************************
31 * Helper functions
32 ****************************************************************/
33
Kevin O'Connor217f2bc2009-05-31 00:46:47 -040034static inline void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040035call16_vgaint(u32 eax, u32 ebx)
36{
37 asm volatile(
38 "int $0x10\n"
39 "cli\n"
40 "cld"
41 :
42 : "a"(eax), "b"(ebx)
43 : "cc", "memory");
44}
45
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040046static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040047perform_gray_scale_summing(u16 start, u16 count)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040048{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040049 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040050 int i;
51 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040052 u8 rgb[3];
53 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040054
55 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040056 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040057 if (intensity > 0x3f)
58 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040059
Kevin O'Connora0ecb052009-05-18 23:34:00 -040060 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040061 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040062 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040063}
64
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040065static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040066set_cursor_shape(u8 start, u8 end)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040067{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040068 start &= 0x3f;
69 end &= 0x1f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040070
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040071 u16 curs = (start << 8) + end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040072 SET_BDA(cursor_type, curs);
73
Kevin O'Connordd2be772009-05-16 15:41:23 -040074 u8 modeset_ctl = GET_BDA(modeset_ctl);
75 u16 cheight = GET_BDA(char_height);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040076 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
77 if (end != (start + 1))
78 start = ((start + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040079 else
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040080 start = ((end + 1) * cheight / 8) - 2;
81 end = ((end + 1) * cheight / 8) - 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040082 }
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040083 vgahw_set_cursor_shape(start, end);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040084}
85
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040086static u16
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040087get_cursor_shape(u8 page)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040088{
89 if (page > 7)
90 return 0;
91 // FIXME should handle VGA 14/16 lines
92 return GET_BDA(cursor_type);
93}
94
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040095static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040096set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040097{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040098 // Should not happen...
Kevin O'Connor918b1562009-05-25 11:05:18 -040099 if (cp.page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400100 return;
101
102 // Bios cursor pos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400103 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400104
105 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400106 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400107 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400108 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400109
Kevin O'Connordd2be772009-05-16 15:41:23 -0400110 // Get the dimensions
111 u16 nbcols = GET_BDA(video_cols);
112 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400113
Kevin O'Connordd2be772009-05-16 15:41:23 -0400114 // Calculate the address knowing nbcols nbrows and page num
Kevin O'Connor918b1562009-05-25 11:05:18 -0400115 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
116 + cp.x + cp.y * nbcols);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400117
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400118 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400119}
120
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400121static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400122get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400123{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400124 if (page == 0xff)
125 // special case - use current page
126 page = GET_BDA(video_page);
127 if (page > 7) {
128 struct cursorpos cp = { 0, 0, 0xfe };
129 return cp;
130 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400131 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400132 u16 xy = GET_BDA(cursor_pos[page]);
133 struct cursorpos cp = {xy, xy>>8, page};
134 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400135}
136
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400137static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400138set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400139{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400140 if (page > 7)
141 return;
142
143 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400144 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
145 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400146 return;
147
148 // Get pos curs pos for the right page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400149 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400150
Kevin O'Connordd2be772009-05-16 15:41:23 -0400151 u16 address;
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400152 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400153 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400154 u16 nbcols = GET_BDA(video_cols);
155 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400156
157 // Calculate the address knowing nbcols nbrows and page num
158 address = SCREEN_MEM_START(nbcols, nbrows, page);
159 SET_BDA(video_pagestart, address);
160
161 // Start address
162 address = SCREEN_IO_START(nbcols, nbrows, page);
163 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400164 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
165 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400166 }
167
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400168 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400169
170 // And change the BIOS page
171 SET_BDA(video_page, page);
172
Kevin O'Connora12c2152009-05-13 22:06:16 -0400173 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400174
175 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400176 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400177}
178
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400179static void
180set_scan_lines(u8 lines)
181{
182 vgahw_set_scan_lines(lines);
183 if (lines == 8)
184 set_cursor_shape(0x06, 0x07);
185 else
186 set_cursor_shape(lines - 4, lines - 3);
187 SET_BDA(char_height, lines);
188 u16 vde = vgahw_get_vde();
189 u8 rows = vde / lines;
190 SET_BDA(video_rows, rows - 1);
191 u16 cols = GET_BDA(video_cols);
192 SET_BDA(video_pagesize, rows * cols * 2);
193}
194
195
196/****************************************************************
197 * Character writing
198 ****************************************************************/
199
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400200// Scroll the screen one line. This function is designed to be called
201// tail-recursive to reduce stack usage.
202static void noinline
203scroll_one(u16 nbrows, u16 nbcols, u8 page)
Kevin O'Connor09262412009-05-25 11:44:11 -0400204{
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400205 struct cursorpos ul = {0, 0, page};
206 struct cursorpos lr = {nbcols-1, nbrows-1, page};
207 vgafb_scroll(1, -1, ul, lr);
208}
209
210// Write a character to the screen at a given position. Implement
211// special characters and scroll the screen if necessary.
212static void
213write_teletype(struct cursorpos *pcp, struct carattr ca)
214{
215 struct cursorpos cp = *pcp;
216
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400217 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400218 u16 nbrows = GET_BDA(video_rows) + 1;
219 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400220
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400221 switch (ca.car) {
222 case 7:
223 //FIXME should beep
224 break;
225 case 8:
226 if (cp.x > 0)
227 cp.x--;
228 break;
229 case '\r':
230 cp.x = 0;
231 break;
232 case '\n':
233 cp.y++;
234 break;
235 case '\t':
236 do {
237 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
238 vgafb_write_char(cp, dummyca);
239 cp.x++;
240 } while (cp.x < nbcols && cp.x % 8);
241 break;
242 default:
243 vgafb_write_char(cp, ca);
244 cp.x++;
245 }
246
Kevin O'Connor82221b22009-05-26 00:20:40 -0400247 // Do we need to wrap ?
248 if (cp.x == nbcols) {
249 cp.x = 0;
250 cp.y++;
251 }
252 // Do we need to scroll ?
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400253 if (cp.y < nbrows) {
254 *pcp = cp;
255 return;
Kevin O'Connor82221b22009-05-26 00:20:40 -0400256 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400257 // Scroll screen
258 cp.y--;
259 *pcp = cp;
260 scroll_one(nbrows, nbcols, cp.page);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400261}
262
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400263// Write out a buffer of alternating characters and attributes.
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400264static void
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400265write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400266{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400267 while (count--) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400268 u8 car = GET_FARVAR(seg, *offset_far);
269 offset_far++;
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400270 u8 attr = GET_FARVAR(seg, *offset_far);
271 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400272
Kevin O'Connor09262412009-05-25 11:44:11 -0400273 struct carattr ca = {car, attr, 1};
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400274 write_teletype(pcp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400275 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400276}
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400277
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400278// Write out a buffer of characters.
279static void
280write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
281{
282 while (count--) {
283 u8 car = GET_FARVAR(seg, *offset_far);
284 offset_far++;
285
286 struct carattr ca = {car, attr, 1};
287 write_teletype(pcp, ca);
288 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400289}
290
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400291
292/****************************************************************
293 * Save and restore bda state
294 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400295
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400296static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400297save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400298{
Kevin O'Connorca668642009-05-21 23:06:08 -0400299 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
300 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
301 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
302 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
303 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
304 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
305 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
306 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
307 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
308 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
309 u16 i;
310 for (i=0; i<8; i++)
311 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
312 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
313 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
314 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400315 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
316 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400317}
318
Kevin O'Connorca668642009-05-21 23:06:08 -0400319static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400320restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400321{
Kevin O'Connorca668642009-05-21 23:06:08 -0400322 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
323 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
324 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
325 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
326 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
327 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
328 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
329 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
330 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
331 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
332 u16 i;
333 for (i = 0; i < 8; i++)
334 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
335 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
336 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
337 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400338 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
339 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400340}
341
342
343/****************************************************************
344 * VGA int 10 handler
345 ****************************************************************/
346
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400347// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400348static void
349handle_1000(struct bregs *regs)
350{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400351 u8 noclearmem = regs->al & 0x80;
352 u8 mode = regs->al & 0x7f;
353
Kevin O'Connor918b1562009-05-25 11:05:18 -0400354 // Set regs->al
355 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400356 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400357 else if (mode == 6)
358 regs->al = 0x3f;
359 else
360 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400361
362 if (CONFIG_CIRRUS)
363 cirrus_set_video_mode(mode);
364
365 if (CONFIG_VBE)
366 if (vbe_has_vbe_display())
367 dispi_set_enable(VBE_DISPI_DISABLED);
368
369 // find the entry in the video modes
370 struct vgamode_s *vmode_g = find_vga_entry(mode);
371 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
372 if (!vmode_g)
373 return;
374
375 // Read the bios mode set control
376 u8 modeset_ctl = GET_BDA(modeset_ctl);
377
378 // Then we know the number of lines
379// FIXME
380
381 // if palette loading (bit 3 of modeset ctl = 0)
382 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
383 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
384
385 // From which palette
386 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
387 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
388
389 // Always 256*3 values
390 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
391 u16 i;
392 for (i = palsize; i < 0x0100; i++) {
393 static u8 rgb[3] VAR16;
394 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
395 }
396
397 if ((modeset_ctl & 0x02) == 0x02)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400398 perform_gray_scale_summing(0x00, 0x100);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400399 }
400
401 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
402 vgahw_set_mode(vparam_g);
403
404 if (noclearmem == 0x00)
405 clear_screen(vmode_g);
406
407 // Set CRTC address VGA or MDA
408 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
409 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
410 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
411
412 // Set the BIOS mem
413 u16 cheight = GET_GLOBAL(vparam_g->cheight);
414 SET_BDA(video_mode, mode);
415 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
416 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
417 SET_BDA(crtc_address, crtc_addr);
418 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
419 SET_BDA(char_height, cheight);
420 SET_BDA(video_ctl, (0x60 | noclearmem));
421 SET_BDA(video_switches, 0xF9);
422 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
423
424 // FIXME We nearly have the good tables. to be reworked
425 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
Kevin O'Connor9f985422009-09-09 11:34:39 -0400426 SET_BDA(video_savetable
427 , SEGOFF(get_global_seg(), (u32)video_save_pointer_table));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400428
429 // FIXME
430 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
431 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
432
433 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400434 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400435 set_cursor_shape(0x06, 0x07);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400436 // Set cursor pos for page 0..7
437 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400438 for (i = 0; i < 8; i++) {
439 struct cursorpos cp = {0, 0, i};
440 set_cursor_pos(cp);
441 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400442
443 // Set active page 0
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400444 set_active_page(0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400445
446 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400447 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400448 call16_vgaint(0x1104, 0);
449 call16_vgaint(0x1103, 0);
450 }
451 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400452 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400453
454 switch (cheight) {
455 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400456 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400457 break;
458 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400459 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400460 break;
461 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400462 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400463 break;
464 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400465}
466
467static void
468handle_1001(struct bregs *regs)
469{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400470 set_cursor_shape(regs->ch, regs->cl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400471}
472
473static void
474handle_1002(struct bregs *regs)
475{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400476 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
477 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400478}
479
480static void
481handle_1003(struct bregs *regs)
482{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400483 regs->cx = get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400484 struct cursorpos cp = get_cursor_pos(regs->bh);
485 regs->dl = cp.x;
486 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400487}
488
489// Read light pen pos (unimplemented)
490static void
491handle_1004(struct bregs *regs)
492{
493 debug_stub(regs);
494 regs->ax = regs->bx = regs->cx = regs->dx = 0;
495}
496
497static void
498handle_1005(struct bregs *regs)
499{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400500 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400501}
502
503static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400504verify_scroll(struct bregs *regs, int dir)
505{
506 u8 page = GET_BDA(video_page);
507 struct cursorpos ul = {regs->cl, regs->ch, page};
508 struct cursorpos lr = {regs->dl, regs->dh, page};
509
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400510 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400511 if (lr.y >= nbrows)
512 lr.y = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400513 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400514 if (lr.x >= nbcols)
515 lr.x = nbcols - 1;
516
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400517 if (ul.x > lr.x || ul.y > lr.y)
518 return;
519
520 u16 nblines = regs->al;
521 if (!nblines || nblines > lr.y - ul.y + 1)
522 nblines = lr.y - ul.y + 1;
523
524 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400525}
526
527static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400528handle_1006(struct bregs *regs)
529{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400530 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400531}
532
533static void
534handle_1007(struct bregs *regs)
535{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400536 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400537}
538
539static void
540handle_1008(struct bregs *regs)
541{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400542 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400543 regs->al = ca.car;
544 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400545}
546
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400547static void noinline
Kevin O'Connord3b38152009-05-26 00:05:37 -0400548write_chars(u8 page, struct carattr ca, u16 count)
549{
550 struct cursorpos cp = get_cursor_pos(page);
551 while (count--) {
552 vgafb_write_char(cp, ca);
553 cp.x++;
554 }
555}
556
557static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400558handle_1009(struct bregs *regs)
559{
Kevin O'Connor09262412009-05-25 11:44:11 -0400560 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400561 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400562}
563
564static void
565handle_100a(struct bregs *regs)
566{
Kevin O'Connor09262412009-05-25 11:44:11 -0400567 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400568 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400569}
570
571
572static void
573handle_100b00(struct bregs *regs)
574{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400575 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400576}
577
578static void
579handle_100b01(struct bregs *regs)
580{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400581 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400582}
583
584static void
585handle_100bXX(struct bregs *regs)
586{
587 debug_stub(regs);
588}
589
590static void
591handle_100b(struct bregs *regs)
592{
593 switch (regs->bh) {
594 case 0x00: handle_100b00(regs); break;
595 case 0x01: handle_100b01(regs); break;
596 default: handle_100bXX(regs); break;
597 }
598}
599
600
601static void
602handle_100c(struct bregs *regs)
603{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400604 // XXX - page (regs->bh) is unused
605 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400606}
607
608static void
609handle_100d(struct bregs *regs)
610{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400611 // XXX - page (regs->bh) is unused
612 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400613}
614
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400615static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400616handle_100e(struct bregs *regs)
617{
618 // Ralf Brown Interrupt list is WRONG on bh(page)
619 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400620 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400621 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400622 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400623 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400624}
625
626static void
627handle_100f(struct bregs *regs)
628{
Kevin O'Connore7132042009-05-25 00:10:35 -0400629 regs->bh = GET_BDA(video_page);
630 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
631 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400632}
633
634
635static void
636handle_101000(struct bregs *regs)
637{
638 if (regs->bl > 0x14)
639 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400640 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400641}
642
643static void
644handle_101001(struct bregs *regs)
645{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400646 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400647}
648
649static void
650handle_101002(struct bregs *regs)
651{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400652 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400653}
654
655static void
656handle_101003(struct bregs *regs)
657{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400658 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400659}
660
661static void
662handle_101007(struct bregs *regs)
663{
664 if (regs->bl > 0x14)
665 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400666 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400667}
668
669static void
670handle_101008(struct bregs *regs)
671{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400672 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400673}
674
675static void
676handle_101009(struct bregs *regs)
677{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400678 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400679}
680
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400681static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400682handle_101010(struct bregs *regs)
683{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400684 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
685 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400686}
687
688static void
689handle_101012(struct bregs *regs)
690{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400691 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400692}
693
694static void
695handle_101013(struct bregs *regs)
696{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400697 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
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_101015(struct bregs *regs)
702{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400703 u8 rgb[3];
704 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
705 regs->dh = rgb[0];
706 regs->ch = rgb[1];
707 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400708}
709
710static void
711handle_101017(struct bregs *regs)
712{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400713 vgahw_get_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_101018(struct bregs *regs)
718{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400719 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400720}
721
722static void
723handle_101019(struct bregs *regs)
724{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400725 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400726}
727
728static void
729handle_10101a(struct bregs *regs)
730{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400731 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400732}
733
734static void
735handle_10101b(struct bregs *regs)
736{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400737 perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400738}
739
740static void
741handle_1010XX(struct bregs *regs)
742{
743 debug_stub(regs);
744}
745
746static void
747handle_1010(struct bregs *regs)
748{
749 switch (regs->al) {
750 case 0x00: handle_101000(regs); break;
751 case 0x01: handle_101001(regs); break;
752 case 0x02: handle_101002(regs); break;
753 case 0x03: handle_101003(regs); break;
754 case 0x07: handle_101007(regs); break;
755 case 0x08: handle_101008(regs); break;
756 case 0x09: handle_101009(regs); break;
757 case 0x10: handle_101010(regs); break;
758 case 0x12: handle_101012(regs); break;
759 case 0x13: handle_101013(regs); break;
760 case 0x15: handle_101015(regs); break;
761 case 0x17: handle_101017(regs); break;
762 case 0x18: handle_101018(regs); break;
763 case 0x19: handle_101019(regs); break;
764 case 0x1a: handle_10101a(regs); break;
765 case 0x1b: handle_10101b(regs); break;
766 default: handle_1010XX(regs); break;
767 }
768}
769
770
771static void
772handle_101100(struct bregs *regs)
773{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400774 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
775 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400776}
777
778static void
779handle_101101(struct bregs *regs)
780{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400781 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400782}
783
784static void
785handle_101102(struct bregs *regs)
786{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400787 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400788}
789
790static void
791handle_101103(struct bregs *regs)
792{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400793 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400794}
795
796static void
797handle_101104(struct bregs *regs)
798{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400799 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400800}
801
802static void
803handle_101110(struct bregs *regs)
804{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400805 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
806 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400807 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400808}
809
810static void
811handle_101111(struct bregs *regs)
812{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400813 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400814 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400815}
816
817static void
818handle_101112(struct bregs *regs)
819{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400820 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400821 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400822}
823
824static void
825handle_101114(struct bregs *regs)
826{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400827 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400828 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400829}
830
831static void
832handle_101130(struct bregs *regs)
833{
Kevin O'Connore7132042009-05-25 00:10:35 -0400834 switch (regs->bh) {
835 case 0x00: {
836 u32 segoff = GET_IVT(0x1f).segoff;
837 regs->es = segoff >> 16;
838 regs->bp = segoff;
839 break;
840 }
841 case 0x01: {
842 u32 segoff = GET_IVT(0x43).segoff;
843 regs->es = segoff >> 16;
844 regs->bp = segoff;
845 break;
846 }
847 case 0x02:
848 regs->es = get_global_seg();
849 regs->bp = (u32)vgafont14;
850 break;
851 case 0x03:
852 regs->es = get_global_seg();
853 regs->bp = (u32)vgafont8;
854 break;
855 case 0x04:
856 regs->es = get_global_seg();
857 regs->bp = (u32)vgafont8 + 128 * 8;
858 break;
859 case 0x05:
860 regs->es = get_global_seg();
861 regs->bp = (u32)vgafont14alt;
862 break;
863 case 0x06:
864 regs->es = get_global_seg();
865 regs->bp = (u32)vgafont16;
866 break;
867 case 0x07:
868 regs->es = get_global_seg();
869 regs->bp = (u32)vgafont16alt;
870 break;
871 default:
872 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
873 return;
874 }
875 // Set byte/char of on screen font
876 regs->cx = GET_BDA(char_height) & 0xff;
877
878 // Set Highest char row
879 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400880}
881
882static void
883handle_1011XX(struct bregs *regs)
884{
885 debug_stub(regs);
886}
887
888static void
889handle_1011(struct bregs *regs)
890{
891 switch (regs->al) {
892 case 0x00: handle_101100(regs); break;
893 case 0x01: handle_101101(regs); break;
894 case 0x02: handle_101102(regs); break;
895 case 0x03: handle_101103(regs); break;
896 case 0x04: handle_101104(regs); break;
897 case 0x10: handle_101110(regs); break;
898 case 0x11: handle_101111(regs); break;
899 case 0x12: handle_101112(regs); break;
900 case 0x14: handle_101114(regs); break;
901 case 0x30: handle_101130(regs); break;
902 default: handle_1011XX(regs); break;
903 }
904}
905
906
907static void
908handle_101210(struct bregs *regs)
909{
Kevin O'Connore7132042009-05-25 00:10:35 -0400910 u16 crtc_addr = GET_BDA(crtc_address);
911 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
912 regs->bx = 0x0103;
913 else
914 regs->bx = 0x0003;
915 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400916}
917
918static void
919handle_101230(struct bregs *regs)
920{
Kevin O'Connore7132042009-05-25 00:10:35 -0400921 u8 mctl = GET_BDA(modeset_ctl);
922 u8 vswt = GET_BDA(video_switches);
923 switch (regs->al) {
924 case 0x00:
925 // 200 lines
926 mctl = (mctl & ~0x10) | 0x80;
927 vswt = (vswt & ~0x0f) | 0x08;
928 break;
929 case 0x01:
930 // 350 lines
931 mctl &= ~0x90;
932 vswt = (vswt & ~0x0f) | 0x09;
933 break;
934 case 0x02:
935 // 400 lines
936 mctl = (mctl & ~0x80) | 0x10;
937 vswt = (vswt & ~0x0f) | 0x09;
938 break;
939 default:
940 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
941 break;
942 }
943 SET_BDA(modeset_ctl, mctl);
944 SET_BDA(video_switches, vswt);
945 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400946}
947
948static void
949handle_101231(struct bregs *regs)
950{
Kevin O'Connore7132042009-05-25 00:10:35 -0400951 u8 v = (regs->al & 0x01) << 3;
952 u8 mctl = GET_BDA(video_ctl) & ~0x08;
953 SET_BDA(video_ctl, mctl | v);
954 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400955}
956
957static void
958handle_101232(struct bregs *regs)
959{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400960 vgahw_enable_video_addressing(regs->al);
961 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400962}
963
964static void
965handle_101233(struct bregs *regs)
966{
Kevin O'Connore7132042009-05-25 00:10:35 -0400967 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
968 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
969 SET_BDA(modeset_ctl, v | v2);
970 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400971}
972
973static void
974handle_101234(struct bregs *regs)
975{
Kevin O'Connore7132042009-05-25 00:10:35 -0400976 u8 v = (regs->al & 0x01) ^ 0x01;
977 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
978 SET_BDA(modeset_ctl, v | v2);
979 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400980}
981
982static void
983handle_101235(struct bregs *regs)
984{
985 debug_stub(regs);
986 regs->al = 0x12;
987}
988
989static void
990handle_101236(struct bregs *regs)
991{
992 debug_stub(regs);
993 regs->al = 0x12;
994}
995
996static void
997handle_1012XX(struct bregs *regs)
998{
999 debug_stub(regs);
1000}
1001
1002static void
1003handle_1012(struct bregs *regs)
1004{
1005 switch (regs->bl) {
1006 case 0x10: handle_101210(regs); break;
1007 case 0x30: handle_101230(regs); break;
1008 case 0x31: handle_101231(regs); break;
1009 case 0x32: handle_101232(regs); break;
1010 case 0x33: handle_101233(regs); break;
1011 case 0x34: handle_101234(regs); break;
1012 case 0x35: handle_101235(regs); break;
1013 case 0x36: handle_101236(regs); break;
1014 default: handle_1012XX(regs); break;
1015 }
1016
1017 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1018}
1019
1020
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001021// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -04001022static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001023handle_1013(struct bregs *regs)
1024{
Kevin O'Connor918b1562009-05-25 11:05:18 -04001025 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -04001026 // if row=0xff special case : use current cursor position
1027 if (cp.y == 0xff)
1028 cp = get_cursor_pos(cp.page);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001029 u8 flag = regs->al;
1030 if (flag & 2)
1031 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1032 else
1033 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1034
1035 if (flag & 1)
1036 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001037}
1038
1039
1040static void
1041handle_101a00(struct bregs *regs)
1042{
Kevin O'Connore7132042009-05-25 00:10:35 -04001043 regs->bx = GET_BDA(dcc_index);
1044 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001045}
1046
1047static void
1048handle_101a01(struct bregs *regs)
1049{
Kevin O'Connore7132042009-05-25 00:10:35 -04001050 SET_BDA(dcc_index, regs->bl);
1051 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1052 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001053}
1054
1055static void
1056handle_101aXX(struct bregs *regs)
1057{
1058 debug_stub(regs);
1059}
1060
1061static void
1062handle_101a(struct bregs *regs)
1063{
1064 switch (regs->al) {
1065 case 0x00: handle_101a00(regs); break;
1066 case 0x01: handle_101a01(regs); break;
1067 default: handle_101aXX(regs); break;
1068 }
1069}
1070
1071
Kevin O'Connorca668642009-05-21 23:06:08 -04001072struct funcInfo {
1073 u16 static_functionality_off;
1074 u16 static_functionality_seg;
1075 u8 bda_0x49[30];
1076 u8 bda_0x84[3];
1077 u8 dcc_index;
1078 u8 dcc_alt;
1079 u16 colors;
1080 u8 pages;
1081 u8 scan_lines;
1082 u8 primary_char;
1083 u8 secondar_char;
1084 u8 misc;
1085 u8 non_vga_mode;
1086 u8 reserved_2f[2];
1087 u8 video_mem;
1088 u8 save_flags;
1089 u8 disp_info;
1090 u8 reserved_34[12];
1091};
1092
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001093static void
1094handle_101b(struct bregs *regs)
1095{
Kevin O'Connorca668642009-05-21 23:06:08 -04001096 u16 seg = regs->es;
1097 struct funcInfo *info = (void*)(regs->di+0);
1098 memset_far(seg, info, 0, sizeof(*info));
1099 // Address of static functionality table
1100 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1101 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1102
1103 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001104 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1105 , sizeof(info->bda_0x49));
1106 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1107 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001108
1109 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1110 SET_FARVAR(seg, info->colors, 16);
1111 SET_FARVAR(seg, info->pages, 8);
1112 SET_FARVAR(seg, info->scan_lines, 2);
1113 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001114 regs->al = 0x1B;
1115}
1116
1117
1118static void
1119handle_101c00(struct bregs *regs)
1120{
Kevin O'Connorca668642009-05-21 23:06:08 -04001121 u16 flags = regs->cx;
1122 u16 size = 0;
1123 if (flags & 1)
1124 size += sizeof(struct saveVideoHardware);
1125 if (flags & 2)
1126 size += sizeof(struct saveBDAstate);
1127 if (flags & 4)
1128 size += sizeof(struct saveDACcolors);
1129 regs->bx = size;
1130 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001131}
1132
1133static void
1134handle_101c01(struct bregs *regs)
1135{
Kevin O'Connorca668642009-05-21 23:06:08 -04001136 u16 flags = regs->cx;
1137 u16 seg = regs->es;
1138 void *data = (void*)(regs->bx+0);
1139 if (flags & 1) {
1140 vgahw_save_state(seg, data);
1141 data += sizeof(struct saveVideoHardware);
1142 }
1143 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001144 save_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001145 data += sizeof(struct saveBDAstate);
1146 }
1147 if (flags & 4)
1148 vgahw_save_dac_state(seg, data);
1149 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001150}
1151
1152static void
1153handle_101c02(struct bregs *regs)
1154{
Kevin O'Connorca668642009-05-21 23:06:08 -04001155 u16 flags = regs->cx;
1156 u16 seg = regs->es;
1157 void *data = (void*)(regs->bx+0);
1158 if (flags & 1) {
1159 vgahw_restore_state(seg, data);
1160 data += sizeof(struct saveVideoHardware);
1161 }
1162 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001163 restore_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001164 data += sizeof(struct saveBDAstate);
1165 }
1166 if (flags & 4)
1167 vgahw_restore_dac_state(seg, data);
1168 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001169}
1170
1171static void
1172handle_101cXX(struct bregs *regs)
1173{
1174 debug_stub(regs);
1175}
1176
1177static void
1178handle_101c(struct bregs *regs)
1179{
1180 switch (regs->al) {
1181 case 0x00: handle_101c00(regs); break;
1182 case 0x01: handle_101c01(regs); break;
1183 case 0x02: handle_101c02(regs); break;
1184 default: handle_101cXX(regs); break;
1185 }
1186}
1187
1188
1189static void
1190handle_104f00(struct bregs *regs)
1191{
1192 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1193 // XXX - OR cirrus_vesa_00h
1194}
1195
1196static void
1197handle_104f01(struct bregs *regs)
1198{
1199 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1200 // XXX - OR cirrus_vesa_01h
1201}
1202
1203static void
1204handle_104f02(struct bregs *regs)
1205{
1206 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1207 // XXX - OR cirrus_vesa_02h
1208}
1209
1210static void
1211handle_104f03(struct bregs *regs)
1212{
1213 // XXX - vbe_biosfn_return_current_mode
1214 // XXX - OR cirrus_vesa_03h
1215}
1216
1217static void
1218handle_104f04(struct bregs *regs)
1219{
1220 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1221}
1222
1223static void
1224handle_104f05(struct bregs *regs)
1225{
1226 // XXX - vbe_biosfn_display_window_control
1227 // XXX - OR cirrus_vesa_05h
1228}
1229
1230static void
1231handle_104f06(struct bregs *regs)
1232{
1233 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1234 // XXX - OR cirrus_vesa_06h
1235}
1236
1237static void
1238handle_104f07(struct bregs *regs)
1239{
1240 // XXX - vbe_biosfn_set_get_display_start
1241 // XXX - OR cirrus_vesa_07h
1242}
1243
1244static void
1245handle_104f08(struct bregs *regs)
1246{
1247 // XXX - vbe_biosfn_set_get_dac_palette_format
1248}
1249
1250static void
1251handle_104f0a(struct bregs *regs)
1252{
1253 // XXX - vbe_biosfn_return_protected_mode_interface
1254}
1255
1256static void
1257handle_104fXX(struct bregs *regs)
1258{
1259 debug_stub(regs);
1260 regs->ax = 0x0100;
1261}
1262
1263static void
1264handle_104f(struct bregs *regs)
1265{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001266 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001267 handle_104fXX(regs);
1268 return;
1269 }
1270
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001271 switch (regs->al) {
1272 case 0x00: handle_104f00(regs); break;
1273 case 0x01: handle_104f01(regs); break;
1274 case 0x02: handle_104f02(regs); break;
1275 case 0x03: handle_104f03(regs); break;
1276 case 0x04: handle_104f04(regs); break;
1277 case 0x05: handle_104f05(regs); break;
1278 case 0x06: handle_104f06(regs); break;
1279 case 0x07: handle_104f07(regs); break;
1280 case 0x08: handle_104f08(regs); break;
1281 case 0x0a: handle_104f0a(regs); break;
1282 default: handle_104fXX(regs); break;
1283 }
1284}
1285
1286
1287static void
1288handle_10XX(struct bregs *regs)
1289{
1290 debug_stub(regs);
1291}
1292
1293// INT 10h Video Support Service Entry Point
1294void VISIBLE16
1295handle_10(struct bregs *regs)
1296{
1297 debug_enter(regs, DEBUG_VGA_10);
1298 switch (regs->ah) {
1299 case 0x00: handle_1000(regs); break;
1300 case 0x01: handle_1001(regs); break;
1301 case 0x02: handle_1002(regs); break;
1302 case 0x03: handle_1003(regs); break;
1303 case 0x04: handle_1004(regs); break;
1304 case 0x05: handle_1005(regs); break;
1305 case 0x06: handle_1006(regs); break;
1306 case 0x07: handle_1007(regs); break;
1307 case 0x08: handle_1008(regs); break;
1308 case 0x09: handle_1009(regs); break;
1309 case 0x0a: handle_100a(regs); break;
1310 case 0x0b: handle_100b(regs); break;
1311 case 0x0c: handle_100c(regs); break;
1312 case 0x0d: handle_100d(regs); break;
1313 case 0x0e: handle_100e(regs); break;
1314 case 0x0f: handle_100f(regs); break;
1315 case 0x10: handle_1010(regs); break;
1316 case 0x11: handle_1011(regs); break;
1317 case 0x12: handle_1012(regs); break;
1318 case 0x13: handle_1013(regs); break;
1319 case 0x1a: handle_101a(regs); break;
1320 case 0x1b: handle_101b(regs); break;
1321 case 0x1c: handle_101c(regs); break;
1322 case 0x4f: handle_104f(regs); break;
1323 default: handle_10XX(regs); break;
1324 }
1325}
1326
1327
1328/****************************************************************
1329 * VGA post
1330 ****************************************************************/
1331
1332static void
1333init_bios_area()
1334{
1335 // init detected hardware BIOS Area
1336 // set 80x25 color (not clear from RBIL but usual)
1337 u16 eqf = GET_BDA(equipment_list_flags);
1338 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1339
1340 // Just for the first int10 find its children
1341
1342 // the default char height
1343 SET_BDA(char_height, 0x10);
1344
1345 // Clear the screen
1346 SET_BDA(video_ctl, 0x60);
1347
1348 // Set the basic screen we have
1349 SET_BDA(video_switches, 0xf9);
1350
1351 // Set the basic modeset options
1352 SET_BDA(modeset_ctl, 0x51);
1353
1354 // Set the default MSR
1355 SET_BDA(video_msr, 0x09);
1356}
1357
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001358void VISIBLE16
1359vga_post(struct bregs *regs)
1360{
1361 debug_enter(regs, DEBUG_VGA_POST);
1362
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001363 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001364
1365 init_bios_area();
1366
Kevin O'Connor21079f42009-05-16 21:30:10 -04001367 if (CONFIG_VBE)
1368 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001369
1370 extern void entry_10(void);
Kevin O'Connor9f985422009-09-09 11:34:39 -04001371 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001372
1373 if (CONFIG_CIRRUS)
1374 cirrus_init();
1375
1376 // XXX - clear screen and display info
1377
1378 // XXX: fill it
1379 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001380 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001381
1382 // Fixup checksum
1383 extern u8 _rom_header_size, _rom_header_checksum;
1384 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001385 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001386 SET_VGA(_rom_header_checksum, sum);
1387}