blob: 14efece6087f6675720318c11d9f61059a500db8 [file] [log] [blame]
Kevin O'Connor40401952011-12-31 03:43:12 -05001// Video Bios Extensions handlers
2//
3// Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2001-2008 the LGPL VGABios developers Team
5//
6// This file may be distributed under the terms of the GNU LGPLv3 license.
7
8#include "vgabios.h" // handle_104f
9#include "config.h" // CONFIG_*
10#include "bregs.h" // struct bregs
11#include "vbe.h" // struct vbe_info
12#include "util.h" // dprintf
13#include "biosvar.h" // get_global_set
Kevin O'Connor5108c692011-12-31 19:13:45 -050014#include "vgahw.h" // vgahw_set_mode
Kevin O'Connor40401952011-12-31 03:43:12 -050015
Kevin O'Connor3339c052012-01-13 20:00:35 -050016int VBE_enabled VAR16;
17u32 VBE_total_memory VAR16 = 256 * 1024;
18u32 VBE_capabilities VAR16;
19u32 VBE_framebuffer VAR16;
Kevin O'Connor643290f2012-01-13 22:08:52 -050020u16 VBE_win_granularity VAR16 = 64;
Kevin O'Connor3339c052012-01-13 20:00:35 -050021
Kevin O'Connor40401952011-12-31 03:43:12 -050022static void
23vbe_104f00(struct bregs *regs)
24{
25 u16 seg = regs->es;
26 struct vbe_info *info = (void*)(regs->di+0);
27
28 if (GET_FARVAR(seg, info->signature) == VBE2_SIGNATURE) {
29 dprintf(4, "Get VBE Controller: VBE2 Signature found\n");
30 } else if (GET_FARVAR(seg, info->signature) == VESA_SIGNATURE) {
31 dprintf(4, "Get VBE Controller: VESA Signature found\n");
32 } else {
33 dprintf(4, "Get VBE Controller: Invalid Signature\n");
34 }
35
36 memset_far(seg, info, 0, sizeof(*info));
37
38 SET_FARVAR(seg, info->signature, VESA_SIGNATURE);
39
40 SET_FARVAR(seg, info->version, 0x0200);
41
42 SET_FARVAR(seg, info->oem_string,
43 SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING));
Kevin O'Connor3339c052012-01-13 20:00:35 -050044 SET_FARVAR(seg, info->capabilities, GET_GLOBAL(VBE_capabilities));
Kevin O'Connor40401952011-12-31 03:43:12 -050045
46 /* We generate our mode list in the reserved field of the info block */
Kevin O'Connor34203cd2012-01-09 20:55:31 -050047 u16 *destmode = (void*)info->reserved;
48 SET_FARVAR(seg, info->video_mode, SEGOFF(seg, (u32)destmode));
Kevin O'Connor40401952011-12-31 03:43:12 -050049
50 /* Total memory (in 64 blocks) */
Kevin O'Connor3339c052012-01-13 20:00:35 -050051 SET_FARVAR(seg, info->total_memory
52 , GET_GLOBAL(VBE_total_memory) / (64*1024));
Kevin O'Connor40401952011-12-31 03:43:12 -050053
54 SET_FARVAR(seg, info->oem_vendor_string,
55 SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING));
56 SET_FARVAR(seg, info->oem_product_string,
57 SEGOFF(get_global_seg(), (u32)VBE_PRODUCT_STRING));
58 SET_FARVAR(seg, info->oem_revision_string,
59 SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING));
60
61 /* Fill list of modes */
Kevin O'Connor34203cd2012-01-09 20:55:31 -050062 u16 *last = (void*)&info->reserved[sizeof(info->reserved)];
63 vgahw_list_modes(seg, destmode, last - 1);
Kevin O'Connor40401952011-12-31 03:43:12 -050064
Kevin O'Connor3339c052012-01-13 20:00:35 -050065 regs->ax = 0x004f;
Kevin O'Connor40401952011-12-31 03:43:12 -050066}
67
68static void
69vbe_104f01(struct bregs *regs)
70{
71 u16 seg = regs->es;
72 struct vbe_mode_info *info = (void*)(regs->di+0);
73 u16 mode = regs->cx;
Kevin O'Connor40401952011-12-31 03:43:12 -050074
75 dprintf(1, "VBE mode info request: %x\n", mode);
76
Kevin O'Connor3339c052012-01-13 20:00:35 -050077 struct vgamode_s *vmode_g = vgahw_find_mode(mode);
78 if (! vmode_g) {
Kevin O'Connor40401952011-12-31 03:43:12 -050079 dprintf(1, "VBE mode %x not found\n", mode);
Kevin O'Connor3339c052012-01-13 20:00:35 -050080 regs->ax = 0x0100;
Kevin O'Connor40401952011-12-31 03:43:12 -050081 return;
82 }
83
Kevin O'Connor643290f2012-01-13 22:08:52 -050084 memset_far(seg, info, 0, sizeof(*info));
Kevin O'Connor40401952011-12-31 03:43:12 -050085 u16 mode_attr = VBE_MODE_ATTRIBUTE_SUPPORTED |
86 VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE |
87 VBE_MODE_ATTRIBUTE_COLOR_MODE |
Kevin O'Connor643290f2012-01-13 22:08:52 -050088 VBE_MODE_ATTRIBUTE_GRAPHICS_MODE |
89 VBE_MODE_ATTRIBUTE_NOT_VGA_COMPATIBLE;
90 u32 framebuffer = GET_GLOBAL(VBE_framebuffer);
Kevin O'Connor3339c052012-01-13 20:00:35 -050091 int depth = GET_GLOBAL(vmode_g->depth);
92 if (depth == 4)
Kevin O'Connor40401952011-12-31 03:43:12 -050093 mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT;
Kevin O'Connor643290f2012-01-13 22:08:52 -050094 else if (framebuffer)
Kevin O'Connor40401952011-12-31 03:43:12 -050095 mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE;
96 SET_FARVAR(seg, info->mode_attributes, mode_attr);
97 SET_FARVAR(seg, info->winA_attributes,
98 VBE_WINDOW_ATTRIBUTE_RELOCATABLE |
99 VBE_WINDOW_ATTRIBUTE_READABLE |
100 VBE_WINDOW_ATTRIBUTE_WRITEABLE);
101 SET_FARVAR(seg, info->winB_attributes, 0);
Kevin O'Connor643290f2012-01-13 22:08:52 -0500102 SET_FARVAR(seg, info->win_granularity, GET_GLOBAL(VBE_win_granularity));
Kevin O'Connor40401952011-12-31 03:43:12 -0500103 SET_FARVAR(seg, info->win_size, 64); /* Bank size 64K */
Kevin O'Connor643290f2012-01-13 22:08:52 -0500104 SET_FARVAR(seg, info->winA_seg, SEG_GRAPH);
Kevin O'Connor40401952011-12-31 03:43:12 -0500105 SET_FARVAR(seg, info->winB_seg, 0x0);
106 SET_FARVAR(seg, info->win_func_ptr.segoff, 0x0);
Kevin O'Connor3339c052012-01-13 20:00:35 -0500107 int width = GET_GLOBAL(vmode_g->width);
108 int height = GET_GLOBAL(vmode_g->height);
Kevin O'Connore19a68f2012-01-14 14:52:01 -0500109 int linesize = width * DIV_ROUND_UP(depth, 8);
Kevin O'Connor3339c052012-01-13 20:00:35 -0500110 SET_FARVAR(seg, info->bytes_per_scanline, linesize);
111 SET_FARVAR(seg, info->xres, width);
112 SET_FARVAR(seg, info->yres, height);
Kevin O'Connor40401952011-12-31 03:43:12 -0500113 SET_FARVAR(seg, info->xcharsize, 8);
114 SET_FARVAR(seg, info->ycharsize, 16);
Kevin O'Connor3339c052012-01-13 20:00:35 -0500115 if (depth == 4)
Kevin O'Connor40401952011-12-31 03:43:12 -0500116 SET_FARVAR(seg, info->planes, 4);
117 else
118 SET_FARVAR(seg, info->planes, 1);
Kevin O'Connor3339c052012-01-13 20:00:35 -0500119 SET_FARVAR(seg, info->bits_per_pixel, depth);
Kevin O'Connor643290f2012-01-13 22:08:52 -0500120 SET_FARVAR(seg, info->banks, 1);
121 SET_FARVAR(seg, info->mem_model, GET_GLOBAL(vmode_g->memmodel));
Kevin O'Connor40401952011-12-31 03:43:12 -0500122 SET_FARVAR(seg, info->bank_size, 0);
Kevin O'Connor3339c052012-01-13 20:00:35 -0500123 u32 pages = GET_GLOBAL(VBE_total_memory) / (height * linesize);
124 if (depth == 4)
Kevin O'Connor40401952011-12-31 03:43:12 -0500125 SET_FARVAR(seg, info->pages, (pages / 4) - 1);
126 else
127 SET_FARVAR(seg, info->pages, pages - 1);
128 SET_FARVAR(seg, info->reserved0, 1);
129
130 u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
131
Kevin O'Connor3339c052012-01-13 20:00:35 -0500132 switch (depth) {
Kevin O'Connor40401952011-12-31 03:43:12 -0500133 case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5;
134 b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break;
135 case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5;
136 b_size = 5; b_pos = 0; a_size = 0; a_pos = 0; break;
137 case 24: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
138 b_size = 8; b_pos = 0; a_size = 0; a_pos = 0; break;
139 case 32: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
140 b_size = 8; b_pos = 0; a_size = 8; a_pos = 24; break;
141 default: r_size = 0; r_pos = 0; g_size = 0; g_pos = 0;
142 b_size = 0; b_pos = 0; a_size = 0; a_pos = 0; break;
143 }
144
145 SET_FARVAR(seg, info->red_size, r_size);
146 SET_FARVAR(seg, info->red_pos, r_pos);
147 SET_FARVAR(seg, info->green_size, g_size);
148 SET_FARVAR(seg, info->green_pos, g_pos);
149 SET_FARVAR(seg, info->blue_size, b_size);
150 SET_FARVAR(seg, info->blue_pos, b_pos);
151 SET_FARVAR(seg, info->alpha_size, a_size);
152 SET_FARVAR(seg, info->alpha_pos, a_pos);
153
Kevin O'Connor3339c052012-01-13 20:00:35 -0500154 if (depth == 32)
Kevin O'Connor40401952011-12-31 03:43:12 -0500155 SET_FARVAR(seg, info->directcolor_info,
156 VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE);
157 else
158 SET_FARVAR(seg, info->directcolor_info, 0);
159
Kevin O'Connor3339c052012-01-13 20:00:35 -0500160 if (depth > 4)
161 SET_FARVAR(seg, info->phys_base, GET_GLOBAL(VBE_framebuffer));
Kevin O'Connor40401952011-12-31 03:43:12 -0500162 else
163 SET_FARVAR(seg, info->phys_base, 0);
164
165 SET_FARVAR(seg, info->reserved1, 0);
166 SET_FARVAR(seg, info->reserved2, 0);
Kevin O'Connor3339c052012-01-13 20:00:35 -0500167 SET_FARVAR(seg, info->linear_bytes_per_scanline, linesize);
Kevin O'Connor40401952011-12-31 03:43:12 -0500168 SET_FARVAR(seg, info->bank_pages, 0);
169 SET_FARVAR(seg, info->linear_pages, 0);
170 SET_FARVAR(seg, info->linear_red_size, r_size);
171 SET_FARVAR(seg, info->linear_red_pos, r_pos);
172 SET_FARVAR(seg, info->linear_green_size, g_size);
173 SET_FARVAR(seg, info->linear_green_pos, g_pos);
174 SET_FARVAR(seg, info->linear_blue_size, b_size);
175 SET_FARVAR(seg, info->linear_blue_pos, b_pos);
176 SET_FARVAR(seg, info->linear_alpha_size, a_size);
177 SET_FARVAR(seg, info->linear_alpha_pos, a_pos);
178 SET_FARVAR(seg, info->pixclock_max, 0);
179
Kevin O'Connor3339c052012-01-13 20:00:35 -0500180 regs->ax = 0x004f;
Kevin O'Connor40401952011-12-31 03:43:12 -0500181}
182
183static void
184vbe_104f02(struct bregs *regs)
185{
Kevin O'Connor5108c692011-12-31 19:13:45 -0500186 dprintf(1, "VBE mode set: %x\n", regs->bx);
Kevin O'Connor40401952011-12-31 03:43:12 -0500187
Kevin O'Connor5108c692011-12-31 19:13:45 -0500188 int mode = regs->bx & 0x1ff;
189 int flags = regs->bx & (MF_CUSTOMCRTC|MF_LINEARFB|MF_NOCLEARMEM);
190 int ret = vgahw_set_mode(mode, flags);
Kevin O'Connor40401952011-12-31 03:43:12 -0500191
Kevin O'Connor5108c692011-12-31 19:13:45 -0500192 regs->ah = ret;
193 regs->al = 0x4f;
Kevin O'Connor40401952011-12-31 03:43:12 -0500194}
195
196static void
197vbe_104f03(struct bregs *regs)
198{
Kevin O'Connor3339c052012-01-13 20:00:35 -0500199 u16 mode = GET_BDA(vbe_mode);
200 if (!mode)
Kevin O'Connor40401952011-12-31 03:43:12 -0500201 regs->bx = GET_BDA(video_mode);
Kevin O'Connor40401952011-12-31 03:43:12 -0500202
203 dprintf(1, "VBE current mode=%x\n", regs->bx);
204
Kevin O'Connor3339c052012-01-13 20:00:35 -0500205 regs->ax = 0x004f;
Kevin O'Connor40401952011-12-31 03:43:12 -0500206}
207
208static void
209vbe_104f04(struct bregs *regs)
210{
211 debug_stub(regs);
212 regs->ax = 0x0100;
213}
214
215static void
216vbe_104f05(struct bregs *regs)
217{
218 debug_stub(regs);
219 regs->ax = 0x0100;
220}
221
222static void
223vbe_104f06(struct bregs *regs)
224{
225 debug_stub(regs);
226 regs->ax = 0x0100;
227}
228
229static void
230vbe_104f07(struct bregs *regs)
231{
232 debug_stub(regs);
233 regs->ax = 0x0100;
234}
235
236static void
237vbe_104f08(struct bregs *regs)
238{
239 debug_stub(regs);
240 regs->ax = 0x0100;
241}
242
243static void
244vbe_104f0a(struct bregs *regs)
245{
246 debug_stub(regs);
247 regs->ax = 0x0100;
248}
249
250static void
251vbe_104fXX(struct bregs *regs)
252{
253 debug_stub(regs);
254 regs->ax = 0x0100;
255}
256
257void
258handle_104f(struct bregs *regs)
259{
Kevin O'Connor3339c052012-01-13 20:00:35 -0500260 if (!GET_GLOBAL(VBE_enabled)) {
Kevin O'Connor40401952011-12-31 03:43:12 -0500261 vbe_104fXX(regs);
262 return;
263 }
264
265 switch (regs->al) {
266 case 0x00: vbe_104f00(regs); break;
267 case 0x01: vbe_104f01(regs); break;
268 case 0x02: vbe_104f02(regs); break;
269 case 0x03: vbe_104f03(regs); break;
270 case 0x04: vbe_104f04(regs); break;
271 case 0x05: vbe_104f05(regs); break;
272 case 0x06: vbe_104f06(regs); break;
273 case 0x07: vbe_104f07(regs); break;
274 case 0x08: vbe_104f08(regs); break;
275 case 0x0a: vbe_104f0a(regs); break;
276 default: vbe_104fXX(regs); break;
277 }
278}