source: rtems-docs/cpu_supplement/sparc.rst @ e6fe68d

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

Set SPDX License Identifier in each source file.

  • Property mode set to 100644
File size: 37.2 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3SPARC Specific Information
4##########################
5
6The Real Time Executive for Multiprocessor Systems
7(RTEMS) is designed to be portable across multiple processor
8architectures.  However, the nature of real-time systems makes
9it essential that the application designer understand certain
10processor dependent implementation details.  These processor
11dependencies include calling convention, board support package
12issues, interrupt processing, exact RTEMS memory requirements,
13performance data, header files, and the assembly language
14interface to the executive.
15
16This document discusses the SPARC architecture dependencies in this
17port of RTEMS.  This architectural port is for SPARC Version 7 and
188. Implementations for SPARC V9 are in the sparc64 target.
19
20It is highly recommended that the SPARC RTEMS
21application developer obtain and become familiar with the
22documentation for the processor being used as well as the
23specification for the revision of the SPARC architecture which
24corresponds to that processor.
25
26**SPARC Architecture Documents**
27
28For information on the SPARC architecture, refer to
29the following documents available from SPARC International, Inc.
30(http://www.sparc.com):
31
32- SPARC Standard Version 7.
33
34- SPARC Standard Version 8.
35
36**ERC32 Specific Information**
37
38The European Space Agency's ERC32 is a three chip
39computing core implementing a SPARC V7 processor and associated
40support circuitry for embedded space applications. The integer
41and floating-point units (90C601E & 90C602E) are based on the
42Cypress 7C601 and 7C602, with additional error-detection and
43recovery functions. The memory controller (MEC) implements
44system support functions such as address decoding, memory
45interface, DMA interface, UARTs, timers, interrupt control,
46write-protection, memory reconfiguration and error-detection.
47The core is designed to work at 25MHz, but using space qualified
48memories limits the system frequency to around 15 MHz, resulting
49in a performance of 10 MIPS and 2 MFLOPS.
50
51Information on the ERC32 and a number of development
52support tools, such as the SPARC Instruction Simulator (SIS),
53are freely available on the Internet.  The following documents
54and SIS are available via anonymous ftp or pointing your web
55browser at ftp://ftp.estec.esa.nl/pub/ws/wsd/erc32.
56
57- ERC32 System Design Document
58
59- MEC Device Specification
60
61Additionally, the SPARC RISC User's Guide from Matra
62MHS documents the functionality of the integer and floating
63point units including the instruction set information.  To
64obtain this document as well as ERC32 components and VHDL models
65contact:
66.. code:: c
67
68    Matra MHS SA
69    3 Avenue du Centre, BP 309,
70    78054 St-Quentin-en-Yvelines,
71    Cedex, France
72    VOICE: +31-1-30607087
73    FAX: +31-1-30640693
74
75Amar Guennon (amar.guennon@matramhs.fr) is familiar with the ERC32.
76
77.. COMMENT: COPYRIGHT (c) 1988-2002.
78
79.. COMMENT: On-Line Applications Research Corporation (OAR).
80
81.. COMMENT: All rights reserved.
82
83CPU Model Dependent Features
84============================
85
86Microprocessors are generally classified into
87families with a variety of CPU models or implementations within
88that family.  Within a processor family, there is a high level
89of binary compatibility.  This family may be based on either an
90architectural specification or on maintaining compatibility with
91a popular processor.  Recent microprocessor families such as the
92SPARC or PowerPC are based on an architectural specification
93which is independent or any particular CPU model or
94implementation.  Older families such as the M68xxx and the iX86
95evolved as the manufacturer strived to produce higher
96performance processor models which maintained binary
97compatibility with older models.
98
99RTEMS takes advantage of the similarity of the
100various models within a CPU family.  Although the models do vary
101in significant ways, the high level of compatibility makes it
102possible to share the bulk of the CPU dependent executive code
103across the entire family.
104
105CPU Model Feature Flags
106-----------------------
107
108Each processor family supported by RTEMS has a
109list of features which vary between CPU models
110within a family.  For example, the most common model dependent
111feature regardless of CPU family is the presence or absence of a
112floating point unit or coprocessor.  When defining the list of
113features present on a particular CPU model, one simply notes
114that floating point hardware is or is not present and defines a
115single constant appropriately.  Conditional compilation is
116utilized to include the appropriate source code for this CPU
117model's feature set.  It is important to note that this means
118that RTEMS is thus compiled using the appropriate feature set
119and compilation flags optimal for this CPU model used.  The
120alternative would be to generate a binary which would execute on
121all family members using only the features which were always
122present.
123
124This section presents the set of features which vary
125across SPARC implementations and are of importance to RTEMS.
126The set of CPU model feature macros are defined in the file
127cpukit/score/cpu/sparc/sparc.h based upon the particular CPU
128model defined on the compilation command line.
129
130CPU Model Name
131~~~~~~~~~~~~~~
132
133The macro CPU_MODEL_NAME is a string which designates
134the name of this CPU model.  For example, for the European Space
135Agency's ERC32 SPARC model, this macro is set to the string
136"erc32".
137
138Floating Point Unit
139~~~~~~~~~~~~~~~~~~~
140
141The macro SPARC_HAS_FPU is set to 1 to indicate that
142this CPU model has a hardware floating point unit and 0
143otherwise.
144
145Bitscan Instruction
146~~~~~~~~~~~~~~~~~~~
147
148The macro SPARC_HAS_BITSCAN is set to 1 to indicate
149that this CPU model has the bitscan instruction.  For example,
150this instruction is supported by the Fujitsu SPARClite family.
151
152Number of Register Windows
153~~~~~~~~~~~~~~~~~~~~~~~~~~
154
155The macro SPARC_NUMBER_OF_REGISTER_WINDOWS is set to
156indicate the number of register window sets implemented by this
157CPU model.  The SPARC architecture allows a for a maximum of
158thirty-two register window sets although most implementations
159only include eight.
160
161Low Power Mode
162~~~~~~~~~~~~~~
163
164The macro SPARC_HAS_LOW_POWER_MODE is set to one to
165indicate that this CPU model has a low power mode.  If low power
166is enabled, then there must be CPU model specific implementation
167of the IDLE task in cpukit/score/cpu/sparc/cpu.c.  The low
168power mode IDLE task should be of the form:
169.. code:: c
170
171    while ( TRUE ) {
172    enter low power mode
173    }
174
175The code required to enter low power mode is CPU model specific.
176
177CPU Model Implementation Notes
178------------------------------
179
180The ERC32 is a custom SPARC V7 implementation based on the Cypress 601/602
181chipset.  This CPU has a number of on-board peripherals and was developed by
182the European Space Agency to target space applications.  RTEMS currently
183provides support for the following peripherals:
184
185- UART Channels A and B
186
187- General Purpose Timer
188
189- Real Time Clock
190
191- Watchdog Timer (so it can be disabled)
192
193- Control Register (so powerdown mode can be enabled)
194
195- Memory Control Register
196
197- Interrupt Control
198
199The General Purpose Timer and Real Time Clock Timer provided with the ERC32
200share the Timer Control Register.  Because the Timer Control Register is write
201only, we must mirror it in software and insure that writes to one timer do not
202alter the current settings and status of the other timer.  Routines are
203provided in erc32.h which promote the view that the two timers are completely
204independent.  By exclusively using these routines to access the Timer Control
205Register, the application can view the system as having a General Purpose
206Timer Control Register and a Real Time Clock Timer Control Register
207rather than the single shared value.
208
209The RTEMS Idle thread take advantage of the low power mode provided by the
210ERC32.  Low power mode is entered during idle loops and is enabled at
211initialization time.
212
213.. COMMENT: COPYRIGHT (c) 1988-2002.
214
215.. COMMENT: On-Line Applications Research Corporation (OAR).
216
217.. COMMENT: All rights reserved.
218
219Calling Conventions
220===================
221
222Each high-level language compiler generates subroutine entry and exit code
223based upon a set of rules known as the application binary interface (ABI)
224calling convention.   These rules address the following issues:
225
226- register preservation and usage
227
228- parameter passing
229
230- call and return mechanism
231
232An ABI calling convention is of importance when interfacing to subroutines
233written in another language either assembly or high-level.  It determines also
234the set of registers to be saved or restored during a context switch and
235interrupt processing.
236
237The ABI relevant for RTEMS on SPARC is defined by SYSTEM V APPLICATION BINARY
238INTERFACE, SPARC Processor Supplement, Third Edition.
239
240Programming Model
241-----------------
242
243This section discusses the programming model for the
244SPARC architecture.
245
246Non-Floating Point Registers
247~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248
249The SPARC architecture defines thirty-two
250non-floating point registers directly visible to the programmer.
251These are divided into four sets:
252
253- input registers
254
255- local registers
256
257- output registers
258
259- global registers
260
261Each register is referred to by either two or three
262names in the SPARC reference manuals.  First, the registers are
263referred to as r0 through r31 or with the alternate notation
264r[0] through r[31].  Second, each register is a member of one of
265the four sets listed above.  Finally, some registers have an
266architecturally defined role in the programming model which
267provides an alternate name.  The following table describes the
268mapping between the 32 registers and the register sets:
269
270.. code:: c
271
272    +-----------------+----------------+------------------+
273    | Register Number | Register Names |   Description    |
274    +-----------------+----------------+------------------+
275    |     0 - 7       |    g0 - g7     | Global Registers |
276    +-----------------+----------------+------------------+
277    |     8 - 15      |    o0 - o7     | Output Registers |
278    +-----------------+----------------+------------------+
279    |    16 - 23      |    l0 - l7     | Local Registers  |
280    +-----------------+----------------+------------------+
281    |    24 - 31      |    i0 - i7     | Input Registers  |
282    +-----------------+----------------+------------------+
283
284As mentioned above, some of the registers serve
285defined roles in the programming model.  The following table
286describes the role of each of these registers:
287
288.. code:: c
289
290    +---------------+----------------+----------------------+
291    | Register Name | Alternate Name |      Description     |
292    +---------------+----------------+----------------------+
293    |     g0        |      na        |    reads return 0    |
294    |               |                |  writes are ignored  |
295    +---------------+----------------+----------------------+
296    |     o6        |      sp        |     stack pointer    |
297    +---------------+----------------+----------------------+
298    |     i6        |      fp        |     frame pointer    |
299    +---------------+----------------+----------------------+
300    |     i7        |      na        |    return address    |
301    +---------------+----------------+----------------------+
302
303The registers g2 through g4 are reserved for applications.  GCC uses them as
304volatile registers by default.  So they are treated like volatile registers in
305RTEMS as well.
306
307The register g6 is reserved for the operating system and contains the address
308of the per-CPU control block of the current processor.  This register is
309initialized during system start and then remains unchanged.  It is not
310saved/restored by the context switch or interrupt processing code.
311
312The register g7 is reserved for the operating system and contains the thread
313pointer used for thread-local storage (TLS) as mandated by the SPARC ABI.
314
315Floating Point Registers
316~~~~~~~~~~~~~~~~~~~~~~~~
317
318The SPARC V7 architecture includes thirty-two,
319thirty-two bit registers.  These registers may be viewed as
320follows:
321
322- 32 single precision floating point or integer registers
323  (f0, f1,  ... f31)
324
325- 16 double precision floating point registers (f0, f2,
326  f4, ... f30)
327
328- 8 extended precision floating point registers (f0, f4,
329  f8, ... f28)
330
331The floating point status register (FSR) specifies
332the behavior of the floating point unit for rounding, contains
333its condition codes, version specification, and trap information.
334
335According to the ABI all floating point registers and the floating point status
336register (FSR) are volatile.  Thus the floating point context of a thread is the
337empty set.  The rounding direction is a system global state and must not be
338modified by threads.
339
340A queue of the floating point instructions which have
341started execution but not yet completed is maintained.  This
342queue is needed to support the multiple cycle nature of floating
343point operations and to aid floating point exception trap
344handlers.  Once a floating point exception has been encountered,
345the queue is frozen until it is emptied by the trap handler.
346The floating point queue is loaded by launching instructions.
347It is emptied normally when the floating point completes all
348outstanding instructions and by floating point exception
349handlers with the store double floating point queue (stdfq)
350instruction.
351
352Special Registers
353~~~~~~~~~~~~~~~~~
354
355The SPARC architecture includes two special registers
356which are critical to the programming model: the Processor State
357Register (psr) and the Window Invalid Mask (wim).  The psr
358contains the condition codes, processor interrupt level, trap
359enable bit, supervisor mode and previous supervisor mode bits,
360version information, floating point unit and coprocessor enable
361bits, and the current window pointer (cwp).  The cwp field of
362the psr and wim register are used to manage the register windows
363in the SPARC architecture.  The register windows are discussed
364in more detail below.
365
366Register Windows
367----------------
368
369The SPARC architecture includes the concept of
370register windows.  An overly simplistic way to think of these
371windows is to imagine them as being an infinite supply of
372"fresh" register sets available for each subroutine to use.  In
373reality, they are much more complicated.
374
375The save instruction is used to obtain a new register
376window.  This instruction decrements the current window pointer,
377thus providing a new set of registers for use.  This register
378set includes eight fresh local registers for use exclusively by
379this subroutine.  When done with a register set, the restore
380instruction increments the current window pointer and the
381previous register set is once again available.
382
383The two primary issues complicating the use of
384register windows are that (1) the set of register windows is
385finite, and (2) some registers are shared between adjacent
386registers windows.
387
388Because the set of register windows is finite, it is
389possible to execute enough save instructions without
390corresponding restore's to consume all of the register windows.
391This is easily accomplished in a high level language because
392each subroutine typically performs a save instruction upon
393entry.  Thus having a subroutine call depth greater than the
394number of register windows will result in a window overflow
395condition.  The window overflow condition generates a trap which
396must be handled in software.  The window overflow trap handler
397is responsible for saving the contents of the oldest register
398window on the program stack.
399
400Similarly, the subroutines will eventually complete
401and begin to perform restore's.  If the restore results in the
402need for a register window which has previously been written to
403memory as part of an overflow, then a window underflow condition
404results.  Just like the window overflow, the window underflow
405condition must be handled in software by a trap handler.  The
406window underflow trap handler is responsible for reloading the
407contents of the register window requested by the restore
408instruction from the program stack.
409
410The Window Invalid Mask (wim) and the Current Window
411Pointer (cwp) field in the psr are used in conjunction to manage
412the finite set of register windows and detect the window
413overflow and underflow conditions.  The cwp contains the index
414of the register window currently in use.  The save instruction
415decrements the cwp modulo the number of register windows.
416Similarly, the restore instruction increments the cwp modulo the
417number of register windows.  Each bit in the  wim represents
418represents whether a register window contains valid information.
419The value of 0 indicates the register window is valid and 1
420indicates it is invalid.  When a save instruction causes the cwp
421to point to a register window which is marked as invalid, a
422window overflow condition results.  Conversely, the restore
423instruction may result in a window underflow condition.
424
425Other than the assumption that a register window is
426always available for trap (i.e. interrupt) handlers, the SPARC
427architecture places no limits on the number of register windows
428simultaneously marked as invalid (i.e. number of bits set in the
429wim).  However, RTEMS assumes that only one register window is
430marked invalid at a time (i.e. only one bit set in the wim).
431This makes the maximum possible number of register windows
432available to the user while still meeting the requirement that
433window overflow and underflow conditions can be detected.
434
435The window overflow and window underflow trap
436handlers are a critical part of the run-time environment for a
437SPARC application.  The SPARC architectural specification allows
438for the number of register windows to be any power of two less
439than or equal to 32.  The most common choice for SPARC
440implementations appears to be 8 register windows.  This results
441in the cwp ranging in value from 0 to 7 on most implementations.
442
443The second complicating factor is the sharing of
444registers between adjacent register windows.  While each
445register window has its own set of local registers, the input
446and output registers are shared between adjacent windows.  The
447output registers for register window N are the same as the input
448registers for register window ((N - 1) modulo RW) where RW is
449the number of register windows.  An alternative way to think of
450this is to remember how parameters are passed to a subroutine on
451the SPARC.  The caller loads values into what are its output
452registers.  Then after the callee executes a save instruction,
453those parameters are available in its input registers.  This is
454a very efficient way to pass parameters as no data is actually
455moved by the save or restore instructions.
456
457Call and Return Mechanism
458-------------------------
459
460The SPARC architecture supports a simple yet
461effective call and return mechanism.  A subroutine is invoked
462via the call (call) instruction.  This instruction places the
463return address in the caller's output register 7 (o7).  After
464the callee executes a save instruction, this value is available
465in input register 7 (i7) until the corresponding restore
466instruction is executed.
467
468The callee returns to the caller via a jmp to the
469return address.  There is a delay slot following this
470instruction which is commonly used to execute a restore
471instruction - if a register window was allocated by this
472subroutine.
473
474It is important to note that the SPARC subroutine
475call and return mechanism does not automatically save and
476restore any registers.  This is accomplished via the save and
477restore instructions which manage the set of registers windows.
478
479In case a floating-point unit is supported, then floating-point return values
480appear in the floating-point registers.  Single-precision values occupy %f0;
481double-precision values occupy %f0 and %f1.  Otherwise, these are scratch
482registers.  Due to this the hardware and software floating-point ABIs are
483incompatible.
484
485Calling Mechanism
486-----------------
487
488All RTEMS directives are invoked using the regular
489SPARC calling convention via the call instruction.
490
491Register Usage
492--------------
493
494As discussed above, the call instruction does not
495automatically save any registers.  The save and restore
496instructions are used to allocate and deallocate register
497windows.  When a register window is allocated, the new set of
498local registers are available for the exclusive use of the
499subroutine which allocated this register set.
500
501Parameter Passing
502-----------------
503
504RTEMS assumes that arguments are placed in the
505caller's output registers with the first argument in output
506register 0 (o0), the second argument in output register 1 (o1),
507and so forth.  Until the callee executes a save instruction, the
508parameters are still visible in the output registers.  After the
509callee executes a save instruction, the parameters are visible
510in the corresponding input registers.  The following pseudo-code
511illustrates the typical sequence used to call a RTEMS directive
512with three (3) arguments:
513.. code:: c
514
515    load third argument into o2
516    load second argument into o1
517    load first argument into o0
518    invoke directive
519
520User-Provided Routines
521----------------------
522
523All user-provided routines invoked by RTEMS, such as
524user extensions, device drivers, and MPCI routines, must also
525adhere to these calling conventions.
526
527.. COMMENT: COPYRIGHT (c) 1988-2002.
528
529.. COMMENT: On-Line Applications Research Corporation (OAR).
530
531.. COMMENT: All rights reserved.
532
533Memory Model
534============
535
536A processor may support any combination of memory
537models ranging from pure physical addressing to complex demand
538paged virtual memory systems.  RTEMS supports a flat memory
539model which ranges contiguously over the processor's allowable
540address space.  RTEMS does not support segmentation or virtual
541memory of any kind.  The appropriate memory model for RTEMS
542provided by the targeted processor and related characteristics
543of that model are described in this chapter.
544
545Flat Memory Model
546-----------------
547
548The SPARC architecture supports a flat 32-bit address
549space with addresses ranging from 0x00000000 to 0xFFFFFFFF (4
550gigabytes).  Each address is represented by a 32-bit value and
551is byte addressable.  The address may be used to reference a
552single byte, half-word (2-bytes), word (4 bytes), or doubleword
553(8 bytes).  Memory accesses within this address space are
554performed in big endian fashion by the SPARC.  Memory accesses
555which are not properly aligned generate a "memory address not
556aligned" trap (type number 7).  The following table lists the
557alignment requirements for a variety of data accesses:
558
559.. code:: c
560
561    +--------------+-----------------------+
562    |   Data Type  | Alignment Requirement |
563    +--------------+-----------------------+
564    |     byte     |          1            |
565    |   half-word  |          2            |
566    |     word     |          4            |
567    |  doubleword  |          8            |
568    +--------------+-----------------------+
569
570Doubleword load and store operations must use a pair
571of registers as their source or destination.  This pair of
572registers must be an adjacent pair of registers with the first
573of the pair being even numbered.  For example, a valid
574destination for a doubleword load might be input registers 0 and
5751 (i0 and i1).  The pair i1 and i2 would be invalid.  \[NOTE:
576Some assemblers for the SPARC do not generate an error if an odd
577numbered register is specified as the beginning register of the
578pair.  In this case, the assembler assumes that what the
579programmer meant was to use the even-odd pair which ends at the
580specified register.  This may or may not have been a correct
581assumption.]
582
583RTEMS does not support any SPARC Memory Management
584Units, therefore, virtual memory or segmentation systems
585involving the SPARC are not supported.
586
587.. COMMENT: COPYRIGHT (c) 1988-2002.
588
589.. COMMENT: On-Line Applications Research Corporation (OAR).
590
591.. COMMENT: All rights reserved.
592
593Interrupt Processing
594====================
595
596Different types of processors respond to the
597occurrence of an interrupt in its own unique fashion. In
598addition, each processor type provides a control mechanism to
599allow for the proper handling of an interrupt.  The processor
600dependent response to the interrupt modifies the current
601execution state and results in a change in the execution stream.
602Most processors require that an interrupt handler utilize some
603special control mechanisms to return to the normal processing
604stream.  Although RTEMS hides many of the processor dependent
605details of interrupt processing, it is important to understand
606how the RTEMS interrupt manager is mapped onto the processor's
607unique architecture. Discussed in this chapter are the SPARC's
608interrupt response and control mechanisms as they pertain to
609RTEMS.
610
611RTEMS and associated documentation uses the terms
612interrupt and vector.  In the SPARC architecture, these terms
613correspond to traps and trap type, respectively.  The terms will
614be used interchangeably in this manual.
615
616Synchronous Versus Asynchronous Traps
617-------------------------------------
618
619The SPARC architecture includes two classes of traps:
620synchronous and asynchronous.  Asynchronous traps occur when an
621external event interrupts the processor.  These traps are not
622associated with any instruction executed by the processor and
623logically occur between instructions.  The instruction currently
624in the execute stage of the processor is allowed to complete
625although subsequent instructions are annulled.  The return
626address reported by the processor for asynchronous traps is the
627pair of instructions following the current instruction.
628
629Synchronous traps are caused by the actions of an
630instruction.  The trap stimulus in this case either occurs
631internally to the processor or is from an external signal that
632was provoked by the instruction.  These traps are taken
633immediately and the instruction that caused the trap is aborted
634before any state changes occur in the processor itself.   The
635return address reported by the processor for synchronous traps
636is the instruction which caused the trap and the following
637instruction.
638
639Vectoring of Interrupt Handler
640------------------------------
641
642Upon receipt of an interrupt the SPARC automatically
643performs the following actions:
644
645- disables traps (sets the ET bit of the psr to 0),
646
647- the S bit of the psr is copied into the Previous
648  Supervisor Mode (PS) bit of the psr,
649
650- the cwp is decremented by one (modulo the number of
651  register windows) to activate a trap window,
652
653- the PC and nPC are loaded into local register 1 and 2
654  (l0 and l1),
655
656- the trap type (tt) field of the Trap Base Register (TBR)
657  is set to the appropriate value, and
658
659- if the trap is not a reset, then the PC is written with
660  the contents of the TBR and the nPC is written with TBR + 4.  If
661  the trap is a reset, then the PC is set to zero and the nPC is
662  set to 4.
663
664Trap processing on the SPARC has two features which
665are noticeably different than interrupt processing on other
666architectures.  First, the value of psr register in effect
667immediately before the trap occurred is not explicitly saved.
668Instead only reversible alterations are made to it.  Second, the
669Processor Interrupt Level (pil) is not set to correspond to that
670of the interrupt being processed.  When a trap occurs, ALL
671subsequent traps are disabled.  In order to safely invoke a
672subroutine during trap handling, traps must be enabled to allow
673for the possibility of register window overflow and underflow
674traps.
675
676If the interrupt handler was installed as an RTEMS
677interrupt handler, then upon receipt of the interrupt, the
678processor passes control to the RTEMS interrupt handler which
679performs the following actions:
680
681- saves the state of the interrupted task on it's stack,
682
683- insures that a register window is available for
684  subsequent traps,
685
686- if this is the outermost (i.e. non-nested) interrupt,
687  then the RTEMS interrupt handler switches from the current stack
688  to the interrupt stack,
689
690- enables traps,
691
692- invokes the vectors to a user interrupt service routine (ISR).
693
694Asynchronous interrupts are ignored while traps are
695disabled.  Synchronous traps which occur while traps are
696disabled result in the CPU being forced into an error mode.
697
698A nested interrupt is processed similarly with the
699exception that the current stack need not be switched to the
700interrupt stack.
701
702Traps and Register Windows
703--------------------------
704
705One of the register windows must be reserved at all
706times for trap processing.  This is critical to the proper
707operation of the trap mechanism in the SPARC architecture.  It
708is the responsibility of the trap handler to insure that there
709is a register window available for a subsequent trap before
710re-enabling traps.  It is likely that any high level language
711routines invoked by the trap handler (such as a user-provided
712RTEMS interrupt handler) will allocate a new register window.
713The save operation could result in a window overflow trap.  This
714trap cannot be correctly processed unless (1) traps are enabled
715and (2) a register window is reserved for traps.  Thus, the
716RTEMS interrupt handler insures that a register window is
717available for subsequent traps before enabling traps and
718invoking the user's interrupt handler.
719
720Interrupt Levels
721----------------
722
723Sixteen levels (0-15) of interrupt priorities are
724supported by the SPARC architecture with level fifteen (15)
725being the highest priority.  Level zero (0) indicates that
726interrupts are fully enabled.  Interrupt requests for interrupts
727with priorities less than or equal to the current interrupt mask
728level are ignored. Level fifteen (15) is a non-maskable interrupt
729(NMI), which makes it unsuitable for standard usage since it can
730affect the real-time behaviour by interrupting critical sections
731and spinlocks. Disabling traps stops also the NMI interrupt from
732happening. It can however be used for power-down or other
733critical events.
734
735Although RTEMS supports 256 interrupt levels, the
736SPARC only supports sixteen.  RTEMS interrupt levels 0 through
73715 directly correspond to SPARC processor interrupt levels.  All
738other RTEMS interrupt levels are undefined and their behavior is
739unpredictable.
740
741Many LEON SPARC v7/v8 systems features an extended interrupt controller
742which adds an extra step of interrupt decoding to allow handling of
743interrupt 16-31. When such an extended interrupt is generated the CPU
744traps into a specific interrupt trap level 1-14 and software reads out from
745the interrupt controller which extended interrupt source actually caused the
746interrupt.
747
748Disabling of Interrupts by RTEMS
749--------------------------------
750
751During the execution of directive calls, critical
752sections of code may be executed.  When these sections are
753encountered, RTEMS disables interrupts to level fifteen (15)
754before the execution of the section and restores them to the
755previous level upon completion of the section.  RTEMS has been
756optimized to ensure that interrupts are disabled for less than
757RTEMS_MAXIMUM_DISABLE_PERIOD microseconds on a RTEMS_MAXIMUM_DISABLE_PERIOD_MHZ
758Mhz ERC32 with zero wait states.
759These numbers will vary based the number of wait states and
760processor speed present on the target board.
761\[NOTE:  The maximum period with interrupts disabled is hand calculated.  This
762calculation was last performed for Release
763RTEMS_RELEASE_FOR_MAXIMUM_DISABLE_PERIOD.]
764
765[NOTE: It is thought that the length of time at which
766the processor interrupt level is elevated to fifteen by RTEMS is
767not anywhere near as long as the length of time ALL traps are
768disabled as part of the "flush all register windows" operation.]
769
770Non-maskable interrupts (NMI) cannot be disabled, and
771ISRs which execute at this level MUST NEVER issue RTEMS system
772calls.  If a directive is invoked, unpredictable results may
773occur due to the inability of RTEMS to protect its critical
774sections.  However, ISRs that make no system calls may safely
775execute as non-maskable interrupts.
776
777Interrupts are disabled or enabled by performing a system call
778to the Operating System reserved software traps 9
779(SPARC_SWTRAP_IRQDIS) or 10 (SPARC_SWTRAP_IRQDIS). The trap is
780generated by the software trap (Ticc) instruction or indirectly
781by calling sparc_disable_interrupts() or sparc_enable_interrupts()
782functions. Disabling interrupts return the previous interrupt level
783(on trap entry) in register G1 and sets PSR.PIL to 15 to disable
784all maskable interrupts. The interrupt level can be restored by
785trapping into the enable interrupt handler with G1 containing the
786new interrupt level.
787
788Interrupt Stack
789---------------
790
791The SPARC architecture does not provide for a
792dedicated interrupt stack.  Thus by default, trap handlers would
793execute on the stack of the RTEMS task which they interrupted.
794This artificially inflates the stack requirements for each task
795since EVERY task stack would have to include enough space to
796account for the worst case interrupt stack requirements in
797addition to it's own worst case usage.  RTEMS addresses this
798problem on the SPARC by providing a dedicated interrupt stack
799managed by software.
800
801During system initialization, RTEMS allocates the
802interrupt stack from the Workspace Area.  The amount of memory
803allocated for the interrupt stack is determined by the
804interrupt_stack_size field in the CPU Configuration Table.  As
805part of processing a non-nested interrupt, RTEMS will switch to
806the interrupt stack before invoking the installed handler.
807
808.. COMMENT: COPYRIGHT (c) 1988-2002.
809
810.. COMMENT: On-Line Applications Research Corporation (OAR).
811
812.. COMMENT: All rights reserved.
813
814Default Fatal Error Processing
815==============================
816
817Upon detection of a fatal error by either the
818application or RTEMS the fatal error manager is invoked.  The
819fatal error manager will invoke the user-supplied fatal error
820handlers.  If no user-supplied handlers are configured,  the
821RTEMS provided default fatal error handler is invoked.  If the
822user-supplied fatal error handlers return to the executive the
823default fatal error handler is then invoked.  This chapter
824describes the precise operations of the default fatal error
825handler.
826
827Default Fatal Error Handler Operations
828--------------------------------------
829
830The default fatal error handler which is invoked by
831the fatal_error_occurred directive when there is no user handler
832configured or the user handler returns control to RTEMS.
833
834If the BSP has been configured with ``BSP_POWER_DOWN_AT_FATAL_HALT``
835set to true, the default handler will disable interrupts
836and enter power down mode. If power down mode is not available,
837it goes into an infinite loop to simulate a halt processor instruction.
838
839If ``BSP_POWER_DOWN_AT_FATAL_HALT`` is set to false, the default
840handler will place the value ``1`` in register ``g1``, the
841error source in register ``g2``, and the error code in register``g3``. It will then generate a system error which will
842hand over control to the debugger, simulator, etc.
843
844Symmetric Multiprocessing
845=========================
846
847SMP is supported.  Available platforms are the Cobham Gaisler GR712RC and
848GR740.
849
850Thread-Local Storage
851====================
852
853Thread-local storage is supported.
854
855.. COMMENT: COPYRIGHT (c) 1988-2002.
856
857.. COMMENT: On-Line Applications Research Corporation (OAR).
858
859.. COMMENT: All rights reserved.
860
861Board Support Packages
862======================
863
864An RTEMS Board Support Package (BSP) must be designed
865to support a particular processor and target board combination.
866This chapter presents a discussion of SPARC specific BSP issues.
867For more information on developing a BSP, refer to the chapter
868titled Board Support Packages in the RTEMS
869Applications User's Guide.
870
871System Reset
872------------
873
874An RTEMS based application is initiated or
875re-initiated when the SPARC processor is reset.  When the SPARC
876is reset, the processor performs the following actions:
877
878- the enable trap (ET) of the psr is set to 0 to disable
879  traps,
880
881- the supervisor bit (S) of the psr is set to 1 to enter
882  supervisor mode, and
883
884- the PC is set 0 and the nPC is set to 4.
885
886The processor then begins to execute the code at
887location 0.  It is important to note that all fields in the psr
888are not explicitly set by the above steps and all other
889registers retain their value from the previous execution mode.
890This is true even of the Trap Base Register (TBR) whose contents
891reflect the last trap which occurred before the reset.
892
893Processor Initialization
894------------------------
895
896It is the responsibility of the application's
897initialization code to initialize the TBR and install trap
898handlers for at least the register window overflow and register
899window underflow conditions.  Traps should be enabled before
900invoking any subroutines to allow for register window
901management.  However, interrupts should be disabled by setting
902the Processor Interrupt Level (pil) field of the psr to 15.
903RTEMS installs it's own Trap Table as part of initialization
904which is initialized with the contents of the Trap Table in
905place when the ``rtems_initialize_executive`` directive was invoked.
906Upon completion of executive initialization, interrupts are
907enabled.
908
909If this SPARC implementation supports on-chip caching
910and this is to be utilized, then it should be enabled during the
911reset application initialization code.
912
913In addition to the requirements described in the
914Board Support Packages chapter of the C
915Applications Users Manual for the reset code
916which is executed before the call to``rtems_initialize_executive``, the SPARC version has the following
917specific requirements:
918
919- Must leave the S bit of the status register set so that
920  the SPARC remains in the supervisor state.
921
922- Must set stack pointer (sp) such that a minimum stack
923  size of MINIMUM_STACK_SIZE bytes is provided for the``rtems_initialize_executive`` directive.
924
925- Must disable all external interrupts (i.e. set the pil
926  to 15).
927
928- Must enable traps so window overflow and underflow
929  conditions can be properly handled.
930
931- Must initialize the SPARC's initial trap table with at
932  least trap handlers for register window overflow and register
933  window underflow.
934
935.. COMMENT: COPYRIGHT (c) 1988-2002.
936
937.. COMMENT: On-Line Applications Research Corporation (OAR).
938
939.. COMMENT: All rights reserved.
940
Note: See TracBrowser for help on using the repository browser.