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