Linux Kernel Architecture

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

Appendix C: Notes on C


The exact meaning of the individual assembler commands is of no concern here, because it is beyond
the scope of this appendix to provide a full introduction to assembler programming. Indeed, a separate
book would be needed for each architecture supportedby the kernel. Of more importance is the structure
of the code generated. Constant strings are held in a separate section from which they are loaded when
they are passed to a function (printfin this case) or when they are generally needed. In assembler code,
functions (onlymainis used here) retain the same name as in C code.

The same initial code generates totally different assembler code on IA-64 systems (because the archi-
tecture is completely different), but the ultimateeffectis identical to that of the code generated on IA-32
systems.
.file "hello.c"
.pred.safe_across_calls p1-p5,p16-p63
.section .rodata
.align 8
.LC0:
stringz "Hello, World!\n"
.text
.align 16
.global main#
.proc main#
main:
.prologue 14, 33
.save ar.pfs, r34
alloc r34 = ar.pfs, 0, 4, 1, 0
.vframe r35
mov r35 = r12
.save rp, r33
mov r33 = b0
.body
addl r14 = @ltoff(.LC0), gp
;;
ld8 r36 = [r14]
mov r32 = r1
br.call.sptk.many b0 = printf#
;;
mov r1 = r32
mov r14 = r0
;;
mov r8 = r14
mov ar.pfs = r34
mov b0 = r33
.restore sp
mov r12 = r35
br.ret.sptk.many b0
;;
.endp main#
.ident "GCC: (GNU) 3.1"

To give you an example of how this is handled by a non-Intel architecture, the following is the code
generated by the ARM variant:

.file "hello.c"
.section .rodata
.align 2
Free download pdf