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)
}
RAM1 0x10000000
{
LOADADDR __data_lmastart
ADDR __data_start
* (+RW, +ZI)
}
}
ROM2 0x10804000
{
SEC1 0x10804000
{
* (.section1)
}
}
The point above is the ROM2 address.
ROM2 0x10804000
{
SEC1 0x10804000
{
* (.section1)
}
}The lma and vma of .section1 are the same.Then use the nds_ldsag to generate *.ld file.
Attachment:
ld.gif [ 2.71 KiB | Viewed 7387 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:
3 .section0 00000004 10800000 0000012c 00002000 2**2
CONTENTS, ALLOC, LOAD, DATA
......
9 .section1 0000000e 10804000 10804000 00004000 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
Another thing I would like to mention.
In this program, the vma of .section0 is different from LMA.
So we should copy .section0 from their LMA to VMA in real case.
3 .section0 00000004 10800000 0000012c 00002000 2**2
CONTENTS, ALLOC, LOAD, DATA
......
9 .section1 0000000e
10804000 10804000 00004000 2**1
CONTENTS, ALLOC, LOAD, READONLY, CODE
Here is the example:
Attachment:
assign-lma.zip [21.59 KiB]
Downloaded 703 times
related article:
viewtopic.php?f=25&t=753&p=884