免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1575 | 回复: 0
打印 上一主题 下一主题

Linker Script的使用/MPLAB开发环境 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-20 09:44 |只看该作者 |倒序浏览

链接脚本的使用极大方便了开发人员控制代码的存储位置和存储空间,以下是从文档中摘取的链接脚本典型案例,供参考。

MPLAB-C18-Getting-Started_51295f.pdf

6.5 SECTIONS

As described above, sections are the various areas in PIC18XXXX memory, including program memory, file register (data) memory, EEDATA nonvolatile memory and data stack memory, among others.

Usually sections are needed for program memory and data memory. As the design becomes more sophisticated, other section types may be required.

Sections are defined in the linker scripts. Here is the linker script for the PIC18F452:

EXAMPLE 6-1: PIC18F452 SAMPLE LINKER SCRIPT

This linker script defines the main program memory with the name page extending from address 0x002A to 0x7FFF. When a #pragma code directive is encountered, the compiler will generate machine code instructions to be placed in this area.

在代码中使用了# pragma code segm1c = 0xXXXX,即指定了这个位置之后的代码在代码段中的位置,同时注意在链接脚本中给这段代码分配合适的空间。

Data memory is defined for the six file register banks (gpr = General Purpose Register bank) of the PIC18F452. Due to the nature of banked memory on the PIC18XXXX, these six regions are defined as separate sections. When #pragma udata and

#pragma idata directives are encountered, the compiler will reserve areas in these file register banks for storage of the variables subsequently defined.

The accessram and accesssfr sections define the Access RAM areas in data memory.

Note that some areas are marked “PROTECTED”. This means that the linker will not put code or data into those areas unless specifically directed. To put code or data into a protected area, use the #pragma directive as shown here:

链接脚本中的"protected"意味着如果你要在这个区域放置代码,你必须先在要放置的代码前面添加#pragma这个预处理指令。

#pragma code page

This will cause the subsequent instructions to be compiled in the page section, usually the main program memory area as defined in the linker script.

// Sample linker script for the PIC18F452 processor

LIBPATH .

FILES c018i.o

FILES clib.lib

FILES p18f452.lib // 不同型号的MCU这里更换为相应的库。

CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED

CODEPAGE NAME=page START=0x2A END=0x7FFF

CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED

CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED

CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED

CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED

ACCESSBANK NAME=accessram START=0x0 END=0x7F

DATABANK NAME=gpr0 START=0x80 END=0xFF

DATABANK NAME=gpr1 START=0x100 END=0x1FF

DATABANK NAME=gpr2 START=0x200 END=0x2FF

DATABANK NAME=gpr3 START=0x300 END=0x3FF

DATABANK NAME=gpr4 START=0x400 END=0x4FF

DATABANK NAME=gpr5 START=0x500 END=0x5FF

ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED

SECTION NAME=CONFIG ROM=config

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP