Deleted Added
full compact
vesa.c (197323) vesa.c (197383)
1/*-
2 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/fb/vesa.c 197323 2009-09-19 04:36:38Z jkim $");
28__FBSDID("$FreeBSD: head/sys/dev/fb/vesa.c 197383 2009-09-21 08:17:57Z delphij $");
29
30#include "opt_vga.h"
31#include "opt_vesa.h"
32
33#ifndef VGA_NO_MODE_CHANGE
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/malloc.h>
40#include <sys/fbio.h>
41
42#include <vm/vm.h>
43#include <vm/vm_extern.h>
44#include <vm/vm_kern.h>
45#include <vm/vm_param.h>
46#include <vm/pmap.h>
47
29
30#include "opt_vga.h"
31#include "opt_vesa.h"
32
33#ifndef VGA_NO_MODE_CHANGE
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/malloc.h>
40#include <sys/fbio.h>
41
42#include <vm/vm.h>
43#include <vm/vm_extern.h>
44#include <vm/vm_kern.h>
45#include <vm/vm_param.h>
46#include <vm/pmap.h>
47
48#include <machine/pc/bios.h>
48#include <dev/fb/vesa.h>
49
50#include <dev/fb/fbreg.h>
51#include <dev/fb/vgareg.h>
52
53#include <isa/isareg.h>
49#include <dev/fb/vesa.h>
50
51#include <dev/fb/fbreg.h>
52#include <dev/fb/vgareg.h>
53
54#include <isa/isareg.h>
54#include <machine/cpufunc.h>
55
55
56#include <contrib/x86emu/x86emu.h>
57#include <contrib/x86emu/x86emu_regs.h>
56#include <dev/x86bios/x86bios.h>
58
59#define VESA_VIA_CLE266 "VIA CLE266\r\n"
60
61#ifndef VESA_DEBUG
62#define VESA_DEBUG 0
63#endif
64
65/* VESA video adapter state buffer stub */
66struct adp_state {
67 int sig;
68#define V_STATE_SIG 0x61736576
69 u_char regs[1];
70};
71typedef struct adp_state adp_state_t;
72
73/* VESA video adapter */
74static video_adapter_t *vesa_adp = NULL;
75static int vesa_state_buf_size = 0;
57
58#define VESA_VIA_CLE266 "VIA CLE266\r\n"
59
60#ifndef VESA_DEBUG
61#define VESA_DEBUG 0
62#endif
63
64/* VESA video adapter state buffer stub */
65struct adp_state {
66 int sig;
67#define V_STATE_SIG 0x61736576
68 u_char regs[1];
69};
70typedef struct adp_state adp_state_t;
71
72/* VESA video adapter */
73static video_adapter_t *vesa_adp = NULL;
74static int vesa_state_buf_size = 0;
76#define VESA_X86EMU_BUFSIZE (3 * PAGE_SIZE)
75#define VESA_BIOS_BUFSIZE (3 * PAGE_SIZE)
77
78/* VESA functions */
79#if 0
80static int vesa_nop(void);
81#endif
82static int vesa_error(void);
83static vi_probe_t vesa_probe;
84static vi_init_t vesa_init;

--- 16 unchanged lines hidden (view full) ---

101static vi_mmap_t vesa_mmap;
102static vi_ioctl_t vesa_ioctl;
103static vi_clear_t vesa_clear;
104static vi_fill_rect_t vesa_fill_rect;
105static vi_bitblt_t vesa_bitblt;
106static vi_diag_t vesa_diag;
107static int vesa_bios_info(int level);
108
76
77/* VESA functions */
78#if 0
79static int vesa_nop(void);
80#endif
81static int vesa_error(void);
82static vi_probe_t vesa_probe;
83static vi_init_t vesa_init;

--- 16 unchanged lines hidden (view full) ---

