blob: 8256cae4ce91f2564044a8f6ebcff6a80e2ae574 [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 "bochsvga.h" // bochsvga_hires_enabled
15#include "vgahw.h" // vgahw_set_mode
Kevin O'Connor40401952011-12-31 03:43:12 -050016
17static void
18vbe_104f00(struct bregs *regs)
19{
20 u16 seg = regs->es;
21 struct vbe_info *info = (void*)(regs->di+0);
22
23 if (GET_FARVAR(seg, info->signature) == VBE2_SIGNATURE) {
24 dprintf(4, "Get VBE Controller: VBE2 Signature found\n");
25 } else if (GET_FARVAR(seg, info->signature) == VESA_SIGNATURE) {
26 dprintf(4, "Get VBE Controller: VESA Signature found\n");
27 } else {
28 dprintf(4, "Get VBE Controller: Invalid Signature\n");
29 }
30
31 memset_far(seg, info, 0, sizeof(*info));
32
33 SET_FARVAR(seg, info->signature, VESA_SIGNATURE);
34
35 SET_FARVAR(seg, info->version, 0x0200);
36
37 SET_FARVAR(seg, info->oem_string,
38 SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING));
39 SET_FARVAR(seg, info->capabilities, 0x1); /* 8BIT DAC */
40
41 /* We generate our mode list in the reserved field of the info block */
42 SET_FARVAR(seg, info->video_mode, SEGOFF(seg, regs->di + 34));
43
44 /* Total memory (in 64 blocks) */
45 SET_FARVAR(seg, info->total_memory, bochsvga_total_mem());
46
47 SET_FARVAR(seg, info->oem_vendor_string,
48 SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING));
49 SET_FARVAR(seg, info->oem_product_string,
50 SEGOFF(get_global_seg(), (u32)VBE_PRODUCT_STRING));
51 SET_FARVAR(seg, info->oem_revision_string,
52 SEGOFF(get_global_seg(), (u32)VBE_REVISION_STRING));
53
54 /* Fill list of modes */
55 bochsvga_list_modes(seg, regs->di + 32);
56
57 regs->al = regs->ah; /* 0x4F, Function supported */
58 regs->ah = 0x0; /* 0x0, Function call successful */
59}
60
61static void
62vbe_104f01(struct bregs *regs)
63{
64 u16 seg = regs->es;
65 struct vbe_mode_info *info = (void*)(regs->di+0);
66 u16 mode = regs->cx;
67 struct vbe_modeinfo modeinfo;
68 int rc;
69
70 dprintf(1, "VBE mode info request: %x\n", mode);
71
72 rc = bochsvga_mode_info(mode, &modeinfo);
73 if (rc) {
74 dprintf(1, "VBE mode %x not found\n", mode);
75 regs->ax = 0x100;
76 return;
77 }
78
79 u16 mode_attr = VBE_MODE_ATTRIBUTE_SUPPORTED |
80 VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE |
81 VBE_MODE_ATTRIBUTE_COLOR_MODE |
82 VBE_MODE_ATTRIBUTE_GRAPHICS_MODE;
83 if (modeinfo.depth == 4)
84 mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT;
85 else
86 mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE;
87 SET_FARVAR(seg, info->mode_attributes, mode_attr);
88 SET_FARVAR(seg, info->winA_attributes,
89 VBE_WINDOW_ATTRIBUTE_RELOCATABLE |
90 VBE_WINDOW_ATTRIBUTE_READABLE |
91 VBE_WINDOW_ATTRIBUTE_WRITEABLE);
92 SET_FARVAR(seg, info->winB_attributes, 0);
93 SET_FARVAR(seg, info->win_granularity, 64); /* Bank size 64K */
94 SET_FARVAR(seg, info->win_size, 64); /* Bank size 64K */
95 SET_FARVAR(seg, info->winA_seg, 0xA000);
96 SET_FARVAR(seg, info->winB_seg, 0x0);
97 SET_FARVAR(seg, info->win_func_ptr.segoff, 0x0);
98 SET_FARVAR(seg, info->bytes_per_scanline, modeinfo.linesize);
99 SET_FARVAR(seg, info->xres, modeinfo.width);
100 SET_FARVAR(seg, info->yres, modeinfo.height);
101 SET_FARVAR(seg, info->xcharsize, 8);
102 SET_FARVAR(seg, info->ycharsize, 16);
103 if (modeinfo.depth == 4)
104 SET_FARVAR(seg, info->planes, 4);
105 else
106 SET_FARVAR(seg, info->planes, 1);
107 SET_FARVAR(seg, info->bits_per_pixel, modeinfo.depth);
108 SET_FARVAR(seg, info->banks,
109 (modeinfo.linesize * modeinfo.height + 65535) / 65536);
110 if (modeinfo.depth == 4)
111 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PLANAR);
112 else if (modeinfo.depth == 8)
113 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PACKED_PIXEL);
114 else
115 SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_DIRECT_COLOR);
116 SET_FARVAR(seg, info->bank_size, 0);
117 u32 pages = modeinfo.vram_size / (modeinfo.height * modeinfo.linesize);
118 if (modeinfo.depth == 4)
119 SET_FARVAR(seg, info->pages, (pages / 4) - 1);
120 else
121 SET_FARVAR(seg, info->pages, pages - 1);
122 SET_FARVAR(seg, info->reserved0, 1);
123
124 u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
125
126 switch (modeinfo.depth) {
127 case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5;
128 b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break;
129 case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5;
130 b_size = 5; b_pos = 0; a_size = 0; a_pos = 0; break;
131 case 24: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
132 b_size = 8; b_pos = 0; a_size = 0; a_pos = 0; break;
133 case 32: r_size = 8; r_pos = 16; g_size = 8; g_pos = 8;
134 b_size = 8; b_pos = 0; a_size = 8; a_pos = 24; break;
135 default: r_size = 0; r_pos = 0; g_size = 0; g_pos = 0;
136 b_size = 0; b_pos = 0; a_size = 0; a_pos = 0; break;
137 }
138
139 SET_FARVAR(seg, info->red_size, r_size);
140 SET_FARVAR(seg, info->red_pos, r_pos);
141 SET_FARVAR(seg, info->green_size, g_size);
142 SET_FARVAR(seg, info->green_pos, g_pos);
143 SET_FARVAR(seg, info->blue_size, b_size);
144 SET_FARVAR(seg, info->blue_pos, b_pos);
145 SET_FARVAR(seg, info->alpha_size, a_size);
146 SET_FARVAR(seg, info->alpha_pos, a_pos);
147
148 if (modeinfo.depth == 32)
149 SET_FARVAR(seg, info->directcolor_info,
150 VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE);
151 else
152 SET_FARVAR(seg, info->directcolor_info, 0);
153
154 if (modeinfo.depth > 4)
155 SET_FARVAR(seg, info->phys_base, modeinfo.phys_base);
156 else
157 SET_FARVAR(seg, info->phys_base, 0);
158
159 SET_FARVAR(seg, info->reserved1, 0);
160 SET_FARVAR(seg, info->reserved2, 0);
161 SET_FARVAR(seg, info->linear_bytes_per_scanline, modeinfo.linesize);
162 SET_FARVAR(seg, info->bank_pages, 0);
163 SET_FARVAR(seg, info->linear_pages, 0);
164 SET_FARVAR(seg, info->linear_red_size, r_size);
165 SET_FARVAR(seg, info->linear_red_pos, r_pos);
166 SET_FARVAR(seg, info->linear_green_size, g_size);
167 SET_FARVAR(seg, info->linear_green_pos, g_pos);
168 SET_FARVAR(seg, info->linear_blue_size, b_size);
169 SET_FARVAR(seg, info->linear_blue_pos, b_pos);
170 SET_FARVAR(seg, info->linear_alpha_size, a_size);
171 SET_FARVAR(seg, info->linear_alpha_pos, a_pos);
172 SET_FARVAR(seg, info->pixclock_max, 0);
173
174 regs->al = regs->ah; /* 0x4F, Function supported */
175 regs->ah = 0x0; /* 0x0, Function call successful */
176}
177
178static void
179vbe_104f02(struct bregs *regs)
180{
Kevin O'Connor5108c692011-12-31 19:13:45 -0500181 dprintf(1, "VBE mode set: %x\n", regs->bx);
Kevin O'Connor40401952011-12-31 03:43:12 -0500182
Kevin O'Connor5108c692011-12-31 19:13:45 -0500183 int mode = regs->bx & 0x1ff;
184 int flags = regs->bx & (MF_CUSTOMCRTC|MF_LINEARFB|MF_NOCLEARMEM);
185 int ret = vgahw_set_mode(mode, flags);
Kevin O'Connor40401952011-12-31 03:43:12 -0500186
Kevin O'Connor5108c692011-12-31 19:13:45 -0500187 regs->ah = ret;
188 regs->al = 0x4f;
Kevin O'Connor40401952011-12-31 03:43:12 -0500189}
190
191static void
192vbe_104f03(struct bregs *regs)
193{
194 if (!bochsvga_hires_enabled()) {
195 regs->bx = GET_BDA(video_mode);
196 } else {
197 regs->bx = bochsvga_curr_mode();
198 }
199
200 dprintf(1, "VBE current mode=%x\n", regs->bx);
201
202 regs->al = regs->ah; /* 0x4F, Function supported */
203 regs->ah = 0x0; /* 0x0, Function call successful */
204}
205
206static void
207vbe_104f04(struct bregs *regs)
208{
209 debug_stub(regs);
210 regs->ax = 0x0100;
211}
212
213static void
214vbe_104f05(struct bregs *regs)
215{
216 debug_stub(regs);
217 regs->ax = 0x0100;
218}
219
220static void
221vbe_104f06(struct bregs *regs)
222{
223 debug_stub(regs);
224 regs->ax = 0x0100;
225}
226
227static void
228vbe_104f07(struct bregs *regs)
229{
230 debug_stub(regs);
231 regs->ax = 0x0100;
232}
233
234static void
235vbe_104f08(struct bregs *regs)
236{
237 debug_stub(regs);
238 regs->ax = 0x0100;
239}
240
241static void
242vbe_104f0a(struct bregs *regs)
243{
244 debug_stub(regs);
245 regs->ax = 0x0100;
246}
247
248static void
249vbe_104fXX(struct bregs *regs)
250{
251 debug_stub(regs);
252 regs->ax = 0x0100;
253}
254
255void
256handle_104f(struct bregs *regs)
257{
258 if (!bochsvga_enabled()) {
259 vbe_104fXX(regs);
260 return;
261 }
262
263 switch (regs->al) {
264 case 0x00: vbe_104f00(regs); break;
265 case 0x01: vbe_104f01(regs); break;
266 case 0x02: vbe_104f02(regs); break;
267 case 0x03: vbe_104f03(regs); break;
268 case 0x04: vbe_104f04(regs); break;
269 case 0x05: vbe_104f05(regs); break;
270 case 0x06: vbe_104f06(regs); break;
271 case 0x07: vbe_104f07(regs); break;
272 case 0x08: vbe_104f08(regs); break;
273 case 0x0a: vbe_104f0a(regs); break;
274 default: vbe_104fXX(regs); break;
275 }
276}