Reply by Dan Lyke August 15, 20092009-08-15
On Sat, 15 Aug 2009 08:34:33 -0000
"gene_klein2000" wrote:
> The problem is when I use a class the system goes crazy.

Huh. I have several classes instantiated globally with no problems.
However, in looking back at my code I am just using it for code
organization, no vtables, no constructor code, and I'm not using any
dynamic allocation.

Sorry for that dead-end.

Dan
Reply by gene_klein2000 August 15, 20092009-08-15
Thanks Dan,

Already did this.

The problem is when I use a class the system goes crazy.

Added this code to board_startup.S for initializing the constructors

/* call C++ constructors of global objects */

LDR r0, =__ctors_start__
LDR r1, =__ctors_end__
ctor_loop:
CMP r0, r1
BEQ ctor_end
LDR r2, [r0], #4
STMFD sp!, {r0-r1}
MOV lr, pc
BX r2
LDMFD sp!, {r0-r1}
B ctor_loop
ctor_end:

/* Branch to main() */

to the linker file I've added

. = ALIGN(0x4);
PROVIDE(__ctors_start__ = .);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
PROVIDE(__ctors_end__ = .);

. = ALIGN(4);
_efixed = .;

And made a small class like this

class TOptel
{
public :
int getal;

TOptel()
{
getal = 0;
}

void Task()
{
getal++;
}

};
extern TOptel Optel;

I've verified the calling of the constructor for this class.
A simple debug print in the constructor and i see the text.
So it is called.

The main loop is like this

int main()
{
unsigned long teller = 0;

// setup debug port
DBGU_Configure( DBGU_STANDARD, 115200, BOARD_MCK );

LED_Configure( LED_YELLOW );

// Optel.Task();

// the main loop
while( 1 )
{
teller ++;
if( teller >= 5000000 )
{
teller = 0;

LED_Toggle( LED_YELLOW );

DBGU_PutChar('"x' );
}

}
}

Normally this put an X on the terminal window every second or so.
As soon as I uncomment the line Optel.Task();
The terminal window is filled with X's.
And the delay is no more there
What is the problem here, what am I doing wrong ???
Thanks for any help,

Gene
Reply by Dan Lyke August 14, 20092009-08-14
On Fri, 14 Aug 2009 18:36:39 -0000
"gene_klein2000" wrote:
> I would like to start programming in c++ on a at91sam9260-ek.
>
> Is there anyone who can help me with the linker file and startup code
> for the constructors\destructors(if i need them).

On the AT91SAM9XE-EK, I just set up my Makefile to have C++ targets,
basically everywhere I had a CC I duplicated it with CXX and made the
appropriate change in the dependency rules from .c to .cxx compiled 'em
with $(CROSS)g++, and everything worked.
A quick look through my Makefile... Add

CXX = $(CROSS)g++
# like CFLAGS, except no -std -fgnu89inline
CXXFLAGS = -mlong-calls -ffunction-sections -Wall
# and just like CFLAGS
CXXFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP)

Setup your CXX_OBJECTS just like your C_OBJECTS (remember that you'll
need to "extern C {...}" your include files to call C_OBJECTS compiled
bits:

CXX_OBJECTS = main.o
CXX_OBJECTS += ...

Down in your "define RULES" section, do something similar to the
C_OBJECTS with CXX_OBJECTS and make sure you add $$(CXX_OBJECTS_$(1))
to the dependencies for your $(1)

CXX_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(CXX_OBJECTS))

$$(CXX_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.cxx Makefile
$(CXX) $(CXXFLAGS) -D$(1) -c -o $$@ $$<
Dan
Reply by gene_klein2000 August 14, 20092009-08-14
Hi,

I would like to start programming in c++ on a at91sam9260-ek.

Is there anyone who can help me with the linker file and startup code for the constructors\destructors(if i need them).

What I'm using now is the AT91lib & getting started as an starting point.

My compiler are the Yagarto tools.

thanks ,
gene