100static vi_mmap_t vesa_mmap;
101static vi_ioctl_t vesa_ioctl;
102static vi_clear_t vesa_clear;
103static vi_fill_rect_t vesa_fill_rect;
104static vi_bitblt_t vesa_bitblt;
105static vi_diag_t vesa_diag;
106static int vesa_bios_info(int level);
107
109static struct x86emu vesa_emu;
110
111static video_switch_t vesavidsw = {
112 vesa_probe,
113 vesa_init,
114 vesa_get_info,
115 vesa_query_mode,
116 vesa_set_mode,
117 vesa_save_font,
118 vesa_load_font,

--- 82 unchanged lines hidden (view full) ---

201static void vesa_clear_modes(video_info_t *info, int color);
202static vm_offset_t vesa_map_buffer(u_int paddr, size_t size);
203static void vesa_unmap_buffer(vm_offset_t vaddr, size_t size);
204
205#if 0
206static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
207#endif
208
108static video_switch_t vesavidsw = {
109 vesa_probe,
110 vesa_init,
111 vesa_get_info,
112 vesa_query_mode,
113 vesa_set_mode,
114 vesa_save_font,
115 vesa_load_font,

--- 82 unchanged lines hidden (view full) ---

198static void vesa_clear_modes(video_info_t *info, int color);
199static vm_offset_t vesa_map_buffer(u_int paddr, size_t size);
200static void vesa_unmap_buffer(vm_offset_t vaddr, size_t size);
201
202#if 0
203static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
204#endif
205
209#define SEG_ADDR(x) (((x) >> 4) & 0x00F000)
210#define SEG_OFF(x) ((x) & 0x0FFFF)
211
212#if _BYTE_ORDER == _LITTLE_ENDIAN
213#define B_O16(x) (x)
214#define B_O32(x) (x)
215#else
216#define B_O16(x) ((((x) & 0xff) << 8) | (((x) & 0xff) >> 8))
217#define B_O32(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) \
218 | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24))
219#endif
220
221#define L_ADD(x) (B_O32(x) & 0xffff) + ((B_O32(x) >> 12) & 0xffff00)
222#define FARP(p) (((unsigned)(p & 0xffff0000) >> 12) | (p & 0xffff))
223
224#define REALOFF(x) (x*4096)
225
226static unsigned char *emumem = NULL;
227
228static uint8_t
229vm86_emu_inb(struct x86emu *emu, uint16_t port)
230{
231 if (port == 0xb2) /* APM scratch register */
232 return 0;
233 if (port >= 0x80 && port < 0x88) /* POST status register */
234 return 0;
235 return inb(port);
236}
237
238static uint16_t
239vm86_emu_inw(struct x86emu *emu, uint16_t port)
240{
241 if (port >= 0x80 && port < 0x88) /* POST status register */
242 return 0;
243 return inw(port);
244}
245
246static uint32_t
247vm86_emu_inl(struct x86emu *emu, uint16_t port)
248{
249 if (port >= 0x80 && port < 0x88) /* POST status register */
250 return 0;
251 return inl(port);
252}
253
254static void
206static void
255vm86_emu_outb(struct x86emu *emu, uint16_t port, uint8_t val)
256{
257 if (port == 0xb2) /* APM scratch register */
258 return;
259 if (port >= 0x80 && port < 0x88) /* POST status register */
260 return;
261 outb(port, val);
262}
263
264static void
265vm86_emu_outw(struct x86emu *emu, uint16_t port, uint16_t val)
266{
267 if (port >= 0x80 && port < 0x88) /* POST status register */
268 return;
269 outw(port, val);
270}
271
272static void
273vm86_emu_outl(struct x86emu *emu, uint16_t port, uint32_t val)
274{
275 if (port >= 0x80 && port < 0x88) /* POST status register */
276 return;
277 outl(port, val);
278}
279
280static void
281dump_buffer(u_char *buf, size_t len)
282{
283 int i;
284
285 for(i = 0; i < len;) {
286 printf("%02x ", buf[i]);
287 if ((++i % 16) == 0)
288 printf("\n");
289 }
290}
291
292/* INT 10 BIOS calls */
293static int
294int10_set_mode(int mode)
295{
207dump_buffer(u_char *buf, size_t len)
208{
209 int i;
210
211 for(i = 0; i < len;) {
212 printf("%02x ", buf[i]);
213 if ((++i % 16) == 0)
214 printf("\n");
215 }
216}
217
218/* INT 10 BIOS calls */
219static int
220int10_set_mode(int mode)
221{
296 vesa_emu.x86.R_EAX = 0x0000 | mode;
297 x86emu_exec_intr(&vesa_emu, 0x10);
222 x86regs_t regs;
298
223
224 regs.R_EAX = 0x0000 | mode;
225
226 x86biosCall(&regs, 0x10);
227
299 return 0;
300}
301
302/* VESA BIOS calls */
303static int
304vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
305{
228 return 0;
229}
230
231/* VESA BIOS calls */
232static int
233vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
234{
235 x86regs_t regs;
236 int offs;
306 u_char *buf;
307
237 u_char *buf;
238
308 vesa_emu.x86.R_EAX = 0x4f01;
309 vesa_emu.x86.R_ECX = mode;
239 regs.R_EAX = 0x4f01;
240 regs.R_ECX = mode;
310
241
311 buf = (emumem + REALOFF(3));
312 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(3));
313 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(3));
242 buf = (u_char *)x86biosAlloc(1, &offs);
314
243
315 x86emu_exec_intr(&vesa_emu, 0x10);
244 regs.R_ES = SEG_ADDR(offs);
245 regs.R_DI = SEG_OFF(offs);
316
246
317 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
247 x86biosCall(&regs, 0x10);
248
249 if ((regs.R_AX & 0xff) != 0x4f)
250 {
251 x86biosFree(buf, 1);
318 return 1;
252 return 1;
253 }
319
320 bcopy(buf, vmode, sizeof(*vmode));
254
255 bcopy(buf, vmode, sizeof(*vmode));
256 x86biosFree(buf, 1);
321
322 return 0;
323}
324
325static int
326vesa_bios_set_mode(int mode)
327{
257
258 return 0;
259}
260
261static int
262vesa_bios_set_mode(int mode)
263{
328 vesa_emu.x86.R_EAX = 0x4f02;
329 vesa_emu.x86.R_EBX = mode;
264 x86regs_t regs;
330
265
331 x86emu_exec_intr(&vesa_emu, 0x10);
266 regs.R_EAX = 0x4f02;
267 regs.R_EBX = mode;
332
268
333 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
269 x86biosCall(&regs, 0x10);
270
271 return ((regs.R_AX & 0xff) != 0x4f);
334}
335
336static int
337vesa_bios_get_dac(void)
338{
272}
273
274static int
275vesa_bios_get_dac(void)
276{
339 vesa_emu.x86.R_EAX = 0x4f08;
340 vesa_emu.x86.R_EBX = 1;
277 x86regs_t regs;
341
278
342 x86emu_exec_intr(&vesa_emu, 0x10);
279 regs.R_EAX = 0x4f08;
280 regs.R_EBX = 1;
343
281
344 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
282 x86biosCall(&regs, 0x10);
283
284 if ((regs.R_AX & 0xff) != 0x4f)
345 return 6;
346
285 return 6;
286
347 return ((vesa_emu.x86.R_EBX >> 8) & 0x00ff);
287 return ((regs.R_EBX >> 8) & 0x00ff);
348}
349
350static int
351vesa_bios_set_dac(int bits)
352{
288}
289
290static int
291vesa_bios_set_dac(int bits)
292{
353 vesa_emu.x86.R_EAX = 0x4f08;
354 vesa_emu.x86.R_EBX = (bits << 8);
293 x86regs_t regs;
355
294
356 x86emu_exec_intr(&vesa_emu, 0x10);
295 regs.R_EAX = 0x4f08;
296 regs.R_EBX = (bits << 8);
357
297
358 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
298 x86biosCall(&regs, 0x10);
299
300 if ((regs.R_AX & 0xff) != 0x4f)
359 return 6;
360
301 return 6;
302
361 return ((vesa_emu.x86.R_EBX >> 8) & 0x00ff);
303 return ((regs.R_EBX >> 8) & 0x00ff);
362}
363
364static int
365vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
366{
304}
305
306static int
307vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
308{
309 x86regs_t regs;
310 int offs;
367 u_char *p;
368 int i;
369
311 u_char *p;
312 int i;
313
370 vesa_emu.x86.R_EAX = 0x4f09;
371 vesa_emu.x86.R_EBX = 1;
372 vesa_emu.x86.R_ECX = colors;
373 vesa_emu.x86.R_EDX = start;
314 regs.R_EAX = 0x4f09;
315 regs.R_EBX = 1;
316 regs.R_ECX = colors;
317 regs.R_EDX = start;
374
318
375 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
376 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
319 p = (u_char *)x86biosAlloc(1, &offs);
377
320
378 p = emumem + REALOFF(2);
321 regs.R_ES = SEG_ADDR(offs);
322 regs.R_DI = SEG_OFF(offs);
379
323
380 x86emu_exec_intr(&vesa_emu, 0x10);
324 x86biosCall(&regs, 0x10);
381
325
382 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
326 if ((regs.R_AX & 0xff) != 0x4f)
327 {
328 x86biosFree(p, 1);
383 return 1;
329 return 1;
330 }
384
385 bits = 8 - bits;
386 for (i = 0; i < colors; ++i) {
387 palette[i*3] = p[i*4 + 2] << bits;
388 palette[i*3 + 1] = p[i*4 + 1] << bits;
389 palette[i*3 + 2] = p[i*4] << bits;
390 }
331
332 bits = 8 - bits;
333 for (i = 0; i < colors; ++i) {
334 palette[i*3] = p[i*4 + 2] << bits;
335 palette[i*3 + 1] = p[i*4 + 1] << bits;
336 palette[i*3 + 2] = p[i*4] << bits;
337 }
338
339 x86biosFree(p, 1);
391 return 0;
392}
393
394static int
395vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
396 int bits)
397{
340 return 0;
341}
342
343static int
344vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
345 int bits)
346{
347 x86regs_t regs;
348 int offs;
398 u_char *p;
399 int i;
400
349 u_char *p;
350 int i;
351
401 vesa_emu.x86.R_EAX = 0x4f09;
402 vesa_emu.x86.R_EBX = 1;
403 vesa_emu.x86.R_ECX = colors;
404 vesa_emu.x86.R_EDX = start;
352 regs.R_EAX = 0x4f09;
353 regs.R_EBX = 1;
354 regs.R_ECX = colors;
355 regs.R_EDX = start;
405
356
406 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
407 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
357 p = (u_char *)x86biosAlloc(1, &offs);
408
358
409 p = emumem + REALOFF(2);
359 regs.R_ES = SEG_ADDR(offs);
360 regs.R_DI = SEG_OFF(offs);
410
361
411 x86emu_exec_intr(&vesa_emu, 0x10);
362 x86biosCall(&regs, 0x10);
412
363
413 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
364 if ((regs.R_AX & 0xff) != 0x4f)
365 {
366 x86biosFree(p, 1);
414 return 1;
367 return 1;
368 }
415
416 bits = 8 - bits;
417 for (i = 0; i < colors; ++i) {
418 r[i] = p[i*4 + 2] << bits;
419 g[i] = p[i*4 + 1] << bits;
420 b[i] = p[i*4] << bits;
421 }
369
370 bits = 8 - bits;
371 for (i = 0; i < colors; ++i) {
372 r[i] = p[i*4 + 2] << bits;
373 g[i] = p[i*4 + 1] << bits;
374 b[i] = p[i*4] << bits;
375 }
376
377 x86biosFree(p, 1);
422 return 0;
423}
424
425static int
426vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
427{
378 return 0;
379}
380
381static int
382vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
383{
384 x86regs_t regs;
385 int offs;
428 u_char *p;
429 int i;
430
386 u_char *p;
387 int i;
388
431 p = (emumem + REALOFF(2));
389 p = (u_char *)x86biosAlloc(1, &offs);
432
433 bits = 8 - bits;
434 for (i = 0; i < colors; ++i) {
435 p[i*4] = palette[i*3 + 2] >> bits;
436 p[i*4 + 1] = palette[i*3 + 1] >> bits;
437 p[i*4 + 2] = palette[i*3] >> bits;
438 p[i*4 + 3] = 0;
439 }
440
390
391 bits = 8 - bits;
392 for (i = 0; i < colors; ++i) {
393 p[i*4] = palette[i*3 + 2] >> bits;
394 p[i*4 + 1] = palette[i*3 + 1] >> bits;
395 p[i*4 + 2] = palette[i*3] >> bits;
396 p[i*4 + 3] = 0;
397 }
398
441 vesa_emu.x86.R_EAX = 0x4f09;
442 vesa_emu.x86.R_EBX = 0;
443 vesa_emu.x86.R_ECX = colors;
444 vesa_emu.x86.R_EDX = start;
399 regs.R_EAX = 0x4f09;
400 regs.R_EBX = 0;
401 regs.R_ECX = colors;
402 regs.R_EDX = start;
445
403
446 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
447 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
404 regs.R_ES = SEG_ADDR(offs);
405 regs.R_DI = SEG_OFF(offs);
448
406
449 x86emu_exec_intr(&vesa_emu, 0x10);
407 x86biosCall(&regs, 0x10);
450
408
451 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
409 x86biosFree(p, 1);
410
411 return ((regs.R_AX & 0xff) != 0x4f);
452}
453
454#ifdef notyet
455static int
456vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
457 int bits)
458{
412}
413
414#ifdef notyet
415static int
416vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
417 int bits)
418{
419 x86regs_t regs;
420 int offs;
459 u_char *p;
460 int i;
461
421 u_char *p;
422 int i;
423
462 p = (emumem + REALOFF(2));
424 p = (u_char *)x86biosAlloc(1, &offs);
463
464 bits = 8 - bits;
465 for (i = 0; i < colors; ++i) {
466 p[i*4] = b[i] >> bits;
467 p[i*4 + 1] = g[i] >> bits;
468 p[i*4 + 2] = r[i] >> bits;
469 p[i*4 + 3] = 0;
470 }
471
425
426 bits = 8 - bits;
427 for (i = 0; i < colors; ++i) {
428 p[i*4] = b[i] >> bits;
429 p[i*4 + 1] = g[i] >> bits;
430 p[i*4 + 2] = r[i] >> bits;
431 p[i*4 + 3] = 0;
432 }
433
472 vesa_emu.x86.R_EAX = 0x4f09;
473 vesa_emu.x86.R_EBX = 0;
474 vesa_emu.x86.R_ECX = colors;
475 vesa_emu.x86.R_EDX = start;
434 regs.R_EAX = 0x4f09;
435 regs.R_EBX = 0;
436 regs.R_ECX = colors;
437 regs.R_EDX = start;
476
438
477 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
478 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
439 regs.R_ES = SEG_ADDR(offs);
440 regs.R_DI = SEG_OFF(offs);
479
441
480 x86emu_exec_intr(&vesa_emu, 0x10);
442 x86biosCall(&regs, 0x10);
481
443
482 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
444 x86biosFree(p, 1);
445
446 return ((regs.R_AX & 0xff) != 0x4f);
483}
484#endif
485
486static int
487vesa_bios_state_buf_size(void)
488{
447}
448#endif
449
450static int
451vesa_bios_state_buf_size(void)
452{
489 vesa_emu.x86.R_EAX = 0x4f04;
490 vesa_emu.x86.R_ECX = STATE_ALL;
491 vesa_emu.x86.R_EDX = STATE_SIZE;
453 x86regs_t regs;
492
454
493 x86emu_exec_intr(&vesa_emu, 0x10);
455 regs.R_EAX = 0x4f04;
456 regs.R_ECX = STATE_ALL;
457 regs.R_EDX = STATE_SIZE;
494
458
495 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
459 x86biosCall(&regs, 0x10);
460
461 if ((regs.R_AX & 0xff) != 0x4f)
496 return 0;
497
462 return 0;
463
498 return vesa_emu.x86.R_BX*64;
464 return regs.R_BX*64;
499}
500
501static int
502vesa_bios_save_restore(int code, void *p, size_t size)
503{
465}
466
467static int
468vesa_bios_save_restore(int code, void *p, size_t size)
469{
470 x86regs_t regs;
471 int offs;
504 u_char *buf;
505
472 u_char *buf;
473
506 if (size > VESA_X86EMU_BUFSIZE)
474 if (size > VESA_BIOS_BUFSIZE)
507 return (1);
508
475 return (1);
476
509 vesa_emu.x86.R_EAX = 0x4f04;
510 vesa_emu.x86.R_ECX = STATE_ALL;
511 vesa_emu.x86.R_EDX = code;
477 regs.R_EAX = 0x4f04;
478 regs.R_ECX = STATE_ALL;
479 regs.R_EDX = code;
512
480
513 buf = emumem + REALOFF(2);
481 buf = (u_char *)x86biosAlloc(1, &offs);
514
482
515 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
516 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
483 regs.R_ES = SEG_ADDR(offs);
484 regs.R_DI = SEG_OFF(offs);
517
518 bcopy(p, buf, size);
519
485
486 bcopy(p, buf, size);
487
520 x86emu_exec_intr(&vesa_emu, 0x10);
488 x86biosCall(&regs, 0x10);
521
522 bcopy(buf, p, size);
523
489
490 bcopy(buf, p, size);
491
524 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
492 x86biosFree(p, 1);
493
494 return ((regs.R_AX & 0xff) != 0x4f);
525}
526
527static int
528vesa_bios_get_line_length(void)
529{
495}
496
497static int
498vesa_bios_get_line_length(void)
499{
530 vesa_emu.x86.R_EAX = 0x4f06;
531 vesa_emu.x86.R_EBX = 1;
500 x86regs_t regs;
532
501
533 x86emu_exec_intr(&vesa_emu, 0x10);
502 regs.R_EAX = 0x4f06;
503 regs.R_EBX = 1;
534
504
535 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
505 x86biosCall(&regs, 0x10);
506
507 if ((regs.R_AX & 0xff) != 0x4f)
536 return -1;
508 return -1;
537 return vesa_emu.x86.R_BX;
509
510 return regs.R_BX;
538}
539
540static int
541vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
542{
511}
512
513static int
514vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
515{
543 vesa_emu.x86.R_EAX = 0x4f06;
544 vesa_emu.x86.R_EBX = 0;
545 vesa_emu.x86.R_ECX = pixel;
516 x86regs_t regs;
546
517
547 x86emu_exec_intr(&vesa_emu, 0x10);
518 regs.R_EAX = 0x4f06;
519 regs.R_EBX = 0;
520 regs.R_ECX = pixel;
548
521
522 x86biosCall(&regs, 0x10);
523
549#if VESA_DEBUG > 1
524#if VESA_DEBUG > 1
550 printf("bx:%d, cx:%d, dx:%d\n", vesa_emu.x86.R_BX, vesa_emu.x86.R_CX, vesa_emu.x86.R_DX);
525 printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
551#endif
526#endif
552 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
527 if ((regs.R_AX & 0xff) != 0x4f)
553 return -1;
554
555 if (bytes)
528 return -1;
529
530 if (bytes)
556 *bytes = vesa_emu.x86.R_BX;
531 *bytes = regs.R_BX;
557 if (lines)
532 if (lines)
558 *lines = vesa_emu.x86.R_DX;
533 *lines = regs.R_DX;
559
560 return 0;
561}
562
563#if 0
564static int
565vesa_bios_get_start(int *x, int *y)
566{
534
535 return 0;
536}
537
538#if 0
539static int
540vesa_bios_get_start(int *x, int *y)
541{
567 vesa_emu.x86.R_EAX = 0x4f07;
568 vesa_emu.x86.R_EBX = 1;
542 x86regs_t regs;
569
543
570 x86emu_exec_intr(&vesa_emu, 0x10);
544 regs.R_EAX = 0x4f07;
545 regs.R_EBX = 1;
571
546
572 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
547 x86biosCall(&regs, 0x10);
548
549 if ((regs.R_AX & 0xff) != 0x4f)
573 return -1;
574
550 return -1;
551
575 *x = vesa_emu.x86.R_CX;
576 *y = vesa_emu.x86.R_DX;
552 *x = regs.R_CX;
553 *y = regs.R_DX;
577
578 return 0;
579}
580#endif
581
582static int
583vesa_bios_set_start(int x, int y)
584{
554
555 return 0;
556}
557#endif
558
559static int
560vesa_bios_set_start(int x, int y)
561{
585 vesa_emu.x86.R_EAX = 0x4f07;
586 vesa_emu.x86.R_EBX = 0x80;
587 vesa_emu.x86.R_EDX = y;
588 vesa_emu.x86.R_ECX = x;
562 x86regs_t regs;
589
563
590 x86emu_exec_intr(&vesa_emu, 0x10);
564 regs.R_EAX = 0x4f07;
565 regs.R_EBX = 0x80;
566 regs.R_EDX = y;
567 regs.R_ECX = x;
591
568
592 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
569 x86biosCall(&regs, 0x10);
570
571 return ((regs.R_AX & 0xff) != 0x4f);
593}
594
595/* map a generic video mode to a known mode */
596static int
597vesa_map_gen_mode_num(int type, int color, int mode)
598{
599 static struct {
600 int from;

--- 59 unchanged lines hidden (view full) ---

660}
661
662static int
663vesa_bios_init(void)
664{
665 static struct vesa_info buf;
666 struct vesa_mode vmode;
667 video_info_t *p;
572}
573
574/* map a generic video mode to a known mode */
575static int
576vesa_map_gen_mode_num(int type, int color, int mode)
577{
578 static struct {
579 int from;

--- 59 unchanged lines hidden (view full) ---

639}
640
641static int
642vesa_bios_init(void)
643{
644 static struct vesa_info buf;
645 struct vesa_mode vmode;
646 video_info_t *p;
647 x86regs_t regs;
648 int offs;
668 u_char *vmbuf;
669 int is_via_cle266;
670 int modes;
671 int i;
672
673 if (vesa_init_done)
674 return 0;
675
676 has_vesa_bios = FALSE;
677 vesa_adp_info = NULL;
678 vesa_vmode_max = 0;
679 vesa_vmode[0].vi_mode = EOT;
680
649 u_char *vmbuf;
650 int is_via_cle266;
651 int modes;
652 int i;
653
654 if (vesa_init_done)
655 return 0;
656
657 has_vesa_bios = FALSE;
658 vesa_adp_info = NULL;
659 vesa_vmode_max = 0;
660 vesa_vmode[0].vi_mode = EOT;
661
681 vmbuf = (emumem + REALOFF(2));
662 vmbuf = (u_char *)x86biosAlloc(1, &offs);
682 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
683
663 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
664
684 vesa_emu.x86.R_EAX = 0x4f00;
685 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
686 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
665 regs.R_EAX = 0x4f00;
666 regs.R_ES = SEG_ADDR(offs);
667 regs.R_DI = SEG_OFF(offs);
687
668
688 x86emu_exec_intr(&vesa_emu, 0x10);
669 x86biosCall(&regs, 0x10);
689
670
690 if (((vesa_emu.x86.R_AX & 0xff) != 0x4f) || bcmp("VESA", vmbuf, 4))
671 if (((regs.R_AX & 0xff) != 0x4f) || bcmp("VESA", vmbuf, 4))
691 return 1;
692
693 bcopy(vmbuf, &buf, sizeof(buf));
694
695 vesa_adp_info = &buf;
696 if (bootverbose) {
697 printf("VESA: information block\n");
698 dump_buffer((u_char *)&buf, sizeof(buf));
699 }
700 if (vesa_adp_info->v_version < 0x0102) {
701 printf("VESA: VBE version %d.%d is not supported; "
702 "version 1.2 or later is required.\n",
703 ((vesa_adp_info->v_version & 0xf000) >> 12) * 10
704 + ((vesa_adp_info->v_version & 0x0f00) >> 8),
705 ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10
706 + (vesa_adp_info->v_version & 0x000f));
707 return 1;
708 }
709
672 return 1;
673
674 bcopy(vmbuf, &buf, sizeof(buf));
675
676 vesa_adp_info = &buf;
677 if (bootverbose) {
678 printf("VESA: information block\n");
679 dump_buffer((u_char *)&buf, sizeof(buf));
680 }
681 if (vesa_adp_info->v_version < 0x0102) {
682 printf("VESA: VBE version %d.%d is not supported; "
683 "version 1.2 or later is required.\n",
684 ((vesa_adp_info->v_version & 0xf000) >> 12) * 10
685 + ((vesa_adp_info->v_version & 0x0f00) >> 8),
686 ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10
687 + (vesa_adp_info->v_version & 0x000f));
688 return 1;
689 }
690
710 vesa_oemstr = (char *)(emumem + L_ADD(vesa_adp_info->v_oemstr));
691 vesa_oemstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_oemstr));
711
712 is_via_cle266 = strcmp(vesa_oemstr, VESA_VIA_CLE266) == 0;
713
714 if (vesa_adp_info->v_version >= 0x0200) {
692
693 is_via_cle266 = strcmp(vesa_oemstr, VESA_VIA_CLE266) == 0;
694
695 if (vesa_adp_info->v_version >= 0x0200) {
715 vesa_venderstr = (char *)(emumem+L_ADD(vesa_adp_info->v_venderstr));
716 vesa_prodstr = (char *)(emumem+L_ADD(vesa_adp_info->v_prodstr));
717 vesa_revstr = (char *)(emumem+L_ADD(vesa_adp_info->v_revstr));
696 vesa_venderstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_venderstr));
697 vesa_prodstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_prodstr));
698 vesa_revstr = (char *)x86biosOffs(FARP(vesa_adp_info->v_revstr));
718 }
719
699 }
700
720 vesa_vmodetab = (u_int16_t *)(emumem+L_ADD(vesa_adp_info->v_modetable));
701 vesa_vmodetab = (u_int16_t *)x86biosOffs(FARP(vesa_adp_info->v_modetable));
721
722 if (vesa_vmodetab == NULL)
723 return 1;
724
725 for (i = 0, modes = 0;
726 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
727 && (vesa_vmodetab[i] != 0xffff); ++i) {
728 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))

