source: rtems/doc/cpu_supplement/sparc.t @ f9eca790

4.115
Last change on this file since f9eca790 was 7c0bd74, checked in by Sebastian Huber <sebastian.huber@…>, on 04/22/14 at 08:15:39

sparc: Add _CPU_Get_current_per_CPU_control()

Use register g6 for the per-CPU control of the current processor. The
register g6 is reserved for the operating system by the SPARC ABI. On
Linux register g6 is used for a similar purpose with the same method
since 1996.

The register g6 must be initialized during system startup and then must
remain unchanged.

Since the per-CPU control is used in all critical sections of the
operating system, this is a performance optimization for the operating
system core procedures. An additional benefit is that the low-level
context switch and interrupt processing code is now identical on non-SMP
and SMP configurations.

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