Discussion:
[avr-libc-dev] [bug #45701] redundant stack initialization in crt1.o
anonymous
2015-08-05 16:03:14 UTC
Permalink
URL:
<http://savannah.nongnu.org/bugs/?45701>

Summary: redundant stack initialization in crt1.o
Project: AVR C Runtime Library
Submitted by: None
Submitted on: Wed 05 Aug 2015 04:03:13 PM UTC
Category: Library
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Startup code
Status: None
Percent Complete: 0%
Assigned to: None
Originator Email: ***@gmail.com
Open/Closed: Open
Discussion Lock: Any
Release: 1.8.0
Fixed Release: None

_______________________________________________________

Details:

It appears crt1.o always initializes the stack and clears SREG, even for
modern AVRs that don't require it.
While it is necessary for old AVRs like the mega8, since SPH/SPL is
initialized to 0 on reset (datasheet s. 7.5.1), on the tinyx5, tinyx4,
mega48/88/168/328, and many others SPH/SPL is initialized to RAMEND upon
reset. See, for example, s. 4.8.1 of the tiny84a datasheet.




_______________________________________________________

Reply to this item at:

<http://savannah.nongnu.org/bugs/?45701>

_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/
Georg-Johann Lay
2016-07-11 19:16:05 UTC
Permalink
Follow-up Comment #1, bug #45701 (project avr-libc):

The current startup code allows a custom value for SP init by defining symbol
__stack , for example: -Wl,--defsym,__stack=0x123 or by defining that symbol
in a custom linker description file.

Moreover it is not uncommon to (re)start an application by jumping to 0x0,
e.g. from a bootloader. If the startup code was "optimized" as proposed, that
code will no more work as expected.

_______________________________________________________

Reply to this item at:

<http://savannah.nongnu.org/bugs/?45701>

_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/
anonymous
2016-07-18 19:14:16 UTC
Permalink
Follow-up Comment #2, bug #45701 (project avr-libc):

Acutally a bootloader just jumping to 0x0 would not only be uncommon, it would
be shitty coding. All the bootloaders I have written ensure the registers are
in their reset state before jumping to the start of the application code.
Another option is to use a WDT reset like Optiboot.

_______________________________________________________

Reply to this item at:

<http://savannah.nongnu.org/bugs/?45701>

_______________________________________________
Message sent via/by Savannah
http://savannah.nongnu.org/

Loading...