The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to assign virtual address?. veeru_jarugula UNIX for Dummies Questions & Answers 1 08-17-2007 01:30 AM
address of pointer Poison Ivy High Level Programming 19 08-16-2006 04:04 AM
The best partitioning schem for a 250GB Sata hard drive & a 75GB SCSI hard drive sirbijan Filesystems, Disks and Memory 0 04-05-2006 11:19 AM
Trying to copy old hard drive to new hard drive. shorty UNIX for Dummies Questions & Answers 4 01-30-2006 02:47 PM
Virtual IP address kanejm IP Networking 2 01-13-2006 10:21 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 12-11-2005
Registered User
 

Join Date: Dec 2005
Posts: 5
A Pointer to non-Virtual Address, and All of my Hard drive

How do I get a pointer to any 32 bit address on my hard drive, in which I then could read that memory or write to that memory address?

And, while the subject is on, how do get a 32 bit pointer in RAM also, in which I can do the same?


I'm using C and Objective-C with gcc on an iBook G4.

A small example in C would be greatly appreciated.
Reply With Quote
Forum Sponsor
  #2  
Old 12-12-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
What you want to do is direct physical I/O. It is completely hardware/kernel depdendant. You will probably have to write a kernel mode module, since user mode I/O does not have access to an address on a disk. You do realize you can trash your whole filesystem by writing something in the wrong place.

You'll have to get information on your kernel's source, and actually create a system call to do what you want, if one doesn't already exist.
Reply With Quote
  #3  
Old 12-12-2005
Registered User
 

Join Date: Dec 2005
Posts: 5
When you say get information on your kernel's source, does that mean the C code will be different from platform to platform?

I asking, because I'm really after a C code example to get me going. I'm assuming the code example has got to be pretty simple.

Psuedocode:
Code:
Get a pointer to an address;
Write this value to such an address;
I have a tutorial on writing kernels for OS X, but I just don't know what the C code would begin to look like.
Reply With Quote
  #4  
Old 12-12-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
Yes - the kernel source is different from distro to distro and has lots of hardware dependencies for things like endianess.

Some points --

1. OS X is open source, I believe. That means either you already have or can download kernel source.

2. kernel code is not always super-simple, but there may be an existing physical I/O function you can work with. If there is you can make a minor change and allow the function to be exported from the kernel to user space. Then you can call it from C.

3. If there is no function you can use, then you will have to create one.

In any event, you will have to learn something about the kernel. I just googled for
'linux kernel programming' and got a load of white papers, turtorials, and books.
You will have to do some reading.

PS: sometimes you can directly access the BIOS on your box. I'm not an OS X person, but be sure to research BIOS access - sometimes it's possible from a simple 3 line ASM call embedded in C.
Reply With Quote
  #5  
Old 12-12-2005
Registered User
 

Join Date: Dec 2005
Posts: 5
Hey thanks. I've began a turotial on loading and unloading kexts in the kernel. I'll see how far that takes me.
Reply With Quote
  #6  
Old 12-12-2005
Registered User
 

Join Date: Dec 2005
Posts: 5
<deleted message>

Last edited by xcoder66; 12-15-2005 at 11:00 PM.
Reply With Quote
  #7  
Old 12-18-2005
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 979
I don't know if you can do it with pointers, but on some UNIX systems you can get access to physical memory via /dev/mem.

[edit] Actually, if you can mmap it, you can get pointers to these things. Find out what device under /dev your hard drive is, and mmap-ing it will map a region of virtual memory into your memory which will act like this area of space on the device you've mapped. It's a very elegant way to access things. See 'man mmap'.

Last edited by Corona688; 12-18-2005 at 12:46 PM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0