Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
8 years ago

Defining a code section besides ".text" section

Hello,

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");

function();

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,
No RepliesBe the first to reply