http://supp.iar.com/Support/?Note=27498

EWARM v5.xx (and newer)

The placement of a few functions in a specific section is done with the ...

#pragma location="FUNCTIONS"
void h(void);

... but this becomes impractical when there are many functions to place.

So the ILINK linker of EWARM 5.xx can place all functions from a file into a specific section.

Placing many functions

Collect these functions in one (or more) source files.

Remove any #pragma location you have earlier added.

Edit the .icf file with a line the holds the keyword "object" as exemplified below. For more information, please see the chapter Section-selectors in the EWARM_DevelopmentGuide.pdf file.

Example
The link to the right holds an edited variant of "Tutor 1", where ILINK will place all code from the file Utilities.c at address 0x7000000 and higher.

The change made to the "Tutor 1", is the addition of these files to the .icf file:

define symbol __EXAMPLE_start__ = 0x7000000;
define symbol __EXAMPLE_end__ = 0x700FFFF;
define region EXAMPLE_region = mem:[from __EXAMPLE_start__ to __EXAMPLE_end__];
place in EXAMPLE_region { readonly object Utilities.o};

EWARM v6.70 (and newer)

Two new pragma directives have been added in v6.70 ...

#pragma default_variable_attributes

... and ...

#pragma default_function_attributes

... to set default placement and attributes for variable/function declarations and definitions.

This means that you can override multiple declarations and definitions by using a single #pragma.

Example

Below is an example of how to use these new pragmas:

/* Place following functions in section MY_FUNC */
#pragma default_function_attributes = @ "MY_FUNC" int fun1(int x)
{
return x + ;
} int fun2(int x)
{
return x - ;
} /* Stop placing functions in section MY_FUNC */
#pragma default_function_attributes = int fun3(int x)
{
return x + x;
} /* Place following data in section MY_DATA */
#pragma default_variable_attributes = @ "MY_DATA" int data1;
int data2; /* Stop placing data in section MY_DATA */
#pragma default_variable_attributes = int data3; int main()
{
data1 = fun1();
data2 = fun2();
data3 = fun3(); return data1 + data2 + data3;
}

#pragma location

Syntax

#pragma location={address|register|NAME}

Parameters

Description Use this pragma directive to specify:

address The absolute address of the global or static variable or function for which you want an absolute location.

register An identifier that corresponds to one of the ARM core registers R4–R11.

NAME A user-defined section name; cannot be a section name predefined for use by the compiler and linker.

Description

Use this pragma directive to specify:

The location—the absolute address—of the global or static variable whose declaration follows the pragma directive.

The variables must be declared __no_init.

An identifier specifying a register. The variable defined after the pragma directive is placed in the register.

The variable must be declared as __no_init and have file scope.

A string specifying a section for placing either a variable or function whose declaration follows the pragma directive.

Do not place variables that would normally be in different sections

(for example, variables declared as __no_init and variables declared as const) in the same named section.

#pragma location=0xFFFF0400
__no_init volatile char PORT1;
/* PORT1 is located at address 0xFFFF0400 */ #pragma location=R8
__no_init int TASK;
/* TASK is placed in R8 */ #pragma location="FLASH"
char PORT2;
/* PORT2 is located in section FLASH */ /* A better way is to use a corresponding mechanism */
#define FLASH _Pragma("location=\"FLASH\"")
FLASH int i; /* i is placed in the FLASH section */

Controlling data and function placement in memory

The compiler provides different mechanisms for controlling placement of functions and data objects in memory.

To use memory efficiently, you should be familiar with these mechanisms to know

which one is best suited for different situations. You can use:

The @ operator and the #pragma location directive for absolute placement

Use the @ operator or the #pragma location directive to place individual global and static variables at absolute addresses.

This is useful for individual data objects that must be located at a fixed address to conform to external requirements,

for example to populate interrupt vectors or other hardware tables.

Note that it is not possible to use this notation for absolute placement of individual functions.

The @ operator and the #pragma location directive for section placement

Use the @ operator or the #pragma location directive to place groups of functions or global and static variables in named sections,

without having explicit control of each object.

The sections can, for example, be placed in specific areas of memory, or initialized or copied in controlled ways using the section begin and end operators.

This is also useful if you want an interface between separately linked units, for example an application project and a boot loader project.

Use named sections when absolute control over the placement of individual variables is not needed, or not useful.

The @ operator and the #pragma location directive for register placement

Use the @ operator or the #pragma location directive to place individual global and static variables in registers.

The variables must be declared __no_init. This is useful for individual data objects that must be located in a specific register.

The --section option

Use the --section option to place functions and/or data objects in named sections, which is useful, for example,

if you want to direct them to different fast or slow memories. For more information, see --section, page 266.

--section OldName=NewName

Description The compiler places functions and data objects into named sections which are referred to by the IAR ILINK Linker.

Use this option to change the name of the section OldName to NewName.

This is useful if you want to place your code or data in different address ranges and you find the @ notation,

alternatively the #pragma location directive, insufficient.

Note that any changes to the section names require corresponding modifications in the linker configuration file.

