Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

Set function section

Altera_Forum
Honored Contributor II
757 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
82 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.
Altera_Forum
Honored Contributor II
82 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;
Altera_Forum
Honored Contributor II
82 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.
Reply