嵌入式的设备如DSP上的栈空间是Kb级别,在函数内定义数组或申请空间都不能像linux下那样直接定义和申请,要么定义成全局的,要么指向一块划分好的空间,否则就会造成覆盖代码段等的问题。
片上有三片可读写的内存区域
L2:0x00800000-0x00880000 512Kb
L3:0x0C000000-0x0C400000 4Mb
DDR:0x80000000-0xFFFFFFFF 2Gb
DSP的所有变量,函数,以及程序员定义的地址都保存在这三片空间上,程序员在定义变量时,若没有特殊规定,则编译器自动把变量分配到可读写空间上的任意位置,所以当程序员使用int *p = 0x00810000;这种语法的时候,很有可能会覆盖掉程序保存变量和函数的空间,导致程序运行异常,因此需要一个.cmd文件来约束,哪些地方用来给程序员自己定义变量地址用,哪些地方用来给程序为变量和函数申请内存来用。
/******************************************************************************
* Copyright (c) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
/*
* Linker command file
*
*/
-c
-heap 0x8000
-stack 0x5000
/* Memory Map 1 - the default */
MEMORY
{
L1PSRAM (RWX) : org = 0x00E00000, len = 0x7FFF
L1DSRAM (RWX) : org = 0x00F00000, len = 0x7FFF
L2SRAM (RWX) : org = 0x00800000, len = 0x50000
L2SELFUSE : org = 0x00850000, len = 0x30000
MSMCSRAM (RWX) : org = 0xc000000, len = 0x20000
DATASRAM : org = 0xc100000, len = 0x200000
// FPGADATA : org = 0xc300000, len = 0x20000
NOCACHE : org = 0x50050000, len = 30000h
DDR3DATA (RWX) : org =0x80000000,len=0x10000000
DDR3 (RWX) : org = 0x90000000,len = 0x10000000
DDR3_MID (RWX) : org = 0xA0000000,len = 0x10000000
}
SECTIONS
{
.csl_vect > L2SRAM//srio测试可以放在L2或者L3上
.text > L2SRAM//srio测试可以放在L2或者L3上 //代码段
GROUP (NEAR_DP)
{
.neardata //已初始化的全局单变量
.rodata //带const修饰的已初始化的全局单变量
.bss //未初始化的全局单变量
} load > L2SRAM//srio测试可以放在L2
.stack > L2SRAM//srio测试可以放在L2 //栈
.cinit > L2SRAM//srio测试可以放在L2或者L3上 //程序初始化段
.cio > L2SRAM//srio测试可以放在L2 //printf用到的段
.const > L2SRAM//srio测试可以放在L2或者L3上 //带const修饰的全局多变量
.data > L2SRAM//srio测试可以放在L2或者L3上
.switch > L2SRAM//srio测试可以放在L2或者L3上 //switch表
.sysmem > MSMCSRAM//srio测试可以放在L2或者L3上 //堆,malloc
.far > L2SRAM//srio测试必须放在L2或者L3上 //未初始化的全局多变量
.testMem > L2SRAM//srio测试可以放在L2或者L3上
.fardata > L2SRAM//srio测试可以放在L2或者L3上 //已初始化的全局多变量
platform_lib > L2SRAM//srio测试可以放在L2或者L3上
.L2 > L2SRAM//srio测试可以放在L2或者L3上
.L3 > MSMCSRAM
.NoCache > NOCACHE
//必须放在MSMCSRAM
.qmssSharedMem: load >> MSMCSRAM
.cppiSharedMem: load >> MSMCSRAM
.i2ceeprom: load >> MSMCSRAM//i2ceeprom段必须放在MSMCSRAM
.emif16nandflash load >> MSMCSRAM//emif16nandflash段必须放在MSMCSRAM
.srioSharedMem > MSMCSRAM//srio放在msmc上的代码
.ChipIntc > MSMCSRAM //片级中断控制器的段
.Sharemem > MSMCSRAM //edma3多核测试main.c程序中的段
.timerSharedMem > MSMCSRAM //timer多核测试main.c程序中的段
//必须放在L2上
.srioL2Mem > L2SRAM//srio放在L2上的代码
.qmssL2Mem: load >> L2SRAM//qmss放在L2上的代码
.cppiL2Mem: load >> L2SRAM//cppi放在L2上的代码
.CoreIntcL2Mem: load >> L2SRAM//coreintc放在L2上的代码
.edma3 load >> L2SRAM//edma3放在L2上的代码
.DDRDATA: load>> DDR3DATA
.DDR3_MID: load>> DDR3_MID
}
MEMORY中定义的是所有内存的分配情况,SECTIONS定义的是每一块内存上定义了些什么东西。
//必须放在MSMCSRAM
.qmssSharedMem: load >> MSMCSRAM
.cppiSharedMem: load >> MSMCSRAM
.i2ceeprom: load >> MSMCSRAM//i2ceeprom段必须放在MSMCSRAM
.emif16nandflash load >> MSMCSRAM//emif16nandflash段必须放在MSMCSRAM
.srioSharedMem > MSMCSRAM//srio放在msmc上的代码
.ChipIntc > MSMCSRAM //片级中断控制器的段
.Sharemem > MSMCSRAM //edma3多核测试main.c程序中的段
.timerSharedMem > MSMCSRAM //timer多核测试main.c程序中的段
//必须放在L2上
.srioL2Mem > L2SRAM//srio放在L2上的代码
.qmssL2Mem: load >> L2SRAM//qmss放在L2上的代码
.cppiL2Mem: load >> L2SRAM//cppi放在L2上的代码
.CoreIntcL2Mem: load >> L2SRAM//coreintc放在L2上的代码
.edma3 load >> L2SRAM//edma3放在L2上的代码
.DDRDATA: load>> DDR3DATA
.DDR3_MID: load>> DDR3_MID
定义的是C6455库的内存分配方式,若要使用哪种库,就必须按照相应的规则去定义。