blob: 7d40c8bde2c2c7734abf8b9b6f0eb48e28e103bd [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// * refactor redundant code into sub-functions
12// * See if there is a method to the in/out stuff that can be encapsulated.
13// * remove "biosfn" prefixes
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040014// * verify all funcs static
15//
Kevin O'Connor6ace78f2009-05-14 19:24:49 -040016// * convert vbe/clext code
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040017
18#include "bregs.h" // struct bregs
19#include "biosvar.h" // GET_BDA
20#include "util.h" // memset
Kevin O'Connorc0c7df62009-05-17 18:11:33 -040021#include "vgatables.h" // find_vga_entry
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040022
23// XXX
24#define CONFIG_VBE 0
25#define CONFIG_CIRRUS 0
26
27// XXX
28#define DEBUG_VGA_POST 1
29#define DEBUG_VGA_10 3
30
Kevin O'Connord113a992009-05-16 21:05:02 -040031#define SET_VGA(var, val) SET_FARVAR(get_global_seg(), (var), (val))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040032
Kevin O'Connor217f2bc2009-05-31 00:46:47 -040033static inline void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040034call16_vgaint(u32 eax, u32 ebx)
35{
36 asm volatile(
37 "int $0x10\n"
38 "cli\n"
39 "cld"
40 :
41 : "a"(eax), "b"(ebx)
42 : "cc", "memory");
43}
44
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040045static void
46biosfn_perform_gray_scale_summing(u16 start, u16 count)
47{
Kevin O'Connora0ecb052009-05-18 23:34:00 -040048 vgahw_screen_disable();
Kevin O'Connordd2be772009-05-16 15:41:23 -040049 int i;
50 for (i = start; i < start+count; i++) {
Kevin O'Connora0ecb052009-05-18 23:34:00 -040051 u8 rgb[3];
52 vgahw_get_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040053
54 // intensity = ( 0.3 * Red ) + ( 0.59 * Green ) + ( 0.11 * Blue )
Kevin O'Connora0ecb052009-05-18 23:34:00 -040055 u16 intensity = ((77 * rgb[0] + 151 * rgb[1] + 28 * rgb[2]) + 0x80) >> 8;
Kevin O'Connordd2be772009-05-16 15:41:23 -040056 if (intensity > 0x3f)
57 intensity = 0x3f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040058
Kevin O'Connora0ecb052009-05-18 23:34:00 -040059 vgahw_set_dac_regs(GET_SEG(SS), rgb, i, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040060 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040061 vgahw_screen_enable();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040062}
63
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040064static void
65biosfn_set_cursor_shape(u8 CH, u8 CL)
66{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040067 CH &= 0x3f;
68 CL &= 0x1f;
69
Kevin O'Connordd2be772009-05-16 15:41:23 -040070 u16 curs = (CH << 8) + CL;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040071 SET_BDA(cursor_type, curs);
72
Kevin O'Connordd2be772009-05-16 15:41:23 -040073 u8 modeset_ctl = GET_BDA(modeset_ctl);
74 u16 cheight = GET_BDA(char_height);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040075 if ((modeset_ctl & 0x01) && (cheight > 8) && (CL < 8) && (CH < 0x20)) {
Kevin O'Connordd2be772009-05-16 15:41:23 -040076 if (CL != (CH + 1))
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040077 CH = ((CH + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040078 else
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040079 CH = ((CL + 1) * cheight / 8) - 2;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040080 CL = ((CL + 1) * cheight / 8) - 1;
81 }
Kevin O'Connora0ecb052009-05-18 23:34:00 -040082 vgahw_set_cursor_shape(CH, CL);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040083}
84
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040085static u16
86biosfn_get_cursor_shape(u8 page)
87{
88 if (page > 7)
89 return 0;
90 // FIXME should handle VGA 14/16 lines
91 return GET_BDA(cursor_type);
92}
93
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040094static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040095set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040096{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040097 // Should not happen...
Kevin O'Connor918b1562009-05-25 11:05:18 -040098 if (cp.page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040099 return;
100
101 // Bios cursor pos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400102 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400103
104 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -0400105 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400106 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400107 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400108
Kevin O'Connordd2be772009-05-16 15:41:23 -0400109 // Get the dimensions
110 u16 nbcols = GET_BDA(video_cols);
111 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400112
Kevin O'Connordd2be772009-05-16 15:41:23 -0400113 // Calculate the address knowing nbcols nbrows and page num
Kevin O'Connor918b1562009-05-25 11:05:18 -0400114 u16 address = (SCREEN_IO_START(nbcols, nbrows, cp.page)
115 + cp.x + cp.y * nbcols);
Kevin O'Connordd2be772009-05-16 15:41:23 -0400116
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400117 vgahw_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400118}
119
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400120static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400121get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400122{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400123 if (page == 0xff)
124 // special case - use current page
125 page = GET_BDA(video_page);
126 if (page > 7) {
127 struct cursorpos cp = { 0, 0, 0xfe };
128 return cp;
129 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400130 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400131 u16 xy = GET_BDA(cursor_pos[page]);
132 struct cursorpos cp = {xy, xy>>8, page};
133 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400134}
135
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400136static void
137biosfn_set_active_page(u8 page)
138{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400139 if (page > 7)
140 return;
141
142 // Get the mode
Kevin O'Connor5727c292009-05-16 17:29:32 -0400143 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
144 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400145 return;
146
147 // Get pos curs pos for the right page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400148 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400149
Kevin O'Connordd2be772009-05-16 15:41:23 -0400150 u16 address;
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400151 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400152 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400153 u16 nbcols = GET_BDA(video_cols);
154 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400155
156 // Calculate the address knowing nbcols nbrows and page num
157 address = SCREEN_MEM_START(nbcols, nbrows, page);
158 SET_BDA(video_pagestart, address);
159
160 // Start address
161 address = SCREEN_IO_START(nbcols, nbrows, page);
162 } else {
Kevin O'Connor5727c292009-05-16 17:29:32 -0400163 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
164 address = page * GET_GLOBAL(vparam_g->slength);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400165 }
166
Kevin O'Connora0ecb052009-05-18 23:34:00 -0400167 vgahw_set_active_page(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400168
169 // And change the BIOS page
170 SET_BDA(video_page, page);
171
Kevin O'Connora12c2152009-05-13 22:06:16 -0400172 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400173
174 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400175 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400176}
177
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400178// Scroll the screen one line. This function is designed to be called
179// tail-recursive to reduce stack usage.
180static void noinline
181scroll_one(u16 nbrows, u16 nbcols, u8 page)
Kevin O'Connor09262412009-05-25 11:44:11 -0400182{
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400183 struct cursorpos ul = {0, 0, page};
184 struct cursorpos lr = {nbcols-1, nbrows-1, page};
185 vgafb_scroll(1, -1, ul, lr);
186}
187
188// Write a character to the screen at a given position. Implement
189// special characters and scroll the screen if necessary.
190static void
191write_teletype(struct cursorpos *pcp, struct carattr ca)
192{
193 struct cursorpos cp = *pcp;
194
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400195 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400196 u16 nbrows = GET_BDA(video_rows) + 1;
197 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400198
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400199 switch (ca.car) {
200 case 7:
201 //FIXME should beep
202 break;
203 case 8:
204 if (cp.x > 0)
205 cp.x--;
206 break;
207 case '\r':
208 cp.x = 0;
209 break;
210 case '\n':
211 cp.y++;
212 break;
213 case '\t':
214 do {
215 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
216 vgafb_write_char(cp, dummyca);
217 cp.x++;
218 } while (cp.x < nbcols && cp.x % 8);
219 break;
220 default:
221 vgafb_write_char(cp, ca);
222 cp.x++;
223 }
224
Kevin O'Connor82221b22009-05-26 00:20:40 -0400225 // Do we need to wrap ?
226 if (cp.x == nbcols) {
227 cp.x = 0;
228 cp.y++;
229 }
230 // Do we need to scroll ?
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400231 if (cp.y < nbrows) {
232 *pcp = cp;
233 return;
Kevin O'Connor82221b22009-05-26 00:20:40 -0400234 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400235 // Scroll screen
236 cp.y--;
237 *pcp = cp;
238 scroll_one(nbrows, nbcols, cp.page);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400239}
240
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400241// Write out a buffer of alternating characters and attributes.
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400242static void
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400243write_attr_string(struct cursorpos *pcp, u16 count, u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400244{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400245 while (count--) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400246 u8 car = GET_FARVAR(seg, *offset_far);
247 offset_far++;
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400248 u8 attr = GET_FARVAR(seg, *offset_far);
249 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400250
Kevin O'Connor09262412009-05-25 11:44:11 -0400251 struct carattr ca = {car, attr, 1};
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400252 write_teletype(pcp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400253 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400254}
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400255
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400256// Write out a buffer of characters.
257static void
258write_string(struct cursorpos *pcp, u8 attr, u16 count, u16 seg, u8 *offset_far)
259{
260 while (count--) {
261 u8 car = GET_FARVAR(seg, *offset_far);
262 offset_far++;
263
264 struct carattr ca = {car, attr, 1};
265 write_teletype(pcp, ca);
266 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400267}
268
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400269static void
Kevin O'Connore7132042009-05-25 00:10:35 -0400270set_scan_lines(u8 lines)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400271{
Kevin O'Connore7132042009-05-25 00:10:35 -0400272 vgahw_set_scan_lines(lines);
273 if (lines == 8)
274 biosfn_set_cursor_shape(0x06, 0x07);
275 else
276 biosfn_set_cursor_shape(lines - 4, lines - 3);
277 SET_BDA(char_height, lines);
278 u16 vde = vgahw_get_vde();
279 u8 rows = vde / lines;
280 SET_BDA(video_rows, rows - 1);
281 u16 cols = GET_BDA(video_cols);
282 SET_BDA(video_pagesize, rows * cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400283}
284
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400285static void
Kevin O'Connorca668642009-05-21 23:06:08 -0400286biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400287{
Kevin O'Connorca668642009-05-21 23:06:08 -0400288 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
289 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
290 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
291 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
292 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
293 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
294 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
295 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
296 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
297 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
298 u16 i;
299 for (i=0; i<8; i++)
300 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
301 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
302 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
303 /* current font */
304 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
305 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400306}
307
Kevin O'Connorca668642009-05-21 23:06:08 -0400308static void
309biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400310{
Kevin O'Connorca668642009-05-21 23:06:08 -0400311 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
312 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
313 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
314 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
315 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
316 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
317 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
318 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
319 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
320 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
321 u16 i;
322 for (i = 0; i < 8; i++)
323 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
324 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
325 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
326 /* current font */
327 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
328 , GET_FARVAR(seg, info->font0_off));
329 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
330 , GET_FARVAR(seg, info->font1_off));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400331}
332
333
334/****************************************************************
335 * VGA int 10 handler
336 ****************************************************************/
337
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400338// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400339static void
340handle_1000(struct bregs *regs)
341{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400342 u8 noclearmem = regs->al & 0x80;
343 u8 mode = regs->al & 0x7f;
344
Kevin O'Connor918b1562009-05-25 11:05:18 -0400345 // Set regs->al
346 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400347 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400348 else if (mode == 6)
349 regs->al = 0x3f;
350 else
351 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400352
353 if (CONFIG_CIRRUS)
354 cirrus_set_video_mode(mode);
355
356 if (CONFIG_VBE)
357 if (vbe_has_vbe_display())
358 dispi_set_enable(VBE_DISPI_DISABLED);
359
360 // find the entry in the video modes
361 struct vgamode_s *vmode_g = find_vga_entry(mode);
362 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
363 if (!vmode_g)
364 return;
365
366 // Read the bios mode set control
367 u8 modeset_ctl = GET_BDA(modeset_ctl);
368
369 // Then we know the number of lines
370// FIXME
371
372 // if palette loading (bit 3 of modeset ctl = 0)
373 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
374 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
375
376 // From which palette
377 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
378 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
379
380 // Always 256*3 values
381 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
382 u16 i;
383 for (i = palsize; i < 0x0100; i++) {
384 static u8 rgb[3] VAR16;
385 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
386 }
387
388 if ((modeset_ctl & 0x02) == 0x02)
389 biosfn_perform_gray_scale_summing(0x00, 0x100);
390 }
391
392 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
393 vgahw_set_mode(vparam_g);
394
395 if (noclearmem == 0x00)
396 clear_screen(vmode_g);
397
398 // Set CRTC address VGA or MDA
399 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
400 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
401 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
402
403 // Set the BIOS mem
404 u16 cheight = GET_GLOBAL(vparam_g->cheight);
405 SET_BDA(video_mode, mode);
406 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
407 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
408 SET_BDA(crtc_address, crtc_addr);
409 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
410 SET_BDA(char_height, cheight);
411 SET_BDA(video_ctl, (0x60 | noclearmem));
412 SET_BDA(video_switches, 0xF9);
413 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
414
415 // FIXME We nearly have the good tables. to be reworked
416 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
417 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
418 SET_BDA(video_savetable_seg, get_global_seg());
419
420 // FIXME
421 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
422 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
423
424 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400425 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400426 biosfn_set_cursor_shape(0x06, 0x07);
427 // Set cursor pos for page 0..7
428 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400429 for (i = 0; i < 8; i++) {
430 struct cursorpos cp = {0, 0, i};
431 set_cursor_pos(cp);
432 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400433
434 // Set active page 0
435 biosfn_set_active_page(0x00);
436
437 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400438 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400439 call16_vgaint(0x1104, 0);
440 call16_vgaint(0x1103, 0);
441 }
442 // Set the ints 0x1F and 0x43
443 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
444
445 switch (cheight) {
446 case 8:
447 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
448 break;
449 case 14:
450 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
451 break;
452 case 16:
453 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
454 break;
455 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400456}
457
458static void
459handle_1001(struct bregs *regs)
460{
461 biosfn_set_cursor_shape(regs->ch, regs->cl);
462}
463
464static void
465handle_1002(struct bregs *regs)
466{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400467 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
468 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400469}
470
471static void
472handle_1003(struct bregs *regs)
473{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400474 regs->cx = biosfn_get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400475 struct cursorpos cp = get_cursor_pos(regs->bh);
476 regs->dl = cp.x;
477 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400478}
479
480// Read light pen pos (unimplemented)
481static void
482handle_1004(struct bregs *regs)
483{
484 debug_stub(regs);
485 regs->ax = regs->bx = regs->cx = regs->dx = 0;
486}
487
488static void
489handle_1005(struct bregs *regs)
490{
491 biosfn_set_active_page(regs->al);
492}
493
494static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400495verify_scroll(struct bregs *regs, int dir)
496{
497 u8 page = GET_BDA(video_page);
498 struct cursorpos ul = {regs->cl, regs->ch, page};
499 struct cursorpos lr = {regs->dl, regs->dh, page};
500
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400501 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400502 if (lr.y >= nbrows)
503 lr.y = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400504 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400505 if (lr.x >= nbcols)
506 lr.x = nbcols - 1;
507
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400508 if (ul.x > lr.x || ul.y > lr.y)
509 return;
510
511 u16 nblines = regs->al;
512 if (!nblines || nblines > lr.y - ul.y + 1)
513 nblines = lr.y - ul.y + 1;
514
515 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400516}
517
518static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400519handle_1006(struct bregs *regs)
520{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400521 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400522}
523
524static void
525handle_1007(struct bregs *regs)
526{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400527 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400528}
529
530static void
531handle_1008(struct bregs *regs)
532{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400533 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400534 regs->al = ca.car;
535 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400536}
537
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400538static void noinline
Kevin O'Connord3b38152009-05-26 00:05:37 -0400539write_chars(u8 page, struct carattr ca, u16 count)
540{
541 struct cursorpos cp = get_cursor_pos(page);
542 while (count--) {
543 vgafb_write_char(cp, ca);
544 cp.x++;
545 }
546}
547
548static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400549handle_1009(struct bregs *regs)
550{
Kevin O'Connor09262412009-05-25 11:44:11 -0400551 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400552 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400553}
554
555static void
556handle_100a(struct bregs *regs)
557{
Kevin O'Connor09262412009-05-25 11:44:11 -0400558 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400559 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400560}
561
562
563static void
564handle_100b00(struct bregs *regs)
565{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400566 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400567}
568
569static void
570handle_100b01(struct bregs *regs)
571{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400572 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400573}
574
575static void
576handle_100bXX(struct bregs *regs)
577{
578 debug_stub(regs);
579}
580
581static void
582handle_100b(struct bregs *regs)
583{
584 switch (regs->bh) {
585 case 0x00: handle_100b00(regs); break;
586 case 0x01: handle_100b01(regs); break;
587 default: handle_100bXX(regs); break;
588 }
589}
590
591
592static void
593handle_100c(struct bregs *regs)
594{
595 // XXX - inline
596 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
597}
598
599static void
600handle_100d(struct bregs *regs)
601{
602 // XXX - inline
603 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
604}
605
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400606static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400607handle_100e(struct bregs *regs)
608{
609 // Ralf Brown Interrupt list is WRONG on bh(page)
610 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400611 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400612 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400613 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400614 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400615}
616
617static void
618handle_100f(struct bregs *regs)
619{
Kevin O'Connore7132042009-05-25 00:10:35 -0400620 regs->bh = GET_BDA(video_page);
621 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
622 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400623}
624
625
626static void
627handle_101000(struct bregs *regs)
628{
629 if (regs->bl > 0x14)
630 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400631 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400632}
633
634static void
635handle_101001(struct bregs *regs)
636{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400637 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400638}
639
640static void
641handle_101002(struct bregs *regs)
642{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400643 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400644}
645
646static void
647handle_101003(struct bregs *regs)
648{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400649 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400650}
651
652static void
653handle_101007(struct bregs *regs)
654{
655 if (regs->bl > 0x14)
656 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400657 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400658}
659
660static void
661handle_101008(struct bregs *regs)
662{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400663 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400664}
665
666static void
667handle_101009(struct bregs *regs)
668{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400669 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400670}
671
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400672static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400673handle_101010(struct bregs *regs)
674{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400675 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
676 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400677}
678
679static void
680handle_101012(struct bregs *regs)
681{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400682 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400683}
684
685static void
686handle_101013(struct bregs *regs)
687{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400688 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400689}
690
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400691static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400692handle_101015(struct bregs *regs)
693{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400694 u8 rgb[3];
695 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
696 regs->dh = rgb[0];
697 regs->ch = rgb[1];
698 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400699}
700
701static void
702handle_101017(struct bregs *regs)
703{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400704 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400705}
706
707static void
708handle_101018(struct bregs *regs)
709{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400710 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400711}
712
713static void
714handle_101019(struct bregs *regs)
715{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400716 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400717}
718
719static void
720handle_10101a(struct bregs *regs)
721{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400722 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400723}
724
725static void
726handle_10101b(struct bregs *regs)
727{
728 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
729}
730
731static void
732handle_1010XX(struct bregs *regs)
733{
734 debug_stub(regs);
735}
736
737static void
738handle_1010(struct bregs *regs)
739{
740 switch (regs->al) {
741 case 0x00: handle_101000(regs); break;
742 case 0x01: handle_101001(regs); break;
743 case 0x02: handle_101002(regs); break;
744 case 0x03: handle_101003(regs); break;
745 case 0x07: handle_101007(regs); break;
746 case 0x08: handle_101008(regs); break;
747 case 0x09: handle_101009(regs); break;
748 case 0x10: handle_101010(regs); break;
749 case 0x12: handle_101012(regs); break;
750 case 0x13: handle_101013(regs); break;
751 case 0x15: handle_101015(regs); break;
752 case 0x17: handle_101017(regs); break;
753 case 0x18: handle_101018(regs); break;
754 case 0x19: handle_101019(regs); break;
755 case 0x1a: handle_10101a(regs); break;
756 case 0x1b: handle_10101b(regs); break;
757 default: handle_1010XX(regs); break;
758 }
759}
760
761
762static void
763handle_101100(struct bregs *regs)
764{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400765 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
766 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400767}
768
769static void
770handle_101101(struct bregs *regs)
771{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400772 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400773}
774
775static void
776handle_101102(struct bregs *regs)
777{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400778 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400779}
780
781static void
782handle_101103(struct bregs *regs)
783{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400784 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400785}
786
787static void
788handle_101104(struct bregs *regs)
789{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400790 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400791}
792
793static void
794handle_101110(struct bregs *regs)
795{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400796 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
797 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400798 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400799}
800
801static void
802handle_101111(struct bregs *regs)
803{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400804 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400805 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400806}
807
808static void
809handle_101112(struct bregs *regs)
810{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400811 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400812 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400813}
814
815static void
816handle_101114(struct bregs *regs)
817{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400818 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400819 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400820}
821
822static void
823handle_101130(struct bregs *regs)
824{
Kevin O'Connore7132042009-05-25 00:10:35 -0400825 switch (regs->bh) {
826 case 0x00: {
827 u32 segoff = GET_IVT(0x1f).segoff;
828 regs->es = segoff >> 16;
829 regs->bp = segoff;
830 break;
831 }
832 case 0x01: {
833 u32 segoff = GET_IVT(0x43).segoff;
834 regs->es = segoff >> 16;
835 regs->bp = segoff;
836 break;
837 }
838 case 0x02:
839 regs->es = get_global_seg();
840 regs->bp = (u32)vgafont14;
841 break;
842 case 0x03:
843 regs->es = get_global_seg();
844 regs->bp = (u32)vgafont8;
845 break;
846 case 0x04:
847 regs->es = get_global_seg();
848 regs->bp = (u32)vgafont8 + 128 * 8;
849 break;
850 case 0x05:
851 regs->es = get_global_seg();
852 regs->bp = (u32)vgafont14alt;
853 break;
854 case 0x06:
855 regs->es = get_global_seg();
856 regs->bp = (u32)vgafont16;
857 break;
858 case 0x07:
859 regs->es = get_global_seg();
860 regs->bp = (u32)vgafont16alt;
861 break;
862 default:
863 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
864 return;
865 }
866 // Set byte/char of on screen font
867 regs->cx = GET_BDA(char_height) & 0xff;
868
869 // Set Highest char row
870 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400871}
872
873static void
874handle_1011XX(struct bregs *regs)
875{
876 debug_stub(regs);
877}
878
879static void
880handle_1011(struct bregs *regs)
881{
882 switch (regs->al) {
883 case 0x00: handle_101100(regs); break;
884 case 0x01: handle_101101(regs); break;
885 case 0x02: handle_101102(regs); break;
886 case 0x03: handle_101103(regs); break;
887 case 0x04: handle_101104(regs); break;
888 case 0x10: handle_101110(regs); break;
889 case 0x11: handle_101111(regs); break;
890 case 0x12: handle_101112(regs); break;
891 case 0x14: handle_101114(regs); break;
892 case 0x30: handle_101130(regs); break;
893 default: handle_1011XX(regs); break;
894 }
895}
896
897
898static void
899handle_101210(struct bregs *regs)
900{
Kevin O'Connore7132042009-05-25 00:10:35 -0400901 u16 crtc_addr = GET_BDA(crtc_address);
902 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
903 regs->bx = 0x0103;
904 else
905 regs->bx = 0x0003;
906 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400907}
908
909static void
910handle_101230(struct bregs *regs)
911{
Kevin O'Connore7132042009-05-25 00:10:35 -0400912 u8 mctl = GET_BDA(modeset_ctl);
913 u8 vswt = GET_BDA(video_switches);
914 switch (regs->al) {
915 case 0x00:
916 // 200 lines
917 mctl = (mctl & ~0x10) | 0x80;
918 vswt = (vswt & ~0x0f) | 0x08;
919 break;
920 case 0x01:
921 // 350 lines
922 mctl &= ~0x90;
923 vswt = (vswt & ~0x0f) | 0x09;
924 break;
925 case 0x02:
926 // 400 lines
927 mctl = (mctl & ~0x80) | 0x10;
928 vswt = (vswt & ~0x0f) | 0x09;
929 break;
930 default:
931 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
932 break;
933 }
934 SET_BDA(modeset_ctl, mctl);
935 SET_BDA(video_switches, vswt);
936 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400937}
938
939static void
940handle_101231(struct bregs *regs)
941{
Kevin O'Connore7132042009-05-25 00:10:35 -0400942 u8 v = (regs->al & 0x01) << 3;
943 u8 mctl = GET_BDA(video_ctl) & ~0x08;
944 SET_BDA(video_ctl, mctl | v);
945 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400946}
947
948static void
949handle_101232(struct bregs *regs)
950{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400951 vgahw_enable_video_addressing(regs->al);
952 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400953}
954
955static void
956handle_101233(struct bregs *regs)
957{
Kevin O'Connore7132042009-05-25 00:10:35 -0400958 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
959 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
960 SET_BDA(modeset_ctl, v | v2);
961 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400962}
963
964static void
965handle_101234(struct bregs *regs)
966{
Kevin O'Connore7132042009-05-25 00:10:35 -0400967 u8 v = (regs->al & 0x01) ^ 0x01;
968 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
969 SET_BDA(modeset_ctl, v | v2);
970 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400971}
972
973static void
974handle_101235(struct bregs *regs)
975{
976 debug_stub(regs);
977 regs->al = 0x12;
978}
979
980static void
981handle_101236(struct bregs *regs)
982{
983 debug_stub(regs);
984 regs->al = 0x12;
985}
986
987static void
988handle_1012XX(struct bregs *regs)
989{
990 debug_stub(regs);
991}
992
993static void
994handle_1012(struct bregs *regs)
995{
996 switch (regs->bl) {
997 case 0x10: handle_101210(regs); break;
998 case 0x30: handle_101230(regs); break;
999 case 0x31: handle_101231(regs); break;
1000 case 0x32: handle_101232(regs); break;
1001 case 0x33: handle_101233(regs); break;
1002 case 0x34: handle_101234(regs); break;
1003 case 0x35: handle_101235(regs); break;
1004 case 0x36: handle_101236(regs); break;
1005 default: handle_1012XX(regs); break;
1006 }
1007
1008 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
1009}
1010
1011
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001012// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -04001013static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001014handle_1013(struct bregs *regs)
1015{
Kevin O'Connor918b1562009-05-25 11:05:18 -04001016 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -04001017 // if row=0xff special case : use current cursor position
1018 if (cp.y == 0xff)
1019 cp = get_cursor_pos(cp.page);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001020 u8 flag = regs->al;
1021 if (flag & 2)
1022 write_attr_string(&cp, regs->cx, regs->es, (void*)(regs->bp + 0));
1023 else
1024 write_string(&cp, regs->bl, regs->cx, regs->es, (void*)(regs->bp + 0));
1025
1026 if (flag & 1)
1027 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001028}
1029
1030
1031static void
1032handle_101a00(struct bregs *regs)
1033{
Kevin O'Connore7132042009-05-25 00:10:35 -04001034 regs->bx = GET_BDA(dcc_index);
1035 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001036}
1037
1038static void
1039handle_101a01(struct bregs *regs)
1040{
Kevin O'Connore7132042009-05-25 00:10:35 -04001041 SET_BDA(dcc_index, regs->bl);
1042 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1043 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001044}
1045
1046static void
1047handle_101aXX(struct bregs *regs)
1048{
1049 debug_stub(regs);
1050}
1051
1052static void
1053handle_101a(struct bregs *regs)
1054{
1055 switch (regs->al) {
1056 case 0x00: handle_101a00(regs); break;
1057 case 0x01: handle_101a01(regs); break;
1058 default: handle_101aXX(regs); break;
1059 }
1060}
1061
1062
Kevin O'Connorca668642009-05-21 23:06:08 -04001063struct funcInfo {
1064 u16 static_functionality_off;
1065 u16 static_functionality_seg;
1066 u8 bda_0x49[30];
1067 u8 bda_0x84[3];
1068 u8 dcc_index;
1069 u8 dcc_alt;
1070 u16 colors;
1071 u8 pages;
1072 u8 scan_lines;
1073 u8 primary_char;
1074 u8 secondar_char;
1075 u8 misc;
1076 u8 non_vga_mode;
1077 u8 reserved_2f[2];
1078 u8 video_mem;
1079 u8 save_flags;
1080 u8 disp_info;
1081 u8 reserved_34[12];
1082};
1083
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001084static void
1085handle_101b(struct bregs *regs)
1086{
Kevin O'Connorca668642009-05-21 23:06:08 -04001087 u16 seg = regs->es;
1088 struct funcInfo *info = (void*)(regs->di+0);
1089 memset_far(seg, info, 0, sizeof(*info));
1090 // Address of static functionality table
1091 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1092 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1093
1094 // Hard coded copy from BIOS area. Should it be cleaner ?
1095 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1096 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1097
1098 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1099 SET_FARVAR(seg, info->colors, 16);
1100 SET_FARVAR(seg, info->pages, 8);
1101 SET_FARVAR(seg, info->scan_lines, 2);
1102 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001103 regs->al = 0x1B;
1104}
1105
1106
1107static void
1108handle_101c00(struct bregs *regs)
1109{
Kevin O'Connorca668642009-05-21 23:06:08 -04001110 u16 flags = regs->cx;
1111 u16 size = 0;
1112 if (flags & 1)
1113 size += sizeof(struct saveVideoHardware);
1114 if (flags & 2)
1115 size += sizeof(struct saveBDAstate);
1116 if (flags & 4)
1117 size += sizeof(struct saveDACcolors);
1118 regs->bx = size;
1119 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001120}
1121
1122static void
1123handle_101c01(struct bregs *regs)
1124{
Kevin O'Connorca668642009-05-21 23:06:08 -04001125 u16 flags = regs->cx;
1126 u16 seg = regs->es;
1127 void *data = (void*)(regs->bx+0);
1128 if (flags & 1) {
1129 vgahw_save_state(seg, data);
1130 data += sizeof(struct saveVideoHardware);
1131 }
1132 if (flags & 2) {
1133 biosfn_save_bda_state(seg, data);
1134 data += sizeof(struct saveBDAstate);
1135 }
1136 if (flags & 4)
1137 vgahw_save_dac_state(seg, data);
1138 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001139}
1140
1141static void
1142handle_101c02(struct bregs *regs)
1143{
Kevin O'Connorca668642009-05-21 23:06:08 -04001144 u16 flags = regs->cx;
1145 u16 seg = regs->es;
1146 void *data = (void*)(regs->bx+0);
1147 if (flags & 1) {
1148 vgahw_restore_state(seg, data);
1149 data += sizeof(struct saveVideoHardware);
1150 }
1151 if (flags & 2) {
1152 biosfn_restore_bda_state(seg, data);
1153 data += sizeof(struct saveBDAstate);
1154 }
1155 if (flags & 4)
1156 vgahw_restore_dac_state(seg, data);
1157 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001158}
1159
1160static void
1161handle_101cXX(struct bregs *regs)
1162{
1163 debug_stub(regs);
1164}
1165
1166static void
1167handle_101c(struct bregs *regs)
1168{
1169 switch (regs->al) {
1170 case 0x00: handle_101c00(regs); break;
1171 case 0x01: handle_101c01(regs); break;
1172 case 0x02: handle_101c02(regs); break;
1173 default: handle_101cXX(regs); break;
1174 }
1175}
1176
1177
1178static void
1179handle_104f00(struct bregs *regs)
1180{
1181 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1182 // XXX - OR cirrus_vesa_00h
1183}
1184
1185static void
1186handle_104f01(struct bregs *regs)
1187{
1188 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1189 // XXX - OR cirrus_vesa_01h
1190}
1191
1192static void
1193handle_104f02(struct bregs *regs)
1194{
1195 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1196 // XXX - OR cirrus_vesa_02h
1197}
1198
1199static void
1200handle_104f03(struct bregs *regs)
1201{
1202 // XXX - vbe_biosfn_return_current_mode
1203 // XXX - OR cirrus_vesa_03h
1204}
1205
1206static void
1207handle_104f04(struct bregs *regs)
1208{
1209 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1210}
1211
1212static void
1213handle_104f05(struct bregs *regs)
1214{
1215 // XXX - vbe_biosfn_display_window_control
1216 // XXX - OR cirrus_vesa_05h
1217}
1218
1219static void
1220handle_104f06(struct bregs *regs)
1221{
1222 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1223 // XXX - OR cirrus_vesa_06h
1224}
1225
1226static void
1227handle_104f07(struct bregs *regs)
1228{
1229 // XXX - vbe_biosfn_set_get_display_start
1230 // XXX - OR cirrus_vesa_07h
1231}
1232
1233static void
1234handle_104f08(struct bregs *regs)
1235{
1236 // XXX - vbe_biosfn_set_get_dac_palette_format
1237}
1238
1239static void
1240handle_104f0a(struct bregs *regs)
1241{
1242 // XXX - vbe_biosfn_return_protected_mode_interface
1243}
1244
1245static void
1246handle_104fXX(struct bregs *regs)
1247{
1248 debug_stub(regs);
1249 regs->ax = 0x0100;
1250}
1251
1252static void
1253handle_104f(struct bregs *regs)
1254{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001255 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001256 handle_104fXX(regs);
1257 return;
1258 }
1259
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001260 switch (regs->al) {
1261 case 0x00: handle_104f00(regs); break;
1262 case 0x01: handle_104f01(regs); break;
1263 case 0x02: handle_104f02(regs); break;
1264 case 0x03: handle_104f03(regs); break;
1265 case 0x04: handle_104f04(regs); break;
1266 case 0x05: handle_104f05(regs); break;
1267 case 0x06: handle_104f06(regs); break;
1268 case 0x07: handle_104f07(regs); break;
1269 case 0x08: handle_104f08(regs); break;
1270 case 0x0a: handle_104f0a(regs); break;
1271 default: handle_104fXX(regs); break;
1272 }
1273}
1274
1275
1276static void
1277handle_10XX(struct bregs *regs)
1278{
1279 debug_stub(regs);
1280}
1281
1282// INT 10h Video Support Service Entry Point
1283void VISIBLE16
1284handle_10(struct bregs *regs)
1285{
1286 debug_enter(regs, DEBUG_VGA_10);
1287 switch (regs->ah) {
1288 case 0x00: handle_1000(regs); break;
1289 case 0x01: handle_1001(regs); break;
1290 case 0x02: handle_1002(regs); break;
1291 case 0x03: handle_1003(regs); break;
1292 case 0x04: handle_1004(regs); break;
1293 case 0x05: handle_1005(regs); break;
1294 case 0x06: handle_1006(regs); break;
1295 case 0x07: handle_1007(regs); break;
1296 case 0x08: handle_1008(regs); break;
1297 case 0x09: handle_1009(regs); break;
1298 case 0x0a: handle_100a(regs); break;
1299 case 0x0b: handle_100b(regs); break;
1300 case 0x0c: handle_100c(regs); break;
1301 case 0x0d: handle_100d(regs); break;
1302 case 0x0e: handle_100e(regs); break;
1303 case 0x0f: handle_100f(regs); break;
1304 case 0x10: handle_1010(regs); break;
1305 case 0x11: handle_1011(regs); break;
1306 case 0x12: handle_1012(regs); break;
1307 case 0x13: handle_1013(regs); break;
1308 case 0x1a: handle_101a(regs); break;
1309 case 0x1b: handle_101b(regs); break;
1310 case 0x1c: handle_101c(regs); break;
1311 case 0x4f: handle_104f(regs); break;
1312 default: handle_10XX(regs); break;
1313 }
1314}
1315
1316
1317/****************************************************************
1318 * VGA post
1319 ****************************************************************/
1320
1321static void
1322init_bios_area()
1323{
1324 // init detected hardware BIOS Area
1325 // set 80x25 color (not clear from RBIL but usual)
1326 u16 eqf = GET_BDA(equipment_list_flags);
1327 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1328
1329 // Just for the first int10 find its children
1330
1331 // the default char height
1332 SET_BDA(char_height, 0x10);
1333
1334 // Clear the screen
1335 SET_BDA(video_ctl, 0x60);
1336
1337 // Set the basic screen we have
1338 SET_BDA(video_switches, 0xf9);
1339
1340 // Set the basic modeset options
1341 SET_BDA(modeset_ctl, 0x51);
1342
1343 // Set the default MSR
1344 SET_BDA(video_msr, 0x09);
1345}
1346
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001347void VISIBLE16
1348vga_post(struct bregs *regs)
1349{
1350 debug_enter(regs, DEBUG_VGA_POST);
1351
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001352 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001353
1354 init_bios_area();
1355
Kevin O'Connor21079f42009-05-16 21:30:10 -04001356 if (CONFIG_VBE)
1357 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001358
1359 extern void entry_10(void);
Kevin O'Connord113a992009-05-16 21:05:02 -04001360 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001361
1362 if (CONFIG_CIRRUS)
1363 cirrus_init();
1364
1365 // XXX - clear screen and display info
1366
1367 // XXX: fill it
1368 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001369 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001370
1371 // Fixup checksum
1372 extern u8 _rom_header_size, _rom_header_checksum;
1373 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001374 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001375 SET_VGA(_rom_header_checksum, sum);
1376}