--- 68 unchanged lines hidden (view full) ---

797 = vesa_adp_info->v_memsize*64*1024;
798#if 0
799 if (vmode.v_offscreen > vmode.v_lfb)
800 vesa_vmode[modes].vi_buffer_size
801 = vmode.v_offscreen + vmode.v_offscreensize*1024
802 - vmode.v_lfb;
803 else
804 vesa_vmode[modes].vi_buffer_size
702
703 if (vesa_vmodetab == NULL)
704 return 1;
705
706 for (i = 0, modes = 0;
707 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
708 && (vesa_vmodetab[i] != 0xffff); ++i) {
709 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))

--- 68 unchanged lines hidden (view full) ---

778 = vesa_adp_info->v_memsize*64*1024;
779#if 0
780 if (vmode.v_offscreen > vmode.v_lfb)
781 vesa_vmode[modes].vi_buffer_size
782 = vmode.v_offscreen + vmode.v_offscreensize*1024
783 - vmode.v_lfb;
784 else
785 vesa_vmode[modes].vi_buffer_size
805 = vmode.v_offscreen + vmode.v_offscreensize*1024
786 = vmode.v_offscreen + vmode.v_offscreensize*1024;
806#endif
807 vesa_vmode[modes].vi_mem_model
808 = vesa_translate_mmodel(vmode.v_memmodel);
809 vesa_vmode[modes].vi_pixel_fields[0] = 0;
810 vesa_vmode[modes].vi_pixel_fields[1] = 0;
811 vesa_vmode[modes].vi_pixel_fields[2] = 0;
812 vesa_vmode[modes].vi_pixel_fields[3] = 0;
813 vesa_vmode[modes].vi_pixel_fsizes[0] = 0;

