在Keil C中可能需要指定某个函数或者某段程序链接后存放在程序区中的位置。

  1. 如何指定某个函数在程序区中的位置

QUESTION

How do I locate a C function at an absolute address? I succeeded in variables using _at_, but it doesn’t work for functions.

ANSWER

You must use the BL51 Linker or LX51 Linker to locate functions at fixed addresses. To do so, make a note of the function name and the source file in which it is saved. The compiler creates a symbol name for the function using the following format:

?PR?function_name?file_name

So, the function named func in main.c would have a symbol name of:

?PR?FUNC?MAIN

Everything is uppercase to comply with the OMF51 standard.

There may be derivatives of this naming convention. For example, if the function accepts arguments that can all be passed in registers, the function name is prefixed with an underscore (‘_’) and the above would be:

?PR?_FUNC?MAIN

You may look in the linker’s map file to figure out the symbolic names for your functions.

Once you know the symbolic name, it is a simple matter of telling the linker where to locate it using the CODE directive. For example:

BL51 main.obj code(?pr?func?main(2000h))

Tells the linker to locate the function func at code address 0×2000.

If you use the µVision IDE you may enter the starting address for segments under Project – Options for Target. For the BL51 Linker/Locater enter the following code segment with the address under BL51 Locate – Code. For the LX51 Linker/Locater enter it under LX51 Locate – User Segments:

?pr?func?main(C:0x2000)

  2,如何指定一段代码在程序区中的位置

QUESTION

I am writing an IAP loader and would like to locate it in the first 1024 Bytes of my CODE memory. How can I ensure this? I have tried to use wildcards, but this did not work out, since it collidates with interrupt vectors.

ANSWER

The best approch is to locate the program code with a USER CLASS. User classes are an extension of the LX51 Linker/Locater (which is available in the PK51 Professional Developer’s Kit).

For example, you can write the following pragma within the C source files that contain the IAP loader program code:

#pragma userclass (code = IAP) // generates CODE_IAP class

This userclass directive places the program code of the module to the memory class CODE_IAP. Now you can separately locate this memory class when you enter it in µVision under Project – Options for Target – LX51 Locate – User Class. To locate the IAP code to the first 1KB of your program section enter here.

CODE_IAP (C:0 - C:0x3FF)

Note that you have to select the Use Extended Linker LX51 under Project – Options for Target – LX51 Locate – User Class.

MORE INFORMATION

Refer to USERCLASS in the Cx51 User’s Guide.

Refer to CLASSES in the LX51 User’s Guide.

  

  补充:

1.  如果没有在“Options for Target”中找到“ LX51 Locate”标签,请先在“Device”标签页中选中“Use Extended Linker(LX51) instead of "BL51"

2. 指定的USERCLASS的地址不能和其他CODE 区的地址重叠,包括原始的CODE区。

