help with mmap() please...

bridged with qdn.public.qnxrtp.applications
Post Reply
Jason Farque

help with mmap() please...

Post by Jason Farque » Fri Mar 08, 2002 4:21 pm

Can someone please tell me what I'm doing wrong with mmap()? I've been
wrestling with arguments for two days and cannot get the following program
to dump the contents of my video buffer to the display. The program below
is based on the example in the QNX help file and it compiles file. Running
as root doesn't seem to matter, the mmap() function doesn't return an
error... I'm baffled. I have also tried to open("/dev/mem") and use its
file descriptor. That didn't work either. What am I doing wrong?

Thanks,
Jason
-------------------------------------------
int main()
{
void *ptr;
char buff[80*25];
int i;

ptr = mmap( NULL, 0xffff, PROT_READ|PROT_WRITE, MAP_PHYS|MAP_SHARED,
NOFD, 0xa0000 );
if( ptr == MAP_FAILED) {
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
}
for( i=0; i<(80*25); i++ ) {
buff = *(char *)(ptr+i);
}
for( i=0; i<(80*25); i++ ) {
fprintf( stdout, "%c", buff );
}
}
---------------------------------------------

Adam Mallory

Re: help with mmap() please...

Post by Adam Mallory » Mon Mar 11, 2002 9:50 pm

You should use mmap_device_memory() to map in a video cards memory into
your process space. Are you sure it's not working, or you have the correct
address for the physical location? AFAIK, text memory is located at
0xb8000 (and I'm sure it differs for some cards). Also remember that
everything is double bytes when it comes to the text mode, one byte for
attribute and one for the char.

Hope that helps
--
Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]
---------------------------------------------------
With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
--Peter J. Schoenster <pschon@baste.magibox.net>


"Jason Farque" <jasonf@pigging.com> wrote in
news:a6ao01$7ug$1@inn.qnx.com:
Can someone please tell me what I'm doing wrong with mmap()? I've been
wrestling with arguments for two days and cannot get the following
program to dump the contents of my video buffer to the display. The
program below is based on the example in the QNX help file and it
compiles file. Running as root doesn't seem to matter, the mmap()
function doesn't return an error... I'm baffled. I have also tried to
open("/dev/mem") and use its file descriptor. That didn't work either.
What am I doing wrong?

Thanks,
Jason
-------------------------------------------
int main()
{
void *ptr;
char buff[80*25];
int i;

ptr = mmap( NULL, 0xffff, PROT_READ|PROT_WRITE, MAP_PHYS|MAP_SHARED,
NOFD, 0xa0000 );
if( ptr == MAP_FAILED) {
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
}
for( i=0; i<(80*25); i++ ) {
buff = *(char *)(ptr+i);
}
for( i=0; i<(80*25); i++ ) {
fprintf( stdout, "%c", buff );
}
}
---------------------------------------------


David Gibbs

Re: help with mmap() please...

Post by David Gibbs » Mon Mar 11, 2002 10:12 pm

Jason Farque <jasonf@pigging.com> wrote:
Can someone please tell me what I'm doing wrong with mmap()? I've been
wrestling with arguments for two days and cannot get the following program
to dump the contents of my video buffer to the display. The program below
is based on the example in the QNX help file and it compiles file. Running
as root doesn't seem to matter, the mmap() function doesn't return an
error... I'm baffled. I have also tried to open("/dev/mem") and use its
file descriptor. That didn't work either. What am I doing wrong?
Thanks,
Jason
-------------------------------------------
int main()
{
void *ptr;
char buff[80*25];
int i;

ptr = mmap( NULL, 0xffff, PROT_READ|PROT_WRITE, MAP_PHYS|MAP_SHARED,
NOFD, 0xa0000 );
Try 0xb8000 for color vga memory.

Note, also, this will only likely give you anything meaningful
in text mode.

I did:

ptr = mmap( NULL, 64*1024, PROT_READ|PROT_WRITE|PROT_NOCACHE,
MAP_PHYS|MAP_SHARED, NOFD, 0xb8000 );

memcpy( buff, ptr, 80*25 );

for ( i = 0; i<(80x25); i+= 2 )
{
if(!(i%40)) printf("\n");
printf("%c", buff);
}

(printing every second character to skip the attribute byte)

-David


if( ptr == MAP_FAILED) {
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
}
for( i=0; i<(80*25); i++ ) {
buff = *(char *)(ptr+i);
}
for( i=0; i<(80*25); i++ ) {
fprintf( stdout, "%c", buff );
}
}
---------------------------------------------



--
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Post Reply

Return to “qdn.public.qnxrtp.applications”