source: rtems-docs/cpu_supplement/port.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

  • Property mode set to 100644
File size: 19.4 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3Port Specific Information
4#########################
5
6This chaper provides a general description of the type of
7architecture specific information which is in each of
8the architecture specific chapters that follow.  The outline
9of this chapter is identical to that of the architecture
10specific chapters.
11
12In each of the architecture specific chapters, this
13introductory section will provide an overview of the
14architecture
15
16**Architecture Documents**
17
18In each of the architecture specific chapters, this
19section will provide pointers on where to obtain
20documentation.
21
22CPU Model Dependent Features
23============================
24
25Microprocessors are generally classified into families with a variety of
26CPU models or implementations within that family.  Within a processor
27family, there is a high level of binary compatibility.  This family
28may be based on either an architectural specification or on maintaining
29compatibility with a popular processor.  Recent microprocessor families
30such as the SPARC or PowerPC are based on an architectural specification
31which is independent or any particular CPU model or implementation.
32Older families such as the Motorola 68000 and the Intel x86 evolved as the
33manufacturer strived to produce higher performance processor models which
34maintained binary compatibility with older models.
35
36RTEMS takes advantage of the similarity of the various models within a
37CPU family.  Although the models do vary in significant ways, the high
38level of compatibility makes it possible to share the bulk of the CPU
39dependent executive code across the entire family.  Each processor family
40supported by RTEMS has a list of features which vary between CPU models
41within a family.  For example, the most common model dependent feature
42regardless of CPU family is the presence or absence of a floating point
43unit or coprocessor.  When defining the list of features present on a
44particular CPU model, one simply notes that floating point hardware
45is or is not present and defines a single constant appropriately.
46Conditional compilation is utilized to include the appropriate source
47code for this CPU model's feature set.  It is important to note that
48this means that RTEMS is thus compiled using the appropriate feature set
49and compilation flags optimal for this CPU model used.  The alternative
50would be to generate a binary which would execute on all family members
51using only the features which were always present.
52
53The set of CPU model feature macros are defined in the file``cpukit/score/cpu/CPU/rtems/score/cpu.h`` based upon the GNU tools
54multilib variant that is appropriate for the particular CPU model defined
55on the compilation command line.
56
57In each of the architecture specific chapters, this section presents
58the set of features which vary across various implementations of the
59architecture that may be of importance to RTEMS application developers.
60
61The subsections will vary amongst the target architecture chapters as
62the specific features may vary.  However, each port will include a few
63common features such as the CPU Model Name and presence of a hardware
64Floating Point Unit.  The common features are described here.
65
66CPU Model Name
67--------------
68
69The macro ``CPU_MODEL_NAME`` is a string which designates
70the name of this CPU model.  For example, for the MC68020
71processor model from the m68k architecture, this macro
72is set to the string "mc68020".
73
74Floating Point Unit
75-------------------
76
77In most architectures, the presence of a floating point unit is an option.
78It does not matter whether the hardware floating point support is
79incorporated on-chip or is an external coprocessor as long as it
80appears an FPU per the ISA.  However, if a hardware FPU is not present,
81it is possible that the floating point emulation library for this
82CPU is not reentrant and thus context switched by RTEMS.
83
84RTEMS provides two feature macros to indicate the FPU configuration:
85
86- CPU_HARDWARE_FP
87  is set to TRUE to indicate that a hardware FPU is present.
88
89- CPU_SOFTWARE_FP
90  is set to TRUE to indicate that a hardware FPU is not present and that
91  the FP software emulation will be context switched.
92
93Multilibs
94=========
95
96Newlib and GCC provide several target libraries like the :file:`libc.a`,:file:`libm.a` and :file:`libgcc.a`.  These libraries are artifacts of the GCC
97build process.  Newlib is built together with GCC.  To provide optimal support
98for various chip derivatives and instruction set revisions multiple variants of
99these libraries are available for each architecture.  For example one set may
100use software floating point support and another set may use hardware floating
101point instructions.  These sets of libraries are called *multilibs*.  Each
102library set corresponds to an application binary interface (ABI) and
103instruction set.
104
105A multilib variant can be usually detected via built-in compiler defines at
106compile-time.  This mechanism is used by RTEMS to select for example the
107context switch support for a particular BSP.  The built-in compiler defines
108corresponding to multilibs are the only architecture specific defines allowed
109in the ``cpukit`` area of the RTEMS sources.
110
111Invoking the GCC with the ``-print-multi-lib`` option lists the available
112multilibs.  Each line of the output describes one multilib variant.  The
113default variant is denoted by ``.`` which is selected when no or
114contradicting GCC machine options are selected.  The multilib selection for a
115target is specified by target makefile fragments (see file :file:`t-rtems` in
116the GCC sources and section`The Target Makefile Fragment <https://gcc.gnu.org/onlinedocs/gccint/Target-Fragment.html#Target-Fragment>`_
117in the `GCC Internals Manual <https://gcc.gnu.org/onlinedocs/gccint/>`_.
118
119Calling Conventions
120===================
121
122Each high-level language compiler generates subroutine entry and exit
123code based upon a set of rules known as the compiler's calling convention.
124These rules address the following issues:
125
126- register preservation and usage
127
128- parameter passing
129
130- call and return mechanism
131
132A compiler's calling convention is of importance when
133interfacing to subroutines written in another language either
134assembly or high-level.  Even when the high-level language and
135target processor are the same, different compilers may use
136different calling conventions.  As a result, calling conventions
137are both processor and compiler dependent.
138
139Calling Mechanism
140-----------------
141
142In each of the architecture specific chapters, this subsection will
143describe the instruction(s) used to perform a *normal* subroutine
144invocation.  All RTEMS directives are invoked as *normal* C language
145functions so it is important to the user application to understand the
146call and return mechanism.
147
148Register Usage
149--------------
150
151In each of the architecture specific chapters, this subsection will
152detail the set of registers which are *NOT* preserved across subroutine
153invocations.  The registers which are not preserved are assumed to be
154available for use as scratch registers.  Therefore, the contents of these
155registers should not be assumed upon return from any RTEMS directive.
156
157In some architectures, there may be a set of registers made available
158automatically as a side-effect of the subroutine invocation
159mechanism.
160
161Parameter Passing
162-----------------
163
164In each of the architecture specific chapters, this subsection will
165describe the mechanism by which the parameters or arguments are passed
166by the caller to a subroutine.  In some architectures, all parameters
167are passed on the stack while in others some are passed in registers.
168
169User-Provided Routines
170----------------------
171
172All user-provided routines invoked by RTEMS, such as
173user extensions, device drivers, and MPCI routines, must also
174adhere to these calling conventions.
175
176Memory Model
177============
178
179A processor may support any combination of memory
180models ranging from pure physical addressing to complex demand
181paged virtual memory systems.  RTEMS supports a flat memory
182model which ranges contiguously over the processor's allowable
183address space.  RTEMS does not support segmentation or virtual
184memory of any kind.  The appropriate memory model for RTEMS
185provided by the targeted processor and related characteristics
186of that model are described in this chapter.
187
188Flat Memory Model
189-----------------
190
191Most RTEMS target processors can be initialized to support a flat address
192space.  Although the size of addresses varies between architectures, on
193most RTEMS targets, an address is 32-bits wide which defines addresses
194ranging from 0x00000000 to 0xFFFFFFFF (4 gigabytes).  Each address is
195represented by a 32-bit value and is byte addressable.  The address may be
196used to reference a single byte, word (2-bytes), or long word (4 bytes).
197Memory accesses within this address space may be performed in little or
198big endian fashion.
199
200On smaller CPU architectures supported by RTEMS, the address space
201may only be 20 or 24 bits wide.
202
203If the CPU model has support for virtual memory or segmentation, it is
204the responsibility of the Board Support Package (BSP) to initialize the
205MMU hardware to perform address translations which correspond to flat
206memory model.
207
208In each of the architecture specific chapters, this subsection will
209describe any architecture characteristics that differ from this general
210description.
211
212Interrupt Processing
213====================
214
215Different types of processors respond to the occurrence of an interrupt
216in its own unique fashion. In addition, each processor type provides
217a control mechanism to allow for the proper handling of an interrupt.
218The processor dependent response to the interrupt modifies the current
219execution state and results in a change in the execution stream.  Most
220processors require that an interrupt handler utilize some special control
221mechanisms to return to the normal processing stream.  Although RTEMS
222hides many of the processor dependent details of interrupt processing,
223it is important to understand how the RTEMS interrupt manager is mapped
224onto the processor's unique architecture.
225
226RTEMS supports a dedicated interrupt stack for all architectures.
227On architectures with hardware support for a dedicated interrupt stack,
228it will be initialized such that when an interrupt occurs, the processor
229automatically switches to this dedicated stack.  On architectures without
230hardware support for a dedicated interrupt stack which is separate from
231those of the tasks, RTEMS will support switching to a dedicated stack
232for interrupt processing.
233
234Without a dedicated interrupt stack, every task in
235the system MUST have enough stack space to accommodate the worst
236case stack usage of that particular task and the interrupt
237service routines COMBINED.  By supporting a dedicated interrupt
238stack, RTEMS significantly lowers the stack requirements for
239each task.
240
241A nested interrupt is processed similarly with the exception that since
242the CPU is already executing on the interrupt stack, there is no need
243to switch to the interrupt stack.
244
245In some configurations, RTEMS allocates the interrupt stack from the
246Workspace Area.  The amount of memory allocated for the interrupt stack
247is user configured and based upon the ``confdefs.h`` parameter``CONFIGURE_INTERRUPT_STACK_SIZE``.  This parameter is described
248in detail in the Configuring a System chapter of the User's Guide.
249On configurations in which RTEMS allocates the interrupt stack, during
250the initialization process, RTEMS will also install its interrupt stack.
251In other configurations, the interrupt stack is allocated and installed
252by the Board Support Package (BSP).
253
254In each of the architecture specific chapters, this section discesses
255the interrupt response and control mechanisms of the architecture as
256they pertain to RTEMS.
257
258Vectoring of an Interrupt Handler
259---------------------------------
260
261In each of the architecture specific chapters, this subsection will
262describe the architecture specific details of the interrupt vectoring
263process.  In particular, it should include a description of the
264Interrupt Stack Frame (ISF).
265
266Interrupt Levels
267----------------
268
269In each of the architecture specific chapters, this subsection will
270describe how the interrupt levels available on this particular architecture
271are mapped onto the 255 reserved in the task mode.  The interrupt level
272value of zero (0) should always mean that interrupts are enabled.
273
274Any use of an  interrupt level that is is not undefined on a particular
275architecture may result in behavior that is unpredictable.
276
277Disabling of Interrupts by RTEMS
278--------------------------------
279
280During the execution of directive calls, critical sections of code may
281be executed.  When these sections are encountered, RTEMS disables all
282external interrupts before the execution of this section and restores
283them to the previous level upon completion of the section.  RTEMS has
284been optimized to ensure that interrupts are disabled for the shortest
285number of instructions possible.  Since the precise number of instructions
286and their execution time varies based upon target CPU family, CPU model,
287board memory speed, compiler version, and optimization level, it is
288not practical to provide the precise number for all possible RTEMS
289configurations.
290
291Historically, the measurements were made by hand analyzing and counting
292the execution time of instruction sequences during interrupt disable
293critical sections.  For reference purposes, on a 16 Mhz Motorola
294MC68020, the maximum interrupt disable period was typically approximately
295ten (10) to thirteen (13) microseconds.  This architecture was memory bound
296and had a slow bit scan instruction.  In contrast, during the same
297period a 14 Mhz SPARC would have a worst case disable time of approximately
298two (2) to three (3) microseconds because it had a single cycle bit scan
299instruction and used fewer cycles for memory accesses.
300
301If you are interested in knowing the worst case execution time for
302a particular version of RTEMS, please contact OAR Corporation and
303we will be happy to product the results as a consulting service.
304
305Non-maskable interrupts (NMI) cannot be disabled, and
306ISRs which execute at this level MUST NEVER issue RTEMS system
307calls.  If a directive is invoked, unpredictable results may
308occur due to the inability of RTEMS to protect its critical
309sections.  However, ISRs that make no system calls may safely
310execute as non-maskable interrupts.
311
312Default Fatal Error Processing
313==============================
314
315Upon detection of a fatal error by either the application or RTEMS during
316initialization the ``rtems_fatal_error_occurred`` directive supplied
317by the Fatal Error Manager is invoked.  The Fatal Error Manager will
318invoke the user-supplied fatal error handlers.  If no user-supplied
319handlers are configured or all of them return without taking action to
320shutdown the processor or reset, a default fatal error handler is invoked.
321
322Most of the action performed as part of processing the fatal error are
323described in detail in the Fatal Error Manager chapter in the User's
324Guide.  However, the if no user provided extension or BSP specific fatal
325error handler takes action, the final default action is to invoke a
326CPU architecture specific function.  Typically this function disables
327interrupts and halts the processor.
328
329In each of the architecture specific chapters, this describes the precise
330operations of the default CPU specific fatal error handler.
331
332Symmetric Multiprocessing
333=========================
334
335This section contains information about the Symmetric Multiprocessing (SMP)
336status of a particular architecture.
337
338Thread-Local Storage
339====================
340
341In order to support thread-local storage (TLS) the CPU port must implement the
342facilities mandated by the application binary interface (ABI) of the CPU
343architecture.  The CPU port must initialize the TLS area in the``_CPU_Context_Initialize()`` function.  There are support functions available
344via ``#include <rtems/score/tls.h>`` which implement Variants I and II
345according to Ulrich Drepper, *ELF Handling For Thread-Local Storage*.
346
347``_TLS_TCB_at_area_begin_initialize()``
348    Uses Variant I, TLS offsets emitted by linker takes the TCB into account.  For
349    a reference implementation see :file:`cpukit/score/cpu/arm/cpu.c`.
350
351``_TLS_TCB_before_TLS_block_initialize()``
352    Uses Variant I, TLS offsets emitted by linker neglects the TCB.  For a
353    reference implementation see:file:`c/src/lib/libcpu/powerpc/new-exceptions/cpu.c`.
354
355``_TLS_TCB_after_TLS_block_initialize()``
356    Uses Variant II.  For a reference implementation see:file:`cpukit/score/cpu/sparc/cpu.c`.
357
358The board support package (BSP) must provide the following sections and symbols
359in its linker command file:
360.. code:: c
361
362    .tdata : {
363    _TLS_Data_begin = .;
364    \*(.tdata .tdata.* .gnu.linkonce.td.*)
365    _TLS_Data_end = .;
366    }
367    .tbss : {
368    _TLS_BSS_begin = .;
369    \*(.tbss .tbss.* .gnu.linkonce.tb.*) \*(.tcommon)
370    _TLS_BSS_end = .;
371    }
372    _TLS_Data_size = _TLS_Data_end - _TLS_Data_begin;
373    _TLS_Data_begin = _TLS_Data_size != 0 ? _TLS_Data_begin : _TLS_BSS_begin;
374    _TLS_Data_end = _TLS_Data_size != 0 ? _TLS_Data_end : _TLS_BSS_begin;
375    _TLS_BSS_size = _TLS_BSS_end - _TLS_BSS_begin;
376    _TLS_Size = _TLS_BSS_end - _TLS_Data_begin;
377    _TLS_Alignment = MAX (ALIGNOF (.tdata), ALIGNOF (.tbss));
378
379CPU counter
380===========
381
382The CPU support must implement the CPU counter interface.  A CPU counter is
383some free-running counter.  It ticks usually with a frequency close to the CPU
384or system bus clock.  On some architectures the actual implementation is board
385support package dependent.  The CPU counter is used for profiling of low-level
386functions.  It is also used to implement two busy wait functions``rtems_counter_delay_ticks()`` and ``rtems_counter_delay_nanoseconds()``
387which may be used in device drivers.  It may be also used as an entropy source
388for random number generators.
389
390The CPU counter interface uses a CPU port specific unsigned integer type``CPU_Counter_ticks`` to represent CPU counter values.  The CPU port must
391provide the following two functions
392
393- ``_CPU_Counter_read()`` to read the current CPU counter value, and
394
395- ``_CPU_Counter_difference()`` to get the difference between two CPU
396  counter values.
397
398Interrupt Profiling
399===================
400
401The RTEMS profiling needs support by the CPU port for the interrupt entry and
402exit times.  In case profiling is enabled via the RTEMS build configuration
403option ``--enable-profiling`` (in this case the pre-processor symbol``RTEMS_PROFILING`` is defined) the CPU port may provide data for the
404interrupt entry and exit times of the outer-most interrupt.  The CPU port can
405feed interrupt entry and exit times with the``_Profiling_Outer_most_interrupt_entry_and_exit()`` function
406(``#include <rtems/score/profiling.h>``).  For an example please have a look
407at ``cpukit/score/cpu/arm/arm_exc_interrupt.S``.
408
409Board Support Packages
410======================
411
412An RTEMS Board Support Package (BSP) must be designed to support a
413particular processor model and target board combination.
414
415In each of the architecture specific chapters, this section will present
416a discussion of architecture specific BSP issues.   For more information
417on developing a BSP, refer to BSP and Device Driver Development Guide
418and the chapter titled Board Support Packages in the RTEMS
419Applications User's Guide.
420
421System Reset
422------------
423
424An RTEMS based application is initiated or re-initiated when the processor
425is reset or transfer is passed to it from a boot monitor or ROM monitor.
426
427In each of the architecture specific chapters, this subsection describes
428the actions that the BSP must tak assuming the application gets control
429when the microprocessor is reset.
430
431.. COMMENT: COPYRIGHT (c) 1988-2002.
432
433.. COMMENT: On-Line Applications Research Corporation (OAR).
434
435.. COMMENT: All rights reserved.
436
Note: See TracBrowser for help on using the repository browser.