1 | .. comment SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. Copyright (C) 2018 Chris Johns <chrisj@rtems.org> |
---|
4 | |
---|
5 | RTEMS Executable |
---|
6 | ================ |
---|
7 | .. index:: RTEMS Executable |
---|
8 | |
---|
9 | Running executables is the most important part of working with RTEMS, it is |
---|
10 | after all how you run your application and use the RTEMS kernel services. |
---|
11 | |
---|
12 | An RTEMS executable is embedded in a target and executing an embedded |
---|
13 | executable has challenges not faced when executing software on a desktop or |
---|
14 | server computer. A desktop or server operating system kernel provides all the |
---|
15 | support needed to bring an executable's code and data into a process's address |
---|
16 | space passing control to it and cleaning up when it exits. An embedded target |
---|
17 | has to provide similar functionality to execute an embedded executable. |
---|
18 | |
---|
19 | An RTEMS Source Builder (RSB) built RTEMS tool chain is used to create RTEMS |
---|
20 | executables. The tool chain executable creates a fixed position statically |
---|
21 | linked Extendable Loader Format (ELF) file that contains the RTEMS kernel, |
---|
22 | standard libraries, 3rd party libraries and application code. RTEMS executes in |
---|
23 | a single address space which means it does not support the ``fork`` or ``exec`` |
---|
24 | system calls so statically linking all the code is the easiest and best way to |
---|
25 | create an executable. |
---|
26 | |
---|
27 | An RTEMS application is constructed vertically with the RTEMS kernel, BSP |
---|
28 | support code and drivers close to the hardware, above which sit the RTEMS |
---|
29 | Application Programming Interfaces (API) for control of threads, mutex and |
---|
30 | other resources an application may use. Middle-ware services like networking, |
---|
31 | interpreted languages, and protocol stacks sit between the RTEMS APIs and the |
---|
32 | application components. The software built into an executable can be see as a |
---|
33 | vertical software stack. |
---|
34 | |
---|
35 | .. _fig-exe-vert-stack: |
---|
36 | |
---|
37 | .. figure:: ../../images/user/exe-vert-stack.png |
---|
38 | :width: 35% |
---|
39 | :alt: Vertical Software Stack |
---|
40 | :figclass: align-center |
---|
41 | |
---|
42 | Vertical Software Stack |
---|
43 | |
---|
44 | Building an Application |
---|
45 | ======================= |
---|
46 | .. index:: Building an Application |
---|
47 | |
---|
48 | RTEMS views any code it is running and using it's interfaces as an |
---|
49 | application. RTEMS conforms to a number of international standards such as |
---|
50 | POSIX and can build and run portable code written in languages such as C, C++ |
---|
51 | and Ada. |
---|
52 | |
---|
53 | Applications are built from source into ELF object files, 3rd party packages |
---|
54 | can be built as libraries or they can be imported as source into an application |
---|
55 | code base. The application, 3rd party packages, RTEMS and standard libraries |
---|
56 | are linked to create the RTEMS executable. The executable is transferred to the |
---|
57 | target and a bootloader loads it from the non-volatile storage into RAM or the |
---|
58 | code is executed in place in the non-volatile storage. The target hardware |
---|
59 | defines what happens. |
---|
60 | |
---|
61 | .. _fig-exe-app: |
---|
62 | |
---|
63 | .. figure:: ../../images/user/exe-app.png |
---|
64 | :width: 90% |
---|
65 | :alt: Building an Application |
---|
66 | :figclass: align-center |
---|
67 | |
---|
68 | Building an Application |
---|
69 | |
---|
70 | The standard and 3rd party libraries are a collection of object files built |
---|
71 | using the same set of tools the application source is compiled with. The |
---|
72 | package collects it's object files into an archive or library. |
---|
73 | |
---|
74 | RTEMS does not provide a standard application build system. The RTEMS ecosystem |
---|
75 | provides support so a range of build systems can be used. Applications can be |
---|
76 | built with ``make``, ``autotools``, ``cmake``, ``waf`` and more. User should |
---|
77 | select a build system that meets their project, system, corporate or personal |
---|
78 | needs. |
---|
79 | |
---|
80 | Machine Flags and ABI |
---|
81 | --------------------- |
---|
82 | .. index:: Machine flags |
---|
83 | .. index:: Application Binary Interface |
---|
84 | .. index:: ABI |
---|
85 | |
---|
86 | |
---|
87 | All code in an RTEMS executable must be built with the same machine flags. The |
---|
88 | machine flags control the instruction set and application binary interface |
---|
89 | (ABI) the compiler generates. As the executable is statically linked all code |
---|
90 | must use the same instruction set the hardware is configured to support and all |
---|
91 | code must conform to the same ABI. Any variation can result in unpredictable |
---|
92 | behavior such as crashes, failures or lock ups. It is recommend an executable |
---|
93 | is built with the same or equivalent tool set. Mixing of tool set versions can |
---|
94 | also result in undefined behavior. The RTEMS tool ``rtems-execinfo`` can audit |
---|
95 | an RTEMS executable and list the machine flags and compilers used. |
---|
96 | |
---|
97 | RTEMS by default does not support instruction emulation for unsupported |
---|
98 | instructions. RTEMS applications are normally built from source so binary |
---|
99 | compatibility is not as important as performance. Instruction emulation is |
---|
100 | costly to execute and rebuilding the executable with the correct instruction |
---|
101 | set only needs to be done once. |
---|