C51 函数/程序段的定位的更多相关文章

  1. C51函数的递归调用

    前几天在写C51程序时用到了递归,简单程序如下: void WRITE_ADD(uchar addr,uchar wbyte) { START(); //先发送起始信号 WRITE_BYTE(0xa0 ...

  2. 在Selenium Webdriver中使用XPath Contains、Sibling函数定位

    前言 在一般情况下,我们通过简单的xpath即可定位到目标元素,但对于一些既没id又没name,而且其他属性都是动态的情况就很难通过简单的方式进行定位了. 在这种情况下,我们需要使用xpath1.0内 ...

  3. Linux pwn入门教程(10)——针对函数重定位流程的几种攻击

    作者:Tangerine@SAINTSEC 本系列的最后一篇 感谢各位看客的支持 感谢原作者的付出一直以来都有读者向笔者咨询教程系列问题,奈何该系列并非笔者所写[笔者仅为代发]且笔者功底薄弱,故无法解 ...

  4. UNIX高级环境编程(7)标准IO函数库 - 二进制文件IO,流定位,创建临时文件和内存流

    1 二进制IO(Binary IO) 在前一篇我们了解了逐字符读写和逐行读写函数. 如果我们在读写二进制文件,希望以此读写整个文件内容,这两个函数虽然可以实现,但是明显会很麻烦且多次循环明显效率很低. ...

  5. CTF丨Linux Pwn入门教程:针对函数重定位流程的相关测试(下)

    Linux Pwn入门教程系列分享已接近尾声,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/a ...

  6. [PHP] 使用ftell和fseek函数直接定位文件位置获取部分数据

    对于大文件只获取部分数据很有用 1.使用ftell函数可以获取当前指针的字节位置2.使用fseek函数可以直接定位到指定的位置3.读取指定字节的数据就可以部分获取文件内容了 <?php clas ...

  7. keil c51笔记

    第一章 Keil C51开发系统基本知识 第一节 系统概述 Keil C51是美国Keil Software公司出品的51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上.结构性.可读性. ...

  8. 深入剖析keil c51 --- 从汇编到c51

    第一节 main()函数和启动代码 汇编是从org 0000h开始启动,那么keil c51是如何启动main()函数的?keil c51有一个启动程序startup.a51,它总是和c程序一起编译和 ...

  9. Keil C51 知识点

    第一节 Keil C51扩展关键字     深入理解并应用C51对标准ANSIC的扩展是学习C51的关键之一.因为大多数扩展功能都是直接针对8051系列CPU硬件的.大致有以下8类: 8051存储类型 ...

随机推荐

  1. Keil的可重定位段

    对于一个大的文件,为了便于管理,一个好的办法时把一个大文件分为若干个小文件,每个小文件包含一部分相关的功能,这样功能将显得很整洁,而且移植到其它工程的时候也很方便,把文件copy过去即可. 对于汇编, ...

  2. MOUNT MACBOOK DISK (OSX / HFS+) ON UBUNTU 12.04 LTS WITH READ/WRITE

    MOUNT MACBOOK DISK (OSX / HFS+) ON UBUNTU 12.04 LTS WITH READ/WRITE So you want to mount your HFS+ ( ...

  3. Go语言中的管道(Channel)总结

    管道(Channel)是Go语言中比较重要的部分,经常在Go中的并发中使用.今天尝试对Go语言的管道来做以下总结.总结的形式采用问答式的方法,让答案更有目的性. Q1.管道是什么? 管道是Go语言在语 ...

  4. 符号表实现(Symbol Table Implementations)

    符号表的实现有很多方式,下面介绍其中的几种. 乱序(未排序)数组实现 这种情况,不需要改变数组,操作就在这个数组上执行.在最坏的情况下插入,搜索,删除时间复杂度为O(n). 有序(已排序)数组实现 这 ...

  5. css备忘录(关于relative、absolute)

    父级用:position: relative; 子级才能用:position: absolute; relative里面用margin调位置: absolute里面用top.left.right.bo ...

  6. OpenXML - 如何导出List<DataModel>到Excel -- Part 1

    最近这几天研究OpenXML: 这是Open XML的一些介绍: Open XML 介绍:http://baike.baidu.com/view/1201978.htm 下载:http://www.m ...

  7. JavaScript 判断一个字符串是否在另一个字符串中

    传统上,JavaScript只有indexOf方法,可以用来确定一个字符串是否包含在另一个字符串中.ES6又提供了三种新方法. includes():返回布尔值,表示是否找到了参数字符串. start ...

  8. (转)iPhone 判断UITableView 滚动到底部

    UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate. ...

  9. [2011山东省第二届ACM大学生程序设计竞赛]——Identifiers

    Identifiers Time Limit: 1000MS Memory limit: 65536K 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?act ...

  10. 快速构建AdapterView的Adapter--ingeniousadapter

    项目地址:ingeniousadapter 前面的话:本项目的原型是QuickAdapter,它们的思路基本一致,但本项目的优势在于: 支持AdapterView存在多个layout类型 可配置图片加 ...