--- 24 unchanged lines hidden (view full) ---

838 vesa_vmode[modes].vi_pixel_size = 0;
839 }
840
841 vesa_vmode[modes].vi_flags
842 = vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
843 ++modes;
844 }
845 vesa_vmode[modes].vi_mode = EOT;
787#endif
788 vesa_vmode[modes].vi_mem_model
789 = vesa_translate_mmodel(vmode.v_memmodel);
790 vesa_vmode[modes].vi_pixel_fields[0] = 0;
791 vesa_vmode[modes].vi_pixel_fields[1] = 0;
792 vesa_vmode[modes].vi_pixel_fields[2] = 0;
793 vesa_vmode[modes].vi_pixel_fields[3] = 0;
794 vesa_vmode[modes].vi_pixel_fsizes[0] = 0;

--- 24 unchanged lines hidden (view full) ---

819 vesa_vmode[modes].vi_pixel_size = 0;
820 }
821
822 vesa_vmode[modes].vi_flags
823 = vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
824 ++modes;
825 }
826 vesa_vmode[modes].vi_mode = EOT;
827
828 x86biosFree(vmbuf, 1);
829
846 if (bootverbose)
847 printf("VESA: %d mode(s) found\n", modes);
848
849 has_vesa_bios = (modes > 0);
850 if (!has_vesa_bios)
851 return (1);
852
853 return (0);

