blob: 858f415afa10c316af4e4f52e6a6b13367e5e6e8 [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'Connorc9aecfc2014-10-22 20:57:37 -040053// Determine cursor shape (taking into account possible cursor scaling)
54static u16
55get_cursor_shape(void)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040056{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040057 u16 cursor_type = GET_BDA(cursor_type);
Kevin O'Connor479fd722014-10-22 20:27:28 -040058 u8 emulate_cursor = (GET_BDA(video_ctl) & 1) == 0;
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040059 if (!emulate_cursor)
60 return cursor_type;
61 u8 start = (cursor_type >> 8) & 0x3f;
62 u8 end = cursor_type & 0x1f;
Kevin O'Connordd2be772009-05-16 15:41:23 -040063 u16 cheight = GET_BDA(char_height);
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040064 if (cheight <= 8 || end >= 8 || start >= 0x20)
65 return cursor_type;
66 if (end != (start + 1))
67 start = ((start + 1) * cheight / 8) - 1;
68 else
69 start = ((end + 1) * cheight / 8) - 2;
70 end = ((end + 1) * cheight / 8) - 1;
71 return (start << 8) | end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040072}
73
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040074static void
75set_cursor_shape(u16 cursor_type)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040076{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040077 SET_BDA(cursor_type, cursor_type);
78 if (CONFIG_VGA_STDVGA_PORTS)
79 stdvga_set_cursor_shape(get_cursor_shape());
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040080}
81
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040082static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040083set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040084{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050085 u8 page = cp.page, x = cp.x, y = cp.y;
86
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040087 // Should not happen...
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050088 if (page > 7)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040089 return;
90
91 // Bios cursor pos
Kevin O'Connor6ee837b2012-02-13 20:09:02 -050092 SET_BDA(cursor_pos[page], (y << 8) | x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040093
Kevin O'Connorefbf4d62014-02-09 11:50:21 -050094 if (!CONFIG_VGA_STDVGA_PORTS)
95 return;
96
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040097 // Set the hardware cursor
Kevin O'Connordd2be772009-05-16 15:41:23 -040098 u8 current = GET_BDA(video_page);
Kevin O'Connor918b1562009-05-25 11:05:18 -040099 if (cp.page != current)
Kevin O'Connordd2be772009-05-16 15:41:23 -0400100 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400101
Kevin O'Connor83047be2012-01-07 18:27:19 -0500102 // Calculate the memory address
Kevin O'Connora02d4182014-04-05 22:48:05 -0400103 stdvga_set_cursor_pos((int)text_address(cp));
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'Connor918b1562009-05-25 11:05:18 -0400116 u16 xy = GET_BDA(cursor_pos[page]);
117 struct cursorpos cp = {xy, xy>>8, page};
118 return cp;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400119}
120
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400121static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400122set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400123{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400124 if (page > 7)
125 return;
126
127 // Get the mode
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500128 struct vgamode_s *vmode_g = get_current_mode();
Kevin O'Connor5727c292009-05-16 17:29:32 -0400129 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400130 return;
131
Kevin O'Connor83047be2012-01-07 18:27:19 -0500132 // Calculate memory address of start of page
Kevin O'Connora02d4182014-04-05 22:48:05 -0400133 struct cursorpos cp = {0, 0, page};
134 int address = (int)text_address(cp);
Kevin O'Connord61fc532012-01-27 20:37:45 -0500135 vgahw_set_displaystart(vmode_g, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400136
137 // And change the BIOS page
Kevin O'Connor83047be2012-01-07 18:27:19 -0500138 SET_BDA(video_pagestart, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400139 SET_BDA(video_page, page);
140
Kevin O'Connora12c2152009-05-13 22:06:16 -0400141 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400142
143 // Display the cursor, now the page is active
Kevin O'Connora02d4182014-04-05 22:48:05 -0400144 set_cursor_pos(get_cursor_pos(page));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400145}
146
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400147static void
148set_scan_lines(u8 lines)
149{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500150 stdvga_set_scan_lines(lines);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400151 SET_BDA(char_height, lines);
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500152 u16 vde = stdvga_get_vde();
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400153 u8 rows = vde / lines;
154 SET_BDA(video_rows, rows - 1);
155 u16 cols = GET_BDA(video_cols);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500156 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
Kevin O'Connor479fd722014-10-22 20:27:28 -0400157 if (lines == 8)
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400158 set_cursor_shape(0x0607);
Kevin O'Connor479fd722014-10-22 20:27:28 -0400159 else
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400160 set_cursor_shape(((lines - 3) << 8) | (lines - 2));
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400161}
162
163
164/****************************************************************
165 * Character writing
166 ****************************************************************/
167
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500168// Write a character to the screen and calculate new cursor position.
169static void
170write_char(struct cursorpos *pcp, struct carattr ca)
Kevin O'Connor09262412009-05-25 11:44:11 -0400171{
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500172 vgafb_write_char(*pcp, ca);
173 pcp->x++;
174 // Do we need to wrap ?
175 if (pcp->x == GET_BDA(video_cols)) {
176 pcp->x = 0;
177 pcp->y++;
178 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400179}
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{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400186 switch (ca.car) {
187 case 7:
188 //FIXME should beep
189 break;
190 case 8:
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500191 if (pcp->x > 0)
192 pcp->x--;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400193 break;
194 case '\r':
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500195 pcp->x = 0;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400196 break;
197 case '\n':
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500198 pcp->y++;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400199 break;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400200 default:
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500201 write_char(pcp, ca);
202 break;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400203 }
204
Kevin O'Connor82221b22009-05-26 00:20:40 -0400205 // Do we need to scroll ?
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500206 u16 nbrows = GET_BDA(video_rows);
207 if (pcp->y > nbrows) {
208 pcp->y--;
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400209
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400210 struct cursorpos dest = {0, 0, pcp->page};
211 struct cursorpos src = {0, 1, pcp->page};
212 struct cursorpos size = {GET_BDA(video_cols), nbrows};
Kevin O'Connor7217ae72014-10-17 21:47:10 -0400213 vgafb_move_chars(dest, src, size);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400214
215 struct cursorpos clr = {0, nbrows, pcp->page};
216 struct carattr attr = {' ', 0, 0};
217 struct cursorpos clrsize = {GET_BDA(video_cols), 1};
Kevin O'Connor7217ae72014-10-17 21:47:10 -0400218 vgafb_clear_chars(clr, attr, clrsize);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400219 }
Kevin O'Connor82221b22009-05-26 00:20:40 -0400220}
221
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400222
223/****************************************************************
224 * Save and restore bda state
225 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400226
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500227struct saveBDAstate {
228 u8 bda_0x49[28];
229 u8 bda_0x84[6];
230 u16 vbe_mode;
231 struct segoff_s font0;
232 struct segoff_s font1;
233};
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400234
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500235int
236bda_save_restore(int cmd, u16 seg, void *data)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400237{
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500238 if (!(cmd & SR_BDA))
239 return 0;
240 struct saveBDAstate *info = data;
241 if (cmd & SR_SAVE) {
242 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));
Kevin O'Connor9978d492014-10-17 21:17:48 -0400246 SET_FARVAR(seg, info->vbe_mode, GET_BDA_EXT(vbe_mode));
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500247 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
248 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
249 }
250 if (cmd & SR_RESTORE) {
251 memcpy_far(SEG_BDA, (void*)0x49, seg, info->bda_0x49
252 , sizeof(info->bda_0x49));
253 memcpy_far(SEG_BDA, (void*)0x84, seg, info->bda_0x84
254 , sizeof(info->bda_0x84));
Kevin O'Connorf7f22632014-10-17 21:37:23 -0400255 u16 vbe_mode = GET_FARVAR(seg, info->vbe_mode);
256 SET_BDA_EXT(vbe_mode, vbe_mode);
257 struct vgamode_s *vmode_g = vgahw_find_mode(vbe_mode);
258 SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500259 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
260 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
261 }
262 return sizeof(*info);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400263}
264
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500265
266/****************************************************************
267 * Mode setting
268 ****************************************************************/
269
270struct vgamode_s *
271get_current_mode(void)
272{
Kevin O'Connorf7f22632014-10-17 21:37:23 -0400273 return (void*)(GET_BDA_EXT(vgamode_offset)+0);
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500274}
275
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500276// Setup BDA after a mode switch.
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500277int
278vga_set_mode(int mode, int flags)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400279{
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500280 dprintf(1, "set VGA mode %x\n", mode);
281 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
282 if (!vmode_g)
283 return VBE_RETURN_STATUS_FAILED;
284
285 int ret = vgahw_set_mode(vmode_g, flags);
286 if (ret)
287 return ret;
288
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400289 // Set the BIOS mem
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500290 int width = GET_GLOBAL(vmode_g->width);
291 int height = GET_GLOBAL(vmode_g->height);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500292 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500293 int cheight = GET_GLOBAL(vmode_g->cheight);
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500294 if (mode < 0x100)
295 SET_BDA(video_mode, mode);
296 else
297 SET_BDA(video_mode, 0xff);
Kevin O'Connor9978d492014-10-17 21:17:48 -0400298 SET_BDA_EXT(vbe_mode, mode | (flags & MF_VBEFLAGS));
Kevin O'Connorf7f22632014-10-17 21:37:23 -0400299 SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500300 if (memmodel == MM_TEXT) {
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500301 SET_BDA(video_cols, width);
302 SET_BDA(video_rows, height-1);
303 SET_BDA(cursor_type, 0x0607);
304 } else {
305 int cwidth = GET_GLOBAL(vmode_g->cwidth);
306 SET_BDA(video_cols, width / cwidth);
307 SET_BDA(video_rows, (height / cheight) - 1);
308 SET_BDA(cursor_type, 0x0000);
309 }
Kevin O'Connor83047be2012-01-07 18:27:19 -0500310 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500311 SET_BDA(crtc_address, CONFIG_VGA_STDVGA_PORTS ? stdvga_get_crtc() : 0);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400312 SET_BDA(char_height, cheight);
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500313 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400314 SET_BDA(video_switches, 0xF9);
315 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
Kevin O'Connorcecbc5d2011-12-31 17:24:11 -0500316 int i;
317 for (i=0; i<8; i++)
318 SET_BDA(cursor_pos[i], 0x0000);
319 SET_BDA(video_pagestart, 0x0000);
320 SET_BDA(video_page, 0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400321
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400322 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400323 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400324
325 switch (cheight) {
326 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400327 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400328 break;
329 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400330 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400331 break;
332 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400333 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400334 break;
335 }
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500336
337 return 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400338}
339
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500340
341/****************************************************************
342 * VGA int 10 handler
343 ****************************************************************/
344
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400345static void
Julian Pidancet87879e22011-12-19 05:08:00 +0000346handle_1000(struct bregs *regs)
347{
Kevin O'Connor5108c692011-12-31 19:13:45 -0500348 int mode = regs->al & 0x7f;
Julian Pidancet87879e22011-12-19 05:08:00 +0000349
350 // Set regs->al
351 if (mode > 7)
352 regs->al = 0x20;
353 else if (mode == 6)
354 regs->al = 0x3f;
355 else
356 regs->al = 0x30;
357
Kevin O'Connorb7b92932013-03-09 13:04:47 -0500358 int flags = MF_LEGACY | (GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM));
Kevin O'Connor5108c692011-12-31 19:13:45 -0500359 if (regs->al & 0x80)
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500360 flags |= MF_NOCLEARMEM;
361
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500362 vga_set_mode(mode, flags);
Julian Pidancet87879e22011-12-19 05:08:00 +0000363}
364
365static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400366handle_1001(struct bregs *regs)
367{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400368 set_cursor_shape(regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400369}
370
371static void
372handle_1002(struct bregs *regs)
373{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400374 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
375 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400376}
377
378static void
379handle_1003(struct bregs *regs)
380{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400381 regs->cx = GET_BDA(cursor_type);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400382 struct cursorpos cp = get_cursor_pos(regs->bh);
383 regs->dl = cp.x;
384 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400385}
386
387// Read light pen pos (unimplemented)
388static void
389handle_1004(struct bregs *regs)
390{
391 debug_stub(regs);
392 regs->ax = regs->bx = regs->cx = regs->dx = 0;
393}
394
395static void
396handle_1005(struct bregs *regs)
397{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400398 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400399}
400
401static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400402verify_scroll(struct bregs *regs, int dir)
403{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500404 u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400405 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500406 if (lry >= nbrows)
407 lry = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400408 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500409 if (lrx >= nbcols)
410 lrx = nbcols - 1;
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400411 int wincols = lrx - ulx + 1, winrows = lry - uly + 1;
412 if (wincols <= 0 || winrows <= 0)
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400413 return;
414
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500415 u8 page = GET_BDA(video_page);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400416 int clearlines = regs->al, movelines = winrows - clearlines;
417 if (!clearlines || movelines <= 0) {
418 // Clear whole area.
419 struct cursorpos clr = {ulx, uly, page};
420 struct carattr attr = {' ', regs->bh, 1};
421 struct cursorpos clrsize = {wincols, winrows};
Kevin O'Connor7217ae72014-10-17 21:47:10 -0400422 vgafb_clear_chars(clr, attr, clrsize);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400423 return;
424 }
425
426 if (dir > 0) {
427 // Normal scroll
428 struct cursorpos dest = {ulx, uly, page};
429 struct cursorpos src = {ulx, uly + clearlines, page};
430 struct cursorpos size = {wincols, movelines};
Kevin O'Connor7217ae72014-10-17 21:47:10 -0400431 vgafb_move_chars(dest, src, size);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400432
433 struct cursorpos clr = {ulx, uly + movelines, page};
434 struct carattr attr = {' ', regs->bh, 1};
435 struct cursorpos clrsize = {wincols, clearlines};
Kevin O'Connor7217ae72014-10-17 21:47:10 -0400436 vgafb_clear_chars(clr, attr, clrsize);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400437 } else {
438 // Scroll down
439 struct cursorpos dest = {ulx, uly + clearlines, page};
440 struct cursorpos src = {ulx, uly, page};
441 struct cursorpos size = {wincols, movelines};
Kevin O'Connor7217ae72014-10-17 21:47:10 -0400442 vgafb_move_chars(dest, src, size);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400443
444 struct cursorpos clr = {ulx, uly, page};
445 struct carattr attr = {' ', regs->bh, 1};
446 struct cursorpos clrsize = {wincols, clearlines};
Kevin O'Connor7217ae72014-10-17 21:47:10 -0400447 vgafb_clear_chars(clr, attr, clrsize);
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400448 }
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400449}
450
451static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400452handle_1006(struct bregs *regs)
453{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400454 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400455}
456
457static void
458handle_1007(struct bregs *regs)
459{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400460 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400461}
462
463static void
464handle_1008(struct bregs *regs)
465{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400466 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400467 regs->al = ca.car;
468 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400469}
470
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400471static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400472handle_1009(struct bregs *regs)
473{
Kevin O'Connor09262412009-05-25 11:44:11 -0400474 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500475 struct cursorpos cp = get_cursor_pos(regs->bh);
476 int count = regs->cx;
477 while (count--)
478 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400479}
480
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500481static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400482handle_100a(struct bregs *regs)
483{
Kevin O'Connor09262412009-05-25 11:44:11 -0400484 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500485 struct cursorpos cp = get_cursor_pos(regs->bh);
486 int count = regs->cx;
487 while (count--)
488 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400489}
490
491
492static void
493handle_100b00(struct bregs *regs)
494{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500495 stdvga_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400496}
497
498static void
499handle_100b01(struct bregs *regs)
500{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500501 stdvga_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400502}
503
504static void
505handle_100bXX(struct bregs *regs)
506{
507 debug_stub(regs);
508}
509
510static void
511handle_100b(struct bregs *regs)
512{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500513 if (!CONFIG_VGA_STDVGA_PORTS) {
514 handle_100bXX(regs);
515 return;
516 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400517 switch (regs->bh) {
518 case 0x00: handle_100b00(regs); break;
519 case 0x01: handle_100b01(regs); break;
520 default: handle_100bXX(regs); break;
521 }
522}
523
524
525static void
526handle_100c(struct bregs *regs)
527{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400528 // XXX - page (regs->bh) is unused
529 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400530}
531
532static void
533handle_100d(struct bregs *regs)
534{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400535 // XXX - page (regs->bh) is unused
536 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400537}
538
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400539static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400540handle_100e(struct bregs *regs)
541{
542 // Ralf Brown Interrupt list is WRONG on bh(page)
543 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400544 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor116a0442009-05-26 00:47:32 -0400545 struct cursorpos cp = get_cursor_pos(0xff);
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400546 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400547 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400548}
549
550static void
551handle_100f(struct bregs *regs)
552{
Kevin O'Connore7132042009-05-25 00:10:35 -0400553 regs->bh = GET_BDA(video_page);
554 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
555 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400556}
557
558
559static void
560handle_101000(struct bregs *regs)
561{
562 if (regs->bl > 0x14)
563 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500564 stdvga_attr_write(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400565}
566
567static void
568handle_101001(struct bregs *regs)
569{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500570 stdvga_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400571}
572
573static void
574handle_101002(struct bregs *regs)
575{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500576 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400577}
578
579static void
580handle_101003(struct bregs *regs)
581{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500582 stdvga_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400583}
584
585static void
586handle_101007(struct bregs *regs)
587{
588 if (regs->bl > 0x14)
589 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500590 regs->bh = stdvga_attr_read(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400591}
592
593static void
594handle_101008(struct bregs *regs)
595{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500596 regs->bh = stdvga_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400597}
598
599static void
600handle_101009(struct bregs *regs)
601{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500602 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400603}
604
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400605static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400606handle_101010(struct bregs *regs)
607{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400608 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500609 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400610}
611
612static void
613handle_101012(struct bregs *regs)
614{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500615 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400616}
617
618static void
619handle_101013(struct bregs *regs)
620{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500621 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400622}
623
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400624static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400625handle_101015(struct bregs *regs)
626{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400627 u8 rgb[3];
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500628 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400629 regs->dh = rgb[0];
630 regs->ch = rgb[1];
631 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400632}
633
634static void
635handle_101017(struct bregs *regs)
636{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500637 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400638}
639
640static void
641handle_101018(struct bregs *regs)
642{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500643 stdvga_pelmask_write(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400644}
645
646static void
647handle_101019(struct bregs *regs)
648{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500649 regs->bl = stdvga_pelmask_read();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400650}
651
652static void
653handle_10101a(struct bregs *regs)
654{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500655 stdvga_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400656}
657
658static void
659handle_10101b(struct bregs *regs)
660{
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500661 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400662}
663
664static void
665handle_1010XX(struct bregs *regs)
666{
667 debug_stub(regs);
668}
669
670static void
671handle_1010(struct bregs *regs)
672{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500673 if (!CONFIG_VGA_STDVGA_PORTS) {
674 handle_1010XX(regs);
675 return;
676 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400677 switch (regs->al) {
678 case 0x00: handle_101000(regs); break;
679 case 0x01: handle_101001(regs); break;
680 case 0x02: handle_101002(regs); break;
681 case 0x03: handle_101003(regs); break;
682 case 0x07: handle_101007(regs); break;
683 case 0x08: handle_101008(regs); break;
684 case 0x09: handle_101009(regs); break;
685 case 0x10: handle_101010(regs); break;
686 case 0x12: handle_101012(regs); break;
687 case 0x13: handle_101013(regs); break;
688 case 0x15: handle_101015(regs); break;
689 case 0x17: handle_101017(regs); break;
690 case 0x18: handle_101018(regs); break;
691 case 0x19: handle_101019(regs); break;
692 case 0x1a: handle_10101a(regs); break;
693 case 0x1b: handle_10101b(regs); break;
694 default: handle_1010XX(regs); break;
695 }
696}
697
698
699static void
700handle_101100(struct bregs *regs)
701{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500702 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
703 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400704}
705
706static void
707handle_101101(struct bregs *regs)
708{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500709 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400710}
711
712static void
713handle_101102(struct bregs *regs)
714{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500715 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400716}
717
718static void
719handle_101103(struct bregs *regs)
720{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500721 stdvga_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400722}
723
724static void
725handle_101104(struct bregs *regs)
726{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500727 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400728}
729
730static void
731handle_101110(struct bregs *regs)
732{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500733 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
734 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400735 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400736}
737
738static void
739handle_101111(struct bregs *regs)
740{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500741 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400742 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400743}
744
745static void
746handle_101112(struct bregs *regs)
747{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500748 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400749 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400750}
751
752static void
753handle_101114(struct bregs *regs)
754{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500755 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400756 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400757}
758
759static void
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100760handle_101120(struct bregs *regs)
761{
762 SET_IVT(0x1f, SEGOFF(regs->es, regs->bp));
763}
764
765void
766load_gfx_font(u16 seg, u16 off, u8 height, u8 bl, u8 dl)
767{
768 u8 rows;
769
770 SET_IVT(0x43, SEGOFF(seg, off));
771 switch(bl) {
772 case 0:
773 rows = dl;
774 break;
775 case 1:
776 rows = 14;
777 break;
778 case 3:
779 rows = 43;
780 break;
781 case 2:
782 default:
783 rows = 25;
784 break;
785 }
786 SET_BDA(video_rows, rows - 1);
787 SET_BDA(char_height, height);
788}
789
790static void
791handle_101121(struct bregs *regs)
792{
793 load_gfx_font(regs->es, regs->bp, regs->cx, regs->bl, regs->dl);
794}
795
796static void
797handle_101122(struct bregs *regs)
798{
799 load_gfx_font(get_global_seg(), (u32)vgafont14, 14, regs->bl, regs->dl);
800}
801
802static void
803handle_101123(struct bregs *regs)
804{
805 load_gfx_font(get_global_seg(), (u32)vgafont8, 8, regs->bl, regs->dl);
806}
807
808static void
809handle_101124(struct bregs *regs)
810{
811 load_gfx_font(get_global_seg(), (u32)vgafont16, 16, regs->bl, regs->dl);
812}
813
814static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400815handle_101130(struct bregs *regs)
816{
Kevin O'Connore7132042009-05-25 00:10:35 -0400817 switch (regs->bh) {
818 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500819 struct segoff_s so = GET_IVT(0x1f);
820 regs->es = so.seg;
821 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400822 break;
823 }
824 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500825 struct segoff_s so = GET_IVT(0x43);
826 regs->es = so.seg;
827 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400828 break;
829 }
830 case 0x02:
831 regs->es = get_global_seg();
832 regs->bp = (u32)vgafont14;
833 break;
834 case 0x03:
835 regs->es = get_global_seg();
836 regs->bp = (u32)vgafont8;
837 break;
838 case 0x04:
839 regs->es = get_global_seg();
840 regs->bp = (u32)vgafont8 + 128 * 8;
841 break;
842 case 0x05:
843 regs->es = get_global_seg();
844 regs->bp = (u32)vgafont14alt;
845 break;
846 case 0x06:
847 regs->es = get_global_seg();
848 regs->bp = (u32)vgafont16;
849 break;
850 case 0x07:
851 regs->es = get_global_seg();
852 regs->bp = (u32)vgafont16alt;
853 break;
854 default:
855 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
856 return;
857 }
858 // Set byte/char of on screen font
859 regs->cx = GET_BDA(char_height) & 0xff;
860
861 // Set Highest char row
Kevin O'Connor4c85a262012-02-12 11:50:52 -0500862 regs->dl = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400863}
864
865static void
866handle_1011XX(struct bregs *regs)
867{
868 debug_stub(regs);
869}
870
871static void
872handle_1011(struct bregs *regs)
873{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500874 if (CONFIG_VGA_STDVGA_PORTS) {
875 switch (regs->al) {
Kevin O'Connorc58799c2014-05-28 09:09:05 -0400876 case 0x00: handle_101100(regs); return;
877 case 0x01: handle_101101(regs); return;
878 case 0x02: handle_101102(regs); return;
879 case 0x03: handle_101103(regs); return;
880 case 0x04: handle_101104(regs); return;
881 case 0x10: handle_101110(regs); return;
882 case 0x11: handle_101111(regs); return;
883 case 0x12: handle_101112(regs); return;
884 case 0x14: handle_101114(regs); return;
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500885 }
886 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400887 switch (regs->al) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400888 case 0x30: handle_101130(regs); break;
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100889 case 0x20: handle_101120(regs); break;
890 case 0x21: handle_101121(regs); break;
891 case 0x22: handle_101122(regs); break;
892 case 0x23: handle_101123(regs); break;
893 case 0x24: handle_101124(regs); break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400894 default: handle_1011XX(regs); break;
895 }
896}
897
898
899static void
900handle_101210(struct bregs *regs)
901{
Kevin O'Connore7132042009-05-25 00:10:35 -0400902 u16 crtc_addr = GET_BDA(crtc_address);
903 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
904 regs->bx = 0x0103;
905 else
906 regs->bx = 0x0003;
907 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400908}
909
910static void
911handle_101230(struct bregs *regs)
912{
Kevin O'Connore7132042009-05-25 00:10:35 -0400913 u8 mctl = GET_BDA(modeset_ctl);
914 u8 vswt = GET_BDA(video_switches);
915 switch (regs->al) {
916 case 0x00:
917 // 200 lines
918 mctl = (mctl & ~0x10) | 0x80;
919 vswt = (vswt & ~0x0f) | 0x08;
920 break;
921 case 0x01:
922 // 350 lines
923 mctl &= ~0x90;
924 vswt = (vswt & ~0x0f) | 0x09;
925 break;
926 case 0x02:
927 // 400 lines
928 mctl = (mctl & ~0x80) | 0x10;
929 vswt = (vswt & ~0x0f) | 0x09;
930 break;
931 default:
932 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
933 break;
934 }
935 SET_BDA(modeset_ctl, mctl);
936 SET_BDA(video_switches, vswt);
937 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400938}
939
940static void
941handle_101231(struct bregs *regs)
942{
Kevin O'Connore7132042009-05-25 00:10:35 -0400943 u8 v = (regs->al & 0x01) << 3;
944 u8 mctl = GET_BDA(video_ctl) & ~0x08;
945 SET_BDA(video_ctl, mctl | v);
946 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400947}
948
949static void
950handle_101232(struct bregs *regs)
951{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500952 if (CONFIG_VGA_STDVGA_PORTS) {
953 stdvga_enable_video_addressing(regs->al);
954 regs->al = 0x12;
955 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400956}
957
958static void
959handle_101233(struct bregs *regs)
960{
Kevin O'Connore7132042009-05-25 00:10:35 -0400961 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
962 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
963 SET_BDA(modeset_ctl, v | v2);
964 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400965}
966
967static void
968handle_101234(struct bregs *regs)
969{
Kevin O'Connor479fd722014-10-22 20:27:28 -0400970 SET_BDA(video_ctl, (GET_BDA(video_ctl) & ~0x01) | (regs->al & 0x01));
Kevin O'Connore7132042009-05-25 00:10:35 -0400971 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400972}
973
974static void
975handle_101235(struct bregs *regs)
976{
977 debug_stub(regs);
978 regs->al = 0x12;
979}
980
981static void
982handle_101236(struct bregs *regs)
983{
984 debug_stub(regs);
985 regs->al = 0x12;
986}
987
988static void
989handle_1012XX(struct bregs *regs)
990{
991 debug_stub(regs);
992}
993
994static void
995handle_1012(struct bregs *regs)
996{
Kevin O'Connore91ec7c2012-01-14 16:30:49 -0500997 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
998 clext_1012(regs);
999 return;
1000 }
1001
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001002 switch (regs->bl) {
1003 case 0x10: handle_101210(regs); break;
1004 case 0x30: handle_101230(regs); break;
1005 case 0x31: handle_101231(regs); break;
1006 case 0x32: handle_101232(regs); break;
1007 case 0x33: handle_101233(regs); break;
1008 case 0x34: handle_101234(regs); break;
1009 case 0x35: handle_101235(regs); break;
1010 case 0x36: handle_101236(regs); break;
1011 default: handle_1012XX(regs); break;
1012 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001013}
1014
1015
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001016// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -04001017static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001018handle_1013(struct bregs *regs)
1019{
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001020 struct cursorpos cp;
1021 if (regs->dh == 0xff)
1022 // if row=0xff special case : use current cursor position
1023 cp = get_cursor_pos(regs->bh);
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001024 else
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001025 cp = (struct cursorpos) {regs->dl, regs->dh, regs->bh};
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001026
Kevin O'Connor6ee837b2012-02-13 20:09:02 -05001027 u16 count = regs->cx;
1028 u8 *offset_far = (void*)(regs->bp + 0);
1029 u8 attr = regs->bl;
1030 while (count--) {
1031 u8 car = GET_FARVAR(regs->es, *offset_far);
1032 offset_far++;
1033 if (regs->al & 2) {
1034 attr = GET_FARVAR(regs->es, *offset_far);
1035 offset_far++;
1036 }
1037
1038 struct carattr ca = {car, attr, 1};
1039 write_teletype(&cp, ca);
1040 }
1041
1042 if (regs->al & 1)
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001043 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001044}
1045
1046
1047static void
1048handle_101a00(struct bregs *regs)
1049{
Kevin O'Connore7132042009-05-25 00:10:35 -04001050 regs->bx = GET_BDA(dcc_index);
1051 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001052}
1053
1054static void
1055handle_101a01(struct bregs *regs)
1056{
Kevin O'Connore7132042009-05-25 00:10:35 -04001057 SET_BDA(dcc_index, regs->bl);
1058 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1059 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001060}
1061
1062static void
1063handle_101aXX(struct bregs *regs)
1064{
1065 debug_stub(regs);
1066}
1067
1068static void
1069handle_101a(struct bregs *regs)
1070{
1071 switch (regs->al) {
1072 case 0x00: handle_101a00(regs); break;
1073 case 0x01: handle_101a01(regs); break;
1074 default: handle_101aXX(regs); break;
1075 }
1076}
1077
1078
Kevin O'Connor12900b12014-10-23 16:37:08 -04001079struct video_func_static static_functionality VAR16 = {
1080 .modes = 0x00, // Filled in by stdvga_build_video_param()
Kevin O'Connor63977902014-10-23 16:24:36 -04001081 .scanlines = 0x07, // 200, 350, 400 scan lines
1082 .cblocks = 0x02, // mamimum number of visible charsets in text mode
1083 .active_cblocks = 0x08, // total number of charset blocks in text mode
1084 .misc_flags = 0x0ce7,
Kevin O'Connorefb45232012-01-14 22:55:11 -05001085};
1086
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001087static void
1088handle_101b(struct bregs *regs)
1089{
Kevin O'Connorca668642009-05-21 23:06:08 -04001090 u16 seg = regs->es;
Kevin O'Connor63977902014-10-23 16:24:36 -04001091 struct video_func_info *info = (void*)(regs->di+0);
Kevin O'Connorca668642009-05-21 23:06:08 -04001092 memset_far(seg, info, 0, sizeof(*info));
1093 // Address of static functionality table
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001094 SET_FARVAR(seg, info->static_functionality
Kevin O'Connor63977902014-10-23 16:24:36 -04001095 , SEGOFF(get_global_seg(), (u32)&static_functionality));
Kevin O'Connorca668642009-05-21 23:06:08 -04001096
1097 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001098 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1099 , sizeof(info->bda_0x49));
1100 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1101 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001102
1103 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1104 SET_FARVAR(seg, info->colors, 16);
1105 SET_FARVAR(seg, info->pages, 8);
1106 SET_FARVAR(seg, info->scan_lines, 2);
1107 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001108 regs->al = 0x1B;
1109}
1110
1111
1112static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001113handle_101c(struct bregs *regs)
1114{
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001115 u16 seg = regs->es;
1116 void *data = (void*)(regs->bx+0);
1117 u16 states = regs->cx;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001118 u8 cmd = regs->al;
1119 if (states & ~0x07 || cmd > 2)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001120 goto fail;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001121 int ret = vgahw_save_restore(states | (cmd<<8), seg, data);
1122 if (ret < 0)
1123 goto fail;
1124 if (cmd == 0)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001125 regs->bx = ret / 64;
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001126 regs->al = 0x1c;
1127fail:
1128 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001129}
1130
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001131static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001132handle_10XX(struct bregs *regs)
1133{
1134 debug_stub(regs);
1135}
1136
1137// INT 10h Video Support Service Entry Point
1138void VISIBLE16
1139handle_10(struct bregs *regs)
1140{
1141 debug_enter(regs, DEBUG_VGA_10);
1142 switch (regs->ah) {
1143 case 0x00: handle_1000(regs); break;
1144 case 0x01: handle_1001(regs); break;
1145 case 0x02: handle_1002(regs); break;
1146 case 0x03: handle_1003(regs); break;
1147 case 0x04: handle_1004(regs); break;
1148 case 0x05: handle_1005(regs); break;
1149 case 0x06: handle_1006(regs); break;
1150 case 0x07: handle_1007(regs); break;
1151 case 0x08: handle_1008(regs); break;
1152 case 0x09: handle_1009(regs); break;
1153 case 0x0a: handle_100a(regs); break;
1154 case 0x0b: handle_100b(regs); break;
1155 case 0x0c: handle_100c(regs); break;
1156 case 0x0d: handle_100d(regs); break;
1157 case 0x0e: handle_100e(regs); break;
1158 case 0x0f: handle_100f(regs); break;
1159 case 0x10: handle_1010(regs); break;
1160 case 0x11: handle_1011(regs); break;
1161 case 0x12: handle_1012(regs); break;
1162 case 0x13: handle_1013(regs); break;
1163 case 0x1a: handle_101a(regs); break;
1164 case 0x1b: handle_101b(regs); break;
1165 case 0x1c: handle_101c(regs); break;
1166 case 0x4f: handle_104f(regs); break;
1167 default: handle_10XX(regs); break;
1168 }
1169}