avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Startup code.


From: Erik Christiansen
Subject: Re: [avr-chat] Startup code.
Date: Thu, 23 Sep 2010 01:03:51 +1000
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

On Wed, Sep 22, 2010 at 02:51:15PM +0200, Robert von Knobloch wrote:
> OK Erik,
> 
> I think I can see the mechanism now.

Very close, now. :-)

> The crt[tn13].o seems to be complied from avr-libc-1.4.6/crt1/gcrt1.S
> which has:
> ==========================================================================
> #ifndef __AVR_ASM_ONLY__
>       .weak   __stack
> 
>       /* By default, malloc() uses the current value of the stack pointer
>          minus __malloc_margin as the highest available address.
> 
>          In some applications with external SRAM, the stack can be below
>          the data section (in the internal SRAM - faster), and __heap_end
>          should be set to the highest address available for malloc().  */
>       .weak   __heap_end
>       .set    __heap_end, 0
> 
>       .section .init2,"ax",@progbits
>       clr     __zero_reg__
>       out     _SFR_IO_ADDR(SREG), __zero_reg__
>       ldi     r28,lo8(__stack)
> #ifdef SPH
>       ldi     r29,hi8(__stack)
>       out     _SFR_IO_ADDR(SPH), r29
> #endif
>       out     _SFR_IO_ADDR(SPL), r28
> ==========================================================================
> This means that the __stack value is determined at the time of compiling
> avr-libc. It is marked as weak, so I can override it's value in my
> source file (tested). 

Errm, this file doesn't give a value to __stack. That's why it's still
undefined in crttn13.o. The default value originates elsewhere, not that
it's critical.

> It's a shame that not all the .init[x] sections
> aren't marked as weak so they could be individually overwritten (.init0 is).

They're code. Different mechanism. You can see that the conditional
assembly elides two lines if SPH isn't defined, as is the case for tiny
13. It is easy to do the same with anything else which might need to be
managed.

> Either I live with the (admitted small - but on these parts every byte
> counts when you're up against the end stops) penalty of some redundant
> code or I modify my avr-libc and recompile as a non-standard toolchain.

Ah, but there is no redundant code. This code initialises SREG and SPL
for you, using your overwritten __stack value, when you choose to apply
it. Whack in a #def, a command line -D, or a linker script assignment,
to set __stack, and it's good to go. You're not adding any run-time
code to set your value.

> I checked the latest release and the code here is still the same.

That could be 'cos it's OK as is. ;-)

> Anyway, many thanks for your comments Erik, I wish you good health,

Thank you kindly.

Have fun with all those variable silicon shipments.
They'll keep you on your toes, by the look of it.

Erik



reply via email to

[Prev in Thread] Current Thread [Next in Thread]