LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 07-29-2007, 01:17 PM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 536

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, 01:38 PM   #2
paulsm4
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.

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/

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

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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;

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


Reply


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 05:49 AM
Copy a function to other memory location and execute it amit_bst Programming 11 06-28-2006 11:34 PM
PCI Memory Map rajtendulkar Linux - Hardware 0 03-20-2006 10:00 PM
ethernet card 3C 905c TX :cant map port memory on fbsd4.9 Dominik *BSD 0 03-13-2004 08:40 AM


All times are GMT -5. The time now is 03:08 PM.

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