Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Set function section

Altera_Forum
Honored Contributor II
986 Views

how do i put a function or a code file in a specific memory section? 

other than .text... 

 

tnx...
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
311 Views

Add (IIRC) __attribute__((section("section_name"))) to the definition, 

either at the end of a declaration, or (I think) before the function name itself.
0 Kudos
Altera_Forum
Honored Contributor II
311 Views

The attribute directive must be added after the function declaration. 

 

For example you declare: 

int myFunction (void) __attribute__ ((section (".onchip_mem_code"))); 

 

Then the function definition without any attribute: 

int myFunction (void) 

// function body 

 

 

Similarly for data, except here you must specify attribute when you define the variable, not when you declare it: 

int myVariable __attribute__ ((section (".onchip_mem_data"))); 

For external referencing the variable, don't use any attribute: 

extern int myVariable;
0 Kudos
Altera_Forum
Honored Contributor II
311 Views

You can also put the section attribute before the function name, eg: 

 

static __attribute__((section(".text.foo"))) int foo(void) { /* function body */ } 

 

(It can go either side of the return type, not sure which is preferred.) 

For non-static functions this rather depends on whether you want the section info in the .c file or the .h one. 

 

For data, the section in an 'extern' is used to determine whether to use 'small data' (%gp relative) addressing (.sdata or .sbss). The location of the data itself depends on the actual definition.
0 Kudos
Reply