* Re: Memory initialization (not)
[not found] <fc.3b9aca009a5ccd273b9aca0070320fb3.1629327@ecrm.com>
@ 2008-09-30 14:03 ` Jim Dougherty
2008-09-30 14:29 ` Eljay Love-Jensen
2008-09-30 14:30 ` Mihai Donțu
0 siblings, 2 replies; 7+ messages in thread
From: Jim Dougherty @ 2008-09-30 14:03 UTC (permalink / raw)
To: Mihai Donțu, gcc-help
Mihai Donțu wrote:
> On Tuesday 30 September 2008, Jim Dougherty wrote:
>> I have a section of memory that I do not want to be initialized with
>> zeros when my program starts.
>> Is there a way to achieve this?
>
> I think that zero initialization is a consequence of how the process
> images is
> created. For example:
>
> static char a[65536];
>
> will make the .bss section of size ~65536 bytes which is allocated by the
> dynamic linker by means of mmap() which always provides zeroed-out pages.
>
> So to answer your question: global variables are likely to be always
> initialized with zero (it's out of gcc-s hands). Stack variables, on the
> other hand, are "initialized" with whatever is on the stack, which yeah, if
> you don't explicitly initialize them, could be called uninitialized. :)
>
> --
> Mihai Don\x1au (unices@bitdefender.com <mailto:unices@bitdefender.com>)
I think that you are wrong although I do not know what the answer is.
I am writing firmware for an embedded system that contains conventional
general purpose RAM but it also contains a small amount of battery
backed up RAM. We store data in the battery backed up RAM that is
basically permanent, the data is not lost when power is turned off and
on. In the case of this battery backed up RAM, we do not want the
compiler writing over our good data at powerup.
I have to believe that there is a way to do this but I do not know what
it is?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Memory initialization (not)
2008-09-30 14:03 ` Memory initialization (not) Jim Dougherty
@ 2008-09-30 14:29 ` Eljay Love-Jensen
2008-09-30 14:30 ` Mihai Donțu
1 sibling, 0 replies; 7+ messages in thread
From: Eljay Love-Jensen @ 2008-09-30 14:29 UTC (permalink / raw)
To: Jim Dougherty, GCC-help
Hi Jim,
How do you access the battery backed RAM?
Is the battery backed RAM part of the heap? Special section?
On a system that I worked on, which had I/O memory at 0xC0000000, part of
which was battery backed memory, I used this:
char* RawC000Page = (char*)0xC0000000;
I also used this for the same memory:
struct C000Page_t* C000Page = (struct C000Page_t*)0xC0000000;
Note: some of the C000Page_t was write-only (reading would be BAD), some of
C000Page_t was read-only (writing would be BAD), some was read/write (but
reading and writing semantically meant different things to the I/O
register), and some was battery backed RAM (reading/writing okay).
The memory was not part of the heap, nor was it part of the .data or .bss
sections. I just wrangled a pointer to point to it. There was no OS, it
was just the code in EEPROM, bootstrapped from an initialization ROM. There
was a managed heap using malloc/free, but that heap was no where near the
0xC0000000 page. The stack was carved out of the heap.
Would something like this work for you?
HTH,
--Eljay
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Memory initialization (not)
2008-09-30 14:03 ` Memory initialization (not) Jim Dougherty
2008-09-30 14:29 ` Eljay Love-Jensen
@ 2008-09-30 14:30 ` Mihai Donțu
1 sibling, 0 replies; 7+ messages in thread
From: Mihai Donțu @ 2008-09-30 14:30 UTC (permalink / raw)
To: Jim Dougherty; +Cc: gcc-help
On Tuesday 30 September 2008, Jim Dougherty wrote:
> Mihai DonÈu wrote:
> > On Tuesday 30 September 2008, Jim Dougherty wrote:
> >> I have a section of memory that I do not want to be initialized with
> >> zeros when my program starts.
> >> Is there a way to achieve this?
> >
> > I think that zero initialization is a consequence of how the process
> > images is
> > created. For example:
> >
> > static char a[65536];
> >
> > will make the .bss section of size ~65536 bytes which is allocated by the
> > dynamic linker by means of mmap() which always provides zeroed-out pages.
> >
> > So to answer your question: global variables are likely to be always
> > initialized with zero (it's out of gcc-s hands). Stack variables, on the
> > other hand, are "initialized" with whatever is on the stack, which yeah,
> > if you don't explicitly initialize them, could be called uninitialized.
> > :)
>
> I think that you are wrong although I do not know what the answer is.
I might very well. :) I did not know you were referring to an embedded system
so I just assumed a common GNU based os.
> I am writing firmware for an embedded system that contains conventional
> general purpose RAM but it also contains a small amount of battery
> backed up RAM. We store data in the battery backed up RAM that is
> basically permanent, the data is not lost when power is turned off and
> on. In the case of this battery backed up RAM, we do not want the
> compiler writing over our good data at powerup.
I'm assuming (again) that the program will be created withing the same address
boundaries and you want it's data sections to be mapped over an already
initialized memory.
I am not aware of gcc generating initializer code without it being requested.
Could you give us more details about the environment you are using to build
your program?
> I have to believe that there is a way to do this but I do not know what
> it is?
--
Mihai DonÈu (unices.bitdefender.com)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Memory initialization (not)
@ 2008-09-30 23:35 Duane Ellis
0 siblings, 0 replies; 7+ messages in thread
From: Duane Ellis @ 2008-09-30 23:35 UTC (permalink / raw)
To: j_dougherty, gcc-help
jim> [I have an embedded system with special memory I do not want
initialized]
You have the following choices:
(A) Do you control the code at the reset vector?
(B) Or is your program "loaded" by some external boot loader?
If you control the code at the reset vector, you can change that code to
do what you want.
Typically in a bare-metal application the code sequence at hard reset is:
1) configure an initial stack pointer
2) program the clocks, plls, and enable SDRAM
[all of which is very chip/silicon specific code]
3) Copy data data from "ROM" to your initialized data area.
4) zero memory.
5) Call the "C++" constructors and initializers - (if you need C++)
6) Sometimes, call some OS dependent functions.
7) Call some function - example: EtherNut calls it "NutMain()" others -
just call it "main()"
8) often you find the above in a file called "crt0.s", other times it
is called "reset.s" it varies. I've also seen "vectors.s" -
You need to modify the file described above for your target board.
Here is an example from "lostarm" - for an Atmel ARM7 based AT91SAM7X256
http://lostarm.svn.sourceforge.net/viewvc/lostarm/release/rev0.1/chips/at91sam7x256/source/sam7_crt0.S?revision=53&view=markup
Here is an example from "ethernut" - for another ARM cpu.
http://ethernut.cvs.sourceforge.net/viewvc/ethernut/nut/arch/arm/init/crtat91_ram.S?view=markup
----
If your code is: "loaded" - ie: via UBOOT (a boot loader) over TCP/IP,
you might need to fiddle with the ELF flags that define what gets done
at load time, that is not always easy, and often one must resort to
"modifying the boot loader" so that it does not zap memory.
---
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Memory initialization (not)
2008-09-30 13:40 Jim Dougherty
2008-09-30 13:54 ` Mihai Donțu
@ 2008-09-30 13:55 ` John Fine
1 sibling, 0 replies; 7+ messages in thread
From: John Fine @ 2008-09-30 13:55 UTC (permalink / raw)
To: Jim Dougherty; +Cc: gcc-help
Jim Dougherty wrote:
> I have a section of memory that I do not want to be initialized with
> zeros when my program starts.
> Is there a way to achieve this?
>
>
Why and/or what do you want to have happen instead?
For example:
1) You want to violate security and have you program able to read the
discarded memory contents left over by some previous program.
2) You want to map and use some specific section of physical memory,
such as an I/O mapped area.
3) You want demand zeroed memory (instead of when your program starts):
The OS well fill each page of such memory with zeroes only when that
page is accessed, not all such pages at the start of the program.
4) You want all the memory filled with something else.
My main point is that saying what you DON'T WANT is too vague.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Memory initialization (not)
2008-09-30 13:40 Jim Dougherty
@ 2008-09-30 13:54 ` Mihai Donțu
2008-09-30 13:55 ` John Fine
1 sibling, 0 replies; 7+ messages in thread
From: Mihai Donțu @ 2008-09-30 13:54 UTC (permalink / raw)
To: gcc-help; +Cc: Jim Dougherty
On Tuesday 30 September 2008, Jim Dougherty wrote:
> I have a section of memory that I do not want to be initialized with
> zeros when my program starts.
> Is there a way to achieve this?
I think that zero initialization is a consequence of how the process images is
created. For example:
static char a[65536];
will make the .bss section of size ~65536 bytes which is allocated by the
dynamic linker by means of mmap() which always provides zeroed-out pages.
So to answer your question: global variables are likely to be always
initialized with zero (it's out of gcc-s hands). Stack variables, on the
other hand, are "initialized" with whatever is on the stack, which yeah, if
you don't explicitly initialize them, could be called uninitialized. :)
--
Mihai DonÈu (unices@bitdefender.com)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Memory initialization (not)
@ 2008-09-30 13:40 Jim Dougherty
2008-09-30 13:54 ` Mihai Donțu
2008-09-30 13:55 ` John Fine
0 siblings, 2 replies; 7+ messages in thread
From: Jim Dougherty @ 2008-09-30 13:40 UTC (permalink / raw)
To: gcc-help
I have a section of memory that I do not want to be initialized with
zeros when my program starts.
Is there a way to achieve this?
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-09-30 23:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <fc.3b9aca009a5ccd273b9aca0070320fb3.1629327@ecrm.com>
2008-09-30 14:03 ` Memory initialization (not) Jim Dougherty
2008-09-30 14:29 ` Eljay Love-Jensen
2008-09-30 14:30 ` Mihai Donțu
2008-09-30 23:35 Duane Ellis
-- strict thread matches above, loose matches on Subject: below --
2008-09-30 13:40 Jim Dougherty
2008-09-30 13:54 ` Mihai Donțu
2008-09-30 13:55 ` John Fine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).