Analysis and understanding of ARM position-independent code PIC

Publisher:清新心情Latest update time:2016-06-21 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The characteristics of PIC are:

        It can be correctly executed when loaded into any address space. The principle is that PIC's operations on constants and function entry addresses are based on the addressing mode of PC + offset. Even if the program is moved, the PC also changes, but the offset remains unchanged, so the program can still find the correct entry address or constant.

 

 

Loading domain: the address where the code is stored

Runtime domain: is the address when the code is running

Link address: The address where the program should be located when running.

In some cases, some code is not executed at the address where it is stored. For example, the code placed in norflash may eventually be run in RAM. In this case, the address in norflash is the load domain, and the address in RAM is the run domain.

 

In assembly code, we often see some jump instructions, such as b, bl (position-independent instructions), etc. These instructions are followed by a relative address rather than an absolute address. For example, b main, how should we understand this instruction? What exactly is main here?

       At this time, the concept of link address is involved. Link address is actually the linker arranging an address for variable names, function names and other things in the code, giving these abstract things an address, and then accessing these variable names and function names in the program is accessing some addresses. Generally speaking, the link address refers to the starting address of linking these codes. The code must be placed at the beginning of this address to run normally. Otherwise, when the code tries to access and execute the code at the address corresponding to a variable name or function name, it will not be found, and then the program will undoubtedly run away.

        But the case of b main mentioned above is a little special. Jump instructions such as b and bl are not absolute jump instructions, but relative jump instructions. What does it mean? That is, the main label finally gets not the absolute address of main after being arranged by the linker, but the value obtained by subtracting the absolute address of the current instruction from the absolute address of main. In other words, b and bl access a relative address, not an absolute address. Therefore, the code segment including this statement and main can run normally regardless of whether it is placed in its execution domain. This is the so-called position-independent code.

From the above discussion, we can know that if your code needs to be position-independent, then you cannot use absolute addressing instructions, otherwise it will be position-dependent.

Keywords:ARM Reference address:Analysis and understanding of ARM position-independent code PIC

Previous article:ARM position-independent code design for uboot
Next article:The driver module in arm is loaded and called by the application

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号