F28027第七课---CMD文件

来源:互联网 发布:穿越火线mac官方下载 编辑:程序博客网 时间:2024/05/06 08:53

断断续续看了两天CMD的知识,只是肤浅的了解一点,勿怪。

CMD文件实现对程序存储器空间和数据存储器空间的分配。这个链接器文件主要有两大部分, MEMORY部分和SECTIONS部分。其中MEMORY部分就是芯片内存相对应的部分,包括PAGE 0——默认的是程序代码的内存部分,PAGE 1 是变量代码的内存部分。选址可以自定义,比如定义Flash 是定义片上的闪存部分,起始地址、长度也是和对应的芯片相对应。SECTIONS部分有通常的链接器默认名,“·text”、“·ebss”等等,要指定这个代码映射到某一个位置所对应的PAGE 是0 还是1。

现在目标很明显,就是学习MEMORY和SECTIONS相关的概念和操作。

首先来说MEMORY

常见的MEMORY操作示例如下:


看完样例,我们就需要具体分析MEMORY每个字段和符号的含义了,这样方便我们更能深入了解系统运行,先来看下MEMORY的结构:

 

 

其中page---指定要使用的存储器页面,name---存储名字(A-Z, a-z, $, .,  _),attr---属性(R/W/X/I),oraigin---起始地址,length---存储长度,fill---默认填充内容。


这个是每个字段都保留了的样例,MEMORY到这里就差不多讲完了,相对SECTIONS是比较简单的,知识简单的罗列了每个内存段的起始地址 和长度等消息而已。

下面我们来看下相对复杂的SECTIONS部分。

SECTIONS部分是具体的段到内存的映射关系列表,操作格式如下:


name就是段名,主要有默认段和自定义段,其中默认段主要有以下几个:


默认段主要是存储常量、变量、代码等相关参数的已初始化和未初始化数据段,自定义段主要是用户自己以寄存器命名的相关段,等下后面示例我们会讲到。

下面我们重点看下name后面的属性参数:


这里注意,=和>是等价的操作符。这几个参数是段的加载地址、运行地址、输入加载文件段、属性和默认值,下面来看个样例:


除了上面基本属性外,还有几个重要的概念:


上样例:


最后上一个整体的样例程序:

MEMORY
{
PAGE 0 :
   /* For this example, L0 is split between PAGE 0 and PAGE 1 */
   /* BEGIN is used for the "boot to SARAM" bootloader mode   */

   BEGIN      : origin = 0x000000, length = 0x000002
   RAMM0      : origin = 0x000050, length = 0x0003B0
   PRAML0     : origin = 0x008000, length = 0x000900
   RESET      : origin = 0x3FFFC0, length = 0x000002

   IQTABLES   : origin = 0x3FE000, length = 0x000B50     /* IQ Math Tables in Boot ROM */
   IQTABLES2  : origin = 0x3FEB50, length = 0x00008C     /* IQ Math Tables in Boot ROM */
   IQTABLES3  : origin = 0x3FEBDC, length = 0x0000AA/* IQ Math Tables in Boot ROM */

   BOOTROM    : origin = 0x3FF27C, length = 0x000D44

PAGE 1 :

   /* For this example, L0 is split between PAGE 0 and PAGE 1 */
   BOOT_RSVD   : origin = 0x000002, length = 0x00004E     /* Part of M0, BOOT rom will use this for stack */
   RAMM1       : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
   DRAML0      : origin = 0x008900, length = 0x000700
}

SECTIONS
{
   /* Setup for "boot to SARAM" mode:
      The codestart section (found in DSP28_CodeStartBranch.asm)
      re-directs execution to the start of user code.  */
   codestart        : > BEGIN,     PAGE = 0
   ramfuncs         : > RAMM0      PAGE = 0
   .text            : > PRAML0,    PAGE = 0
   .cinit           : > RAMM0,     PAGE = 0
   .pinit           : > RAMM0,     PAGE = 0
   .switch          : > RAMM0,     PAGE = 0
   .reset           : > RESET,     PAGE = 0, TYPE = DSECT /* not used, */

   .stack           : > RAMM1,     PAGE = 1
   .ebss            : > DRAML0,    PAGE = 1
   .econst          : > DRAML0,    PAGE = 1
   .esysmem         : > RAMM1,     PAGE = 1

   IQmath           : > PRAML0,    PAGE = 0
   IQmathTables     : > IQTABLES,  PAGE = 0, TYPE = NOLOAD

  /* Uncomment the section below if calling the IQNexp() or IQexp()
      functions from the IQMath.lib library in order to utilize the
      relevant IQ Math table in Boot ROM (This saves space and Boot ROM
      is 1 wait-state). If this section is not uncommented, IQmathTables2
      will be loaded into other memory (SARAM, Flash, etc.) and will take
      up space, but 0 wait-state is possible.
   */
   /*
   IQmathTables2    : > IQTABLES2, PAGE = 0, TYPE = NOLOAD
   {
              IQmath.lib<IQNexpTable.obj> (IQmathTablesRam)
   }
   */
   /* Uncomment the section below if calling the IQNasin() or IQasin()
      functions from the IQMath.lib library in order to utilize the
      relevant IQ Math table in Boot ROM (This saves space and Boot ROM
      is 1 wait-state). If this section is not uncommented, IQmathTables2
      will be loaded into other memory (SARAM, Flash, etc.) and will take
      up space, but 0 wait-state is possible.
   */
   /*
   IQmathTables3    : > IQTABLES3, PAGE = 0, TYPE = NOLOAD
   {
              IQmath.lib<IQNasinTable.obj> (IQmathTablesRam)
   }
   */
}

迷迷糊糊的就把CMD这部分讲完了,又是似懂非懂的,可能我真的太笨了,没办法,只有多动手写才行了。

从下节课开始,就进入边讲边实战的模式了,代码和仿真图我也会相应的上传上去,做完所有实践后,模拟一个项目,然后去打样,买器件,动手做板调试,好激动啊,呵呵,我要去准备下相应的环境和工具了。

菜鸟交流qq群107691092


 

1 0
原创粉丝点击