ARM Linux Specifics: Thomas Petazzoni / Michael Opdenacker Free Electrons
ARM Linux Specifics: Thomas Petazzoni / Michael Opdenacker Free Electrons
Rights to copy
Copyright 2004-2008 Free Electrons [email protected] Document sources, updates and translations: http://free-electrons.com/docs/arm-linux Corrections, suggestions, contributions and translations are welcome!
Attribution ShareAlike 3.0 You are free to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions Attribution. You must give the original author credit. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. License text: http://creativecommons.org/licenses/by-sa/3.0/legalcode
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
Training contents
Floating point and ABIs Floating point support on ARM Linux Different ABIs Thumb mode Introduction to Thumb Thumb and ARM code together Interworking on your system Other ARM extensions
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
EABI (1)
EABI is a new standardized ABI for the ARM platforms It has several advantages
Ability to mix hard and soft float code, so that general code can be compiled with soft float and several versions of optimized libraries can be provided using hard float Allows to link with code generated by other compilers and provided by other vendors Has integrated support for Thumb interworking
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
EABI (2)
Other changes coming from EABI Structure packing and alignment rules change : no minimum alignement in structures Stack alignment on function entry is 8 bytes instead of 4 bytes Alignment of 64 bits types is 8 bytes instead of 4 System call interface The system call number was passed as part of the swi instruction The kernel had to read and decode the swi instruction, polluting the data cache with instructions Now, the system call number is passed in r7 64 bits function arguments are aligned to an even-number register instead of using the next available pair
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
10
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
11
Introduction to Thumb
Introduction to Thumb
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
12
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
13
Instruction encoding
15 001 10 Thumb instruction 0 Rd 8-bit immediate
Immediate value
31 1110 001
Condition: always
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
14
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
15
bl
0 <bar>
A.7.1.17 BL, BLX instructions in Thumb mode These Thumb instructions must always occur in the pairs described above
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
16
Size gains
Size gains on a small, non-representative example
int bar(int c, int d) { return c + d; } int foo(int a, int b) { a += 3; b -= 2; return bar(b, a); }
arm-linux-gcc -c
test.arm.o
$ sizediff test.arm.o test.thumb.o text data bss dec 124 0 0 124 96 0 0 96 -28 0 0 -28
hex 7c 60 -1C
arm-linux-gcc -c -mthumb
test.thumb.o
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
17
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
18
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
19
Interworking
The GNU C Compiler provides a transparent mechanism called interworking to allow the mix of ARM and Thumb code Interworking-enabled code can be generated using
-mthumb-interwork
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
20
Interworking (2)
000081c4 <main>: 81c4: b580 81c6: af00 [...] 81cc: f005 fb30 [...] 00008220 <foo>: 8220: e1a0c00d 8224: e92dd800 [...] 8254: e12fff1e 0000d830 <__foo_from_thumb>: d830: 4778 d832: 46c0 push add bl {r7, lr} r7, sp, #0 d830 <__foo_from_thumb>
mov push bx
bx nop
8220 <foo>
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
21
Interworking (3)
Two thumb b instructions
lr = pc + (immediate << 12) pc = lr + (immediate) lr = addr of next instruction | 1
f005 fb30 bl d830 <__foo_from_thumb>
Call the correct function Return to Thumb mode at the calling site
lr has the lowest bit to 0, switch to Thumb
eaffea79
b 8220 <foo>
e12fff1e
bx lr
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
22
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
23
Several solutions
ARM and Thumb mode of the kernel and userspace are independent Can use a ARM kernel with a Thumb mode userspace, the system call ABI remains the same Full Thumb userspace, including the libc uClibc doesn't seem to support Thumb mode correctly, at least gcc 4.2 is not able to compile it Thumb userspace, excluding the libc The solution chosen for our experiments
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
24
25
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
26
27
ThumbEE
ThumbEE stands for Thumb Execution Environment
Adds more instructions designed for runtime generated code, for example by JIT compilation (automatic null pointer checks or array boundary checks, branch to handlers, etc.)
http://www.arm.com/pdfs/JazelleRCTWhitePaper_final1-0_.pdf
ARM Linux specifics Copyright 2004-2008, Free Electrons Creative Commons Attribution-ShareAlike 3.0 license http://free-electrons.com Sep 15, 2009
28
Related documents
All our technical presentations on http://free-electrons.com/docs Linux kernel Device drivers Architecture specifics Embedded Linux system development
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//free-electrons.com
How to help
You can help us to improve and maintain this document... By sending corrections, suggestions, contributions and translations By asking your organization to order development, consulting and training services performed by the authors of these documents (see http://free-electrons.com/). By sharing this document with your friends, colleagues and with the local Free Software community. By adding links on your website to our on-line materials, to increase their visibility in search engine results.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//free-electrons.com
Linux kernel Linux device drivers Board support code Mainstreaming kernel code Kernel debugging Embedded Linux Training All materials released with a free license! Unix and GNU/Linux basics Linux kernel and drivers development Real-time Linux, uClinux Development and profiling tools Lightweight tools for embedded systems Root filesystem creation Audio and multimedia System optimization
Free Electrons
Our services
Custom Development System integration Embedded Linux demos and prototypes System optimization Application and interface development Consulting and technical support Help in decision making System architecture System design and performance review Development tool and application support Investigating issues and fixing tool bugs