source: rtems-docs/cpu_supplement/cpu_supplement.rst @ 5daabd2

4.115am
Last change on this file since 5daabd2 was 5daabd2, checked in by Amar Takhar <amar@…>, on 01/16/16 at 04:41:06

Initial reST documentation using Sphinx.

  • 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.. code:: c
1330
1331    +----------------------+
1332    | Old EFLAGS Register  | ESP+8
1333    +----------+-----------+
1334    |   UNUSED |  Old CS   | ESP+4
1335    +----------+-----------+
1336    |       Old EIP        | ESP
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.. code:: c
1937
1938    +----------------------+
1939    |    Status Register   | 0x0
1940    +----------------------+
1941    | Program Counter High | 0x2
1942    +----------------------+
1943    | Program Counter Low  | 0x4
1944    +----------------------+
1945    | Format/Vector Offset | 0x6
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.. code:: c
2761
2762    +--------------+-----------------------+
2763    |   Data Type  | Alignment Requirement |
2764    +--------------+-----------------------+
2765    |     byte     |          1            |
2766    |   half-word  |          2            |
2767    |     word     |          4            |
2768    |  doubleword  |          8            |
2769    +--------------+-----------------------+
2770
2771Doubleword load and store operations are only available in
2772PowerPC CPU models which are sixty-four bit implementations.
2773
2774RTEMS does not directly support any PowerPC Memory Management
2775Units, therefore, virtual memory or segmentation systems
2776involving the PowerPC  are not supported.
2777
2778.. COMMENT: COPYRIGHT (c) 1989-2007.
2779
2780.. COMMENT: On-Line Applications Research Corporation (OAR).
2781
2782.. COMMENT: All rights reserved.
2783
2784Interrupt Processing
2785====================
2786
2787Although RTEMS hides many of the processor dependent
2788details of interrupt processing, it is important to understand
2789how the RTEMS interrupt manager is mapped onto the processor’s
2790unique architecture. Discussed in this chapter are the PowerPC’s
2791interrupt response and control mechanisms as they pertain to
2792RTEMS.
2793
2794RTEMS and associated documentation uses the terms interrupt and vector.
2795In the PowerPC architecture, these terms correspond to exception and
2796exception handler, respectively.  The terms will be used interchangeably
2797in this manual.
2798
2799Synchronous Versus Asynchronous Exceptions
2800------------------------------------------
2801
2802In the PowerPC architecture exceptions can be either precise or
2803imprecise and either synchronous or asynchronous.  Asynchronous
2804exceptions occur when an external event interrupts the processor.
2805Synchronous exceptions are caused by the actions of an
2806instruction. During an exception SRR0 is used to calculate where
2807instruction processing should resume.  All instructions prior to
2808the resume instruction will have completed execution.  SRR1 is used to
2809store the machine status.
2810
2811There are two asynchronous nonmaskable, highest-priority exceptions
2812system reset and machine check.  There are two asynchrononous maskable
2813low-priority exceptions external interrupt and decrementer.  Nonmaskable
2814execptions are never delayed, therefore if two nonmaskable, asynchronous
2815exceptions occur in immediate succession, the state information saved by
2816the first exception may be overwritten when the subsequent exception occurs.
2817
2818The PowerPC arcitecure defines one imprecise exception, the imprecise
2819floating point enabled exception.  All other synchronous exceptions are
2820precise.  The synchronization occuring during asynchronous precise
2821exceptions conforms to the requirements for context synchronization.
2822
2823Vectoring of Interrupt Handler
2824------------------------------
2825
2826Upon determining that an exception can be taken the PowerPC automatically
2827performs the following actions:
2828
2829- an instruction address is loaded into SRR0
2830
2831- bits 33-36 and 42-47 of SRR1 are loaded with information
2832  specific to the exception.
2833
2834- bits 0-32, 37-41, and 48-63 of SRR1 are loaded with corresponding
2835  bits from the MSR.
2836
2837- the MSR is set based upon the exception type.
2838
2839- instruction fetch and execution resumes, using the new MSR value, at a location specific to the execption type.
2840
2841If the interrupt handler was installed as an RTEMS
2842interrupt handler, then upon receipt of the interrupt, the
2843processor passes control to the RTEMS interrupt handler which
2844performs the following actions:
2845
2846- saves the state of the interrupted task on it’s stack,
2847
2848- saves all registers which are not normally preserved
2849  by the calling sequence so the user’s interrupt service
2850  routine can be written in a high-level language.
2851
2852- if this is the outermost (i.e. non-nested) interrupt,
2853  then the RTEMS interrupt handler switches from the current stack
2854  to the interrupt stack,
2855
2856- enables exceptions,
2857
2858- invokes the vectors to a user interrupt service routine (ISR).
2859
2860Asynchronous interrupts are ignored while exceptions are
2861disabled.  Synchronous interrupts which occur while are
2862disabled result in the CPU being forced into an error mode.
2863
2864A nested interrupt is processed similarly with the
2865exception that the current stack need not be switched to the
2866interrupt stack.
2867
2868Interrupt Levels
2869----------------
2870
2871The PowerPC architecture supports only a single external
2872asynchronous interrupt source.  This interrupt source
2873may be enabled and disabled via the External Interrupt Enable (EE)
2874bit in the Machine State Register (MSR).  Thus only two level (enabled
2875and disabled) of external device interrupt priorities are
2876directly supported by the PowerPC architecture.
2877
2878Some PowerPC implementations include a Critical Interrupt capability
2879which is often used to receive interrupts from high priority external
2880devices.
2881
2882The RTEMS interrupt level mapping scheme for the PowerPC is not
2883a numeric level as on most RTEMS ports.  It is a bit mapping in
2884which the least three significiant bits of the interrupt level
2885are mapped directly to the enabling of specific interrupt
2886sources as follows:
2887
2888*Critical Interrupt*
2889    Setting bit 0 (the least significant bit) of the interrupt level
2890    enables the Critical Interrupt source, if it is available on this
2891    CPU model.
2892
2893*Machine Check*
2894    Setting bit 1 of the interrupt level enables Machine Check execptions.
2895
2896*External Interrupt*
2897    Setting bit 2 of the interrupt level enables External Interrupt execptions.
2898
2899All other bits in the RTEMS task interrupt level are ignored.
2900
2901Default Fatal Error Processing
2902==============================
2903
2904The default fatal error handler for this architecture performs the
2905following actions:
2906
2907- places the error code in r3, and
2908
2909- executes a trap instruction which results in a Program Exception.
2910
2911If the Program Exception returns, then the following actions are performed:
2912
2913- disables all processor exceptions by loading a 0 into the MSR, and
2914
2915- goes into an infinite loop to simulate a halt processor instruction.
2916
2917Symmetric Multiprocessing
2918=========================
2919
2920SMP is supported.  Available platforms are the Freescale QorIQ P series (e.g.
2921P1020) and T series (e.g. T2080, T4240).
2922
2923Thread-Local Storage
2924====================
2925
2926Thread-local storage is supported.
2927
2928Board Support Packages
2929======================
2930
2931System Reset
2932------------
2933
2934An RTEMS based application is initiated or
2935re-initiated when the PowerPC processor is reset.  The PowerPC
2936architecture defines a Reset Exception, but leaves the
2937details of the CPU state as implementation specific.  Please
2938refer to the User’s Manual for the CPU model in question.
2939
2940In general, at power-up the PowerPC begin execution at address
29410xFFF00100 in supervisor mode with all exceptions disabled.  For
2942soft resets, the CPU will vector to either 0xFFF00100 or 0x00000100
2943depending upon the setting of the Exception Prefix bit in the MSR.
2944If during a soft reset, a Machine Check Exception occurs, then the
2945CPU may execute a hard reset.
2946
2947Processor Initialization
2948------------------------
2949
2950If this PowerPC implementation supports on-chip caching
2951and this is to be utilized, then it should be enabled during the
2952reset application initialization code.  On-chip caching has been
2953observed to prevent some emulators from working properly, so it
2954may be necessary to run with caching disabled to use these emulators.
2955
2956In addition to the requirements described in the*Board Support Packages* chapter of the RTEMS C
2957Applications User’s Manual for the reset code
2958which is executed before the call to ``rtems_initialize_executive``,
2959the PowrePC version has the following specific requirements:
2960
2961- Must leave the PR bit of the Machine State Register (MSR) set
2962  to 0 so the PowerPC remains in the supervisor state.
2963
2964- Must set stack pointer (sp or r1) such that a minimum stack
2965  size of MINIMUM_STACK_SIZE bytes is provided for the RTEMS initialization
2966  sequence.
2967
2968- Must disable all external interrupts (i.e. clear the EI (EE)
2969  bit of the machine state register).
2970
2971- Must enable traps so window overflow and underflow
2972  conditions can be properly handled.
2973
2974- Must initialize the PowerPC’s initial Exception Table with default
2975  handlers.
2976
2977.. COMMENT: COPYRIGHT (c) 1988-2002.
2978
2979.. COMMENT: On-Line Applications Research Corporation (OAR).
2980
2981.. COMMENT: All rights reserved.
2982
2983SuperH Specific Information
2984###########################
2985
2986This chapter discusses the SuperH architecture dependencies
2987in this port of RTEMS.  The SuperH family has a wide variety
2988of implementations by a wide range of vendors.  Consequently,
2989there are many, many CPU models within it.
2990
2991**Architecture Documents**
2992
2993For information on the SuperH architecture,
2994refer to the following documents available from VENDOR
2995(:file:`http//www.XXX.com/`):
2996
2997- *SuperH Family Reference, VENDOR, PART NUMBER*.
2998
2999CPU Model Dependent Features
3000============================
3001
3002This chapter presents the set of features which vary
3003across SuperH implementations and are of importance to RTEMS.
3004The set of CPU model feature macros are defined in the file``cpukit/score/cpu/sh/sh.h`` based upon the particular CPU
3005model specified on the compilation command line.
3006
3007Another Optional Feature
3008------------------------
3009
3010The macro XXX
3011
3012Calling Conventions
3013===================
3014
3015Calling Mechanism
3016-----------------
3017
3018All RTEMS directives are invoked using a ``XXX``
3019instruction and return to the user application via the``XXX`` instruction.
3020
3021Register Usage
3022--------------
3023
3024The SH1 has 16 general registers (r0..r15).
3025
3026- r0..r3 used as general volatile registers
3027
3028- r4..r7 used to pass up to 4 arguments to functions, arguments
3029  above 4 are
3030  passed via the stack)
3031
3032- r8..13 caller saved registers (i.e. push them to the stack if you
3033  need them inside of a function)
3034
3035- r14 frame pointer
3036
3037- r15 stack pointer
3038
3039Parameter Passing
3040-----------------
3041
3042XXX
3043
3044Memory Model
3045============
3046
3047Flat Memory Model
3048-----------------
3049
3050The SuperH family supports a flat 32-bit address
3051space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
3052gigabytes).  Each address is represented by a 32-bit value and
3053is byte addressable.  The address may be used to reference a
3054single byte, word (2-bytes), or long word (4 bytes).  Memory
3055accesses within this address space are performed in big endian
3056fashion by the processors in this family.
3057
3058Some of the SuperH family members support virtual memory and
3059segmentation.  RTEMS does not support virtual memory or
3060segmentation on any of the SuperH family members.  It is the
3061responsibility of the BSP to initialize the mapping for
3062a flat memory model.
3063
3064Interrupt Processing
3065====================
3066
3067Although RTEMS hides many of the processor dependent
3068details of interrupt processing, it is important to understand
3069how the RTEMS interrupt manager is mapped onto the processor’s
3070unique architecture. Discussed in this chapter are the MIPS’s
3071interrupt response and control mechanisms as they pertain to
3072RTEMS.
3073
3074Vectoring of an Interrupt Handler
3075---------------------------------
3076
3077Upon receipt of an interrupt the XXX family
3078members with separate interrupt stacks automatically perform the
3079following actions:
3080
3081- TBD
3082
3083A nested interrupt is processed similarly by these
3084CPU models with the exception that only a single ISF is placed
3085on the interrupt stack and the current stack need not be
3086switched.
3087
3088Interrupt Levels
3089----------------
3090
3091TBD
3092
3093Default Fatal Error Processing
3094==============================
3095
3096The default fatal error handler for this architecture disables processor
3097interrupts, places the error code in *XXX*, and executes a ``XXX``
3098instruction to simulate a halt processor instruction.
3099
3100Symmetric Multiprocessing
3101=========================
3102
3103SMP is not supported.
3104
3105Thread-Local Storage
3106====================
3107
3108Thread-local storage is not implemented.
3109
3110Board Support Packages
3111======================
3112
3113System Reset
3114------------
3115
3116An RTEMS based application is initiated or
3117re-initiated when the processor is reset.  When the
3118processor is reset, it performs the following actions:
3119
3120- TBD
3121
3122Processor Initialization
3123------------------------
3124
3125TBD
3126
3127.. COMMENT: COPYRIGHT (c) 1988-2002.
3128
3129.. COMMENT: On-Line Applications Research Corporation (OAR).
3130
3131.. COMMENT: All rights reserved.
3132
3133SPARC Specific Information
3134##########################
3135
3136The Real Time Executive for Multiprocessor Systems
3137(RTEMS) is designed to be portable across multiple processor
3138architectures.  However, the nature of real-time systems makes
3139it essential that the application designer understand certain
3140processor dependent implementation details.  These processor
3141dependencies include calling convention, board support package
3142issues, interrupt processing, exact RTEMS memory requirements,
3143performance data, header files, and the assembly language
3144interface to the executive.
3145
3146This document discusses the SPARC architecture dependencies in this
3147port of RTEMS.  This architectural port is for SPARC Version 7 and
31488. Implementations for SPARC V9 are in the sparc64 target.
3149
3150It is highly recommended that the SPARC RTEMS
3151application developer obtain and become familiar with the
3152documentation for the processor being used as well as the
3153specification for the revision of the SPARC architecture which
3154corresponds to that processor.
3155
3156**SPARC Architecture Documents**
3157
3158For information on the SPARC architecture, refer to
3159the following documents available from SPARC International, Inc.
3160(http://www.sparc.com):
3161
3162- SPARC Standard Version 7.
3163
3164- SPARC Standard Version 8.
3165
3166**ERC32 Specific Information**
3167
3168The European Space Agency’s ERC32 is a three chip
3169computing core implementing a SPARC V7 processor and associated
3170support circuitry for embedded space applications. The integer
3171and floating-point units (90C601E & 90C602E) are based on the
3172Cypress 7C601 and 7C602, with additional error-detection and
3173recovery functions. The memory controller (MEC) implements
3174system support functions such as address decoding, memory
3175interface, DMA interface, UARTs, timers, interrupt control,
3176write-protection, memory reconfiguration and error-detection.
3177The core is designed to work at 25MHz, but using space qualified
3178memories limits the system frequency to around 15 MHz, resulting
3179in a performance of 10 MIPS and 2 MFLOPS.
3180
3181Information on the ERC32 and a number of development
3182support tools, such as the SPARC Instruction Simulator (SIS),
3183are freely available on the Internet.  The following documents
3184and SIS are available via anonymous ftp or pointing your web
3185browser at ftp://ftp.estec.esa.nl/pub/ws/wsd/erc32.
3186
3187- ERC32 System Design Document
3188
3189- MEC Device Specification
3190
3191Additionally, the SPARC RISC User’s Guide from Matra
3192MHS documents the functionality of the integer and floating
3193point units including the instruction set information.  To
3194obtain this document as well as ERC32 components and VHDL models
3195contact:
3196.. code:: c
3197
3198    Matra MHS SA
3199    3 Avenue du Centre, BP 309,
3200    78054 St-Quentin-en-Yvelines,
3201    Cedex, France
3202    VOICE: +31-1-30607087
3203    FAX: +31-1-30640693
3204
3205Amar Guennon (amar.guennon@matramhs.fr) is familiar with the ERC32.
3206
3207.. COMMENT: COPYRIGHT (c) 1988-2002.
3208
3209.. COMMENT: On-Line Applications Research Corporation (OAR).
3210
3211.. COMMENT: All rights reserved.
3212
3213CPU Model Dependent Features
3214============================
3215
3216Microprocessors are generally classified into
3217families with a variety of CPU models or implementations within
3218that family.  Within a processor family, there is a high level
3219of binary compatibility.  This family may be based on either an
3220architectural specification or on maintaining compatibility with
3221a popular processor.  Recent microprocessor families such as the
3222SPARC or PowerPC are based on an architectural specification
3223which is independent or any particular CPU model or
3224implementation.  Older families such as the M68xxx and the iX86
3225evolved as the manufacturer strived to produce higher
3226performance processor models which maintained binary
3227compatibility with older models.
3228
3229RTEMS takes advantage of the similarity of the
3230various models within a CPU family.  Although the models do vary
3231in significant ways, the high level of compatibility makes it
3232possible to share the bulk of the CPU dependent executive code
3233across the entire family.
3234
3235CPU Model Feature Flags
3236-----------------------
3237
3238Each processor family supported by RTEMS has a
3239list of features which vary between CPU models
3240within a family.  For example, the most common model dependent
3241feature regardless of CPU family is the presence or absence of a
3242floating point unit or coprocessor.  When defining the list of
3243features present on a particular CPU model, one simply notes
3244that floating point hardware is or is not present and defines a
3245single constant appropriately.  Conditional compilation is
3246utilized to include the appropriate source code for this CPU
3247model’s feature set.  It is important to note that this means
3248that RTEMS is thus compiled using the appropriate feature set
3249and compilation flags optimal for this CPU model used.  The
3250alternative would be to generate a binary which would execute on
3251all family members using only the features which were always
3252present.
3253
3254This section presents the set of features which vary
3255across SPARC implementations and are of importance to RTEMS.
3256The set of CPU model feature macros are defined in the file
3257cpukit/score/cpu/sparc/sparc.h based upon the particular CPU
3258model defined on the compilation command line.
3259
3260CPU Model Name
3261~~~~~~~~~~~~~~
3262
3263The macro CPU_MODEL_NAME is a string which designates
3264the name of this CPU model.  For example, for the European Space
3265Agency’s ERC32 SPARC model, this macro is set to the string
3266"erc32".
3267
3268Floating Point Unit
3269~~~~~~~~~~~~~~~~~~~
3270
3271The macro SPARC_HAS_FPU is set to 1 to indicate that
3272this CPU model has a hardware floating point unit and 0
3273otherwise.
3274
3275Bitscan Instruction
3276~~~~~~~~~~~~~~~~~~~
3277
3278The macro SPARC_HAS_BITSCAN is set to 1 to indicate
3279that this CPU model has the bitscan instruction.  For example,
3280this instruction is supported by the Fujitsu SPARClite family.
3281
3282Number of Register Windows
3283~~~~~~~~~~~~~~~~~~~~~~~~~~
3284
3285The macro SPARC_NUMBER_OF_REGISTER_WINDOWS is set to
3286indicate the number of register window sets implemented by this
3287CPU model.  The SPARC architecture allows a for a maximum of
3288thirty-two register window sets although most implementations
3289only include eight.
3290
3291Low Power Mode
3292~~~~~~~~~~~~~~
3293
3294The macro SPARC_HAS_LOW_POWER_MODE is set to one to
3295indicate that this CPU model has a low power mode.  If low power
3296is enabled, then there must be CPU model specific implementation
3297of the IDLE task in cpukit/score/cpu/sparc/cpu.c.  The low
3298power mode IDLE task should be of the form:
3299.. code:: c
3300
3301    while ( TRUE ) {
3302    enter low power mode
3303    }
3304
3305The code required to enter low power mode is CPU model specific.
3306
3307CPU Model Implementation Notes
3308------------------------------
3309
3310The ERC32 is a custom SPARC V7 implementation based on the Cypress 601/602
3311chipset.  This CPU has a number of on-board peripherals and was developed by
3312the European Space Agency to target space applications.  RTEMS currently
3313provides support for the following peripherals:
3314
3315- UART Channels A and B
3316
3317- General Purpose Timer
3318
3319- Real Time Clock
3320
3321- Watchdog Timer (so it can be disabled)
3322
3323- Control Register (so powerdown mode can be enabled)
3324
3325- Memory Control Register
3326
3327- Interrupt Control
3328
3329The General Purpose Timer and Real Time Clock Timer provided with the ERC32
3330share the Timer Control Register.  Because the Timer Control Register is write
3331only, we must mirror it in software and insure that writes to one timer do not
3332alter the current settings and status of the other timer.  Routines are
3333provided in erc32.h which promote the view that the two timers are completely
3334independent.  By exclusively using these routines to access the Timer Control
3335Register, the application can view the system as having a General Purpose
3336Timer Control Register and a Real Time Clock Timer Control Register
3337rather than the single shared value.
3338
3339The RTEMS Idle thread take advantage of the low power mode provided by the
3340ERC32.  Low power mode is entered during idle loops and is enabled at
3341initialization time.
3342
3343.. COMMENT: COPYRIGHT (c) 1988-2002.
3344
3345.. COMMENT: On-Line Applications Research Corporation (OAR).
3346
3347.. COMMENT: All rights reserved.
3348
3349Calling Conventions
3350===================
3351
3352Each high-level language compiler generates subroutine entry and exit code
3353based upon a set of rules known as the application binary interface (ABI)
3354calling convention.   These rules address the following issues:
3355
3356- register preservation and usage
3357
3358- parameter passing
3359
3360- call and return mechanism
3361
3362An ABI calling convention is of importance when interfacing to subroutines
3363written in another language either assembly or high-level.  It determines also
3364the set of registers to be saved or restored during a context switch and
3365interrupt processing.
3366
3367The ABI relevant for RTEMS on SPARC is defined by SYSTEM V APPLICATION BINARY
3368INTERFACE, SPARC Processor Supplement, Third Edition.
3369
3370Programming Model
3371-----------------
3372
3373This section discusses the programming model for the
3374SPARC architecture.
3375
3376Non-Floating Point Registers
3377~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3378
3379The SPARC architecture defines thirty-two
3380non-floating point registers directly visible to the programmer.
3381These are divided into four sets:
3382
3383- input registers
3384
3385- local registers
3386
3387- output registers
3388
3389- global registers
3390
3391Each register is referred to by either two or three
3392names in the SPARC reference manuals.  First, the registers are
3393referred to as r0 through r31 or with the alternate notation
3394r[0] through r[31].  Second, each register is a member of one of
3395the four sets listed above.  Finally, some registers have an
3396architecturally defined role in the programming model which
3397provides an alternate name.  The following table describes the
3398mapping between the 32 registers and the register sets:
3399.. code:: c
3400
3401    +-----------------+----------------+------------------+
3402    | Register Number | Register Names |   Description    |
3403    +-----------------+----------------+------------------+
3404    |     0 - 7       |    g0 - g7     | Global Registers |
3405    +-----------------+----------------+------------------+
3406    |     8 - 15      |    o0 - o7     | Output Registers |
3407    +-----------------+----------------+------------------+
3408    |    16 - 23      |    l0 - l7     | Local Registers  |
3409    +-----------------+----------------+------------------+
3410    |    24 - 31      |    i0 - i7     | Input Registers  |
3411    +-----------------+----------------+------------------+
3412
3413As mentioned above, some of the registers serve
3414defined roles in the programming model.  The following table
3415describes the role of each of these registers:
3416.. code:: c
3417
3418    +---------------+----------------+----------------------+
3419    | Register Name | Alternate Name |      Description     |
3420    +---------------+----------------+----------------------+
3421    |     g0        |      na        |    reads return 0    |
3422    |               |                |  writes are ignored  |
3423    +---------------+----------------+----------------------+
3424    |     o6        |      sp        |     stack pointer    |
3425    +---------------+----------------+----------------------+
3426    |     i6        |      fp        |     frame pointer    |
3427    +---------------+----------------+----------------------+
3428    |     i7        |      na        |    return address    |
3429    +---------------+----------------+----------------------+
3430
3431The registers g2 through g4 are reserved for applications.  GCC uses them as
3432volatile registers by default.  So they are treated like volatile registers in
3433RTEMS as well.
3434
3435The register g6 is reserved for the operating system and contains the address
3436of the per-CPU control block of the current processor.  This register is
3437initialized during system start and then remains unchanged.  It is not
3438saved/restored by the context switch or interrupt processing code.
3439
3440The register g7 is reserved for the operating system and contains the thread
3441pointer used for thread-local storage (TLS) as mandated by the SPARC ABI.
3442
3443Floating Point Registers
3444~~~~~~~~~~~~~~~~~~~~~~~~
3445
3446The SPARC V7 architecture includes thirty-two,
3447thirty-two bit registers.  These registers may be viewed as
3448follows:
3449
3450- 32 single precision floating point or integer registers
3451  (f0, f1,  ... f31)
3452
3453- 16 double precision floating point registers (f0, f2,
3454  f4, ... f30)
3455
3456- 8 extended precision floating point registers (f0, f4,
3457  f8, ... f28)
3458
3459The floating point status register (FSR) specifies
3460the behavior of the floating point unit for rounding, contains
3461its condition codes, version specification, and trap information.
3462
3463According to the ABI all floating point registers and the floating point status
3464register (FSR) are volatile.  Thus the floating point context of a thread is the
3465empty set.  The rounding direction is a system global state and must not be
3466modified by threads.
3467
3468A queue of the floating point instructions which have
3469started execution but not yet completed is maintained.  This
3470queue is needed to support the multiple cycle nature of floating
3471point operations and to aid floating point exception trap
3472handlers.  Once a floating point exception has been encountered,
3473the queue is frozen until it is emptied by the trap handler.
3474The floating point queue is loaded by launching instructions.
3475It is emptied normally when the floating point completes all
3476outstanding instructions and by floating point exception
3477handlers with the store double floating point queue (stdfq)
3478instruction.
3479
3480Special Registers
3481~~~~~~~~~~~~~~~~~
3482
3483The SPARC architecture includes two special registers
3484which are critical to the programming model: the Processor State
3485Register (psr) and the Window Invalid Mask (wim).  The psr
3486contains the condition codes, processor interrupt level, trap
3487enable bit, supervisor mode and previous supervisor mode bits,
3488version information, floating point unit and coprocessor enable
3489bits, and the current window pointer (cwp).  The cwp field of
3490the psr and wim register are used to manage the register windows
3491in the SPARC architecture.  The register windows are discussed
3492in more detail below.
3493
3494Register Windows
3495----------------
3496
3497The SPARC architecture includes the concept of
3498register windows.  An overly simplistic way to think of these
3499windows is to imagine them as being an infinite supply of
3500"fresh" register sets available for each subroutine to use.  In
3501reality, they are much more complicated.
3502
3503The save instruction is used to obtain a new register
3504window.  This instruction decrements the current window pointer,
3505thus providing a new set of registers for use.  This register
3506set includes eight fresh local registers for use exclusively by
3507this subroutine.  When done with a register set, the restore
3508instruction increments the current window pointer and the
3509previous register set is once again available.
3510
3511The two primary issues complicating the use of
3512register windows are that (1) the set of register windows is
3513finite, and (2) some registers are shared between adjacent
3514registers windows.
3515
3516Because the set of register windows is finite, it is
3517possible to execute enough save instructions without
3518corresponding restore’s to consume all of the register windows.
3519This is easily accomplished in a high level language because
3520each subroutine typically performs a save instruction upon
3521entry.  Thus having a subroutine call depth greater than the
3522number of register windows will result in a window overflow
3523condition.  The window overflow condition generates a trap which
3524must be handled in software.  The window overflow trap handler
3525is responsible for saving the contents of the oldest register
3526window on the program stack.
3527
3528Similarly, the subroutines will eventually complete
3529and begin to perform restore’s.  If the restore results in the
3530need for a register window which has previously been written to
3531memory as part of an overflow, then a window underflow condition
3532results.  Just like the window overflow, the window underflow
3533condition must be handled in software by a trap handler.  The
3534window underflow trap handler is responsible for reloading the
3535contents of the register window requested by the restore
3536instruction from the program stack.
3537
3538The Window Invalid Mask (wim) and the Current Window
3539Pointer (cwp) field in the psr are used in conjunction to manage
3540the finite set of register windows and detect the window
3541overflow and underflow conditions.  The cwp contains the index
3542of the register window currently in use.  The save instruction
3543decrements the cwp modulo the number of register windows.
3544Similarly, the restore instruction increments the cwp modulo the
3545number of register windows.  Each bit in the  wim represents
3546represents whether a register window contains valid information.
3547The value of 0 indicates the register window is valid and 1
3548indicates it is invalid.  When a save instruction causes the cwp
3549to point to a register window which is marked as invalid, a
3550window overflow condition results.  Conversely, the restore
3551instruction may result in a window underflow condition.
3552
3553Other than the assumption that a register window is
3554always available for trap (i.e. interrupt) handlers, the SPARC
3555architecture places no limits on the number of register windows
3556simultaneously marked as invalid (i.e. number of bits set in the
3557wim).  However, RTEMS assumes that only one register window is
3558marked invalid at a time (i.e. only one bit set in the wim).
3559This makes the maximum possible number of register windows
3560available to the user while still meeting the requirement that
3561window overflow and underflow conditions can be detected.
3562
3563The window overflow and window underflow trap
3564handlers are a critical part of the run-time environment for a
3565SPARC application.  The SPARC architectural specification allows
3566for the number of register windows to be any power of two less
3567than or equal to 32.  The most common choice for SPARC
3568implementations appears to be 8 register windows.  This results
3569in the cwp ranging in value from 0 to 7 on most implementations.
3570
3571The second complicating factor is the sharing of
3572registers between adjacent register windows.  While each
3573register window has its own set of local registers, the input
3574and output registers are shared between adjacent windows.  The
3575output registers for register window N are the same as the input
3576registers for register window ((N - 1) modulo RW) where RW is
3577the number of register windows.  An alternative way to think of
3578this is to remember how parameters are passed to a subroutine on
3579the SPARC.  The caller loads values into what are its output
3580registers.  Then after the callee executes a save instruction,
3581those parameters are available in its input registers.  This is
3582a very efficient way to pass parameters as no data is actually
3583moved by the save or restore instructions.
3584
3585Call and Return Mechanism
3586-------------------------
3587
3588The SPARC architecture supports a simple yet
3589effective call and return mechanism.  A subroutine is invoked
3590via the call (call) instruction.  This instruction places the
3591return address in the caller’s output register 7 (o7).  After
3592the callee executes a save instruction, this value is available
3593in input register 7 (i7) until the corresponding restore
3594instruction is executed.
3595
3596The callee returns to the caller via a jmp to the
3597return address.  There is a delay slot following this
3598instruction which is commonly used to execute a restore
3599instruction – if a register window was allocated by this
3600subroutine.
3601
3602It is important to note that the SPARC subroutine
3603call and return mechanism does not automatically save and
3604restore any registers.  This is accomplished via the save and
3605restore instructions which manage the set of registers windows.
3606
3607In case a floating-point unit is supported, then floating-point return values
3608appear in the floating-point registers.  Single-precision values occupy %f0;
3609double-precision values occupy %f0 and %f1.  Otherwise, these are scratch
3610registers.  Due to this the hardware and software floating-point ABIs are
3611incompatible.
3612
3613Calling Mechanism
3614-----------------
3615
3616All RTEMS directives are invoked using the regular
3617SPARC calling convention via the call instruction.
3618
3619Register Usage
3620--------------
3621
3622As discussed above, the call instruction does not
3623automatically save any registers.  The save and restore
3624instructions are used to allocate and deallocate register
3625windows.  When a register window is allocated, the new set of
3626local registers are available for the exclusive use of the
3627subroutine which allocated this register set.
3628
3629Parameter Passing
3630-----------------
3631
3632RTEMS assumes that arguments are placed in the
3633caller’s output registers with the first argument in output
3634register 0 (o0), the second argument in output register 1 (o1),
3635and so forth.  Until the callee executes a save instruction, the
3636parameters are still visible in the output registers.  After the
3637callee executes a save instruction, the parameters are visible
3638in the corresponding input registers.  The following pseudo-code
3639illustrates the typical sequence used to call a RTEMS directive
3640with three (3) arguments:
3641.. code:: c
3642
3643    load third argument into o2
3644    load second argument into o1
3645    load first argument into o0
3646    invoke directive
3647
3648User-Provided Routines
3649----------------------
3650
3651All user-provided routines invoked by RTEMS, such as
3652user extensions, device drivers, and MPCI routines, must also
3653adhere to these calling conventions.
3654
3655.. COMMENT: COPYRIGHT (c) 1988-2002.
3656
3657.. COMMENT: On-Line Applications Research Corporation (OAR).
3658
3659.. COMMENT: All rights reserved.
3660
3661Memory Model
3662============
3663
3664A processor may support any combination of memory
3665models ranging from pure physical addressing to complex demand
3666paged virtual memory systems.  RTEMS supports a flat memory
3667model which ranges contiguously over the processor’s allowable
3668address space.  RTEMS does not support segmentation or virtual
3669memory of any kind.  The appropriate memory model for RTEMS
3670provided by the targeted processor and related characteristics
3671of that model are described in this chapter.
3672
3673Flat Memory Model
3674-----------------
3675
3676The SPARC architecture supports a flat 32-bit address
3677space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
3678gigabytes).  Each address is represented by a 32-bit value and
3679is byte addressable.  The address may be used to reference a
3680single byte, half-word (2-bytes), word (4 bytes), or doubleword
3681(8 bytes).  Memory accesses within this address space are
3682performed in big endian fashion by the SPARC.  Memory accesses
3683which are not properly aligned generate a "memory address not
3684aligned" trap (type number 7).  The following table lists the
3685alignment requirements for a variety of data accesses:
3686.. code:: c
3687
3688    +--------------+-----------------------+
3689    |   Data Type  | Alignment Requirement |
3690    +--------------+-----------------------+
3691    |     byte     |          1            |
3692    |   half-word  |          2            |
3693    |     word     |          4            |
3694    |  doubleword  |          8            |
3695    +--------------+-----------------------+
3696
3697Doubleword load and store operations must use a pair
3698of registers as their source or destination.  This pair of
3699registers must be an adjacent pair of registers with the first
3700of the pair being even numbered.  For example, a valid
3701destination for a doubleword load might be input registers 0 and
37021 (i0 and i1).  The pair i1 and i2 would be invalid.  \[NOTE:
3703Some assemblers for the SPARC do not generate an error if an odd
3704numbered register is specified as the beginning register of the
3705pair.  In this case, the assembler assumes that what the
3706programmer meant was to use the even-odd pair which ends at the
3707specified register.  This may or may not have been a correct
3708assumption.]
3709
3710RTEMS does not support any SPARC Memory Management
3711Units, therefore, virtual memory or segmentation systems
3712involving the SPARC are not supported.
3713
3714.. COMMENT: COPYRIGHT (c) 1988-2002.
3715
3716.. COMMENT: On-Line Applications Research Corporation (OAR).
3717
3718.. COMMENT: All rights reserved.
3719
3720Interrupt Processing
3721====================
3722
3723Different types of processors respond to the
3724occurrence of an interrupt in its own unique fashion. In
3725addition, each processor type provides a control mechanism to
3726allow for the proper handling of an interrupt.  The processor
3727dependent response to the interrupt modifies the current
3728execution state and results in a change in the execution stream.
3729Most processors require that an interrupt handler utilize some
3730special control mechanisms to return to the normal processing
3731stream.  Although RTEMS hides many of the processor dependent
3732details of interrupt processing, it is important to understand
3733how the RTEMS interrupt manager is mapped onto the processor’s
3734unique architecture. Discussed in this chapter are the SPARC’s
3735interrupt response and control mechanisms as they pertain to
3736RTEMS.
3737
3738RTEMS and associated documentation uses the terms
3739interrupt and vector.  In the SPARC architecture, these terms
3740correspond to traps and trap type, respectively.  The terms will
3741be used interchangeably in this manual.
3742
3743Synchronous Versus Asynchronous Traps
3744-------------------------------------
3745
3746The SPARC architecture includes two classes of traps:
3747synchronous and asynchronous.  Asynchronous traps occur when an
3748external event interrupts the processor.  These traps are not
3749associated with any instruction executed by the processor and
3750logically occur between instructions.  The instruction currently
3751in the execute stage of the processor is allowed to complete
3752although subsequent instructions are annulled.  The return
3753address reported by the processor for asynchronous traps is the
3754pair of instructions following the current instruction.
3755
3756Synchronous traps are caused by the actions of an
3757instruction.  The trap stimulus in this case either occurs
3758internally to the processor or is from an external signal that
3759was provoked by the instruction.  These traps are taken
3760immediately and the instruction that caused the trap is aborted
3761before any state changes occur in the processor itself.   The
3762return address reported by the processor for synchronous traps
3763is the instruction which caused the trap and the following
3764instruction.
3765
3766Vectoring of Interrupt Handler
3767------------------------------
3768
3769Upon receipt of an interrupt the SPARC automatically
3770performs the following actions:
3771
3772- disables traps (sets the ET bit of the psr to 0),
3773
3774- the S bit of the psr is copied into the Previous
3775  Supervisor Mode (PS) bit of the psr,
3776
3777- the cwp is decremented by one (modulo the number of
3778  register windows) to activate a trap window,
3779
3780- the PC and nPC are loaded into local register 1 and 2
3781  (l0 and l1),
3782
3783- the trap type (tt) field of the Trap Base Register (TBR)
3784  is set to the appropriate value, and
3785
3786- if the trap is not a reset, then the PC is written with
3787  the contents of the TBR and the nPC is written with TBR + 4.  If
3788  the trap is a reset, then the PC is set to zero and the nPC is
3789  set to 4.
3790
3791Trap processing on the SPARC has two features which
3792are noticeably different than interrupt processing on other
3793architectures.  First, the value of psr register in effect
3794immediately before the trap occurred is not explicitly saved.
3795Instead only reversible alterations are made to it.  Second, the
3796Processor Interrupt Level (pil) is not set to correspond to that
3797of the interrupt being processed.  When a trap occurs, ALL
3798subsequent traps are disabled.  In order to safely invoke a
3799subroutine during trap handling, traps must be enabled to allow
3800for the possibility of register window overflow and underflow
3801traps.
3802
3803If the interrupt handler was installed as an RTEMS
3804interrupt handler, then upon receipt of the interrupt, the
3805processor passes control to the RTEMS interrupt handler which
3806performs the following actions:
3807
3808- saves the state of the interrupted task on it’s stack,
3809
3810- insures that a register window is available for
3811  subsequent traps,
3812
3813- if this is the outermost (i.e. non-nested) interrupt,
3814  then the RTEMS interrupt handler switches from the current stack
3815  to the interrupt stack,
3816
3817- enables traps,
3818
3819- invokes the vectors to a user interrupt service routine (ISR).
3820
3821Asynchronous interrupts are ignored while traps are
3822disabled.  Synchronous traps which occur while traps are
3823disabled result in the CPU being forced into an error mode.
3824
3825A nested interrupt is processed similarly with the
3826exception that the current stack need not be switched to the
3827interrupt stack.
3828
3829Traps and Register Windows
3830--------------------------
3831
3832One of the register windows must be reserved at all
3833times for trap processing.  This is critical to the proper
3834operation of the trap mechanism in the SPARC architecture.  It
3835is the responsibility of the trap handler to insure that there
3836is a register window available for a subsequent trap before
3837re-enabling traps.  It is likely that any high level language
3838routines invoked by the trap handler (such as a user-provided
3839RTEMS interrupt handler) will allocate a new register window.
3840The save operation could result in a window overflow trap.  This
3841trap cannot be correctly processed unless (1) traps are enabled
3842and (2) a register window is reserved for traps.  Thus, the
3843RTEMS interrupt handler insures that a register window is
3844available for subsequent traps before enabling traps and
3845invoking the user’s interrupt handler.
3846
3847Interrupt Levels
3848----------------
3849
3850Sixteen levels (0-15) of interrupt priorities are
3851supported by the SPARC architecture with level fifteen (15)
3852being the highest priority.  Level zero (0) indicates that
3853interrupts are fully enabled.  Interrupt requests for interrupts
3854with priorities less than or equal to the current interrupt mask
3855level are ignored. Level fifteen (15) is a non-maskable interrupt
3856(NMI), which makes it unsuitable for standard usage since it can
3857affect the real-time behaviour by interrupting critical sections
3858and spinlocks. Disabling traps stops also the NMI interrupt from
3859happening. It can however be used for power-down or other
3860critical events.
3861
3862Although RTEMS supports 256 interrupt levels, the
3863SPARC only supports sixteen.  RTEMS interrupt levels 0 through
386415 directly correspond to SPARC processor interrupt levels.  All
3865other RTEMS interrupt levels are undefined and their behavior is
3866unpredictable.
3867
3868Many LEON SPARC v7/v8 systems features an extended interrupt controller
3869which adds an extra step of interrupt decoding to allow handling of
3870interrupt 16-31. When such an extended interrupt is generated the CPU
3871traps into a specific interrupt trap level 1-14 and software reads out from
3872the interrupt controller which extended interrupt source actually caused the
3873interrupt.
3874
3875Disabling of Interrupts by RTEMS
3876--------------------------------
3877
3878During the execution of directive calls, critical
3879sections of code may be executed.  When these sections are
3880encountered, RTEMS disables interrupts to level fifteen (15)
3881before the execution of the section and restores them to the
3882previous level upon completion of the section.  RTEMS has been
3883optimized to ensure that interrupts are disabled for less than
3884RTEMS_MAXIMUM_DISABLE_PERIOD microseconds on a RTEMS_MAXIMUM_DISABLE_PERIOD_MHZ
3885Mhz ERC32 with zero wait states.
3886These numbers will vary based the number of wait states and
3887processor speed present on the target board.
3888\[NOTE:  The maximum period with interrupts disabled is hand calculated.  This
3889calculation was last performed for Release
3890RTEMS_RELEASE_FOR_MAXIMUM_DISABLE_PERIOD.]
3891
3892[NOTE: It is thought that the length of time at which
3893the processor interrupt level is elevated to fifteen by RTEMS is
3894not anywhere near as long as the length of time ALL traps are
3895disabled as part of the "flush all register windows" operation.]
3896
3897Non-maskable interrupts (NMI) cannot be disabled, and
3898ISRs which execute at this level MUST NEVER issue RTEMS system
3899calls.  If a directive is invoked, unpredictable results may
3900occur due to the inability of RTEMS to protect its critical
3901sections.  However, ISRs that make no system calls may safely
3902execute as non-maskable interrupts.
3903
3904Interrupts are disabled or enabled by performing a system call
3905to the Operating System reserved software traps 9
3906(SPARC_SWTRAP_IRQDIS) or 10 (SPARC_SWTRAP_IRQDIS). The trap is
3907generated by the software trap (Ticc) instruction or indirectly
3908by calling sparc_disable_interrupts() or sparc_enable_interrupts()
3909functions. Disabling interrupts return the previous interrupt level
3910(on trap entry) in register G1 and sets PSR.PIL to 15 to disable
3911all maskable interrupts. The interrupt level can be restored by
3912trapping into the enable interrupt handler with G1 containing the
3913new interrupt level.
3914
3915Interrupt Stack
3916---------------
3917
3918The SPARC architecture does not provide for a
3919dedicated interrupt stack.  Thus by default, trap handlers would
3920execute on the stack of the RTEMS task which they interrupted.
3921This artificially inflates the stack requirements for each task
3922since EVERY task stack would have to include enough space to
3923account for the worst case interrupt stack requirements in
3924addition to it’s own worst case usage.  RTEMS addresses this
3925problem on the SPARC by providing a dedicated interrupt stack
3926managed by software.
3927
3928During system initialization, RTEMS allocates the
3929interrupt stack from the Workspace Area.  The amount of memory
3930allocated for the interrupt stack is determined by the
3931interrupt_stack_size field in the CPU Configuration Table.  As
3932part of processing a non-nested interrupt, RTEMS will switch to
3933the interrupt stack before invoking the installed handler.
3934
3935.. COMMENT: COPYRIGHT (c) 1988-2002.
3936
3937.. COMMENT: On-Line Applications Research Corporation (OAR).
3938
3939.. COMMENT: All rights reserved.
3940
3941Default Fatal Error Processing
3942==============================
3943
3944Upon detection of a fatal error by either the
3945application or RTEMS the fatal error manager is invoked.  The
3946fatal error manager will invoke the user-supplied fatal error
3947handlers.  If no user-supplied handlers are configured,  the
3948RTEMS provided default fatal error handler is invoked.  If the
3949user-supplied fatal error handlers return to the executive the
3950default fatal error handler is then invoked.  This chapter
3951describes the precise operations of the default fatal error
3952handler.
3953
3954Default Fatal Error Handler Operations
3955--------------------------------------
3956
3957The default fatal error handler which is invoked by
3958the fatal_error_occurred directive when there is no user handler
3959configured or the user handler returns control to RTEMS.
3960
3961If the BSP has been configured with ``BSP_POWER_DOWN_AT_FATAL_HALT``
3962set to true, the default handler will disable interrupts
3963and enter power down mode. If power down mode is not available,
3964it goes into an infinite loop to simulate a halt processor instruction.
3965
3966If ``BSP_POWER_DOWN_AT_FATAL_HALT`` is set to false, the default
3967handler will place the value ``1`` in register ``g1``, the
3968error source in register ``g2``, and the error code in register``g3``. It will then generate a system error which will
3969hand over control to the debugger, simulator, etc.
3970
3971Symmetric Multiprocessing
3972=========================
3973
3974SMP is supported.  Available platforms are the Cobham Gaisler GR712RC and
3975GR740.
3976
3977Thread-Local Storage
3978====================
3979
3980Thread-local storage is supported.
3981
3982.. COMMENT: COPYRIGHT (c) 1988-2002.
3983
3984.. COMMENT: On-Line Applications Research Corporation (OAR).
3985
3986.. COMMENT: All rights reserved.
3987
3988Board Support Packages
3989======================
3990
3991An RTEMS Board Support Package (BSP) must be designed
3992to support a particular processor and target board combination.
3993This chapter presents a discussion of SPARC specific BSP issues.
3994For more information on developing a BSP, refer to the chapter
3995titled Board Support Packages in the RTEMS
3996Applications User’s Guide.
3997
3998System Reset
3999------------
4000
4001An RTEMS based application is initiated or
4002re-initiated when the SPARC processor is reset.  When the SPARC
4003is reset, the processor performs the following actions:
4004
4005- the enable trap (ET) of the psr is set to 0 to disable
4006  traps,
4007
4008- the supervisor bit (S) of the psr is set to 1 to enter
4009  supervisor mode, and
4010
4011- the PC is set 0 and the nPC is set to 4.
4012
4013The processor then begins to execute the code at
4014location 0.  It is important to note that all fields in the psr
4015are not explicitly set by the above steps and all other
4016registers retain their value from the previous execution mode.
4017This is true even of the Trap Base Register (TBR) whose contents
4018reflect the last trap which occurred before the reset.
4019
4020Processor Initialization
4021------------------------
4022
4023It is the responsibility of the application’s
4024initialization code to initialize the TBR and install trap
4025handlers for at least the register window overflow and register
4026window underflow conditions.  Traps should be enabled before
4027invoking any subroutines to allow for register window
4028management.  However, interrupts should be disabled by setting
4029the Processor Interrupt Level (pil) field of the psr to 15.
4030RTEMS installs it’s own Trap Table as part of initialization
4031which is initialized with the contents of the Trap Table in
4032place when the ``rtems_initialize_executive`` directive was invoked.
4033Upon completion of executive initialization, interrupts are
4034enabled.
4035
4036If this SPARC implementation supports on-chip caching
4037and this is to be utilized, then it should be enabled during the
4038reset application initialization code.
4039
4040In addition to the requirements described in the
4041Board Support Packages chapter of the C
4042Applications Users Manual for the reset code
4043which is executed before the call to``rtems_initialize_executive``, the SPARC version has the following
4044specific requirements:
4045
4046- Must leave the S bit of the status register set so that
4047  the SPARC remains in the supervisor state.
4048
4049- Must set stack pointer (sp) such that a minimum stack
4050  size of MINIMUM_STACK_SIZE bytes is provided for the``rtems_initialize_executive`` directive.
4051
4052- Must disable all external interrupts (i.e. set the pil
4053  to 15).
4054
4055- Must enable traps so window overflow and underflow
4056  conditions can be properly handled.
4057
4058- Must initialize the SPARC’s initial trap table with at
4059  least trap handlers for register window overflow and register
4060  window underflow.
4061
4062.. COMMENT: COPYRIGHT (c) 1988-2002.
4063
4064.. COMMENT: On-Line Applications Research Corporation (OAR).
4065
4066.. COMMENT: All rights reserved.
4067
4068SPARC-64 Specific Information
4069#############################
4070
4071This document discusses the SPARC Version 9 (aka SPARC-64, SPARC64 or SPARC V9)
4072architecture dependencies in this port of RTEMS.
4073
4074The SPARC V9 architecture leaves a lot of undefined implemenation dependencies
4075which are defined by the processor models. Consult the specific CPU model
4076section in this document for additional documents covering the implementation
4077dependent architectural features.
4078
4079**sun4u Specific Information**
4080
4081sun4u is the subset of the SPARC V9 implementations comprising the UltraSPARC I
4082through UltraSPARC IV processors.
4083
4084The following documents were used in developing the SPARC-64 sun4u port:
4085
4086- UltraSPARC  User’s Manual
4087  (http://www.sun.com/microelectronics/manuals/ultrasparc/802-7220-02.pdf)
4088
4089- UltraSPARC IIIi Processor (datasheets.chipdb.org/Sun/UltraSparc-IIIi.pdf)
4090
4091**sun4v Specific Information**
4092
4093sun4v is the subset of the SPARC V9 implementations comprising the
4094UltraSPARC T1 or T2 processors.
4095
4096The following documents were used in developing the SPARC-64 sun4v port:
4097
4098- UltraSPARC Architecture 2005 Specification
4099  (http://opensparc-t1.sunsource.net/specs/UA2005-current-draft-P-EXT.pdf)
4100
4101- UltraSPARC T1 supplement to UltraSPARC Architecture 2005 Specification
4102  (http://opensparc-t1.sunsource.net/specs/UST1-UASuppl-current-draft-P-EXT.pdf)
4103
4104The defining feature that separates the sun4v architecture from its
4105predecessor is the existence of a super-privileged hypervisor that
4106is responsible for providing virtualized execution environments.  The impact
4107of the hypervisor on the real-time guarantees available with sun4v has not
4108yet been determined.
4109
4110CPU Model Dependent Features
4111============================
4112
4113CPU Model Feature Flags
4114-----------------------
4115
4116This section presents the set of features which vary across
4117SPARC-64 implementations and
4118are of importance to RTEMS. The set of CPU model feature macros
4119are defined in the file
4120cpukit/score/cpu/sparc64/sparc64.h based upon the particular
4121CPU model defined on the compilation command line.
4122
4123CPU Model Name
4124~~~~~~~~~~~~~~
4125
4126The macro CPU MODEL NAME is a string which designates
4127the name of this CPU model.
4128For example, for the UltraSPARC T1 SPARC V9 model,
4129this macro is set to the string "sun4v".
4130
4131Floating Point Unit
4132~~~~~~~~~~~~~~~~~~~
4133
4134The macro SPARC_HAS_FPU is set to 1 to indicate that
4135this CPU model has a hardware floating point unit and 0
4136otherwise.
4137
4138Number of Register Windows
4139~~~~~~~~~~~~~~~~~~~~~~~~~~
4140
4141The macro SPARC_NUMBER_OF_REGISTER_WINDOWS is set to
4142indicate the number of register window sets implemented by this
4143CPU model.  The SPARC architecture allows for a maximum of
4144thirty-two register window sets although most implementations
4145only include eight.
4146
4147CPU Model Implementation Notes
4148------------------------------
4149
4150This section describes the implemenation dependencies of the
4151CPU Models sun4u and sun4v of the SPARC V9 architecture.
4152
4153sun4u Notes
4154~~~~~~~~~~~
4155
4156XXX
4157
4158sun4v Notes
4159-----------
4160
4161XXX
4162
4163.. COMMENT: COPYRIGHT (c) 1988-2002.
4164
4165.. COMMENT: On-Line Applications Research Corporation (OAR).
4166
4167.. COMMENT: All rights reserved.
4168
4169Calling Conventions
4170===================
4171
4172Each high-level language compiler generates
4173subroutine entry and exit code based upon a set of rules known
4174as the compiler’s calling convention.   These rules address the
4175following issues:
4176
4177- register preservation and usage
4178
4179- parameter passing
4180
4181- call and return mechanism
4182
4183A compiler’s calling convention is of importance when
4184interfacing to subroutines written in another language either
4185assembly or high-level.  Even when the high-level language and
4186target processor are the same, different compilers may use
4187different calling conventions.  As a result, calling conventions
4188are both processor and compiler dependent.
4189
4190The following document also provides some conventions on the
4191global register usage in SPARC V9:
4192http://developers.sun.com/solaris/articles/sparcv9abi.html
4193
4194Programming Model
4195-----------------
4196
4197This section discusses the programming model for the
4198SPARC architecture.
4199
4200Non-Floating Point Registers
4201~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4202
4203The SPARC architecture defines thirty-two
4204non-floating point registers directly visible to the programmer.
4205These are divided into four sets:
4206
4207- input registers
4208
4209- local registers
4210
4211- output registers
4212
4213- global registers
4214
4215Each register is referred to by either two or three
4216names in the SPARC reference manuals.  First, the registers are
4217referred to as r0 through r31 or with the alternate notation
4218r[0] through r[31].  Second, each register is a member of one of
4219the four sets listed above.  Finally, some registers have an
4220architecturally defined role in the programming model which
4221provides an alternate name.  The following table describes the
4222mapping between the 32 registers and the register sets:
4223.. code:: c
4224
4225    +-----------------+----------------+------------------+
4226    | Register Number | Register Names |   Description    |
4227    +-----------------+----------------+------------------+
4228    |     0 - 7       |    g0 - g7     | Global Registers |
4229    +-----------------+----------------+------------------+
4230    |     8 - 15      |    o0 - o7     | Output Registers |
4231    +-----------------+----------------+------------------+
4232    |    16 - 23      |    l0 - l7     | Local Registers  |
4233    +-----------------+----------------+------------------+
4234    |    24 - 31      |    i0 - i7     | Input Registers  |
4235    +-----------------+----------------+------------------+
4236
4237As mentioned above, some of the registers serve
4238defined roles in the programming model.  The following table
4239describes the role of each of these registers:
4240.. code:: c
4241
4242    +---------------+----------------+----------------------+
4243    | Register Name | Alternate Name |      Description     |
4244    +---------------+----------------+----------------------+
4245    |     g0        |      na        |    reads return 0    |
4246    |               |                |  writes are ignored  |
4247    +---------------+----------------+----------------------+
4248    |     o6        |      sp        |     stack pointer    |
4249    +---------------+----------------+----------------------+
4250    |     i6        |      fp        |     frame pointer    |
4251    +---------------+----------------+----------------------+
4252    |     i7        |      na        |    return address    |
4253    +---------------+----------------+----------------------+
4254
4255Floating Point Registers
4256~~~~~~~~~~~~~~~~~~~~~~~~
4257
4258The SPARC V9 architecture includes sixty-four,
4259thirty-two bit registers.  These registers may be viewed as
4260follows:
4261
4262- 32 32-bit single precision floating point or integer registers
4263  (f0, f1,  ... f31)
4264
4265- 32 64-bit double precision floating point registers (f0, f2,
4266  f4, ... f62)
4267
4268- 16 128-bit extended precision floating point registers (f0, f4,
4269  f8, ... f60)
4270
4271The floating point state register (fsr) specifies
4272the behavior of the floating point unit for rounding, contains
4273its condition codes, version specification, and trap information.
4274
4275Special Registers
4276~~~~~~~~~~~~~~~~~
4277
4278The SPARC architecture includes a number of special registers:
4279
4280*``Ancillary State Registers (ASRs)``*
4281    The ancillary state registers (ASRs) are optional state registers that
4282    may be privileged or nonprivileged. ASRs 16-31 are implementation-
4283    dependent. The SPARC V9 ASRs include: y, ccr, asi, tick, pc, fprs.
4284    The sun4u ASRs include: pcr, pic, dcr, gsr, softint set, softint clr,
4285    softint, and tick cmpr. The sun4v ASRs include: pcr, pic, gsr, soft-
4286    int set, softint clr, softint, tick cmpr, stick, and stick cmpr.
4287
4288*``Processor State Register (pstate)``*
4289    The privileged pstate register contains control fields for the proces-
4290    sor’s current state. Its flag fields include the interrupt enable, privi-
4291    leged mode, and enable FPU.
4292
4293*``Processor Interrupt Level (pil)``*
4294    The PIL specifies the interrupt level above which interrupts will be
4295    accepted.
4296
4297*``Trap Registers``*
4298    The trap handling mechanism of the SPARC V9 includes a number of
4299    registers, including: trap program counter (tpc), trap next pc (tnpc),
4300    trap state (tstate), trap type (tt), trap base address (tba), and trap
4301    level (tl).
4302
4303*``Alternate Globals``*
4304    The AG bit of the pstate register provides access to an alternate set
4305    of global registers. On sun4v, the AG bit is replaced by the global
4306    level (gl) register, providing access to at least two and at most eight
4307    alternate sets of globals.
4308
4309*``Register Window registers``*
4310    A number of registers assist in register window management.
4311    These include the current window pointer (cwp), savable windows
4312    (cansave), restorable windows (canrestore), clean windows (clean-
4313    win), other windows (otherwin), and window state (wstate).
4314
4315Register Windows
4316----------------
4317
4318The SPARC architecture includes the concept of
4319register windows.  An overly simplistic way to think of these
4320windows is to imagine them as being an infinite supply of
4321"fresh" register sets available for each subroutine to use.  In
4322reality, they are much more complicated.
4323
4324The save instruction is used to obtain a new register window.
4325This instruction increments the current window pointer, thus
4326providing a new set of registers for use. This register set
4327includes eight fresh local registers for use exclusively by
4328this subroutine. When done with a register set, the restore
4329instruction decrements the current window pointer and the
4330previous register set is once again available.
4331
4332The two primary issues complicating the use of register windows
4333are that (1) the set of register windows is finite, and (2) some
4334registers are shared between adjacent registers windows.
4335
4336Because the set of register windows is finite, it is
4337possible to execute enough save instructions without
4338corresponding restore’s to consume all of the register windows.
4339This is easily accomplished in a high level language because
4340each subroutine typically performs a save instruction upon
4341entry.  Thus having a subroutine call depth greater than the
4342number of register windows will result in a window overflow
4343condition.  The window overflow condition generates a trap which
4344must be handled in software.  The window overflow trap handler
4345is responsible for saving the contents of the oldest register
4346window on the program stack.
4347
4348Similarly, the subroutines will eventually complete
4349and begin to perform restore’s.  If the restore results in the
4350need for a register window which has previously been written to
4351memory as part of an overflow, then a window underflow condition
4352results.  Just like the window overflow, the window underflow
4353condition must be handled in software by a trap handler.  The
4354window underflow trap handler is responsible for reloading the
4355contents of the register window requested by the restore
4356instruction from the program stack.
4357
4358The cansave, canrestore, otherwin, and cwp are used in conjunction
4359to manage the finite set of register windows and detect the window
4360overflow and underflow conditions. The first three of these
4361registers must satisfy the invariant cansave + canrestore + otherwin =
4362nwindow - 2, where nwindow is the number of register windows.
4363The cwp contains the index of the register window currently in use.
4364RTEMS does not use the cleanwin and otherwin registers.
4365
4366The save instruction increments the cwp modulo the number of
4367register windows, and if cansave is 0 then it also generates a
4368window overflow. Similarly, the restore instruction decrements the
4369cwp modulo the number of register windows, and if canrestore is 0 then it
4370also generates a window underflow.
4371
4372Unlike with the SPARC model, the SPARC-64 port does not assume that
4373a register window is available for a trap. The window overflow
4374and underflow conditions are not detected without hardware generating
4375the trap. (These conditions can be detected by reading the register window
4376registers and doing some simple arithmetic.)
4377
4378The window overflow and window underflow trap
4379handlers are a critical part of the run-time environment for a
4380SPARC application.  The SPARC architectural specification allows
4381for the number of register windows to be any power of two less
4382than or equal to 32.  The most common choice for SPARC
4383implementations appears to be 8 register windows.  This results
4384in the cwp ranging in value from 0 to 7 on most implementations.
4385
4386The second complicating factor is the sharing of
4387registers between adjacent register windows.  While each
4388register window has its own set of local registers, the input
4389and output registers are shared between adjacent windows.  The
4390output registers for register window N are the same as the input
4391registers for register window ((N + 1) modulo RW) where RW is
4392the number of register windows.  An alternative way to think of
4393this is to remember how parameters are passed to a subroutine on
4394the SPARC.  The caller loads values into what are its output
4395registers.  Then after the callee executes a save instruction,
4396those parameters are available in its input registers.  This is
4397a very efficient way to pass parameters as no data is actually
4398moved by the save or restore instructions.
4399
4400Call and Return Mechanism
4401-------------------------
4402
4403The SPARC architecture supports a simple yet
4404effective call and return mechanism.  A subroutine is invoked
4405via the call (call) instruction.  This instruction places the
4406return address in the caller’s output register 7 (o7).  After
4407the callee executes a save instruction, this value is available
4408in input register 7 (i7) until the corresponding restore
4409instruction is executed.
4410
4411The callee returns to the caller via a jmp to the
4412return address.  There is a delay slot following this
4413instruction which is commonly used to execute a restore
4414instruction – if a register window was allocated by this
4415subroutine.
4416
4417It is important to note that the SPARC subroutine
4418call and return mechanism does not automatically save and
4419restore any registers.  This is accomplished via the save and
4420restore instructions which manage the set of registers windows.
4421This allows for the compiler to generate leaf-optimized functions
4422that utilize the caller’s output registers without using save and restore.
4423
4424Calling Mechanism
4425-----------------
4426
4427All RTEMS directives are invoked using the regular
4428SPARC calling convention via the call instruction.
4429
4430Register Usage
4431--------------
4432
4433As discussed above, the call instruction does not
4434automatically save any registers.  The save and restore
4435instructions are used to allocate and deallocate register
4436windows.  When a register window is allocated, the new set of
4437local registers are available for the exclusive use of the
4438subroutine which allocated this register set.
4439
4440Parameter Passing
4441-----------------
4442
4443RTEMS assumes that arguments are placed in the
4444caller’s output registers with the first argument in output
4445register 0 (o0), the second argument in output register 1 (o1),
4446and so forth.  Until the callee executes a save instruction, the
4447parameters are still visible in the output registers.  After the
4448callee executes a save instruction, the parameters are visible
4449in the corresponding input registers.  The following pseudo-code
4450illustrates the typical sequence used to call a RTEMS directive
4451with three (3) arguments:
4452.. code:: c
4453
4454    load third argument into o2
4455    load second argument into o1
4456    load first argument into o0
4457    invoke directive
4458
4459User-Provided Routines
4460----------------------
4461
4462All user-provided routines invoked by RTEMS, such as
4463user extensions, device drivers, and MPCI routines, must also
4464adhere to these calling conventions.
4465
4466.. COMMENT: COPYRIGHT (c) 1988-2002.
4467
4468.. COMMENT: On-Line Applications Research Corporation (OAR).
4469
4470.. COMMENT: All rights reserved.
4471
4472Memory Model
4473============
4474
4475A processor may support any combination of memory
4476models ranging from pure physical addressing to complex demand
4477paged virtual memory systems.  RTEMS supports a flat memory
4478model which ranges contiguously over the processor’s allowable
4479address space.  RTEMS does not support segmentation or virtual
4480memory of any kind.  The appropriate memory model for RTEMS
4481provided by the targeted processor and related characteristics
4482of that model are described in this chapter.
4483
4484Flat Memory Model
4485-----------------
4486
4487The SPARC-64 architecture supports a flat 64-bit address space with
4488addresses ranging from 0x0000000000000000 to 0xFFFFFFFFFFFFFFFF.
4489Each address is represented by a 64-bit value (and an 8-bit address
4490space identifider or ASI) and is byte addressable. The address
4491may be used to reference a single byte, half-word (2-bytes),
4492word (4 bytes), doubleword (8 bytes), or quad-word (16 bytes).
4493Memory accesses within this address space are performed
4494in big endian fashion by the SPARC. Memory accesses which are not
4495properly aligned generate a "memory address not aligned" trap
4496(type number 0x34). The following table lists the alignment
4497requirements for a variety of data accesses:
4498.. code:: c
4499
4500    +--------------+-----------------------+
4501    |   Data Type  | Alignment Requirement |
4502    +--------------+-----------------------+
4503    |     byte     |          1            |
4504    |   half-word  |          2            |
4505    |     word     |          4            |
4506    |  doubleword  |          8            |
4507    |   quadword   |          16           |
4508    +--------------+-----------------------+
4509
4510RTEMS currently does not support any SPARC Memory Management
4511Units, therefore, virtual memory or segmentation systems
4512involving the SPARC are not supported.
4513
4514.. COMMENT: COPYRIGHT (c) 1988-2002.
4515
4516.. COMMENT: On-Line Applications Research Corporation (OAR).
4517
4518.. COMMENT: All rights reserved.
4519
4520Interrupt Processing
4521====================
4522
4523RTEMS and associated documentation uses the terms
4524interrupt and vector.  In the SPARC architecture, these terms
4525correspond to traps and trap type, respectively.  The terms will
4526be used interchangeably in this manual. Note that in the SPARC manuals,
4527interrupts are a subset of the traps that are delivered to software
4528interrupt handlers.
4529
4530Synchronous Versus Asynchronous Traps
4531-------------------------------------
4532
4533The SPARC architecture includes two classes of traps:
4534synchronous (precise) and asynchronous (deferred).
4535Asynchronous traps occur when an
4536external event interrupts the processor.  These traps are not
4537associated with any instruction executed by the processor and
4538logically occur between instructions.  The instruction currently
4539in the execute stage of the processor is allowed to complete
4540although subsequent instructions are annulled.  The return
4541address reported by the processor for asynchronous traps is the
4542pair of instructions following the current instruction.
4543
4544Synchronous traps are caused by the actions of an
4545instruction.  The trap stimulus in this case either occurs
4546internally to the processor or is from an external signal that
4547was provoked by the instruction.  These traps are taken
4548immediately and the instruction that caused the trap is aborted
4549before any state changes occur in the processor itself.   The
4550return address reported by the processor for synchronous traps
4551is the instruction which caused the trap and the following
4552instruction.
4553
4554Vectoring of Interrupt Handler
4555------------------------------
4556
4557Upon receipt of an interrupt the SPARC automatically
4558performs the following actions:
4559
4560- The trap level is set. This provides access to a fresh set of
4561  privileged trap-state registers used to save the current state,
4562  in effect, pushing a frame on the trap stack.
4563  TL <- TL + 1
4564
4565- Existing state is preserved
4566  - TSTATE[TL].CCR <- CCR
4567  - TSTATE[TL].ASI <- ASI
4568  - TSTATE[TL].PSTATE <- PSTATE
4569  - TSTATE[TL].CWP <- CWP
4570  - TPC[TL] <- PC
4571  - TNPC[TL] <- nPC
4572
4573- The trap type is preserved. TT[TL] <- the trap type
4574
4575- The PSTATE register is updated to a predefined state
4576  - PSTATE.MM is unchanged
4577  - PSTATE.RED <- 0
4578  - PSTATE.PEF <- 1 if FPU is present, 0 otherwise
4579  - PSTATE.AM <- 0 (address masking is turned off)
4580  - PSTATE.PRIV <- 1 (the processor enters privileged mode)
4581  - PSTATE.IE <- 0 (interrupts are disabled)
4582  - PSTATE.AG <- 1 (global regs are replaced with alternate globals)
4583  - PSTATE.CLE <- PSTATE.TLE (set endian mode for traps)
4584
4585- For a register-window trap only, CWP is set to point to the register
4586  window that must be accessed by the trap-handler software, that is:
4587  - If TT[TL] = 0x24 (a clean window trap), then CWP <- CWP + 1.
4588  - If (0x80 <= TT[TL] <= 0xBF) (window spill trap), then CWP <- CWP +
4589    CANSAVE + 2.
4590  - If (0xC0 <= TT[TL] <= 0xFF) (window fill trap), then CWP <- CWP1.
4591  - For non-register-window traps, CWP is not changed.
4592
4593- Control is transferred into the trap table:
4594  - PC <- TBA<63:15> (TL>0) TT[TL] 0 0000
4595  - nPC <- TBA<63:15> (TL>0) TT[TL] 0 0100
4596  - where (TL>0) is 0 if TL = 0, and 1 if TL > 0.
4597
4598In order to safely invoke a subroutine during trap handling, traps must be
4599enabled to allow for the possibility of register window overflow and
4600underflow traps.
4601
4602If the interrupt handler was installed as an RTEMS
4603interrupt handler, then upon receipt of the interrupt, the
4604processor passes control to the RTEMS interrupt handler which
4605performs the following actions:
4606
4607- saves the state of the interrupted task on it’s stack,
4608
4609- switches the processor to trap level 0,
4610
4611- if this is the outermost (i.e. non-nested) interrupt,
4612  then the RTEMS interrupt handler switches from the current stack
4613  to the interrupt stack,
4614
4615- enables traps,
4616
4617- invokes the vectors to a user interrupt service routine (ISR).
4618
4619Asynchronous interrupts are ignored while traps are
4620disabled.  Synchronous traps which occur while traps are
4621disabled may result in the CPU being forced into an error mode.
4622
4623A nested interrupt is processed similarly with the
4624exception that the current stack need not be switched to the
4625interrupt stack.
4626
4627Traps and Register Windows
4628--------------------------
4629
4630XXX
4631
4632Interrupt Levels
4633----------------
4634
4635Sixteen levels (0-15) of interrupt priorities are
4636supported by the SPARC architecture with level fifteen (15)
4637being the highest priority.  Level zero (0) indicates that
4638interrupts are fully enabled.  Interrupt requests for interrupts
4639with priorities less than or equal to the current interrupt mask
4640level are ignored.
4641
4642Although RTEMS supports 256 interrupt levels, the
4643SPARC only supports sixteen.  RTEMS interrupt levels 0 through
464415 directly correspond to SPARC processor interrupt levels.  All
4645other RTEMS interrupt levels are undefined and their behavior is
4646unpredictable.
4647
4648Disabling of Interrupts by RTEMS
4649--------------------------------
4650
4651XXX
4652
4653Interrupt Stack
4654---------------
4655
4656The SPARC architecture does not provide for a
4657dedicated interrupt stack.  Thus by default, trap handlers would
4658execute on the stack of the RTEMS task which they interrupted.
4659This artificially inflates the stack requirements for each task
4660since EVERY task stack would have to include enough space to
4661account for the worst case interrupt stack requirements in
4662addition to it’s own worst case usage.  RTEMS addresses this
4663problem on the SPARC by providing a dedicated interrupt stack
4664managed by software.
4665
4666During system initialization, RTEMS allocates the
4667interrupt stack from the Workspace Area.  The amount of memory
4668allocated for the interrupt stack is determined by the
4669interrupt_stack_size field in the CPU Configuration Table.  As
4670part of processing a non-nested interrupt, RTEMS will switch to
4671the interrupt stack before invoking the installed handler.
4672
4673.. COMMENT: COPYRIGHT (c) 1988-2002.
4674
4675.. COMMENT: On-Line Applications Research Corporation (OAR).
4676
4677.. COMMENT: All rights reserved.
4678
4679Default Fatal Error Processing
4680==============================
4681
4682Upon detection of a fatal error by either the
4683application or RTEMS the fatal error manager is invoked.  The
4684fatal error manager will invoke the user-supplied fatal error
4685handlers.  If no user-supplied handlers are configured,  the
4686RTEMS provided default fatal error handler is invoked.  If the
4687user-supplied fatal error handlers return to the executive the
4688default fatal error handler is then invoked.  This chapter
4689describes the precise operations of the default fatal error
4690handler.
4691
4692Default Fatal Error Handler Operations
4693--------------------------------------
4694
4695The default fatal error handler which is invoked by
4696the fatal_error_occurred directive when there is no user handler
4697configured or the user handler returns control to RTEMS.  The
4698default fatal error handler disables processor interrupts to
4699level 15, places the error code in g1, and goes into an infinite
4700loop to simulate a halt processor instruction.
4701
4702Symmetric Multiprocessing
4703=========================
4704
4705SMP is not supported.
4706
4707Thread-Local Storage
4708====================
4709
4710Thread-local storage is supported.
4711
4712.. COMMENT: COPYRIGHT (c) 1988-2002.
4713
4714.. COMMENT: On-Line Applications Research Corporation (OAR).
4715
4716.. COMMENT: All rights reserved.
4717
4718Board Support Packages
4719======================
4720
4721An RTEMS Board Support Package (BSP) must be designed
4722to support a particular processor and target board combination.
4723This chapter presents a discussion of SPARC specific BSP issues.
4724For more information on developing a BSP, refer to the chapter
4725titled Board Support Packages in the RTEMS
4726Applications User’s Guide.
4727
4728HelenOS and Open Firmware
4729-------------------------
4730
4731The provided BSPs make use of some bootstrap and low-level hardware code
4732of the HelenOS operating system. These files can be found in the shared/helenos
4733directory of the sparc64 bsp directory.  Consult the sources for more
4734detailed information.
4735
4736The shared BSP code also uses the Open Firmware interface to re-use firmware
4737code, primarily for console support and default trap handlers.
4738
4739Command and Variable Index
4740##########################
4741
4742There are currently no Command and Variable Index entries.
4743
4744.. COMMENT: @printindex fn
4745
4746Concept Index
4747#############
4748
4749There are currently no Concept Index entries.
4750
4751.. COMMENT: @printindex cp
Note: See TracBrowser for help on using the repository browser.