source: rtems-docs/cpu_supplement/cpu_supplement_old_reference_only.rst @ 170418a

4.115
Last change on this file since 170418a was 3c29186, checked in by Amar Takhar <amar@…>, on 01/17/16 at 01:13:24

Rename old document for reference only.

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