vbeinfo

view src/main.c @ 4:d2c44edd8b77

print the framebuffer address
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 07 Jan 2019 13:52:58 +0200
parents 193757920de9
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "vbe.h"
5 #define REALPTR(s, o) (void*)(((uint32_t)(s) << 4) + (uint32_t)(o))
6 #define VBEPTR(x) REALPTR(((x) & 0xffff0000) >> 16, (x) & 0xffff)
7 #define VBEPTR_SEG(x) (((x) & 0xffff0000) >> 16)
8 #define VBEPTR_OFF(x) ((x) & 0xffff)
10 struct video_mode {
11 int xres, yres, bpp;
12 unsigned long addr;
13 };
15 void sort_modes(struct video_mode *arr, int sz, int field);
17 int main(int argc, char **argv)
18 {
19 int i, nmodes;
20 struct vbe_info *vbe;
21 struct vbe_mode_info *mode;
22 uint16_t *modes;
23 struct video_mode *vmodes;
24 char *vendor, *product, *prod_rev;
25 unsigned long prev_addr = 0;
27 if(!(vbe = vbe_get_info())) {
28 fprintf(stderr, "VBE not found\n");
29 return 1;
30 }
32 if(!(vendor = VBEPTR(vbe->oem_vendor_name_ptr)) || !*vendor) {
33 vendor = "unknown";
34 }
35 if(!(product = VBEPTR(vbe->oem_product_name_ptr)) || !*product) {
36 product = "unknown";
37 }
38 if(!(prod_rev = VBEPTR(vbe->oem_product_rev_ptr)) || !*prod_rev) {
39 prod_rev = "unknown";
40 }
42 printf("VBE version: %x.%x\n", vbe->version >> 8, vbe->version & 0xff);
43 printf("Graphics adapter: %s, %s (%s)\n", vendor, product, prod_rev);
44 printf("Video memory: %dkb\n", vbe->total_mem << 6);
46 modes = VBEPTR(vbe->vid_mode_ptr);
47 nmodes = 0;
48 for(i=0; i<1024; i++) {
49 if(modes[i] == 0xffff) break;
50 nmodes++;
51 }
52 printf("%d video modes found:\n", nmodes);
54 if(!(vmodes = malloc(nmodes * sizeof *vmodes))) {
55 fprintf(stderr, "failed to allocate video modes array\n");
56 return 1;
57 }
59 for(i=0; i<nmodes; i++) {
60 if(!(mode = vbe_get_mode_info(modes[i]))) {
61 fprintf(stderr, "failed to get mode %d info\n", i);
62 }
63 vmodes[i].xres = mode->xres;
64 vmodes[i].yres = mode->yres;
65 vmodes[i].bpp = mode->bpp;
66 vmodes[i].addr = mode->fb_addr;
67 }
69 sort_modes(vmodes, nmodes, 2);
70 sort_modes(vmodes, nmodes, 1);
72 for(i=0; i<nmodes; i++) {
73 if(i == 0 || vmodes[i].xres != vmodes[i - 1].xres ||
74 vmodes[i].yres != vmodes[i - 1].yres) {
75 printf("\n%4dx%d - depth:", vmodes[i].xres, vmodes[i].yres);
76 }
77 printf(" %d", vmodes[i].bpp);
78 }
79 putchar('\n');
81 printf("fb addr:");
82 for(i=0; i<nmodes; i++) {
83 if(vmodes[i].addr && vmodes[i].addr != prev_addr) {
84 printf(" %lx", vmodes[i].addr);
85 prev_addr = vmodes[i].addr;
86 }
87 }
88 putchar('\n');
90 free(vmodes);
91 return 0;
92 }
94 void sort_modes(struct video_mode *arr, int sz, int field)
95 {
96 int i, j;
97 struct video_mode tmp;
99 for(i=0; i<sz; i++) {
100 for(j=i+1; j<sz; j++) {
101 if(((int*)(arr + i))[field] >= ((int*)(arr + j))[field]) {
102 tmp = arr[i];
103 arr[i] = arr[j];
104 arr[j] = tmp;
105 }
106 }
107 }
108 }