pointing to a memory map location in C
Hi all,
I hope someone can help me out on this or point me the right direction. I need to get the checksum of a memory range. I understand how to get this if I’m pointing to a buffer or array. However I need to get this for a direct memory address, so it might be memory map location 0x00ff and the next 50 bytes after this. So I need to be able to point via an address rather than from a buffer/array name. I’m really unsure how to do this, can anyone point (no pun intended) me in the right direction. Thanks BTW I’m using C on an embedded processor. Thanks |
Hi -
If you're doing this from user space, then the virtual address *IS* the address. Trying to compute a checksum of an arbitrary memory range with respect to using "physical memory" ranges is nonsense: a) It's a lot of extra work (you can already easily get a user space pointer) b) It isn't even necessarily valid (the "real" addresses can change - many times - under your feet while you're computing the checksum. Your final "sum" would be pure fantasy!) There are (as always) exceptions ... and you might indeed have a legitimate requirement in here. But based on the information you've given ... don't do it! Just compute the user-space checksum from your user-space virtual address range ... and you should be Happy. IMHO .. PSM PS: Otherwise, if I've misunderstood the question, you might be interested in looking at: a) mmap ... and/or ... b) the C/C++ "volatile" keyword ... and/or ... c) Writing your own kernel module to access physical hardware (memory and registers) Here's a link that might be of interest: http://www.simtec.co.uk/appnotes/AN0014/ |
If this is a typical 8-bit microcontoller or the like, where you are not running under a protected mode OS, simply load up a pointer with the address you want it to point to, and dereference to your heart's content:
Code:
void * arbitrary_ptr; |
All times are GMT -5. The time now is 03:52 PM. |