C Conditional Format What Makes C Conditional Format So Addictive That You Never Want To Miss One?
Amitav Halder, Arunendra Tomar, Umesh Pratap Singh (Freescale Semiconductors)
SoCs ambiance includes lots of modules/IP and cores/processors. In the accomplished ambiance altered languages/scripts or methodologies used. In a archetypal SoCs setup, bang to modules is provided application the.c/cpp files through altered interfaces. In this .c/cpp architecture action includes altered phases/stages. And bang is generated agnate to what is in .c/cpp, that bang is accommodate to IP/modules through assorted interfaces and core.
When the C cipher runs there is four stages of C cipher architecture action which utilizes altered ‘tools’ such as a preprocessor, compiler, assembler, and linker. Finally we get executable/.hex book from .c file.
Here are the stages which are complex in C cipher architecture action in adjustment behindhand of the operating system/compiler.
Preprocessing is the aboriginal date of any C cipher building. It processes include-files, codicillary accumulation instructions and macros. Here we get “make errors” if there is some affair apropos the accommodate files/macros.If some accommodate files/macros are missing than there is “make_errors” or such errors are alleged accomplish errors. For archetype #define my_dma_en, if this “my_dma_en” deifne is acclimated afterwards “#define my_dma_en”, than there will be accomplish absurdity for “my_dma_en” as amorphous “my_dma_en”
Compilation is the additional date of any C cipher architecture . It takes the achievement of the preprocessor, and the antecedent code, and generates assembler antecedent code. On this date .asm files generated. If there is syntactical errors in antecedent cipher than such errors are alleged accumulation error.
Assembly is the third date of C cipher architecture . It takes the accumulation antecedent cipher and produces an accumulation advertisement with offsets. The assembler achievement is stored in an article file.In this action .obj fabricated from .asm.
Linking is the final date of C cipher building. It takes one or added article files or libraries as ascribe and combines them to aftermath a distinct (usually executable) file. In this action .exe fabricated from .obj.
Fig1: C/CPP BIULDING FLOW ON SoCs
NOTE: In UNIX/Linux, the executable or bifold book doesn’t accept addendum admitting in Windows the executables for archetype may accept .exe, .com and .dll. analogously book extensions can be .o or .obj for article book and .s or .asm for accumulation files.
WHAT ARE OBJECT FILES AND EXECUTABLE FILES:
Assembler and linker generates the .obj or .o and .exe respectively. An article and executable appear in several formats such as ELF (Executable and Bond Format) and COFF (Common Object-File Format) depending on OS .
An article book is basically a book absolute apparatus accent instructions and abstracts in a anatomy that the linker can use to actualize an executable program. Anniversary accepted or abstracts account authentic in an article book has a agnate attribute name by which it is referenced. A attribute generated for a accepted or abstracts analogue can be either a bounded analogue or all-around definition. Any advertence to a attribute alfresco the article book is accepted as an alien reference.
These article files accept areas alleged sections. Sections can authority executable code, data, activating bond information, debugging data, attribute tables, alteration information, comments, cord tables, and notes.
Some sections are loaded into the action angel and some accommodate advice bare in the architecture of a action angel while still others are acclimated alone in bond article files. For archetype .txt breadth or .bss section.
By absence , the architecture (.obj or .o) is cacographic architecture but can be fabricated in .obj.txt architecture to accomplish it clear format.
Here are the capacity for important fields of article files:
.text :This breadth contains the executable apprenticeship codes and is aggregate amid every action active the aforementioned binary. This breadth usually has READ and EXECUTE permissions only. This breadth is the one best afflicted by optimization.
.bss: BSS stands for ‘Block Started by Symbol’. It holds un-initialized all-around and changeless variables. Since the BSS alone holds variables that don’t accept any ethics yet, it doesn’t absolutely charge to abundance the angel of these variables. The admeasurement that BSS will crave at runtime is recorded in the article file, but the BSS (unlike the abstracts section) doesn’t booty up any absolute amplitude in the article file.
.data: Contains the initialized all-around and changeless variables and their values. It is usually the bigger allotment of the executable. It usually has READ/WRITE permissions.
.reloc: Stores the advice adapted for relocating the angel while loading.
ELF(Executable and Bond Architecture ) is bifold format, which is acclimated in Unix and Linux systems
For example: my_pattern.elf(its architecture is unreadble) and my_pattern.elf.txt(its is in clear format) which contains below:
Note: The beneath accustomed elf is for ARM amount .
NOTE: ELF is acclimated on Linux systems, while COFF is acclimated on Windows systems.
COFF:The COFF (Common Article Book Format) files may accept assorted sections, anniversary prefixed by a header. The cardinal of sections is limited. The COFF blueprint includes abutment for debugging but the debugging advice was limited. There is no book addendum for this format.
ELF:The ELF (Executable and Bond Format) is agnate to COFF in actuality organized into a cardinal of sections, but it removes abounding of COFF’s limitations. ELF acclimated on best avant-garde Unix systems, including GNU/Linux, Solaris and Irix. Additionally acclimated on abounding anchored systems.
Executable and Bond Architecture (ELF) is bifold format, which is acclimated in Unix and Linux systems.
It is a architecture for autumn programs or bits of programs on disk, created as a aftereffect of accumulation and linking.
ELF not alone simplifies the assignment of authoritative aggregate libraries, but additionally enhances activating loading of modules at runtime.
Because there are assorted article files which are included as references to anniversary others cipher and/or data, so assorted locations, these are accumulated during the articulation time.
For example: the article book that has main() includes calls to functions funct() and printf().
After bond all of the article files together, the linker uses the alteration annal to acquisition all of the addresses that charge to be abounding in.
Click to enlarge
Fig2:Files generated in c architecture breeze on SoCs
In a archetypal system, a cardinal of programs will be running. Anniversary affairs relies on a cardinal of functions, some of which will be accepted C library functions, like printf(), malloc(), strcpy(), etc. and some are non-standard or user authentic functions.
If every affairs uses the accepted C library, it agency that anniversary affairs would commonly accept a different archetype of this accurate library present aural it.This aftereffect in ashen resources, abase the adeptness and performance. So it is bigger to accept anniversary affairs advertence the accepted (because the C library is common,) one instance of that library, instead of accepting anniversary affairs accommodate a archetype of the library.
This is implemented during the bond action breadth some of the altar are affiliated during the articulation time admitting some done during the run time (deferred/dynamic linking).
The appellation ‘statically linked’ agency that the bounden amid the affairs and the accurate library is anchored and accepted at articulation time afore the affairs run. This bounden can’t be changed, unless we re-link the affairs with a new adaptation of the library.
Programs that are affiliated statically are affiliated adjoin athenaeum of altar (libraries) that about accept the addendum of .a. e.g. libc.a
The limitation of this abode is that the executable is absolutely big in size, all the bare advice charge to be brought together.
The appellation ‘dynamically linked’ agency that the bounden amid the affairs and the aggregate article is done at runtime that is afore the affairs starts, the adapted aggregate altar are begin and bound.
The linker places advice into the executable that tells the loader which aggregate article bore the cipher is in and which runtime linker should be acclimated to acquisition and bind the references.
Programs that are affiliated dynamically are affiliated adjoin aggregate altar that accept the addendum .so. e.g. libc.so
Program files (on disk) become abundant abate because they charge not authority all all-important argument and abstracts segments information. It is actual advantageous for portability.
In aggregate with basic memory, activating bond permits two or added processes to allotment read-only executable modules such as accepted C libraries. Application this technique, alone one archetype of a bore needs be citizen in anamnesis at any time, and assorted processes, anniversary can executes this aggregate cipher (read only). This after-effects in a ample anamnesis saving, although demands an able swapping policy.
In Linux processes loaded from a book arrangement (using either the execve() or spawn() arrangement calls) are in ELF format. This elf architecture contains assorted sections such as .init,.text,.bss.got,.data,.ctors,.dtors as apparent in aloft elf format(my_pattern.elf.txt)
When the .exe(executable) runs , afore active this charge to amount into memory.
This is done by the loader, which is about allotment of the operating system. The loader does the afterward things (from added things):
Memory and admission validation – Firstly, the OS arrangement atom reads in the affairs file’s attack advice and does the validation for type, admission permissions, anamnesis claim and its adeptness to run its instructions. It confirms that book is an executable angel and calculates anamnesis requirements.
Process bureaucracy includes:
i.e. The operating arrangement logically copies a file’s articulation to a basic anamnesis articulation according to the advice provided in the affairs attack table. The OS can additionally use segments to actualize a aggregate anamnesis resource.
Address amplitude is anamnesis amplitude that contains affairs code, stack, and abstracts segments or in added word, all abstracts the affairs uses as it runs. The anamnesis layout, consists of three segments (text, data, and stack).
C EXECUTION FLOW IN SoCs:
In a SoCs , there is lots of modules and ample ambiance bureaucracy exists. So we charge make_file to abridge and run the arrangement with the accomplished ambiance .In SoCs, there is core/processor which gives the bang to bore application the C file. In the accomplish book (like makefile.stimulus and _makefile.defs_) accept to accommodate the accordant switches.
How core/processor appear to apperceive that from which function/part of C in SoCs beheading will starts:
As apparent aloft , application accomplish book we accommodate the amount directives and accompanying switches.
In the core/processor directory, there is “crto.s” book which gives the advice about the startup code.
The access point of the C runtime-startup cipher is accustomed in “crto.s” in typcal SoCs. In a archetypal system, this will be alleged by the target-specific startup cipher afterwards it has initialized the target.
i.e. the access point is the breadth at which beheading begins in the a.out file.
The crto.s looks like: (this is of ARM core)
And ability PC amount ‘s crto.s looks like:
Because of this “BL pre_main_init @ alarm the C code” amount will alpha to assassinate this function. This action “pre_main_init” itself calls “main” and “post_main”.
NOTE: the functions “pre_main and post_main” are not all-encompassing ,this are cocky fabricated as per SoC environment, CORE may anon alpha to assassinate “main” of C file.
Thus, in this way amount gets the access point and assassinate the C in SoC environment.
In SoC setup,when C affairs runs, .exe/.elf is fabricated afterwards activity through the C architecture processes i.e. authoritative ->compiling and linking. In SoC bureaucracy this .exe/elf is adapted into a formatted hex which is loaded at adapted location(sram,flash or gram).
This “hex ” book is fabricated so that,core can assassinate the hex from the adapted location(sram,flash or gram).
NOTE:In this hex, there is advice anchored of the accomplished SoC environment(core files,all modules,C files and SoC bureaucracy files).
Therefore, In SoC environment, a “hex” book is generated from .elf/.exe. Amount executes this hex book and bang agnate to .C files is generated for modules in SoC setup.
The pattern.hex looks like:
NOTE: aboriginal cavalcade is the abode of anamnesis (sram,flash or gram) breadth hex is loaded.address.
Above hex book in the architecture of abode followed by abstracts .
From which breadth amount will alpha beheading and hex book will amount the advice i.e what will be alpha and end breadth in Hex file:
The hex book (which is generated anatomy .exe/.elf) can be loaded in to adapted anamnesis location(sram,flash or gram).The breadth or alpha and end addresses in hex book accompanying advice is provided through linker book .lnk.
.lnk looks like: (this linker book is of ARM core)
And ability PC amount ‘s linker book looks like:
The accent fields accord the advice for hex. In the aloft “ocram0” accept locations of sram starting from the abode “0x3ef00000” and len is “0x24000” i.e. hex book starting will be “0x3ef00000” and may go upto “starting abode len =3ef24000”.
If the .elf/hex requires added breadth than the provided in linker book than there will be ERROR “memory out of range” during the accomplish “process of C code”. In that case either optimize the .c book or extend the anamnesis arena in linker file.
FILES GENARTED ON SoCs ON RUNNING “.C” files
When a “.c” book runs in SoC bureaucracy ,the beneath files generated for anniversary .c.
*.crt0.o, *.lst , .map, *.o, *.out, *.lnk, *.hex, *.srec
NOTE:* is arrangement name like,PATTERN_NAME.hex
Map book and .lst file:
Map files contains the anamnesis allocation capacity and addresses for anniversary modules. And .lst gives the capacity for affairs adverse movement for anniversary allotment of cipher and files/functions which are executed.
A attribute table is a look-up amid attribute names and their addresses in memory. Compiler commonly produces .lst book for the accumulation code, and .map book with advice about affairs and abstracts anamnesis usage.
A archetypal map book looks like: (this is for ARM amount based SoCs)
And .lst looks like:
And .srec looks like:
In SoC environment, there is lots of bore exists and bang is generated from .c file. For accumulation and active the accomplished SoC ambiance for .c file, accomplish book is adapted in which the core/processor accompanying switches are provided. Through the C architecture process, hex book is generated that hex book is loaded in to a adapted memory. The starting and end abode ambit for hex book is absitively by linker book and access point for c beheading is accustomed in crto file. Finally core/processor , assassinate this hex book and bang is generated agnate to .c file.
Conclusion and approaching work:
In SoC setup, Amount assassinate the hex book and bang is generated agnate to what is provided in .c file.In SoC environment, to run at baby arrangement or .c the accomplished bureaucracy is accomplish and aggregate for which the hex book is generated, although the claim was that to accomplish the hex book of the included and all-important files acclimated for .c accomplish and abridge flow. For example, to run the arrangement (.c file) which has alone one annals reading/ autograph and book the info, the accomplished SoC bureaucracy will accomplish and abridge and hex will generated for that files also, in such hex should accept the advice of the files which are acclimated in .c architecture process. This can be taken affliction by tool/core or some calligraphy so that hex book is of the all-important files acclimated in C architecture process.
Book: Real-Time Concepts for Anchored Systems(http://www.e-reading.club/book.php?book=102147)
C Conditional Format What Makes C Conditional Format So Addictive That You Never Want To Miss One? – c conditional format
| Allowed for you to our weblog, with this period I will teach you about keyword. Now, this is actually the initial photograph: