Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer app03.tex V1 - 09/04/2008 6:11pm Page 1179

Appendix C: Notes on C


.LC0:
.ascii "Hello, World!\n\000"
.text
.align 2
.global main
.type main,function
main:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 1, uses_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
ldr r0, .L2
bl printf
mov r3, #0
mov r0, r3
ldmea fp, {fp, sp, pc}
.L3:
.align 2
.L2:
.word .LC0
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.2.1"

How does the GCC obtain information on the capabilities and command options of the target processor?
The answer is that amachine descriptionis present for each target architecture supported. This consists of
two parts and provides the desired information.


First, there is a file withinstruction patternswhose structure is a mixture of LISP and RTL syntax.^2
Some parts of this pattern can be supplied with values by the compiler when RTL code is gen-
erated. Restrictions can be placed on the possible values by defining various conditions or other
prerequisites. Generation of the actual code is performed by the output patterns that represent the
possible assembler instructions and are associated with the instruction patterns. The source files that
hold the instruction patterns for the individual systems are a very important part of the compiler
and are therefore correspondingly large. The statement list for IA-32 processors is about 14,000
lines long; the Alpha variant is 6,000 lines long; and approximately 10,000 lines are needed for the
Sparc family.


Theinstruction patternsare supplemented by C header files and macro definitions in which processor-
specific special situations that do not fit into the instruction patterns can be handled.^3 It is necessary to
use C code, even if the target instruction cannot be implemented with a fixed string or simple macro
substitutions.


(^2) LISP is a programming language whose origins lie in artificial intelligence. It is often used as a dynamic extension language for
application programs. Large parts ofemacsare programmed in a LISP dialect, and theGIMP image manipulation program uses
the Scheme extension language (a simplified LISP variant). GUILE, a library developed by the GNU project, features simple options
for providing programs with a Scheme interpreter as an extension language.
(^3) An explicit goal when developing the GCC was to rank performance higher than theoretic elegance. It would be possible to describe
processors solely with the help of the instruction pattern files, but this would entail a loss of performance and flexibility. The addi-
tional macro definitions do not contribute to the elegance of the overall system, but are a useful enhancement to help accomodate
the special features of the individual CPU types.

Free download pdf