Cross gcc Mailing List Archive
[Prev][Next][Index][Thread]
Re: volital registers
> This is what I have now
>
> #define SCSR (*(unsigned short *)0xfffC0C)
> #define SCDR (*(unsigned short *)0xfffC0E)
>
> This works OK until the the I do this
>
> while (SCSR & 0X0100)
> ;
> SCDR = c ;
> The optimizer (-O2 ) thinks SCSR is a constant
...snip...
> How do specify pointer to a volital area in memory?
Easy. This is a common problem. Do it like this:
volatile unsigned short *SCSR_reg = (unsigned short *)0xfffC0C;
volatile unsigned short *SCDR_reg = (unsigned short *)0xfffC0E;
#define SCSR (*SCSR_reg)
#define SCDR (*SCDR_reg)
The key here is the "volatile" keyword. The optimiser won't touch
anything marked volatile.
Or, if you define a structure to access a set of registers, mark each
element as volatile:
typedef struct _regs {
volatile unsigned short SCSR;
volatile unsigned short SCDR;
} hw_regs;
hw_regs *regs = (hw_regs *)0xfffC0C;
then use:
status = regs->SCSR;
regs->SCDR = data;
> OR
>
> I would like to have the CPU's internal I/O show up
> in the linker map
> so that if someone tries to map something else in
> the same location the
> linker will give a warning or error.
>
>
> Is there a simple way to get the symbols into the
> memory map?
> Has it been done?
You can define areas in the linker command script (assuming you are
using the GNU ld). If you define the memory available to the program as
genuine RAM addresses then the linker should throw out any attempts to
position things outside of it.
Here is one of my linker scripts (for a 68030 card) that defines symbols
and locates things in particular places. The .ramtext section contains
code which is copied from EPROM into RAM at startup. The .text section
executes from EPROM.
OUTPUT_ARCH(m68k)
STARTUP(bootstrap.o)
INPUT(crt0-873.o)
/* --------------------------------------------------------------
Specify the memory available in the target
-------------------------------------------------------------- */
MEMORY
{
Eprom (RX) : ORIGIN = 0, LENGTH = 512K
Sram (RWX) : ORIGIN = 0x200000, LENGTH = 256K
}
/* Define some symbols */
__ram_start = 0x200000;
__ram_size = 256 * 1024;
__stack_size = 8 * 1024;
/* --------------------------------------------------------------
Specify the how the program sections are positioned
-------------------------------------------------------------- */
SECTIONS
{
/*
* Locate for run-time address in SRAM, but place into the output
* file immediately following .text.
* This section is declared first so that the files pre-linked in
* ramcode.o are explicitly placed in Sram; the rest are handled
* in the .text section below.
*/
.ramtext : AT(_etext)
{
_ramtext = .;
ramcode.o(.text)
. = ALIGN(0x8);
_eramtext = .;
} > Sram
/*
* Locate for run-time address in SRAM, but place into the output
* file immediately following .ramtext.
*/
.data : AT(_etext + SIZEOF(.ramtext))
{
_data =.;
*(.data)
_edata = .;
} > Sram
.bss BLOCK(0x8):
{
__bss_start = .;
*(.bss)
*(COMMON)
end = ALIGN(0x8);
_end = ALIGN(0x8);
__end = ALIGN(0x8);
} > Sram
/*
* Locate the rest of .text in the upper of of EPROM:
* 0x20000 for 27C1001
* 0x40000 for 27C2001
*/
.text 0x40000 :
{
_text = .;
*(.text)
. = ALIGN(0x8);
_etext = .;
} > Eprom
}
--
Mark Powell, Senior Software Engineer <medp@primag.co.uk>
Primagraphics Limited, Melbourn Science Park, Royston, Herts SG8 6EJ, England.
Tel. +44 1763 262041 Fax. +44 1763 262551 http://www.primag.co.uk/
References:
Home |
Subject Index |
Thread Index