DSPRelated.com
Forums

Re: Execution never reaches the 'main' function unless I do several

Started by Andrew Nesterov December 1, 2006
Hi Timothy,

> Re: Execution never reaches the 'main' function unless I do several
> Posted by: "Timothy Fosdike" t...@dspace.com.au
> Date: Thu Nov 30, 2006 7:10 am ((PST))
>
> Hi Carlos,
>
> By my understanding, the _auto_init function initializes C++ objects
> that have been statically allocated (compiled in). The other functions
> are initializing data memory segments such as .data and .bss.

Don't recall exactly about .data section, but TI linker never initializes
.bss, unless vars declared there were explicitly initialized.

> My guess at your problem is that you have allocated some memory segment
> over the top of some registers. Note that any memory that is not
> explicitly allocated will be allocated at the lowest possible address.
> This may overwrite memory-mapped registers, causing the incorrect
> behaviour that you have seen.

If that were this simple. I've been working with TI processors for a
long time, and this problem was always there, appearing between builds.
The reason might be anywhere except the allocation strategy, which works
fine even if there were no .cmd file specified, in that case a default
allocation rules (see description of lnk6x) are applied. In fact the
linker knows processor memory map and would never overwrite memory
mapped registers region, unless a memory section was erroneously mapped
there in the project's .cmd/.lcf file using an absolute address of the
peripheral bus.

I've never fought over the problem of "not reaching the main() function"...
Sometimes it may happen, so I usually reset the processor, or restart CCS,
or increase amount of .stack memory, or reload the binary image several times.

> I think this should be written down somewhere as the #1 trap for
> beginners on TI DSPs!

So do I, although there are several more problems which could also be
good candidates for the #1 traps :) E.g. sometimes stdout would strangely
refuse to work (printf(),puts() do not print anything, and even fflash()
does not help).

Sorry that my email actually poses more questions instead of giving answers.

Rgds,

Andrew

> Regards,
>
> Timothy
>
> -----Original Message-----
> From: c... [mailto:c...] On
> Behalf Of Carlos Ojea
> Sent: Wednesday, 29 November 2006 8:11 PM
> To: c...
> Subject: [code-comp] Execution never reaches the 'main' function unless
> I do several 'steps into' pressing F11
>
> I am using code composer studio and a xds560r emulator to connect to a
> ti davinci cpu (6416 dsp)
>
> When I load a program onto CPU target and I try to run it, it never
> reaches the 'main' function !!
>
> I have to do several 'steps into' pressing F11 until I reach some
> funtions like '$C$L6' and only then if I press the 'run target' button I
> could reach the 'main' function. Someone knows what is happening?
>
> During my 'step into' journey I saw some initialization functions like
> '_auto_init', $C$L1, memcpy, $C$RL0, $C$L5 ...
>
> Where could I get information about these functions and their utility?
>
> Many thanks,
>
> Carlos
>
>
> If that were this simple. I've been working with TI processors for a
> long time, and this problem was always there, appearing between builds.
Oh, no! I thought the problem goes away if I put almost all sections on DDR2
instead of IRAM.
So, do you think the problem will appear again soon or later ?

Thanks and regards,
Carlos
--- In c..., Andrew Nesterov
wrote:
> Hi Timothy,
>
> > Re: Execution never reaches the 'main' function unless I do several
> > By my understanding, the _auto_init function initializes C++ objects
> > that have been statically allocated (compiled in). The other
functions
> > are initializing data memory segments such as .data and .bss.
>
> Don't recall exactly about .data section, but TI linker never
initializes
> .bss, unless vars declared there were explicitly initialized.
>

I'm not sure if you are using C++ or C, but we have run into a similar
problem with static objects in C++.

Remember that static objects are initialized before main runs. If you
are using classes, this can mean that any static object can contain
code rather than simple initialization. We have, in more than one
occasion, run into issues were a lot of code runs before main. Twice
we've ended up with a infinite loop or recursive function calls and
main was never reached.

If you're only using simple types, this isn't a problem. This isn't
unique to TI, but a long standing C/C++ initialization problem.

PS> That stdout/printf problem misteriously not working is a real
thorn in our side too!

Good luck,
Matt Townsend
> Date: 01-Dec-2006 01:20:30 -0800
> From: Carlos Ojea
> To: Andrew Nesterov
> Cc: c...
> Subject: Re: [code-comp] Re: Execution never reaches the 'main' function
> unless I do several
>
> >
> > If that were this simple. I've been working with TI processors for a
> > long time, and this problem was always there, appearing between builds.
> Oh, no! I thought the problem goes away if I put almost all sections on DDR2
> instead of IRAM.
> So, do you think the problem will appear again soon or later ?

Well, we'll see.

Fundamentally, RAM is RAM, its physical characteristics may vary, but
there has to be no difference for the CPU to execute up to the main() address
wherever address of the .text section is allocated, in IRAM, SDRAM, ZBT,
SBSRAM, DDR, DDR2, etc. The only difference is access time, the other things
(like refresh rate) are handled by the external memory controller.

Sorry again that there are no answers...

Rgds,

Andrew

> Thanks and regards,
> Carlos
>
We are using only .c and .asm
Today I saw the problem again. It reached the main function the second time
I tried to run the program ...
Thanks and regards,
Carlos