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++
12600 Discussions

Defining a code section besides ".text" section

Honored Contributor II



I am working with a design that includes: 

- Nios II processor version "e" 

- On chip memory dedicated for data and instructions 


I used the SBT to write a function in assembly langage. This function is called in main: 


void function() __attribute__((section(".function"))); 


int main() 

alt_printf("Hello function\n\r"); 


return 0; 


Actually, I added to the linker file a section ".function" that will contain the code of the function. I have defined it after the ".text" section. 


.text : 

} > memory = 0x3a880100 /* NOP instruction (always in big-endian byte ordering) */ 


.function : AT ( LOADADDR (.text) + SIZEOF (.text) ) 

PROVIDE (function_mem_start = ABSOLUTE(.)); *(.function) 

. = ALIGN(4); 

PROVIDE (function_mem_end = ABSOLUTE(.)); 

} > memory 



The problem is that when I execute my code, it never runs the "function()" code. Each time the nios reaches "function", it restarts the execution of the program from the beginning. Hence, I get an infinite "Hello function" printed in the console. However when I delete "__attribute__((section(".function")))" from the main program, the program is executed correctly and my function code is saved in the ".text" section. 


My question is, why I can't execute a program from a section other than ".text" and what should I do to make it possible? 


Thank you,
0 Kudos
0 Replies