Skip navigation.
Home
The QNX Community Portal

View topic - Using the virtual address to navigate the userspace?

Using the virtual address to navigate the userspace?

General Help about QNX

Using the virtual address to navigate the userspace?

Postby JFGagnon » Wed Mar 28, 2012 7:09 pm

Hi,

is it possible to use the virtual address from mmap_device_io() to navigate through the userspace? By that I mean is it possible to do the same operation as a pointer and move through memory from adding offset to the virtual address?
let's say for example I have this code :
Code: Select all
mmap_addr = mmap_device_io(8,0x48310000);
   if (mmap_addr == MAP_DEVICE_FAILED){
      std::cout << " mmap_device_io failed" << std::endl;
      error = 1;
   }
mmap_addr = mmap_addr + 4;

Would that mean that I would point to the virtual address of 0x48310004 ?

And if I would like to use one virtual memory address pointer instead of declaring each pointer for only 1 register at a time, would the method above be the good thing to do? Basically , what I would like to do is put a pointer at the base address of a module ( for example, GPIO1 is 0x48310000 ) and use the same pointer by simply changing the address to access different register. How would I go about that with QNX?

Thank you
Jean-Francois
JFGagnon
Active Member
 
Posts: 18
Joined: Mon Mar 12, 2012 8:17 pm

Re: Using the virtual address to navigate the userspace?

Postby mario » Thu Mar 29, 2012 12:13 pm

Nope, IO are meant to access IO not memory. On many processor IO and memory are the same thing but on some it's not. In fact to be portable you should NOT treat the value returned by mmap_device_io() as a pointer.

But no you cannot "easily" access user space and to math with a pointer, because you map to physical memory and you don't really know what is the physical layout of the user memory, for example the heap could be fragmented. That info is available but not simple to get ( the sources of pidin are a good reference ). The other problem is that user space memory layout can change, for example when the heap grows or shrink.

Why would you want to access user space?
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: Using the virtual address to navigate the userspace?

Postby JFGagnon » Thu Mar 29, 2012 2:45 pm

mario wrote:Why would you want to access user space?


I thought it would be the "safest" method. What I do normally with a microcontroller is map a structure over the memory of a certain module. For example, if I want to control a GPIO module, I'll make a structure with bitfields and such and put it "over" (if i may say) the memory to have an easy access and control of the module. With QNX , direct memory access seems to be protected.

Now I'm coding with C++ and what I would like to do is to have a pointer in the range of the memory of a certain module and move it inside that range without having to use a function every time to set a new address to access different registers. For example , a pointer is pointing at 0x10000000 and I want to go to 0x10004000 , so I just increment the pointer to 0x10004000 and modify the register. I'd like to do that instead of calling mmap_device_io() everytime I want to access a register.

Jean-Francois
JFGagnon
Active Member
 
Posts: 18
Joined: Mon Mar 12, 2012 8:17 pm

Re: Using the virtual address to navigate the userspace?

Postby maschoen » Thu Mar 29, 2012 3:59 pm

The answer is basically, yes. When you call mmap_device_io(), there is a size parameter. You do not need to call this routine for each individual I/O port. You can (and probably should) map the entire space with one call. You can then access the entire space via a pointer to a structure. You need to take steps so that the compile does not optimize code in ways that will not work, for example by storing an I/O port value in a register, or executing code out of order.

And I think I'm repeating myself, but you should NOT be calling mmap_device_io() every time you want to access a register, likewise you should NOT be un-mapping after you access.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: Using the virtual address to navigate the userspace?

Postby JFGagnon » Thu Mar 29, 2012 4:20 pm

HI Maschoen,

thank you for your reply. That is what exactly what I was looking for. So let's say that my module is located at 0x00000000 and is 1024 bytes large (0x400). So I would do that call
Code: Select all
mmap_addr = mmap_device_io(0x400,0x00000000);


Then I could do arithmetic on mmap_addr or use it in a struct/class?

Code: Select all
mmap_addr = mmap_addr + offset;
JFGagnon
Active Member
 
Posts: 18
Joined: Mon Mar 12, 2012 8:17 pm

Re: Using the virtual address to navigate the userspace?

Postby maschoen » Thu Mar 29, 2012 4:25 pm

That should work.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: Using the virtual address to navigate the userspace?

Postby JFGagnon » Thu Mar 29, 2012 5:53 pm

I'll run some tests on that and post my results here.

Thank you
Jean-Francois
JFGagnon
Active Member
 
