blob: 198ee5555584385e19a5ee6db4672f89dd0021a9 [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'Connor2d2fa312013-09-14 21:55:26 -040010#include "config.h" // CONFIG_*
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040011#include "output.h" // dprintf
Kevin O'Connor2e57c812013-09-14 22:29:32 -040012#include "std/vbe.h" // VBE_RETURN_STATUS_FAILED
Kevin O'Connor536129a2016-08-05 10:58:24 -040013#include "std/vga.h" // struct video_func_static
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
Kevin O'Connor0397e802016-08-04 17:53:45 -040017#include "vgafb.h" // vgafb_write_char
Kevin O'Connor2d2fa312013-09-14 21:55:26 -040018#include "vgahw.h" // vgahw_set_mode
Kevin O'Connor2f2ec112016-08-05 11:14:58 -040019#include "vgautil.h" // swcursor_pre_handle10
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040020
Kevin O'Connor227a2bb2009-05-31 22:00:20 -040021
22/****************************************************************
23 * Helper functions
24 ****************************************************************/
25
Kevin O'Connor3876b532012-01-24 00:07:44 -050026// Return the bits per pixel in system memory for a given mode.
27int
28vga_bpp(struct vgamode_s *vmode_g)
29{
30 switch (GET_GLOBAL(vmode_g->memmodel)) {
31 case MM_TEXT:
32 return 16;
33 case MM_PLANAR:
34 return 1;
35 }
36 u8 depth = GET_GLOBAL(vmode_g->depth);
37 if (depth > 8)
38 return ALIGN(depth, 8);
39 return depth;
40}
41
Kevin O'Connor83047be2012-01-07 18:27:19 -050042u16
43calc_page_size(u8 memmodel, u16 width, u16 height)
44{
45 switch (memmodel) {
46 case MM_TEXT:
47 return ALIGN(width * height * 2, 2*1024);
48 case MM_CGA:
49 return 16*1024;
50 default:
51 return ALIGN(width * height / 8, 8*1024);
52 }
53}
54
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040055// Determine cursor shape (taking into account possible cursor scaling)
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -040056u16
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040057get_cursor_shape(void)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040058{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040059 u16 cursor_type = GET_BDA(cursor_type);
Kevin O'Connor479fd722014-10-22 20:27:28 -040060 u8 emulate_cursor = (GET_BDA(video_ctl) & 1) == 0;
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040061 if (!emulate_cursor)
62 return cursor_type;
63 u8 start = (cursor_type >> 8) & 0x3f;
64 u8 end = cursor_type & 0x1f;
Kevin O'Connordd2be772009-05-16 15:41:23 -040065 u16 cheight = GET_BDA(char_height);
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040066 if (cheight <= 8 || end >= 8 || start >= 0x20)
67 return cursor_type;
68 if (end != (start + 1))
69 start = ((start + 1) * cheight / 8) - 1;
70 else
71 start = ((end + 1) * cheight / 8) - 2;
72 end = ((end + 1) * cheight / 8) - 1;
73 return (start << 8) | end;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040074}
75
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040076static void
77set_cursor_shape(u16 cursor_type)
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040078{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -040079 SET_BDA(cursor_type, cursor_type);
80 if (CONFIG_VGA_STDVGA_PORTS)
81 stdvga_set_cursor_shape(get_cursor_shape());
Kevin O'Connor0818e1a2009-05-16 18:00:19 -040082}
83
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040084static void
Kevin O'Connor918b1562009-05-25 11:05:18 -040085set_cursor_pos(struct cursorpos cp)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040086{
Kevin O'Connor13213a22016-07-04 12:31:50 -040087 if (cp.page > 7)
88 // Should not happen...
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040089 return;
90
Kevin O'Connor13213a22016-07-04 12:31:50 -040091 if (cp.page == GET_BDA(video_page)) {
92 // Update cursor in hardware
Kevin O'Connor13213a22016-07-04 12:31:50 -040093 if (CONFIG_VGA_STDVGA_PORTS)
94 stdvga_set_cursor_pos((int)text_address(cp));
95 }
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -040096
Kevin O'Connor13213a22016-07-04 12:31:50 -040097 // Update BIOS cursor pos
98 SET_BDA(cursor_pos[cp.page], (cp.y << 8) | cp.x);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -040099}
100
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -0400101struct cursorpos
Kevin O'Connor918b1562009-05-25 11:05:18 -0400102get_cursor_pos(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400103{
Kevin O'Connorb3036872016-07-04 12:27:38 -0400104 if (page > 7)
105 return (struct cursorpos) { 0, 0, 0 };
Kevin O'Connor918b1562009-05-25 11:05:18 -0400106 u16 xy = GET_BDA(cursor_pos[page]);
Kevin O'Connorb3036872016-07-04 12:27:38 -0400107 return (struct cursorpos) { xy, xy>>8, page };
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400108}
109
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400110static void
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400111set_active_page(u8 page)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400112{
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400113 if (page > 7)
114 return;
115
116 // Get the mode
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500117 struct vgamode_s *vmode_g = get_current_mode();
Kevin O'Connor5727c292009-05-16 17:29:32 -0400118 if (!vmode_g)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400119 return;
120
Kevin O'Connor83047be2012-01-07 18:27:19 -0500121 // Calculate memory address of start of page
Kevin O'Connora02d4182014-04-05 22:48:05 -0400122 struct cursorpos cp = {0, 0, page};
123 int address = (int)text_address(cp);
Kevin O'Connord61fc532012-01-27 20:37:45 -0500124 vgahw_set_displaystart(vmode_g, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400125
126 // And change the BIOS page
Kevin O'Connor83047be2012-01-07 18:27:19 -0500127 SET_BDA(video_pagestart, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400128 SET_BDA(video_page, page);
129
Kevin O'Connora12c2152009-05-13 22:06:16 -0400130 dprintf(1, "Set active page %02x address %04x\n", page, address);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400131
132 // Display the cursor, now the page is active
Kevin O'Connora02d4182014-04-05 22:48:05 -0400133 set_cursor_pos(get_cursor_pos(page));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400134}
135
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400136static void
137set_scan_lines(u8 lines)
138{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500139 stdvga_set_scan_lines(lines);
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400140 SET_BDA(char_height, lines);
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500141 u16 vde = stdvga_get_vde();
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400142 u8 rows = vde / lines;
143 SET_BDA(video_rows, rows - 1);
144 u16 cols = GET_BDA(video_cols);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500145 SET_BDA(video_pagesize, calc_page_size(MM_TEXT, cols, rows));
Kevin O'Connor479fd722014-10-22 20:27:28 -0400146 if (lines == 8)
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400147 set_cursor_shape(0x0607);
Kevin O'Connor479fd722014-10-22 20:27:28 -0400148 else
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400149 set_cursor_shape(((lines - 3) << 8) | (lines - 2));
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400150}
151
152
153/****************************************************************
154 * Character writing
155 ****************************************************************/
156
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500157// Write a character to the screen and calculate new cursor position.
158static void
159write_char(struct cursorpos *pcp, struct carattr ca)
Kevin O'Connor09262412009-05-25 11:44:11 -0400160{
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500161 vgafb_write_char(*pcp, ca);
162 pcp->x++;
163 // Do we need to wrap ?
164 if (pcp->x == GET_BDA(video_cols)) {
165 pcp->x = 0;
166 pcp->y++;
167 }
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400168}
169
170// Write a character to the screen at a given position. Implement
171// special characters and scroll the screen if necessary.
172static void
173write_teletype(struct cursorpos *pcp, struct carattr ca)
174{
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400175 switch (ca.car) {
176 case 7:
177 //FIXME should beep
178 break;
179 case 8:
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500180 if (pcp->x > 0)
181 pcp->x--;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400182 break;
183 case '\r':
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500184 pcp->x = 0;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400185 break;
186 case '\n':
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500187 pcp->y++;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400188 break;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400189 default:
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500190 write_char(pcp, ca);
191 break;
Kevin O'Connor2e86c6a2009-05-31 20:43:06 -0400192 }
193
Kevin O'Connor82221b22009-05-26 00:20:40 -0400194 // Do we need to scroll ?
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500195 u16 nbrows = GET_BDA(video_rows);
196 if (pcp->y > nbrows) {
197 pcp->y--;
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400198
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400199 struct cursorpos win = {0, 0, pcp->page};
200 struct cursorpos winsize = {GET_BDA(video_cols), nbrows+1};
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400201 struct carattr attr = {' ', 0, 0};
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400202 vgafb_scroll(win, winsize, 1, attr);
Kevin O'Connor82221b22009-05-26 00:20:40 -0400203 }
Kevin O'Connor82221b22009-05-26 00:20:40 -0400204}
205
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400206
207/****************************************************************
208 * Save and restore bda state
209 ****************************************************************/
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400210
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500211struct saveBDAstate {
212 u8 bda_0x49[28];
213 u8 bda_0x84[6];
214 u16 vbe_mode;
215 struct segoff_s font0;
216 struct segoff_s font1;
217};
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400218
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500219int
220bda_save_restore(int cmd, u16 seg, void *data)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400221{
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500222 if (!(cmd & SR_BDA))
223 return 0;
224 struct saveBDAstate *info = data;
225 if (cmd & SR_SAVE) {
226 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
227 , sizeof(info->bda_0x49));
228 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
229 , sizeof(info->bda_0x84));
Kevin O'Connor9978d492014-10-17 21:17:48 -0400230 SET_FARVAR(seg, info->vbe_mode, GET_BDA_EXT(vbe_mode));
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500231 SET_FARVAR(seg, info->font0, GET_IVT(0x1f));
232 SET_FARVAR(seg, info->font1, GET_IVT(0x43));
233 }
234 if (cmd & SR_RESTORE) {
235 memcpy_far(SEG_BDA, (void*)0x49, seg, info->bda_0x49
236 , sizeof(info->bda_0x49));
237 memcpy_far(SEG_BDA, (void*)0x84, seg, info->bda_0x84
238 , sizeof(info->bda_0x84));
Kevin O'Connorf7f22632014-10-17 21:37:23 -0400239 u16 vbe_mode = GET_FARVAR(seg, info->vbe_mode);
240 SET_BDA_EXT(vbe_mode, vbe_mode);
Kevin O'Connor18449682015-03-17 10:52:16 -0400241 struct vgamode_s *vmode_g = vgahw_find_mode(vbe_mode & ~MF_VBEFLAGS);
Kevin O'Connorf7f22632014-10-17 21:37:23 -0400242 SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
Kevin O'Connor20dc4192014-02-05 20:52:25 -0500243 SET_IVT(0x1f, GET_FARVAR(seg, info->font0));
244 SET_IVT(0x43, GET_FARVAR(seg, info->font1));
245 }
246 return sizeof(*info);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400247}
248
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500249
250/****************************************************************
251 * Mode setting
252 ****************************************************************/
253
254struct vgamode_s *
255get_current_mode(void)
256{
Kevin O'Connorf7f22632014-10-17 21:37:23 -0400257 return (void*)(GET_BDA_EXT(vgamode_offset)+0);
Kevin O'Connor4a73f932012-01-21 11:08:35 -0500258}
259
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500260// Setup BDA after a mode switch.
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500261int
262vga_set_mode(int mode, int flags)
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400263{
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500264 dprintf(1, "set VGA mode %x\n", mode);
265 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
266 if (!vmode_g)
267 return VBE_RETURN_STATUS_FAILED;
268
269 int ret = vgahw_set_mode(vmode_g, flags);
270 if (ret)
271 return ret;
272
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400273 // Set the BIOS mem
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500274 int width = GET_GLOBAL(vmode_g->width);
275 int height = GET_GLOBAL(vmode_g->height);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500276 u8 memmodel = GET_GLOBAL(vmode_g->memmodel);
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500277 int cheight = GET_GLOBAL(vmode_g->cheight);
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500278 if (mode < 0x100)
279 SET_BDA(video_mode, mode);
280 else
281 SET_BDA(video_mode, 0xff);
Kevin O'Connor9978d492014-10-17 21:17:48 -0400282 SET_BDA_EXT(vbe_mode, mode | (flags & MF_VBEFLAGS));
Kevin O'Connorf7f22632014-10-17 21:37:23 -0400283 SET_BDA_EXT(vgamode_offset, (u32)vmode_g);
Kevin O'Connor3b9b9f22015-04-09 12:24:18 -0400284 if (CONFIG_VGA_ALLOCATE_EXTRA_STACK)
Kevin O'Connor251e2632015-03-17 11:37:25 -0400285 // Disable extra stack if it appears a modern OS is in use.
286 // This works around bugs in some versions of Windows (Vista
287 // and possibly later) when the stack is in the e-segment.
288 MASK_BDA_EXT(flags, BF_EXTRA_STACK
289 , (flags & MF_LEGACY) ? BF_EXTRA_STACK : 0);
Kevin O'Connor83047be2012-01-07 18:27:19 -0500290 if (memmodel == MM_TEXT) {
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500291 SET_BDA(video_cols, width);
292 SET_BDA(video_rows, height-1);
293 SET_BDA(cursor_type, 0x0607);
294 } else {
295 int cwidth = GET_GLOBAL(vmode_g->cwidth);
296 SET_BDA(video_cols, width / cwidth);
297 SET_BDA(video_rows, (height / cheight) - 1);
Kevin O'Connorb4eb6fc2014-10-17 22:15:42 -0400298 SET_BDA(cursor_type, vga_emulate_text() ? 0x0607 : 0x0000);
Kevin O'Connor80da87d2012-01-02 11:13:14 -0500299 }
Kevin O'Connor83047be2012-01-07 18:27:19 -0500300 SET_BDA(video_pagesize, calc_page_size(memmodel, width, height));
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500301 SET_BDA(crtc_address, CONFIG_VGA_STDVGA_PORTS ? stdvga_get_crtc() : 0);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400302 SET_BDA(char_height, cheight);
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500303 SET_BDA(video_ctl, 0x60 | (flags & MF_NOCLEARMEM ? 0x80 : 0x00));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400304 SET_BDA(video_switches, 0xF9);
305 SET_BDA(modeset_ctl, GET_BDA(modeset_ctl) & 0x7f);
Kevin O'Connorcecbc5d2011-12-31 17:24:11 -0500306 int i;
307 for (i=0; i<8; i++)
308 SET_BDA(cursor_pos[i], 0x0000);
309 SET_BDA(video_pagestart, 0x0000);
310 SET_BDA(video_page, 0x00);
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400311
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400312 // Set the ints 0x1F and 0x43
Kevin O'Connor9f985422009-09-09 11:34:39 -0400313 SET_IVT(0x1f, SEGOFF(get_global_seg(), (u32)&vgafont8[128 * 8]));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400314
315 switch (cheight) {
316 case 8:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400317 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont8));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400318 break;
319 case 14:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400320 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont14));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400321 break;
322 case 16:
Kevin O'Connor9f985422009-09-09 11:34:39 -0400323 SET_IVT(0x43, SEGOFF(get_global_seg(), (u32)vgafont16));
Kevin O'Connor85ea07e2009-05-25 09:41:07 -0400324 break;
325 }
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500326
327 return 0;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400328}
329
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500330
331/****************************************************************
332 * VGA int 10 handler
333 ****************************************************************/
334
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400335static void
Julian Pidancet87879e22011-12-19 05:08:00 +0000336handle_1000(struct bregs *regs)
337{
Kevin O'Connor5108c692011-12-31 19:13:45 -0500338 int mode = regs->al & 0x7f;
Kevin O'Connor6ada2282020-07-13 18:50:52 -0400339 int flags = MF_LEGACY | (GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM));
340 if (regs->al & 0x80)
341 flags |= MF_NOCLEARMEM;
Julian Pidancet87879e22011-12-19 05:08:00 +0000342
343 // Set regs->al
344 if (mode > 7)
345 regs->al = 0x20;
346 else if (mode == 6)
347 regs->al = 0x3f;
348 else
349 regs->al = 0x30;
350
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500351 vga_set_mode(mode, flags);
Julian Pidancet87879e22011-12-19 05:08:00 +0000352}
353
354static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400355handle_1001(struct bregs *regs)
356{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400357 set_cursor_shape(regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400358}
359
360static void
361handle_1002(struct bregs *regs)
362{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400363 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
364 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400365}
366
367static void
368handle_1003(struct bregs *regs)
369{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400370 regs->cx = GET_BDA(cursor_type);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400371 struct cursorpos cp = get_cursor_pos(regs->bh);
372 regs->dl = cp.x;
373 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400374}
375
376// Read light pen pos (unimplemented)
377static void
378handle_1004(struct bregs *regs)
379{
380 debug_stub(regs);
381 regs->ax = regs->bx = regs->cx = regs->dx = 0;
382}
383
384static void
385handle_1005(struct bregs *regs)
386{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400387 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400388}
389
390static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400391verify_scroll(struct bregs *regs, int dir)
392{
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400393 // Verify parameters
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500394 u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400395 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500396 if (lry >= nbrows)
397 lry = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400398 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500399 if (lrx >= nbcols)
400 lrx = nbcols - 1;
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400401 int wincols = lrx - ulx + 1, winrows = lry - uly + 1;
402 if (wincols <= 0 || winrows <= 0)
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400403 return;
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400404 int lines = regs->al;
405 if (lines >= winrows)
406 lines = 0;
407 lines *= dir;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400408
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400409 // Scroll (or clear) window
410 struct cursorpos win = {ulx, uly, GET_BDA(video_page)};
411 struct cursorpos winsize = {wincols, winrows};
412 struct carattr attr = {' ', regs->bh, 1};
413 vgafb_scroll(win, winsize, lines, attr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400414}
415
416static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400417handle_1006(struct bregs *regs)
418{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400419 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400420}
421
422static void
423handle_1007(struct bregs *regs)
424{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400425 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400426}
427
428static void
429handle_1008(struct bregs *regs)
430{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400431 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400432 regs->al = ca.car;
433 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400434}
435
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400436static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400437handle_1009(struct bregs *regs)
438{
Kevin O'Connor09262412009-05-25 11:44:11 -0400439 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500440 struct cursorpos cp = get_cursor_pos(regs->bh);
441 int count = regs->cx;
442 while (count--)
443 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400444}
445
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500446static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400447handle_100a(struct bregs *regs)
448{
Kevin O'Connor09262412009-05-25 11:44:11 -0400449 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500450 struct cursorpos cp = get_cursor_pos(regs->bh);
451 int count = regs->cx;
452 while (count--)
453 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400454}
455
456
457static void
458handle_100b00(struct bregs *regs)
459{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500460 stdvga_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400461}
462
463static void
464handle_100b01(struct bregs *regs)
465{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500466 stdvga_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400467}
468
469static void
470handle_100bXX(struct bregs *regs)
471{
472 debug_stub(regs);
473}
474
475static void
476handle_100b(struct bregs *regs)
477{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500478 if (!CONFIG_VGA_STDVGA_PORTS) {
479 handle_100bXX(regs);
480 return;
481 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400482 switch (regs->bh) {
483 case 0x00: handle_100b00(regs); break;
484 case 0x01: handle_100b01(regs); break;
485 default: handle_100bXX(regs); break;
486 }
487}
488
489
490static void
491handle_100c(struct bregs *regs)
492{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400493 // XXX - page (regs->bh) is unused
494 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400495}
496
497static void
498handle_100d(struct bregs *regs)
499{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400500 // XXX - page (regs->bh) is unused
501 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400502}
503
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400504static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400505handle_100e(struct bregs *regs)
506{
507 // Ralf Brown Interrupt list is WRONG on bh(page)
508 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400509 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connorb3036872016-07-04 12:27:38 -0400510 struct cursorpos cp = get_cursor_pos(GET_BDA(video_page));
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400511 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400512 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400513}
514
515static void
516handle_100f(struct bregs *regs)
517{
Kevin O'Connore7132042009-05-25 00:10:35 -0400518 regs->bh = GET_BDA(video_page);
519 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
520 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400521}
522
523
524static void
525handle_101000(struct bregs *regs)
526{
527 if (regs->bl > 0x14)
528 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500529 stdvga_attr_write(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400530}
531
532static void
533handle_101001(struct bregs *regs)
534{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500535 stdvga_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400536}
537
538static void
539handle_101002(struct bregs *regs)
540{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500541 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400542}
543
544static void
545handle_101003(struct bregs *regs)
546{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500547 stdvga_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400548}
549
550static void
551handle_101007(struct bregs *regs)
552{
553 if (regs->bl > 0x14)
554 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500555 regs->bh = stdvga_attr_read(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400556}
557
558static void
559handle_101008(struct bregs *regs)
560{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500561 regs->bh = stdvga_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400562}
563
564static void
565handle_101009(struct bregs *regs)
566{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500567 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400568}
569
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400570static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400571handle_101010(struct bregs *regs)
572{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400573 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500574 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400575}
576
577static void
578handle_101012(struct bregs *regs)
579{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500580 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400581}
582
583static void
584handle_101013(struct bregs *regs)
585{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500586 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400587}
588
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400589static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400590handle_101015(struct bregs *regs)
591{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400592 u8 rgb[3];
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500593 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400594 regs->dh = rgb[0];
595 regs->ch = rgb[1];
596 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400597}
598
599static void
600handle_101017(struct bregs *regs)
601{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500602 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400603}
604
605static void
606handle_101018(struct bregs *regs)
607{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500608 stdvga_pelmask_write(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400609}
610
611static void
612handle_101019(struct bregs *regs)
613{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500614 regs->bl = stdvga_pelmask_read();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400615}
616
617static void
618handle_10101a(struct bregs *regs)
619{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500620 stdvga_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400621}
622
623static void
624handle_10101b(struct bregs *regs)
625{
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500626 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400627}
628
629static void
630handle_1010XX(struct bregs *regs)
631{
632 debug_stub(regs);
633}
634
635static void
636handle_1010(struct bregs *regs)
637{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500638 if (!CONFIG_VGA_STDVGA_PORTS) {
639 handle_1010XX(regs);
640 return;
641 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400642 switch (regs->al) {
643 case 0x00: handle_101000(regs); break;
644 case 0x01: handle_101001(regs); break;
645 case 0x02: handle_101002(regs); break;
646 case 0x03: handle_101003(regs); break;
647 case 0x07: handle_101007(regs); break;
648 case 0x08: handle_101008(regs); break;
649 case 0x09: handle_101009(regs); break;
650 case 0x10: handle_101010(regs); break;
651 case 0x12: handle_101012(regs); break;
652 case 0x13: handle_101013(regs); break;
653 case 0x15: handle_101015(regs); break;
654 case 0x17: handle_101017(regs); break;
655 case 0x18: handle_101018(regs); break;
656 case 0x19: handle_101019(regs); break;
657 case 0x1a: handle_10101a(regs); break;
658 case 0x1b: handle_10101b(regs); break;
659 default: handle_1010XX(regs); break;
660 }
661}
662
663
664static void
665handle_101100(struct bregs *regs)
666{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500667 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
668 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400669}
670
671static void
672handle_101101(struct bregs *regs)
673{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500674 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400675}
676
677static void
678handle_101102(struct bregs *regs)
679{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500680 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400681}
682
683static void
684handle_101103(struct bregs *regs)
685{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500686 stdvga_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400687}
688
689static void
690handle_101104(struct bregs *regs)
691{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500692 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400693}
694
695static void
696handle_101110(struct bregs *regs)
697{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500698 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
699 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400700 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400701}
702
703static void
704handle_101111(struct bregs *regs)
705{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500706 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400707 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400708}
709
710static void
711handle_101112(struct bregs *regs)
712{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500713 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400714 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400715}
716
717static void
718handle_101114(struct bregs *regs)
719{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500720 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400721 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400722}
723
724static void
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100725handle_101120(struct bregs *regs)
726{
727 SET_IVT(0x1f, SEGOFF(regs->es, regs->bp));
728}
729
730void
731load_gfx_font(u16 seg, u16 off, u8 height, u8 bl, u8 dl)
732{
733 u8 rows;
734
735 SET_IVT(0x43, SEGOFF(seg, off));
736 switch(bl) {
737 case 0:
738 rows = dl;
739 break;
740 case 1:
741 rows = 14;
742 break;
743 case 3:
744 rows = 43;
745 break;
746 case 2:
747 default:
748 rows = 25;
749 break;
750 }
751 SET_BDA(video_rows, rows - 1);
752 SET_BDA(char_height, height);
753}
754
755static void
756handle_101121(struct bregs *regs)
757{
758 load_gfx_font(regs->es, regs->bp, regs->cx, regs->bl, regs->dl);
759}
760
761static void
762handle_101122(struct bregs *regs)
763{
764 load_gfx_font(get_global_seg(), (u32)vgafont14, 14, regs->bl, regs->dl);
765}
766
767static void
768handle_101123(struct bregs *regs)
769{
770 load_gfx_font(get_global_seg(), (u32)vgafont8, 8, regs->bl, regs->dl);
771}
772
773static void
774handle_101124(struct bregs *regs)
775{
776 load_gfx_font(get_global_seg(), (u32)vgafont16, 16, regs->bl, regs->dl);
777}
778
779static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400780handle_101130(struct bregs *regs)
781{
Kevin O'Connore7132042009-05-25 00:10:35 -0400782 switch (regs->bh) {
783 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500784 struct segoff_s so = GET_IVT(0x1f);
785 regs->es = so.seg;
786 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400787 break;
788 }
789 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500790 struct segoff_s so = GET_IVT(0x43);
791 regs->es = so.seg;
792 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400793 break;
794 }
795 case 0x02:
796 regs->es = get_global_seg();
797 regs->bp = (u32)vgafont14;
798 break;
799 case 0x03:
800 regs->es = get_global_seg();
801 regs->bp = (u32)vgafont8;
802 break;
803 case 0x04:
804 regs->es = get_global_seg();
805 regs->bp = (u32)vgafont8 + 128 * 8;
806 break;
807 case 0x05:
808 regs->es = get_global_seg();
809 regs->bp = (u32)vgafont14alt;
810 break;
811 case 0x06:
812 regs->es = get_global_seg();
813 regs->bp = (u32)vgafont16;
814 break;
815 case 0x07:
816 regs->es = get_global_seg();
817 regs->bp = (u32)vgafont16alt;
818 break;
819 default:
820 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
821 return;
822 }
823 // Set byte/char of on screen font
824 regs->cx = GET_BDA(char_height) & 0xff;
825
826 // Set Highest char row
Kevin O'Connor4c85a262012-02-12 11:50:52 -0500827 regs->dl = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400828}
829
830static void
831handle_1011XX(struct bregs *regs)
832{
833 debug_stub(regs);
834}
835
836static void
837handle_1011(struct bregs *regs)
838{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500839 if (CONFIG_VGA_STDVGA_PORTS) {
840 switch (regs->al) {
Kevin O'Connorc58799c2014-05-28 09:09:05 -0400841 case 0x00: handle_101100(regs); return;
842 case 0x01: handle_101101(regs); return;
843 case 0x02: handle_101102(regs); return;
844 case 0x03: handle_101103(regs); return;
845 case 0x04: handle_101104(regs); return;
846 case 0x10: handle_101110(regs); return;
847 case 0x11: handle_101111(regs); return;
848 case 0x12: handle_101112(regs); return;
849 case 0x14: handle_101114(regs); return;
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500850 }
851 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400852 switch (regs->al) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400853 case 0x30: handle_101130(regs); break;
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100854 case 0x20: handle_101120(regs); break;
855 case 0x21: handle_101121(regs); break;
856 case 0x22: handle_101122(regs); break;
857 case 0x23: handle_101123(regs); break;
858 case 0x24: handle_101124(regs); break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400859 default: handle_1011XX(regs); break;
860 }
861}
862
863
864static void
865handle_101210(struct bregs *regs)
866{
Kevin O'Connore7132042009-05-25 00:10:35 -0400867 u16 crtc_addr = GET_BDA(crtc_address);
868 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
869 regs->bx = 0x0103;
870 else
871 regs->bx = 0x0003;
872 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400873}
874
875static void
876handle_101230(struct bregs *regs)
877{
Kevin O'Connore7132042009-05-25 00:10:35 -0400878 u8 mctl = GET_BDA(modeset_ctl);
879 u8 vswt = GET_BDA(video_switches);
880 switch (regs->al) {
881 case 0x00:
882 // 200 lines
883 mctl = (mctl & ~0x10) | 0x80;
884 vswt = (vswt & ~0x0f) | 0x08;
885 break;
886 case 0x01:
887 // 350 lines
888 mctl &= ~0x90;
889 vswt = (vswt & ~0x0f) | 0x09;
890 break;
891 case 0x02:
892 // 400 lines
893 mctl = (mctl & ~0x80) | 0x10;
894 vswt = (vswt & ~0x0f) | 0x09;
895 break;
896 default:
897 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
898 break;
899 }
900 SET_BDA(modeset_ctl, mctl);
901 SET_BDA(video_switches, vswt);
902 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400903}
904
905static void
906handle_101231(struct bregs *regs)
907{
Kevin O'Connore7132042009-05-25 00:10:35 -0400908 u8 v = (regs->al & 0x01) << 3;
909 u8 mctl = GET_BDA(video_ctl) & ~0x08;
910 SET_BDA(video_ctl, mctl | v);
911 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400912}
913
914static void
915handle_101232(struct bregs *regs)
916{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500917 if (CONFIG_VGA_STDVGA_PORTS) {
918 stdvga_enable_video_addressing(regs->al);
919 regs->al = 0x12;
920 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400921}
922
923static void
924handle_101233(struct bregs *regs)
925{
Kevin O'Connore7132042009-05-25 00:10:35 -0400926 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
927 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
928 SET_BDA(modeset_ctl, v | v2);
929 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400930}
931
932static void
933handle_101234(struct bregs *regs)
934{
Kevin O'Connor479fd722014-10-22 20:27:28 -0400935 SET_BDA(video_ctl, (GET_BDA(video_ctl) & ~0x01) | (regs->al & 0x01));
Kevin O'Connore7132042009-05-25 00:10:35 -0400936 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400937}
938
939static void
940handle_101235(struct bregs *regs)
941{
942 debug_stub(regs);
943 regs->al = 0x12;
944}
945
946static void
947handle_101236(struct bregs *regs)
948{
949 debug_stub(regs);
950 regs->al = 0x12;
951}
952
953static void
954handle_1012XX(struct bregs *regs)
955{
956 debug_stub(regs);
957}
958
959static void
960handle_1012(struct bregs *regs)
961{
Kevin O'Connore91ec7c2012-01-14 16:30:49 -0500962 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
963 clext_1012(regs);
964 return;
965 }
966
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400967 switch (regs->bl) {
968 case 0x10: handle_101210(regs); break;
969 case 0x30: handle_101230(regs); break;
970 case 0x31: handle_101231(regs); break;
971 case 0x32: handle_101232(regs); break;
972 case 0x33: handle_101233(regs); break;
973 case 0x34: handle_101234(regs); break;
974 case 0x35: handle_101235(regs); break;
975 case 0x36: handle_101236(regs); break;
976 default: handle_1012XX(regs); break;
977 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400978}
979
980
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400981// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400982static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400983handle_1013(struct bregs *regs)
984{
Kevin O'Connore5839ea2016-07-04 12:20:48 -0400985 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500986 u16 count = regs->cx;
987 u8 *offset_far = (void*)(regs->bp + 0);
988 u8 attr = regs->bl;
989 while (count--) {
990 u8 car = GET_FARVAR(regs->es, *offset_far);
991 offset_far++;
992 if (regs->al & 2) {
993 attr = GET_FARVAR(regs->es, *offset_far);
994 offset_far++;
995 }
996
997 struct carattr ca = {car, attr, 1};
998 write_teletype(&cp, ca);
999 }
1000
1001 if (regs->al & 1)
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001002 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001003}
1004
1005
1006static void
1007handle_101a00(struct bregs *regs)
1008{
Kevin O'Connore7132042009-05-25 00:10:35 -04001009 regs->bx = GET_BDA(dcc_index);
1010 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001011}
1012
1013static void
1014handle_101a01(struct bregs *regs)
1015{
Kevin O'Connore7132042009-05-25 00:10:35 -04001016 SET_BDA(dcc_index, regs->bl);
1017 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1018 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001019}
1020
1021static void
1022handle_101aXX(struct bregs *regs)
1023{
1024 debug_stub(regs);
1025}
1026
1027static void
1028handle_101a(struct bregs *regs)
1029{
1030 switch (regs->al) {
1031 case 0x00: handle_101a00(regs); break;
1032 case 0x01: handle_101a01(regs); break;
1033 default: handle_101aXX(regs); break;
1034 }
1035}
1036
1037
Kevin O'Connor12900b12014-10-23 16:37:08 -04001038struct video_func_static static_functionality VAR16 = {
1039 .modes = 0x00, // Filled in by stdvga_build_video_param()
Kevin O'Connor63977902014-10-23 16:24:36 -04001040 .scanlines = 0x07, // 200, 350, 400 scan lines
1041 .cblocks = 0x02, // mamimum number of visible charsets in text mode
1042 .active_cblocks = 0x08, // total number of charset blocks in text mode
1043 .misc_flags = 0x0ce7,
Kevin O'Connorefb45232012-01-14 22:55:11 -05001044};
1045
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001046static void
1047handle_101b(struct bregs *regs)
1048{
Kevin O'Connorca668642009-05-21 23:06:08 -04001049 u16 seg = regs->es;
Kevin O'Connor63977902014-10-23 16:24:36 -04001050 struct video_func_info *info = (void*)(regs->di+0);
Kevin O'Connorca668642009-05-21 23:06:08 -04001051 memset_far(seg, info, 0, sizeof(*info));
1052 // Address of static functionality table
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001053 SET_FARVAR(seg, info->static_functionality
Kevin O'Connor63977902014-10-23 16:24:36 -04001054 , SEGOFF(get_global_seg(), (u32)&static_functionality));
Kevin O'Connorca668642009-05-21 23:06:08 -04001055
1056 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001057 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1058 , sizeof(info->bda_0x49));
1059 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1060 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001061
1062 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1063 SET_FARVAR(seg, info->colors, 16);
1064 SET_FARVAR(seg, info->pages, 8);
1065 SET_FARVAR(seg, info->scan_lines, 2);
1066 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001067 regs->al = 0x1B;
1068}
1069
1070
1071static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001072handle_101c(struct bregs *regs)
1073{
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001074 u16 seg = regs->es;
1075 void *data = (void*)(regs->bx+0);
1076 u16 states = regs->cx;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001077 u8 cmd = regs->al;
1078 if (states & ~0x07 || cmd > 2)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001079 goto fail;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001080 int ret = vgahw_save_restore(states | (cmd<<8), seg, data);
1081 if (ret < 0)
1082 goto fail;
1083 if (cmd == 0)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001084 regs->bx = ret / 64;
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001085 regs->al = 0x1c;
1086fail:
1087 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001088}
1089
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001090static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001091handle_10XX(struct bregs *regs)
1092{
1093 debug_stub(regs);
1094}
1095
1096// INT 10h Video Support Service Entry Point
1097void VISIBLE16
1098handle_10(struct bregs *regs)
1099{
1100 debug_enter(regs, DEBUG_VGA_10);
Kevin O'Connor774f5cd2016-08-04 17:02:16 -04001101 swcursor_pre_handle10(regs);
1102
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001103 switch (regs->ah) {
1104 case 0x00: handle_1000(regs); break;
1105 case 0x01: handle_1001(regs); break;
1106 case 0x02: handle_1002(regs); break;
1107 case 0x03: handle_1003(regs); break;
1108 case 0x04: handle_1004(regs); break;
1109 case 0x05: handle_1005(regs); break;
1110 case 0x06: handle_1006(regs); break;
1111 case 0x07: handle_1007(regs); break;
1112 case 0x08: handle_1008(regs); break;
1113 case 0x09: handle_1009(regs); break;
1114 case 0x0a: handle_100a(regs); break;
1115 case 0x0b: handle_100b(regs); break;
1116 case 0x0c: handle_100c(regs); break;
1117 case 0x0d: handle_100d(regs); break;
1118 case 0x0e: handle_100e(regs); break;
1119 case 0x0f: handle_100f(regs); break;
1120 case 0x10: handle_1010(regs); break;
1121 case 0x11: handle_1011(regs); break;
1122 case 0x12: handle_1012(regs); break;
1123 case 0x13: handle_1013(regs); break;
1124 case 0x1a: handle_101a(regs); break;
1125 case 0x1b: handle_101b(regs); break;
1126 case 0x1c: handle_101c(regs); break;
1127 case 0x4f: handle_104f(regs); break;
1128 default: handle_10XX(regs); break;
1129 }
1130}