Andes Workshop
http://forum.andestech.com/

User defined sections (lma=vma)
http://forum.andestech.com/viewtopic.php?f=25&t=760
Page 1 of 1

Author:  cindy [ Fri Dec 06, 2013 11:40 pm ]
Post subject:  User defined sections (lma=vma)

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
ld.gif [ 2.71 KiB | Viewed 7392 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

Page 1 of 1 All times are UTC + 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/