Posts: 18
Joined: Mon Mar 12, 2012 8:17 pm

Re: Using the virtual address to navigate the userspace?

Postby mario » Thu Mar 29, 2012 8:09 pm

ah by user space I though you meant having access to the memory of another process. In QNX there is no "kernel space" and "user space".

It's true that with many microcontroller you can map a structure to some IO, but it's not portable ( x86 familly ).
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: Using the virtual address to navigate the userspace?

Postby JFGagnon » Mon Apr 02, 2012 2:57 pm

mario wrote:It's true that with many microcontroller you can map a structure to some IO, but it's not portable ( x86 familly ).


We don't plan on making our QNX application portable. It's a pretty specific and custom application. But basically what I am trying to do is code in 2 layers if I can say. Hardware layer and software layer. If the company would want to change the hardware for whatever reason, they would only have to change the Hardware layer (and maybe a little bit of the software but hopefully not :P). Right now I am at the hardware layer , trying to interface everything so we can use what we want/need in our application.
JFGagnon
Active Member
 
Posts: 18
Joined: Mon Mar 12, 2012 8:17 pm

Re: Using the virtual address to navigate the userspace?

Postby mario » Mon Apr 02, 2012 4:20 pm

JFGagnon wrote:
mario wrote:It's true that with many microcontroller you can map a structure to some IO, but it's not portable ( x86 familly ).


We don't plan on making our QNX application portable. It's a pretty specific and custom application. But basically what I am trying to do is code in 2 layers if I can say. Hardware layer and software layer. If the company would want to change the hardware for whatever reason, they would only have to change the Hardware layer (and maybe a little bit of the software but hopefully not :P). Right now I am at the hardware layer , trying to interface everything so we can use what we want/need in our application.


Don`t have much detail here but if you want to encapsulate the hardware layer, I looks to me like mapping IO isn`t the way to go. You need either a "real" driver or just hide the hardware detail in a library.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: Using the virtual address to navigate the userspace?

Postby JFGagnon » Mon Apr 02, 2012 5:23 pm

Well my knowledge with QNX and RTOS in general is very limited so I thought I would first try to hide the hardware in libraries and later on try to switch to driver . That way I can still separate the hardware from software and be able to change the hardware layer afterwards and still be able to develop something. Right now I am also just an intern and I'm going back to school this May so I try to get something to work with for the next person to take over the project.
JFGagnon
Active Member
 
Posts: 18
Joined: Mon Mar 12, 2012 8:17 pm

Re: Using the virtual address to navigate the userspace?

Postby jacks_benny » Sun Apr 15, 2012 3:29 pm

Some truly nice and useful information on this internet site , likewise I believe the style and design has got excellent features.
jacks_benny
New Member
 
Posts: 1
Joined: Sun Apr 15, 2012 3:25 pm

Re: Using the virtual address to navigate the userspace?

Postby maschoen » Sun Apr 15, 2012 7:29 pm

jacks_benny wrote:Some truly nice and useful information on this internet site , likewise I believe the style and design has got excellent features.


As part of this site's clean up committee, I am truly baffled about this post. It looks a lot like a spam, post. But such a post would be followed with a link to some website selling Viagra, porn or whatever. On the other hand it could be just a nice comment about the site. But then why is it in this random thread? Maybe this is just where the "browser" found himself when he felt like complimenting. The suspcious user name "Jack(s) Benny" only encourages me to think it was spam. But since it is benign, I'm leaving it up. Anyone else have an opinion? :-).
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: Using the virtual address to navigate the userspace?

Postby mario » Mon Apr 16, 2012 1:05 pm

maschoen wrote:
jacks_benny wrote:Some truly nice and useful information on this internet site , likewise I believe the style and design has got excellent features.


As part of this site's clean up committee, I am truly baffled about this post. It looks a lot like a spam, post. But such a post would be followed with a link to some website selling Viagra, porn or whatever. On the other hand it could be just a nice comment about the site. But then why is it in this random thread? Maybe this is just where the "browser" found himself when he felt like complimenting. The suspcious user name "Jack(s) Benny" only encourages me to think it was spam. But since it is benign, I'm leaving it up. Anyone else have an opinion? :-).


I agree, my guess is that it's some sort of post to get around the 3 post rules, once the user had been fully approved that is when they slip-in there poison.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: Using the virtual address to navigate the userspace?

Postby maschoen » Mon Apr 16, 2012 6:33 pm

I don't even know about the 3 posting rule, but fear not, I'm vigilant. Spammers, bring it on.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest