1 | .. SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | |
---|
4 | .. Copyright (C) 1988, 2002 On-Line Applications Research Corporation (OAR) |
---|
5 | |
---|
6 | Miscellaneous Support Files |
---|
7 | *************************** |
---|
8 | |
---|
9 | .. warning:: |
---|
10 | |
---|
11 | This chapter contains outdated and confusing information. |
---|
12 | |
---|
13 | GCC Compiler Specifications File |
---|
14 | ================================ |
---|
15 | |
---|
16 | The file ``bsp_specs`` defines the start files and libraries that are always |
---|
17 | used with this BSP. The format of this file is admittedly cryptic and this |
---|
18 | document will make no attempt to explain it completely. Below is the |
---|
19 | ``bsp_specs`` file from the PowerPC psim BSP: |
---|
20 | |
---|
21 | .. code-block:: c |
---|
22 | |
---|
23 | %rename endfile old_endfile |
---|
24 | %rename startfile old_startfile |
---|
25 | %rename link old_link |
---|
26 | *startfile: |
---|
27 | %{!qrtems: %(old_startfile)} \ |
---|
28 | %{!nostdlib: %{qrtems: ecrti%O%s rtems_crti%O%s crtbegin.o%s start.o%s}} |
---|
29 | *link: |
---|
30 | %{!qrtems: %(old_link)} %{qrtems: -Qy -dp -Bstatic -e _start -u __vectors} |
---|
31 | *endfile: |
---|
32 | %{!qrtems: %(old_endfile)} %{qrtems: crtend.o%s ecrtn.o%s} |
---|
33 | |
---|
34 | The first section of this file renames the built-in definition of some |
---|
35 | specification variables so they can be augmented without embedded their |
---|
36 | original definition. The subsequent sections specify what behavior is expected |
---|
37 | when the ``-qrtems`` option is specified. |
---|
38 | |
---|
39 | The ``*startfile`` section specifies that the BSP specific file ``start.o`` |
---|
40 | will be used instead of ``crt0.o``. In addition, various EABI support files |
---|
41 | (``ecrti.o`` etc.) will be linked in with the executable. |
---|
42 | |
---|
43 | The ``*link`` section adds some arguments to the linker when it is invoked by |
---|
44 | GCC to link an application for this BSP. |
---|
45 | |
---|
46 | The format of this file is specific to the GNU Compiler Suite. The argument |
---|
47 | used to override and extend the compiler built-in specifications is available |
---|
48 | in all recent GCC versions. The ``-specs`` option is present in all ``egcs`` |
---|
49 | distributions and ``gcc`` distributions starting with version 2.8.0. |
---|
50 | |
---|
51 | README Files |
---|
52 | ============ |
---|
53 | |
---|
54 | Most BSPs provide one or more ``README`` files. Generally, there is a |
---|
55 | ``README`` file at the top of the BSP source. This file describes the board |
---|
56 | and its hardware configuration, provides vendor information, local |
---|
57 | configuration information, information on downloading code to the board, |
---|
58 | debugging, etc.. The intent of this file is to help someone begin to use the |
---|
59 | BSP faster. |
---|
60 | |
---|
61 | A ``README`` file in a BSP subdirectory typically explains something about the |
---|
62 | contents of that subdirectory in greater detail. For example, it may list the |
---|
63 | documentation available for a particular peripheral controller and how to |
---|
64 | obtain that documentation. It may also explain some particularly cryptic part |
---|
65 | of the software in that directory or provide rationale on the implementation. |
---|
66 | |
---|
67 | Times |
---|
68 | ===== |
---|
69 | |
---|
70 | This file contains the results of the RTEMS Timing Test Suite. It is in a |
---|
71 | standard format so that results from one BSP can be easily compared with those |
---|
72 | of another target board. |
---|
73 | |
---|
74 | If a BSP supports multiple variants, then there may be multiple ``times`` |
---|
75 | files. Usually these are named ``times.VARIANTn``. |
---|
76 | |
---|
77 | Tools Subdirectory |
---|
78 | ================== |
---|
79 | |
---|
80 | Some BSPs provide additional tools that aid in using the target board. These |
---|
81 | tools run on the development host and are built as part of building the BSP. |
---|
82 | Most common is a script to automate running the RTEMS Test Suites on the BSP. |
---|
83 | Examples of this include: |
---|
84 | |
---|
85 | - ``powerpc/psim`` includes scripts to ease use of the simulator |
---|
86 | |
---|
87 | - ``m68k/mvme162`` includes a utility to download across the VMEbus into target |
---|
88 | memory if the host is a VMEbus board in the same chasis. |
---|
89 | |
---|
90 | bsp.h Include File |
---|
91 | ================== |
---|
92 | |
---|
93 | The file ``include/bsp.h`` contains prototypes and definitions specific to this |
---|
94 | board. Every BSP is required to provide a ``bsp.h``. The best approach to |
---|
95 | writing a ``bsp.h`` is copying an existing one as a starting point. |
---|
96 | |
---|
97 | Many ``bsp.h`` files provide prototypes of variables defined in the linker |
---|
98 | script (``linkcmds``). |
---|
99 | |
---|
100 | tm27.h Include File |
---|
101 | =================== |
---|
102 | |
---|
103 | The ``tm27`` test from the RTEMS Timing Test Suite is designed to measure the |
---|
104 | length of time required to vector to and return from an interrupt handler. This |
---|
105 | test requires some help from the BSP to know how to cause and manipulate the |
---|
106 | interrupt source used for this measurement. The following is a list of these: |
---|
107 | |
---|
108 | - ``MUST_WAIT_FOR_INTERRUPT`` - modifies behavior of ``tm27``. |
---|
109 | |
---|
110 | - ``Install_tm27_vector`` - installs the interrupt service routine for the |
---|
111 | Interrupt Benchmark Test (``tm27``). |
---|
112 | |
---|
113 | - ``Cause_tm27_intr`` - generates the interrupt source used in the Interrupt |
---|
114 | Benchmark Test (``tm27``). |
---|
115 | |
---|
116 | - ``Clear_tm27_intr`` - clears the interrupt source used in the Interrupt |
---|
117 | Benchmark Test (``tm27``). |
---|
118 | |
---|
119 | - ``Lower_tm27_intr`` - lowers the interrupt mask so the interrupt source used |
---|
120 | in the Interrupt Benchmark Test (``tm27``) can generate a nested interrupt. |
---|
121 | |
---|
122 | All members of the Timing Test Suite are designed to run *WITHOUT* the Clock |
---|
123 | Device Driver installed. This increases the predictability of the tests' |
---|
124 | execution as well as avoids occassionally including the overhead of a clock |
---|
125 | tick interrupt in the time reported. Because of this it is sometimes possible |
---|
126 | to use the clock tick interrupt source as the source of this test interrupt. |
---|
127 | On other architectures, it is possible to directly force an interrupt to occur. |
---|
128 | |
---|
129 | sbrk() Implementation |
---|
130 | ===================== |
---|
131 | |
---|
132 | Although nearly all BSPs give all possible memory to the C Program Heap at |
---|
133 | initialization, it is possible for a BSP to configure the initial size of the |
---|
134 | heap small and let it grow on demand. If the BSP wants to dynamically extend |
---|
135 | the heap used by the C Library memory allocation routines (i.e. ``malloc`` |
---|
136 | family), then the``sbrk`` routine must be functional. The following is the |
---|
137 | prototype for this routine: |
---|
138 | |
---|
139 | .. code-block:: c |
---|
140 | |
---|
141 | void * sbrk(size_t increment) |
---|
142 | |
---|
143 | The ``increment`` amount is based upon the ``sbrk_amount`` parameter passed to |
---|
144 | the ``bsp_libc_init`` during system initialization. |
---|
145 | |
---|
146 | .. index:: CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK |
---|
147 | |
---|
148 | If your BSP does not want to support dynamic heap extension, then you do not |
---|
149 | have to do anything special. However, if you want to support ``sbrk``, you |
---|
150 | must provide an implementation of this method and define |
---|
151 | ``CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK`` in ``bsp.h``. This informs |
---|
152 | ``rtems/confdefs.h`` to configure the Malloc Family Extensions which support |
---|
153 | ``sbrk``. |
---|
154 | |
---|
155 | bsp_fatal_extension() - Cleanup the Hardware |
---|
156 | ============================================ |
---|
157 | |
---|
158 | The ``bsp_fatal_extension()`` is an optional BSP specific initial extension |
---|
159 | invoked once a fatal system state is reached. Most of the BSPs use the same |
---|
160 | shared version of ``bsp_fatal_extension()`` that does nothing or performs a |
---|
161 | system reset. This implementation is located in the |
---|
162 | `bsps/shared/start/bspfatal-default.c <https://git.rtems.org/rtems/tree/bsps/shared/start/bspfatal-default.c>`_ |
---|
163 | file. |
---|
164 | |
---|
165 | The ``bsp_fatal_extension()`` routine can be used to return to a ROM monitor, |
---|
166 | insure that interrupt sources are disabled, etc.. This routine is the last |
---|
167 | place to ensure a clean shutdown of the hardware. The fatal source, internal |
---|
168 | error indicator, and the fatal code arguments are available to evaluate the |
---|
169 | fatal condition. All of the non-fatal shutdown sequences ultimately pass their |
---|
170 | exit status to ``rtems_shutdown_executive`` and this is what is passed to this |
---|
171 | routine in case the fatal source is ``RTEMS_FATAL_SOURCE_EXIT``. |
---|
172 | |
---|
173 | On some BSPs, it prints a message indicating that the application completed |
---|
174 | execution and waits for the user to press a key before resetting the board. |
---|
175 | The PowerPC/gen83xx and PowerPC/gen5200 BSPs do this when they are built to |
---|
176 | support the FreeScale evaluation boards. This is convenient when using the |
---|
177 | boards in a development environment and may be disabled for production use. |
---|
178 | |
---|
179 | Configuration Macros |
---|
180 | ==================== |
---|
181 | |
---|
182 | Each BSP can define macros in bsp.h which alter some of the the default |
---|
183 | configuration parameters in ``rtems/confdefs.h``. This section describes those |
---|
184 | macros: |
---|
185 | |
---|
186 | .. index:: CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK |
---|
187 | |
---|
188 | - ``CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK`` must be defined if the BSP has proper |
---|
189 | support for ``sbrk``. This is discussed in more detail in the previous |
---|
190 | section. |
---|
191 | |
---|
192 | .. index:: BSP_IDLE_TASK_BODY |
---|
193 | |
---|
194 | - ``BSP_IDLE_TASK_BODY`` may be defined to the entry point of a BSP specific |
---|
195 | IDLE thread implementation. This may be overridden if the application |
---|
196 | provides its own IDLE task implementation. |
---|
197 | |
---|
198 | .. index:: BSP_IDLE_TASK_STACK_SIZE |
---|
199 | |
---|
200 | - ``BSP_IDLE_TASK_STACK_SIZE`` may be defined to the desired default stack size |
---|
201 | for the IDLE task as recommended when using this BSP. |
---|
202 | |
---|
203 | .. index:: BSP_INTERRUPT_STACK_SIZE |
---|
204 | |
---|
205 | - ``BSP_INTERRUPT_STACK_SIZE`` may be defined to the desired default interrupt |
---|
206 | stack size as recommended when using this BSP. This is sometimes required |
---|
207 | when the BSP developer has knowledge of stack intensive interrupt handlers. |
---|
208 | |
---|
209 | .. index:: BSP_ZERO_WORKSPACE_AUTOMATICALLY |
---|
210 | |
---|
211 | - ``BSP_ZERO_WORKSPACE_AUTOMATICALLY`` is defined when the BSP requires that |
---|
212 | RTEMS zero out the RTEMS C Program Heap at initialization. If the memory is |
---|
213 | already zeroed out by a test sequence or boot ROM, then the boot time can be |
---|
214 | reduced by not zeroing memory twice. |
---|
215 | |
---|
216 | .. index:: BSP_DEFAULT_UNIFIED_WORK_AREAS |
---|
217 | |
---|
218 | - ``BSP_DEFAULT_UNIFIED_WORK_AREAS`` is defined when the BSP recommends that |
---|
219 | the unified work areas configuration should always be used. This is |
---|
220 | desirable when the BSP is known to always have very little RAM and thus |
---|
221 | saving memory by any means is desirable. |
---|
222 | |
---|
223 | set_vector() - Install an Interrupt Vector |
---|
224 | ========================================== |
---|
225 | |
---|
226 | On targets with Simple Vectored Interrupts, the BSP must provide an |
---|
227 | implementation of the ``set_vector`` routine. This routine is responsible for |
---|
228 | installing an interrupt vector. It invokes the support routines necessary to |
---|
229 | install an interrupt handler as either a "raw" or an RTEMS interrupt handler. |
---|
230 | Raw handlers bypass the RTEMS interrupt structure and are responsible for |
---|
231 | saving and restoring all their own registers. Raw handlers are useful for |
---|
232 | handling traps, debug vectors, etc. |
---|
233 | |
---|
234 | The ``set_vector`` routine is a central place to perform interrupt controller |
---|
235 | manipulation and encapsulate that information. It is usually implemented as |
---|
236 | follows: |
---|
237 | |
---|
238 | .. code-block:: c |
---|
239 | |
---|
240 | rtems_isr_entry set_vector( /* returns old vector */ |
---|
241 | rtems_isr_entry handler, /* isr routine */ |
---|
242 | rtems_vector_number vector, /* vector number */ |
---|
243 | int type /* RTEMS or RAW intr */ |
---|
244 | ) |
---|
245 | { |
---|
246 | if the type is RAW |
---|
247 | install the raw vector |
---|
248 | else |
---|
249 | use rtems_interrupt_catch to install the vector |
---|
250 | perform any interrupt controller necessary to unmask the interrupt source |
---|
251 | return the previous handler |
---|
252 | } |
---|
253 | |
---|
254 | .. note:: |
---|
255 | |
---|
256 | The i386, PowerPC and ARM ports use a Programmable Interrupt Controller |
---|
257 | model which does not require the BSP to implement ``set_vector``. BSPs for |
---|
258 | these architectures must provide a different set of support routines. |
---|
259 | |
---|
260 | Interrupt Delay Profiling |
---|
261 | ========================= |
---|
262 | |
---|
263 | The RTEMS profiling needs support by the BSP for the interrupt delay times. In |
---|
264 | case profiling is enabled via the RTEMS build configuration option |
---|
265 | ``--enable-profiling`` (in this case the pre-processor symbol |
---|
266 | ``RTEMS_PROFILING`` is defined) a BSP may provide data for the interrupt delay |
---|
267 | times. The BSP can feed interrupt delay times with the |
---|
268 | ``_Profiling_Update_max_interrupt_delay()`` function (``#include |
---|
269 | <rtems/score/profiling.h>``). For an example please have a look at |
---|
270 | `bsps/sparc/leon3/clock/ckinit.c <https://git.rtems.org/rtems/tree/bsps/sparc/leon3/clock/ckinit.c>`_. |
---|
271 | |
---|
272 | Programmable Interrupt Controller API |
---|
273 | ===================================== |
---|
274 | |
---|
275 | A BSP can use the PIC API to install Interrupt Service Routines through a set |
---|
276 | of generic methods. In order to do so, the header files |
---|
277 | `<bsp/irq-generic.h> <https://git.rtems.org/rtems/tree/bsps/include/bsp/irq-generic.h>`_ |
---|
278 | and |
---|
279 | `<bsp/irq-info.h> <https://git.rtems.org/rtems/tree/bsps/include/bsp/irq-info.h>`_ |
---|
280 | must be included by the bsp specific irq.h file present in the include/ |
---|
281 | directory. The irq.h acts as a BSP interrupt support configuration file which |
---|
282 | is used to define some important MACROS. It contains the declarations for any |
---|
283 | required global functions like bsp_interrupt_dispatch(). Thus later on, every |
---|
284 | call to the PIC interface requires including ``<bsp/irq.h>`` |
---|
285 | |
---|
286 | The generic interrupt handler table is intitalized by invoking the |
---|
287 | ``bsp_interrupt_initialize()`` method from bsp_start() in the bspstart.c file |
---|
288 | which sets up this table to store the ISR addresses, whose size is based on the |
---|
289 | definition of macros, ``BSP_INTERRUPT_VECTOR_MIN`` and |
---|
290 | ``BSP_INTERRUPT_VECTOR_MAX`` in include/bsp.h |
---|
291 | |
---|
292 | For the generic handler table to properly function, some bsp specific code is |
---|
293 | required, that should be present in ``irq/irq.c``. The bsp-specific functions |
---|
294 | required to be writen by the BSP developer are : |
---|
295 | |
---|
296 | .. index:: bsp_interrupt_facility_initialize() |
---|
297 | |
---|
298 | - ``bsp_interrupt_facility_initialize()`` contains bsp specific interrupt |
---|
299 | initialization code(Clear Pending interrupts by modifying registers, etc.). |
---|
300 | This method is called from ``bsp_interrupt_initialize()`` internally while |
---|
301 | setting up the table. |
---|
302 | |
---|
303 | .. index:: bsp_interrupt_handler_default() |
---|
304 | |
---|
305 | - ``bsp_interrupt_handler_default()`` acts as a fallback handler when no ISR |
---|
306 | address has been provided corresponding to a vector in the table. |
---|
307 | |
---|
308 | .. index:: bsp_interrupt_dispatch() |
---|
309 | |
---|
310 | - ``bsp_interrupt_dispatch()`` service the ISR by handling any bsp specific |
---|
311 | code & calling the generic method ``bsp_interrupt_handler_dispatch()`` which |
---|
312 | in turn services the interrupt by running the ISR after looking it up in the |
---|
313 | table. It acts as an entry to the interrupt switchboard, since the bsp |
---|
314 | branches to this function at the time of occurrence of an interrupt. |
---|
315 | |
---|
316 | .. index:: bsp_interrupt_vector_enable() |
---|
317 | |
---|
318 | - ``bsp_interrupt_vector_enable()`` enables interrupts and is called in |
---|
319 | irq-generic.c while setting up the table. |
---|
320 | |
---|
321 | .. index:: bsp_interrupt_vector_disable() |
---|
322 | |
---|
323 | - ``bsp_interrupt_vector_disable()`` disables interrupts and is called in |
---|
324 | irq-generic.c while setting up the table & during other important parts. |
---|
325 | |
---|
326 | An interrupt handler is installed or removed with the help of the following functions : |
---|
327 | |
---|
328 | .. code-block:: c |
---|
329 | |
---|
330 | rtems_status_code rtems_interrupt_handler_install( /* returns status code */ |
---|
331 | rtems_vector_number vector, /* interrupt vector */ |
---|
332 | const char *info, /* custom identification text */ |
---|
333 | rtems_option options, /* Type of Interrupt */ |
---|
334 | rtems_interrupt_handler handler, /* interrupt handler */ |
---|
335 | void *arg /* parameter to be passed |
---|
336 | to handler at the time of |
---|
337 | invocation */ |
---|
338 | ) |
---|
339 | rtems_status_code rtems_interrupt_handler_remove( /* returns status code */ |
---|
340 | rtems_vector_number vector, /* interrupt vector */ |
---|
341 | rtems_interrupt_handler handler, /* interrupt handler */ |
---|
342 | void *arg /* parameter to be passed to handler */ |
---|
343 | ) |
---|