avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Missing "call main()" in startup code


From: Georg-Johann Lay
Subject: Re: [avr-gcc-list] Missing "call main()" in startup code
Date: Tue, 15 Nov 2011 18:40:50 +0100
User-agent: Thunderbird 2.0.0.24 (X11/20100302)

Dave Harper wrote:
> Target MCU: XMega32A4
> WinAVR: WinAVR-20100110
> Studio: v4.18 Build 716
> 
> I recently completed initial debug of a bootloader for the above target
> device.  The bootloader is fairly large and, to keep from overflowing
> the 4K bootloader flash area, I used the "-nostartfiles" linker flag to
> eliminate the vector table since interrupts are not being used.  While
> debugging using the Studio debugger, I compiled using the -O0 option to
> remove optimizations.  The compiler produced normal startup code which,
> at the end, "fell" into main().  Once debugging was complete, I
> recompiled with -Os.  Not surprisingly, the order of the code was
> restructured with the main() entry point appearing further down in the
> code, proceeded by several functions.  What was missing was a call to
> the main() entry point at the end of the startup code.  When I removed
> the -nostartfiles linker option (still using -Os optimization) I found
> that the call to main() was included.  Unfortunately, inclusion of the
> vector table - which uses 376 bytes, just about offsets any savings
> gained from the -Os optimization.  This puts me very close to the 4K
> limit again.  I'd really like to have this extra space as the next step
> (interaction between the application and bootloader) will use a debug
> mechanism which uses values written to an I/O port that are monitored by
> a logic analyzer to trace the path of execution, as well as variable
> values.  While these individual debug statements don't take much room
> individually, I will be limited in the number I can put in the code at
> any given time.
> 
> Also, as a check, I downloaded the latest Studio 5.0 and recompiled
> using it (GCC v4.5.1).  Same thing.
> 
> Anyone have any ideas on a workaround that might get me past this problem?

If you kick out the start-up code, you are left alone to add the relevant bits:

* Initializing zero-reg and SP
* Clean .bss
* Set-up .data
* Call constructors/destructors
* Call main
* Call _exit
* Initialize vector table

For parts of start-up code coming from libgcc, see [1] and search for .init.
For parts of start-up code coming from avr-libc see [2], in particular section
.init9.


[1]
http://gcc.gnu.org/viewcvs/trunk/libgcc/config/avr/lib1funcs.S?content-type=text%2Fplain&view=co

[2]
http://svn.savannah.nongnu.org/viewvc/trunk/avr-libc/crt1/gcrt1.S?root=avr-libc&view=co

> Thanks,
> Dave

Johann




reply via email to

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