Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-29-2007, 02:17 PM   #1
Registered: Mar 2006
Posts: 622

Rep: Reputation: 42
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
Old 07-29-2007, 02:38 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.


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:

Last edited by paulsm4; 07-29-2007 at 03:52 PM.
Old 08-01-2007, 07:25 PM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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:
   void * arbitrary_ptr;

   arbitrary_ptr = 0x8123;
   for( i = 0; i < 128; i++ ){
      chksum = calc_checksum( *arbitrary_ptr++, chksum );
---- rod.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable at random location in memory? Ephracis Linux - Software 2 08-27-2006 06:49 AM
Copy a function to other memory location and execute it amit_bst Programming 11 06-29-2006 12:34 AM
PCI Memory Map rajtendulkar Linux - Hardware 0 03-20-2006 11:00 PM
ethernet card 3C 905c TX :cant map port memory on fbsd4.9 Dominik *BSD 0 03-13-2004 09:40 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration