Andes Workshop

It is currently Thu Mar 28, 2024 11:17 pm

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: User defined sections
PostPosted: Thu Nov 14, 2013 3:43 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)
    }
  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
ld.gif [ 2.71 KiB | Viewed 6794 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 702 times


related article:
viewtopic.php?f=25&t=760&p=893


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 6 guests


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