To place functions in the section MyText, use:
--section .text=MyText

At compile time, data and functions are placed in different sections, see Modules and sections, page 68.

At link time, one of the most important functions of the linker is to assign load addresses to the various sections used by the application.

All sections, except for the sections holding absolute located data, are automatically allocated to memory according to the specifications

in the linker configuration file, see Placing code and data—the linker configuration file, page 70.

Placing code and data—the linker configuration file

The placement of sections in memory is performed by the IAR ILINK Linker. It uses the linker configuration file

where you can define how ILINK should treat each section and how they should be placed into the available memories.

A typical linker configuration file contains definitions of:

● Available addressable memories
● Populated regions of those memories
● How to treat input sections
● Created sections
● How to place sections into the available regions.

The file consists of a sequence of declarative directives. This means that the linking process will be governed by all directives at the same time.

To use the same source code with different derivatives, just rebuild the code with the appropriate configuration file.

How do I place a group of functions or variables in a specific section?的更多相关文章

  1. 7 Scatter-loading Features

    7.1 About scatter-loading The scatter-loading mechanism enables you to specify the memory map of an ...

  2. Think Python - Chapter 03 - Functions

    3.1 Function callsIn the context of programming, a function is a named sequence of statements that p ...

  3. Analytic Functions in Oracle

    Contents Overview and IntroductionHow Analytic Functions WorkThe SyntaxExamplesCalculate a running T ...

  4. Aggregate (GROUP BY) Function Descriptions

    w Table 13.25 Aggregate (GROUP BY) Functions Name Description AVG() Return the average value of the ...

  5. C-Language Functions

    转自:https://www.postgresql.org/docs/9.6/xfunc-c.html 可以作为学习基于c编写pg extension 的资料 36.9. C-Language Fun ...

  6. 表视图为Group类型的注意问题

    使用group类型的tableview时,第一个section距离navigationbar的距离很大,不符合这边的设计图. 使用 myTableView . sectionHeaderHeight  ...

  7. CentOS 6.8 LAMP 安装配置

    1.远程系统拒绝了连接: 需要关闭防火墙/etc/rc.d/init.d/iptables stop service iptables stop chkconfig iptables off sete ...

  8. Web服务之LNMMP架构及动静分离实现

    原文链接:http://hoolee.blog.51cto.com/7934938/1413346 讲的非常详细,尽管我只看动静分离,可是看了一下其他的部署,也是非常不错,适合新手 一.LNMMP  ...

  9. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

随机推荐

  1. 《A Tour of PostgreSQL Internals》学习笔记——系统表和数据类型

    上周末学习了<A Tour of PostgreSQL Internals>的第一部分(View 1),今天我们继续打开书本,继续View 2 部分. View 2 Postgresql的 ...

  2. WebAPI初探

    由于即将要接手的新项目计划用ASP.NET MVC3来开发,所以最近一段时间一直在看相关的书或文章.因为之前在大学里也曾学习过MVC2开发,也做过几个简单的MVC2的小型测试项目,不过在后来工作以后主 ...

  3. delphi 中字符串与16进制、10进制转换函数

      //字符串转成16进制代码function strToHexStr(str:string):string;varc:char;ss:string;i:integer;beginwhile str& ...

  4. hadoop是什么?

    在如今这个信息高速发展的今天,hadoop也越来越火了,那么到底是什么原因让hadoop如此的火,接下来新霸哥将详细的为了介绍,并让你快速的任何hadoop是什么? hadoop思想起源:Google ...

  5. 黑马程序员——OC与C语言的异同比较

    1.  文件介绍:Objective-C 也使用头文件(header files),后缀为 .h, 但使用 .m(即 message, 其他面向对象编程语言也叫 method),作为源文件的后缀.   ...

  6. WinForm 根据屏幕分辨率自适应

    方法来自百度, 不算太好,但目前能满足需求.(窗口在LOAD的时候记录每个控件的坐标,每次窗口重绘的时候引时SizeChange事件,根据比率重新设置坐标) 以下是代码  AutoSizeFormCl ...

  7. Android 订阅-发布者模式-详解

    1.概念简述 Android 简称观察者模式, GoF说道:Observer模式的意图是“定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新”. 有 ...

  8. [WebService]之DTD

    文档类型定义(DTD)可定义合法的XML文档构建模块.它使用一系列合法的元素来定义文档的结构.  DTD 可被成行地声明于 XML 文档中,也可作为一个外部引用. <?xml version=& ...

  9. gVIM 简洁配置 in Windows

    原文链接:http://www.errdev.com/post/2/ 捣鼓了一段时间的VIM,神器终归是神器,果然编码效率提升了许多,当然还需要很多插件来配合.自己装插件很麻烦,还要有Vundle这个 ...

  10. JDBC连接Oracle数据库的问题

    场景:最近做一个java web项目,使用jdbc连接Oracle数据库,遇到了两个问题. 问题1:jdbc连接不上Ubuntu Oracle服务器? 后来发现这个问题的原因是由于连接字符串写错了,修 ...