.data, .bss, .noinit

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello! Can anyone point me some good docs on the meaning of these sections (and there are probably others as well), and what they should contain and why?

Also, how can I put some code into the initialization section of an app, (the one that would run BEFORE main() gets called? Like stack initialization and stuff like that)

Thx,
axos88

axos88

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The memory sections area of the avr-libc documentation: http://www.nongnu.org/avr-libc/u...

Look at the .init3 section ( http://www.nongnu.org/avr-libc/u... ) example for executing code prior to the start of main().

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

axos88 wrote:

Also, how can I put some code into the initialization section of an app, (the one that would run BEFORE main() gets called? Like stack initialization and stuff like that)

And you don't trust the compiler initializes the stack for you?

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was wondering if he meant that, Jepal, or meant having code execute around the same time as (ideally after!) stack initialization. I assumed the latter, but I think your statement about the former is a good safety remark.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wondered if he meant what I do in most programs - have something running in .init3 that floods all of SRAM with a recognisable value like 0xAA or something that runs before the .data copy and the .bss wipe and before the stack begins to be used.

Later if you stop the code in the debugger and look at the area between the top of .bss and the current bottom of the stack and find some 0xAA's there you know the two have not collided.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff: that's a nice description on how to integrate with GCC the techique of catching stack overflows by overwriting a known, preexisting value.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually I want to initialize my own HEAP structure, so that I don't have to call manually heap_init() as first thing in the main(). Thanks for your input

axos88

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff, I don't see it in the avr-libc files, but do they define the end of I/O (and extended I/O) memory space so that when you overwrite the SRAM that you know what is the first memory location of SRAM?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd take a look at the source for the real malloc() in the library but if the heap really needs some kind of initialisation wouldn't you just do it within malloc:

void * malloc(int n) {
 static initialised;

 if (!initialised) {
  // do the init stuff
  initialised = 1;
 }

 // normall malloc stuff
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually I was aiming for minimal code and execution time, but let's just say I want it this way, just b'caz... I'm hard-headed or something :)

Anyways, putting the code in .initN works, now I'll only have to find a way to make it work if the whole thing is put into the library (because it will not be referenced, and thus not linked) But I have opened another thread on this subject, please post there if you have any suggestions: https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=60011

axos88

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Cliff, I don't see it in the avr-libc files, but do they define the end of I/O (and extended I/O) memory space so that when you overwrite the SRAM that you know what is the first memory location of SRAM?
I'm not Cliff, but what I do is use the linker provided '_end', since there's no use in 'marking' sram that will shortly be overwritten by the startup code (and also preserves the .noinit section).

I'm not sure how to get hold of the actual sram start address except through linker provided '__data_start'. I think the only place its known is by gcc and passed to the linker (data section start address). I'm guessing, though.

bottom of file-
http://www.mtcnet.net/~henryvm/4...
is where I clear sram.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the info, Curt. _end works very well -- thanks!