--- 268 unchanged lines hidden (view full) ---

1122 vesa_adp_info->v_memsize*64*1024);
1123 vesa_adp->va_buffer_size = info.vi_buffer_size;
1124 vesa_adp->va_window = vesa_adp->va_buffer;
1125 vesa_adp->va_window_size = info.vi_buffer_size/info.vi_planes;
1126 vesa_adp->va_window_gran = info.vi_buffer_size/info.vi_planes;
1127 } else {
1128 vesa_adp->va_buffer = 0;
1129 vesa_adp->va_buffer_size = info.vi_buffer_size;
830 if (bootverbose)
831 printf("VESA: %d mode(s) found\n", modes);
832
833 has_vesa_bios = (modes > 0);
834 if (!has_vesa_bios)
835 return (1);
836
837 return (0);

--- 268 unchanged lines hidden (view full) ---

1106 vesa_adp_info->v_memsize*64*1024);
1107 vesa_adp->va_buffer_size = info.vi_buffer_size;
1108 vesa_adp->va_window = vesa_adp->va_buffer;
1109 vesa_adp->va_window_size = info.vi_buffer_size/info.vi_planes;
1110 vesa_adp->va_window_gran = info.vi_buffer_size/info.vi_planes;
1111 } else {
1112 vesa_adp->va_buffer = 0;
1113 vesa_adp->va_buffer_size = info.vi_buffer_size;
1130 vesa_adp->va_window = (vm_offset_t)(emumem+L_ADD(info.vi_window));
1114 vesa_adp->va_window = BIOS_PADDRTOVADDR(info.vi_window);
1131 vesa_adp->va_window_size = info.vi_window_size;
1132 vesa_adp->va_window_gran = info.vi_window_gran;
1133 }
1134 vesa_adp->va_window_orig = 0;
1135 len = vesa_bios_get_line_length();
1136 if (len > 0) {
1137 vesa_adp->va_line_width = len;
1138 } else if (info.vi_flags & V_INFO_GRAPHICS) {

--- 132 unchanged lines hidden (view full) ---

1271 return vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1272 vesa_state_buf_size);
1273}
1274
1275#if 0
1276static int
1277vesa_get_origin(video_adapter_t *adp, off_t *offset)
1278{
1115 vesa_adp->va_window_size = info.vi_window_size;
1116 vesa_adp->va_window_gran = info.vi_window_gran;
1117 }
1118 vesa_adp->va_window_orig = 0;
1119 len = vesa_bios_get_line_length();
1120 if (len > 0) {
1121 vesa_adp->va_line_width = len;
1122 } else if (info.vi_flags & V_INFO_GRAPHICS) {

--- 132 unchanged lines hidden (view full) ---

1255 return vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1256 vesa_state_buf_size);
1257}
1258
1259#if 0
1260static int
1261vesa_get_origin(video_adapter_t *adp, off_t *offset)
1262{
1279 vesa_emu.x86.R_EAX = 0x4f05;
1280 vesa_emu.x86.R_EBX = 0x10;
1263 x86regs_t regs;
1281
1264
1282 x86emu_exec_intr(&vesa_emu, 0x10);
1265 regs.R_EAX = 0x4f05;
1266 regs.R_EBX = 0x10;
1283
1267
1284 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
1268 x86biosCall(&regs, 0x10);
1269
1270 if ((regs.R_AX & 0xff) != 0x4f)
1285 return 1;
1271 return 1;
1286 *offset = vesa_emu.x86.DX*adp->va_window_gran;
1272 *offset = regs.DX*adp->va_window_gran;
1287
1288 return 0;
1289}
1290#endif
1291
1292static int
1293vesa_set_origin(video_adapter_t *adp, off_t offset)
1294{
1273
1274 return 0;
1275}
1276#endif
1277
1278static int
1279vesa_set_origin(video_adapter_t *adp, off_t offset)
1280{
1281 x86regs_t regs;
1282
1295 /*
1296 * This function should return as quickly as possible to
1297 * maintain good performance of the system. For this reason,
1298 * error checking is kept minimal and let the VESA BIOS to
1299 * detect error.
1300 */
1301 if (adp != vesa_adp)
1302 return (*prevvidsw->set_win_org)(adp, offset);
1303
1304 /* if this is a linear frame buffer, do nothing */
1305 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1306 return 0;
1307 /* XXX */
1308 if (adp->va_window_gran == 0)
1309 return 1;
1310
1283 /*
1284 * This function should return as quickly as possible to
1285 * maintain good performance of the system. For this reason,
1286 * error checking is kept minimal and let the VESA BIOS to
1287 * detect error.
1288 */
1289 if (adp != vesa_adp)
1290 return (*prevvidsw->set_win_org)(adp, offset);
1291
1292 /* if this is a linear frame buffer, do nothing */
1293 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1294 return 0;
1295 /* XXX */
1296 if (adp->va_window_gran == 0)
1297 return 1;
1298
1311 vesa_emu.x86.R_EAX = 0x4f05;
1312 vesa_emu.x86.R_EBX = 0;
1313 vesa_emu.x86.R_EDX = offset/adp->va_window_gran;
1314 x86emu_exec_intr(&vesa_emu, 0x10);
1299 regs.R_EAX = 0x4f05;
1300 regs.R_EBX = 0;
1301 regs.R_EDX = offset/adp->va_window_gran;
1302 x86biosCall(&regs, 0x10);
1315
1303
1316 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
1304 if ((regs.R_AX & 0xff) != 0x4f)
1317 return 1;
1318
1305 return 1;
1306
1319 vesa_emu.x86.R_EAX = 0x4f05;
1320 vesa_emu.x86.R_EBX = 1;
1321 vesa_emu.x86.R_EDX = offset/adp->va_window_gran;
1322 x86emu_exec_intr(&vesa_emu, 0x10);
1307 regs.R_EAX = 0x4f05;
1308 regs.R_EBX = 1;
1309 regs.R_EDX = offset/adp->va_window_gran;
1310 x86biosCall(&regs, 0x10);
1323
1324 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1325 return 0; /* XXX */
1326}
1327
1328static int
1329vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1330{

--- 318 unchanged lines hidden (view full) ---

1649vesa_load(void)
1650{
1651 int error;
1652 int s;
1653
1654 if (vesa_init_done)
1655 return 0;
1656
1311
1312 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1313 return 0; /* XXX */
1314}
1315
1316static int
1317vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1318{

--- 318 unchanged lines hidden (view full) ---

1637vesa_load(void)
1638{
1639 int error;
1640 int s;
1641
1642 if (vesa_init_done)
1643 return 0;
1644
1657 /* Can `emumem' be NULL here? */
1658 emumem = pmap_mapbios(0x0, 0xc00000);
1659
1660 memset(&vesa_emu, 0, sizeof(vesa_emu));
1661 x86emu_init_default(&vesa_emu);
1662
1663 vesa_emu.emu_inb = vm86_emu_inb;
1664 vesa_emu.emu_inw = vm86_emu_inw;
1665 vesa_emu.emu_inl = vm86_emu_inl;
1666 vesa_emu.emu_outb = vm86_emu_outb;
1667 vesa_emu.emu_outw = vm86_emu_outw;
1668 vesa_emu.emu_outl = vm86_emu_outl;
1669
1670 vesa_emu.mem_base = (char *)emumem;
1671 vesa_emu.mem_size = 1024 * 1024;
1672
1673 /* locate a VGA adapter */
1674 s = spltty();
1675 vesa_adp = NULL;
1676 error = vesa_configure(0);
1677 splx(s);
1678
1679 if (error == 0)
1680 vesa_bios_info(bootverbose);

--- 31 unchanged lines hidden (view full) ---

1712 }
1713 }
1714 vesa_adp->va_flags &= ~V_ADP_VESA;
1715 vidsw[vesa_adp->va_index] = prevvidsw;
1716 }
1717 }
1718 splx(s);
1719
1645 /* locate a VGA adapter */
1646 s = spltty();
1647 vesa_adp = NULL;
1648 error = vesa_configure(0);
1649 splx(s);
1650
1651 if (error == 0)
1652 vesa_bios_info(bootverbose);

