Andes Workshop

It is currently Mon Aug 26, 2019 2:14 pm

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: User defined sections (lma=vma)
PostPosted: Fri Dec 06, 2013 11:40 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
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 3388 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 246 times


related article:
viewtopic.php?f=25&t=753&p=884


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group