blob: 6f954f373e0480e0542307f2b4066279c836f2cb [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'Connor1f2c3072009-05-06 23:35:59 -040033inline void
34call16_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'Connor918b1562009-05-25 11:05:18 -0400120struct cursorpos
121get_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'Connor82221b22009-05-26 00:20:40 -0400178static struct cursorpos
179check_scroll(struct cursorpos cp)
Kevin O'Connor09262412009-05-25 11:44:11 -0400180{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400181 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400182 u16 nbrows = GET_BDA(video_rows) + 1;
183 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400184
Kevin O'Connor82221b22009-05-26 00:20:40 -0400185 // Do we need to wrap ?
186 if (cp.x == nbcols) {
187 cp.x = 0;
188 cp.y++;
189 }
190 // Do we need to scroll ?
191 if (cp.y == nbrows) {
192 // Get the mode
193 struct vgamode_s *vmode_g = find_vga_entry(GET_BDA(video_mode));
194 if (!vmode_g)
195 return cp;
196
197 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
198 biosfn_scroll(0x01, 0x07, 0, 0, nbrows - 1, nbcols - 1, cp.page,
199 SCROLL_UP);
200 else
201 biosfn_scroll(0x01, 0x00, 0, 0, nbrows - 1, nbcols - 1, cp.page,
202 SCROLL_UP);
203 cp.y--;
204 }
205
206 return cp;
207}
208
209static void
210biosfn_write_teletype(u8 page, struct carattr ca)
211{
212 // Get the cursor pos for the page
213 struct cursorpos cp = get_cursor_pos(page);
214
Kevin O'Connor09262412009-05-25 11:44:11 -0400215 switch (ca.car) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400216 case 7:
217 //FIXME should beep
218 break;
219
220 case 8:
Kevin O'Connor918b1562009-05-25 11:05:18 -0400221 if (cp.x > 0)
222 cp.x--;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400223 break;
224
225 case '\r':
Kevin O'Connor918b1562009-05-25 11:05:18 -0400226 cp.x = 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400227 break;
228
229 case '\n':
Kevin O'Connor918b1562009-05-25 11:05:18 -0400230 cp.y++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400231 break;
232
233 case '\t':
234 do {
Kevin O'Connor09262412009-05-25 11:44:11 -0400235 struct carattr dummyca = {' ', ca.attr, ca.use_attr};
Kevin O'Connor82221b22009-05-26 00:20:40 -0400236 vgafb_write_char(cp, dummyca);
237 cp.x++;
238 cp = check_scroll(cp);
239 } while (cp.x % 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400240 break;
241
242 default:
Kevin O'Connord3b38152009-05-26 00:05:37 -0400243 vgafb_write_char(cp, ca);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400244 cp.x++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400245 }
246
Kevin O'Connor82221b22009-05-26 00:20:40 -0400247 cp = check_scroll(cp);
248
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400249 // Set the cursor for the page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400250 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400251}
252
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400253static void
Kevin O'Connor918b1562009-05-25 11:05:18 -0400254biosfn_write_string(struct cursorpos cp, u8 flag, u8 attr, u16 count,
Kevin O'Connordd2be772009-05-16 15:41:23 -0400255 u16 seg, u8 *offset_far)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400256{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400257 // Read curs info for the page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400258 struct cursorpos oldcp = get_cursor_pos(cp.page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400259
260 // if row=0xff special case : use current cursor position
Kevin O'Connor918b1562009-05-25 11:05:18 -0400261 if (cp.y == 0xff)
262 cp = oldcp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400263
Kevin O'Connor918b1562009-05-25 11:05:18 -0400264 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400265
266 while (count-- != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400267 u8 car = GET_FARVAR(seg, *offset_far);
268 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400269 if ((flag & 0x02) != 0) {
Kevin O'Connordd2be772009-05-16 15:41:23 -0400270 attr = GET_FARVAR(seg, *offset_far);
271 offset_far++;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400272 }
273
Kevin O'Connor09262412009-05-25 11:44:11 -0400274 struct carattr ca = {car, attr, 1};
275 biosfn_write_teletype(cp.page, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400276 }
277
278 // Set back curs pos
279 if ((flag & 0x01) == 0)
Kevin O'Connor918b1562009-05-25 11:05:18 -0400280 set_cursor_pos(oldcp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400281}
282
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400283static void
Kevin O'Connore7132042009-05-25 00:10:35 -0400284set_scan_lines(u8 lines)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400285{
Kevin O'Connore7132042009-05-25 00:10:35 -0400286 vgahw_set_scan_lines(lines);
287 if (lines == 8)
288 biosfn_set_cursor_shape(0x06, 0x07);
289 else
290 biosfn_set_cursor_shape(lines - 4, lines - 3);
291 SET_BDA(char_height, lines);
292 u16 vde = vgahw_get_vde();
293 u8 rows = vde / lines;
294 SET_BDA(video_rows, rows - 1);
295 u16 cols = GET_BDA(video_cols);
296 SET_BDA(video_pagesize, rows * cols * 2);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400297}
298
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400299static void
Kevin O'Connorca668642009-05-21 23:06:08 -0400300biosfn_save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400301{
Kevin O'Connorca668642009-05-21 23:06:08 -0400302 SET_FARVAR(seg, info->video_mode, GET_BDA(video_mode));
303 SET_FARVAR(seg, info->video_cols, GET_BDA(video_cols));
304 SET_FARVAR(seg, info->video_pagesize, GET_BDA(video_pagesize));
305 SET_FARVAR(seg, info->crtc_address, GET_BDA(crtc_address));
306 SET_FARVAR(seg, info->video_rows, GET_BDA(video_rows));
307 SET_FARVAR(seg, info->char_height, GET_BDA(char_height));
308 SET_FARVAR(seg, info->video_ctl, GET_BDA(video_ctl));
309 SET_FARVAR(seg, info->video_switches, GET_BDA(video_switches));
310 SET_FARVAR(seg, info->modeset_ctl, GET_BDA(modeset_ctl));
311 SET_FARVAR(seg, info->cursor_type, GET_BDA(cursor_type));
312 u16 i;
313 for (i=0; i<8; i++)
314 SET_FARVAR(seg, info->cursor_pos[i], GET_BDA(cursor_pos[i]));
315 SET_FARVAR(seg, info->video_pagestart, GET_BDA(video_pagestart));
316 SET_FARVAR(seg, info->video_page, GET_BDA(video_page));
317 /* current font */
318 SET_FARVAR(seg, *(u32*)&info->font0_off, GET_IVT(0x1f).segoff);
319 SET_FARVAR(seg, *(u32*)&info->font1_off, GET_IVT(0x43).segoff);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400320}
321
Kevin O'Connorca668642009-05-21 23:06:08 -0400322static void
323biosfn_restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400324{
Kevin O'Connorca668642009-05-21 23:06:08 -0400325 SET_BDA(video_mode, GET_FARVAR(seg, info->video_mode));
326 SET_BDA(video_cols, GET_FARVAR(seg, info->video_cols));
327 SET_BDA(video_pagesize, GET_FARVAR(seg, info->video_pagesize));
328 SET_BDA(crtc_address, GET_FARVAR(seg, info->crtc_address));
329 SET_BDA(video_rows, GET_FARVAR(seg, info->video_rows));
330 SET_BDA(char_height, GET_FARVAR(seg, info->char_height));
331 SET_BDA(video_ctl, GET_FARVAR(seg, info->video_ctl));
332 SET_BDA(video_switches, GET_FARVAR(seg, info->video_switches));
333 SET_BDA(modeset_ctl, GET_FARVAR(seg, info->modeset_ctl));
334 SET_BDA(cursor_type, GET_FARVAR(seg, info->cursor_type));
335 u16 i;
336 for (i = 0; i < 8; i++)
337 SET_BDA(cursor_pos[i], GET_FARVAR(seg, info->cursor_pos[i]));
338 SET_BDA(video_pagestart, GET_FARVAR(seg, info->video_pagestart));
339 SET_BDA(video_page, GET_FARVAR(seg, info->video_page));
340 /* current font */
341 SET_IVT(0x1f, GET_FARVAR(seg, info->font0_seg)
342 , GET_FARVAR(seg, info->font0_off));
343 SET_IVT(0x43, GET_FARVAR(seg, info->font1_seg)
344 , GET_FARVAR(seg, info->font1_off));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400345}
346
347
348/****************************************************************
349 * VGA int 10 handler
350 ****************************************************************/
351
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400352// set video mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400353static void
354handle_1000(struct bregs *regs)
355{
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400356 u8 noclearmem = regs->al & 0x80;
357 u8 mode = regs->al & 0x7f;
358
Kevin O'Connor918b1562009-05-25 11:05:18 -0400359 // Set regs->al
360 if (mode > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400361 regs->al = 0x20;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400362 else if (mode == 6)
363 regs->al = 0x3f;
364 else
365 regs->al = 0x30;
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400366
367 if (CONFIG_CIRRUS)
368 cirrus_set_video_mode(mode);
369
370 if (CONFIG_VBE)
371 if (vbe_has_vbe_display())
372 dispi_set_enable(VBE_DISPI_DISABLED);
373
374 // find the entry in the video modes
375 struct vgamode_s *vmode_g = find_vga_entry(mode);
376 dprintf(1, "mode search %02x found %p\n", mode, vmode_g);
377 if (!vmode_g)
378 return;
379
380 // Read the bios mode set control
381 u8 modeset_ctl = GET_BDA(modeset_ctl);
382
383 // Then we know the number of lines
384// FIXME
385
386 // if palette loading (bit 3 of modeset ctl = 0)
387 if ((modeset_ctl & 0x08) == 0) { // Set the PEL mask
388 vgahw_set_pel_mask(GET_GLOBAL(vmode_g->pelmask));
389
390 // From which palette
391 u8 *palette_g = GET_GLOBAL(vmode_g->dac);
392 u16 palsize = GET_GLOBAL(vmode_g->dacsize) / 3;
393
394 // Always 256*3 values
395 vgahw_set_dac_regs(get_global_seg(), palette_g, 0, palsize);
396 u16 i;
397 for (i = palsize; i < 0x0100; i++) {
398 static u8 rgb[3] VAR16;
399 vgahw_set_dac_regs(get_global_seg(), rgb, i, 1);
400 }
401
402 if ((modeset_ctl & 0x02) == 0x02)
403 biosfn_perform_gray_scale_summing(0x00, 0x100);
404 }
405
406 struct VideoParam_s *vparam_g = GET_GLOBAL(vmode_g->vparam);
407 vgahw_set_mode(vparam_g);
408
409 if (noclearmem == 0x00)
410 clear_screen(vmode_g);
411
412 // Set CRTC address VGA or MDA
413 u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS;
414 if (GET_GLOBAL(vmode_g->memmodel) == MTEXT)
415 crtc_addr = VGAREG_MDA_CRTC_ADDRESS;
416
417 // Set the BIOS mem
418 u16 cheight = GET_GLOBAL(vparam_g->cheight);
419 SET_BDA(video_mode, mode);
420 SET_BDA(video_cols, GET_GLOBAL(vparam_g->twidth));
421 SET_BDA(video_pagesize, GET_GLOBAL(vparam_g->slength));
422 SET_BDA(crtc_address, crtc_addr);
423 SET_BDA(video_rows, GET_GLOBAL(vparam_g->theightm1));
424 SET_BDA(char_height, cheight);
425 SET_BDA(video_ctl, (0x60 | noclearmem));
426 SET_BDA(video_switches, 0xF9);
427 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
428
429 // FIXME We nearly have the good tables. to be reworked
430 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
431 SET_BDA(video_savetable_ptr, (u32)video_save_pointer_table);
432 SET_BDA(video_savetable_seg, get_global_seg());
433
434 // FIXME
435 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
436 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
437
438 // Set cursor shape
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400439 if (GET_GLOBAL(vmode_g->memmodel) & TEXT)
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400440 biosfn_set_cursor_shape(0x06, 0x07);
441 // Set cursor pos for page 0..7
442 int i;
Kevin O'Connor918b1562009-05-25 11:05:18 -0400443 for (i = 0; i < 8; i++) {
444 struct cursorpos cp = {0, 0, i};
445 set_cursor_pos(cp);
446 }
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400447
448 // Set active page 0
449 biosfn_set_active_page(0x00);
450
451 // Write the fonts in memory
Kevin O'Connore4f220f2009-05-25 23:37:13 -0400452 if (GET_GLOBAL(vmode_g->memmodel) & TEXT) {
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400453 call16_vgaint(0x1104, 0);
454 call16_vgaint(0x1103, 0);
455 }
456 // Set the ints 0x1F and 0x43
457 SET_IVT(0x1f, get_global_seg(), (u32)&vgafont8[128 * 8]);
458
459 switch (cheight) {
460 case 8:
461 SET_IVT(0x43, get_global_seg(), (u32)vgafont8);
462 break;
463 case 14:
464 SET_IVT(0x43, get_global_seg(), (u32)vgafont14);
465 break;
466 case 16:
467 SET_IVT(0x43, get_global_seg(), (u32)vgafont16);
468 break;
469 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400470}
471
472static void
473handle_1001(struct bregs *regs)
474{
475 biosfn_set_cursor_shape(regs->ch, regs->cl);
476}
477
478static void
479handle_1002(struct bregs *regs)
480{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400481 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
482 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400483}
484
485static void
486handle_1003(struct bregs *regs)
487{
Kevin O'Connor0818e1a2009-05-16 18:00:19 -0400488 regs->cx = biosfn_get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400489 struct cursorpos cp = get_cursor_pos(regs->bh);
490 regs->dl = cp.x;
491 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400492}
493
494// Read light pen pos (unimplemented)
495static void
496handle_1004(struct bregs *regs)
497{
498 debug_stub(regs);
499 regs->ax = regs->bx = regs->cx = regs->dx = 0;
500}
501
502static void
503handle_1005(struct bregs *regs)
504{
505 biosfn_set_active_page(regs->al);
506}
507
508static void
509handle_1006(struct bregs *regs)
510{
511 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
512 , 0xFF, SCROLL_UP);
513}
514
515static void
516handle_1007(struct bregs *regs)
517{
518 biosfn_scroll(regs->al, regs->bh, regs->ch, regs->cl, regs->dh, regs->dl
519 , 0xFF, SCROLL_DOWN);
520}
521
522static void
523handle_1008(struct bregs *regs)
524{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400525 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400526 regs->al = ca.car;
527 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400528}
529
530static void
Kevin O'Connord3b38152009-05-26 00:05:37 -0400531write_chars(u8 page, struct carattr ca, u16 count)
532{
533 struct cursorpos cp = get_cursor_pos(page);
534 while (count--) {
535 vgafb_write_char(cp, ca);
536 cp.x++;
537 }
538}
539
540static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400541handle_1009(struct bregs *regs)
542{
Kevin O'Connor09262412009-05-25 11:44:11 -0400543 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400544 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400545}
546
547static void
548handle_100a(struct bregs *regs)
549{
Kevin O'Connor09262412009-05-25 11:44:11 -0400550 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400551 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400552}
553
554
555static void
556handle_100b00(struct bregs *regs)
557{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400558 vgahw_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400559}
560
561static void
562handle_100b01(struct bregs *regs)
563{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400564 vgahw_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400565}
566
567static void
568handle_100bXX(struct bregs *regs)
569{
570 debug_stub(regs);
571}
572
573static void
574handle_100b(struct bregs *regs)
575{
576 switch (regs->bh) {
577 case 0x00: handle_100b00(regs); break;
578 case 0x01: handle_100b01(regs); break;
579 default: handle_100bXX(regs); break;
580 }
581}
582
583
584static void
585handle_100c(struct bregs *regs)
586{
587 // XXX - inline
588 biosfn_write_pixel(regs->bh, regs->al, regs->cx, regs->dx);
589}
590
591static void
592handle_100d(struct bregs *regs)
593{
594 // XXX - inline
595 biosfn_read_pixel(regs->bh, regs->cx, regs->dx, &regs->ax);
596}
597
598static void
599handle_100e(struct bregs *regs)
600{
601 // Ralf Brown Interrupt list is WRONG on bh(page)
602 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400603 struct carattr ca = {regs->al, regs->bl, 0};
604 biosfn_write_teletype(0xff, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400605}
606
607static void
608handle_100f(struct bregs *regs)
609{
Kevin O'Connore7132042009-05-25 00:10:35 -0400610 regs->bh = GET_BDA(video_page);
611 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
612 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400613}
614
615
616static void
617handle_101000(struct bregs *regs)
618{
619 if (regs->bl > 0x14)
620 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400621 vgahw_set_single_palette_reg(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400622}
623
624static void
625handle_101001(struct bregs *regs)
626{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400627 vgahw_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400628}
629
630static void
631handle_101002(struct bregs *regs)
632{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400633 vgahw_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400634}
635
636static void
637handle_101003(struct bregs *regs)
638{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400639 vgahw_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400640}
641
642static void
643handle_101007(struct bregs *regs)
644{
645 if (regs->bl > 0x14)
646 return;
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400647 regs->bh = vgahw_get_single_palette_reg(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400648}
649
650static void
651handle_101008(struct bregs *regs)
652{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400653 regs->bh = vgahw_get_overscan_border_color(regs);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400654}
655
656static void
657handle_101009(struct bregs *regs)
658{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400659 vgahw_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400660}
661
662static void
663handle_101010(struct bregs *regs)
664{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400665 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
666 vgahw_set_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400667}
668
669static void
670handle_101012(struct bregs *regs)
671{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400672 vgahw_set_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400673}
674
675static void
676handle_101013(struct bregs *regs)
677{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400678 vgahw_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400679}
680
681static void
682handle_101015(struct bregs *regs)
683{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400684 u8 rgb[3];
685 vgahw_get_dac_regs(GET_SEG(SS), rgb, regs->bx, 1);
686 regs->dh = rgb[0];
687 regs->ch = rgb[1];
688 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400689}
690
691static void
692handle_101017(struct bregs *regs)
693{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400694 vgahw_get_dac_regs(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400695}
696
697static void
698handle_101018(struct bregs *regs)
699{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400700 vgahw_set_pel_mask(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400701}
702
703static void
704handle_101019(struct bregs *regs)
705{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400706 regs->bl = vgahw_get_pel_mask();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400707}
708
709static void
710handle_10101a(struct bregs *regs)
711{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400712 vgahw_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400713}
714
715static void
716handle_10101b(struct bregs *regs)
717{
718 biosfn_perform_gray_scale_summing(regs->bx, regs->cx);
719}
720
721static void
722handle_1010XX(struct bregs *regs)
723{
724 debug_stub(regs);
725}
726
727static void
728handle_1010(struct bregs *regs)
729{
730 switch (regs->al) {
731 case 0x00: handle_101000(regs); break;
732 case 0x01: handle_101001(regs); break;
733 case 0x02: handle_101002(regs); break;
734 case 0x03: handle_101003(regs); break;
735 case 0x07: handle_101007(regs); break;
736 case 0x08: handle_101008(regs); break;
737 case 0x09: handle_101009(regs); break;
738 case 0x10: handle_101010(regs); break;
739 case 0x12: handle_101012(regs); break;
740 case 0x13: handle_101013(regs); break;
741 case 0x15: handle_101015(regs); break;
742 case 0x17: handle_101017(regs); break;
743 case 0x18: handle_101018(regs); break;
744 case 0x19: handle_101019(regs); break;
745 case 0x1a: handle_10101a(regs); break;
746 case 0x1b: handle_10101b(regs); break;
747 default: handle_1010XX(regs); break;
748 }
749}
750
751
752static void
753handle_101100(struct bregs *regs)
754{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400755 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
756 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400757}
758
759static void
760handle_101101(struct bregs *regs)
761{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400762 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400763}
764
765static void
766handle_101102(struct bregs *regs)
767{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400768 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400769}
770
771static void
772handle_101103(struct bregs *regs)
773{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400774 vgahw_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400775}
776
777static void
778handle_101104(struct bregs *regs)
779{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400780 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400781}
782
783static void
784handle_101110(struct bregs *regs)
785{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400786 vgafb_load_font(regs->es, (void*)(regs->bp+0), regs->cx
787 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400788 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400789}
790
791static void
792handle_101111(struct bregs *regs)
793{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400794 vgafb_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400795 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400796}
797
798static void
799handle_101112(struct bregs *regs)
800{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400801 vgafb_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400802 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400803}
804
805static void
806handle_101114(struct bregs *regs)
807{
Kevin O'Connordeb9cb92009-05-25 09:06:50 -0400808 vgafb_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400809 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400810}
811
812static void
813handle_101130(struct bregs *regs)
814{
Kevin O'Connore7132042009-05-25 00:10:35 -0400815 switch (regs->bh) {
816 case 0x00: {
817 u32 segoff = GET_IVT(0x1f).segoff;
818 regs->es = segoff >> 16;
819 regs->bp = segoff;
820 break;
821 }
822 case 0x01: {
823 u32 segoff = GET_IVT(0x43).segoff;
824 regs->es = segoff >> 16;
825 regs->bp = segoff;
826 break;
827 }
828 case 0x02:
829 regs->es = get_global_seg();
830 regs->bp = (u32)vgafont14;
831 break;
832 case 0x03:
833 regs->es = get_global_seg();
834 regs->bp = (u32)vgafont8;
835 break;
836 case 0x04:
837 regs->es = get_global_seg();
838 regs->bp = (u32)vgafont8 + 128 * 8;
839 break;
840 case 0x05:
841 regs->es = get_global_seg();
842 regs->bp = (u32)vgafont14alt;
843 break;
844 case 0x06:
845 regs->es = get_global_seg();
846 regs->bp = (u32)vgafont16;
847 break;
848 case 0x07:
849 regs->es = get_global_seg();
850 regs->bp = (u32)vgafont16alt;
851 break;
852 default:
853 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
854 return;
855 }
856 // Set byte/char of on screen font
857 regs->cx = GET_BDA(char_height) & 0xff;
858
859 // Set Highest char row
860 regs->dx = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400861}
862
863static void
864handle_1011XX(struct bregs *regs)
865{
866 debug_stub(regs);
867}
868
869static void
870handle_1011(struct bregs *regs)
871{
872 switch (regs->al) {
873 case 0x00: handle_101100(regs); break;
874 case 0x01: handle_101101(regs); break;
875 case 0x02: handle_101102(regs); break;
876 case 0x03: handle_101103(regs); break;
877 case 0x04: handle_101104(regs); break;
878 case 0x10: handle_101110(regs); break;
879 case 0x11: handle_101111(regs); break;
880 case 0x12: handle_101112(regs); break;
881 case 0x14: handle_101114(regs); break;
882 case 0x30: handle_101130(regs); break;
883 default: handle_1011XX(regs); break;
884 }
885}
886
887
888static void
889handle_101210(struct bregs *regs)
890{
Kevin O'Connore7132042009-05-25 00:10:35 -0400891 u16 crtc_addr = GET_BDA(crtc_address);
892 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
893 regs->bx = 0x0103;
894 else
895 regs->bx = 0x0003;
896 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400897}
898
899static void
900handle_101230(struct bregs *regs)
901{
Kevin O'Connore7132042009-05-25 00:10:35 -0400902 u8 mctl = GET_BDA(modeset_ctl);
903 u8 vswt = GET_BDA(video_switches);
904 switch (regs->al) {
905 case 0x00:
906 // 200 lines
907 mctl = (mctl & ~0x10) | 0x80;
908 vswt = (vswt & ~0x0f) | 0x08;
909 break;
910 case 0x01:
911 // 350 lines
912 mctl &= ~0x90;
913 vswt = (vswt & ~0x0f) | 0x09;
914 break;
915 case 0x02:
916 // 400 lines
917 mctl = (mctl & ~0x80) | 0x10;
918 vswt = (vswt & ~0x0f) | 0x09;
919 break;
920 default:
921 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
922 break;
923 }
924 SET_BDA(modeset_ctl, mctl);
925 SET_BDA(video_switches, vswt);
926 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400927}
928
929static void
930handle_101231(struct bregs *regs)
931{
Kevin O'Connore7132042009-05-25 00:10:35 -0400932 u8 v = (regs->al & 0x01) << 3;
933 u8 mctl = GET_BDA(video_ctl) & ~0x08;
934 SET_BDA(video_ctl, mctl | v);
935 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400936}
937
938static void
939handle_101232(struct bregs *regs)
940{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400941 vgahw_enable_video_addressing(regs->al);
942 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400943}
944
945static void
946handle_101233(struct bregs *regs)
947{
Kevin O'Connore7132042009-05-25 00:10:35 -0400948 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
949 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
950 SET_BDA(modeset_ctl, v | v2);
951 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400952}
953
954static void
955handle_101234(struct bregs *regs)
956{
Kevin O'Connore7132042009-05-25 00:10:35 -0400957 u8 v = (regs->al & 0x01) ^ 0x01;
958 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
959 SET_BDA(modeset_ctl, v | v2);
960 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400961}
962
963static void
964handle_101235(struct bregs *regs)
965{
966 debug_stub(regs);
967 regs->al = 0x12;
968}
969
970static void
971handle_101236(struct bregs *regs)
972{
973 debug_stub(regs);
974 regs->al = 0x12;
975}
976
977static void
978handle_1012XX(struct bregs *regs)
979{
980 debug_stub(regs);
981}
982
983static void
984handle_1012(struct bregs *regs)
985{
986 switch (regs->bl) {
987 case 0x10: handle_101210(regs); break;
988 case 0x30: handle_101230(regs); break;
989 case 0x31: handle_101231(regs); break;
990 case 0x32: handle_101232(regs); break;
991 case 0x33: handle_101233(regs); break;
992 case 0x34: handle_101234(regs); break;
993 case 0x35: handle_101235(regs); break;
994 case 0x36: handle_101236(regs); break;
995 default: handle_1012XX(regs); break;
996 }
997
998 // XXX - cirrus has 1280, 1281, 1282, 1285, 129a, 12a0, 12a1, 12a2, 12ae
999}
1000
1001
1002static void
1003handle_1013(struct bregs *regs)
1004{
1005 // XXX - inline
Kevin O'Connor918b1562009-05-25 11:05:18 -04001006 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
1007 biosfn_write_string(cp, regs->al, regs->bl, regs->cx
1008 , regs->es, (void*)(regs->bp + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001009}
1010
1011
1012static void
1013handle_101a00(struct bregs *regs)
1014{
Kevin O'Connore7132042009-05-25 00:10:35 -04001015 regs->bx = GET_BDA(dcc_index);
1016 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001017}
1018
1019static void
1020handle_101a01(struct bregs *regs)
1021{
Kevin O'Connore7132042009-05-25 00:10:35 -04001022 SET_BDA(dcc_index, regs->bl);
1023 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1024 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001025}
1026
1027static void
1028handle_101aXX(struct bregs *regs)
1029{
1030 debug_stub(regs);
1031}
1032
1033static void
1034handle_101a(struct bregs *regs)
1035{
1036 switch (regs->al) {
1037 case 0x00: handle_101a00(regs); break;
1038 case 0x01: handle_101a01(regs); break;
1039 default: handle_101aXX(regs); break;
1040 }
1041}
1042
1043
Kevin O'Connorca668642009-05-21 23:06:08 -04001044struct funcInfo {
1045 u16 static_functionality_off;
1046 u16 static_functionality_seg;
1047 u8 bda_0x49[30];
1048 u8 bda_0x84[3];
1049 u8 dcc_index;
1050 u8 dcc_alt;
1051 u16 colors;
1052 u8 pages;
1053 u8 scan_lines;
1054 u8 primary_char;
1055 u8 secondar_char;
1056 u8 misc;
1057 u8 non_vga_mode;
1058 u8 reserved_2f[2];
1059 u8 video_mem;
1060 u8 save_flags;
1061 u8 disp_info;
1062 u8 reserved_34[12];
1063};
1064
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001065static void
1066handle_101b(struct bregs *regs)
1067{
Kevin O'Connorca668642009-05-21 23:06:08 -04001068 u16 seg = regs->es;
1069 struct funcInfo *info = (void*)(regs->di+0);
1070 memset_far(seg, info, 0, sizeof(*info));
1071 // Address of static functionality table
1072 SET_FARVAR(seg, info->static_functionality_off, (u32)static_functionality);
1073 SET_FARVAR(seg, info->static_functionality_seg, get_global_seg());
1074
1075 // Hard coded copy from BIOS area. Should it be cleaner ?
1076 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49, 30);
1077 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84, 3);
1078
1079 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1080 SET_FARVAR(seg, info->colors, 16);
1081 SET_FARVAR(seg, info->pages, 8);
1082 SET_FARVAR(seg, info->scan_lines, 2);
1083 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001084 regs->al = 0x1B;
1085}
1086
1087
1088static void
1089handle_101c00(struct bregs *regs)
1090{
Kevin O'Connorca668642009-05-21 23:06:08 -04001091 u16 flags = regs->cx;
1092 u16 size = 0;
1093 if (flags & 1)
1094 size += sizeof(struct saveVideoHardware);
1095 if (flags & 2)
1096 size += sizeof(struct saveBDAstate);
1097 if (flags & 4)
1098 size += sizeof(struct saveDACcolors);
1099 regs->bx = size;
1100 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001101}
1102
1103static void
1104handle_101c01(struct bregs *regs)
1105{
Kevin O'Connorca668642009-05-21 23:06:08 -04001106 u16 flags = regs->cx;
1107 u16 seg = regs->es;
1108 void *data = (void*)(regs->bx+0);
1109 if (flags & 1) {
1110 vgahw_save_state(seg, data);
1111 data += sizeof(struct saveVideoHardware);
1112 }
1113 if (flags & 2) {
1114 biosfn_save_bda_state(seg, data);
1115 data += sizeof(struct saveBDAstate);
1116 }
1117 if (flags & 4)
1118 vgahw_save_dac_state(seg, data);
1119 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001120}
1121
1122static void
1123handle_101c02(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_restore_state(seg, data);
1130 data += sizeof(struct saveVideoHardware);
1131 }
1132 if (flags & 2) {
1133 biosfn_restore_bda_state(seg, data);
1134 data += sizeof(struct saveBDAstate);
1135 }
1136 if (flags & 4)
1137 vgahw_restore_dac_state(seg, data);
1138 regs->al = 0x1c;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001139}
1140
1141static void
1142handle_101cXX(struct bregs *regs)
1143{
1144 debug_stub(regs);
1145}
1146
1147static void
1148handle_101c(struct bregs *regs)
1149{
1150 switch (regs->al) {
1151 case 0x00: handle_101c00(regs); break;
1152 case 0x01: handle_101c01(regs); break;
1153 case 0x02: handle_101c02(regs); break;
1154 default: handle_101cXX(regs); break;
1155 }
1156}
1157
1158
1159static void
1160handle_104f00(struct bregs *regs)
1161{
1162 // XXX - vbe_biosfn_return_controller_information(&AX,ES,DI);
1163 // XXX - OR cirrus_vesa_00h
1164}
1165
1166static void
1167handle_104f01(struct bregs *regs)
1168{
1169 // XXX - vbe_biosfn_return_mode_information(&AX,CX,ES,DI);
1170 // XXX - OR cirrus_vesa_01h
1171}
1172
1173static void
1174handle_104f02(struct bregs *regs)
1175{
1176 // XXX - vbe_biosfn_set_mode(&AX,BX,ES,DI);
1177 // XXX - OR cirrus_vesa_02h
1178}
1179
1180static void
1181handle_104f03(struct bregs *regs)
1182{
1183 // XXX - vbe_biosfn_return_current_mode
1184 // XXX - OR cirrus_vesa_03h
1185}
1186
1187static void
1188handle_104f04(struct bregs *regs)
1189{
1190 // XXX - vbe_biosfn_save_restore_state(&AX, CX, DX, ES, &BX);
1191}
1192
1193static void
1194handle_104f05(struct bregs *regs)
1195{
1196 // XXX - vbe_biosfn_display_window_control
1197 // XXX - OR cirrus_vesa_05h
1198}
1199
1200static void
1201handle_104f06(struct bregs *regs)
1202{
1203 // XXX - vbe_biosfn_set_get_logical_scan_line_length
1204 // XXX - OR cirrus_vesa_06h
1205}
1206
1207static void
1208handle_104f07(struct bregs *regs)
1209{
1210 // XXX - vbe_biosfn_set_get_display_start
1211 // XXX - OR cirrus_vesa_07h
1212}
1213
1214static void
1215handle_104f08(struct bregs *regs)
1216{
1217 // XXX - vbe_biosfn_set_get_dac_palette_format
1218}
1219
1220static void
1221handle_104f0a(struct bregs *regs)
1222{
1223 // XXX - vbe_biosfn_return_protected_mode_interface
1224}
1225
1226static void
1227handle_104fXX(struct bregs *regs)
1228{
1229 debug_stub(regs);
1230 regs->ax = 0x0100;
1231}
1232
1233static void
1234handle_104f(struct bregs *regs)
1235{
Kevin O'Connor99e08b72009-05-17 00:07:31 -04001236 if (! CONFIG_VBE || !vbe_has_vbe_display()) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001237 handle_104fXX(regs);
1238 return;
1239 }
1240
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001241 switch (regs->al) {
1242 case 0x00: handle_104f00(regs); break;
1243 case 0x01: handle_104f01(regs); break;
1244 case 0x02: handle_104f02(regs); break;
1245 case 0x03: handle_104f03(regs); break;
1246 case 0x04: handle_104f04(regs); break;
1247 case 0x05: handle_104f05(regs); break;
1248 case 0x06: handle_104f06(regs); break;
1249 case 0x07: handle_104f07(regs); break;
1250 case 0x08: handle_104f08(regs); break;
1251 case 0x0a: handle_104f0a(regs); break;
1252 default: handle_104fXX(regs); break;
1253 }
1254}
1255
1256
1257static void
1258handle_10XX(struct bregs *regs)
1259{
1260 debug_stub(regs);
1261}
1262
1263// INT 10h Video Support Service Entry Point
1264void VISIBLE16
1265handle_10(struct bregs *regs)
1266{
1267 debug_enter(regs, DEBUG_VGA_10);
1268 switch (regs->ah) {
1269 case 0x00: handle_1000(regs); break;
1270 case 0x01: handle_1001(regs); break;
1271 case 0x02: handle_1002(regs); break;
1272 case 0x03: handle_1003(regs); break;
1273 case 0x04: handle_1004(regs); break;
1274 case 0x05: handle_1005(regs); break;
1275 case 0x06: handle_1006(regs); break;
1276 case 0x07: handle_1007(regs); break;
1277 case 0x08: handle_1008(regs); break;
1278 case 0x09: handle_1009(regs); break;
1279 case 0x0a: handle_100a(regs); break;
1280 case 0x0b: handle_100b(regs); break;
1281 case 0x0c: handle_100c(regs); break;
1282 case 0x0d: handle_100d(regs); break;
1283 case 0x0e: handle_100e(regs); break;
1284 case 0x0f: handle_100f(regs); break;
1285 case 0x10: handle_1010(regs); break;
1286 case 0x11: handle_1011(regs); break;
1287 case 0x12: handle_1012(regs); break;
1288 case 0x13: handle_1013(regs); break;
1289 case 0x1a: handle_101a(regs); break;
1290 case 0x1b: handle_101b(regs); break;
1291 case 0x1c: handle_101c(regs); break;
1292 case 0x4f: handle_104f(regs); break;
1293 default: handle_10XX(regs); break;
1294 }
1295}
1296
1297
1298/****************************************************************
1299 * VGA post
1300 ****************************************************************/
1301
1302static void
1303init_bios_area()
1304{
1305 // init detected hardware BIOS Area
1306 // set 80x25 color (not clear from RBIL but usual)
1307 u16 eqf = GET_BDA(equipment_list_flags);
1308 SET_BDA(equipment_list_flags, (eqf & 0xffcf) | 0x20);
1309
1310 // Just for the first int10 find its children
1311
1312 // the default char height
1313 SET_BDA(char_height, 0x10);
1314
1315 // Clear the screen
1316 SET_BDA(video_ctl, 0x60);
1317
1318 // Set the basic screen we have
1319 SET_BDA(video_switches, 0xf9);
1320
1321 // Set the basic modeset options
1322 SET_BDA(modeset_ctl, 0x51);
1323
1324 // Set the default MSR
1325 SET_BDA(video_msr, 0x09);
1326}
1327
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001328void VISIBLE16
1329vga_post(struct bregs *regs)
1330{
1331 debug_enter(regs, DEBUG_VGA_POST);
1332
Kevin O'Connor8bc059e2009-05-17 21:19:36 -04001333 vgahw_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001334
1335 init_bios_area();
1336
Kevin O'Connor21079f42009-05-16 21:30:10 -04001337 if (CONFIG_VBE)
1338 vbe_init();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001339
1340 extern void entry_10(void);
Kevin O'Connord113a992009-05-16 21:05:02 -04001341 SET_IVT(0x10, get_global_seg(), (u32)entry_10);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001342
1343 if (CONFIG_CIRRUS)
1344 cirrus_init();
1345
1346 // XXX - clear screen and display info
1347
1348 // XXX: fill it
1349 SET_VGA(video_save_pointer_table[0], (u32)video_param_table);
Kevin O'Connord113a992009-05-16 21:05:02 -04001350 SET_VGA(video_save_pointer_table[1], get_global_seg());
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001351
1352 // Fixup checksum
1353 extern u8 _rom_header_size, _rom_header_checksum;
1354 SET_VGA(_rom_header_checksum, 0);
Kevin O'Connord113a992009-05-16 21:05:02 -04001355 u8 sum = -checksum_far(get_global_seg(), 0, _rom_header_size * 512);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001356 SET_VGA(_rom_header_checksum, sum);
1357}