--- 31 unchanged lines hidden (view full) ---

1684 }
1685 }
1686 vesa_adp->va_flags &= ~V_ADP_VESA;
1687 vidsw[vesa_adp->va_index] = prevvidsw;
1688 }
1689 }
1690 splx(s);
1691
1720 if (emumem)
1721 pmap_unmapdev((vm_offset_t)emumem, 0xc00000);
1722
1723 return error;
1724}
1725
1726static int
1727vesa_mod_event(module_t mod, int type, void *data)
1728{
1729 switch (type) {
1730 case MOD_LOAD:

--- 8 unchanged lines hidden (view full) ---

1739
1740static moduledata_t vesa_mod = {
1741 "vesa",
1742 vesa_mod_event,
1743 NULL,
1744};
1745
1746DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1692 return error;
1693}
1694
1695static int
1696vesa_mod_event(module_t mod, int type, void *data)
1697{
1698 switch (type) {
1699 case MOD_LOAD:

--- 8 unchanged lines hidden (view full) ---

1708
1709static moduledata_t vesa_mod = {
1710 "vesa",
1711 vesa_mod_event,
1712 NULL,
1713};
1714
1715DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1747MODULE_DEPEND(vesa, x86emu, 1, 1, 1);
1716MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
1748
1749#endif /* VGA_NO_MODE_CHANGE */
1717
1718#endif /* VGA_NO_MODE_CHANGE */