This article demonstrates how to put a variable or a function on user-defined sections.
In other words, you can assign address of some variables or functions.
First, write your own sag file.
Code:
USER_SECTIONS .section0, .section1
ROM 0x0
{
RAM 0x0
{
STACK = 0x10800000
* (+RO)
}
SEC0 0x10800000
{
* (.section0)
}
SEC1 0x10804000
{
* (.section1)
}
RAM1 0x10000000
{
LOADADDR __data_lmastart
ADDR __data_start
* (+RW, +ZI)
}
}
Then use the nds_ldsag to generate *.ld file.
Attachment:
ld.gif [ 2.71 KiB | Viewed 6878 times ]
In program, we should specify the address of variables and functions.
The syntax is :
Code:
int number1 __attribute__((section(".section0")))=1234;
int addnum(int, int) __attribute__((section(".section1")));
The following is the full program:
Code:
/*
* main.c
*
* Created on: 2013/11/14
* Author: hylai
*/
int number1 __attribute__((section(".section0")))=1234;
int addnum(int, int) __attribute__((section(".section1")));
int main(){
addnum(3,number1);
return 0;
}
int addnum(int x, int y)
{
return (x+y);
}
It works. The following is the symbol table.
Code:
10800000 D number1 E:\Andestech\AndeSight201MCU\mcu\workspace\assign\Debug/../main.c:8
10804000 T addnum E:\Andestech\AndeSight201MCU\mcu\workspace\assign\Debug/../main.c:19
Another thing I would like to mention.
In this program, the vma of .section0 and .section1 are different with LMA.
So we should copy .section0 and .section1 from their LMA to VMA in real case.
Idx Name Size
VMA LMA File off Algn
4 .section0 00000004
10800000 00000120 00002000 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .section1 0000000e
10804000 00000124 00003000 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
Here is the example:
Attachment:
assign.zip [20.58 KiB]
Downloaded 727 times
related article:
viewtopic.php?f=25&t=760&p=893