On Mon, 2002-01-21 at 15:08, Erez Doron wrote:
> one can not access physical memory, only virtual memory.
>
> the linux kernel, by default, maps all physical memory to virtual one.
> the problem is that if i tell it to use less memory, via mem=... i get
> the rest of the physical memory not mapped to virtual adresses.
>
> one solution is to let the ramdisk map the physical to virtual, but i do
> not know how to do that ...
So why didn't you ask THAT? ;-)
The following is not elegant or efficient soultion but it works. The
elegant and efficient solution btw, is to write a shared memory handler
that will map the "special" physical memory addresses to your proccess
memory map when it is opened.
In lilo.conf put:
image=/boot/zImage
label=rtlinux-0.6
root=/dev/hda2
read-only
append="mem=31m"
#define BASE_ADDRESS (31 * 0x100000)
#include <unistd.h> /* open() */
#include <fcntl.h> /* O_RDWR */
int fd;
if ((fd = open("/dev/mem", O_RDWR)) < 0)
{
/* handle error here */
}
Due to security reasons, the default permissions on /dev/mem allow only
root processes to read or write /dev/mem. To access physical memory, the
program must be run as root, its permissions must be changed to setuid
root, or the permissions on /dev/mem must be changed to allow access to
users other than root.
After the file descriptor is opened, the Linux process maps the shared
memory into its address space using mmap(), as shown here:
#include <stdlib.h> /* sizeof() */
#include <sys/mman.h> /* mmap(), PROT_READ, MAP_FILE */
#define MAP_FAILED ((void *) -1) /* omitted from Linux mman.h */
MY_STRUCT *ptr;
ptr = (MY_STRUCT *) mmap(0, sizeof(MY_STRUCT),
PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED,
fd, BASE_ADDRESS);
if (MAP_FAILED == ptr)
{
/* handle error here */
}
close(fd); /* fd no longer needed */
BASE_ADDRESS is passed to mmap() which returns a pointer to the shared
memory as mapped into the Linux process' address space. Once the shared
memory is mapped, it may be accessed by dereferencing the pointer, for
example:
ptr->arg1 = 1;
ptr->arg2 = 2;
When the process terminates, use munmap() to unmap the shared memory by
passing the pointer and the size of its object:
#include <sys/mman.h>
#include "myheader.h"
munmap(ptr, sizeof(MY_STRUCT));
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]