GoTTimw
GoTTimw

Reputation: 2430

Finding physical memory offset to video buffer

I am using Fedora 17 running on board with integrated graphics. Given that I am able to manipulate content of physical memory, how can I find out the physical memory offsets that I could write to in order to display something on the screen?

I tried to lookup 0xB8000 and 0xB0000 offsets but they contain all 0xff.

Is there a specific pattern that starts video buffer in memory? Is there any good source of information about this topic?

The root cause of my problem was that Linux is not using legacy video mode, so the memory at 0xB8000 is restricted (in my case read only). However issuing an interrupt can switch to other modes:

INT 10 - VIDEO - SET VIDEO MODE

AH = 00h
AL = desired video mode (see #00010)

Found on: http://www.delorie.com/djgpp/doc/rbinter/id/74/0.html

Upvotes: 2

Views: 2814

Answers (2)

artless-noise-bye-due2AI
artless-noise-bye-due2AI

Reputation: 22420

Living like it's 1989

    #include <linux/fb.h>
    #define DEV_MEM     "/dev/fb0"

    /* Screen parameters (probably via ioctl() and /sys. */
    #define YRES 240
    #define XRES 320
    #define BYTES_PER_PIXEL (sizeof(unsigned short)) /* 16 bit pixels. */
    #define MAP_SIZE    XRES*YRES*BYTES_PER_PIXEL
    unsigned short  *map_lbase;

    if((fd = open(DEV_MEM, O_RDWR | O_SYNC)) == -1) {
        fprintf(stderr, "cannot open %s - are you root?\n", DEV_MEM);
        exit(1);
    }

   // Map that page.
    map_lbase = (unsigned short *)mmap(NULL, MAP_SIZE,
        PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if((long)map_lbase == -1) {
        perror("cannot mmap");
        exit(1);
    }

Humons - Framebuffer API doc, Framebuffer Doc dir.
Smart Humons - Internals, Deferred I/O doc or how to emulate memory mapped video.


You can not use 0xB8000 and 0xB0000 directly as those are physical addresses. I assume you are in user space and not writing a kernel driver. Under Linux, we normally have the MMU enable; In other words, we have virtual memory. Not all processes/users have access to video memory. However, if you are allowed, you can mmap a framebuffer device to your address space. It is best to let the kernel give you an address and not request a specific one.

Or see how professionals do it.

Man: mmap

Edit: If you aren't root, you can still use Unix permissions on /dev/fb0 (or which ever device) to give group permission to read/write or use some sort of login process that gives a user on the current tty permission.

Upvotes: 3

jsbueno
jsbueno

Reputation: 110271

Maybe you could start around here: http://www.tldp.org/HOWTO/Framebuffer-HOWTO/

But modern video graphics are in no way as simple as "finding where in the meory is the VRAM" and writing there.

Upvotes: 0

Related Questions