_low_level_init() / _init_startup *solved*

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

Hi Freaks,

I have a function for IAR called __low_level_init(). I know, it is called before main().
Now I'm porting it to gcc. I allready found out, that I have to use _init_startup() for this.

But now, I cannot find any documentation about this and I have a few open questions.

1. Is the _init_startup() allready somehow 'filled' with code, so that I have to expand it with my code? Or is it a normaly empty function which I can just fill with my code?

2. How can I be sure, that this function is really called during startup? I compilled my software with the _init_startup() in it, but when checking the .lss file I cannot find any jump to this function.

Baldrian

Last Edited: Mon. Sep 29, 2008 - 01:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whenever I have ported IAR code, I have just explicitly called __low_level_init() at the beginning of main().

I have never looked at crts.s ( or equivalent ).

If there is an empty sub there, you could always just #define __low_level_init _some_gcc_stub and do things transparently.

Personally I would prefer to know about what functions I am calling, so prefer the explicit call. ( I just enclose with a #ifndef __IAR_whatever___ conditonal).

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void __low_level_init() __attribute__((__naked__, section(".init3")));
void __low_level_init()
{


}

Baldrian wrote:
2. How can I be sure, that this function is really called during startup?
.initX sections are declared with KEEP() in linker scripts, so anything in .initX can't be flushed by linker durind garbage collection. You can find more information about .initX sections in avr-libc documentation.

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

Alternatively, make the function prototype use the "constructor" attribute to force it to be called at the appropriate time before the main routine -- no messing with the initialization sections or linker scripts required.

void __low_level_init() __attribute__((constructor));
void __low_level_init()
{


}

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

innocent_bystander wrote:

void __low_level_init() __attribute__((__naked__, section(".init3")));
void __low_level_init()
{


}

Baldrian wrote:
2. How can I be sure, that this function is really called during startup?
.initX sections are declared with KEEP() in linker scripts, so anything in .initX can't be flushed by linker durind garbage collection. You can find more information about .initX sections in avr-libc documentation.

Nice. That helped. Now I can see the low_level_init at the right position in the .lss file :-)

Thanks alot :D
Baldrian

Edit: And also thanks to abcminiuser. Yout tip is also very appreciated.

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

abcminiuser wrote:
no messing with the initialization sections or linker scripts required.
Yes, but it adds unnecessary code overhead to call/ret.

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