blob: 47bfe2cb324d264f3a00ffa42af92123b9cdad9f [file] [log] [blame]
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001// VGA bios implementation
2//
Kevin O'Connordab0a742013-12-03 11:50:49 -05003// Copyright (C) 2009-2013 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04004// 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
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04008#include "biosvar.h" // GET_BDA
Kevin O'Connor2d2fa312013-09-14 21:55:26 -04009#include "bregs.h" // struct bregs
Kevin O'Connore91ec7c2012-01-14 16:30:49 -050010#include "clext.h" // clext_1012
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040011#include "config.h" // CONFIG_*
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040012#include "output.h" // dprintf
Kevin O'Connor2e57c812013-09-14 22:29:32 -040013#include "std/vbe.h" // VBE_RETURN_STATUS_FAILED
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040014#include "stdvga.h" // stdvga_set_cursor_shape
Kevin O'Connorfa9c66a2013-09-14 19:10:40 -040015#include "string.h" // memset_far
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040016#include "vgabios.h" // calc_page_size
17#include "vgahw.h" // vgahw_set_mode
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040018
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040019
20/****************************************************************
21 * Helper functions
22 ****************************************************************/
23
Kevin O'Connor3876b532012-01-24 00:07:44 -050024// Return the bits per pixel in system memory for a given mode.
25int
26vga_bpp(struct vgamode_s *vmode_g)
27{
28 switch (GET_GLOBAL(vmode_g->memmodel)) {
29 case MM_TEXT:
30 return 16;
31 case MM_PLANAR:
32 return 1;
33 }
34 u8 depth = GET_GLOBAL(vmode_g->depth);
35 if (depth > 8)
36 return ALIGN(depth, 8);
37 return depth;
38}
39
Kevin O'Connor83047be2012-01-07 18:27:19 -050040u16
41calc_page_size(u8 memmodel, u16 width, u16 height)
42{
43 switch (memmodel) {
44 case MM_TEXT:
45 return ALIGN(width * height * 2, 2*1024);
46 case MM_CGA:
47 return 16*1024;
48 default:
49 return ALIGN(width * height / 8, 8*1024);
50 }
51}
52
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040053static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040054set_cursor_shape(u8 start, u8 end)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040055{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040056 start &= 0x3f;
57 end &= 0x1f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040058
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040059 u16 curs = (start << 8) + end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040060 SET_BDA(cursor_type, curs);
61
Kevin O'Connordd2be772009-05-16 15:41:23 -040062 u8 modeset_ctl = GET_BDA(modeset_ctl);
63 u16 cheight = GET_BDA(char_height);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040064 if ((modeset_ctl & 0x01) && (cheight > 8) && (end < 8) && (start < 0x20)) {
65 if (end != (start + 1))
66 start = ((start + 1) * cheight / 8) - 1;
Kevin O'Connordd2be772009-05-16 15:41:23 -040067 else
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040068 start = ((end + 1) * cheight / 8) - 2;
69 end = ((end + 1) * cheight / 8) - 1;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040070 }
Kevin O'Connor88ca7412011-12-31 04:24:20 -050071 stdvga_set_cursor_shape(start, end);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040072}
73
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040074static u16
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040075get_cursor_shape(u8 page)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040076{
77 if (page > 7)
78 return 0;
79 // FIXME should handle VGA 14/16 lines
80 return GET_BDA(cursor_type);
81}
82
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040083static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040084set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040085{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050086 u8 page = cp.page, x = cp.x, y = cp.y;
87
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040088 // Should not happen...
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050089 if (page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040090 return;
91
92 // Bios cursor pos
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050093 SET_BDA(cursor_pos[page], (y << 8) | x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040094
95 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -040096 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -040097 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -040098 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040099
Kevin O'Connor83047be2012-01-07 18:27:19 -0500100 // Calculate the memory address
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500101 int address = (GET_BDA(video_pagesize) * page
102 + (x + y * GET_BDA(video_cols)) * 2);
Kevin O'Connor16920072012-01-27 22:59:46 -0500103 stdvga_set_cursor_pos(address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400104}
105
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400106static struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400107get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400108{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400109 if (page == 0xff)
110 // special case - use current page
111 page = GET_BDA(video_page);
112 if (page > 7) {
113 struct cursorpos cp = { 0, 0, 0xfe };
114 return cp;
115 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400116 // FIXME should handle VGA 14/16 lines
Kevin O'Connor918b1562009-05-25 11:05:18 -0400117 u16 xy = GET_BDA(cursor_pos[page]);
118 struct cursorpos cp = {xy, xy>>8, page};
119 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400120}
121
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400122static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400123set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400124{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400125 if (page > 7)
126 return;
127
128 // Get the mode
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500129 struct vgamode_s *vmode_g = get_current_mode();
Kevin O'Connor5727c292009-05-16 17:29:32 -0400130 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400131 return;
132
Kevin O'Connor4c85a262012-02-12 11:50:52 -0500133 // Get cursor pos for the given page
Kevin O'Connor918b1562009-05-25 11:05:18 -0400134 struct cursorpos cp = get_cursor_pos(page);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400135
Kevin O'Connor83047be2012-01-07 18:27:19 -0500136 // Calculate memory address of start of page
Kevin O'Connord61fc532012-01-27 20:37:45 -0500137 int address = GET_BDA(video_pagesize) * page;
138 vgahw_set_displaystart(vmode_g, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400139
140 // And change the BIOS page
Kevin O'Connor83047be2012-01-07 18:27:19 -0500141 SET_BDA(video_pagestart, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400142 SET_BDA(video_page, page);
143
Kevin O'Connora12c2152009-05-13 22:06:16 -0400144 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400145
146 // Display the cursor, now the page is active
Kevin O'Connor918b1562009-05-25 11:05:18 -0400147 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400148}
149
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400150static void
151set_scan_lines(u8 lines)
152{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500153 stdvga_set_scan_lines(lines);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400154 if (lines == 8)
155 set_cursor_shape(0x06, 0x07);
156 else
157 set_cursor_shape(lines - 4, lines - 3);
158 SET_BDA(char_height, lines);
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500159 u16 vde = stdvga_get_vde();
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400160 u8 rows = vde / lines;
161 SET_BDA(video_rows, rows - 1);
162 u16 cols = GET_BDA(video_cols);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500163 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400164}
165
166
167/****************************************************************
168 * Character writing
169 ****************************************************************/
170
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400171// Scroll the screen one line. This function is designed to be called
172// tail-recursive to reduce stack usage.
173static void noinline
174scroll_one(u16 nbrows, u16 nbcols, u8 page)
Kevin O'Connor09262412009-05-25 11:44:11 -0400175{
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400176 struct cursorpos ul = {0, 0, page};
177 struct cursorpos lr = {nbcols-1, nbrows-1, page};
178 vgafb_scroll(1, -1, ul, lr);
179}
180
181// Write a character to the screen at a given position. Implement
182// special characters and scroll the screen if necessary.
183static void
184write_teletype(struct cursorpos *pcp, struct carattr ca)
185{
186 struct cursorpos cp = *pcp;
187
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400188 // Get the dimensions
Kevin O'Connordd2be772009-05-16 15:41:23 -0400189 u16 nbrows = GET_BDA(video_rows) + 1;
190 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400191
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400192 switch (ca.car) {
193 case 7:
194 //FIXME should beep
195 break;
196 case 8:
197 if (cp.x > 0)
198 cp.x--;
199 break;
200 case '\r':
201 cp.x = 0;
202 break;
203 case '\n':
204 cp.y++;
205 break;
206 case '\t':
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500207 ca.car = ' ';
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400208 do {
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500209 vgafb_write_char(cp, ca);
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400210 cp.x++;
211 } while (cp.x < nbcols && cp.x % 8);
212 break;
213 default:
214 vgafb_write_char(cp, ca);
215 cp.x++;
216 }
217
Kevin O'Connor82221b22009-05-26 00:20:40 -0400218 // Do we need to wrap ?
219 if (cp.x == nbcols) {
220 cp.x = 0;
221 cp.y++;
222 }
223 // Do we need to scroll ?
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400224 if (cp.y < nbrows) {
225 *pcp = cp;
226 return;
Kevin O'Connor82221b22009-05-26 00:20:40 -0400227 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400228 // Scroll screen
229 cp.y--;
230 *pcp = cp;
231 scroll_one(nbrows, nbcols, cp.page);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400232}
233
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400234
235/****************************************************************
236 * Save and restore bda state
237 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400238
Kevin O'Connor9f857fc2012-02-04 11:59:02 -0500239void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400240save_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400241{
Kevin O'Connorda6a1572014-02-05 19:29:08 -0500242 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
243 , sizeof(info->bda_0x49));
244 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
245 , sizeof(info->bda_0x84));
246 SET_FARVAR(seg, info->vbe_mode, GET_BDA(vbe_mode));
Kevin O'Connor9f985422009-09-09 11:34:39 -0400247 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
248 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400249}
250
Kevin O'Connor9f857fc2012-02-04 11:59:02 -0500251void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400252restore_bda_state(u16 seg, struct saveBDAstate *info)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400253{
Kevin O'Connorda6a1572014-02-05 19:29:08 -0500254 memcpy_far(SEG_BDA, (void*)0x49, seg, info->bda_0x49
255 , sizeof(info->bda_0x49));
256 memcpy_far(SEG_BDA, (void*)0x84, seg, info->bda_0x84
257 , sizeof(info->bda_0x84));
258 SET_BDA(vbe_mode, GET_FARVAR(seg, info->vbe_mode));
Kevin O'Connor9f985422009-09-09 11:34:39 -0400259 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
260 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400261}
262
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500263
264/****************************************************************
265 * Mode setting
266 ****************************************************************/
267
268struct vgamode_s *
269get_current_mode(void)
270{
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500271 return vgahw_find_mode(GET_BDA(vbe_mode) & ~MF_VBEFLAGS);
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500272}
273
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500274// Setup BDA after a mode switch.
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500275int
276vga_set_mode(int mode, int flags)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400277{
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500278 dprintf(1, "set VGA mode %x\n", mode);
279 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
280 if (!vmode_g)
281 return VBE_RETURN_STATUS_FAILED;
282
283 int ret = vgahw_set_mode(vmode_g, flags);
284 if (ret)
285 return ret;
286
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400287 // Set the BIOS mem
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500288 int width = GET_GLOBAL(vmode_g->width);
289 int height = GET_GLOBAL(vmode_g->height);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500290 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500291 int cheight = GET_GLOBAL(vmode_g->cheight);
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500292 if (mode < 0x100)
293 SET_BDA(video_mode, mode);
294 else
295 SET_BDA(video_mode, 0xff);
296 SET_BDA(vbe_mode, mode | (flags & MF_VBEFLAGS));
Kevin O'Connor83047be2012-01-07 18:27:19 -0500297 if (memmodel == MM_TEXT) {
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500298 SET_BDA(video_cols, width);
299 SET_BDA(video_rows, height-1);
300 SET_BDA(cursor_type, 0x0607);
301 } else {
302 int cwidth = GET_GLOBAL(vmode_g->cwidth);
303 SET_BDA(video_cols, width / cwidth);
304 SET_BDA(video_rows, (height / cheight) - 1);
305 SET_BDA(cursor_type, 0x0000);
306 }
Kevin O'Connor83047be2012-01-07 18:27:19 -0500307 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
Kevin O'Connorcecbc5d2011-12-31 17:24:11 -0500308 SET_BDA(crtc_address, stdvga_get_crtc());
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400309 SET_BDA(char_height, cheight);
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500310 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400311 SET_BDA(video_switches, 0xF9);
312 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
Kevin O'Connorcecbc5d2011-12-31 17:24:11 -0500313 int i;
314 for (i=0; i<8; i++)
315 SET_BDA(cursor_pos[i], 0x0000);
316 SET_BDA(video_pagestart, 0x0000);
317 SET_BDA(video_page, 0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400318
319 // FIXME We nearly have the good tables. to be reworked
320 SET_BDA(dcc_index, 0x08); // 8 is VGA should be ok for now
Kevin O'Connor9f985422009-09-09 11:34:39 -0400321 SET_BDA(video_savetable
Kevin O'Connor815e4472011-12-21 09:05:32 -0500322 , SEGOFF(get_global_seg(), (u32)&video_save_pointer_table));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400323
324 // FIXME
325 SET_BDA(video_msr, 0x00); // Unavailable on vanilla vga, but...
326 SET_BDA(video_pal, 0x00); // Unavailable on vanilla vga, but...
327
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400328 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400329 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400330
331 switch (cheight) {
332 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400333 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400334 break;
335 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400336 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400337 break;
338 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400339 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400340 break;
341 }
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500342
343 return 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400344}
345
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500346
347/****************************************************************
348 * VGA int 10 handler
349 ****************************************************************/
350
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400351static void
Julian Pidancet87879e22011-12-19 05:08:00 +0000352handle_1000(struct bregs *regs)
353{
Kevin O'Connor5108c692011-12-31 19:13:45 -0500354 int mode = regs->al & 0x7f;
Julian Pidancet87879e22011-12-19 05:08:00 +0000355
356 // Set regs->al
357 if (mode > 7)
358 regs->al = 0x20;
359 else if (mode == 6)
360 regs->al = 0x3f;
361 else
362 regs->al = 0x30;
363
Kevin O'Connorb7b92932013-03-09 13:04:47 -0500364 int flags = MF_LEGACY | (GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM));
Kevin O'Connor5108c692011-12-31 19:13:45 -0500365 if (regs->al & 0x80)
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500366 flags |= MF_NOCLEARMEM;
367
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500368 vga_set_mode(mode, flags);
Julian Pidancet87879e22011-12-19 05:08:00 +0000369}
370
371static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400372handle_1001(struct bregs *regs)
373{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400374 set_cursor_shape(regs->ch, regs->cl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400375}
376
377static void
378handle_1002(struct bregs *regs)
379{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400380 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
381 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400382}
383
384static void
385handle_1003(struct bregs *regs)
386{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400387 regs->cx = get_cursor_shape(regs->bh);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400388 struct cursorpos cp = get_cursor_pos(regs->bh);
389 regs->dl = cp.x;
390 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400391}
392
393// Read light pen pos (unimplemented)
394static void
395handle_1004(struct bregs *regs)
396{
397 debug_stub(regs);
398 regs->ax = regs->bx = regs->cx = regs->dx = 0;
399}
400
401static void
402handle_1005(struct bregs *regs)
403{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400404 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400405}
406
407static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400408verify_scroll(struct bregs *regs, int dir)
409{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500410 u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400411 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500412 if (lry >= nbrows)
413 lry = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400414 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500415 if (lrx >= nbcols)
416 lrx = nbcols - 1;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400417
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500418 if (ulx > lrx || uly > lry)
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400419 return;
420
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500421 int nblines = regs->al;
422 if (!nblines || nblines > lry - uly + 1)
423 nblines = lry - uly + 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400424
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500425 u8 page = GET_BDA(video_page);
426 struct cursorpos ul = {ulx, uly, page};
427 struct cursorpos lr = {lrx, lry, page};
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400428 vgafb_scroll(dir * nblines, regs->bh, ul, lr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400429}
430
431static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400432handle_1006(struct bregs *regs)
433{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400434 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400435}
436
437static void
438handle_1007(struct bregs *regs)
439{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400440 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400441}
442
443static void
444handle_1008(struct bregs *regs)
445{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400446 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400447 regs->al = ca.car;
448 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400449}
450
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400451static void noinline
Kevin O'Connord3b38152009-05-26 00:05:37 -0400452write_chars(u8 page, struct carattr ca, u16 count)
453{
Kevin O'Connor7b975e52012-03-05 17:11:50 -0500454 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connord3b38152009-05-26 00:05:37 -0400455 struct cursorpos cp = get_cursor_pos(page);
456 while (count--) {
457 vgafb_write_char(cp, ca);
458 cp.x++;
Kevin O'Connor7b975e52012-03-05 17:11:50 -0500459 if (cp.x >= nbcols) {
460 cp.x -= nbcols;
461 cp.y++;
462 }
Kevin O'Connord3b38152009-05-26 00:05:37 -0400463 }
464}
465
466static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400467handle_1009(struct bregs *regs)
468{
Kevin O'Connor09262412009-05-25 11:44:11 -0400469 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400470 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400471}
472
473static void
474handle_100a(struct bregs *regs)
475{
Kevin O'Connor09262412009-05-25 11:44:11 -0400476 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connord3b38152009-05-26 00:05:37 -0400477 write_chars(regs->bh, ca, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400478}
479
480
481static void
482handle_100b00(struct bregs *regs)
483{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500484 stdvga_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400485}
486
487static void
488handle_100b01(struct bregs *regs)
489{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500490 stdvga_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400491}
492
493static void
494handle_100bXX(struct bregs *regs)
495{
496 debug_stub(regs);
497}
498
499static void
500handle_100b(struct bregs *regs)
501{
502 switch (regs->bh) {
503 case 0x00: handle_100b00(regs); break;
504 case 0x01: handle_100b01(regs); break;
505 default: handle_100bXX(regs); break;
506 }
507}
508
509
510static void
511handle_100c(struct bregs *regs)
512{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400513 // XXX - page (regs->bh) is unused
514 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400515}
516
517static void
518handle_100d(struct bregs *regs)
519{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400520 // XXX - page (regs->bh) is unused
521 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400522}
523
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400524static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400525handle_100e(struct bregs *regs)
526{
527 // Ralf Brown Interrupt list is WRONG on bh(page)
528 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400529 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400530 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400531 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400532 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400533}
534
535static void
536handle_100f(struct bregs *regs)
537{
Kevin O'Connore7132042009-05-25 00:10:35 -0400538 regs->bh = GET_BDA(video_page);
539 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
540 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400541}
542
543
544static void
545handle_101000(struct bregs *regs)
546{
547 if (regs->bl > 0x14)
548 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500549 stdvga_attr_write(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400550}
551
552static void
553handle_101001(struct bregs *regs)
554{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500555 stdvga_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400556}
557
558static void
559handle_101002(struct bregs *regs)
560{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500561 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400562}
563
564static void
565handle_101003(struct bregs *regs)
566{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500567 stdvga_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400568}
569
570static void
571handle_101007(struct bregs *regs)
572{
573 if (regs->bl > 0x14)
574 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500575 regs->bh = stdvga_attr_read(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400576}
577
578static void
579handle_101008(struct bregs *regs)
580{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500581 regs->bh = stdvga_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400582}
583
584static void
585handle_101009(struct bregs *regs)
586{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500587 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400588}
589
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400590static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400591handle_101010(struct bregs *regs)
592{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400593 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500594 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400595}
596
597static void
598handle_101012(struct bregs *regs)
599{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500600 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400601}
602
603static void
604handle_101013(struct bregs *regs)
605{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500606 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400607}
608
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400609static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400610handle_101015(struct bregs *regs)
611{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400612 u8 rgb[3];
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500613 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400614 regs->dh = rgb[0];
615 regs->ch = rgb[1];
616 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400617}
618
619static void
620handle_101017(struct bregs *regs)
621{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500622 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400623}
624
625static void
626handle_101018(struct bregs *regs)
627{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500628 stdvga_pelmask_write(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400629}
630
631static void
632handle_101019(struct bregs *regs)
633{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500634 regs->bl = stdvga_pelmask_read();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400635}
636
637static void
638handle_10101a(struct bregs *regs)
639{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500640 stdvga_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400641}
642
643static void
644handle_10101b(struct bregs *regs)
645{
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500646 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400647}
648
649static void
650handle_1010XX(struct bregs *regs)
651{
652 debug_stub(regs);
653}
654
655static void
656handle_1010(struct bregs *regs)
657{
658 switch (regs->al) {
659 case 0x00: handle_101000(regs); break;
660 case 0x01: handle_101001(regs); break;
661 case 0x02: handle_101002(regs); break;
662 case 0x03: handle_101003(regs); break;
663 case 0x07: handle_101007(regs); break;
664 case 0x08: handle_101008(regs); break;
665 case 0x09: handle_101009(regs); break;
666 case 0x10: handle_101010(regs); break;
667 case 0x12: handle_101012(regs); break;
668 case 0x13: handle_101013(regs); break;
669 case 0x15: handle_101015(regs); break;
670 case 0x17: handle_101017(regs); break;
671 case 0x18: handle_101018(regs); break;
672 case 0x19: handle_101019(regs); break;
673 case 0x1a: handle_10101a(regs); break;
674 case 0x1b: handle_10101b(regs); break;
675 default: handle_1010XX(regs); break;
676 }
677}
678
679
680static void
681handle_101100(struct bregs *regs)
682{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500683 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
684 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400685}
686
687static void
688handle_101101(struct bregs *regs)
689{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500690 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400691}
692
693static void
694handle_101102(struct bregs *regs)
695{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500696 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400697}
698
699static void
700handle_101103(struct bregs *regs)
701{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500702 stdvga_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400703}
704
705static void
706handle_101104(struct bregs *regs)
707{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500708 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400709}
710
711static void
712handle_101110(struct bregs *regs)
713{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500714 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
715 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400716 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400717}
718
719static void
720handle_101111(struct bregs *regs)
721{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500722 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400723 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400724}
725
726static void
727handle_101112(struct bregs *regs)
728{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500729 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400730 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400731}
732
733static void
734handle_101114(struct bregs *regs)
735{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500736 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400737 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400738}
739
740static void
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100741handle_101120(struct bregs *regs)
742{
743 SET_IVT(0x1f, SEGOFF(regs->es, regs->bp));
744}
745
746void
747load_gfx_font(u16 seg, u16 off, u8 height, u8 bl, u8 dl)
748{
749 u8 rows;
750
751 SET_IVT(0x43, SEGOFF(seg, off));
752 switch(bl) {
753 case 0:
754 rows = dl;
755 break;
756 case 1:
757 rows = 14;
758 break;
759 case 3:
760 rows = 43;
761 break;
762 case 2:
763 default:
764 rows = 25;
765 break;
766 }
767 SET_BDA(video_rows, rows - 1);
768 SET_BDA(char_height, height);
769}
770
771static void
772handle_101121(struct bregs *regs)
773{
774 load_gfx_font(regs->es, regs->bp, regs->cx, regs->bl, regs->dl);
775}
776
777static void
778handle_101122(struct bregs *regs)
779{
780 load_gfx_font(get_global_seg(), (u32)vgafont14, 14, regs->bl, regs->dl);
781}
782
783static void
784handle_101123(struct bregs *regs)
785{
786 load_gfx_font(get_global_seg(), (u32)vgafont8, 8, regs->bl, regs->dl);
787}
788
789static void
790handle_101124(struct bregs *regs)
791{
792 load_gfx_font(get_global_seg(), (u32)vgafont16, 16, regs->bl, regs->dl);
793}
794
795static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400796handle_101130(struct bregs *regs)
797{
Kevin O'Connore7132042009-05-25 00:10:35 -0400798 switch (regs->bh) {
799 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500800 struct segoff_s so = GET_IVT(0x1f);
801 regs->es = so.seg;
802 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400803 break;
804 }
805 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500806 struct segoff_s so = GET_IVT(0x43);
807 regs->es = so.seg;
808 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400809 break;
810 }
811 case 0x02:
812 regs->es = get_global_seg();
813 regs->bp = (u32)vgafont14;
814 break;
815 case 0x03:
816 regs->es = get_global_seg();
817 regs->bp = (u32)vgafont8;
818 break;
819 case 0x04:
820 regs->es = get_global_seg();
821 regs->bp = (u32)vgafont8 + 128 * 8;
822 break;
823 case 0x05:
824 regs->es = get_global_seg();
825 regs->bp = (u32)vgafont14alt;
826 break;
827 case 0x06:
828 regs->es = get_global_seg();
829 regs->bp = (u32)vgafont16;
830 break;
831 case 0x07:
832 regs->es = get_global_seg();
833 regs->bp = (u32)vgafont16alt;
834 break;
835 default:
836 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
837 return;
838 }
839 // Set byte/char of on screen font
840 regs->cx = GET_BDA(char_height) & 0xff;
841
842 // Set Highest char row
Kevin O'Connor4c85a262012-02-12 11:50:52 -0500843 regs->dl = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400844}
845
846static void
847handle_1011XX(struct bregs *regs)
848{
849 debug_stub(regs);
850}
851
852static void
853handle_1011(struct bregs *regs)
854{
855 switch (regs->al) {
856 case 0x00: handle_101100(regs); break;
857 case 0x01: handle_101101(regs); break;
858 case 0x02: handle_101102(regs); break;
859 case 0x03: handle_101103(regs); break;
860 case 0x04: handle_101104(regs); break;
861 case 0x10: handle_101110(regs); break;
862 case 0x11: handle_101111(regs); break;
863 case 0x12: handle_101112(regs); break;
864 case 0x14: handle_101114(regs); break;
865 case 0x30: handle_101130(regs); break;
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100866 case 0x20: handle_101120(regs); break;
867 case 0x21: handle_101121(regs); break;
868 case 0x22: handle_101122(regs); break;
869 case 0x23: handle_101123(regs); break;
870 case 0x24: handle_101124(regs); break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400871 default: handle_1011XX(regs); break;
872 }
873}
874
875
876static void
877handle_101210(struct bregs *regs)
878{
Kevin O'Connore7132042009-05-25 00:10:35 -0400879 u16 crtc_addr = GET_BDA(crtc_address);
880 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
881 regs->bx = 0x0103;
882 else
883 regs->bx = 0x0003;
884 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400885}
886
887static void
888handle_101230(struct bregs *regs)
889{
Kevin O'Connore7132042009-05-25 00:10:35 -0400890 u8 mctl = GET_BDA(modeset_ctl);
891 u8 vswt = GET_BDA(video_switches);
892 switch (regs->al) {
893 case 0x00:
894 // 200 lines
895 mctl = (mctl & ~0x10) | 0x80;
896 vswt = (vswt & ~0x0f) | 0x08;
897 break;
898 case 0x01:
899 // 350 lines
900 mctl &= ~0x90;
901 vswt = (vswt & ~0x0f) | 0x09;
902 break;
903 case 0x02:
904 // 400 lines
905 mctl = (mctl & ~0x80) | 0x10;
906 vswt = (vswt & ~0x0f) | 0x09;
907 break;
908 default:
909 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
910 break;
911 }
912 SET_BDA(modeset_ctl, mctl);
913 SET_BDA(video_switches, vswt);
914 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400915}
916
917static void
918handle_101231(struct bregs *regs)
919{
Kevin O'Connore7132042009-05-25 00:10:35 -0400920 u8 v = (regs->al & 0x01) << 3;
921 u8 mctl = GET_BDA(video_ctl) & ~0x08;
922 SET_BDA(video_ctl, mctl | v);
923 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400924}
925
926static void
927handle_101232(struct bregs *regs)
928{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500929 stdvga_enable_video_addressing(regs->al);
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400930 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400931}
932
933static void
934handle_101233(struct bregs *regs)
935{
Kevin O'Connore7132042009-05-25 00:10:35 -0400936 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
937 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
938 SET_BDA(modeset_ctl, v | v2);
939 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400940}
941
942static void
943handle_101234(struct bregs *regs)
944{
Kevin O'Connore7132042009-05-25 00:10:35 -0400945 u8 v = (regs->al & 0x01) ^ 0x01;
946 u8 v2 = GET_BDA(modeset_ctl) & ~0x01;
947 SET_BDA(modeset_ctl, v | v2);
948 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400949}
950
951static void
952handle_101235(struct bregs *regs)
953{
954 debug_stub(regs);
955 regs->al = 0x12;
956}
957
958static void
959handle_101236(struct bregs *regs)
960{
961 debug_stub(regs);
962 regs->al = 0x12;
963}
964
965static void
966handle_1012XX(struct bregs *regs)
967{
968 debug_stub(regs);
969}
970
971static void
972handle_1012(struct bregs *regs)
973{
Kevin O'Connore91ec7c2012-01-14 16:30:49 -0500974 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
975 clext_1012(regs);
976 return;
977 }
978
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400979 switch (regs->bl) {
980 case 0x10: handle_101210(regs); break;
981 case 0x30: handle_101230(regs); break;
982 case 0x31: handle_101231(regs); break;
983 case 0x32: handle_101232(regs); break;
984 case 0x33: handle_101233(regs); break;
985 case 0x34: handle_101234(regs); break;
986 case 0x35: handle_101235(regs); break;
987 case 0x36: handle_101236(regs); break;
988 default: handle_1012XX(regs); break;
989 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400990}
991
992
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400993// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400994static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400995handle_1013(struct bregs *regs)
996{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500997 struct cursorpos cp;
998 if (regs->dh == 0xff)
999 // if row=0xff special case : use current cursor position
1000 cp = get_cursor_pos(regs->bh);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001001 else
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001002 cp = (struct cursorpos) {regs->dl, regs->dh, regs->bh};
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001003
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001004 u16 count = regs->cx;
1005 u8 *offset_far = (void*)(regs->bp + 0);
1006 u8 attr = regs->bl;
1007 while (count--) {
1008 u8 car = GET_FARVAR(regs->es, *offset_far);
1009 offset_far++;
1010 if (regs->al & 2) {
1011 attr = GET_FARVAR(regs->es, *offset_far);
1012 offset_far++;
1013 }
1014
1015 struct carattr ca = {car, attr, 1};
1016 write_teletype(&cp, ca);
1017 }
1018
1019 if (regs->al & 1)
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001020 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001021}
1022
1023
1024static void
1025handle_101a00(struct bregs *regs)
1026{
Kevin O'Connore7132042009-05-25 00:10:35 -04001027 regs->bx = GET_BDA(dcc_index);
1028 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001029}
1030
1031static void
1032handle_101a01(struct bregs *regs)
1033{
Kevin O'Connore7132042009-05-25 00:10:35 -04001034 SET_BDA(dcc_index, regs->bl);
1035 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1036 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001037}
1038
1039static void
1040handle_101aXX(struct bregs *regs)
1041{
1042 debug_stub(regs);
1043}
1044
1045static void
1046handle_101a(struct bregs *regs)
1047{
1048 switch (regs->al) {
1049 case 0x00: handle_101a00(regs); break;
1050 case 0x01: handle_101a01(regs); break;
1051 default: handle_101aXX(regs); break;
1052 }
1053}
1054
1055
Kevin O'Connorefb45232012-01-14 22:55:11 -05001056static u8 static_functionality[0x10] VAR16 = {
1057 /* 0 */ 0xff, // All modes supported #1
1058 /* 1 */ 0xe0, // All modes supported #2
1059 /* 2 */ 0x0f, // All modes supported #3
1060 /* 3 */ 0x00, 0x00, 0x00, 0x00, // reserved
1061 /* 7 */ 0x07, // 200, 350, 400 scan lines
1062 /* 8 */ 0x02, // mamimum number of visible charsets in text mode
1063 /* 9 */ 0x08, // total number of charset blocks in text mode
1064 /* a */ 0xe7, // Change to add new functions
1065 /* b */ 0x0c, // Change to add new functions
1066 /* c */ 0x00, // reserved
1067 /* d */ 0x00, // reserved
1068 /* e */ 0x00, // Change to add new functions
1069 /* f */ 0x00 // reserved
1070};
1071
Kevin O'Connorca668642009-05-21 23:06:08 -04001072struct funcInfo {
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001073 struct segoff_s static_functionality;
Kevin O'Connorca668642009-05-21 23:06:08 -04001074 u8 bda_0x49[30];
1075 u8 bda_0x84[3];
1076 u8 dcc_index;
1077 u8 dcc_alt;
1078 u16 colors;
1079 u8 pages;
1080 u8 scan_lines;
1081 u8 primary_char;
1082 u8 secondar_char;
1083 u8 misc;
1084 u8 non_vga_mode;
1085 u8 reserved_2f[2];
1086 u8 video_mem;
1087 u8 save_flags;
1088 u8 disp_info;
1089 u8 reserved_34[12];
Kevin O'Connorf5ec1e02014-02-05 18:49:44 -05001090} PACKED;
Kevin O'Connorca668642009-05-21 23:06:08 -04001091
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001092static void
1093handle_101b(struct bregs *regs)
1094{
Kevin O'Connorca668642009-05-21 23:06:08 -04001095 u16 seg = regs->es;
1096 struct funcInfo *info = (void*)(regs->di+0);
1097 memset_far(seg, info, 0, sizeof(*info));
1098 // Address of static functionality table
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001099 SET_FARVAR(seg, info->static_functionality
1100 , SEGOFF(get_global_seg(), (u32)static_functionality));
Kevin O'Connorca668642009-05-21 23:06:08 -04001101
1102 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001103 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1104 , sizeof(info->bda_0x49));
1105 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1106 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001107
1108 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1109 SET_FARVAR(seg, info->colors, 16);
1110 SET_FARVAR(seg, info->pages, 8);
1111 SET_FARVAR(seg, info->scan_lines, 2);
1112 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001113 regs->al = 0x1B;
1114}
1115
1116
1117static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001118handle_101c(struct bregs *regs)
1119{
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001120 u16 seg = regs->es;
1121 void *data = (void*)(regs->bx+0);
1122 u16 states = regs->cx;
1123 if (states & ~0x07)
1124 goto fail;
1125 int ret;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001126 switch (regs->al) {
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001127 case 0x00:
Kevin O'Connor2469f892012-02-04 12:40:02 -05001128 ret = vgahw_size_state(states);
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001129 if (ret < 0)
1130 goto fail;
1131 regs->bx = ret / 64;
1132 break;
1133 case 0x01:
Kevin O'Connor2469f892012-02-04 12:40:02 -05001134 ret = vgahw_save_state(seg, data, states);
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001135 if (ret)
1136 goto fail;
1137 break;
1138 case 0x02:
Kevin O'Connor2469f892012-02-04 12:40:02 -05001139 ret = vgahw_restore_state(seg, data, states);
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001140 if (ret)
1141 goto fail;
1142 break;
1143 default:
1144 goto fail;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001145 }
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001146 regs->al = 0x1c;
1147fail:
1148 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001149}
1150
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001151static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001152handle_10XX(struct bregs *regs)
1153{
1154 debug_stub(regs);
1155}
1156
1157// INT 10h Video Support Service Entry Point
1158void VISIBLE16
1159handle_10(struct bregs *regs)
1160{
1161 debug_enter(regs, DEBUG_VGA_10);
1162 switch (regs->ah) {
1163 case 0x00: handle_1000(regs); break;
1164 case 0x01: handle_1001(regs); break;
1165 case 0x02: handle_1002(regs); break;
1166 case 0x03: handle_1003(regs); break;
1167 case 0x04: handle_1004(regs); break;
1168 case 0x05: handle_1005(regs); break;
1169 case 0x06: handle_1006(regs); break;
1170 case 0x07: handle_1007(regs); break;
1171 case 0x08: handle_1008(regs); break;
1172 case 0x09: handle_1009(regs); break;
1173 case 0x0a: handle_100a(regs); break;
1174 case 0x0b: handle_100b(regs); break;
1175 case 0x0c: handle_100c(regs); break;
1176 case 0x0d: handle_100d(regs); break;
1177 case 0x0e: handle_100e(regs); break;
1178 case 0x0f: handle_100f(regs); break;
1179 case 0x10: handle_1010(regs); break;
1180 case 0x11: handle_1011(regs); break;
1181 case 0x12: handle_1012(regs); break;
1182 case 0x13: handle_1013(regs); break;
1183 case 0x1a: handle_101a(regs); break;
1184 case 0x1b: handle_101b(regs); break;
1185 case 0x1c: handle_101c(regs); break;
1186 case 0x4f: handle_104f(regs); break;
1187 default: handle_10XX(regs); break;
1188 }
1189}