source: rtems-docs/bsp-howto/miscellanous_support.rst @ bb58b81

5
Last change on this file since bb58b81 was bb58b81, checked in by Joel Sherrill <joel@…>, on 11/22/19 at 17:27:09

bsp-howto/miscellanous_support.rst: Fix grammar mistake.

  • Property mode set to 100644
File size: 14.9 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3
4.. Copyright (C) 1988, 2002 On-Line Applications Research Corporation (OAR)
5
6Miscellaneous Support Files
7***************************
8
9.. warning::
10
11   This chapter contains outdated and confusing information.
12
13GCC Compiler Specifications File
14================================
15
16The file ``bsp_specs`` defines the start files and libraries that are always
17used with this BSP.  The format of this file is admittedly cryptic and this
18document 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
34The first section of this file renames the built-in definition of some
35specification variables so they can be augmented without embedded their
36original definition.  The subsequent sections specify what behavior is expected
37when the ``-qrtems`` option is specified.
38
39The ``*startfile`` section specifies that the BSP specific file ``start.o``
40will be used instead of ``crt0.o``.  In addition, various EABI support files
41(``ecrti.o`` etc.) will be linked in with the executable.
42
43The ``*link`` section adds some arguments to the linker when it is invoked by
44GCC to link an application for this BSP.
45
46The format of this file is specific to the GNU Compiler Suite.  The argument
47used to override and extend the compiler built-in specifications is available
48in all recent GCC versions.  The ``-specs`` option is present in all ``egcs``
49distributions and ``gcc`` distributions starting with version 2.8.0.
50
51README Files
52============
53
54Most 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
56and its hardware configuration, provides vendor information, local
57configuration information, information on downloading code to the board,
58debugging, etc..  The intent of this file is to help someone begin to use the
59BSP faster.
60
61A ``README`` file in a BSP subdirectory typically explains something about the
62contents of that subdirectory in greater detail.  For example, it may list the
63documentation available for a particular peripheral controller and how to
64obtain that documentation.  It may also explain some particularly cryptic part
65of the software in that directory or provide rationale on the implementation.
66
67Times
68=====
69
70This file contains the results of the RTEMS Timing Test Suite.  It is in a
71standard format so that results from one BSP can be easily compared with those
72of another target board.
73
74If a BSP supports multiple variants, then there may be multiple ``times``
75files.  Usually these are named ``times.VARIANTn``.
76
77Tools Subdirectory
78==================
79
80Some BSPs provide additional tools that aid in using the target board.  These
81tools run on the development host and are built as part of building the BSP.
82Most common is a script to automate running the RTEMS Test Suites on the BSP.
83Examples 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
90bsp.h Include File
91==================
92
93The file ``include/bsp.h`` contains prototypes and definitions specific to this
94board.  Every BSP is required to provide a ``bsp.h``.  The best approach to
95writing a ``bsp.h`` is copying an existing one as a starting point.
96
97Many ``bsp.h`` files provide prototypes of variables defined in the linker
98script (``linkcmds``).
99
100tm27.h Include File
101===================
102
103The ``tm27`` test from the RTEMS Timing Test Suite is designed to measure the
104length of time required to vector to and return from an interrupt handler. This
105test requires some help from the BSP to know how to cause and manipulate the
106interrupt 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
122All members of the Timing Test Suite are designed to run *WITHOUT* the Clock
123Device Driver installed.  This increases the predictability of the tests'
124execution as well as avoids occassionally including the overhead of a clock
125tick interrupt in the time reported.  Because of this it is sometimes possible
126to use the clock tick interrupt source as the source of this test interrupt.
127On other architectures, it is possible to directly force an interrupt to occur.
128
129sbrk() Implementation
130=====================
131
132Although nearly all BSPs give all possible memory to the C Program Heap at
133initialization, it is possible for a BSP to configure the initial size of the
134heap small and let it grow on demand.  If the BSP wants to dynamically extend
135the heap used by the C Library memory allocation routines (i.e. ``malloc``
136family), then the``sbrk`` routine must be functional.  The following is the
137prototype for this routine:
138
139.. code-block:: c
140
141    void * sbrk(ptrdiff_t increment)
142
143The ``increment`` amount is based upon the ``sbrk_amount`` parameter passed to
144the ``bsp_libc_init`` during system initialization.
145
146.. index:: CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
147
148If your BSP does not want to support dynamic heap extension, then you do not
149have to do anything special.  However, if you want to support ``sbrk``, you
150must 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
155bsp_fatal_extension() - Cleanup the Hardware
156============================================
157
158The ``bsp_fatal_extension()`` is an optional BSP specific initial extension
159invoked once a fatal system state is reached.  Most of the BSPs use the same
160shared version of ``bsp_fatal_extension()`` that does nothing or performs a
161system 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>`_
163file.
164
165The ``bsp_fatal_extension()`` routine can be used to return to a ROM monitor,
166insure that interrupt sources are disabled, etc..  This routine is the last
167place to ensure a clean shutdown of the hardware.  The fatal source, internal
168error indicator, and the fatal code arguments are available to evaluate the
169fatal condition.  All of the non-fatal shutdown sequences ultimately pass their
170exit status to ``rtems_shutdown_executive`` and this is what is passed to this
171routine in case the fatal source is ``RTEMS_FATAL_SOURCE_EXIT``.
172
173On some BSPs, it prints a message indicating that the application completed
174execution and waits for the user to press a key before resetting the board.
175The PowerPC/gen83xx and PowerPC/gen5200 BSPs do this when they are built to
176support the FreeScale evaluation boards.  This is convenient when using the
177boards in a development environment and may be disabled for production use.
178
179Configuration Macros
180====================
181
182Each BSP can define macros in bsp.h which alter some of the the default
183configuration parameters in ``rtems/confdefs.h``.  This section describes those
184macros:
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
223set_vector() - Install an Interrupt Vector
224==========================================
225
226On targets with Simple Vectored Interrupts, the BSP must provide an
227implementation of the ``set_vector`` routine.  This routine is responsible for
228installing an interrupt vector.  It invokes the support routines necessary to
229install an interrupt handler as either a "raw" or an RTEMS interrupt handler.
230Raw handlers bypass the RTEMS interrupt structure and are responsible for
231saving and restoring all their own registers.  Raw handlers are useful for
232handling traps, debug vectors, etc.
233
234The ``set_vector`` routine is a central place to perform interrupt controller
235manipulation and encapsulate that information.  It is usually implemented as
236follows:
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
260Interrupt Delay Profiling
261=========================
262
263The RTEMS profiling needs support by the BSP for the interrupt delay times.  In
264case 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
267times.  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
272Programmable Interrupt Controller API
273=====================================
274
275A BSP can use the PIC API to install Interrupt Service Routines through a set
276of 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>`_
278and
279`<bsp/irq-info.h> <https://git.rtems.org/rtems/tree/bsps/include/bsp/irq-info.h>`_
280must be included by the bsp specific irq.h file present in the include/
281directory. The irq.h acts as a BSP interrupt support configuration file which
282is used to define some important MACROS. It contains the declarations for any
283required global functions like bsp_interrupt_dispatch(). Thus later on, every
284call to the PIC interface requires including ``<bsp/irq.h>``
285
286The generic interrupt handler table is intitalized by invoking the
287``bsp_interrupt_initialize()`` method from bsp_start() in the bspstart.c file
288which sets up this table to store the ISR addresses, whose size is based on the
289definition of macros, ``BSP_INTERRUPT_VECTOR_MIN`` and
290``BSP_INTERRUPT_VECTOR_MAX`` in include/bsp.h
291
292For the generic handler table to properly function, some bsp specific code is
293required, that should be present in ``irq/irq.c``. The bsp-specific functions
294required 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()`` services 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
326An 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    )
Note: See TracBrowser for help on using the repository browser.