Andes Workshop

It is currently Wed Nov 21, 2018 9:24 pm

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: 把某些text放到SRAM上執行的example
PostPosted: Tue Jul 31, 2012 4:00 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
下面有一小段code,

Code:
int main(void) {

    int result;

   result=add(1,2);
   result=mul(3,4);
   return EXIT_SUCCESS;
}


其中add()這個function我要放到flash上,
在執行前要搬到copy到ram裡,
使得add()在ram上執行。

步驟:
(1) 在linker script裡,要定義add的text在特定區域裡執行。
Code:
  .text2 : {
        PROVIDE (_begin_text2 = . );
      add.o (.text)
        PROVIDE (_end_text2 = .);
   }>SDRAM AT>FLASH

其中>SDRAM AT>FLASH表示放在flash裡,(lma在flash裡)
執行時在SDRAM裡。(vma在SDRAM裡)

我們從elf檔可知,text2的VMA在0x8000,LMA在0x40。

Code:
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .nds32_init   00000040  00000000  00000000  00001000  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text2        00000034  00008000  00000040  00002000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .text         0000014c  00000074  00000074  00002074  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE




(2)在執行add()之前,必須要先將code從flash copy到ram裡。
如果覺得執行速度太慢,也有人用硬體實作搬移的工作。
Code:
int copy_text2(void) {

    int size;
    int text2_vma_begin, text2_vma_end, text2_lma_begin;

    text2_vma_begin=(unsigned int)&_begin_text2;
    text2_vma_end=(unsigned int)&_end_text2;
    text2_lma_begin=(unsigned int)&_lma_text2;

    size=text2_vma_end-text2_vma_begin;

    /* copy mul from lma to vma */

   volatile unsigned int *src = (volatile unsigned int *)text2_lma_begin;
   volatile unsigned int *dest = (volatile unsigned int *)text2_vma_begin;

   while (size > 0) {
      *dest++ = *src++;
      size = size - 4;
   }
   return 0;
}


之後main呼叫時,就和一般的程式相同。


完整的example:
Attachment:
text_n8.zip [89.41 KiB]
Downloaded 695 times


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 30 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