1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "vbe.h"
#include "vesamode.h"
#ident "$Id$"
#define SQR(x) ((x) * (x))
int main(void)
{
int i, j;
u_int16_t *mode_list;
unsigned char hmin, hmax, vmin, vmax;
struct vbe_info *vbe_info;
struct vbe_edid1_info *edid;
struct vbe_modeline *modelines;
#if KERNEL_BOOT_INFO
u_int32_t vga_bios_base, vga_bios_size;
u_int32_t page_size;
int dev_mem_fd;
char *mem;
#endif
if ((vbe_info = vbe_get_vbe_info()) == NULL) return 1;
printf("%dKB of video ram\n", vbe_info->memory_size * 64);
#if KERNEL_BOOT_INFO
/* Open /dev/mem for extra information from VGA BIOS. */
if ((dev_mem_fd = open("/dev/mem", O_RDONLY)) < 0) {
perror("open /dev/mem");
return 1;
}
page_size = getpagesize();
vga_bios_base = vbe_info->mode_list.base & ~0xffff;
vga_bios_size = (vbe_info->mode_list.base - vga_bios_base + page_size - 1) & -page_size;
mem = malloc(vga_bios_size);
if (lseek(dev_mem_fd, vga_bios_base, SEEK_SET) != vga_bios_base)
return 1;
if (read(dev_mem_fd, mem, vga_bios_size) != vga_bios_size)
return 1;
mode_list = (u_int16_t *)(mem + vbe_info->mode_list.base - vga_bios_base);
#endif
#if defined(__i386__)
mode_list = (u_int16_t *)vbe_info->mode_list.ptr;
#endif
/* List supported standard modes. */
while (*mode_list != 0xffff) {
for (i = 0; known_vesa_modes[i].x; i++)
if (known_vesa_modes[i].number == *mode_list)
printf("%d %d %d\n",
known_vesa_modes[i].colors,
known_vesa_modes[i].x,
known_vesa_modes[i].y
);
mode_list++;
}
printf("\n");
#if KERNEL_BOOT_INFO
free(mem);
close(dev_mem_fd);
#endif
if ((edid = vbe_get_edid_info()) == NULL) return 0;
if (edid->version == 255 && edid->revision == 255) return 0;
vbe_get_edid_ranges(edid, &hmin, &hmax, &vmin, &vmax);
modelines = vbe_get_edid_modelines(edid);
if (hmin > hmax || vmin > vmax) return 0;
printf(hmin ? "%d-%d kHz HorizSync\n" : "\n", hmin, hmax);
printf(vmin ? "%d-%d Hz VertRefresh\n" : "\n", vmin, vmax);
if (edid->max_size_horizontal != 127 && edid->max_size_vertical != 127) {
char manufacturer[4];
double size = sqrt(SQR(edid->max_size_horizontal) +
SQR(edid->max_size_vertical)) / 2.54;
manufacturer[0] = edid->manufacturer_name.char1 + 'A' - 1;
manufacturer[1] = edid->manufacturer_name.char2 + 'A' - 1;
manufacturer[2] = edid->manufacturer_name.char3 + 'A' - 1;
manufacturer[3] = '\0';
printf(size ? "%3.2f inches monitor (truly %3.2f') EISA ID=%s%04x\n" : "\n", size * 1.08, size, manufacturer, edid->product_code);
}
for(j=0; modelines && (modelines[j].refresh != 0); j++){
printf("# %dx%d, %1.1f%sHz",
modelines[j].width,
modelines[j].height,
modelines[j].refresh,
modelines[j].interlaced?"i":""
);
if(modelines[j].modeline) {
printf("; hfreq=%f, vfreq=%f\n%s\n",
modelines[j].hfreq,
modelines[j].vfreq,
modelines[j].modeline);
} else printf("\n");
}
return 0;
}
|