Discriminant analysis to compile and run addresses of

Ubuntu 16.04.2 cross compiler environment arm-linux3.4.5 arm s3c2440 chip as the internet architecture

       32-bit processor, the length of each instruction is 4 bytes, in 4 byte order. Considering only the execution order, the processor will be sequentially read out according to an instruction execution order, but in consideration of the jump implemented, with only the case where the instruction sequence stored in this condition, the only way to achieve that is executed jump Jump such a convention to "how many bytes back or forward" position. No doubt this is inefficient and cumbersome calculations

 

So the need for instruction addressing, that gives the address of each instruction.

This is done in the compilation process, compiler initial address bits in an address, storing data in accordance with the order of the addresses given to each byte.

And this is the address the compiler address.

The actual execution address operation run address bit programs.


Compile address can be considered to be a writer , "expect" address at run time, and actually compile and run addresses some differences.


First need to know the cross compiler can use parameters -T arm-linux-ld when the program specified to the compiler to compile the source file data segment address
, such as:
arm-linux-ld -Ttext 0x30000000 start.O hello.o
namely the compiled address text (code) section arranged to 0x30000000 as the initial value, the order is generally block:
.text -> .rodata -> .data -> .bss

.text for a code segment, .rodata read-only data, .data for the data segment (stored initialized global variable or a static variable) ,. bss segment store global variables uninitialized

If -T parameter is not given, the compiler according to the default rules to address as an initial address 0 addressing sequentially

generated after compilation is .elf file format, need to go through the steps of:
ARM-Linux the objcopy -O-binary xxx.elf xxx.bin -S
ARM-Linux-objdump -D xxx.elf> xxx.dis
can obtain .bin file format for programmed into the device, the second command is used to generate the disassembled code, by disassembled code you can visually see the compiler translates source code to make the program, optimization, and addressing (compiler address).


After compilation of the program to go through the process to get programmed into the chip, and it is here where the compiler to generate a difference and run addresses the
assumption that the program must be programmed in chip flash, that is unified addressing the chip address 0 place. then:

1. When the arm-linux-ld is 0 or -Ttext parameters given address of the program compiled for an initial addressing to 0, the program begins at the start of the operation of addressing the chip address 0 to address operation must start from 0 address (unless otherwise specified), and the compiler address is from 0, from this point of view, compile and run the address is no different address

2. If the arm-linux-ld of -Ttext parameters given to 0x30000000, 0x30000000 to address the compiler initial addressing, seen from the 1, electric start running program or start from 0 address, the address is 0 runs, from here compile and run addresses will be different, but the program will still run from 0, but can also run normally

 Here it should be mentioned that the concept of a position-independent code and location-related code, and can be seen from the difference between the two is whether the name associated with the location code where the code execution.
Position-independent code is generally used relative jump instructions or jump to other positions relative performed, there is no particular relationship with the actual address, so called position-independent code, similar to the relative path to the file.

Location-related instruction code requires the use of an absolute address, which is compiled address jump, that jump to the address specified by the compiler, and the actual address where the instructions related to similar absolute path to the file.

arm architecture instruction set, irrespective of the position relative jump instruction code B, and code associated with a position command ldr

B by b as jump and jump mode is the main PC + offset value (PC value is equal to the current address + 8)
and jump ldr ldr implemented by PC, lab (lab here as reference) sucked lab label compilation directly address assigned to the PC, so jump to absolute address

has been programmed to start compiling unified chip from 0 address, so the program is stored in memory beginning at address 0, and also began to run from 0 address, if no intermediate position correlation code, the program in the program execution at the address 0 is feasible, because it is a program stored position, the instructions and data required to be able to take, but is now running the compiler and the address is not the same address.
If the program, subject to certain initialization, use instructions ldr pc pointing to the "expected" address, that address the compiler, the compiler and run addresses can achieve equal (pc runtime).

Then bare metal program or other programs often inconsistent compile and run addresses for bare metal program, for example, use s3c2440 chips, norflash use as a storage case, norflash address to 0 at the beginning, but as we know norflash similar rom, can normal read data, but requires special way to write data, which leads us to burn into the program, some global variables or stored in a stack area if global variables are stored on norflash words will not be in accordance with the desired program as can be assigned modified, so the code needs to be relocated to another storage location, such as on my board SDRAM, so the resulting inconsistencies compile and run addresses of.

Note that the code will be relocated to the area before compiling addresses, you need to initialize the target storage area, for example, I use SDRAM, then I need to initialize SDRAM settings, as well as the need to copy the code, data and other information into the target area, because our relocation target area, the target area is empty before copying the code of the code stored in the storage area rather than address 0, then it will jump directly absolutely unpredictable things happen ???
 

There are other reasons about the different compilers and run addresses, as well as the need for relocation of reason codes, here to do some simple analysis of the situation, in other cases, similar to the truth, you can learn by analogy, analogy. Relocation also differentiated manner, evacuated later analysis.


Conclusion:
Compile address: the compilation process in addressing man-made code specified address, the programmer is "expected" position running

 

Operating Address: actual operation of the value of the program pointer pc, and the actual operation and the code vector memory location related.

 

Welcome to exchange, discuss or correct me! Common progress!

---------------------------------------------------------

2020 revisited with some new ideas, can the venue to https://blog.csdn.net/G_METHOD/article/details/104508545 .

Published 19 original articles · won praise 7 · views 6942

Guess you like

Origin blog.csdn.net/G_METHOD/article/details/79512285