🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.dsp
Article #2093

Is this a Legal Way to Access a Specific Address?

#2093
From: Scott R. Chilcote
Date: Sat, 23 Jan 1993 04:26
44 lines
2234 bytes
Hi Folks!
 
We're programming a device that has a RAM cache at address 809800H.

Is it legal to address this memory in C as follows?

#define ON_CHIP 0x809800

int main(void)
{

   float *oc_ptr = (float *) ON_CHIP;


Our device-specific ANSI C compiler lets us do this in order to address the
on-chip memory, without a warning.  The emulator shows that it works.  I've
looked in several textbooks, however, and I've never seen mention of setting
a pointer equal to a constant in order to define a specific address.  Even the
new K & R book doesn't mention if this is legal.

Does anyone know if this is acceptable coding, and what kinds of problems could
crop up from using this method?

The other way we can achieve the same result is using the linker for this 
device to declare a section of memory at a specific address, and associate
a label with the section.  We can then use that label with an external pointer
declaration in the C program ( extern void *on_chip; ) to reference the 
specific address we need.  This method requires more CPU cycles than the one
above to resolve pointers, but at least the address space we're using is 
declared in the linker's memory map.

Note that this device has no operating system to speak of, so we're free to 
access all address space with impunity.

Thanks for any help!


-------------------------------------------------------------
Disclaimer: I do not represent Verdix Corporation, and my
postings do not represent their opinions.  
-------------------------------------------------------------
                                            Scott R. Chilcote
                                            scotty@verdix.com  - or -
                                            scotty%verdix.com@uunet.uu.net
Technical Details
Message-ID: <1993Jan23.042626.991@verdix.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!sarge!scotty

Show Full Headers
Complete Article Headers
Newsgroups: comp.dsp,comp.lang.c
Path: arc1-ca.pugleaf.net!sparky!uunet!sarge!scotty
From: scotty@verdix.com (Scott R. Chilcote)
Subject: Is this a Legal Way to Access a Specific Address?
Message-ID: <1993Jan23.042626.991@verdix.com>
Summary: Assigning Pointer = Constant
Keywords: DSP, C, ANSI, Fixed RAM
Sender: news@verdix.com
Nntp-Posting-Host: sarge.hq.verdix.com
Organization: Lack Thereof
Date: Sat, 23 Jan 1993 04:26:26 GMT
Lines: 44