blob: 3b9694c69c4bce372467bda059d27ae400154a29 [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;
Julian Pidancet87879e22011-12-19 05:08:00 +0000339
340 // Set regs->al
341 if (mode > 7)
342 regs->al = 0x20;
343 else if (mode == 6)
344 regs->al = 0x3f;
345 else
346 regs->al = 0x30;
347
Kevin O'Connorb7b92932013-03-09 13:04:47 -0500348 int flags = MF_LEGACY | (GET_BDA(modeset_ctl) & (MF_NOPALETTE|MF_GRAYSUM));
Kevin O'Connor5108c692011-12-31 19:13:45 -0500349 if (regs->al & 0x80)
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500350 flags |= MF_NOCLEARMEM;
351
Kevin O'Connore6bc4c12012-01-21 11:26:37 -0500352 vga_set_mode(mode, flags);
Julian Pidancet87879e22011-12-19 05:08:00 +0000353}
354
355static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400356handle_1001(struct bregs *regs)
357{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400358 set_cursor_shape(regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400359}
360
361static void
362handle_1002(struct bregs *regs)
363{
Kevin O'Connor918b1562009-05-25 11:05:18 -0400364 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
365 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400366}
367
368static void
369handle_1003(struct bregs *regs)
370{
Kevin O'Connorc9aecfc2014-10-22 20:57:37 -0400371 regs->cx = GET_BDA(cursor_type);
Kevin O'Connor918b1562009-05-25 11:05:18 -0400372 struct cursorpos cp = get_cursor_pos(regs->bh);
373 regs->dl = cp.x;
374 regs->dh = cp.y;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400375}
376
377// Read light pen pos (unimplemented)
378static void
379handle_1004(struct bregs *regs)
380{
381 debug_stub(regs);
382 regs->ax = regs->bx = regs->cx = regs->dx = 0;
383}
384
385static void
386handle_1005(struct bregs *regs)
387{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400388 set_active_page(regs->al);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400389}
390
391static void
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400392verify_scroll(struct bregs *regs, int dir)
393{
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400394 // Verify parameters
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500395 u8 ulx = regs->cl, uly = regs->ch, lrx = regs->dl, lry = regs->dh;
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400396 u16 nbrows = GET_BDA(video_rows) + 1;
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500397 if (lry >= nbrows)
398 lry = nbrows - 1;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400399 u16 nbcols = GET_BDA(video_cols);
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500400 if (lrx >= nbcols)
401 lrx = nbcols - 1;
Kevin O'Connor7fd2af62014-03-20 21:16:28 -0400402 int wincols = lrx - ulx + 1, winrows = lry - uly + 1;
403 if (wincols <= 0 || winrows <= 0)
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400404 return;
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400405 int lines = regs->al;
406 if (lines >= winrows)
407 lines = 0;
408 lines *= dir;
Kevin O'Connorc3e15872009-05-31 01:37:54 -0400409
Kevin O'Connor09e24ac2016-07-15 10:54:51 -0400410 // Scroll (or clear) window
411 struct cursorpos win = {ulx, uly, GET_BDA(video_page)};
412 struct cursorpos winsize = {wincols, winrows};
413 struct carattr attr = {' ', regs->bh, 1};
414 vgafb_scroll(win, winsize, lines, attr);
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400415}
416
417static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400418handle_1006(struct bregs *regs)
419{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400420 verify_scroll(regs, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400421}
422
423static void
424handle_1007(struct bregs *regs)
425{
Kevin O'Connor217f2bc2009-05-31 00:46:47 -0400426 verify_scroll(regs, -1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400427}
428
429static void
430handle_1008(struct bregs *regs)
431{
Kevin O'Connord3b38152009-05-26 00:05:37 -0400432 struct carattr ca = vgafb_read_char(get_cursor_pos(regs->bh));
Kevin O'Connor09262412009-05-25 11:44:11 -0400433 regs->al = ca.car;
434 regs->ah = ca.attr;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400435}
436
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400437static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400438handle_1009(struct bregs *regs)
439{
Kevin O'Connor09262412009-05-25 11:44:11 -0400440 struct carattr ca = {regs->al, regs->bl, 1};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500441 struct cursorpos cp = get_cursor_pos(regs->bh);
442 int count = regs->cx;
443 while (count--)
444 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400445}
446
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500447static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400448handle_100a(struct bregs *regs)
449{
Kevin O'Connor09262412009-05-25 11:44:11 -0400450 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connor0910dde2014-02-08 16:43:30 -0500451 struct cursorpos cp = get_cursor_pos(regs->bh);
452 int count = regs->cx;
453 while (count--)
454 write_char(&cp, ca);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400455}
456
457
458static void
459handle_100b00(struct bregs *regs)
460{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500461 stdvga_set_border_color(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400462}
463
464static void
465handle_100b01(struct bregs *regs)
466{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500467 stdvga_set_palette(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400468}
469
470static void
471handle_100bXX(struct bregs *regs)
472{
473 debug_stub(regs);
474}
475
476static void
477handle_100b(struct bregs *regs)
478{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500479 if (!CONFIG_VGA_STDVGA_PORTS) {
480 handle_100bXX(regs);
481 return;
482 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400483 switch (regs->bh) {
484 case 0x00: handle_100b00(regs); break;
485 case 0x01: handle_100b01(regs); break;
486 default: handle_100bXX(regs); break;
487 }
488}
489
490
491static void
492handle_100c(struct bregs *regs)
493{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400494 // XXX - page (regs->bh) is unused
495 vgafb_write_pixel(regs->al, regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400496}
497
498static void
499handle_100d(struct bregs *regs)
500{
Kevin O'Connor227a2bb2009-05-31 22:00:20 -0400501 // XXX - page (regs->bh) is unused
502 regs->al = vgafb_read_pixel(regs->cx, regs->dx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400503}
504
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400505static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400506handle_100e(struct bregs *regs)
507{
508 // Ralf Brown Interrupt list is WRONG on bh(page)
509 // We do output only on the current page !
Kevin O'Connor09262412009-05-25 11:44:11 -0400510 struct carattr ca = {regs->al, regs->bl, 0};
Kevin O'Connorb3036872016-07-04 12:27:38 -0400511 struct cursorpos cp = get_cursor_pos(GET_BDA(video_page));
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400512 write_teletype(&cp, ca);
Kevin O'Connor116a0442009-05-26 00:47:32 -0400513 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400514}
515
516static void
517handle_100f(struct bregs *regs)
518{
Kevin O'Connore7132042009-05-25 00:10:35 -0400519 regs->bh = GET_BDA(video_page);
520 regs->al = GET_BDA(video_mode) | (GET_BDA(video_ctl) & 0x80);
521 regs->ah = GET_BDA(video_cols);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400522}
523
524
525static void
526handle_101000(struct bregs *regs)
527{
528 if (regs->bl > 0x14)
529 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500530 stdvga_attr_write(regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400531}
532
533static void
534handle_101001(struct bregs *regs)
535{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500536 stdvga_set_overscan_border_color(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400537}
538
539static void
540handle_101002(struct bregs *regs)
541{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500542 stdvga_set_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400543}
544
545static void
546handle_101003(struct bregs *regs)
547{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500548 stdvga_toggle_intensity(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400549}
550
551static void
552handle_101007(struct bregs *regs)
553{
554 if (regs->bl > 0x14)
555 return;
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500556 regs->bh = stdvga_attr_read(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400557}
558
559static void
560handle_101008(struct bregs *regs)
561{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500562 regs->bh = stdvga_get_overscan_border_color();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400563}
564
565static void
566handle_101009(struct bregs *regs)
567{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500568 stdvga_get_all_palette_reg(regs->es, (u8*)(regs->dx + 0));
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400569}
570
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400571static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400572handle_101010(struct bregs *regs)
573{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400574 u8 rgb[3] = {regs->dh, regs->ch, regs->cl};
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500575 stdvga_dac_write(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400576}
577
578static void
579handle_101012(struct bregs *regs)
580{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500581 stdvga_dac_write(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400582}
583
584static void
585handle_101013(struct bregs *regs)
586{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500587 stdvga_select_video_dac_color_page(regs->bl, regs->bh);
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_101015(struct bregs *regs)
592{
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400593 u8 rgb[3];
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500594 stdvga_dac_read(GET_SEG(SS), rgb, regs->bx, 1);
Kevin O'Connor8bc059e2009-05-17 21:19:36 -0400595 regs->dh = rgb[0];
596 regs->ch = rgb[1];
597 regs->cl = rgb[2];
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400598}
599
600static void
601handle_101017(struct bregs *regs)
602{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500603 stdvga_dac_read(regs->es, (u8*)(regs->dx + 0), regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400604}
605
606static void
607handle_101018(struct bregs *regs)
608{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500609 stdvga_pelmask_write(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400610}
611
612static void
613handle_101019(struct bregs *regs)
614{
Kevin O'Connor3471fdb2012-01-14 19:02:43 -0500615 regs->bl = stdvga_pelmask_read();
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400616}
617
618static void
619handle_10101a(struct bregs *regs)
620{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500621 stdvga_read_video_dac_state(&regs->bl, &regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400622}
623
624static void
625handle_10101b(struct bregs *regs)
626{
Kevin O'Connor821d6b42011-12-31 18:19:22 -0500627 stdvga_perform_gray_scale_summing(regs->bx, regs->cx);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400628}
629
630static void
631handle_1010XX(struct bregs *regs)
632{
633 debug_stub(regs);
634}
635
636static void
637handle_1010(struct bregs *regs)
638{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500639 if (!CONFIG_VGA_STDVGA_PORTS) {
640 handle_1010XX(regs);
641 return;
642 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400643 switch (regs->al) {
644 case 0x00: handle_101000(regs); break;
645 case 0x01: handle_101001(regs); break;
646 case 0x02: handle_101002(regs); break;
647 case 0x03: handle_101003(regs); break;
648 case 0x07: handle_101007(regs); break;
649 case 0x08: handle_101008(regs); break;
650 case 0x09: handle_101009(regs); break;
651 case 0x10: handle_101010(regs); break;
652 case 0x12: handle_101012(regs); break;
653 case 0x13: handle_101013(regs); break;
654 case 0x15: handle_101015(regs); break;
655 case 0x17: handle_101017(regs); break;
656 case 0x18: handle_101018(regs); break;
657 case 0x19: handle_101019(regs); break;
658 case 0x1a: handle_10101a(regs); break;
659 case 0x1b: handle_10101b(regs); break;
660 default: handle_1010XX(regs); break;
661 }
662}
663
664
665static void
666handle_101100(struct bregs *regs)
667{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500668 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
669 , regs->dx, regs->bl, regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400670}
671
672static void
673handle_101101(struct bregs *regs)
674{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500675 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400676}
677
678static void
679handle_101102(struct bregs *regs)
680{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500681 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400682}
683
684static void
685handle_101103(struct bregs *regs)
686{
Kevin O'Connor88ca7412011-12-31 04:24:20 -0500687 stdvga_set_text_block_specifier(regs->bl);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400688}
689
690static void
691handle_101104(struct bregs *regs)
692{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500693 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400694}
695
696static void
697handle_101110(struct bregs *regs)
698{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500699 stdvga_load_font(regs->es, (void*)(regs->bp+0), regs->cx
700 , regs->dx, regs->bl, regs->bh);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400701 set_scan_lines(regs->bh);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400702}
703
704static void
705handle_101111(struct bregs *regs)
706{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500707 stdvga_load_font(get_global_seg(), vgafont14, 0x100, 0, regs->bl, 14);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400708 set_scan_lines(14);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400709}
710
711static void
712handle_101112(struct bregs *regs)
713{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500714 stdvga_load_font(get_global_seg(), vgafont8, 0x100, 0, regs->bl, 8);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400715 set_scan_lines(8);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400716}
717
718static void
719handle_101114(struct bregs *regs)
720{
Kevin O'Connor2bec7d62011-12-31 04:31:16 -0500721 stdvga_load_font(get_global_seg(), vgafont16, 0x100, 0, regs->bl, 16);
Kevin O'Connorc0c7df62009-05-17 18:11:33 -0400722 set_scan_lines(16);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400723}
724
725static void
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100726handle_101120(struct bregs *regs)
727{
728 SET_IVT(0x1f, SEGOFF(regs->es, regs->bp));
729}
730
731void
732load_gfx_font(u16 seg, u16 off, u8 height, u8 bl, u8 dl)
733{
734 u8 rows;
735
736 SET_IVT(0x43, SEGOFF(seg, off));
737 switch(bl) {
738 case 0:
739 rows = dl;
740 break;
741 case 1:
742 rows = 14;
743 break;
744 case 3:
745 rows = 43;
746 break;
747 case 2:
748 default:
749 rows = 25;
750 break;
751 }
752 SET_BDA(video_rows, rows - 1);
753 SET_BDA(char_height, height);
754}
755
756static void
757handle_101121(struct bregs *regs)
758{
759 load_gfx_font(regs->es, regs->bp, regs->cx, regs->bl, regs->dl);
760}
761
762static void
763handle_101122(struct bregs *regs)
764{
765 load_gfx_font(get_global_seg(), (u32)vgafont14, 14, regs->bl, regs->dl);
766}
767
768static void
769handle_101123(struct bregs *regs)
770{
771 load_gfx_font(get_global_seg(), (u32)vgafont8, 8, regs->bl, regs->dl);
772}
773
774static void
775handle_101124(struct bregs *regs)
776{
777 load_gfx_font(get_global_seg(), (u32)vgafont16, 16, regs->bl, regs->dl);
778}
779
780static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400781handle_101130(struct bregs *regs)
782{
Kevin O'Connore7132042009-05-25 00:10:35 -0400783 switch (regs->bh) {
784 case 0x00: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500785 struct segoff_s so = GET_IVT(0x1f);
786 regs->es = so.seg;
787 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400788 break;
789 }
790 case 0x01: {
Kevin O'Connorc9d3c2d2010-01-01 12:53:32 -0500791 struct segoff_s so = GET_IVT(0x43);
792 regs->es = so.seg;
793 regs->bp = so.offset;
Kevin O'Connore7132042009-05-25 00:10:35 -0400794 break;
795 }
796 case 0x02:
797 regs->es = get_global_seg();
798 regs->bp = (u32)vgafont14;
799 break;
800 case 0x03:
801 regs->es = get_global_seg();
802 regs->bp = (u32)vgafont8;
803 break;
804 case 0x04:
805 regs->es = get_global_seg();
806 regs->bp = (u32)vgafont8 + 128 * 8;
807 break;
808 case 0x05:
809 regs->es = get_global_seg();
810 regs->bp = (u32)vgafont14alt;
811 break;
812 case 0x06:
813 regs->es = get_global_seg();
814 regs->bp = (u32)vgafont16;
815 break;
816 case 0x07:
817 regs->es = get_global_seg();
818 regs->bp = (u32)vgafont16alt;
819 break;
820 default:
821 dprintf(1, "Get font info BH(%02x) was discarded\n", regs->bh);
822 return;
823 }
824 // Set byte/char of on screen font
825 regs->cx = GET_BDA(char_height) & 0xff;
826
827 // Set Highest char row
Kevin O'Connor4c85a262012-02-12 11:50:52 -0500828 regs->dl = GET_BDA(video_rows);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400829}
830
831static void
832handle_1011XX(struct bregs *regs)
833{
834 debug_stub(regs);
835}
836
837static void
838handle_1011(struct bregs *regs)
839{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500840 if (CONFIG_VGA_STDVGA_PORTS) {
841 switch (regs->al) {
Kevin O'Connorc58799c2014-05-28 09:09:05 -0400842 case 0x00: handle_101100(regs); return;
843 case 0x01: handle_101101(regs); return;
844 case 0x02: handle_101102(regs); return;
845 case 0x03: handle_101103(regs); return;
846 case 0x04: handle_101104(regs); return;
847 case 0x10: handle_101110(regs); return;
848 case 0x11: handle_101111(regs); return;
849 case 0x12: handle_101112(regs); return;
850 case 0x14: handle_101114(regs); return;
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500851 }
852 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400853 switch (regs->al) {
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400854 case 0x30: handle_101130(regs); break;
Paolo Bonzini4bd8aeb2013-01-10 13:41:36 +0100855 case 0x20: handle_101120(regs); break;
856 case 0x21: handle_101121(regs); break;
857 case 0x22: handle_101122(regs); break;
858 case 0x23: handle_101123(regs); break;
859 case 0x24: handle_101124(regs); break;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400860 default: handle_1011XX(regs); break;
861 }
862}
863
864
865static void
866handle_101210(struct bregs *regs)
867{
Kevin O'Connore7132042009-05-25 00:10:35 -0400868 u16 crtc_addr = GET_BDA(crtc_address);
869 if (crtc_addr == VGAREG_MDA_CRTC_ADDRESS)
870 regs->bx = 0x0103;
871 else
872 regs->bx = 0x0003;
873 regs->cx = GET_BDA(video_switches) & 0x0f;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400874}
875
876static void
877handle_101230(struct bregs *regs)
878{
Kevin O'Connore7132042009-05-25 00:10:35 -0400879 u8 mctl = GET_BDA(modeset_ctl);
880 u8 vswt = GET_BDA(video_switches);
881 switch (regs->al) {
882 case 0x00:
883 // 200 lines
884 mctl = (mctl & ~0x10) | 0x80;
885 vswt = (vswt & ~0x0f) | 0x08;
886 break;
887 case 0x01:
888 // 350 lines
889 mctl &= ~0x90;
890 vswt = (vswt & ~0x0f) | 0x09;
891 break;
892 case 0x02:
893 // 400 lines
894 mctl = (mctl & ~0x80) | 0x10;
895 vswt = (vswt & ~0x0f) | 0x09;
896 break;
897 default:
898 dprintf(1, "Select vert res (%02x) was discarded\n", regs->al);
899 break;
900 }
901 SET_BDA(modeset_ctl, mctl);
902 SET_BDA(video_switches, vswt);
903 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400904}
905
906static void
907handle_101231(struct bregs *regs)
908{
Kevin O'Connore7132042009-05-25 00:10:35 -0400909 u8 v = (regs->al & 0x01) << 3;
910 u8 mctl = GET_BDA(video_ctl) & ~0x08;
911 SET_BDA(video_ctl, mctl | v);
912 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400913}
914
915static void
916handle_101232(struct bregs *regs)
917{
Kevin O'Connorefbf4d62014-02-09 11:50:21 -0500918 if (CONFIG_VGA_STDVGA_PORTS) {
919 stdvga_enable_video_addressing(regs->al);
920 regs->al = 0x12;
921 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400922}
923
924static void
925handle_101233(struct bregs *regs)
926{
Kevin O'Connore7132042009-05-25 00:10:35 -0400927 u8 v = ((regs->al << 1) & 0x02) ^ 0x02;
928 u8 v2 = GET_BDA(modeset_ctl) & ~0x02;
929 SET_BDA(modeset_ctl, v | v2);
930 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400931}
932
933static void
934handle_101234(struct bregs *regs)
935{
Kevin O'Connor479fd722014-10-22 20:27:28 -0400936 SET_BDA(video_ctl, (GET_BDA(video_ctl) & ~0x01) | (regs->al & 0x01));
Kevin O'Connore7132042009-05-25 00:10:35 -0400937 regs->al = 0x12;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400938}
939
940static void
941handle_101235(struct bregs *regs)
942{
943 debug_stub(regs);
944 regs->al = 0x12;
945}
946
947static void
948handle_101236(struct bregs *regs)
949{
950 debug_stub(regs);
951 regs->al = 0x12;
952}
953
954static void
955handle_1012XX(struct bregs *regs)
956{
957 debug_stub(regs);
958}
959
960static void
961handle_1012(struct bregs *regs)
962{
Kevin O'Connore91ec7c2012-01-14 16:30:49 -0500963 if (CONFIG_VGA_CIRRUS && regs->bl >= 0x80) {
964 clext_1012(regs);
965 return;
966 }
967
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400968 switch (regs->bl) {
969 case 0x10: handle_101210(regs); break;
970 case 0x30: handle_101230(regs); break;
971 case 0x31: handle_101231(regs); break;
972 case 0x32: handle_101232(regs); break;
973 case 0x33: handle_101233(regs); break;
974 case 0x34: handle_101234(regs); break;
975 case 0x35: handle_101235(regs); break;
976 case 0x36: handle_101236(regs); break;
977 default: handle_1012XX(regs); break;
978 }
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400979}
980
981
Kevin O'Connorafb287d2009-05-31 21:15:33 -0400982// Write string
Kevin O'Connor0ad77f02009-05-31 20:46:43 -0400983static void noinline
Kevin O'Connor1f2c3072009-05-06 23:35:59 -0400984handle_1013(struct bregs *regs)
985{
Kevin O'Connore5839ea2016-07-04 12:20:48 -0400986 struct cursorpos cp = {regs->dl, regs->dh, regs->bh};
Kevin O'Connor6ee837b2012-02-13 20:09:02 -0500987 u16 count = regs->cx;
988 u8 *offset_far = (void*)(regs->bp + 0);
989 u8 attr = regs->bl;
990 while (count--) {
991 u8 car = GET_FARVAR(regs->es, *offset_far);
992 offset_far++;
993 if (regs->al & 2) {
994 attr = GET_FARVAR(regs->es, *offset_far);
995 offset_far++;
996 }
997
998 struct carattr ca = {car, attr, 1};
999 write_teletype(&cp, ca);
1000 }
1001
1002 if (regs->al & 1)
Kevin O'Connorafb287d2009-05-31 21:15:33 -04001003 set_cursor_pos(cp);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001004}
1005
1006
1007static void
1008handle_101a00(struct bregs *regs)
1009{
Kevin O'Connore7132042009-05-25 00:10:35 -04001010 regs->bx = GET_BDA(dcc_index);
1011 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001012}
1013
1014static void
1015handle_101a01(struct bregs *regs)
1016{
Kevin O'Connore7132042009-05-25 00:10:35 -04001017 SET_BDA(dcc_index, regs->bl);
1018 dprintf(1, "Alternate Display code (%02x) was discarded\n", regs->bh);
1019 regs->al = 0x1a;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001020}
1021
1022static void
1023handle_101aXX(struct bregs *regs)
1024{
1025 debug_stub(regs);
1026}
1027
1028static void
1029handle_101a(struct bregs *regs)
1030{
1031 switch (regs->al) {
1032 case 0x00: handle_101a00(regs); break;
1033 case 0x01: handle_101a01(regs); break;
1034 default: handle_101aXX(regs); break;
1035 }
1036}
1037
1038
Kevin O'Connor12900b12014-10-23 16:37:08 -04001039struct video_func_static static_functionality VAR16 = {
1040 .modes = 0x00, // Filled in by stdvga_build_video_param()
Kevin O'Connor63977902014-10-23 16:24:36 -04001041 .scanlines = 0x07, // 200, 350, 400 scan lines
1042 .cblocks = 0x02, // mamimum number of visible charsets in text mode
1043 .active_cblocks = 0x08, // total number of charset blocks in text mode
1044 .misc_flags = 0x0ce7,
Kevin O'Connorefb45232012-01-14 22:55:11 -05001045};
1046
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001047static void
1048handle_101b(struct bregs *regs)
1049{
Kevin O'Connorca668642009-05-21 23:06:08 -04001050 u16 seg = regs->es;
Kevin O'Connor63977902014-10-23 16:24:36 -04001051 struct video_func_info *info = (void*)(regs->di+0);
Kevin O'Connorca668642009-05-21 23:06:08 -04001052 memset_far(seg, info, 0, sizeof(*info));
1053 // Address of static functionality table
Kevin O'Connor87dfad32011-12-23 21:18:49 -05001054 SET_FARVAR(seg, info->static_functionality
Kevin O'Connor63977902014-10-23 16:24:36 -04001055 , SEGOFF(get_global_seg(), (u32)&static_functionality));
Kevin O'Connorca668642009-05-21 23:06:08 -04001056
1057 // Hard coded copy from BIOS area. Should it be cleaner ?
Kevin O'Connor9f985422009-09-09 11:34:39 -04001058 memcpy_far(seg, info->bda_0x49, SEG_BDA, (void*)0x49
1059 , sizeof(info->bda_0x49));
1060 memcpy_far(seg, info->bda_0x84, SEG_BDA, (void*)0x84
1061 , sizeof(info->bda_0x84));
Kevin O'Connorca668642009-05-21 23:06:08 -04001062
1063 SET_FARVAR(seg, info->dcc_index, GET_BDA(dcc_index));
1064 SET_FARVAR(seg, info->colors, 16);
1065 SET_FARVAR(seg, info->pages, 8);
1066 SET_FARVAR(seg, info->scan_lines, 2);
1067 SET_FARVAR(seg, info->video_mem, 3);
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001068 regs->al = 0x1B;
1069}
1070
1071
1072static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001073handle_101c(struct bregs *regs)
1074{
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001075 u16 seg = regs->es;
1076 void *data = (void*)(regs->bx+0);
1077 u16 states = regs->cx;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001078 u8 cmd = regs->al;
1079 if (states & ~0x07 || cmd > 2)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001080 goto fail;
Kevin O'Connor20dc4192014-02-05 20:52:25 -05001081 int ret = vgahw_save_restore(states | (cmd<<8), seg, data);
1082 if (ret < 0)
1083 goto fail;
1084 if (cmd == 0)
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001085 regs->bx = ret / 64;
Kevin O'Connor9f857fc2012-02-04 11:59:02 -05001086 regs->al = 0x1c;
1087fail:
1088 return;
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001089}
1090
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001091static void
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001092handle_10XX(struct bregs *regs)
1093{
1094 debug_stub(regs);
1095}
1096
1097// INT 10h Video Support Service Entry Point
1098void VISIBLE16
1099handle_10(struct bregs *regs)
1100{
1101 debug_enter(regs, DEBUG_VGA_10);
Kevin O'Connor774f5cd2016-08-04 17:02:16 -04001102 swcursor_pre_handle10(regs);
1103
Kevin O'Connor1f2c3072009-05-06 23:35:59 -04001104 switch (regs->ah) {
1105 case 0x00: handle_1000(regs); break;
1106 case 0x01: handle_1001(regs); break;
1107 case 0x02: handle_1002(regs); break;
1108 case 0x03: handle_1003(regs); break;
1109 case 0x04: handle_1004(regs); break;
1110 case 0x05: handle_1005(regs); break;
1111 case 0x06: handle_1006(regs); break;
1112 case 0x07: handle_1007(regs); break;
1113 case 0x08: handle_1008(regs); break;
1114 case 0x09: handle_1009(regs); break;
1115 case 0x0a: handle_100a(regs); break;
1116 case 0x0b: handle_100b(regs); break;
1117 case 0x0c: handle_100c(regs); break;
1118 case 0x0d: handle_100d(regs); break;
1119 case 0x0e: handle_100e(regs); break;
1120 case 0x0f: handle_100f(regs); break;
1121 case 0x10: handle_1010(regs); break;
1122 case 0x11: handle_1011(regs); break;
1123 case 0x12: handle_1012(regs); break;
1124 case 0x13: handle_1013(regs); break;
1125 case 0x1a: handle_101a(regs); break;
1126 case 0x1b: handle_101b(regs); break;
1127 case 0x1c: handle_101c(regs); break;
1128 case 0x4f: handle_104f(regs); break;
1129 default: handle_10XX(regs); break;
1130 }
1131}