blob: 748ddd49bfe0fd643a2459b42cf1fa7eeaad1ac4 [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_*
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040020
21// XXX
Julian Pidancet677631f2011-12-19 05:07:53 +000022#define CONFIG_VGA_BOCHS 0
23#define CONFIG_VGA_CIRRUS 0
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040024
25// XXX
26#define DEBUG_VGA_POST 1
27#define DEBUG_VGA_10 3
28
Kevin O'Connord113a992009-05-16 21:05:02 -040029#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040030
Julian Pidancet7c6509c2011-12-19 05:07:55 +000031/****************************************************************
32 * PCI Data
33 ****************************************************************/
34#if CONFIG_VGA_PCI == 1
35struct pci_data rom_pci_data VAR16VISIBLE = {
36 .signature = PCI_ROM_SIGNATURE,
37 .vendor = CONFIG_VGA_VID,
38 .device = CONFIG_VGA_DID,
39 .dlen = 0x18,
40 .class_hi = 0x300,
41 .irevision = 1,
42 .type = PCIROM_CODETYPE_X86,
43 .indicator = 0x80,
44};
45#endif
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040046
47/****************************************************************
48 * Helper functions
49 ****************************************************************/
50
Kevin O'Connor217f2bc2009-05-31 00:46:47 -040051static inline void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040052call16_vgaint(u32 eax, u32 ebx)
53{
54 asm volatile(
55 "int $0x10\n"
56 "cli\n"
57 "cld"
58 :
59 : "a"(eax), "b"(ebx)
60 : "cc", "memory");
61}
62
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040063static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040064perform_gray_scale_summing(u16 start, u16 count)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040065{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040066 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040067 int i;
68 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040069 u8 rgb[3];
70 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040071
72 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040073 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040074 if (intensity > 0x3f)
75 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040076
Kevin O'Connora0ecb052009-05-18 23:34:00 -040077 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040078 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040079 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040080}
81
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040082static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040083set_cursor_shape(u8 start, u8 end)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040084{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040085 start &= 0x3f;
86 end &= 0x1f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040087
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040088 u16 curs = (start << 8) + end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040089 SET_BDA(cursor_type, curs);
90
Kevin O'Connordd2be772009-05-16 15:41:23 -040091 u8 modeset_ctl = GET_BDA(modeset_ctl);
92 u16 cheight = GET_BDA(char_height);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040093 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
94 if (end != (start + 1))
95 start = ((start + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040096 else
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040097 start = ((end + 1) * cheight / 8) - 2;
98 end = ((end + 1) * cheight / 8) - 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040099 }
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400100 vgahw_set_cursor_shape(start, end);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400101}
102
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400103static u16
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400104get_cursor_shape(u8 page)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400105{
106 if (page > 7)
107 return 0;
108 // FIXME should handle VGA 14/16 lines
109 return GET_BDA(cursor_type);
110}
111
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400112static void
Kevin O'Connor918b1562009-05-25 11:05:18 -0400113set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400114{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400115 // Should not happen...
Kevin O'Connor918b1562009-05-25 11:05:18 -0400116 if (cp.page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400117 return;
118
119 // Bios cursor pos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400120 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400121
122 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400123 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400124 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400125 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400126
Kevin O'Connordd2be772009-05-16 15:41:23 -0400127 // Get the dimensions
128 u16 nbcols = GET_BDA(video_cols);
129 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400130
Kevin O'Connordd2be772009-05-16 15:41:23 -0400131 // Calculate the address knowing nbcols nbrows and page num
Kevin O'Connor918b1562009-05-25 11:05:18 -0400132 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
133 + cp.x + cp.y * nbcols);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400134
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400135 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400136}
137
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400138static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400139get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400140{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400141 if (page == 0xff)
142 // special case - use current page
143 page = GET_BDA(video_page);
144 if (page > 7) {
145 struct cursorpos cp = { 0, 0, 0xfe };
146 return cp;
147 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400148 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400149 u16 xy = GET_BDA(cursor_pos[page]);
150 struct cursorpos cp = {xy, xy>>8, page};
151 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400152}
153
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400154static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400155set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400156{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400157 if (page > 7)
158 return;
159
160 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400161 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
162 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400163 return;
164
165 // Get pos curs pos for the right page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400166 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400167
Kevin O'Connordd2be772009-05-16 15:41:23 -0400168 u16 address;
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400169 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400170 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400171 u16 nbcols = GET_BDA(video_cols);
172 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400173
174 // Calculate the address knowing nbcols nbrows and page num
175 address = SCREEN_MEM_START(nbcols, nbrows, page);
176 SET_BDA(video_pagestart, address);
177
178 // Start address
179 address = SCREEN_IO_START(nbcols, nbrows, page);
180 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400181 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
182 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400183 }
184
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400185 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400186
187 // And change the BIOS page
188 SET_BDA(video_page, page);
189
Kevin O'Connora12c2152009-05-13 22:06:16 -0400190 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400191
192 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400193 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400194}
195
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400196static void
197set_scan_lines(u8 lines)
198{
199 vgahw_set_scan_lines(lines);
200 if (lines == 8)
201 set_cursor_shape(0x06, 0x07);
202 else
203 set_cursor_shape(lines - 4, lines - 3);
204 SET_BDA(char_height, lines);
205 u16 vde = vgahw_get_vde();
206 u8 rows = vde / lines;
207 SET_BDA(video_rows, rows - 1);
208 u16 cols = GET_BDA(video_cols);
209 SET_BDA(video_pagesize, rows * cols * 2);
210}
211
212
213/****************************************************************
214 * Character writing
215 ****************************************************************/
216
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400217// Scroll the screen one line. This function is designed to be called
218// tail-recursive to reduce stack usage.
219static void noinline
220scroll_one(u16 nbrows, u16 nbcols, u8 page)
Kevin O'Connor09262412009-05-25 11:44:11 -0400221{
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400222 struct cursorpos ul = {0, 0, page};
223 struct cursorpos lr = {nbcols-1, nbrows-1, page};
224 vgafb_scroll(1, -1, ul, lr);
225}
226
227// Write a character to the screen at a given position. Implement
228// special characters and scroll the screen if necessary.
229static void
230write_teletype(struct cursorpos *pcp, struct carattr ca)
231{
232 struct cursorpos cp = *pcp;
233
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400234 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400235 u16 nbrows = GET_BDA(video_rows) + 1;
236 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400237
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400238 switch (ca.car) {
239 case 7:
240 //FIXME should beep
241 break;
242 case 8:
243 if (cp.x > 0)
244 cp.x--;
245 break;
246 case '\r':
247 cp.x = 0;
248 break;
249 case '\n':
250 cp.y++;
251 break;
252 case '\t':
253 do {
254 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
255 vgafb_write_char(cp, dummyca);
256 cp.x++;
257 } while (cp.x < nbcols && cp.x % 8);
258 break;
259 default:
260 vgafb_write_char(cp, ca);
261 cp.x++;
262 }
263
Kevin O'Connor82221b22009-05-26 00:20:40 -0400264 // Do we need to wrap ?
265 if (cp.x == nbcols) {
266 cp.x = 0;
267 cp.y++;
268 }
269 // Do we need to scroll ?
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400270 if (cp.y < nbrows) {
271 *pcp = cp;
272 return;
Kevin O'Connor82221b22009-05-26 00:20:40 -0400273 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400274 // Scroll screen
275 cp.y--;
276 *pcp = cp;
277 scroll_one(nbrows, nbcols, cp.page);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400278}
279
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400280// Write out a buffer of alternating characters and attributes.
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400281static void
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400282write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400283{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400284 while (count--) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400285 u8 car = GET_FARVAR(seg, *offset_far);
286 offset_far++;
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400287 u8 attr = GET_FARVAR(seg, *offset_far);
288 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400289
Kevin O'Connor09262412009-05-25 11:44:11 -0400290 struct carattr ca = {car, attr, 1};
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400291 write_teletype(pcp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400292 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400293}
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400294
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400295// Write out a buffer of characters.
296static void
297write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
298{
299 while (count--) {
300 u8 car = GET_FARVAR(seg, *offset_far);
301 offset_far++;
302
303 struct carattr ca = {car, attr, 1};
304 write_teletype(pcp, ca);
305 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400306}
307
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400308
309/****************************************************************
310 * Save and restore bda state
311 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400312
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400313static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400314save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400315{
Kevin O'Connorca668642009-05-21 23:06:08 -0400316 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
317 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
318 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
319 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
320 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
321 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
322 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
323 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
324 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
325 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
326 u16 i;
327 for (i=0; i<8; i++)
328 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
329 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
330 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
331 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400332 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
333 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400334}
335
Kevin O'Connorca668642009-05-21 23:06:08 -0400336static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400337restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400338{
Kevin O'Connorca668642009-05-21 23:06:08 -0400339 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
340 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
341 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
342 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
343 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
344 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
345 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
346 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
347 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
348 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
349 u16 i;
350 for (i = 0; i < 8; i++)
351 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
352 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
353 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
354 /* current font */
Kevin O'Connor9f985422009-09-09 11:34:39 -0400355 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
356 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400357}
358
359
360/****************************************************************
361 * VGA int 10 handler
362 ****************************************************************/
363
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400364// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400365static void
366handle_1000(struct bregs *regs)
367{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400368 u8 noclearmem = regs->al & 0x80;
369 u8 mode = regs->al & 0x7f;
370
Kevin O'Connor918b1562009-05-25 11:05:18 -0400371 // Set regs->al
372 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400373 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400374 else if (mode == 6)
375 regs->al = 0x3f;
376 else
377 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400378
Julian Pidancet677631f2011-12-19 05:07:53 +0000379 if (CONFIG_VGA_CIRRUS)
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400380 cirrus_set_video_mode(mode);
381
Julian Pidancet677631f2011-12-19 05:07:53 +0000382 if (CONFIG_VGA_BOCHS)
383 if (bochs_has_vbe_display())
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400384 dispi_set_enable(VBE_DISPI_DISABLED);
385
386 // find the entry in the video modes
387 struct vgamode_s *vmode_g = find_vga_entry(mode);
388 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
389 if (!vmode_g)
390 return;
391
392 // Read the bios mode set control
393 u8 modeset_ctl = GET_BDA(modeset_ctl);
394
395 // Then we know the number of lines
396// FIXME
397
398 // if palette loading (bit 3 of modeset ctl = 0)
399 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
400 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
401
402 // From which palette
403 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
404 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
405
406 // Always 256*3 values
407 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
408 u16 i;
409 for (i = palsize; i < 0x0100; i++) {
410 static u8 rgb[3] VAR16;
411 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
412 }
413
414 if ((modeset_ctl & 0x02) == 0x02)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400415 perform_gray_scale_summing(0x00, 0x100);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400416 }
417
418 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
419 vgahw_set_mode(vparam_g);
420
421 if (noclearmem == 0x00)
422 clear_screen(vmode_g);
423
424 // Set CRTC address VGA or MDA
425 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
426 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
427 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
428
429 // Set the BIOS mem
430 u16 cheight = GET_GLOBAL(vparam_g->cheight);
431 SET_BDA(video_mode, mode);
432 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
433 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
434 SET_BDA(crtc_address, crtc_addr);
435 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
436 SET_BDA(char_height, cheight);
437 SET_BDA(video_ctl, (0x60 | noclearmem));
438 SET_BDA(video_switches, 0xF9);
439 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
440
441 // FIXME We nearly have the good tables. to be reworked
442 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
Kevin O'Connor9f985422009-09-09 11:34:39 -0400443 SET_BDA(video_savetable
444 , SEGOFF(get_global_seg(), (u32)video_save_pointer_table));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400445
446 // FIXME
447 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
448 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
449
450 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400451 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400452 set_cursor_shape(0x06, 0x07);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400453 // Set cursor pos for page 0..7
454 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400455 for (i = 0; i < 8; i++) {
456 struct cursorpos cp = {0, 0, i};
457 set_cursor_pos(cp);
458 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400459
460 // Set active page 0
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400461 set_active_page(0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400462
463 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400464 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400465 call16_vgaint(0x1104, 0);
466 call16_vgaint(0x1103, 0);
467 }
468 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400469 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400470
471 switch (cheight) {
472 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400473 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400474 break;
475 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400476 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400477 break;
478 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400479 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400480 break;
481 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400482}
483
484static void
485handle_1001(struct bregs *regs)
486{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400487 set_cursor_shape(regs->ch, regs->cl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400488}
489
490static void
491handle_1002(struct bregs *regs)
492{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400493 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
494 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400495}
496
497static void
498handle_1003(struct bregs *regs)
499{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400500 regs->cx = get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400501 struct cursorpos cp = get_cursor_pos(regs->bh);
502 regs->dl = cp.x;
503 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400504}
505
506// Read light pen pos (unimplemented)
507static void
508handle_1004(struct bregs *regs)
509{
510 debug_stub(regs);
511 regs->ax = regs->bx = regs->cx = regs->dx = 0;
512}
513
514static void
515handle_1005(struct bregs *regs)
516{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400517 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400518}
519
520static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400521verify_scroll(struct bregs *regs, int dir)
522{
523 u8 page = GET_BDA(video_page);
524 struct cursorpos ul = {regs->cl, regs->ch, page};
525 struct cursorpos lr = {regs->dl, regs->dh, page};
526
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400527 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400528 if (lr.y >= nbrows)
529 lr.y = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400530 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400531 if (lr.x >= nbcols)
532 lr.x = nbcols - 1;
533
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400534 if (ul.x > lr.x || ul.y > lr.y)
535 return;
536
537 u16 nblines = regs->al;
538 if (!nblines || nblines > lr.y - ul.y + 1)
539 nblines = lr.y - ul.y + 1;
540
541 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400542}
543
544static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400545handle_1006(struct bregs *regs)
546{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400547 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400548}
549
550static void
551handle_1007(struct bregs *regs)
552{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400553 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400554}
555
556static void
557handle_1008(struct bregs *regs)
558{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400559 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400560 regs->al = ca.car;
561 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400562}
563
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400564static void noinline
Kevin O'Connord3b38152009-05-26 00:05:37 -0400565write_chars(u8 page, struct carattr ca, u16 count)
566{
567 struct cursorpos cp = get_cursor_pos(page);
568 while (count--) {
569 vgafb_write_char(cp, ca);
570 cp.x++;
571 }
572}
573
574static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400575handle_1009(struct bregs *regs)
576{
Kevin O'Connor09262412009-05-25 11:44:11 -0400577 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400578 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400579}
580
581static void
582handle_100a(struct bregs *regs)
583{
Kevin O'Connor09262412009-05-25 11:44:11 -0400584 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400585 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400586}
587
588
589static void
590handle_100b00(struct bregs *regs)
591{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400592 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400593}
594
595static void
596handle_100b01(struct bregs *regs)
597{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400598 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400599}
600
601static void
602handle_100bXX(struct bregs *regs)
603{
604 debug_stub(regs);
605}
606
607static void
608handle_100b(struct bregs *regs)
609{
610 switch (regs->bh) {
611 case 0x00: handle_100b00(regs); break;
612 case 0x01: handle_100b01(regs); break;
613 default: handle_100bXX(regs); break;
614 }
615}
616
617
618static void
619handle_100c(struct bregs *regs)
620{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400621 // XXX - page (regs->bh) is unused
622 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400623}
624
625static void
626handle_100d(struct bregs *regs)
627{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400628 // XXX - page (regs->bh) is unused
629 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400630}
631
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400632static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400633handle_100e(struct bregs *regs)
634{
635 // Ralf Brown Interrupt list is WRONG on bh(page)
636 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400637 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400638 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400639 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400640 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400641}
642
643static void
644handle_100f(struct bregs *regs)
645{
Kevin O'Connore7132042009-05-25 00:10:35 -0400646 regs->bh = GET_BDA(video_page);
647 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
648 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400649}
650
651
652static void
653handle_101000(struct bregs *regs)
654{
655 if (regs->bl > 0x14)
656 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400657 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400658}
659
660static void
661handle_101001(struct bregs *regs)
662{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400663 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400664}
665
666static void
667handle_101002(struct bregs *regs)
668{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400669 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400670}
671
672static void
673handle_101003(struct bregs *regs)
674{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400675 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400676}
677
678static void
679handle_101007(struct bregs *regs)
680{
681 if (regs->bl > 0x14)
682 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400683 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400684}
685
686static void
687handle_101008(struct bregs *regs)
688{
Kevin O'Connor3862b2d2010-01-03 17:53:58 -0500689 regs->bh = vgahw_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400690}
691
692static void
693handle_101009(struct bregs *regs)
694{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400695 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400696}
697
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400698static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400699handle_101010(struct bregs *regs)
700{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400701 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
702 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400703}
704
705static void
706handle_101012(struct bregs *regs)
707{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400708 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400709}
710
711static void
712handle_101013(struct bregs *regs)
713{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400714 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400715}
716
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400717static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400718handle_101015(struct bregs *regs)
719{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400720 u8 rgb[3];
721 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
722 regs->dh = rgb[0];
723 regs->ch = rgb[1];
724 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400725}
726
727static void
728handle_101017(struct bregs *regs)
729{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400730 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400731}
732
733static void
734handle_101018(struct bregs *regs)
735{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400736 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400737}
738
739static void
740handle_101019(struct bregs *regs)
741{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400742 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400743}
744
745static void
746handle_10101a(struct bregs *regs)
747{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400748 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400749}
750
751static void
752handle_10101b(struct bregs *regs)
753{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400754 perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400755}
756
757static void
758handle_1010XX(struct bregs *regs)
759{
760 debug_stub(regs);
761}
762
763static void
764handle_1010(struct bregs *regs)
765{
766 switch (regs->al) {
767 case 0x00: handle_101000(regs); break;
768 case 0x01: handle_101001(regs); break;
769 case 0x02: handle_101002(regs); break;
770 case 0x03: handle_101003(regs); break;
771 case 0x07: handle_101007(regs); break;
772 case 0x08: handle_101008(regs); break;
773 case 0x09: handle_101009(regs); break;
774 case 0x10: handle_101010(regs); break;
775 case 0x12: handle_101012(regs); break;
776 case 0x13: handle_101013(regs); break;
777 case 0x15: handle_101015(regs); break;
778 case 0x17: handle_101017(regs); break;
779 case 0x18: handle_101018(regs); break;
780 case 0x19: handle_101019(regs); break;
781 case 0x1a: handle_10101a(regs); break;
782 case 0x1b: handle_10101b(regs); break;
783 default: handle_1010XX(regs); break;
784 }
785}
786
787
788static void
789handle_101100(struct bregs *regs)
790{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400791 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
792 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400793}
794
795static void
796handle_101101(struct bregs *regs)
797{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400798 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400799}
800
801static void
802handle_101102(struct bregs *regs)
803{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400804 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400805}
806
807static void
808handle_101103(struct bregs *regs)
809{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400810 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400811}
812
813static void
814handle_101104(struct bregs *regs)
815{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400816 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400817}
818
819static void
820handle_101110(struct bregs *regs)
821{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400822 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
823 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400824 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400825}
826
827static void
828handle_101111(struct bregs *regs)
829{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400830 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400831 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400832}
833
834static void
835handle_101112(struct bregs *regs)
836{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400837 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400838 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400839}
840
841static void
842handle_101114(struct bregs *regs)
843{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400844 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400845 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400846}
847
848static void
849handle_101130(struct bregs *regs)
850{
Kevin O'Connore7132042009-05-25 00:10:35 -0400851 switch (regs->bh) {
852 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500853 struct segoff_s so = GET_IVT(0x1f);
854 regs->es = so.seg;
855 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400856 break;
857 }
858 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500859 struct segoff_s so = GET_IVT(0x43);
860 regs->es = so.seg;
861 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400862 break;
863 }
864 case 0x02:
865 regs->es = get_global_seg();
866 regs->bp = (u32)vgafont14;
867 break;
868 case 0x03:
869 regs->es = get_global_seg();
870 regs->bp = (u32)vgafont8;
871 break;
872 case 0x04:
873 regs->es = get_global_seg();
874 regs->bp = (u32)vgafont8 + 128 * 8;
875 break;
876 case 0x05:
877 regs->es = get_global_seg();
878 regs->bp = (u32)vgafont14alt;
879 break;
880 case 0x06:
881 regs->es = get_global_seg();
882 regs->bp = (u32)vgafont16;
883 break;
884 case 0x07:
885 regs->es = get_global_seg();
886 regs->bp = (u32)vgafont16alt;
887 break;
888 default:
889 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
890 return;
891 }
892 // Set byte/char of on screen font
893 regs->cx = GET_BDA(char_height) & 0xff;
894
895 // Set Highest char row
896 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400897}
898
899static void
900handle_1011XX(struct bregs *regs)
901{
902 debug_stub(regs);
903}
904
905static void
906handle_1011(struct bregs *regs)
907{
908 switch (regs->al) {
909 case 0x00: handle_101100(regs); break;
910 case 0x01: handle_101101(regs); break;
911 case 0x02: handle_101102(regs); break;
912 case 0x03: handle_101103(regs); break;
913 case 0x04: handle_101104(regs); break;
914 case 0x10: handle_101110(regs); break;
915 case 0x11: handle_101111(regs); break;
916 case 0x12: handle_101112(regs); break;
917 case 0x14: handle_101114(regs); break;
918 case 0x30: handle_101130(regs); break;
919 default: handle_1011XX(regs); break;
920 }
921}
922
923
924static void
925handle_101210(struct bregs *regs)
926{
Kevin O'Connore7132042009-05-25 00:10:35 -0400927 u16 crtc_addr = GET_BDA(crtc_address);
928 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
929 regs->bx = 0x0103;
930 else
931 regs->bx = 0x0003;
932 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400933}
934
935static void
936handle_101230(struct bregs *regs)
937{
Kevin O'Connore7132042009-05-25 00:10:35 -0400938 u8 mctl = GET_BDA(modeset_ctl);
939 u8 vswt = GET_BDA(video_switches);
940 switch (regs->al) {
941 case 0x00:
942 // 200 lines
943 mctl = (mctl & ~0x10) | 0x80;
944 vswt = (vswt & ~0x0f) | 0x08;
945 break;
946 case 0x01:
947 // 350 lines
948 mctl &= ~0x90;
949 vswt = (vswt & ~0x0f) | 0x09;
950 break;
951 case 0x02:
952 // 400 lines
953 mctl = (mctl & ~0x80) | 0x10;
954 vswt = (vswt & ~0x0f) | 0x09;
955 break;
956 default:
957 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
958 break;
959 }
960 SET_BDA(modeset_ctl, mctl);
961 SET_BDA(video_switches, vswt);
962 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400963}
964
965static void
966handle_101231(struct bregs *regs)
967{
Kevin O'Connore7132042009-05-25 00:10:35 -0400968 u8 v = (regs->al & 0x01) << 3;
969 u8 mctl = GET_BDA(video_ctl) & ~0x08;
970 SET_BDA(video_ctl, mctl | v);
971 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400972}
973
974static void
975handle_101232(struct bregs *regs)
976{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400977 vgahw_enable_video_addressing(regs->al);
978 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400979}
980
981static void
982handle_101233(struct bregs *regs)
983{
Kevin O'Connore7132042009-05-25 00:10:35 -0400984 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
985 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
986 SET_BDA(modeset_ctl, v | v2);
987 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400988}
989
990static void
991handle_101234(struct bregs *regs)
992{
Kevin O'Connore7132042009-05-25 00:10:35 -0400993 u8 v = (regs->al & 0x01) ^ 0x01;
994 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
995 SET_BDA(modeset_ctl, v | v2);
996 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400997}
998
999static void
1000handle_101235(struct bregs *regs)
1001{
1002 debug_stub(regs);
1003 regs->al = 0x12;
1004}
1005
1006static void
1007handle_101236(struct bregs *regs)
1008{
1009 debug_stub(regs);
1010 regs->al = 0x12;
1011}
1012
1013static void
1014handle_1012XX(struct bregs *regs)
1015{
1016 debug_stub(regs);
1017}
1018
1019static void
1020handle_1012(struct bregs *regs)
1021{
1022 switch (regs->bl) {
1023 case 0x10: handle_101210(regs); break;
1024 case 0x30: handle_101230(regs); break;
1025 case 0x31: handle_101231(regs); break;
1026 case 0x32: handle_101232(regs); break;
1027 case 0x33: handle_101233(regs); break;
1028 case 0x34: handle_101234(regs); break;
1029 case 0x35: handle_101235(regs); break;
1030 case 0x36: handle_101236(regs); break;
1031 default: handle_1012XX(regs); break;
1032 }
1033
1034 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1035}
1036
1037
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001038// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -04001039static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001040handle_1013(struct bregs *regs)
1041{
Kevin O'Connor918b1562009-05-25 11:05:18 -04001042 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -04001043 // if row=0xff special case : use current cursor position
1044 if (cp.y == 0xff)
1045 cp = get_cursor_pos(cp.page);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001046 u8 flag = regs->al;
1047 if (flag & 2)
1048 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1049 else
1050 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1051
1052 if (flag & 1)
1053 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001054}
1055
1056
1057static void
1058handle_101a00(struct bregs *regs)
1059{
Kevin O'Connore7132042009-05-25 00:10:35 -04001060 regs->bx = GET_BDA(dcc_index);
1061 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001062}
1063
1064static void
1065handle_101a01(struct bregs *regs)
1066{
Kevin O'Connore7132042009-05-25 00:10:35 -04001067 SET_BDA(dcc_index, regs->bl);
1068 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1069 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001070}
1071
1072static void
1073handle_101aXX(struct bregs *regs)
1074{
1075 debug_stub(regs);
1076}
1077
1078static void
1079handle_101a(struct bregs *regs)
1080{
1081 switch (regs->al) {
1082 case 0x00: handle_101a00(regs); break;
1083 case 0x01: handle_101a01(regs); break;
1084 default: handle_101aXX(regs); break;
1085 }
1086}
1087
1088
Kevin O'Connorca668642009-05-21 23:06:08 -04001089struct funcInfo {
1090 u16 static_functionality_off;
1091 u16 static_functionality_seg;
1092 u8 bda_0x49[30];
1093 u8 bda_0x84[3];
1094 u8 dcc_index;
1095 u8 dcc_alt;
1096 u16 colors;
1097 u8 pages;
1098 u8 scan_lines;
1099 u8 primary_char;
1100 u8 secondar_char;
1101 u8 misc;
1102 u8 non_vga_mode;
1103 u8 reserved_2f[2];
1104 u8 video_mem;
1105 u8 save_flags;
1106 u8 disp_info;
1107 u8 reserved_34[12];
1108};
1109
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001110static void
1111handle_101b(struct bregs *regs)
1112{
Kevin O'Connorca668642009-05-21 23:06:08 -04001113 u16 seg = regs->es;
1114 struct funcInfo *info = (void*)(regs->di+0);
1115 memset_far(seg, info, 0, sizeof(*info));
1116 // Address of static functionality table
1117 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1118 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1119
1120 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001121 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1122 , sizeof(info->bda_0x49));
1123 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1124 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001125
1126 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1127 SET_FARVAR(seg, info->colors, 16);
1128 SET_FARVAR(seg, info->pages, 8);
1129 SET_FARVAR(seg, info->scan_lines, 2);
1130 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001131 regs->al = 0x1B;
1132}
1133
1134
1135static void
1136handle_101c00(struct bregs *regs)
1137{
Kevin O'Connorca668642009-05-21 23:06:08 -04001138 u16 flags = regs->cx;
1139 u16 size = 0;
1140 if (flags & 1)
1141 size += sizeof(struct saveVideoHardware);
1142 if (flags & 2)
1143 size += sizeof(struct saveBDAstate);
1144 if (flags & 4)
1145 size += sizeof(struct saveDACcolors);
1146 regs->bx = size;
1147 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001148}
1149
1150static void
1151handle_101c01(struct bregs *regs)
1152{
Kevin O'Connorca668642009-05-21 23:06:08 -04001153 u16 flags = regs->cx;
1154 u16 seg = regs->es;
1155 void *data = (void*)(regs->bx+0);
1156 if (flags & 1) {
1157 vgahw_save_state(seg, data);
1158 data += sizeof(struct saveVideoHardware);
1159 }
1160 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001161 save_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001162 data += sizeof(struct saveBDAstate);
1163 }
1164 if (flags & 4)
1165 vgahw_save_dac_state(seg, data);
1166 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001167}
1168
1169static void
1170handle_101c02(struct bregs *regs)
1171{
Kevin O'Connorca668642009-05-21 23:06:08 -04001172 u16 flags = regs->cx;
1173 u16 seg = regs->es;
1174 void *data = (void*)(regs->bx+0);
1175 if (flags & 1) {
1176 vgahw_restore_state(seg, data);
1177 data += sizeof(struct saveVideoHardware);
1178 }
1179 if (flags & 2) {
Kevin O'Connor227a2bb2009-05-31 22:00:20 -04001180 restore_bda_state(seg, data);
Kevin O'Connorca668642009-05-21 23:06:08 -04001181 data += sizeof(struct saveBDAstate);
1182 }
1183 if (flags & 4)
1184 vgahw_restore_dac_state(seg, data);
1185 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001186}
1187
1188static void
1189handle_101cXX(struct bregs *regs)
1190{
1191 debug_stub(regs);
1192}
1193
1194static void
1195handle_101c(struct bregs *regs)
1196{
1197 switch (regs->al) {
1198 case 0x00: handle_101c00(regs); break;
1199 case 0x01: handle_101c01(regs); break;
1200 case 0x02: handle_101c02(regs); break;
1201 default: handle_101cXX(regs); break;
1202 }
1203}
1204
1205
1206static void
1207handle_104f00(struct bregs *regs)
1208{
1209 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1210 // XXX - OR cirrus_vesa_00h
1211}
1212
1213static void
1214handle_104f01(struct bregs *regs)
1215{
1216 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1217 // XXX - OR cirrus_vesa_01h
1218}
1219
1220static void
1221handle_104f02(struct bregs *regs)
1222{
1223 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1224 // XXX - OR cirrus_vesa_02h
1225}
1226
1227static void
1228handle_104f03(struct bregs *regs)
1229{
1230 // XXX - vbe_biosfn_return_current_mode
1231 // XXX - OR cirrus_vesa_03h
1232}
1233
1234static void
1235handle_104f04(struct bregs *regs)
1236{
1237 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1238}
1239
1240static void
1241handle_104f05(struct bregs *regs)
1242{
1243 // XXX - vbe_biosfn_display_window_control
1244 // XXX - OR cirrus_vesa_05h
1245}
1246
1247static void
1248handle_104f06(struct bregs *regs)
1249{
1250 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1251 // XXX - OR cirrus_vesa_06h
1252}
1253
1254static void
1255handle_104f07(struct bregs *regs)
1256{
1257 // XXX - vbe_biosfn_set_get_display_start
1258 // XXX - OR cirrus_vesa_07h
1259}
1260
1261static void
1262handle_104f08(struct bregs *regs)
1263{
1264 // XXX - vbe_biosfn_set_get_dac_palette_format
1265}
1266
1267static void
1268handle_104f0a(struct bregs *regs)
1269{
1270 // XXX - vbe_biosfn_return_protected_mode_interface
1271}
1272
1273static void
1274handle_104fXX(struct bregs *regs)
1275{
1276 debug_stub(regs);
1277 regs->ax = 0x0100;
1278}
1279
1280static void
1281handle_104f(struct bregs *regs)
1282{
Julian Pidancet677631f2011-12-19 05:07:53 +00001283 if (! CONFIG_VGA_BOCHS || !bochs_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001284 handle_104fXX(regs);
1285 return;
1286 }
1287
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001288 switch (regs->al) {
1289 case 0x00: handle_104f00(regs); break;
1290 case 0x01: handle_104f01(regs); break;
1291 case 0x02: handle_104f02(regs); break;
1292 case 0x03: handle_104f03(regs); break;
1293 case 0x04: handle_104f04(regs); break;
1294 case 0x05: handle_104f05(regs); break;
1295 case 0x06: handle_104f06(regs); break;
1296 case 0x07: handle_104f07(regs); break;
1297 case 0x08: handle_104f08(regs); break;
1298 case 0x0a: handle_104f0a(regs); break;
1299 default: handle_104fXX(regs); break;
1300 }
1301}
1302
1303
1304static void
1305handle_10XX(struct bregs *regs)
1306{
1307 debug_stub(regs);
1308}
1309
1310// INT 10h Video Support Service Entry Point
1311void VISIBLE16
1312handle_10(struct bregs *regs)
1313{
1314 debug_enter(regs, DEBUG_VGA_10);
1315 switch (regs->ah) {
1316 case 0x00: handle_1000(regs); break;
1317 case 0x01: handle_1001(regs); break;
1318 case 0x02: handle_1002(regs); break;
1319 case 0x03: handle_1003(regs); break;
1320 case 0x04: handle_1004(regs); break;
1321 case 0x05: handle_1005(regs); break;
1322 case 0x06: handle_1006(regs); break;
1323 case 0x07: handle_1007(regs); break;
1324 case 0x08: handle_1008(regs); break;
1325 case 0x09: handle_1009(regs); break;
1326 case 0x0a: handle_100a(regs); break;
1327 case 0x0b: handle_100b(regs); break;
1328 case 0x0c: handle_100c(regs); break;
1329 case 0x0d: handle_100d(regs); break;
1330 case 0x0e: handle_100e(regs); break;
1331 case 0x0f: handle_100f(regs); break;
1332 case 0x10: handle_1010(regs); break;
1333 case 0x11: handle_1011(regs); break;
1334 case 0x12: handle_1012(regs); break;
1335 case 0x13: handle_1013(regs); break;
1336 case 0x1a: handle_101a(regs); break;
1337 case 0x1b: handle_101b(regs); break;
1338 case 0x1c: handle_101c(regs); break;
1339 case 0x4f: handle_104f(regs); break;
1340 default: handle_10XX(regs); break;
1341 }
1342}
1343
1344
1345/****************************************************************
1346 * VGA post
1347 ****************************************************************/
1348
1349static void
Kevin O'Connor1ca05b02010-01-03 17:43:37 -05001350init_bios_area(void)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001351{
1352 // init detected hardware BIOS Area
1353 // set 80x25 color (not clear from RBIL but usual)
1354 u16 eqf = GET_BDA(equipment_list_flags);
1355 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1356
1357 // Just for the first int10 find its children
1358
1359 // the default char height
1360 SET_BDA(char_height, 0x10);
1361
1362 // Clear the screen
1363 SET_BDA(video_ctl, 0x60);
1364
1365 // Set the basic screen we have
1366 SET_BDA(video_switches, 0xf9);
1367
1368 // Set the basic modeset options
1369 SET_BDA(modeset_ctl, 0x51);
1370
1371 // Set the default MSR
1372 SET_BDA(video_msr, 0x09);
1373}
1374
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001375void VISIBLE16
1376vga_post(struct bregs *regs)
1377{
1378 debug_enter(regs, DEBUG_VGA_POST);
1379
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001380 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001381
1382 init_bios_area();
1383
Julian Pidancet677631f2011-12-19 05:07:53 +00001384 if (CONFIG_VGA_BOCHS)
1385 bochs_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001386
1387 extern void entry_10(void);
Kevin O'Connor9f985422009-09-09 11:34:39 -04001388 SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001389
Julian Pidancet677631f2011-12-19 05:07:53 +00001390 if (CONFIG_VGA_CIRRUS)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001391 cirrus_init();
1392
1393 // XXX - clear screen and display info
1394
1395 // XXX: fill it
1396 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001397 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001398
1399 // Fixup checksum
1400 extern u8 _rom_header_size, _rom_header_checksum;
1401 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001402 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001403 SET_VGA(_rom_header_checksum, sum);
1404}