source: rtems-docs/cpu_supplement/cpu_supplement_old_reference_only.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: 167.2 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3:orphan:
4
5
6
7.. COMMENT: %**end of header
8
9.. COMMENT: COPYRIGHT (c) 1989-2013.
10
11.. COMMENT: On-Line Applications Research Corporation (OAR).
12
13.. COMMENT: All rights reserved.
14
15.. COMMENT: Master file for the CPU Supplement
16
17.. COMMENT: COPYRIGHT (c) 1988-2002.
18
19.. COMMENT: On-Line Applications Research Corporation (OAR).
20
21.. COMMENT: All rights reserved.
22
23.. COMMENT: The following determines which set of the tables and figures we will use.
24
25.. COMMENT: We default to ASCII but if available TeX or HTML versions will
26
27.. COMMENT: be used instead.
28
29.. COMMENT: @clear use-html
30
31.. COMMENT: @clear use-tex
32
33.. COMMENT: The following variable says to use texinfo or html for the two column
34
35.. COMMENT: texinfo tables.  For somethings the format does not look good in html.
36
37.. COMMENT: With our adjustment to the left column in TeX, it nearly always looks
38
39.. COMMENT: good printed.
40
41.. COMMENT: Custom whitespace adjustments.  We could fiddle a bit more.
42
43.. COMMENT: Title Page Stuff
44
45.. COMMENT: I don't really like having a short title page.  -joel
46
47.. COMMENT: @shorttitlepage RTEMS CPU Architecture Supplement
48
49=================================
50RTEMS CPU Architecture Supplement
51=================================
52
53.. COMMENT: COPYRIGHT (c) 1988-2015.
54
55.. COMMENT: On-Line Applications Research Corporation (OAR).
56
57.. COMMENT: All rights reserved.
58
59.. COMMENT: The following puts a space somewhere on an otherwise empty page so we
60
61.. COMMENT: can force the copyright description onto a left hand page.
62
63COPYRIGHT © 1988 - 2015.
64
65On-Line Applications Research Corporation (OAR).
66
67The authors have used their best efforts in preparing
68this material.  These efforts include the development, research,
69and testing of the theories and programs to determine their
70effectiveness.  No warranty of any kind, expressed or implied,
71with regard to the software or the material contained in this
72document is provided.  No liability arising out of the
73application or use of any product described in this document is
74assumed.  The authors reserve the right to revise this material
75and to make changes from time to time in the content hereof
76without obligation to notify anyone of such revision or changes.
77
78The RTEMS Project is hosted at http://www.rtems.org.  Any
79inquiries concerning RTEMS, its related support components, or its
80documentation should be directed to the Community Project hosted athttp://www.rtems.org.
81
82Any inquiries for commercial services including training, support, custom
83development, application development assistance should be directed tohttp://www.rtems.com.
84
85.. COMMENT: This prevents a black box from being printed on "overflow" lines.
86
87.. COMMENT: The alternative is to rework a sentence to avoid this problem.
88
89RTEMS CPU Architecture Supplement
90#################################
91
92.. COMMENT: COPYRIGHT (c) 1989-2011.
93
94.. COMMENT: On-Line Applications Research Corporation (OAR).
95
96.. COMMENT: All rights reserved.
97
98Preface
99#######
100
101The Real Time Executive for Multiprocessor Systems
102(RTEMS) is designed to be portable across multiple processor
103architectures.  However, the nature of real-time systems makes
104it essential that the application designer understand certain
105processor dependent implementation details.  These processor
106dependencies include calling convention, board support package
107issues, interrupt processing, exact RTEMS memory requirements,
108performance data, header files, and the assembly language
109interface to the executive.
110
111Each architecture represents a CPU family and usually there are
112a wide variety of CPU models within it.  These models share a
113common Instruction Set Architecture (ISA) which often varies
114based upon some well-defined rules.  There are often
115multiple implementations of the ISA and these may be from
116one or multiple vendors.
117
118On top of variations in the ISA, there may also be variations
119which occur when a CPU core implementation is combined with
120a set of peripherals to form a system on chip.  For example,
121there are many ARM CPU models from numerous semiconductor
122vendors and a wide variety of peripherals.  But at the
123ISA level, they share a common compatibility.
124
125RTEMS depends upon this core similarity across the CPU models
126and leverages that to minimize the source code that is specific
127to any particular CPU core implementation or CPU model.
128
129This manual is separate and distinct from the RTEMS Porting
130Guide.  That manual is a guide on porting RTEMS to a new
131architecture.  This manual is focused on the more mundane
132CPU architecture specific issues that may impact
133application development.  For example, if you need to write
134a subroutine in assembly language, it is critical to understand
135the calling conventions for the target architecture.
136
137The first chapter in this manual describes these issues
138in general terms.  In a sense, it is posing the questions
139one should be aware may need to be answered and understood
140when porting an RTEMS application to a new architecture.
141Each subsequent chapter gives the answers to those questions
142for a particular CPU architecture.
143
144.. COMMENT: COPYRIGHT (c) 1988-2002.
145
146.. COMMENT: On-Line Applications Research Corporation (OAR).
147
148.. COMMENT: All rights reserved.
149
150Port Specific Information
151#########################
152
153This chaper provides a general description of the type of
154architecture specific information which is in each of
155the architecture specific chapters that follow.  The outline
156of this chapter is identical to that of the architecture
157specific chapters.
158
159In each of the architecture specific chapters, this
160introductory section will provide an overview of the
161architecture
162
163**Architecture Documents**
164
165In each of the architecture specific chapters, this
166section will provide pointers on where to obtain
167documentation.
168
169CPU Model Dependent Features
170============================
171
172Microprocessors are generally classified into families with a variety of
173CPU models or implementations within that family.  Within a processor
174family, there is a high level of binary compatibility.  This family
175may be based on either an architectural specification or on maintaining
176compatibility with a popular processor.  Recent microprocessor families
177such as the SPARC or PowerPC are based on an architectural specification
178which is independent or any particular CPU model or implementation.
179Older families such as the Motorola 68000 and the Intel x86 evolved as the
180manufacturer strived to produce higher performance processor models which
181maintained binary compatibility with older models.
182
183RTEMS takes advantage of the similarity of the various models within a
184CPU family.  Although the models do vary in significant ways, the high
185level of compatibility makes it possible to share the bulk of the CPU
186dependent executive code across the entire family.  Each processor family
187supported by RTEMS has a list of features which vary between CPU models
188within a family.  For example, the most common model dependent feature
189regardless of CPU family is the presence or absence of a floating point
190unit or coprocessor.  When defining the list of features present on a
191particular CPU model, one simply notes that floating point hardware
192is or is not present and defines a single constant appropriately.
193Conditional compilation is utilized to include the appropriate source
194code for this CPU model’s feature set.  It is important to note that
195this means that RTEMS is thus compiled using the appropriate feature set
196and compilation flags optimal for this CPU model used.  The alternative
197would be to generate a binary which would execute on all family members
198using only the features which were always present.
199
200The set of CPU model feature macros are defined in the file``cpukit/score/cpu/CPU/rtems/score/cpu.h`` based upon the GNU tools
201multilib variant that is appropriate for the particular CPU model defined
202on the compilation command line.
203
204In each of the architecture specific chapters, this section presents
205the set of features which vary across various implementations of the
206architecture that may be of importance to RTEMS application developers.
207
208The subsections will vary amongst the target architecture chapters as
209the specific features may vary.  However, each port will include a few
210common features such as the CPU Model Name and presence of a hardware
211Floating Point Unit.  The common features are described here.
212
213CPU Model Name
214--------------
215
216The macro ``CPU_MODEL_NAME`` is a string which designates
217the name of this CPU model.  For example, for the MC68020
218processor model from the m68k architecture, this macro
219is set to the string "mc68020".
220
221Floating Point Unit
222-------------------
223
224In most architectures, the presence of a floating point unit is an option.
225It does not matter whether the hardware floating point support is
226incorporated on-chip or is an external coprocessor as long as it
227appears an FPU per the ISA.  However, if a hardware FPU is not present,
228it is possible that the floating point emulation library for this
229CPU is not reentrant and thus context switched by RTEMS.
230
231RTEMS provides two feature macros to indicate the FPU configuration:
232
233- CPU_HARDWARE_FP
234  is set to TRUE to indicate that a hardware FPU is present.
235
236- CPU_SOFTWARE_FP
237  is set to TRUE to indicate that a hardware FPU is not present and that
238  the FP software emulation will be context switched.
239
240Multilibs
241=========
242
243Newlib 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
244build process.  Newlib is built together with GCC.  To provide optimal support
245for various chip derivatives and instruction set revisions multiple variants of
246these libraries are available for each architecture.  For example one set may
247use software floating point support and another set may use hardware floating
248point instructions.  These sets of libraries are called *multilibs*.  Each
249library set corresponds to an application binary interface (ABI) and
250instruction set.
251
252A multilib variant can be usually detected via built-in compiler defines at
253compile-time.  This mechanism is used by RTEMS to select for example the
254context switch support for a particular BSP.  The built-in compiler defines
255corresponding to multilibs are the only architecture specific defines allowed
256in the ``cpukit`` area of the RTEMS sources.
257
258Invoking the GCC with the ``-print-multi-lib`` option lists the available
259multilibs.  Each line of the output describes one multilib variant.  The
260default variant is denoted by ``.`` which is selected when no or
261contradicting GCC machine options are selected.  The multilib selection for a
262target is specified by target makefile fragments (see file :file:`t-rtems` in
263the GCC sources and section`The Target Makefile Fragment <https://gcc.gnu.org/onlinedocs/gccint/Target-Fragment.html#Target-Fragment>`_
264in the `GCC Internals Manual <https://gcc.gnu.org/onlinedocs/gccint/>`_.
265
266Calling Conventions
267===================
268
269Each high-level language compiler generates subroutine entry and exit
270code based upon a set of rules known as the compiler’s calling convention.
271These rules address the following issues:
272
273- register preservation and usage
274
275- parameter passing
276
277- call and return mechanism
278
279A compiler’s calling convention is of importance when
280interfacing to subroutines written in another language either
281assembly or high-level.  Even when the high-level language and
282target processor are the same, different compilers may use
283different calling conventions.  As a result, calling conventions
284are both processor and compiler dependent.
285
286Calling Mechanism
287-----------------
288
289In each of the architecture specific chapters, this subsection will
290describe the instruction(s) used to perform a *normal* subroutine
291invocation.  All RTEMS directives are invoked as *normal* C language
292functions so it is important to the user application to understand the
293call and return mechanism.
294
295Register Usage
296--------------
297
298In each of the architecture specific chapters, this subsection will
299detail the set of registers which are *NOT* preserved across subroutine
300invocations.  The registers which are not preserved are assumed to be
301available for use as scratch registers.  Therefore, the contents of these
302registers should not be assumed upon return from any RTEMS directive.
303
304In some architectures, there may be a set of registers made available
305automatically as a side-effect of the subroutine invocation
306mechanism.
307
308Parameter Passing
309-----------------
310
311In each of the architecture specific chapters, this subsection will
312describe the mechanism by which the parameters or arguments are passed
313by the caller to a subroutine.  In some architectures, all parameters
314are passed on the stack while in others some are passed in registers.
315
316User-Provided Routines
317----------------------
318
319All user-provided routines invoked by RTEMS, such as
320user extensions, device drivers, and MPCI routines, must also
321adhere to these calling conventions.
322
323Memory Model
324============
325
326A processor may support any combination of memory
327models ranging from pure physical addressing to complex demand
328paged virtual memory systems.  RTEMS supports a flat memory
329model which ranges contiguously over the processor’s allowable
330address space.  RTEMS does not support segmentation or virtual
331memory of any kind.  The appropriate memory model for RTEMS
332provided by the targeted processor and related characteristics
333of that model are described in this chapter.
334
335Flat Memory Model
336-----------------
337
338Most RTEMS target processors can be initialized to support a flat address
339space.  Although the size of addresses varies between architectures, on
340most RTEMS targets, an address is 32-bits wide which defines addresses
341ranging from 0x00000000 to 0xFFFFFFFF (4 gigabytes).  Each address is
342represented by a 32-bit value and is byte addressable.  The address may be
343used to reference a single byte, word (2-bytes), or long word (4 bytes).
344Memory accesses within this address space may be performed in little or
345big endian fashion.
346
347On smaller CPU architectures supported by RTEMS, the address space
348may only be 20 or 24 bits wide.
349
350If the CPU model has support for virtual memory or segmentation, it is
351the responsibility of the Board Support Package (BSP) to initialize the
352MMU hardware to perform address translations which correspond to flat
353memory model.
354
355In each of the architecture specific chapters, this subsection will
356describe any architecture characteristics that differ from this general
357description.
358
359Interrupt Processing
360====================
361
362Different types of processors respond to the occurrence of an interrupt
363in its own unique fashion. In addition, each processor type provides
364a control mechanism to allow for the proper handling of an interrupt.
365The processor dependent response to the interrupt modifies the current
366execution state and results in a change in the execution stream.  Most
367processors require that an interrupt handler utilize some special control
368mechanisms to return to the normal processing stream.  Although RTEMS
369hides many of the processor dependent details of interrupt processing,
370it is important to understand how the RTEMS interrupt manager is mapped
371onto the processor’s unique architecture.
372
373RTEMS supports a dedicated interrupt stack for all architectures.
374On architectures with hardware support for a dedicated interrupt stack,
375it will be initialized such that when an interrupt occurs, the processor
376automatically switches to this dedicated stack.  On architectures without
377hardware support for a dedicated interrupt stack which is separate from
378those of the tasks, RTEMS will support switching to a dedicated stack
379for interrupt processing.
380
381Without a dedicated interrupt stack, every task in
382the system MUST have enough stack space to accommodate the worst
383case stack usage of that particular task and the interrupt
384service routines COMBINED.  By supporting a dedicated interrupt
385stack, RTEMS significantly lowers the stack requirements for
386each task.
387
388A nested interrupt is processed similarly with the exception that since
389the CPU is already executing on the interrupt stack, there is no need
390to switch to the interrupt stack.
391
392In some configurations, RTEMS allocates the interrupt stack from the
393Workspace Area.  The amount of memory allocated for the interrupt stack
394is user configured and based upon the ``confdefs.h`` parameter``CONFIGURE_INTERRUPT_STACK_SIZE``.  This parameter is described
395in detail in the Configuring a System chapter of the User’s Guide.
396On configurations in which RTEMS allocates the interrupt stack, during
397the initialization process, RTEMS will also install its interrupt stack.
398In other configurations, the interrupt stack is allocated and installed
399by the Board Support Package (BSP).
400
401In each of the architecture specific chapters, this section discesses
402the interrupt response and control mechanisms of the architecture as
403they pertain to RTEMS.
404
405Vectoring of an Interrupt Handler
406---------------------------------
407
408In each of the architecture specific chapters, this subsection will
409describe the architecture specific details of the interrupt vectoring
410process.  In particular, it should include a description of the
411Interrupt Stack Frame (ISF).
412
413Interrupt Levels
414----------------
415
416In each of the architecture specific chapters, this subsection will
417describe how the interrupt levels available on this particular architecture
418are mapped onto the 255 reserved in the task mode.  The interrupt level
419value of zero (0) should always mean that interrupts are enabled.
420
421Any use of an  interrupt level that is is not undefined on a particular
422architecture may result in behavior that is unpredictable.
423
424Disabling of Interrupts by RTEMS
425--------------------------------
426
427During the execution of directive calls, critical sections of code may
428be executed.  When these sections are encountered, RTEMS disables all
429external interrupts before the execution of this section and restores
430them to the previous level upon completion of the section.  RTEMS has
431been optimized to ensure that interrupts are disabled for the shortest
432number of instructions possible.  Since the precise number of instructions
433and their execution time varies based upon target CPU family, CPU model,
434board memory speed, compiler version, and optimization level, it is
435not practical to provide the precise number for all possible RTEMS
436configurations.
437
438Historically, the measurements were made by hand analyzing and counting
439the execution time of instruction sequences during interrupt disable
440critical sections.  For reference purposes, on a 16 Mhz Motorola
441MC68020, the maximum interrupt disable period was typically approximately
442ten (10) to thirteen (13) microseconds.  This architecture was memory bound
443and had a slow bit scan instruction.  In contrast, during the same
444period a 14 Mhz SPARC would have a worst case disable time of approximately
445two (2) to three (3) microseconds because it had a single cycle bit scan
446instruction and used fewer cycles for memory accesses.
447
448If you are interested in knowing the worst case execution time for
449a particular version of RTEMS, please contact OAR Corporation and
450we will be happy to product the results as a consulting service.
451
452Non-maskable interrupts (NMI) cannot be disabled, and
453ISRs which execute at this level MUST NEVER issue RTEMS system
454calls.  If a directive is invoked, unpredictable results may
455occur due to the inability of RTEMS to protect its critical
456sections.  However, ISRs that make no system calls may safely
457execute as non-maskable interrupts.
458
459Default Fatal Error Processing
460==============================
461
462Upon detection of a fatal error by either the application or RTEMS during
463initialization the ``rtems_fatal_error_occurred`` directive supplied
464by the Fatal Error Manager is invoked.  The Fatal Error Manager will
465invoke the user-supplied fatal error handlers.  If no user-supplied
466handlers are configured or all of them return without taking action to
467shutdown the processor or reset, a default fatal error handler is invoked.
468
469Most of the action performed as part of processing the fatal error are
470described in detail in the Fatal Error Manager chapter in the User’s
471Guide.  However, the if no user provided extension or BSP specific fatal
472error handler takes action, the final default action is to invoke a
473CPU architecture specific function.  Typically this function disables
474interrupts and halts the processor.
475
476In each of the architecture specific chapters, this describes the precise
477operations of the default CPU specific fatal error handler.
478
479Symmetric Multiprocessing
480=========================
481
482This section contains information about the Symmetric Multiprocessing (SMP)
483status of a particular architecture.
484
485Thread-Local Storage
486====================
487
488In order to support thread-local storage (TLS) the CPU port must implement the
489facilities mandated by the application binary interface (ABI) of the CPU
490architecture.  The CPU port must initialize the TLS area in the``_CPU_Context_Initialize()`` function.  There are support functions available
491via ``#include <rtems/score/tls.h>`` which implement Variants I and II
492according to Ulrich Drepper, *ELF Handling For Thread-Local Storage*.
493
494``_TLS_TCB_at_area_begin_initialize()``
495    Uses Variant I, TLS offsets emitted by linker takes the TCB into account.  For
496    a reference implementation see :file:`cpukit/score/cpu/arm/cpu.c`.
497
498``_TLS_TCB_before_TLS_block_initialize()``
499    Uses Variant I, TLS offsets emitted by linker neglects the TCB.  For a
500    reference implementation see:file:`c/src/lib/libcpu/powerpc/new-exceptions/cpu.c`.
501
502``_TLS_TCB_after_TLS_block_initialize()``
503    Uses Variant II.  For a reference implementation see:file:`cpukit/score/cpu/sparc/cpu.c`.
504
505The board support package (BSP) must provide the following sections and symbols
506in its linker command file:
507.. code:: c
508
509    .tdata : {
510    _TLS_Data_begin = .;
511    \*(.tdata .tdata.* .gnu.linkonce.td.*)
512    _TLS_Data_end = .;
513    }
514    .tbss : {
515    _TLS_BSS_begin = .;
516    \*(.tbss .tbss.* .gnu.linkonce.tb.*) \*(.tcommon)
517    _TLS_BSS_end = .;
518    }
519    _TLS_Data_size = _TLS_Data_end - _TLS_Data_begin;
520    _TLS_Data_begin = _TLS_Data_size != 0 ? _TLS_Data_begin : _TLS_BSS_begin;
521    _TLS_Data_end = _TLS_Data_size != 0 ? _TLS_Data_end : _TLS_BSS_begin;
522    _TLS_BSS_size = _TLS_BSS_end - _TLS_BSS_begin;
523    _TLS_Size = _TLS_BSS_end - _TLS_Data_begin;
524    _TLS_Alignment = MAX (ALIGNOF (.tdata), ALIGNOF (.tbss));
525
526CPU counter
527===========
528
529The CPU support must implement the CPU counter interface.  A CPU counter is
530some free-running counter.  It ticks usually with a frequency close to the CPU
531or system bus clock.  On some architectures the actual implementation is board
532support package dependent.  The CPU counter is used for profiling of low-level
533functions.  It is also used to implement two busy wait functions``rtems_counter_delay_ticks()`` and ``rtems_counter_delay_nanoseconds()``
534which may be used in device drivers.  It may be also used as an entropy source
535for random number generators.
536
537The CPU counter interface uses a CPU port specific unsigned integer type``CPU_Counter_ticks`` to represent CPU counter values.  The CPU port must
538provide the following two functions
539
540- ``_CPU_Counter_read()`` to read the current CPU counter value, and
541
542- ``_CPU_Counter_difference()`` to get the difference between two CPU
543  counter values.
544
545Interrupt Profiling
546===================
547
548The RTEMS profiling needs support by the CPU port for the interrupt entry and
549exit times.  In case profiling is enabled via the RTEMS build configuration
550option ``--enable-profiling`` (in this case the pre-processor symbol``RTEMS_PROFILING`` is defined) the CPU port may provide data for the
551interrupt entry and exit times of the outer-most interrupt.  The CPU port can
552feed interrupt entry and exit times with the``_Profiling_Outer_most_interrupt_entry_and_exit()`` function
553(``#include <rtems/score/profiling.h>``).  For an example please have a look
554at ``cpukit/score/cpu/arm/arm_exc_interrupt.S``.
555
556Board Support Packages
557======================
558
559An RTEMS Board Support Package (BSP) must be designed to support a
560particular processor model and target board combination.
561
562In each of the architecture specific chapters, this section will present
563a discussion of architecture specific BSP issues.   For more information
564on developing a BSP, refer to BSP and Device Driver Development Guide
565and the chapter titled Board Support Packages in the RTEMS
566Applications User’s Guide.
567
568System Reset
569------------
570
571An RTEMS based application is initiated or re-initiated when the processor
572is reset or transfer is passed to it from a boot monitor or ROM monitor.
573
574In each of the architecture specific chapters, this subsection describes
575the actions that the BSP must tak assuming the application gets control
576when the microprocessor is reset.
577
578.. COMMENT: COPYRIGHT (c) 1988-2002.
579
580.. COMMENT: On-Line Applications Research Corporation (OAR).
581
582.. COMMENT: All rights reserved.
583
584ARM Specific Information
585########################
586
587This chapter discusses the`ARM architecture <http://en.wikipedia.org/wiki/ARM_architecture>`_
588dependencies in this port of RTEMS.  The ARMv4T (and compatible), ARMv7-A,
589ARMv7-R and ARMv7-M architecture versions are supported by RTEMS.  Processors
590with a MMU use a static configuration which is set up during system start.  SMP
591is supported.
592
593**Architecture Documents**
594
595For information on the ARM architecture refer to the`ARM Infocenter <http://infocenter.arm.com>`_.
596
597CPU Model Dependent Features
598============================
599
600This section presents the set of features which vary
601across ARM implementations and are of importance to RTEMS.  The set of CPU
602model feature macros are defined in the file:file:`cpukit/score/cpu/arm/rtems/score/arm.h` based upon the particular CPU
603model flags specified on the compilation command line.
604
605CPU Model Name
606--------------
607
608The macro ``CPU_MODEL_NAME`` is a string which designates
609the architectural level of this CPU model.  See in:file:`cpukit/score/cpu/arm/rtems/score/arm.h` for the values.
610
611Count Leading Zeroes Instruction
612--------------------------------
613
614The ARMv5 and later has the count leading zeroes ``clz`` instruction which
615could be used to speed up the find first bit operation.  The use of this
616instruction should significantly speed up the scheduling associated with a
617thread blocking.  This is currently not used.
618
619Floating Point Unit
620-------------------
621
622The following floating point units are supported.
623
624- VFPv3-D32/NEON (for example available on Cortex-A processors)
625
626- VFPv3-D16 (for example available on Cortex-R processors)
627
628- FPv4-SP-D16 (for example available on Cortex-M processors)
629
630Multilibs
631=========
632
633The following multilibs are available:
634
635# ``.``: ARMv4T, ARM instruction set
636
637# ``thumb``: ARMv4T, Thumb-1 instruction set
638
639# ``thumb/armv6-m``: ARMv6M, subset of Thumb-2 instruction set
640
641# ``thumb/armv7-a``: ARMv7-A, Thumb-2 instruction set
642
643# ``thumb/armv7-a/neon/hard``: ARMv7-A, Thumb-2 instruction set with
644  hard-float ABI Neon and VFP-D32 support
645
646# ``thumb/armv7-r``: ARMv7-R, Thumb-2 instruction set
647
648# ``thumb/armv7-r/vfpv3-d16/hard``: ARMv7-R, Thumb-2 instruction set
649  with hard-float ABI VFP-D16 support
650
651# ``thumb/armv7-m``: ARMv7-M, Thumb-2 instruction set with hardware
652  integer division (SDIV/UDIV)
653
654# ``thumb/armv7-m/fpv4-sp-d16``: ARMv7-M, Thumb-2 instruction set with
655  hardware integer division (SDIV/UDIV) and hard-float ABI FPv4-SP support
656
657# ``eb/thumb/armv7-r``: ARMv7-R, Big-endian Thumb-2 instruction set
658
659# ``eb/thumb/armv7-r/vfpv3-d16/hard``: ARMv7-R, Big-endian Thumb-2
660  instruction set with hard-float ABI VFP-D16 support
661
662Multilib 1. and 2. support the standard ARM7TDMI and ARM926EJ-S targets.
663
664Multilib 3. supports the Cortex-M0 and Cortex-M1 cores.
665
666Multilib 8. supports the Cortex-M3 and Cortex-M4 cores, which have a special
667hardware integer division instruction (this is not present in the A and R
668profiles).
669
670Multilib 9. supports the Cortex-M4 cores with a floating point unit.
671
672Multilib 4. and 5. support the Cortex-A processors.
673
674Multilib 6., 7., 10. and 11. support the Cortex-R processors.  Here also
675big-endian variants are available.
676
677Use for example the following GCC options
678.. code:: c
679
680    -mthumb -march=armv7-a -mfpu=neon -mfloat-abi=hard -mtune=cortex-a9
681
682to build an application or BSP for the ARMv7-A architecture and tune the code
683for a Cortex-A9 processor.  It is important to select the options used for the
684multilibs. For example
685.. code:: c
686
687    -mthumb -mcpu=cortex-a9
688
689alone will not select the ARMv7-A multilib.
690
691Calling Conventions
692===================
693
694Please refer to the`Procedure Call Standard for the ARM Architecture <http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042c/IHI0042C_aapcs.pdf>`_.
695
696Memory Model
697============
698
699A flat 32-bit memory model is supported.  The board support package must take
700care about the MMU if necessary.
701
702Interrupt Processing
703====================
704
705The ARMv4T (and compatible) architecture has seven exception types:
706
707- Reset
708
709- Undefined
710
711- Software Interrupt (SWI)
712
713- Prefetch Abort
714
715- Data Abort
716
717- Interrupt (IRQ)
718
719- Fast Interrupt (FIQ)
720
721Of these types only the IRQ has explicit operating system support.  It is
722intentional that the FIQ is not supported by the operating system.  Without
723operating system support for the FIQ it is not necessary to disable them during
724critical sections of the system.
725
726The ARMv7-M architecture has a completely different exception model.  Here
727interrupts are disabled with a write of 0x80 to the ``basepri_max``
728register.  This means that all exceptions and interrupts with a priority value
729of greater than or equal to 0x80 are disabled.  Thus exceptions and interrupts
730with a priority value of less than 0x80 are non-maskable with respect to the
731operating system and therefore must not use operating system services.  Several
732support libraries of chip vendors implicitly shift the priority value somehow
733before the value is written to the NVIC IPR register.  This can easily lead to
734confusion.
735
736Interrupt Levels
737----------------
738
739There are exactly two interrupt levels on ARM with respect to RTEMS.  Level
740zero corresponds to interrupts enabled.  Level one corresponds to interrupts
741disabled.
742
743Interrupt Stack
744---------------
745
746The board support package must initialize the interrupt stack. The memory for
747the stacks is usually reserved in the linker script.
748
749Default Fatal Error Processing
750==============================
751
752The default fatal error handler for this architecture performs the
753following actions:
754
755- disables operating system supported interrupts (IRQ),
756
757- places the error code in ``r0``, and
758
759- executes an infinite loop to simulate a halt processor instruction.
760
761Symmetric Multiprocessing
762=========================
763
764SMP is supported on ARMv7-A.  Available platforms are the Altera Cyclone V and
765the Xilinx Zynq.
766
767Thread-Local Storage
768====================
769
770Thread-local storage is supported.
771
772.. COMMENT: COPYRIGHT (c) 1988-2009.
773
774.. COMMENT: On-Line Applications Research Corporation (OAR).
775
776.. COMMENT: All rights reserved.
777
778Atmel AVR Specific Information
779##############################
780
781This chapter discusses the AVR architecture dependencies in this
782port of RTEMS.
783
784**Architecture Documents**
785
786For information on the AVR architecture, refer to the following
787documents available from Atmel.
788
789TBD
790
791- See other CPUs for documentation reference formatting examples.
792
793CPU Model Dependent Features
794============================
795
796CPUs of the AVR 53X only differ in the peripherals and thus in the
797device drivers. This port does not yet support the 56X dual core variants.
798
799Count Leading Zeroes Instruction
800--------------------------------
801
802The AVR CPU has the XXX instruction which could be used to speed
803up the find first bit operation.  The use of this instruction should
804significantly speed up the scheduling associated with a thread blocking.
805
806Calling Conventions
807===================
808
809Processor Background
810--------------------
811
812The AVR architecture supports a simple call and return mechanism.
813A subroutine is invoked via the call (``call``) instruction.
814This instruction saves the return address in the ``RETS`` register
815and transfers the execution to the given address.
816
817It is the called funcions responsability to use the link instruction
818to reserve space on the stack for the local variables.  Returning from
819a subroutine is done by using the RTS (``RTS``) instruction which
820loads the PC with the adress stored in RETS.
821
822It is is important to note that the ``call`` instruction does not
823automatically save or restore any registers.  It is the responsibility
824of the high-level language compiler to define the register preservation
825and usage convention.
826
827Register Usage
828--------------
829
830A called function may clobber all registers, except RETS, R4-R7, P3-P5,
831FP and SP.  It may also modify the first 12 bytes in the caller’s stack
832frame which is used as an argument area for the first three arguments
833(which are passed in R0...R3 but may be placed on the stack by the
834called function).
835
836Parameter Passing
837-----------------
838
839RTEMS assumes that the AVR GCC calling convention is followed.
840The first three parameters are stored in registers R0, R1, and R2.
841All other parameters are put pushed on the stack.  The result is returned
842through register R0.
843
844Memory Model
845============
846
847The AVR family architecutre support a single unified 4 GB byte
848address space using 32-bit addresses. It maps all resources like internal
849and external memory and IO registers into separate sections of this
850common address space.
851
852The AVR architcture supports some form of memory
853protection via its Memory Management Unit. Since the
854AVR port runs in supervisior mode this memory
855protection mechanisms are not used.
856
857Interrupt Processing
858====================
859
860Discussed in this chapter are the AVR’s interrupt response and
861control mechanisms as they pertain to RTEMS.
862
863Vectoring of an Interrupt Handler
864---------------------------------
865
866TBD
867
868Disabling of Interrupts by RTEMS
869--------------------------------
870
871During interrupt disable critical sections, RTEMS disables interrupts to
872level N (N) before the execution of this section and restores them
873to the previous level upon completion of the section. RTEMS uses the
874instructions CLI and STI to enable and disable Interrupts. Emulation,
875Reset, NMI and Exception Interrupts are never disabled.
876
877Interrupt Stack
878---------------
879
880The AVR Architecture works with two different kind of stacks,
881User and Supervisor Stack. Since RTEMS and its Application run
882in supervisor mode, all interrupts will use the interrupted
883tasks stack for execution.
884
885Default Fatal Error Processing
886==============================
887
888The default fatal error handler for the AVR performs the following
889actions:
890
891- disables processor interrupts,
892
893- places the error code in *r0*, and
894
895- executes an infinite loop (``while(0);`` to
896  simulate a halt processor instruction.
897
898Symmetric Multiprocessing
899=========================
900
901SMP is not supported.
902
903Thread-Local Storage
904====================
905
906Thread-local storage is not supported due to a broken tool chain.
907
908Board Support Packages
909======================
910
911System Reset
912------------
913
914TBD
915
916.. COMMENT: COPYRIGHT (c) 1988-2006.
917
918.. COMMENT: On-Line Applications Research Corporation (OAR).
919
920.. COMMENT: All rights reserved.
921
922Blackfin Specific Information
923#############################
924
925This chapter discusses the Blackfin architecture dependencies in this
926port of RTEMS.
927
928**Architecture Documents**
929
930For information on the Blackfin architecture, refer to the following
931documents available from Analog Devices.
932
933TBD
934
935- *"ADSP-BF533 Blackfin Processor Hardware Reference."*:file:`http://www.analog.com/UploadedFiles/Associated_Docs/892485982bf533_hwr.pdf`
936
937CPU Model Dependent Features
938============================
939
940CPUs of the Blackfin 53X only differ in the peripherals and thus in the
941device drivers. This port does not yet support the 56X dual core variants.
942
943Count Leading Zeroes Instruction
944--------------------------------
945
946The Blackfin CPU has the BITTST instruction which could be used to speed
947up the find first bit operation.  The use of this instruction should
948significantly speed up the scheduling associated with a thread blocking.
949
950Calling Conventions
951===================
952
953This section is heavily based on content taken from the Blackfin uCLinux
954documentation wiki which is edited by Analog Devices and Arcturus
955Networks.  :file:`http://docs.blackfin.uclinux.org/`
956
957Processor Background
958--------------------
959
960The Blackfin architecture supports a simple call and return mechanism.
961A subroutine is invoked via the call (``call``) instruction.
962This instruction saves the return address in the ``RETS`` register
963and transfers the execution to the given address.
964
965It is the called funcions responsability to use the link instruction
966to reserve space on the stack for the local variables.  Returning from
967a subroutine is done by using the RTS (``RTS``) instruction which
968loads the PC with the adress stored in RETS.
969
970It is is important to note that the ``call`` instruction does not
971automatically save or restore any registers.  It is the responsibility
972of the high-level language compiler to define the register preservation
973and usage convention.
974
975Register Usage
976--------------
977
978A called function may clobber all registers, except RETS, R4-R7, P3-P5,
979FP and SP.  It may also modify the first 12 bytes in the caller’s stack
980frame which is used as an argument area for the first three arguments
981(which are passed in R0...R3 but may be placed on the stack by the
982called function).
983
984Parameter Passing
985-----------------
986
987RTEMS assumes that the Blackfin GCC calling convention is followed.
988The first three parameters are stored in registers R0, R1, and R2.
989All other parameters are put pushed on the stack.  The result is returned
990through register R0.
991
992Memory Model
993============
994
995The Blackfin family architecutre support a single unified 4 GB byte
996address space using 32-bit addresses. It maps all resources like internal
997and external memory and IO registers into separate sections of this
998common address space.
999
1000The Blackfin architcture supports some form of memory
1001protection via its Memory Management Unit. Since the
1002Blackfin port runs in supervisior mode this memory
1003protection mechanisms are not used.
1004
1005Interrupt Processing
1006====================
1007
1008Discussed in this chapter are the Blackfin’s interrupt response and
1009control mechanisms as they pertain to RTEMS. The Blackfin architecture
1010support 16 kinds of interrupts broken down into Core and general-purpose
1011interrupts.
1012
1013Vectoring of an Interrupt Handler
1014---------------------------------
1015
1016RTEMS maps levels 0 -15 directly to Blackfins event vectors EVT0 -
1017EVT15. Since EVT0 - EVT6 are core events and it is suggested to use
1018EVT15 and EVT15 for Software interrupts, 7 Interrupts (EVT7-EVT13)
1019are left for periferical use.
1020
1021When installing an RTEMS interrupt handler RTEMS installs a generic
1022Interrupt Handler which saves some context and enables nested interrupt
1023servicing and then vectors to the users interrupt handler.
1024
1025Disabling of Interrupts by RTEMS
1026--------------------------------
1027
1028During interrupt disable critical sections, RTEMS disables interrupts to
1029level four (4) before the execution of this section and restores them
1030to the previous level upon completion of the section. RTEMS uses the
1031instructions CLI and STI to enable and disable Interrupts. Emulation,
1032Reset, NMI and Exception Interrupts are never disabled.
1033
1034Interrupt Stack
1035---------------
1036
1037The Blackfin Architecture works with two different kind of stacks,
1038User and Supervisor Stack. Since RTEMS and its Application run
1039in supervisor mode, all interrupts will use the interrupted
1040tasks stack for execution.
1041
1042Default Fatal Error Processing
1043==============================
1044
1045The default fatal error handler for the Blackfin performs the following
1046actions:
1047
1048- disables processor interrupts,
1049
1050- places the error code in *r0*, and
1051
1052- executes an infinite loop (``while(0);`` to
1053  simulate a halt processor instruction.
1054
1055Symmetric Multiprocessing
1056=========================
1057
1058SMP is not supported.
1059
1060Thread-Local Storage
1061====================
1062
1063Thread-local storage is not implemented.
1064
1065Board Support Packages
1066======================
1067
1068System Reset
1069------------
1070
1071TBD
1072
1073.. COMMENT: Copyright (c) 2015 University of York.
1074
1075.. COMMENT: Hesham ALMatary <hmka501@york.ac.uk>
1076
1077Epiphany Specific Information
1078#############################
1079
1080This chapter discusses the`Epiphany Architecture <http://adapteva.com/docs/epiphany_sdk_ref.pdf>`_
1081dependencies in this port of RTEMS. Epiphany is a chip that can come with 16 and
108264 cores, each of which can run RTEMS separately or they can work together to
1083run a SMP RTEMS application.
1084
1085**Architecture Documents**
1086
1087For information on the Epiphany architecture refer to the`Epiphany Architecture Reference <http://adapteva.com/docs/epiphany_arch_ref.pdf>`_.
1088
1089Calling Conventions
1090===================
1091
1092Please refer to the`Epiphany SDK <http://adapteva.com/docs/epiphany_sdk_ref.pdf>`_
1093Appendix A: Application Binary Interface
1094
1095Floating Point Unit
1096-------------------
1097
1098A floating point unit is currently not supported.
1099
1100Memory Model
1101============
1102
1103A flat 32-bit memory model is supported, no caches. Each core has its own 32 KiB
1104strictly ordered local memory along with an access to a shared 32 MiB external
1105DRAM.
1106
1107Interrupt Processing
1108====================
1109
1110Every Epiphany core has 10 exception types:
1111
1112- Reset
1113
1114- Software Exception
1115
1116- Data Page Fault
1117
1118- Timer 0
1119
1120- Timer 1
1121
1122- Message Interrupt
1123
1124- DMA0 Interrupt
1125
1126- DMA1 Interrupt
1127
1128- WANT Interrupt
1129
1130- User Interrupt
1131
1132Interrupt Levels
1133----------------
1134
1135There are only two levels: interrupts enabled and interrupts disabled.
1136
1137Interrupt Stack
1138---------------
1139
1140The Epiphany RTEMS port uses a dedicated software interrupt stack.
1141The stack for interrupts is allocated during interrupt driver initialization.
1142When an  interrupt is entered, the _ISR_Handler routine is responsible for
1143switching from the interrupted task stack to RTEMS software interrupt stack.
1144
1145Default Fatal Error Processing
1146==============================
1147
1148The default fatal error handler for this architecture performs the
1149following actions:
1150
1151- disables operating system supported interrupts (IRQ),
1152
1153- places the error code in ``r0``, and
1154
1155- executes an infinite loop to simulate a halt processor instruction.
1156
1157Symmetric Multiprocessing
1158=========================
1159
1160SMP is not supported.
1161
1162.. COMMENT: COPYRIGHT (c) 1988-2002.
1163
1164.. COMMENT: On-Line Applications Research Corporation (OAR).
1165
1166.. COMMENT: All rights reserved.
1167
1168Intel/AMD x86 Specific Information
1169##################################
1170
1171This chapter discusses the Intel x86 architecture dependencies
1172in this port of RTEMS.  This family has multiple implementations
1173from multiple vendors and suffers more from having evolved rather
1174than being designed for growth.
1175
1176For information on the i386 processor, refer to the
1177following documents:
1178
1179- *386 Programmer’s Reference Manual, Intel, Order No.  230985-002*.
1180
1181- *386 Microprocessor Hardware Reference Manual, Intel,
1182  Order No. 231732-003*.
1183
1184- *80386 System Software Writer’s Guide, Intel, Order No.  231499-001*.
1185
1186- *80387 Programmer’s Reference Manual, Intel, Order No.  231917-001*.
1187
1188CPU Model Dependent Features
1189============================
1190
1191This section presents the set of features which vary
1192across i386 implementations and are of importance to RTEMS.
1193The set of CPU model feature macros are defined in the file``cpukit/score/cpu/i386/i386.h`` based upon the particular CPU
1194model specified on the compilation command line.
1195
1196bswap Instruction
1197-----------------
1198
1199The macro ``I386_HAS_BSWAP`` is set to 1 to indicate that
1200this CPU model has the ``bswap`` instruction which
1201endian swaps a thirty-two bit quantity.  This instruction
1202appears to be present in all CPU models
1203i486’s and above.
1204
1205Calling Conventions
1206===================
1207
1208Processor Background
1209--------------------
1210
1211The i386 architecture supports a simple yet effective
1212call and return mechanism.  A subroutine is invoked via the call
1213(``call``) instruction.  This instruction pushes the return address
1214on the stack.  The return from subroutine (``ret``) instruction pops
1215the return address off the current stack and transfers control
1216to that instruction.  It is is important to note that the i386
1217call and return mechanism does not automatically save or restore
1218any registers.  It is the responsibility of the high-level
1219language compiler to define the register preservation and usage
1220convention.
1221
1222Calling Mechanism
1223-----------------
1224
1225All RTEMS directives are invoked using a call instruction and return to
1226the user application via the ret instruction.
1227
1228Register Usage
1229--------------
1230
1231As discussed above, the call instruction does not automatically save
1232any registers.  RTEMS uses the registers EAX, ECX, and EDX as scratch
1233registers.  These registers are not preserved by RTEMS directives
1234therefore, the contents of these registers should not be assumed upon
1235return from any RTEMS directive.
1236
1237Parameter Passing
1238-----------------
1239
1240RTEMS assumes that arguments are placed on the
1241current stack before the directive is invoked via the call
1242instruction.  The first argument is assumed to be closest to the
1243return address on the stack.  This means that the first argument
1244of the C calling sequence is pushed last.  The following
1245pseudo-code illustrates the typical sequence used to call a
1246RTEMS directive with three (3) arguments:
1247.. code:: c
1248
1249    push third argument
1250    push second argument
1251    push first argument
1252    invoke directive
1253    remove arguments from the stack
1254
1255The arguments to RTEMS are typically pushed onto the
1256stack using a push instruction.  These arguments must be removed
1257from the stack after control is returned to the caller.  This
1258removal is typically accomplished by adding the size of the
1259argument list in bytes to the stack pointer.
1260
1261Memory Model
1262============
1263
1264Flat Memory Model
1265-----------------
1266
1267RTEMS supports the i386 protected mode, flat memory
1268model with paging disabled.  In this mode, the i386
1269automatically converts every address from a logical to a
1270physical address each time it is used.  The i386 uses
1271information provided in the segment registers and the Global
1272Descriptor Table to convert these addresses.  RTEMS assumes the
1273existence of the following segments:
1274
1275- a single code segment at protection level (0) which
1276  contains all application and executive code.
1277
1278- a single data segment at protection level zero (0) which
1279  contains all application and executive data.
1280
1281The i386 segment registers and associated selectors
1282must be initialized when the initialize_executive directive is
1283invoked.  RTEMS treats the segment registers as system registers
1284and does not modify or context switch them.
1285
1286This i386 memory model supports a flat 32-bit address
1287space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
1288gigabytes).  Each address is represented by a 32-bit value and
1289is byte addressable.  The address may be used to reference a
1290single byte, half-word (2-bytes), or word (4 bytes).
1291
1292Interrupt Processing
1293====================
1294
1295Although RTEMS hides many of the processor
1296dependent details of interrupt processing, it is important to
1297understand how the RTEMS interrupt manager is mapped onto the
1298processor’s unique architecture. Discussed in this chapter are
1299the the processor’s response and control mechanisms as they
1300pertain to RTEMS.
1301
1302Vectoring of Interrupt Handler
1303------------------------------
1304
1305Although the i386 supports multiple privilege levels,
1306RTEMS and all user software executes at privilege level 0.  This
1307decision was made by the RTEMS designers to enhance
1308compatibility with processors which do not provide sophisticated
1309protection facilities like those of the i386.  This decision
1310greatly simplifies the discussion of i386 processing, as one
1311need only consider interrupts without privilege transitions.
1312
1313Upon receipt of an interrupt  the i386 automatically
1314performs the following actions:
1315
1316- pushes the EFLAGS register
1317
1318- pushes the far address of the interrupted instruction
1319
1320- vectors to the interrupt service routine (ISR).
1321
1322A nested interrupt is processed similarly by the
1323i386.
1324
1325Interrupt Stack Frame
1326---------------------
1327
1328The structure of the Interrupt Stack Frame for the
1329i386 which is placed on the interrupt stack by the processor in
1330response to an interrupt is as follows:
1331
1332+----------------------+-------+
1333| Old EFLAGS Register  | ESP+8 |
1334+----------+-----------+-------+
1335|   UNUSED |  Old CS   | ESP+4 |
1336+----------+-----------+-------+
1337|       Old EIP        | ESP   |
1338+----------------------+-------+
1339
1340
1341Interrupt Levels
1342----------------
1343
1344Although RTEMS supports 256 interrupt levels, the
1345i386 only supports two – enabled and disabled.  Interrupts are
1346enabled when the interrupt-enable flag (IF) in the extended
1347flags (EFLAGS) is set.  Conversely, interrupt processing is
1348inhibited when the IF is cleared.  During a non-maskable
1349interrupt, all other interrupts, including other non-maskable
1350ones, are inhibited.
1351
1352RTEMS interrupt levels 0 and 1 such that level zero
1353(0) indicates that interrupts are fully enabled and level one
1354that interrupts are disabled.  All other RTEMS interrupt levels
1355are undefined and their behavior is unpredictable.
1356
1357Interrupt Stack
1358---------------
1359
1360The i386 family does not support a dedicated hardware
1361interrupt stack.  On this processor, RTEMS allocates and manages
1362a dedicated interrupt stack.  As part of vectoring a non-nested
1363interrupt service routine, RTEMS switches from the stack of the
1364interrupted task to a dedicated interrupt stack.  When a
1365non-nested interrupt returns, RTEMS switches back to the stack
1366of the interrupted stack.  The current stack pointer is not
1367altered by RTEMS on nested interrupt.
1368
1369Default Fatal Error Processing
1370==============================
1371
1372The default fatal error handler for this architecture disables processor
1373interrupts, places the error code in EAX, and executes a HLT instruction
1374to halt the processor.
1375
1376Symmetric Multiprocessing
1377=========================
1378
1379SMP is not supported.
1380
1381Thread-Local Storage
1382====================
1383
1384Thread-local storage is not implemented.
1385
1386Board Support Packages
1387======================
1388
1389System Reset
1390------------
1391
1392An RTEMS based application is initiated when the i386 processor is reset.
1393When the i386 is reset,
1394
1395- The EAX register is set to indicate the results of the processor’s
1396  power-up self test.  If the self-test was not executed, the contents of
1397  this register are undefined.  Otherwise, a non-zero value indicates the
1398  processor is faulty and a zero value indicates a successful self-test.
1399
1400- The DX register holds a component identifier and revision level.  DH
1401  contains 3 to indicate an i386 component and DL contains a unique revision
1402  level indicator.
1403
1404- Control register zero (CR0) is set such that the processor is in real
1405  mode with paging disabled.  Other portions of CR0 are used to indicate the
1406  presence of a numeric coprocessor.
1407
1408- All bits in the extended flags register (EFLAG) which are not
1409  permanently set are cleared.  This inhibits all maskable interrupts.
1410
1411- The Interrupt Descriptor Register (IDTR) is set to point at address
1412  zero.
1413
1414- All segment registers are set to zero.
1415
1416- The instruction pointer is set to 0x0000FFF0.  The first instruction
1417  executed after a reset is actually at 0xFFFFFFF0 because the i386 asserts
1418  the upper twelve address until the first intersegment (FAR) JMP or CALL
1419  instruction.  When a JMP or CALL is executed, the upper twelve address
1420  lines are lowered and the processor begins executing in the first megabyte
1421  of memory.
1422
1423Typically, an intersegment JMP to the application’s initialization code is
1424placed at address 0xFFFFFFF0.
1425
1426Processor Initialization
1427------------------------
1428
1429This initialization code is responsible for initializing all data
1430structures required by the i386 in protected mode and for actually entering
1431protected mode.  The i386 must be placed in protected mode and the segment
1432registers and associated selectors must be initialized before the
1433initialize_executive directive is invoked.
1434
1435The initialization code is responsible for initializing the Global
1436Descriptor Table such that the i386 is in the thirty-two bit flat memory
1437model with paging disabled.  In this mode, the i386 automatically converts
1438every address from a logical to a physical address each time it is used.
1439For more information on the memory model used by RTEMS, please refer to the
1440Memory Model chapter in this document.
1441
1442Since the processor is in real mode upon reset, the processor must be
1443switched to protected mode before RTEMS can execute.  Before switching to
1444protected mode, at least one descriptor table and two descriptors must be
1445created.  Descriptors are needed for a code segment and a data segment. (
1446This will give you the flat memory model.)  The stack can be placed in a
1447normal read/write data segment, so no descriptor for the stack is needed.
1448Before the GDT can be used, the base address and limit must be loaded into
1449the GDTR register using an LGDT instruction.
1450
1451If the hardware allows an NMI to be generated, you need to create the IDT
1452and a gate for the NMI interrupt handler.  Before the IDT can be used, the
1453base address and limit for the idt must be loaded into the IDTR register
1454using an LIDT instruction.
1455
1456Protected mode is entered by setting thye PE bit in the CR0 register.
1457Either a LMSW or MOV CR0 instruction may be used to set this bit. Because
1458the processor overlaps the interpretation of several instructions, it is
1459necessary to discard the instructions from the read-ahead cache. A JMP
1460instruction immediately after the LMSW changes the flow and empties the
1461processor if intructions which have been pre-fetched and/or decoded.  At
1462this point, the processor is in protected mode and begins to perform
1463protected mode application initialization.
1464
1465If the application requires that the IDTR be some value besides zero, then
1466it should set it to the required value at this point.  All tasks share the
1467same i386 IDTR value.  Because interrupts are enabled automatically by
1468RTEMS as part of the initialize_executive directive, the IDTR MUST be set
1469properly before this directive is invoked to insure correct interrupt
1470vectoring.  If processor caching is to be utilized, then it should be
1471enabled during the reset application initialization code.  The reset code
1472which is executed before the call to initialize_executive has the following
1473requirements:
1474
1475For more information regarding the i386 data structures and their
1476contents, refer to Intel’s 386 Programmer’s Reference Manual.
1477
1478.. COMMENT: COPYRIGHT (c) 1988-2002.
1479
1480.. COMMENT: On-Line Applications Research Corporation (OAR).
1481
1482.. COMMENT: All rights reserved.
1483
1484.. COMMENT: Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
1485
1486.. COMMENT: Micro-Research Finland Oy
1487
1488Lattice Mico32 Specific Information
1489###################################
1490
1491This chaper discusses the Lattice Mico32 architecture dependencies in
1492this port of RTEMS. The Lattice Mico32 is a 32-bit Harvard, RISC
1493architecture "soft" microprocessor, available for free with an open IP
1494core licensing agreement. Although mainly targeted for Lattice FPGA
1495devices the microprocessor can be implemented on other vendors’ FPGAs,
1496too.
1497
1498**Architecture Documents**
1499
1500For information on the Lattice Mico32 architecture, refer to the
1501following documents available from Lattice Semiconductor:file:`http://www.latticesemi.com/`.
1502
1503- *"LatticeMico32 Processor Reference Manual"*:file:`http://www.latticesemi.com/dynamic/view_document.cfm?document_id=20890`
1504
1505CPU Model Dependent Features
1506============================
1507
1508The Lattice Mico32 architecture allows for different configurations of
1509the processor. This port is based on the assumption that the following options are implemented:
1510
1511- hardware multiplier
1512
1513- hardware divider
1514
1515- hardware barrel shifter
1516
1517- sign extension instructions
1518
1519- instruction cache
1520
1521- data cache
1522
1523- debug
1524
1525Register Architecture
1526=====================
1527
1528This section gives a brief introduction to the register architecture
1529of the Lattice Mico32 processor.
1530
1531The Lattice Mico32 is a RISC archictecture processor with a
153232-register file of 32-bit registers.
1533
1534Register Name
1535
1536Function
1537
1538r0
1539
1540holds value zero
1541
1542r1-r25
1543
1544general purpose
1545
1546r26/gp
1547
1548general pupose / global pointer
1549
1550r27/fp
1551
1552general pupose / frame pointer
1553
1554r28/sp
1555
1556stack pointer
1557
1558r29/ra
1559
1560return address
1561
1562r30/ea
1563
1564exception address
1565
1566r31/ba
1567
1568breakpoint address
1569
1570Note that on processor startup all register values are undefined
1571including r0, thus r0 has to be initialized to zero.
1572
1573Calling Conventions
1574===================
1575
1576Calling Mechanism
1577-----------------
1578
1579A call instruction places the return address to register r29 and a
1580return from subroutine (ret) is actually a branch to r29/ra.
1581
1582Register Usage
1583--------------
1584
1585A subroutine may freely use registers r1 to r10 which are *not*
1586preserved across subroutine invocations.
1587
1588Parameter Passing
1589-----------------
1590
1591When calling a C function the first eight arguments are stored in
1592registers r1 to r8. Registers r1 and r2 hold the return value.
1593
1594Memory Model
1595============
1596
1597The Lattice Mico32 processor supports a flat memory model with a 4
1598Gbyte address space with 32-bit addresses.
1599
1600The following data types are supported:
1601
1602Type
1603
1604Bits
1605
1606C Compiler Type
1607
1608unsigned byte
1609
16108
1611
1612unsigned char
1613
1614signed byte
1615
16168
1617
1618char
1619
1620unsigned half-word
1621
162216
1623
1624unsigned short
1625
1626signed half-word
1627
162816
1629
1630short
1631
1632unsigned word
1633
163432
1635
1636unsigned int / unsigned long
1637
1638signed word
1639
164032
1641
1642int / long
1643
1644Data accesses need to be aligned, with unaligned accesses result are
1645undefined.
1646
1647Interrupt Processing
1648====================
1649
1650The Lattice Mico32 has 32 interrupt lines which are however served by
1651only one exception vector. When an interrupt occurs following happens:
1652
1653- address of next instruction placed in r30/ea
1654
1655- IE field of IE CSR saved to EIE field and IE field cleared preventing further exceptions from occuring.
1656
1657- branch to interrupt exception address EBA CSR + 0xC0
1658
1659The interrupt exception handler determines from the state of the
1660interrupt pending registers (IP CSR) and interrupt enable register (IE
1661CSR) which interrupt to serve and jumps to the interrupt routine
1662pointed to by the corresponding interrupt vector.
1663
1664For now there is no dedicated interrupt stack so every task in
1665the system MUST have enough stack space to accommodate the worst
1666case stack usage of that particular task and the interrupt
1667service routines COMBINED.
1668
1669Nested interrupts are not supported.
1670
1671Default Fatal Error Processing
1672==============================
1673
1674Upon detection of a fatal error by either the application or RTEMS during
1675initialization the ``rtems_fatal_error_occurred`` directive supplied
1676by the Fatal Error Manager is invoked.  The Fatal Error Manager will
1677invoke the user-supplied fatal error handlers.  If no user-supplied
1678handlers are configured or all of them return without taking action to
1679shutdown the processor or reset, a default fatal error handler is invoked.
1680
1681Most of the action performed as part of processing the fatal error are
1682described in detail in the Fatal Error Manager chapter in the User’s
1683Guide.  However, the if no user provided extension or BSP specific fatal
1684error handler takes action, the final default action is to invoke a
1685CPU architecture specific function.  Typically this function disables
1686interrupts and halts the processor.
1687
1688In each of the architecture specific chapters, this describes the precise
1689operations of the default CPU specific fatal error handler.
1690
1691Symmetric Multiprocessing
1692=========================
1693
1694SMP is not supported.
1695
1696Thread-Local Storage
1697====================
1698
1699Thread-local storage is not implemented.
1700
1701Board Support Packages
1702======================
1703
1704An RTEMS Board Support Package (BSP) must be designed to support a
1705particular processor model and target board combination.
1706
1707In each of the architecture specific chapters, this section will present
1708a discussion of architecture specific BSP issues.   For more information
1709on developing a BSP, refer to BSP and Device Driver Development Guide
1710and the chapter titled Board Support Packages in the RTEMS
1711Applications User’s Guide.
1712
1713System Reset
1714------------
1715
1716An RTEMS based application is initiated or re-initiated when the processor
1717is reset.
1718
1719.. COMMENT: Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
1720
1721Renesas M32C Specific Information
1722#################################
1723
1724Symmetric Multiprocessing
1725=========================
1726
1727SMP is not supported.
1728
1729Thread-Local Storage
1730====================
1731
1732Thread-local storage is not implemented.
1733
1734.. COMMENT: COPYRIGHT (c) 1988-2002.
1735
1736.. COMMENT: On-Line Applications Research Corporation (OAR).
1737
1738.. COMMENT: All rights reserved.
1739
1740M68xxx and Coldfire Specific Information
1741########################################
1742
1743This chapter discusses the Freescale (formerly Motorola) MC68xxx
1744and Coldfire architectural dependencies.  The MC68xxx family has a
1745wide variety of CPU models within it based upon different CPU core
1746implementations.  Ignoring the Coldfire parts, the part numbers for
1747these models are generally divided into MC680xx and MC683xx.  The MC680xx
1748models are more general purpose processors with no integrated peripherals.
1749The MC683xx models, on the other hand, are more specialized and have a
1750variety of peripherals on chip including sophisticated timers and serial
1751communications controllers.
1752
1753**Architecture Documents**
1754
1755For information on the MC68xxx and Coldfire architecture, refer to the following documents available from Freescale website (:file:`http//www.freescale.com/`):
1756
1757- *M68000 Family Reference, Motorola, FR68K/D*.
1758
1759- *MC68020 User’s Manual, Motorola, MC68020UM/AD*.
1760
1761- *MC68881/MC68882 Floating-Point Coprocessor User’s Manual,
1762  Motorola, MC68881UM/AD*.
1763
1764CPU Model Dependent Features
1765============================
1766
1767This section presents the set of features which vary
1768across m68k/Coldfire implementations that are of importance to RTEMS.
1769The set of CPU model feature macros are defined in the file``cpukit/score/cpu/m68k/m68k.h`` based upon the particular CPU
1770model selected on the compilation command line.
1771
1772BFFFO Instruction
1773-----------------
1774
1775The macro ``M68K_HAS_BFFFO`` is set to 1 to indicate that
1776this CPU model has the bfffo instruction.
1777
1778Vector Base Register
1779--------------------
1780
1781The macro ``M68K_HAS_VBR`` is set to 1 to indicate that
1782this CPU model has a vector base register (vbr).
1783
1784Separate Stacks
1785---------------
1786
1787The macro ``M68K_HAS_SEPARATE_STACKS`` is set to 1 to
1788indicate that this CPU model has separate interrupt, user, and
1789supervisor mode stacks.
1790
1791Pre-Indexing Address Mode
1792-------------------------
1793
1794The macro ``M68K_HAS_PREINDEXING`` is set to 1 to indicate that
1795this CPU model has the pre-indexing address mode.
1796
1797Extend Byte to Long Instruction
1798-------------------------------
1799
1800The macro ``M68K_HAS_EXTB_L`` is set to 1 to indicate that this CPU model
1801has the extb.l instruction.  This instruction is supposed to be available
1802in all models based on the cpu32 core as well as mc68020 and up models.
1803
1804Calling Conventions
1805===================
1806
1807The MC68xxx architecture supports a simple yet effective call and
1808return mechanism.  A subroutine is invoked via the branch to subroutine
1809(``bsr``) or the jump to subroutine (``jsr``) instructions.
1810These instructions push the return address on the current stack.
1811The return from subroutine (``rts``) instruction pops the return
1812address off the current stack and transfers control to that instruction.
1813It is is important to note that the MC68xxx call and return mechanism does
1814not automatically save or restore any registers.  It is the responsibility
1815of the high-level language compiler to define the register preservation
1816and usage convention.
1817
1818Calling Mechanism
1819-----------------
1820
1821All RTEMS directives are invoked using either a ``bsr`` or ``jsr``
1822instruction and return to the user application via the rts instruction.
1823
1824Register Usage
1825--------------
1826
1827As discussed above, the ``bsr`` and ``jsr`` instructions do not
1828automatically save any registers.  RTEMS uses the registers D0, D1,
1829A0, and A1 as scratch registers.  These registers are not preserved by
1830RTEMS directives therefore, the contents of these registers should not
1831be assumed upon return from any RTEMS directive.
1832
1833Parameter Passing
1834-----------------
1835
1836RTEMS assumes that arguments are placed on the current stack before
1837the directive is invoked via the bsr or jsr instruction.  The first
1838argument is assumed to be closest to the return address on the stack.
1839This means that the first argument of the C calling sequence is pushed
1840last.  The following pseudo-code illustrates the typical sequence used
1841to call a RTEMS directive with three (3) arguments:
1842.. code:: c
1843
1844    push third argument
1845    push second argument
1846    push first argument
1847    invoke directive
1848    remove arguments from the stack
1849
1850The arguments to RTEMS are typically pushed onto the stack using a move
1851instruction with a pre-decremented stack pointer as the destination.
1852These arguments must be removed from the stack after control is returned
1853to the caller.  This removal is typically accomplished by adding the
1854size of the argument list in bytes to the current stack pointer.
1855
1856Memory Model
1857============
1858
1859The MC68xxx family supports a flat 32-bit address
1860space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
1861gigabytes).  Each address is represented by a 32-bit value and
1862is byte addressable.  The address may be used to reference a
1863single byte, word (2-bytes), or long word (4 bytes).  Memory
1864accesses within this address space are performed in big endian
1865fashion by the processors in this family.
1866
1867Some of the MC68xxx family members such as the
1868MC68020, MC68030, and MC68040 support virtual memory and
1869segmentation.  The MC68020 requires external hardware support
1870such as the MC68851 Paged Memory Management Unit coprocessor
1871which is typically used to perform address translations for
1872these systems.  RTEMS does not support virtual memory or
1873segmentation on any of the MC68xxx family members.
1874
1875Interrupt Processing
1876====================
1877
1878Discussed in this section are the MC68xxx’s interrupt response and
1879control mechanisms as they pertain to RTEMS.
1880
1881Vectoring of an Interrupt Handler
1882---------------------------------
1883
1884Depending on whether or not the particular CPU supports a separate
1885interrupt stack, the MC68xxx family has two different interrupt handling
1886models.
1887
1888Models Without Separate Interrupt Stacks
1889~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1890
1891Upon receipt of an interrupt the MC68xxx family members without separate
1892interrupt stacks automatically perform the following actions:
1893
1894- To Be Written
1895
1896Models With Separate Interrupt Stacks
1897~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1898
1899Upon receipt of an interrupt the MC68xxx family members with separate
1900interrupt stacks automatically perform the following actions:
1901
1902- saves the current status register (SR),
1903
1904- clears the master/interrupt (M) bit of the SR to
1905  indicate the switch from master state to interrupt state,
1906
1907- sets the privilege mode to supervisor,
1908
1909- suppresses tracing,
1910
1911- sets the interrupt mask level equal to the level of the
1912  interrupt being serviced,
1913
1914- pushes an interrupt stack frame (ISF), which includes
1915  the program counter (PC), the status register (SR), and the
1916  format/exception vector offset (FVO) word, onto the supervisor
1917  and interrupt stacks,
1918
1919- switches the current stack to the interrupt stack and
1920  vectors to an interrupt service routine (ISR).  If the ISR was
1921  installed with the interrupt_catch directive, then the RTEMS
1922  interrupt handler will begin execution.  The RTEMS interrupt
1923  handler saves all registers which are not preserved according to
1924  the calling conventions and invokes the application’s ISR.
1925
1926A nested interrupt is processed similarly by these
1927CPU models with the exception that only a single ISF is placed
1928on the interrupt stack and the current stack need not be
1929switched.
1930
1931The FVO word in the Interrupt Stack Frame is examined
1932by RTEMS to determine when an outer most interrupt is being
1933exited. Since the FVO is used by RTEMS for this purpose, the
1934user application code MUST NOT modify this field.
1935
1936The following shows the Interrupt Stack Frame for
1937MC68xxx CPU models with separate interrupt stacks:
1938
1939+----------------------+-----+
1940|    Status Register   | 0x0 |
1941+----------------------+-----+
1942| Program Counter High | 0x2 |
1943+----------------------+-----+
1944| Program Counter Low  | 0x4 |
1945+----------------------+-----+
1946| Format/Vector Offset | 0x6 |
1947+----------------------+-----+
1948
1949
1950CPU Models Without VBR and RAM at 0
1951-----------------------------------
1952
1953This is from a post by Zoltan Kocsi <zoltan@bendor.com.au> and is
1954a nice trick in certain situations.  In his words:
1955
1956I think somebody on this list asked about the interupt vector handling
1957w/o VBR and RAM at 0.  The usual trick is to initialise the vector table
1958(except the first 2 two entries, of course) to point to the same location
1959BUT you also add the vector number times 0x1000000 to them. That is,
1960bits 31-24 contain the vector number and 23-0 the address of the common
1961handler.  Since the PC is 32 bit wide but the actual address bus is only
196224, the top byte will be in the PC but will be ignored when jumping onto
1963your routine.
1964
1965Then your common interrupt routine gets this info by loading the PC
1966into some register and based on that info, you can jump to a vector in
1967a vector table pointed by a virtual VBR:
1968.. code:: c
1969
1970    //
1971    //  Real vector table at 0
1972    //
1973    .long   initial_sp
1974    .long   initial_pc
1975    .long   myhandler+0x02000000
1976    .long   myhandler+0x03000000
1977    .long   myhandler+0x04000000
1978    ...
1979    .long   myhandler+0xff000000
1980    //
1981    // This handler will jump to the interrupt routine   of which
1982    // the address is stored at VBR[ vector_no ]
1983    // The registers and stackframe will be intact, the interrupt
1984    // routine will see exactly what it would see if it was called
1985    // directly from the HW vector table at 0.
1986    //
1987    .comm    VBR,4,2        // This defines the 'virtual' VBR
1988    // From C: extern void \*VBR;
1989    myhandler:                  // At entry, PC contains the full vector
1990    move.l  %d0,-(%sp)      // Save d0
1991    move.l  %a0,-(%sp)      // Save a0
1992    lea     0(%pc),%a0      // Get the value of the PC
1993    move.l  %a0,%d0         // Copy it to a data reg, d0 is VV??????
1994    swap    %d0             // Now d0 is ????VV??
1995    and.w   #0xff00,%d0     // Now d0 is ????VV00 (1)
1996    lsr.w   #6,%d0          // Now d0.w contains the VBR table offset
1997    move.l  VBR,%a0         // Get the address from VBR to a0
1998    move.l  (%a0,%d0.w),%a0 // Fetch the vector
1999    move.l  4(%sp),%d0      // Restore d0
2000    move.l  %a0,4(%sp)      // Place target address to the stack
2001    move.l  (%sp)+,%a0      // Restore a0, target address is on TOS
2002    ret                     // This will jump to the handler and
2003    // restore the stack
2004    (1) If 'myhandler' is guaranteed to be in the first 64K, e.g. just
2005    after the vector table then that insn is not needed.
2006
2007There are probably shorter ways to do this, but it I believe is enough
2008to illustrate the trick. Optimisation is left as an exercise to the
2009reader :-)
2010
2011Interrupt Levels
2012----------------
2013
2014Eight levels (0-7) of interrupt priorities are
2015supported by MC68xxx family members with level seven (7) being
2016the highest priority.  Level zero (0) indicates that interrupts
2017are fully enabled.  Interrupt requests for interrupts with
2018priorities less than or equal to the current interrupt mask
2019level are ignored.
2020
2021Although RTEMS supports 256 interrupt levels, the
2022MC68xxx family only supports eight.  RTEMS interrupt levels 0
2023through 7 directly correspond to MC68xxx interrupt levels.  All
2024other RTEMS interrupt levels are undefined and their behavior is
2025unpredictable.
2026
2027Default Fatal Error Processing
2028==============================
2029
2030The default fatal error handler for this architecture disables processor
2031interrupts to level 7, places the error code in D0, and executes a``stop`` instruction to simulate a halt processor instruction.
2032
2033Symmetric Multiprocessing
2034=========================
2035
2036SMP is not supported.
2037
2038Thread-Local Storage
2039====================
2040
2041Thread-local storage is supported.
2042
2043Board Support Packages
2044======================
2045
2046System Reset
2047------------
2048
2049An RTEMS based application is initiated or re-initiated when the MC68020
2050processor is reset.  When the MC68020 is reset, the processor performs
2051the following actions:
2052
2053- The tracing bits of the status register are cleared to
2054  disable tracing.
2055
2056- The supervisor interrupt state is entered by setting the
2057  supervisor (S) bit and clearing the master/interrupt (M) bit of
2058  the status register.
2059
2060- The interrupt mask of the status register is set to
2061  level 7 to effectively disable all maskable interrupts.
2062
2063- The vector base register (VBR) is set to zero.
2064
2065- The cache control register (CACR) is set to zero to
2066  disable and freeze the processor cache.
2067
2068- The interrupt stack pointer (ISP) is set to the value
2069  stored at vector 0 (bytes 0-3) of the exception vector table
2070  (EVT).
2071
2072- The program counter (PC) is set to the value stored at
2073  vector 1 (bytes 4-7) of the EVT.
2074
2075- The processor begins execution at the address stored in
2076  the PC.
2077
2078Processor Initialization
2079------------------------
2080
2081The address of the application’s initialization code should be stored in
2082the first vector of the EVT which will allow the immediate vectoring to
2083the application code.  If the application requires that the VBR be some
2084value besides zero, then it should be set to the required value at this
2085point.  All tasks share the same MC68020’s VBR value.  Because interrupts
2086are enabled automatically by RTEMS as part of the context switch to the
2087first task, the VBR MUST be set by either RTEMS of the BSP before this
2088occurs ensure correct interrupt vectoring.  If processor caching is
2089to be utilized, then it should be enabled during the reset application
2090initialization code.
2091
2092In addition to the requirements described in the
2093Board Support Packages chapter of the Applications User’s
2094Manual for the reset code which is executed before the call to
2095initialize executive, the MC68020 version has the following
2096specific requirements:
2097
2098- Must leave the S bit of the status register set so that
2099  the MC68020 remains in the supervisor state.
2100
2101- Must set the M bit of the status register to remove the
2102  MC68020 from the interrupt state.
2103
2104- Must set the master stack pointer (MSP) such that a
2105  minimum stack size of MINIMUM_STACK_SIZE bytes is provided for
2106  the initialize executive directive.
2107
2108- Must initialize the MC68020’s vector table.
2109
2110.. COMMENT: Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
2111
2112Xilinx MicroBlaze Specific Information
2113######################################
2114
2115Symmetric Multiprocessing
2116=========================
2117
2118SMP is not supported.
2119
2120Thread-Local Storage
2121====================
2122
2123Thread-local storage is not implemented.
2124
2125.. COMMENT: COPYRIGHT (c) 1988-2002.
2126
2127.. COMMENT: On-Line Applications Research Corporation (OAR).
2128
2129.. COMMENT: All rights reserved.
2130
2131MIPS Specific Information
2132#########################
2133
2134This chapter discusses the MIPS architecture dependencies
2135in this port of RTEMS.  The MIPS family has a wide variety
2136of implementations by a wide range of vendors.  Consequently,
2137there are many, many CPU models within it.
2138
2139**Architecture Documents**
2140
2141IDT docs are online at http://www.idt.com/products/risc/Welcome.html
2142
2143For information on the XXX architecture, refer to the following documents
2144available from VENDOR (:file:`http//www.XXX.com/`):
2145
2146- *XXX Family Reference, VENDOR, PART NUMBER*.
2147
2148CPU Model Dependent Features
2149============================
2150
2151This section presents the set of features which vary
2152across MIPS implementations and are of importance to RTEMS.
2153The set of CPU model feature macros are defined in the file``cpukit/score/cpu/mips/mips.h`` based upon the particular CPU
2154model specified on the compilation command line.
2155
2156Another Optional Feature
2157------------------------
2158
2159The macro XXX
2160
2161Calling Conventions
2162===================
2163
2164Processor Background
2165--------------------
2166
2167TBD
2168
2169Calling Mechanism
2170-----------------
2171
2172TBD
2173
2174Register Usage
2175--------------
2176
2177TBD
2178
2179Parameter Passing
2180-----------------
2181
2182TBD
2183
2184Memory Model
2185============
2186
2187Flat Memory Model
2188-----------------
2189
2190The MIPS family supports a flat 32-bit address
2191space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
2192gigabytes).  Each address is represented by a 32-bit value and
2193is byte addressable.  The address may be used to reference a
2194single byte, word (2-bytes), or long word (4 bytes).  Memory
2195accesses within this address space are performed in big endian
2196fashion by the processors in this family.
2197
2198Some of the MIPS family members such as the support virtual memory and
2199segmentation.  RTEMS does not support virtual memory or
2200segmentation on any of these family members.
2201
2202Interrupt Processing
2203====================
2204
2205Although RTEMS hides many of the processor dependent
2206details of interrupt processing, it is important to understand
2207how the RTEMS interrupt manager is mapped onto the processor’s
2208unique architecture. Discussed in this chapter are the MIPS’s
2209interrupt response and control mechanisms as they pertain to
2210RTEMS.
2211
2212Vectoring of an Interrupt Handler
2213---------------------------------
2214
2215Upon receipt of an interrupt the XXX family
2216members with separate interrupt stacks automatically perform the
2217following actions:
2218
2219- TBD
2220
2221A nested interrupt is processed similarly by these
2222CPU models with the exception that only a single ISF is placed
2223on the interrupt stack and the current stack need not be
2224switched.
2225
2226Interrupt Levels
2227----------------
2228
2229TBD
2230
2231Default Fatal Error Processing
2232==============================
2233
2234The default fatal error handler for this target architecture disables
2235processor interrupts, places the error code in *XXX*, and executes a``XXX`` instruction to simulate a halt processor instruction.
2236
2237Symmetric Multiprocessing
2238=========================
2239
2240SMP is not supported.
2241
2242Thread-Local Storage
2243====================
2244
2245Thread-local storage is not implemented.
2246
2247Board Support Packages
2248======================
2249
2250System Reset
2251------------
2252
2253An RTEMS based application is initiated or
2254re-initiated when the processor is reset.  When the
2255processor is reset, it performs the following actions:
2256
2257- TBD
2258
2259Processor Initialization
2260------------------------
2261
2262TBD
2263
2264.. COMMENT: Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
2265
2266Altera Nios II Specific Information
2267###################################
2268
2269Symmetric Multiprocessing
2270=========================
2271
2272SMP is not supported.
2273
2274Thread-Local Storage
2275====================
2276
2277Thread-local storage is not implemented.
2278
2279.. COMMENT: COPYRIGHT (c) 2014 Hesham ALMatary <heshamelmatary@gmail.com>
2280
2281.. COMMENT: All rights reserved.
2282
2283OpenRISC 1000 Specific Information
2284##################################
2285
2286This chapter discusses the`OpenRISC 1000 architecture <http://opencores.org/or1k/Main_Page>`_
2287dependencies in this port of RTEMS. There are many implementations
2288for OpenRISC like or1200 and mor1kx. Currently RTEMS supports basic
2289features that all implementations should have.
2290
2291**Architecture Documents**
2292
2293For information on the OpenRISC 1000 architecture refer to the`OpenRISC 1000 architecture manual <http://openrisc.github.io/or1k.html>`_.
2294
2295Calling Conventions
2296===================
2297
2298Please refer to the`Function Calling Sequence <http://openrisc.github.io/or1k.html#__RefHeading__504887_595890882>`_.
2299
2300Floating Point Unit
2301-------------------
2302
2303A floating point unit is currently not supported.
2304
2305Memory Model
2306============
2307
2308A flat 32-bit memory model is supported.
2309
2310Interrupt Processing
2311====================
2312
2313OpenRISC 1000 architecture has 13 exception types:
2314
2315- Reset
2316
2317- Bus Error
2318
2319- Data Page Fault
2320
2321- Instruction Page Fault
2322
2323- Tick Timer
2324
2325- Alignment
2326
2327- Illegal Instruction
2328
2329- External Interrupt
2330
2331- D-TLB Miss
2332
2333- I-TLB Miss
2334
2335- Range
2336
2337- System Call
2338
2339- Floating Point
2340
2341- Trap
2342
2343Interrupt Levels
2344----------------
2345
2346There are only two levels: interrupts enabled and interrupts disabled.
2347
2348Interrupt Stack
2349---------------
2350
2351The OpenRISC RTEMS port uses a dedicated software interrupt stack.
2352The stack for interrupts is allocated during interrupt driver initialization.
2353When an  interrupt is entered, the _ISR_Handler routine is responsible for
2354switching from the interrupted task stack to RTEMS software interrupt stack.
2355
2356Default Fatal Error Processing
2357==============================
2358
2359The default fatal error handler for this architecture performs the
2360following actions:
2361
2362- disables operating system supported interrupts (IRQ),
2363
2364- places the error code in ``r0``, and
2365
2366- executes an infinite loop to simulate a halt processor instruction.
2367
2368Symmetric Multiprocessing
2369=========================
2370
2371SMP is not supported.
2372
2373.. COMMENT: COPYRIGHT (c) 1989-2007.
2374
2375.. COMMENT: On-Line Applications Research Corporation (OAR).
2376
2377.. COMMENT: All rights reserved.
2378
2379PowerPC Specific Information
2380############################
2381
2382This chapter discusses the PowerPC architecture dependencies
2383in this port of RTEMS.  The PowerPC family has a wide variety
2384of implementations by a range of vendors.  Consequently,
2385there are many, many CPU models within it.
2386
2387It is highly recommended that the PowerPC RTEMS
2388application developer obtain and become familiar with the
2389documentation for the processor being used as well as the
2390specification for the revision of the PowerPC architecture which
2391corresponds to that processor.
2392
2393**PowerPC Architecture Documents**
2394
2395For information on the PowerPC architecture, refer to
2396the following documents available from Motorola and IBM:
2397
2398- *PowerPC Microprocessor Family: The Programming Environment*
2399  (Motorola Document MPRPPCFPE-01).
2400
2401- *IBM PPC403GB Embedded Controller User’s Manual*.
2402
2403- *PoweRisControl MPC500 Family RCPU RISC Central Processing
2404  Unit Reference Manual* (Motorola Document RCPUURM/AD).
2405
2406- *PowerPC 601 RISC Microprocessor User’s Manual*
2407  (Motorola Document MPR601UM/AD).
2408
2409- *PowerPC 603 RISC Microprocessor User’s Manual*
2410  (Motorola Document MPR603UM/AD).
2411
2412- *PowerPC 603e RISC Microprocessor User’s Manual*
2413  (Motorola Document MPR603EUM/AD).
2414
2415- *PowerPC 604 RISC Microprocessor User’s Manual*
2416  (Motorola Document MPR604UM/AD).
2417
2418- *PowerPC MPC821 Portable Systems Microprocessor User’s Manual*
2419  (Motorola Document MPC821UM/AD).
2420
2421- *PowerQUICC MPC860 User’s Manual* (Motorola Document MPC860UM/AD).
2422
2423Motorola maintains an on-line electronic library for the PowerPC
2424at the following URL:
2425
2426-  http://www.mot.com/powerpc/library/library.html
2427
2428This site has a a wealth of information and examples.  Many of the
2429manuals are available from that site in electronic format.
2430
2431**PowerPC Processor Simulator Information**
2432
2433PSIM is a program which emulates the Instruction Set Architecture
2434of the PowerPC microprocessor family.  It is reely available in source
2435code form under the terms of the GNU General Public License (version
24362 or later).  PSIM can be integrated with the GNU Debugger (gdb) to
2437execute and debug PowerPC executables on non-PowerPC hosts.  PSIM
2438supports the addition of user provided device models which can be
2439used to allow one to develop and debug embedded applications using
2440the simulator.
2441
2442The latest version of PSIM is included in GDB and enabled on pre-built
2443binaries provided by the RTEMS Project.
2444
2445CPU Model Dependent Features
2446============================
2447
2448This section presents the set of features which vary
2449across PowerPC implementations and are of importance to RTEMS.
2450The set of CPU model feature macros are defined in the file``cpukit/score/cpu/powerpc/powerpc.h`` based upon the particular CPU
2451model specified on the compilation command line.
2452
2453Alignment
2454---------
2455
2456The macro PPC_ALIGNMENT is set to the PowerPC model’s worst case alignment
2457requirement for data types on a byte boundary.  This value is used
2458to derive the alignment restrictions for memory allocated from
2459regions and partitions.
2460
2461Cache Alignment
2462---------------
2463
2464The macro PPC_CACHE_ALIGNMENT is set to the line size of the cache.  It is
2465used to align the entry point of critical routines so that as much code
2466as possible can be retrieved with the initial read into cache.  This
2467is done for the interrupt handler as well as the context switch routines.
2468
2469In addition, the "shortcut" data structure used by the PowerPC implementation
2470to ease access to data elements frequently accessed by RTEMS routines
2471implemented in assembly language is aligned using this value.
2472
2473Maximum Interrupts
2474------------------
2475
2476The macro PPC_INTERRUPT_MAX is set to the number of exception sources
2477supported by this PowerPC model.
2478
2479Has Double Precision Floating Point
2480-----------------------------------
2481
2482The macro PPC_HAS_DOUBLE is set to 1 to indicate that the PowerPC model
2483has support for double precision floating point numbers.  This is
2484important because the floating point registers need only be four bytes
2485wide (not eight) if double precision is not supported.
2486
2487Critical Interrupts
2488-------------------
2489
2490The macro PPC_HAS_RFCI is set to 1 to indicate that the PowerPC model
2491has the Critical Interrupt capability as defined by the IBM 403 models.
2492
2493Use Multiword Load/Store Instructions
2494-------------------------------------
2495
2496The macro PPC_USE_MULTIPLE is set to 1 to indicate that multiword load and
2497store instructions should be used to perform context switch operations.
2498The relative efficiency of multiword load and store instructions versus
2499an equivalent set of single word load and store instructions varies based
2500upon the PowerPC model.
2501
2502Instruction Cache Size
2503----------------------
2504
2505The macro PPC_I_CACHE is set to the size in bytes of the instruction cache.
2506
2507Data Cache Size
2508---------------
2509
2510The macro PPC_D_CACHE is set to the size in bytes of the data cache.
2511
2512Debug Model
2513-----------
2514
2515The macro PPC_DEBUG_MODEL is set to indicate the debug support features
2516present in this CPU model.  The following debug support feature sets
2517are currently supported:
2518
2519*``PPC_DEBUG_MODEL_STANDARD``*
2520    indicates that the single-step trace enable (SE) and branch trace
2521    enable (BE) bits in the MSR are supported by this CPU model.
2522
2523*``PPC_DEBUG_MODEL_SINGLE_STEP_ONLY``*
2524    indicates that only the single-step trace enable (SE) bit in the MSR
2525    is supported by this CPU model.
2526
2527*``PPC_DEBUG_MODEL_IBM4xx``*
2528    indicates that the debug exception enable (DE) bit in the MSR is supported
2529    by this CPU model.  At this time, this particular debug feature set
2530    has only been seen in the IBM 4xx series.
2531
2532Low Power Model
2533~~~~~~~~~~~~~~~
2534
2535The macro PPC_LOW_POWER_MODE is set to indicate the low power model
2536supported by this CPU model.  The following low power modes are currently
2537supported.
2538
2539*``PPC_LOW_POWER_MODE_NONE``*
2540    indicates that this CPU model has no low power mode support.
2541
2542*``PPC_LOW_POWER_MODE_STANDARD``*
2543    indicates that this CPU model follows the low power model defined for
2544    the PPC603e.
2545
2546Multilibs
2547=========
2548
2549The following multilibs are available:
2550
2551# ``.``: 32-bit PowerPC with FPU
2552
2553# ``nof``: 32-bit PowerPC with software floating point support
2554
2555# ``m403``: Instruction set for PPC403 with FPU
2556
2557# ``m505``: Instruction set for MPC505 with FPU
2558
2559# ``m603e``: Instruction set for MPC603e with FPU
2560
2561# ``m603e/nof``: Instruction set for MPC603e with software floating
2562  point support
2563
2564# ``m604``: Instruction set for MPC604 with FPU
2565
2566# ``m604/nof``: Instruction set for MPC604 with software floating point
2567  support
2568
2569# ``m860``: Instruction set for MPC860 with FPU
2570
2571# ``m7400``: Instruction set for MPC7500 with FPU
2572
2573# ``m7400/nof``: Instruction set for MPC7500 with software floating
2574  point support
2575
2576# ``m8540``: Instruction set for e200, e500 and e500v2 cores with
2577  single-precision FPU and SPE
2578
2579# ``m8540/gprsdouble``: Instruction set for e200, e500 and e500v2 cores
2580  with double-precision FPU and SPE
2581
2582# ``m8540/nof/nospe``: Instruction set for e200, e500 and e500v2 cores
2583  with software floating point support and no SPE
2584
2585# ``me6500/m32``: 32-bit instruction set for e6500 core with FPU and
2586  AltiVec
2587
2588# ``me6500/m32/nof/noaltivec``: 32-bit instruction set for e6500 core
2589  with software floating point support and no AltiVec
2590
2591Calling Conventions
2592===================
2593
2594RTEMS supports the Embedded Application Binary Interface (EABI)
2595calling convention.  Documentation for EABI is available by sending
2596a message with a subject line of "EABI" to eabi@goth.sis.mot.com.
2597
2598Programming Model
2599-----------------
2600
2601This section discusses the programming model for the
2602PowerPC architecture.
2603
2604Non-Floating Point Registers
2605~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2606
2607The PowerPC architecture defines thirty-two non-floating point registers
2608directly visible to the programmer.  In thirty-two bit implementations, each
2609register is thirty-two bits wide.  In sixty-four bit implementations, each
2610register is sixty-four bits wide.
2611
2612These registers are referred to as ``gpr0`` to ``gpr31``.
2613
2614Some of the registers serve defined roles in the EABI programming model.
2615The following table describes the role of each of these registers:
2616.. code:: c
2617
2618    +---------------+----------------+------------------------------+
2619    | Register Name | Alternate Name |         Description          |
2620    +---------------+----------------+------------------------------+
2621    |      r1       |      sp        |         stack pointer        |
2622    +---------------+----------------+------------------------------+
2623    |               |                |  global pointer to the Small |
2624    |      r2       |      na        |     Constant Area (SDA2)     |
2625    +---------------+----------------+------------------------------+
2626    |    r3 - r12   |      na        | parameter and result passing |
2627    +---------------+----------------+------------------------------+
2628    |               |                |  global pointer to the Small |
2629    |      r13      |      na        |         Data Area (SDA)      |
2630    +---------------+----------------+------------------------------+
2631
2632Floating Point Registers
2633~~~~~~~~~~~~~~~~~~~~~~~~
2634
2635The PowerPC architecture includes thirty-two, sixty-four bit
2636floating point registers.  All PowerPC floating point instructions
2637interpret these registers as 32 double precision floating point registers,
2638regardless of whether the processor has 64-bit or 32-bit implementation.
2639
2640The floating point status and control register (fpscr) records exceptions
2641and the type of result generated by floating-point operations.
2642Additionally, it controls the rounding mode of operations and allows the
2643reporting of floating exceptions to be enabled or disabled.
2644
2645Special Registers
2646~~~~~~~~~~~~~~~~~
2647
2648The PowerPC architecture includes a number of special registers
2649which are critical to the programming model:
2650
2651*Machine State Register*
2652    The MSR contains the processor mode, power management mode, endian mode,
2653    exception information, privilege level, floating point available and
2654    floating point excepiton mode, address translation information and
2655    the exception prefix.
2656
2657*Link Register*
2658    The LR contains the return address after a function call.  This register
2659    must be saved before a subsequent subroutine call can be made.  The
2660    use of this register is discussed further in the *Call and Return
2661    Mechanism* section below.
2662
2663*Count Register*
2664    The CTR contains the iteration variable for some loops.  It may also be used
2665    for indirect function calls and jumps.
2666
2667Call and Return Mechanism
2668-------------------------
2669
2670The PowerPC architecture supports a simple yet effective call
2671and return mechanism.  A subroutine is invoked
2672via the "branch and link" (``bl``) and
2673"brank and link absolute" (``bla``)
2674instructions.  This instructions place the return address
2675in the Link Register (LR).  The callee returns to the caller by
2676executing a "branch unconditional to the link register" (``blr``)
2677instruction.  Thus the callee returns to the caller via a jump
2678to the return address which is stored in the LR.
2679
2680The previous contents of the LR are not automatically saved
2681by either the ``bl`` or ``bla``.  It is the responsibility
2682of the callee to save the contents of the LR before invoking
2683another subroutine.  If the callee invokes another subroutine,
2684it must restore the LR before executing the ``blr`` instruction
2685to return to the caller.
2686
2687It is important to note that the PowerPC subroutine
2688call and return mechanism does not automatically save and
2689restore any registers.
2690
2691The LR may be accessed as special purpose register 8 (``SPR8``) using the
2692"move from special register" (``mfspr``) and
2693"move to special register" (``mtspr``) instructions.
2694
2695Calling Mechanism
2696-----------------
2697
2698All RTEMS directives are invoked using the regular
2699PowerPC EABI calling convention via the ``bl`` or``bla`` instructions.
2700
2701Register Usage
2702--------------
2703
2704As discussed above, the call instruction does not
2705automatically save any registers.  It is the responsibility
2706of the callee to save and restore any registers which must be preserved
2707across subroutine calls.  The callee is responsible for saving
2708callee-preserved registers to the program stack and restoring them
2709before returning to the caller.
2710
2711Parameter Passing
2712-----------------
2713
2714RTEMS assumes that arguments are placed in the
2715general purpose registers with the first argument in
2716register 3 (``r3``), the second argument in general purpose
2717register 4 (``r4``), and so forth until the seventh
2718argument is in general purpose register 10 (``r10``).
2719If there are more than seven arguments, then subsequent arguments
2720are placed on the program stack.  The following pseudo-code
2721illustrates the typical sequence used to call a RTEMS directive
2722with three (3) arguments:
2723.. code:: c
2724
2725    load third argument into r5
2726    load second argument into r4
2727    load first argument into r3
2728    invoke directive
2729
2730Memory Model
2731============
2732
2733Flat Memory Model
2734-----------------
2735
2736The PowerPC architecture supports a variety of memory models.
2737RTEMS supports the PowerPC using a flat memory model with
2738paging disabled.  In this mode, the PowerPC automatically
2739converts every address from a logical to a physical address
2740each time it is used.  The PowerPC uses information provided
2741in the Block Address Translation (BAT) to convert these addresses.
2742
2743Implementations of the PowerPC architecture may be thirty-two or sixty-four bit.
2744The PowerPC architecture supports a flat thirty-two or sixty-four bit address
2745space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
2746gigabytes) in thirty-two bit implementations or to 0xFFFFFFFFFFFFFFFF
2747in sixty-four bit implementations.  Each address is represented
2748by either a thirty-two bit or sixty-four bit value and is byte addressable.
2749The address may be used to reference a single byte, half-word
2750(2-bytes), word (4 bytes), or in sixty-four bit implementations a
2751doubleword (8 bytes).  Memory accesses within the address space are
2752performed in big or little endian fashion by the PowerPC based
2753upon the current setting of the Little-endian mode enable bit (LE)
2754in the Machine State Register (MSR).  While the processor is in
2755big endian mode, memory accesses which are not properly aligned
2756generate an "alignment exception" (vector offset 0x00600).  In
2757little endian mode, the PowerPC architecture does not require
2758the processor to generate alignment exceptions.
2759
2760The following table lists the alignment requirements for a variety
2761of data accesses:
2762
2763.. code:: c
2764
2765    +--------------+-----------------------+
2766    |   Data Type  | Alignment Requirement |
2767    +--------------+-----------------------+
2768    |     byte     |          1            |
2769    |   half-word  |          2            |
2770    |     word     |          4            |
2771    |  doubleword  |          8            |
2772    +--------------+-----------------------+
2773
2774Doubleword load and store operations are only available in
2775PowerPC CPU models which are sixty-four bit implementations.
2776
2777RTEMS does not directly support any PowerPC Memory Management
2778Units, therefore, virtual memory or segmentation systems
2779involving the PowerPC  are not supported.
2780
2781.. COMMENT: COPYRIGHT (c) 1989-2007.
2782
2783.. COMMENT: On-Line Applications Research Corporation (OAR).
2784
2785.. COMMENT: All rights reserved.
2786
2787Interrupt Processing
2788====================
2789
2790Although RTEMS hides many of the processor dependent
2791details of interrupt processing, it is important to understand
2792how the RTEMS interrupt manager is mapped onto the processor’s
2793unique architecture. Discussed in this chapter are the PowerPC’s
2794interrupt response and control mechanisms as they pertain to
2795RTEMS.
2796
2797RTEMS and associated documentation uses the terms interrupt and vector.
2798In the PowerPC architecture, these terms correspond to exception and
2799exception handler, respectively.  The terms will be used interchangeably
2800in this manual.
2801
2802Synchronous Versus Asynchronous Exceptions
2803------------------------------------------
2804
2805In the PowerPC architecture exceptions can be either precise or
2806imprecise and either synchronous or asynchronous.  Asynchronous
2807exceptions occur when an external event interrupts the processor.
2808Synchronous exceptions are caused by the actions of an
2809instruction. During an exception SRR0 is used to calculate where
2810instruction processing should resume.  All instructions prior to
2811the resume instruction will have completed execution.  SRR1 is used to
2812store the machine status.
2813
2814There are two asynchronous nonmaskable, highest-priority exceptions
2815system reset and machine check.  There are two asynchrononous maskable
2816low-priority exceptions external interrupt and decrementer.  Nonmaskable
2817execptions are never delayed, therefore if two nonmaskable, asynchronous
2818exceptions occur in immediate succession, the state information saved by
2819the first exception may be overwritten when the subsequent exception occurs.
2820
2821The PowerPC arcitecure defines one imprecise exception, the imprecise
2822floating point enabled exception.  All other synchronous exceptions are
2823precise.  The synchronization occuring during asynchronous precise
2824exceptions conforms to the requirements for context synchronization.
2825
2826Vectoring of Interrupt Handler
2827------------------------------
2828
2829Upon determining that an exception can be taken the PowerPC automatically
2830performs the following actions:
2831
2832- an instruction address is loaded into SRR0
2833
2834- bits 33-36 and 42-47 of SRR1 are loaded with information
2835  specific to the exception.
2836
2837- bits 0-32, 37-41, and 48-63 of SRR1 are loaded with corresponding
2838  bits from the MSR.
2839
2840- the MSR is set based upon the exception type.
2841
2842- instruction fetch and execution resumes, using the new MSR value, at a location specific to the execption type.
2843
2844If the interrupt handler was installed as an RTEMS
2845interrupt handler, then upon receipt of the interrupt, the
2846processor passes control to the RTEMS interrupt handler which
2847performs the following actions:
2848
2849- saves the state of the interrupted task on it’s stack,
2850
2851- saves all registers which are not normally preserved
2852  by the calling sequence so the user’s interrupt service
2853  routine can be written in a high-level language.
2854
2855- if this is the outermost (i.e. non-nested) interrupt,
2856  then the RTEMS interrupt handler switches from the current stack
2857  to the interrupt stack,
2858
2859- enables exceptions,
2860
2861- invokes the vectors to a user interrupt service routine (ISR).
2862
2863Asynchronous interrupts are ignored while exceptions are
2864disabled.  Synchronous interrupts which occur while are
2865disabled result in the CPU being forced into an error mode.
2866
2867A nested interrupt is processed similarly with the
2868exception that the current stack need not be switched to the
2869interrupt stack.
2870
2871Interrupt Levels
2872----------------
2873
2874The PowerPC architecture supports only a single external
2875asynchronous interrupt source.  This interrupt source
2876may be enabled and disabled via the External Interrupt Enable (EE)
2877bit in the Machine State Register (MSR).  Thus only two level (enabled
2878and disabled) of external device interrupt priorities are
2879directly supported by the PowerPC architecture.
2880
2881Some PowerPC implementations include a Critical Interrupt capability
2882which is often used to receive interrupts from high priority external
2883devices.
2884
2885The RTEMS interrupt level mapping scheme for the PowerPC is not
2886a numeric level as on most RTEMS ports.  It is a bit mapping in
2887which the least three significiant bits of the interrupt level
2888are mapped directly to the enabling of specific interrupt
2889sources as follows:
2890
2891*Critical Interrupt*
2892    Setting bit 0 (the least significant bit) of the interrupt level
2893    enables the Critical Interrupt source, if it is available on this
2894    CPU model.
2895
2896*Machine Check*
2897    Setting bit 1 of the interrupt level enables Machine Check execptions.
2898
2899*External Interrupt*
2900    Setting bit 2 of the interrupt level enables External Interrupt execptions.
2901
2902All other bits in the RTEMS task interrupt level are ignored.
2903
2904Default Fatal Error Processing
2905==============================
2906
2907The default fatal error handler for this architecture performs the
2908following actions:
2909
2910- places the error code in r3, and
2911
2912- executes a trap instruction which results in a Program Exception.
2913
2914If the Program Exception returns, then the following actions are performed:
2915
2916- disables all processor exceptions by loading a 0 into the MSR, and
2917
2918- goes into an infinite loop to simulate a halt processor instruction.
2919
2920Symmetric Multiprocessing
2921=========================
2922
2923SMP is supported.  Available platforms are the Freescale QorIQ P series (e.g.
2924P1020) and T series (e.g. T2080, T4240).
2925
2926Thread-Local Storage
2927====================
2928
2929Thread-local storage is supported.
2930
2931Board Support Packages
2932======================
2933
2934System Reset
2935------------
2936
2937An RTEMS based application is initiated or
2938re-initiated when the PowerPC processor is reset.  The PowerPC
2939architecture defines a Reset Exception, but leaves the
2940details of the CPU state as implementation specific.  Please
2941refer to the User’s Manual for the CPU model in question.
2942
2943In general, at power-up the PowerPC begin execution at address
29440xFFF00100 in supervisor mode with all exceptions disabled.  For
2945soft resets, the CPU will vector to either 0xFFF00100 or 0x00000100
2946depending upon the setting of the Exception Prefix bit in the MSR.
2947If during a soft reset, a Machine Check Exception occurs, then the
2948CPU may execute a hard reset.
2949
2950Processor Initialization
2951------------------------
2952
2953If this PowerPC implementation supports on-chip caching
2954and this is to be utilized, then it should be enabled during the
2955reset application initialization code.  On-chip caching has been
2956observed to prevent some emulators from working properly, so it
2957may be necessary to run with caching disabled to use these emulators.
2958
2959In addition to the requirements described in the*Board Support Packages* chapter of the RTEMS C
2960Applications User’s Manual for the reset code
2961which is executed before the call to ``rtems_initialize_executive``,
2962the PowrePC version has the following specific requirements:
2963
2964- Must leave the PR bit of the Machine State Register (MSR) set
2965  to 0 so the PowerPC remains in the supervisor state.
2966
2967- Must set stack pointer (sp or r1) such that a minimum stack
2968  size of MINIMUM_STACK_SIZE bytes is provided for the RTEMS initialization
2969  sequence.
2970
2971- Must disable all external interrupts (i.e. clear the EI (EE)
2972  bit of the machine state register).
2973
2974- Must enable traps so window overflow and underflow
2975  conditions can be properly handled.
2976
2977- Must initialize the PowerPC’s initial Exception Table with default
2978  handlers.
2979
2980.. COMMENT: COPYRIGHT (c) 1988-2002.
2981
2982.. COMMENT: On-Line Applications Research Corporation (OAR).
2983
2984.. COMMENT: All rights reserved.
2985
2986SuperH Specific Information
2987###########################
2988
2989This chapter discusses the SuperH architecture dependencies
2990in this port of RTEMS.  The SuperH family has a wide variety
2991of implementations by a wide range of vendors.  Consequently,
2992there are many, many CPU models within it.
2993
2994**Architecture Documents**
2995
2996For information on the SuperH architecture,
2997refer to the following documents available from VENDOR
2998(:file:`http//www.XXX.com/`):
2999
3000- *SuperH Family Reference, VENDOR, PART NUMBER*.
3001
3002CPU Model Dependent Features
3003============================
3004
3005This chapter presents the set of features which vary
3006across SuperH implementations and are of importance to RTEMS.
3007The set of CPU model feature macros are defined in the file``cpukit/score/cpu/sh/sh.h`` based upon the particular CPU
3008model specified on the compilation command line.
3009
3010Another Optional Feature
3011------------------------
3012
3013The macro XXX
3014
3015Calling Conventions
3016===================
3017
3018Calling Mechanism
3019-----------------
3020
3021All RTEMS directives are invoked using a ``XXX``
3022instruction and return to the user application via the``XXX`` instruction.
3023
3024Register Usage
3025--------------
3026
3027The SH1 has 16 general registers (r0..r15).
3028
3029- r0..r3 used as general volatile registers
3030
3031- r4..r7 used to pass up to 4 arguments to functions, arguments
3032  above 4 are
3033  passed via the stack)
3034
3035- r8..13 caller saved registers (i.e. push them to the stack if you
3036  need them inside of a function)
3037
3038- r14 frame pointer
3039
3040- r15 stack pointer
3041
3042Parameter Passing
3043-----------------
3044
3045XXX
3046
3047Memory Model
3048============
3049
3050Flat Memory Model
3051-----------------
3052
3053The SuperH family supports a flat 32-bit address
3054space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
3055gigabytes).  Each address is represented by a 32-bit value and
3056is byte addressable.  The address may be used to reference a
3057single byte, word (2-bytes), or long word (4 bytes).  Memory
3058accesses within this address space are performed in big endian
3059fashion by the processors in this family.
3060
3061Some of the SuperH family members support virtual memory and
3062segmentation.  RTEMS does not support virtual memory or
3063segmentation on any of the SuperH family members.  It is the
3064responsibility of the BSP to initialize the mapping for
3065a flat memory model.
3066
3067Interrupt Processing
3068====================
3069
3070Although RTEMS hides many of the processor dependent
3071details of interrupt processing, it is important to understand
3072how the RTEMS interrupt manager is mapped onto the processor’s
3073unique architecture. Discussed in this chapter are the MIPS’s
3074interrupt response and control mechanisms as they pertain to
3075RTEMS.
3076
3077Vectoring of an Interrupt Handler
3078---------------------------------
3079
3080Upon receipt of an interrupt the XXX family
3081members with separate interrupt stacks automatically perform the
3082following actions:
3083
3084- TBD
3085
3086A nested interrupt is processed similarly by these
3087CPU models with the exception that only a single ISF is placed
3088on the interrupt stack and the current stack need not be
3089switched.
3090
3091Interrupt Levels
3092----------------
3093
3094TBD
3095
3096Default Fatal Error Processing
3097==============================
3098
3099The default fatal error handler for this architecture disables processor
3100interrupts, places the error code in *XXX*, and executes a ``XXX``
3101instruction to simulate a halt processor instruction.
3102
3103Symmetric Multiprocessing
3104=========================
3105
3106SMP is not supported.
3107
3108Thread-Local Storage
3109====================
3110
3111Thread-local storage is not implemented.
3112
3113Board Support Packages
3114======================
3115
3116System Reset
3117------------
3118
3119An RTEMS based application is initiated or
3120re-initiated when the processor is reset.  When the
3121processor is reset, it performs the following actions:
3122
3123- TBD
3124
3125Processor Initialization
3126------------------------
3127
3128TBD
3129
3130.. COMMENT: COPYRIGHT (c) 1988-2002.
3131
3132.. COMMENT: On-Line Applications Research Corporation (OAR).
3133
3134.. COMMENT: All rights reserved.
3135
3136SPARC Specific Information
3137##########################
3138
3139The Real Time Executive for Multiprocessor Systems
3140(RTEMS) is designed to be portable across multiple processor
3141architectures.  However, the nature of real-time systems makes
3142it essential that the application designer understand certain
3143processor dependent implementation details.  These processor
3144dependencies include calling convention, board support package
3145issues, interrupt processing, exact RTEMS memory requirements,
3146performance data, header files, and the assembly language
3147interface to the executive.
3148
3149This document discusses the SPARC architecture dependencies in this
3150port of RTEMS.  This architectural port is for SPARC Version 7 and
31518. Implementations for SPARC V9 are in the sparc64 target.
3152
3153It is highly recommended that the SPARC RTEMS
3154application developer obtain and become familiar with the
3155documentation for the processor being used as well as the
3156specification for the revision of the SPARC architecture which
3157corresponds to that processor.
3158
3159**SPARC Architecture Documents**
3160
3161For information on the SPARC architecture, refer to
3162the following documents available from SPARC International, Inc.
3163(http://www.sparc.com):
3164
3165- SPARC Standard Version 7.
3166
3167- SPARC Standard Version 8.
3168
3169**ERC32 Specific Information**
3170
3171The European Space Agency’s ERC32 is a three chip
3172computing core implementing a SPARC V7 processor and associated
3173support circuitry for embedded space applications. The integer
3174and floating-point units (90C601E & 90C602E) are based on the
3175Cypress 7C601 and 7C602, with additional error-detection and
3176recovery functions. The memory controller (MEC) implements
3177system support functions such as address decoding, memory
3178interface, DMA interface, UARTs, timers, interrupt control,
3179write-protection, memory reconfiguration and error-detection.
3180The core is designed to work at 25MHz, but using space qualified
3181memories limits the system frequency to around 15 MHz, resulting
3182in a performance of 10 MIPS and 2 MFLOPS.
3183
3184Information on the ERC32 and a number of development
3185support tools, such as the SPARC Instruction Simulator (SIS),
3186are freely available on the Internet.  The following documents
3187and SIS are available via anonymous ftp or pointing your web
3188browser at ftp://ftp.estec.esa.nl/pub/ws/wsd/erc32.
3189
3190- ERC32 System Design Document
3191
3192- MEC Device Specification
3193
3194Additionally, the SPARC RISC User’s Guide from Matra
3195MHS documents the functionality of the integer and floating
3196point units including the instruction set information.  To
3197obtain this document as well as ERC32 components and VHDL models
3198contact:
3199.. code:: c
3200
3201    Matra MHS SA
3202    3 Avenue du Centre, BP 309,
3203    78054 St-Quentin-en-Yvelines,
3204    Cedex, France
3205    VOICE: +31-1-30607087
3206    FAX: +31-1-30640693
3207
3208Amar Guennon (amar.guennon@matramhs.fr) is familiar with the ERC32.
3209
3210.. COMMENT: COPYRIGHT (c) 1988-2002.
3211
3212.. COMMENT: On-Line Applications Research Corporation (OAR).
3213
3214.. COMMENT: All rights reserved.
3215
3216CPU Model Dependent Features
3217============================
3218
3219Microprocessors are generally classified into
3220families with a variety of CPU models or implementations within
3221that family.  Within a processor family, there is a high level
3222of binary compatibility.  This family may be based on either an
3223architectural specification or on maintaining compatibility with
3224a popular processor.  Recent microprocessor families such as the
3225SPARC or PowerPC are based on an architectural specification
3226which is independent or any particular CPU model or
3227implementation.  Older families such as the M68xxx and the iX86
3228evolved as the manufacturer strived to produce higher
3229performance processor models which maintained binary
3230compatibility with older models.
3231
3232RTEMS takes advantage of the similarity of the
3233various models within a CPU family.  Although the models do vary
3234in significant ways, the high level of compatibility makes it
3235possible to share the bulk of the CPU dependent executive code
3236across the entire family.
3237
3238CPU Model Feature Flags
3239-----------------------
3240
3241Each processor family supported by RTEMS has a
3242list of features which vary between CPU models
3243within a family.  For example, the most common model dependent
3244feature regardless of CPU family is the presence or absence of a
3245floating point unit or coprocessor.  When defining the list of
3246features present on a particular CPU model, one simply notes
3247that floating point hardware is or is not present and defines a
3248single constant appropriately.  Conditional compilation is
3249utilized to include the appropriate source code for this CPU
3250model’s feature set.  It is important to note that this means
3251that RTEMS is thus compiled using the appropriate feature set
3252and compilation flags optimal for this CPU model used.  The
3253alternative would be to generate a binary which would execute on
3254all family members using only the features which were always
3255present.
3256
3257This section presents the set of features which vary
3258across SPARC implementations and are of importance to RTEMS.
3259The set of CPU model feature macros are defined in the file
3260cpukit/score/cpu/sparc/sparc.h based upon the particular CPU
3261model defined on the compilation command line.
3262
3263CPU Model Name
3264~~~~~~~~~~~~~~
3265
3266The macro CPU_MODEL_NAME is a string which designates
3267the name of this CPU model.  For example, for the European Space
3268Agency’s ERC32 SPARC model, this macro is set to the string
3269"erc32".
3270
3271Floating Point Unit
3272~~~~~~~~~~~~~~~~~~~
3273
3274The macro SPARC_HAS_FPU is set to 1 to indicate that
3275this CPU model has a hardware floating point unit and 0
3276otherwise.
3277
3278Bitscan Instruction
3279~~~~~~~~~~~~~~~~~~~
3280
3281The macro SPARC_HAS_BITSCAN is set to 1 to indicate
3282that this CPU model has the bitscan instruction.  For example,
3283this instruction is supported by the Fujitsu SPARClite family.
3284
3285Number of Register Windows
3286~~~~~~~~~~~~~~~~~~~~~~~~~~
3287
3288The macro SPARC_NUMBER_OF_REGISTER_WINDOWS is set to
3289indicate the number of register window sets implemented by this
3290CPU model.  The SPARC architecture allows a for a maximum of
3291thirty-two register window sets although most implementations
3292only include eight.
3293
3294Low Power Mode
3295~~~~~~~~~~~~~~
3296
3297The macro SPARC_HAS_LOW_POWER_MODE is set to one to
3298indicate that this CPU model has a low power mode.  If low power
3299is enabled, then there must be CPU model specific implementation
3300of the IDLE task in cpukit/score/cpu/sparc/cpu.c.  The low
3301power mode IDLE task should be of the form:
3302.. code:: c
3303
3304    while ( TRUE ) {
3305    enter low power mode
3306    }
3307
3308The code required to enter low power mode is CPU model specific.
3309
3310CPU Model Implementation Notes
3311------------------------------
3312
3313The ERC32 is a custom SPARC V7 implementation based on the Cypress 601/602
3314chipset.  This CPU has a number of on-board peripherals and was developed by
3315the European Space Agency to target space applications.  RTEMS currently
3316provides support for the following peripherals:
3317
3318- UART Channels A and B
3319
3320- General Purpose Timer
3321
3322- Real Time Clock
3323
3324- Watchdog Timer (so it can be disabled)
3325
3326- Control Register (so powerdown mode can be enabled)
3327
3328- Memory Control Register
3329
3330- Interrupt Control
3331
3332The General Purpose Timer and Real Time Clock Timer provided with the ERC32
3333share the Timer Control Register.  Because the Timer Control Register is write
3334only, we must mirror it in software and insure that writes to one timer do not
3335alter the current settings and status of the other timer.  Routines are
3336provided in erc32.h which promote the view that the two timers are completely
3337independent.  By exclusively using these routines to access the Timer Control
3338Register, the application can view the system as having a General Purpose
3339Timer Control Register and a Real Time Clock Timer Control Register
3340rather than the single shared value.
3341
3342The RTEMS Idle thread take advantage of the low power mode provided by the
3343ERC32.  Low power mode is entered during idle loops and is enabled at
3344initialization time.
3345
3346.. COMMENT: COPYRIGHT (c) 1988-2002.
3347
3348.. COMMENT: On-Line Applications Research Corporation (OAR).
3349
3350.. COMMENT: All rights reserved.
3351
3352Calling Conventions
3353===================
3354
3355Each high-level language compiler generates subroutine entry and exit code
3356based upon a set of rules known as the application binary interface (ABI)
3357calling convention.   These rules address the following issues:
3358
3359- register preservation and usage
3360
3361- parameter passing
3362
3363- call and return mechanism
3364
3365An ABI calling convention is of importance when interfacing to subroutines
3366written in another language either assembly or high-level.  It determines also
3367the set of registers to be saved or restored during a context switch and
3368interrupt processing.
3369
3370The ABI relevant for RTEMS on SPARC is defined by SYSTEM V APPLICATION BINARY
3371INTERFACE, SPARC Processor Supplement, Third Edition.
3372
3373Programming Model
3374-----------------
3375
3376This section discusses the programming model for the
3377SPARC architecture.
3378
3379Non-Floating Point Registers
3380~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3381
3382The SPARC architecture defines thirty-two
3383non-floating point registers directly visible to the programmer.
3384These are divided into four sets:
3385
3386- input registers
3387
3388- local registers
3389
3390- output registers
3391
3392- global registers
3393
3394Each register is referred to by either two or three
3395names in the SPARC reference manuals.  First, the registers are
3396referred to as r0 through r31 or with the alternate notation
3397r[0] through r[31].  Second, each register is a member of one of
3398the four sets listed above.  Finally, some registers have an
3399architecturally defined role in the programming model which
3400provides an alternate name.  The following table describes the
3401mapping between the 32 registers and the register sets:
3402
3403.. code:: c
3404
3405    +-----------------+----------------+------------------+
3406    | Register Number | Register Names |   Description    |
3407    +-----------------+----------------+------------------+
3408    |     0 - 7       |    g0 - g7     | Global Registers |
3409    +-----------------+----------------+------------------+
3410    |     8 - 15      |    o0 - o7     | Output Registers |
3411    +-----------------+----------------+------------------+
3412    |    16 - 23      |    l0 - l7     | Local Registers  |
3413    +-----------------+----------------+------------------+
3414    |    24 - 31      |    i0 - i7     | Input Registers  |
3415    +-----------------+----------------+------------------+
3416
3417As mentioned above, some of the registers serve
3418defined roles in the programming model.  The following table
3419describes the role of each of these registers:
3420
3421.. code:: c
3422
3423    +---------------+----------------+----------------------+
3424    | Register Name | Alternate Name |      Description     |
3425    +---------------+----------------+----------------------+
3426    |     g0        |      na        |    reads return 0    |
3427    |               |                |  writes are ignored  |
3428    +---------------+----------------+----------------------+
3429    |     o6        |      sp        |     stack pointer    |
3430    +---------------+----------------+----------------------+
3431    |     i6        |      fp        |     frame pointer    |
3432    +---------------+----------------+----------------------+
3433    |     i7        |      na        |    return address    |
3434    +---------------+----------------+----------------------+
3435
3436The registers g2 through g4 are reserved for applications.  GCC uses them as
3437volatile registers by default.  So they are treated like volatile registers in
3438RTEMS as well.
3439
3440The register g6 is reserved for the operating system and contains the address
3441of the per-CPU control block of the current processor.  This register is
3442initialized during system start and then remains unchanged.  It is not
3443saved/restored by the context switch or interrupt processing code.
3444
3445The register g7 is reserved for the operating system and contains the thread
3446pointer used for thread-local storage (TLS) as mandated by the SPARC ABI.
3447
3448Floating Point Registers
3449~~~~~~~~~~~~~~~~~~~~~~~~
3450
3451The SPARC V7 architecture includes thirty-two,
3452thirty-two bit registers.  These registers may be viewed as
3453follows:
3454
3455- 32 single precision floating point or integer registers
3456  (f0, f1,  ... f31)
3457
3458- 16 double precision floating point registers (f0, f2,
3459  f4, ... f30)
3460
3461- 8 extended precision floating point registers (f0, f4,
3462  f8, ... f28)
3463
3464The floating point status register (FSR) specifies
3465the behavior of the floating point unit for rounding, contains
3466its condition codes, version specification, and trap information.
3467
3468According to the ABI all floating point registers and the floating point status
3469register (FSR) are volatile.  Thus the floating point context of a thread is the
3470empty set.  The rounding direction is a system global state and must not be
3471modified by threads.
3472
3473A queue of the floating point instructions which have
3474started execution but not yet completed is maintained.  This
3475queue is needed to support the multiple cycle nature of floating
3476point operations and to aid floating point exception trap
3477handlers.  Once a floating point exception has been encountered,
3478the queue is frozen until it is emptied by the trap handler.
3479The floating point queue is loaded by launching instructions.
3480It is emptied normally when the floating point completes all
3481outstanding instructions and by floating point exception
3482handlers with the store double floating point queue (stdfq)
3483instruction.
3484
3485Special Registers
3486~~~~~~~~~~~~~~~~~
3487
3488The SPARC architecture includes two special registers
3489which are critical to the programming model: the Processor State
3490Register (psr) and the Window Invalid Mask (wim).  The psr
3491contains the condition codes, processor interrupt level, trap
3492enable bit, supervisor mode and previous supervisor mode bits,
3493version information, floating point unit and coprocessor enable
3494bits, and the current window pointer (cwp).  The cwp field of
3495the psr and wim register are used to manage the register windows
3496in the SPARC architecture.  The register windows are discussed
3497in more detail below.
3498
3499Register Windows
3500----------------
3501
3502The SPARC architecture includes the concept of
3503register windows.  An overly simplistic way to think of these
3504windows is to imagine them as being an infinite supply of
3505"fresh" register sets available for each subroutine to use.  In
3506reality, they are much more complicated.
3507
3508The save instruction is used to obtain a new register
3509window.  This instruction decrements the current window pointer,
3510thus providing a new set of registers for use.  This register
3511set includes eight fresh local registers for use exclusively by
3512this subroutine.  When done with a register set, the restore
3513instruction increments the current window pointer and the
3514previous register set is once again available.
3515
3516The two primary issues complicating the use of
3517register windows are that (1) the set of register windows is
3518finite, and (2) some registers are shared between adjacent
3519registers windows.
3520
3521Because the set of register windows is finite, it is
3522possible to execute enough save instructions without
3523corresponding restore’s to consume all of the register windows.
3524This is easily accomplished in a high level language because
3525each subroutine typically performs a save instruction upon
3526entry.  Thus having a subroutine call depth greater than the
3527number of register windows will result in a window overflow
3528condition.  The window overflow condition generates a trap which
3529must be handled in software.  The window overflow trap handler
3530is responsible for saving the contents of the oldest register
3531window on the program stack.
3532
3533Similarly, the subroutines will eventually complete
3534and begin to perform restore’s.  If the restore results in the
3535need for a register window which has previously been written to
3536memory as part of an overflow, then a window underflow condition
3537results.  Just like the window overflow, the window underflow
3538condition must be handled in software by a trap handler.  The
3539window underflow trap handler is responsible for reloading the
3540contents of the register window requested by the restore
3541instruction from the program stack.
3542
3543The Window Invalid Mask (wim) and the Current Window
3544Pointer (cwp) field in the psr are used in conjunction to manage
3545the finite set of register windows and detect the window
3546overflow and underflow conditions.  The cwp contains the index
3547of the register window currently in use.  The save instruction
3548decrements the cwp modulo the number of register windows.
3549Similarly, the restore instruction increments the cwp modulo the
3550number of register windows.  Each bit in the  wim represents
3551represents whether a register window contains valid information.
3552The value of 0 indicates the register window is valid and 1
3553indicates it is invalid.  When a save instruction causes the cwp
3554to point to a register window which is marked as invalid, a
3555window overflow condition results.  Conversely, the restore
3556instruction may result in a window underflow condition.
3557
3558Other than the assumption that a register window is
3559always available for trap (i.e. interrupt) handlers, the SPARC
3560architecture places no limits on the number of register windows
3561simultaneously marked as invalid (i.e. number of bits set in the
3562wim).  However, RTEMS assumes that only one register window is
3563marked invalid at a time (i.e. only one bit set in the wim).
3564This makes the maximum possible number of register windows
3565available to the user while still meeting the requirement that
3566window overflow and underflow conditions can be detected.
3567
3568The window overflow and window underflow trap
3569handlers are a critical part of the run-time environment for a
3570SPARC application.  The SPARC architectural specification allows
3571for the number of register windows to be any power of two less
3572than or equal to 32.  The most common choice for SPARC
3573implementations appears to be 8 register windows.  This results
3574in the cwp ranging in value from 0 to 7 on most implementations.
3575
3576The second complicating factor is the sharing of
3577registers between adjacent register windows.  While each
3578register window has its own set of local registers, the input
3579and output registers are shared between adjacent windows.  The
3580output registers for register window N are the same as the input
3581registers for register window ((N - 1) modulo RW) where RW is
3582the number of register windows.  An alternative way to think of
3583this is to remember how parameters are passed to a subroutine on
3584the SPARC.  The caller loads values into what are its output
3585registers.  Then after the callee executes a save instruction,
3586those parameters are available in its input registers.  This is
3587a very efficient way to pass parameters as no data is actually
3588moved by the save or restore instructions.
3589
3590Call and Return Mechanism
3591-------------------------
3592
3593The SPARC architecture supports a simple yet
3594effective call and return mechanism.  A subroutine is invoked
3595via the call (call) instruction.  This instruction places the
3596return address in the caller’s output register 7 (o7).  After
3597the callee executes a save instruction, this value is available
3598in input register 7 (i7) until the corresponding restore
3599instruction is executed.
3600
3601The callee returns to the caller via a jmp to the
3602return address.  There is a delay slot following this
3603instruction which is commonly used to execute a restore
3604instruction – if a register window was allocated by this
3605subroutine.
3606
3607It is important to note that the SPARC subroutine
3608call and return mechanism does not automatically save and
3609restore any registers.  This is accomplished via the save and
3610restore instructions which manage the set of registers windows.
3611
3612In case a floating-point unit is supported, then floating-point return values
3613appear in the floating-point registers.  Single-precision values occupy %f0;
3614double-precision values occupy %f0 and %f1.  Otherwise, these are scratch
3615registers.  Due to this the hardware and software floating-point ABIs are
3616incompatible.
3617
3618Calling Mechanism
3619-----------------
3620
3621All RTEMS directives are invoked using the regular
3622SPARC calling convention via the call instruction.
3623
3624Register Usage
3625--------------
3626
3627As discussed above, the call instruction does not
3628automatically save any registers.  The save and restore
3629instructions are used to allocate and deallocate register
3630windows.  When a register window is allocated, the new set of
3631local registers are available for the exclusive use of the
3632subroutine which allocated this register set.
3633
3634Parameter Passing
3635-----------------
3636
3637RTEMS assumes that arguments are placed in the
3638caller’s output registers with the first argument in output
3639register 0 (o0), the second argument in output register 1 (o1),
3640and so forth.  Until the callee executes a save instruction, the
3641parameters are still visible in the output registers.  After the
3642callee executes a save instruction, the parameters are visible
3643in the corresponding input registers.  The following pseudo-code
3644illustrates the typical sequence used to call a RTEMS directive
3645with three (3) arguments:
3646.. code:: c
3647
3648    load third argument into o2
3649    load second argument into o1
3650    load first argument into o0
3651    invoke directive
3652
3653User-Provided Routines
3654----------------------
3655
3656All user-provided routines invoked by RTEMS, such as
3657user extensions, device drivers, and MPCI routines, must also
3658adhere to these calling conventions.
3659
3660.. COMMENT: COPYRIGHT (c) 1988-2002.
3661
3662.. COMMENT: On-Line Applications Research Corporation (OAR).
3663
3664.. COMMENT: All rights reserved.
3665
3666Memory Model
3667============
3668
3669A processor may support any combination of memory
3670models ranging from pure physical addressing to complex demand
3671paged virtual memory systems.  RTEMS supports a flat memory
3672model which ranges contiguously over the processor’s allowable
3673address space.  RTEMS does not support segmentation or virtual
3674memory of any kind.  The appropriate memory model for RTEMS
3675provided by the targeted processor and related characteristics
3676of that model are described in this chapter.
3677
3678Flat Memory Model
3679-----------------
3680
3681The SPARC architecture supports a flat 32-bit address
3682space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
3683gigabytes).  Each address is represented by a 32-bit value and
3684is byte addressable.  The address may be used to reference a
3685single byte, half-word (2-bytes), word (4 bytes), or doubleword
3686(8 bytes).  Memory accesses within this address space are
3687performed in big endian fashion by the SPARC.  Memory accesses
3688which are not properly aligned generate a "memory address not
3689aligned" trap (type number 7).  The following table lists the
3690alignment requirements for a variety of data accesses:
3691
3692.. code:: c
3693
3694    +--------------+-----------------------+
3695    |   Data Type  | Alignment Requirement |
3696    +--------------+-----------------------+
3697    |     byte     |          1            |
3698    |   half-word  |          2            |
3699    |     word     |          4            |
3700    |  doubleword  |          8            |
3701    +--------------+-----------------------+
3702
3703Doubleword load and store operations must use a pair
3704of registers as their source or destination.  This pair of
3705registers must be an adjacent pair of registers with the first
3706of the pair being even numbered.  For example, a valid
3707destination for a doubleword load might be input registers 0 and
37081 (i0 and i1).  The pair i1 and i2 would be invalid.  \[NOTE:
3709Some assemblers for the SPARC do not generate an error if an odd
3710numbered register is specified as the beginning register of the
3711pair.  In this case, the assembler assumes that what the
3712programmer meant was to use the even-odd pair which ends at the
3713specified register.  This may or may not have been a correct
3714assumption.]
3715
3716RTEMS does not support any SPARC Memory Management
3717Units, therefore, virtual memory or segmentation systems
3718involving the SPARC are not supported.
3719
3720.. COMMENT: COPYRIGHT (c) 1988-2002.
3721
3722.. COMMENT: On-Line Applications Research Corporation (OAR).
3723
3724.. COMMENT: All rights reserved.
3725
3726Interrupt Processing
3727====================
3728
3729Different types of processors respond to the
3730occurrence of an interrupt in its own unique fashion. In
3731addition, each processor type provides a control mechanism to
3732allow for the proper handling of an interrupt.  The processor
3733dependent response to the interrupt modifies the current
3734execution state and results in a change in the execution stream.
3735Most processors require that an interrupt handler utilize some
3736special control mechanisms to return to the normal processing
3737stream.  Although RTEMS hides many of the processor dependent
3738details of interrupt processing, it is important to understand
3739how the RTEMS interrupt manager is mapped onto the processor’s
3740unique architecture. Discussed in this chapter are the SPARC’s
3741interrupt response and control mechanisms as they pertain to
3742RTEMS.
3743
3744RTEMS and associated documentation uses the terms
3745interrupt and vector.  In the SPARC architecture, these terms
3746correspond to traps and trap type, respectively.  The terms will
3747be used interchangeably in this manual.
3748
3749Synchronous Versus Asynchronous Traps
3750-------------------------------------
3751
3752The SPARC architecture includes two classes of traps:
3753synchronous and asynchronous.  Asynchronous traps occur when an
3754external event interrupts the processor.  These traps are not
3755associated with any instruction executed by the processor and
3756logically occur between instructions.  The instruction currently
3757in the execute stage of the processor is allowed to complete
3758although subsequent instructions are annulled.  The return
3759address reported by the processor for asynchronous traps is the
3760pair of instructions following the current instruction.
3761
3762Synchronous traps are caused by the actions of an
3763instruction.  The trap stimulus in this case either occurs
3764internally to the processor or is from an external signal that
3765was provoked by the instruction.  These traps are taken
3766immediately and the instruction that caused the trap is aborted
3767before any state changes occur in the processor itself.   The
3768return address reported by the processor for synchronous traps
3769is the instruction which caused the trap and the following
3770instruction.
3771
3772Vectoring of Interrupt Handler
3773------------------------------
3774
3775Upon receipt of an interrupt the SPARC automatically
3776performs the following actions:
3777
3778- disables traps (sets the ET bit of the psr to 0),
3779
3780- the S bit of the psr is copied into the Previous
3781  Supervisor Mode (PS) bit of the psr,
3782
3783- the cwp is decremented by one (modulo the number of
3784  register windows) to activate a trap window,
3785
3786- the PC and nPC are loaded into local register 1 and 2
3787  (l0 and l1),
3788
3789- the trap type (tt) field of the Trap Base Register (TBR)
3790  is set to the appropriate value, and
3791
3792- if the trap is not a reset, then the PC is written with
3793  the contents of the TBR and the nPC is written with TBR + 4.  If
3794  the trap is a reset, then the PC is set to zero and the nPC is
3795  set to 4.
3796
3797Trap processing on the SPARC has two features which
3798are noticeably different than interrupt processing on other
3799architectures.  First, the value of psr register in effect
3800immediately before the trap occurred is not explicitly saved.
3801Instead only reversible alterations are made to it.  Second, the
3802Processor Interrupt Level (pil) is not set to correspond to that
3803of the interrupt being processed.  When a trap occurs, ALL
3804subsequent traps are disabled.  In order to safely invoke a
3805subroutine during trap handling, traps must be enabled to allow
3806for the possibility of register window overflow and underflow
3807traps.
3808
3809If the interrupt handler was installed as an RTEMS
3810interrupt handler, then upon receipt of the interrupt, the
3811processor passes control to the RTEMS interrupt handler which
3812performs the following actions:
3813
3814- saves the state of the interrupted task on it’s stack,
3815
3816- insures that a register window is available for
3817  subsequent traps,
3818
3819- if this is the outermost (i.e. non-nested) interrupt,
3820  then the RTEMS interrupt handler switches from the current stack
3821  to the interrupt stack,
3822
3823- enables traps,
3824
3825- invokes the vectors to a user interrupt service routine (ISR).
3826
3827Asynchronous interrupts are ignored while traps are
3828disabled.  Synchronous traps which occur while traps are
3829disabled result in the CPU being forced into an error mode.
3830
3831A nested interrupt is processed similarly with the
3832exception that the current stack need not be switched to the
3833interrupt stack.
3834
3835Traps and Register Windows
3836--------------------------
3837
3838One of the register windows must be reserved at all
3839times for trap processing.  This is critical to the proper
3840operation of the trap mechanism in the SPARC architecture.  It
3841is the responsibility of the trap handler to insure that there
3842is a register window available for a subsequent trap before
3843re-enabling traps.  It is likely that any high level language
3844routines invoked by the trap handler (such as a user-provided
3845RTEMS interrupt handler) will allocate a new register window.
3846The save operation could result in a window overflow trap.  This
3847trap cannot be correctly processed unless (1) traps are enabled
3848and (2) a register window is reserved for traps.  Thus, the
3849RTEMS interrupt handler insures that a register window is
3850available for subsequent traps before enabling traps and
3851invoking the user’s interrupt handler.
3852
3853Interrupt Levels
3854----------------
3855
3856Sixteen levels (0-15) of interrupt priorities are
3857supported by the SPARC architecture with level fifteen (15)
3858being the highest priority.  Level zero (0) indicates that
3859interrupts are fully enabled.  Interrupt requests for interrupts
3860with priorities less than or equal to the current interrupt mask
3861level are ignored. Level fifteen (15) is a non-maskable interrupt
3862(NMI), which makes it unsuitable for standard usage since it can
3863affect the real-time behaviour by interrupting critical sections
3864and spinlocks. Disabling traps stops also the NMI interrupt from
3865happening. It can however be used for power-down or other
3866critical events.
3867
3868Although RTEMS supports 256 interrupt levels, the
3869SPARC only supports sixteen.  RTEMS interrupt levels 0 through
387015 directly correspond to SPARC processor interrupt levels.  All
3871other RTEMS interrupt levels are undefined and their behavior is
3872unpredictable.
3873
3874Many LEON SPARC v7/v8 systems features an extended interrupt controller
3875which adds an extra step of interrupt decoding to allow handling of
3876interrupt 16-31. When such an extended interrupt is generated the CPU
3877traps into a specific interrupt trap level 1-14 and software reads out from
3878the interrupt controller which extended interrupt source actually caused the
3879interrupt.
3880
3881Disabling of Interrupts by RTEMS
3882--------------------------------
3883
3884During the execution of directive calls, critical
3885sections of code may be executed.  When these sections are
3886encountered, RTEMS disables interrupts to level fifteen (15)
3887before the execution of the section and restores them to the
3888previous level upon completion of the section.  RTEMS has been
3889optimized to ensure that interrupts are disabled for less than
3890RTEMS_MAXIMUM_DISABLE_PERIOD microseconds on a RTEMS_MAXIMUM_DISABLE_PERIOD_MHZ
3891Mhz ERC32 with zero wait states.
3892These numbers will vary based the number of wait states and
3893processor speed present on the target board.
3894\[NOTE:  The maximum period with interrupts disabled is hand calculated.  This
3895calculation was last performed for Release
3896RTEMS_RELEASE_FOR_MAXIMUM_DISABLE_PERIOD.]
3897
3898[NOTE: It is thought that the length of time at which
3899the processor interrupt level is elevated to fifteen by RTEMS is
3900not anywhere near as long as the length of time ALL traps are
3901disabled as part of the "flush all register windows" operation.]
3902
3903Non-maskable interrupts (NMI) cannot be disabled, and
3904ISRs which execute at this level MUST NEVER issue RTEMS system
3905calls.  If a directive is invoked, unpredictable results may
3906occur due to the inability of RTEMS to protect its critical
3907sections.  However, ISRs that make no system calls may safely
3908execute as non-maskable interrupts.
3909
3910Interrupts are disabled or enabled by performing a system call
3911to the Operating System reserved software traps 9
3912(SPARC_SWTRAP_IRQDIS) or 10 (SPARC_SWTRAP_IRQDIS). The trap is
3913generated by the software trap (Ticc) instruction or indirectly
3914by calling sparc_disable_interrupts() or sparc_enable_interrupts()
3915functions. Disabling interrupts return the previous interrupt level
3916(on trap entry) in register G1 and sets PSR.PIL to 15 to disable
3917all maskable interrupts. The interrupt level can be restored by
3918trapping into the enable interrupt handler with G1 containing the
3919new interrupt level.
3920
3921Interrupt Stack
3922---------------
3923
3924The SPARC architecture does not provide for a
3925dedicated interrupt stack.  Thus by default, trap handlers would
3926execute on the stack of the RTEMS task which they interrupted.
3927This artificially inflates the stack requirements for each task
3928since EVERY task stack would have to include enough space to
3929account for the worst case interrupt stack requirements in
3930addition to it’s own worst case usage.  RTEMS addresses this
3931problem on the SPARC by providing a dedicated interrupt stack
3932managed by software.
3933
3934During system initialization, RTEMS allocates the
3935interrupt stack from the Workspace Area.  The amount of memory
3936allocated for the interrupt stack is determined by the
3937interrupt_stack_size field in the CPU Configuration Table.  As
3938part of processing a non-nested interrupt, RTEMS will switch to
3939the interrupt stack before invoking the installed handler.
3940
3941.. COMMENT: COPYRIGHT (c) 1988-2002.
3942
3943.. COMMENT: On-Line Applications Research Corporation (OAR).
3944
3945.. COMMENT: All rights reserved.
3946
3947Default Fatal Error Processing
3948==============================
3949
3950Upon detection of a fatal error by either the
3951application or RTEMS the fatal error manager is invoked.  The
3952fatal error manager will invoke the user-supplied fatal error
3953handlers.  If no user-supplied handlers are configured,  the
3954RTEMS provided default fatal error handler is invoked.  If the
3955user-supplied fatal error handlers return to the executive the
3956default fatal error handler is then invoked.  This chapter
3957describes the precise operations of the default fatal error
3958handler.
3959
3960Default Fatal Error Handler Operations
3961--------------------------------------
3962
3963The default fatal error handler which is invoked by
3964the fatal_error_occurred directive when there is no user handler
3965configured or the user handler returns control to RTEMS.
3966
3967If the BSP has been configured with ``BSP_POWER_DOWN_AT_FATAL_HALT``
3968set to true, the default handler will disable interrupts
3969and enter power down mode. If power down mode is not available,
3970it goes into an infinite loop to simulate a halt processor instruction.
3971
3972If ``BSP_POWER_DOWN_AT_FATAL_HALT`` is set to false, the default
3973handler will place the value ``1`` in register ``g1``, the
3974error source in register ``g2``, and the error code in register``g3``. It will then generate a system error which will
3975hand over control to the debugger, simulator, etc.
3976
3977Symmetric Multiprocessing
3978=========================
3979
3980SMP is supported.  Available platforms are the Cobham Gaisler GR712RC and
3981GR740.
3982
3983Thread-Local Storage
3984====================
3985
3986Thread-local storage is supported.
3987
3988.. COMMENT: COPYRIGHT (c) 1988-2002.
3989
3990.. COMMENT: On-Line Applications Research Corporation (OAR).
3991
3992.. COMMENT: All rights reserved.
3993
3994Board Support Packages
3995======================
3996
3997An RTEMS Board Support Package (BSP) must be designed
3998to support a particular processor and target board combination.
3999This chapter presents a discussion of SPARC specific BSP issues.
4000For more information on developing a BSP, refer to the chapter
4001titled Board Support Packages in the RTEMS
4002Applications User’s Guide.
4003
4004System Reset
4005------------
4006
4007An RTEMS based application is initiated or
4008re-initiated when the SPARC processor is reset.  When the SPARC
4009is reset, the processor performs the following actions:
4010
4011- the enable trap (ET) of the psr is set to 0 to disable
4012  traps,
4013
4014- the supervisor bit (S) of the psr is set to 1 to enter
4015  supervisor mode, and
4016
4017- the PC is set 0 and the nPC is set to 4.
4018
4019The processor then begins to execute the code at
4020location 0.  It is important to note that all fields in the psr
4021are not explicitly set by the above steps and all other
4022registers retain their value from the previous execution mode.
4023This is true even of the Trap Base Register (TBR) whose contents
4024reflect the last trap which occurred before the reset.
4025
4026Processor Initialization
4027------------------------
4028
4029It is the responsibility of the application’s
4030initialization code to initialize the TBR and install trap
4031handlers for at least the register window overflow and register
4032window underflow conditions.  Traps should be enabled before
4033invoking any subroutines to allow for register window
4034management.  However, interrupts should be disabled by setting
4035the Processor Interrupt Level (pil) field of the psr to 15.
4036RTEMS installs it’s own Trap Table as part of initialization
4037which is initialized with the contents of the Trap Table in
4038place when the ``rtems_initialize_executive`` directive was invoked.
4039Upon completion of executive initialization, interrupts are
4040enabled.
4041
4042If this SPARC implementation supports on-chip caching
4043and this is to be utilized, then it should be enabled during the
4044reset application initialization code.
4045
4046In addition to the requirements described in the
4047Board Support Packages chapter of the C
4048Applications Users Manual for the reset code
4049which is executed before the call to``rtems_initialize_executive``, the SPARC version has the following
4050specific requirements:
4051
4052- Must leave the S bit of the status register set so that
4053  the SPARC remains in the supervisor state.
4054
4055- Must set stack pointer (sp) such that a minimum stack
4056  size of MINIMUM_STACK_SIZE bytes is provided for the``rtems_initialize_executive`` directive.
4057
4058- Must disable all external interrupts (i.e. set the pil
4059  to 15).
4060
4061- Must enable traps so window overflow and underflow
4062  conditions can be properly handled.
4063
4064- Must initialize the SPARC’s initial trap table with at
4065  least trap handlers for register window overflow and register
4066  window underflow.
4067
4068.. COMMENT: COPYRIGHT (c) 1988-2002.
4069
4070.. COMMENT: On-Line Applications Research Corporation (OAR).
4071
4072.. COMMENT: All rights reserved.
4073
4074SPARC-64 Specific Information
4075#############################
4076
4077This document discusses the SPARC Version 9 (aka SPARC-64, SPARC64 or SPARC V9)
4078architecture dependencies in this port of RTEMS.
4079
4080The SPARC V9 architecture leaves a lot of undefined implemenation dependencies
4081which are defined by the processor models. Consult the specific CPU model
4082section in this document for additional documents covering the implementation
4083dependent architectural features.
4084
4085**sun4u Specific Information**
4086
4087sun4u is the subset of the SPARC V9 implementations comprising the UltraSPARC I
4088through UltraSPARC IV processors.
4089
4090The following documents were used in developing the SPARC-64 sun4u port:
4091
4092- UltraSPARC  User’s Manual
4093  (http://www.sun.com/microelectronics/manuals/ultrasparc/802-7220-02.pdf)
4094
4095- UltraSPARC IIIi Processor (datasheets.chipdb.org/Sun/UltraSparc-IIIi.pdf)
4096
4097**sun4v Specific Information**
4098
4099sun4v is the subset of the SPARC V9 implementations comprising the
4100UltraSPARC T1 or T2 processors.
4101
4102The following documents were used in developing the SPARC-64 sun4v port:
4103
4104- UltraSPARC Architecture 2005 Specification
4105  (http://opensparc-t1.sunsource.net/specs/UA2005-current-draft-P-EXT.pdf)
4106
4107- UltraSPARC T1 supplement to UltraSPARC Architecture 2005 Specification
4108  (http://opensparc-t1.sunsource.net/specs/UST1-UASuppl-current-draft-P-EXT.pdf)
4109
4110The defining feature that separates the sun4v architecture from its
4111predecessor is the existence of a super-privileged hypervisor that
4112is responsible for providing virtualized execution environments.  The impact
4113of the hypervisor on the real-time guarantees available with sun4v has not
4114yet been determined.
4115
4116CPU Model Dependent Features
4117============================
4118
4119CPU Model Feature Flags
4120-----------------------
4121
4122This section presents the set of features which vary across
4123SPARC-64 implementations and
4124are of importance to RTEMS. The set of CPU model feature macros
4125are defined in the file
4126cpukit/score/cpu/sparc64/sparc64.h based upon the particular
4127CPU model defined on the compilation command line.
4128
4129CPU Model Name
4130~~~~~~~~~~~~~~
4131
4132The macro CPU MODEL NAME is a string which designates
4133the name of this CPU model.
4134For example, for the UltraSPARC T1 SPARC V9 model,
4135this macro is set to the string "sun4v".
4136
4137Floating Point Unit
4138~~~~~~~~~~~~~~~~~~~
4139
4140The macro SPARC_HAS_FPU is set to 1 to indicate that
4141this CPU model has a hardware floating point unit and 0
4142otherwise.
4143
4144Number of Register Windows
4145~~~~~~~~~~~~~~~~~~~~~~~~~~
4146
4147The macro SPARC_NUMBER_OF_REGISTER_WINDOWS is set to
4148indicate the number of register window sets implemented by this
4149CPU model.  The SPARC architecture allows for a maximum of
4150thirty-two register window sets although most implementations
4151only include eight.
4152
4153CPU Model Implementation Notes
4154------------------------------
4155
4156This section describes the implemenation dependencies of the
4157CPU Models sun4u and sun4v of the SPARC V9 architecture.
4158
4159sun4u Notes
4160~~~~~~~~~~~
4161
4162XXX
4163
4164sun4v Notes
4165-----------
4166
4167XXX
4168
4169.. COMMENT: COPYRIGHT (c) 1988-2002.
4170
4171.. COMMENT: On-Line Applications Research Corporation (OAR).
4172
4173.. COMMENT: All rights reserved.
4174
4175Calling Conventions
4176===================
4177
4178Each high-level language compiler generates
4179subroutine entry and exit code based upon a set of rules known
4180as the compiler’s calling convention.   These rules address the
4181following issues:
4182
4183- register preservation and usage
4184
4185- parameter passing
4186
4187- call and return mechanism
4188
4189A compiler’s calling convention is of importance when
4190interfacing to subroutines written in another language either
4191assembly or high-level.  Even when the high-level language and
4192target processor are the same, different compilers may use
4193different calling conventions.  As a result, calling conventions
4194are both processor and compiler dependent.
4195
4196The following document also provides some conventions on the
4197global register usage in SPARC V9:
4198http://developers.sun.com/solaris/articles/sparcv9abi.html
4199
4200Programming Model
4201-----------------
4202
4203This section discusses the programming model for the
4204SPARC architecture.
4205
4206Non-Floating Point Registers
4207~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4208
4209The SPARC architecture defines thirty-two
4210non-floating point registers directly visible to the programmer.
4211These are divided into four sets:
4212
4213- input registers
4214
4215- local registers
4216
4217- output registers
4218
4219- global registers
4220
4221Each register is referred to by either two or three
4222names in the SPARC reference manuals.  First, the registers are
4223referred to as r0 through r31 or with the alternate notation
4224r[0] through r[31].  Second, each register is a member of one of
4225the four sets listed above.  Finally, some registers have an
4226architecturally defined role in the programming model which
4227provides an alternate name.  The following table describes the
4228mapping between the 32 registers and the register sets:
4229
4230.. code:: c
4231
4232    +-----------------+----------------+------------------+
4233    | Register Number | Register Names |   Description    |
4234    +-----------------+----------------+------------------+
4235    |     0 - 7       |    g0 - g7     | Global Registers |
4236    +-----------------+----------------+------------------+
4237    |     8 - 15      |    o0 - o7     | Output Registers |
4238    +-----------------+----------------+------------------+
4239    |    16 - 23      |    l0 - l7     | Local Registers  |
4240    +-----------------+----------------+------------------+
4241    |    24 - 31      |    i0 - i7     | Input Registers  |
4242    +-----------------+----------------+------------------+
4243
4244As mentioned above, some of the registers serve
4245defined roles in the programming model.  The following table
4246describes the role of each of these registers:
4247
4248.. code:: c
4249
4250    +---------------+----------------+----------------------+
4251    | Register Name | Alternate Name |      Description     |
4252    +---------------+----------------+----------------------+
4253    |     g0        |      na        |    reads return 0    |
4254    |               |                |  writes are ignored  |
4255    +---------------+----------------+----------------------+
4256    |     o6        |      sp        |     stack pointer    |
4257    +---------------+----------------+----------------------+
4258    |     i6        |      fp        |     frame pointer    |
4259    +---------------+----------------+----------------------+
4260    |     i7        |      na        |    return address    |
4261    +---------------+----------------+----------------------+
4262
4263Floating Point Registers
4264~~~~~~~~~~~~~~~~~~~~~~~~
4265
4266The SPARC V9 architecture includes sixty-four,
4267thirty-two bit registers.  These registers may be viewed as
4268follows:
4269
4270- 32 32-bit single precision floating point or integer registers
4271  (f0, f1,  ... f31)
4272
4273- 32 64-bit double precision floating point registers (f0, f2,
4274  f4, ... f62)
4275
4276- 16 128-bit extended precision floating point registers (f0, f4,
4277  f8, ... f60)
4278
4279The floating point state register (fsr) specifies
4280the behavior of the floating point unit for rounding, contains
4281its condition codes, version specification, and trap information.
4282
4283Special Registers
4284~~~~~~~~~~~~~~~~~
4285
4286The SPARC architecture includes a number of special registers:
4287
4288*``Ancillary State Registers (ASRs)``*
4289    The ancillary state registers (ASRs) are optional state registers that
4290    may be privileged or nonprivileged. ASRs 16-31 are implementation-
4291    dependent. The SPARC V9 ASRs include: y, ccr, asi, tick, pc, fprs.
4292    The sun4u ASRs include: pcr, pic, dcr, gsr, softint set, softint clr,
4293    softint, and tick cmpr. The sun4v ASRs include: pcr, pic, gsr, soft-
4294    int set, softint clr, softint, tick cmpr, stick, and stick cmpr.
4295
4296*``Processor State Register (pstate)``*
4297    The privileged pstate register contains control fields for the proces-
4298    sor’s current state. Its flag fields include the interrupt enable, privi-
4299    leged mode, and enable FPU.
4300
4301*``Processor Interrupt Level (pil)``*
4302    The PIL specifies the interrupt level above which interrupts will be
4303    accepted.
4304
4305*``Trap Registers``*
4306    The trap handling mechanism of the SPARC V9 includes a number of
4307    registers, including: trap program counter (tpc), trap next pc (tnpc),
4308    trap state (tstate), trap type (tt), trap base address (tba), and trap
4309    level (tl).
4310
4311*``Alternate Globals``*
4312    The AG bit of the pstate register provides access to an alternate set
4313    of global registers. On sun4v, the AG bit is replaced by the global
4314    level (gl) register, providing access to at least two and at most eight
4315    alternate sets of globals.
4316
4317*``Register Window registers``*
4318    A number of registers assist in register window management.
4319    These include the current window pointer (cwp), savable windows
4320    (cansave), restorable windows (canrestore), clean windows (clean-
4321    win), other windows (otherwin), and window state (wstate).
4322
4323Register Windows
4324----------------
4325
4326The SPARC architecture includes the concept of
4327register windows.  An overly simplistic way to think of these
4328windows is to imagine them as being an infinite supply of
4329"fresh" register sets available for each subroutine to use.  In
4330reality, they are much more complicated.
4331
4332The save instruction is used to obtain a new register window.
4333This instruction increments the current window pointer, thus
4334providing a new set of registers for use. This register set
4335includes eight fresh local registers for use exclusively by
4336this subroutine. When done with a register set, the restore
4337instruction decrements the current window pointer and the
4338previous register set is once again available.
4339
4340The two primary issues complicating the use of register windows
4341are that (1) the set of register windows is finite, and (2) some
4342registers are shared between adjacent registers windows.
4343
4344Because the set of register windows is finite, it is
4345possible to execute enough save instructions without
4346corresponding restore’s to consume all of the register windows.
4347This is easily accomplished in a high level language because
4348each subroutine typically performs a save instruction upon
4349entry.  Thus having a subroutine call depth greater than the
4350number of register windows will result in a window overflow
4351condition.  The window overflow condition generates a trap which
4352must be handled in software.  The window overflow trap handler
4353is responsible for saving the contents of the oldest register
4354window on the program stack.
4355
4356Similarly, the subroutines will eventually complete
4357and begin to perform restore’s.  If the restore results in the
4358need for a register window which has previously been written to
4359memory as part of an overflow, then a window underflow condition
4360results.  Just like the window overflow, the window underflow
4361condition must be handled in software by a trap handler.  The
4362window underflow trap handler is responsible for reloading the
4363contents of the register window requested by the restore
4364instruction from the program stack.
4365
4366The cansave, canrestore, otherwin, and cwp are used in conjunction
4367to manage the finite set of register windows and detect the window
4368overflow and underflow conditions. The first three of these
4369registers must satisfy the invariant cansave + canrestore + otherwin =
4370nwindow - 2, where nwindow is the number of register windows.
4371The cwp contains the index of the register window currently in use.
4372RTEMS does not use the cleanwin and otherwin registers.
4373
4374The save instruction increments the cwp modulo the number of
4375register windows, and if cansave is 0 then it also generates a
4376window overflow. Similarly, the restore instruction decrements the
4377cwp modulo the number of register windows, and if canrestore is 0 then it
4378also generates a window underflow.
4379
4380Unlike with the SPARC model, the SPARC-64 port does not assume that
4381a register window is available for a trap. The window overflow
4382and underflow conditions are not detected without hardware generating
4383the trap. (These conditions can be detected by reading the register window
4384registers and doing some simple arithmetic.)
4385
4386The window overflow and window underflow trap
4387handlers are a critical part of the run-time environment for a
4388SPARC application.  The SPARC architectural specification allows
4389for the number of register windows to be any power of two less
4390than or equal to 32.  The most common choice for SPARC
4391implementations appears to be 8 register windows.  This results
4392in the cwp ranging in value from 0 to 7 on most implementations.
4393
4394The second complicating factor is the sharing of
4395registers between adjacent register windows.  While each
4396register window has its own set of local registers, the input
4397and output registers are shared between adjacent windows.  The
4398output registers for register window N are the same as the input
4399registers for register window ((N + 1) modulo RW) where RW is
4400the number of register windows.  An alternative way to think of
4401this is to remember how parameters are passed to a subroutine on
4402the SPARC.  The caller loads values into what are its output
4403registers.  Then after the callee executes a save instruction,
4404those parameters are available in its input registers.  This is
4405a very efficient way to pass parameters as no data is actually
4406moved by the save or restore instructions.
4407
4408Call and Return Mechanism
4409-------------------------
4410
4411The SPARC architecture supports a simple yet
4412effective call and return mechanism.  A subroutine is invoked
4413via the call (call) instruction.  This instruction places the
4414return address in the caller’s output register 7 (o7).  After
4415the callee executes a save instruction, this value is available
4416in input register 7 (i7) until the corresponding restore
4417instruction is executed.
4418
4419The callee returns to the caller via a jmp to the
4420return address.  There is a delay slot following this
4421instruction which is commonly used to execute a restore
4422instruction – if a register window was allocated by this
4423subroutine.
4424
4425It is important to note that the SPARC subroutine
4426call and return mechanism does not automatically save and
4427restore any registers.  This is accomplished via the save and
4428restore instructions which manage the set of registers windows.
4429This allows for the compiler to generate leaf-optimized functions
4430that utilize the caller’s output registers without using save and restore.
4431
4432Calling Mechanism
4433-----------------
4434
4435All RTEMS directives are invoked using the regular
4436SPARC calling convention via the call instruction.
4437
4438Register Usage
4439--------------
4440
4441As discussed above, the call instruction does not
4442automatically save any registers.  The save and restore
4443instructions are used to allocate and deallocate register
4444windows.  When a register window is allocated, the new set of
4445local registers are available for the exclusive use of the
4446subroutine which allocated this register set.
4447
4448Parameter Passing
4449-----------------
4450
4451RTEMS assumes that arguments are placed in the
4452caller’s output registers with the first argument in output
4453register 0 (o0), the second argument in output register 1 (o1),
4454and so forth.  Until the callee executes a save instruction, the
4455parameters are still visible in the output registers.  After the
4456callee executes a save instruction, the parameters are visible
4457in the corresponding input registers.  The following pseudo-code
4458illustrates the typical sequence used to call a RTEMS directive
4459with three (3) arguments:
4460.. code:: c
4461
4462    load third argument into o2
4463    load second argument into o1
4464    load first argument into o0
4465    invoke directive
4466
4467User-Provided Routines
4468----------------------
4469
4470All user-provided routines invoked by RTEMS, such as
4471user extensions, device drivers, and MPCI routines, must also
4472adhere to these calling conventions.
4473
4474.. COMMENT: COPYRIGHT (c) 1988-2002.
4475
4476.. COMMENT: On-Line Applications Research Corporation (OAR).
4477
4478.. COMMENT: All rights reserved.
4479
4480Memory Model
4481============
4482
4483A processor may support any combination of memory
4484models ranging from pure physical addressing to complex demand
4485paged virtual memory systems.  RTEMS supports a flat memory
4486model which ranges contiguously over the processor’s allowable
4487address space.  RTEMS does not support segmentation or virtual
4488memory of any kind.  The appropriate memory model for RTEMS
4489provided by the targeted processor and related characteristics
4490of that model are described in this chapter.
4491
4492Flat Memory Model
4493-----------------
4494
4495The SPARC-64 architecture supports a flat 64-bit address space with
4496addresses ranging from 0x0000000000000000 to 0xFFFFFFFFFFFFFFFF.
4497Each address is represented by a 64-bit value (and an 8-bit address
4498space identifider or ASI) and is byte addressable. The address
4499may be used to reference a single byte, half-word (2-bytes),
4500word (4 bytes), doubleword (8 bytes), or quad-word (16 bytes).
4501Memory accesses within this address space are performed
4502in big endian fashion by the SPARC. Memory accesses which are not
4503properly aligned generate a "memory address not aligned" trap
4504(type number 0x34). The following table lists the alignment
4505requirements for a variety of data accesses:
4506
4507.. code:: c
4508
4509    +--------------+-----------------------+
4510    |   Data Type  | Alignment Requirement |
4511    +--------------+-----------------------+
4512    |     byte     |          1            |
4513    |   half-word  |          2            |
4514    |     word     |          4            |
4515    |  doubleword  |          8            |
4516    |   quadword   |          16           |
4517    +--------------+-----------------------+
4518
4519RTEMS currently does not support any SPARC Memory Management
4520Units, therefore, virtual memory or segmentation systems
4521involving the SPARC are not supported.
4522
4523.. COMMENT: COPYRIGHT (c) 1988-2002.
4524
4525.. COMMENT: On-Line Applications Research Corporation (OAR).
4526
4527.. COMMENT: All rights reserved.
4528
4529Interrupt Processing
4530====================
4531
4532RTEMS and associated documentation uses the terms
4533interrupt and vector.  In the SPARC architecture, these terms
4534correspond to traps and trap type, respectively.  The terms will
4535be used interchangeably in this manual. Note that in the SPARC manuals,
4536interrupts are a subset of the traps that are delivered to software
4537interrupt handlers.
4538
4539Synchronous Versus Asynchronous Traps
4540-------------------------------------
4541
4542The SPARC architecture includes two classes of traps:
4543synchronous (precise) and asynchronous (deferred).
4544Asynchronous traps occur when an
4545external event interrupts the processor.  These traps are not
4546associated with any instruction executed by the processor and
4547logically occur between instructions.  The instruction currently
4548in the execute stage of the processor is allowed to complete
4549although subsequent instructions are annulled.  The return
4550address reported by the processor for asynchronous traps is the
4551pair of instructions following the current instruction.
4552
4553Synchronous traps are caused by the actions of an
4554instruction.  The trap stimulus in this case either occurs
4555internally to the processor or is from an external signal that
4556was provoked by the instruction.  These traps are taken
4557immediately and the instruction that caused the trap is aborted
4558before any state changes occur in the processor itself.   The
4559return address reported by the processor for synchronous traps
4560is the instruction which caused the trap and the following
4561instruction.
4562
4563Vectoring of Interrupt Handler
4564------------------------------
4565
4566Upon receipt of an interrupt the SPARC automatically
4567performs the following actions:
4568
4569- The trap level is set. This provides access to a fresh set of
4570  privileged trap-state registers used to save the current state,
4571  in effect, pushing a frame on the trap stack.
4572  TL <- TL + 1
4573
4574- Existing state is preserved
4575  - TSTATE[TL].CCR <- CCR
4576  - TSTATE[TL].ASI <- ASI
4577  - TSTATE[TL].PSTATE <- PSTATE
4578  - TSTATE[TL].CWP <- CWP
4579  - TPC[TL] <- PC
4580  - TNPC[TL] <- nPC
4581
4582- The trap type is preserved. TT[TL] <- the trap type
4583
4584- The PSTATE register is updated to a predefined state
4585  - PSTATE.MM is unchanged
4586  - PSTATE.RED <- 0
4587  - PSTATE.PEF <- 1 if FPU is present, 0 otherwise
4588  - PSTATE.AM <- 0 (address masking is turned off)
4589  - PSTATE.PRIV <- 1 (the processor enters privileged mode)
4590  - PSTATE.IE <- 0 (interrupts are disabled)
4591  - PSTATE.AG <- 1 (global regs are replaced with alternate globals)
4592  - PSTATE.CLE <- PSTATE.TLE (set endian mode for traps)
4593
4594- For a register-window trap only, CWP is set to point to the register
4595  window that must be accessed by the trap-handler software, that is:
4596
4597  - If TT[TL] = 0x24 (a clean window trap), then CWP <- CWP + 1.
4598  - If (0x80 <= TT[TL] <= 0xBF) (window spill trap), then CWP <- CWP +
4599    CANSAVE + 2.
4600  - If (0xC0 <= TT[TL] <= 0xFF) (window fill trap), then CWP <- CWP1.
4601  - For non-register-window traps, CWP is not changed.
4602
4603- Control is transferred into the trap table:
4604
4605  - PC <- TBA<63:15> (TL>0) TT[TL] 0 0000
4606  - nPC <- TBA<63:15> (TL>0) TT[TL] 0 0100
4607  - where (TL>0) is 0 if TL = 0, and 1 if TL > 0.
4608
4609In order to safely invoke a subroutine during trap handling, traps must be
4610enabled to allow for the possibility of register window overflow and
4611underflow traps.
4612
4613If the interrupt handler was installed as an RTEMS
4614interrupt handler, then upon receipt of the interrupt, the
4615processor passes control to the RTEMS interrupt handler which
4616performs the following actions:
4617
4618- saves the state of the interrupted task on it’s stack,
4619
4620- switches the processor to trap level 0,
4621
4622- if this is the outermost (i.e. non-nested) interrupt,
4623  then the RTEMS interrupt handler switches from the current stack
4624  to the interrupt stack,
4625
4626- enables traps,
4627
4628- invokes the vectors to a user interrupt service routine (ISR).
4629
4630Asynchronous interrupts are ignored while traps are
4631disabled.  Synchronous traps which occur while traps are
4632disabled may result in the CPU being forced into an error mode.
4633
4634A nested interrupt is processed similarly with the
4635exception that the current stack need not be switched to the
4636interrupt stack.
4637
4638Traps and Register Windows
4639--------------------------
4640
4641XXX
4642
4643Interrupt Levels
4644----------------
4645
4646Sixteen levels (0-15) of interrupt priorities are
4647supported by the SPARC architecture with level fifteen (15)
4648being the highest priority.  Level zero (0) indicates that
4649interrupts are fully enabled.  Interrupt requests for interrupts
4650with priorities less than or equal to the current interrupt mask
4651level are ignored.
4652
4653Although RTEMS supports 256 interrupt levels, the
4654SPARC only supports sixteen.  RTEMS interrupt levels 0 through
465515 directly correspond to SPARC processor interrupt levels.  All
4656other RTEMS interrupt levels are undefined and their behavior is
4657unpredictable.
4658
4659Disabling of Interrupts by RTEMS
4660--------------------------------
4661
4662XXX
4663
4664Interrupt Stack
4665---------------
4666
4667The SPARC architecture does not provide for a
4668dedicated interrupt stack.  Thus by default, trap handlers would
4669execute on the stack of the RTEMS task which they interrupted.
4670This artificially inflates the stack requirements for each task
4671since EVERY task stack would have to include enough space to
4672account for the worst case interrupt stack requirements in
4673addition to it’s own worst case usage.  RTEMS addresses this
4674problem on the SPARC by providing a dedicated interrupt stack
4675managed by software.
4676
4677During system initialization, RTEMS allocates the
4678interrupt stack from the Workspace Area.  The amount of memory
4679allocated for the interrupt stack is determined by the
4680interrupt_stack_size field in the CPU Configuration Table.  As
4681part of processing a non-nested interrupt, RTEMS will switch to
4682the interrupt stack before invoking the installed handler.
4683
4684.. COMMENT: COPYRIGHT (c) 1988-2002.
4685
4686.. COMMENT: On-Line Applications Research Corporation (OAR).
4687
4688.. COMMENT: All rights reserved.
4689
4690Default Fatal Error Processing
4691==============================
4692
4693Upon detection of a fatal error by either the
4694application or RTEMS the fatal error manager is invoked.  The
4695fatal error manager will invoke the user-supplied fatal error
4696handlers.  If no user-supplied handlers are configured,  the
4697RTEMS provided default fatal error handler is invoked.  If the
4698user-supplied fatal error handlers return to the executive the
4699default fatal error handler is then invoked.  This chapter
4700describes the precise operations of the default fatal error
4701handler.
4702
4703Default Fatal Error Handler Operations
4704--------------------------------------
4705
4706The default fatal error handler which is invoked by
4707the fatal_error_occurred directive when there is no user handler
4708configured or the user handler returns control to RTEMS.  The
4709default fatal error handler disables processor interrupts to
4710level 15, places the error code in g1, and goes into an infinite
4711loop to simulate a halt processor instruction.
4712
4713Symmetric Multiprocessing
4714=========================
4715
4716SMP is not supported.
4717
4718Thread-Local Storage
4719====================
4720
4721Thread-local storage is supported.
4722
4723.. COMMENT: COPYRIGHT (c) 1988-2002.
4724
4725.. COMMENT: On-Line Applications Research Corporation (OAR).
4726
4727.. COMMENT: All rights reserved.
4728
4729Board Support Packages
4730======================
4731
4732An RTEMS Board Support Package (BSP) must be designed
4733to support a particular processor and target board combination.
4734This chapter presents a discussion of SPARC specific BSP issues.
4735For more information on developing a BSP, refer to the chapter
4736titled Board Support Packages in the RTEMS
4737Applications User’s Guide.
4738
4739HelenOS and Open Firmware
4740-------------------------
4741
4742The provided BSPs make use of some bootstrap and low-level hardware code
4743of the HelenOS operating system. These files can be found in the shared/helenos
4744directory of the sparc64 bsp directory.  Consult the sources for more
4745detailed information.
4746
4747The shared BSP code also uses the Open Firmware interface to re-use firmware
4748code, primarily for console support and default trap handlers.
4749
4750Command and Variable Index
4751##########################
4752
4753There are currently no Command and Variable Index entries.
4754
4755.. COMMENT: @printindex fn
4756
4757Concept Index
4758#############
4759
4760There are currently no Concept Index entries.
4761
4762.. COMMENT: @printindex cp
Note: See TracBrowser for help on using the repository browser.