LinuxQuestions.org
Review your favorite Linux distribution.
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 03-24-2005, 11:21 PM   #1
cyu021
Member
 
Registered: Oct 2004
Posts: 43

Rep: Reputation: 15
How to access physical memory in C?


Hi folks,

I am trying to convert virtual address to physical memory in a C function, during the kernel is booting in debugging mode. However, I need to read certain content from physical memory throughout the process.

eg.
read content of physical address (CR3 + virtual addr[32..22])... etc.

Is C language capable of access physical memory directly? and how?


Thanks in advance,
James
 
Old 03-25-2005, 08:08 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
With pointers:
Code:
void *ptr = 0x12345678 // Some memory address.
 
Old 03-26-2005, 03:53 AM   #3
cyu021
Member
 
Registered: Oct 2004
Posts: 43

Original Poster
Rep: Reputation: 15
I thought that when a program is being run, its pointers always point to "virtual address"... ?!

Quote:
Originally posted by itsme86
With pointers:
Code:
void *ptr = 0x12345678 // Some memory address.
 
Old 03-26-2005, 10:20 AM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
/dev/mem or /dev/kmem might help. see mem(4)
 
Old 03-26-2005, 11:30 AM   #5
BoldKiller
Member
 
Registered: Apr 2002
Location: Montreal, Quebec
Distribution: Debian, Gentoo, RedHat
Posts: 142

Rep: Reputation: 15
The method actually depends on the system. If you program on a OS with virtual memory(Linux, Solaris, Windows), then adresse are invirtual memory.

If you are on a system not running an OS. Like programming a processor direcly for a embeded application, then you can use pointers.
 
Old 03-27-2005, 12:33 AM   #6
cyu021
Member
 
Registered: Oct 2004
Posts: 43

Original Poster
Rep: Reputation: 15
Thanks for your reply, but I m trying to access the physical memory with its address during the boot up (a break point is set between the start and the end of boot process), and the /dev/ won't be ready to use during this period...

Quote:
Originally posted by aluser
/dev/mem or /dev/kmem might help. see mem(4)
 
Old 03-27-2005, 04:16 AM   #7
Mathsniper
Member
 
Registered: Aug 2004
Posts: 135

Rep: Reputation: 15
you can use C extension, asm. the formula is
asm(code-string : output-list : input-list : overwrite-list);
 
  


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
free physical memory saavik Solaris / OpenSolaris 7 08-26-2005 12:22 PM
Less physical memory? ariek Debian 5 07-21-2005 02:23 PM
get Physical memory in C/C++ Dreampainter Programming 1 10-30-2004 08:54 PM
Physical memory usage piglingz Linux - Hardware 3 04-06-2003 09:07 PM
How Much Physical Memory ? tied2 Linux - Newbie 3 06-17-2002 01:30 AM


All times are GMT -5. The time now is 07:30 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