source: rtems-docs/cpu-supplement/sparc64.rst @ 6f110cc

5
Last change on this file since 6f110cc was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

  • Property mode set to 100644
File size: 23.7 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1988, 2002 On-Line Applications Research Corporation (OAR)
4
5SPARC-64 Specific Information
6*****************************
7
8This document discusses the SPARC Version 9 (aka SPARC-64, SPARC64 or SPARC V9)
9architecture dependencies in this port of RTEMS.
10
11The SPARC V9 architecture leaves a lot of undefined implemenation dependencies
12which are defined by the processor models. Consult the specific CPU model
13section in this document for additional documents covering the implementation
14dependent architectural features.
15
16**sun4u Specific Information**
17
18sun4u is the subset of the SPARC V9 implementations comprising the UltraSPARC I
19through UltraSPARC IV processors.
20
21The following documents were used in developing the SPARC-64 sun4u port:
22
23- UltraSPARC  User's Manual
24  (http://www.sun.com/microelectronics/manuals/ultrasparc/802-7220-02.pdf)
25
26- UltraSPARC IIIi Processor (http://datasheets.chipdb.org/Sun/UltraSparc-IIIi.pdf)
27
28**sun4v Specific Information**
29
30sun4v is the subset of the SPARC V9 implementations comprising the UltraSPARC
31T1 or T2 processors.
32
33The following documents were used in developing the SPARC-64 sun4v port:
34
35- UltraSPARC Architecture 2005 Specification
36  (http://opensparc-t1.sunsource.net/specs/UA2005-current-draft-P-EXT.pdf)
37
38- UltraSPARC T1 supplement to UltraSPARC Architecture 2005 Specification
39  (http://opensparc-t1.sunsource.net/specs/UST1-UASuppl-current-draft-P-EXT.pdf)
40
41The defining feature that separates the sun4v architecture from its predecessor
42is the existence of a super-privileged hypervisor that is responsible for
43providing virtualized execution environments.  The impact of the hypervisor on
44the real-time guarantees available with sun4v has not yet been determined.
45
46CPU Model Dependent Features
47============================
48
49CPU Model Feature Flags
50-----------------------
51
52This section presents the set of features which vary across SPARC-64
53implementations and are of importance to RTEMS. The set of CPU model feature
54macros are defined in the file cpukit/score/cpu/sparc64/sparc64.h based upon
55the particular CPU model defined on the compilation command line.
56
57CPU Model Name
58~~~~~~~~~~~~~~
59
60The macro CPU MODEL NAME is a string which designates the name of this CPU
61model.  For example, for the UltraSPARC T1 SPARC V9 model, this macro is set to
62the string "sun4v".
63
64Floating Point Unit
65~~~~~~~~~~~~~~~~~~~
66
67The macro SPARC_HAS_FPU is set to 1 to indicate that this CPU model has a
68hardware floating point unit and 0 otherwise.
69
70Number of Register Windows
71~~~~~~~~~~~~~~~~~~~~~~~~~~
72
73The macro SPARC_NUMBER_OF_REGISTER_WINDOWS is set to indicate the number of
74register window sets implemented by this CPU model.  The SPARC architecture
75allows for a maximum of thirty-two register window sets although most
76implementations only include eight.
77
78CPU Model Implementation Notes
79------------------------------
80
81This section describes the implemenation dependencies of the CPU Models sun4u
82and sun4v of the SPARC V9 architecture.
83
84sun4u Notes
85~~~~~~~~~~~
86
87XXX
88
89sun4v Notes
90-----------
91
92XXX
93
94Calling Conventions
95===================
96
97Each high-level language compiler generates subroutine entry and exit code
98based upon a set of rules known as the compiler's calling convention.  These
99rules address the following issues:
100
101- register preservation and usage
102
103- parameter passing
104
105- call and return mechanism
106
107A compiler's calling convention is of importance when
108interfacing to subroutines written in another language either
109assembly or high-level.  Even when the high-level language and
110target processor are the same, different compilers may use
111different calling conventions.  As a result, calling conventions
112are both processor and compiler dependent.
113
114The following document also provides some conventions on the global register
115usage in SPARC V9: http://developers.sun.com/solaris/articles/sparcv9abi.html
116
117Programming Model
118-----------------
119
120This section discusses the programming model for the SPARC architecture.
121
122Non-Floating Point Registers
123~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124
125The SPARC architecture defines thirty-two non-floating point registers directly
126visible to the programmer.  These are divided into four sets:
127
128- input registers
129
130- local registers
131
132- output registers
133
134- global registers
135
136Each register is referred to by either two or three names in the SPARC
137reference manuals.  First, the registers are referred to as r0 through r31 or
138with the alternate notation r[0] through r[31].  Second, each register is a
139member of one of the four sets listed above.  Finally, some registers have an
140architecturally defined role in the programming model which provides an
141alternate name.  The following table describes the mapping between the 32
142registers and the register sets:
143
144================ ================ ===================
145Register Number  Register Names   Description
146================ ================ ===================
1470 - 7            g0 - g7          Global Registers
1488 - 15           o0 - o7          Output Registers
14916 - 23          l0 - l7          Local Registers
15024 - 31          i0 - i7          Input Registers
151================ ================ ===================
152
153As mentioned above, some of the registers serve defined roles in the
154programming model.  The following table describes the role of each of these
155registers:
156
157============== ================ ==================================
158Register Name  Alternate Name   Description
159============== ================ ==================================
160g0             na               reads return 0, writes are ignored
161o6             sp               stack pointer
162i6             fp               frame pointer
163i7             na               return address
164============== ================ ==================================
165
166Floating Point Registers
167~~~~~~~~~~~~~~~~~~~~~~~~
168
169The SPARC V9 architecture includes sixty-four, thirty-two bit registers.  These
170registers may be viewed as follows:
171
172- 32 32-bit single precision floating point or integer registers (f0, f1,
173  ... f31)
174
175- 32 64-bit double precision floating point registers (f0, f2, f4, ... f62)
176
177- 16 128-bit extended precision floating point registers (f0, f4, f8, ... f60)
178
179The floating point state register (fsr) specifies the behavior of the floating
180point unit for rounding, contains its condition codes, version specification,
181and trap information.
182
183Special Registers
184~~~~~~~~~~~~~~~~~
185
186The SPARC architecture includes a number of special registers:
187
188*``Ancillary State Registers (ASRs)``*
189    The ancillary state registers (ASRs) are optional state registers that may
190    be privileged or nonprivileged. ASRs 16-31 are implementation-
191    dependent. The SPARC V9 ASRs include: y, ccr, asi, tick, pc, fprs.  The
192    sun4u ASRs include: pcr, pic, dcr, gsr, softint set, softint clr, softint,
193    and tick cmpr. The sun4v ASRs include: pcr, pic, gsr, soft- int set,
194    softint clr, softint, tick cmpr, stick, and stick cmpr.
195
196*``Processor State Register (pstate)``*
197    The privileged pstate register contains control fields for the proces-
198    sor's current state. Its flag fields include the interrupt enable, privi-
199    leged mode, and enable FPU.
200
201*``Processor Interrupt Level (pil)``*
202    The PIL specifies the interrupt level above which interrupts will be
203    accepted.
204
205*``Trap Registers``*
206    The trap handling mechanism of the SPARC V9 includes a number of registers,
207    including: trap program counter (tpc), trap next pc (tnpc), trap state
208    (tstate), trap type (tt), trap base address (tba), and trap level (tl).
209
210*``Alternate Globals``*
211    The AG bit of the pstate register provides access to an alternate set of
212    global registers. On sun4v, the AG bit is replaced by the global level (gl)
213    register, providing access to at least two and at most eight alternate sets
214    of globals.
215
216*``Register Window registers``*
217    A number of registers assist in register window management.  These include
218    the current window pointer (cwp), savable windows (cansave), restorable
219    windows (canrestore), clean windows (clean- win), other windows (otherwin),
220    and window state (wstate).
221
222Register Windows
223----------------
224
225The SPARC architecture includes the concept of register windows.  An overly
226simplistic way to think of these windows is to imagine them as being an
227infinite supply of "fresh" register sets available for each subroutine to use.
228In reality, they are much more complicated.
229
230The save instruction is used to obtain a new register window.  This instruction
231increments the current window pointer, thus providing a new set of registers
232for use. This register set includes eight fresh local registers for use
233exclusively by this subroutine. When done with a register set, the restore
234instruction decrements the current window pointer and the previous register set
235is once again available.
236
237The two primary issues complicating the use of register windows are that (1)
238the set of register windows is finite, and (2) some registers are shared
239between adjacent registers windows.
240
241Because the set of register windows is finite, it is possible to execute enough
242save instructions without corresponding restore's to consume all of the
243register windows.  This is easily accomplished in a high level language because
244each subroutine typically performs a save instruction upon entry.  Thus having
245a subroutine call depth greater than the number of register windows will result
246in a window overflow condition.  The window overflow condition generates a trap
247which must be handled in software.  The window overflow trap handler is
248responsible for saving the contents of the oldest register window on the
249program stack.
250
251Similarly, the subroutines will eventually complete and begin to perform
252restore's.  If the restore results in the need for a register window which has
253previously been written to memory as part of an overflow, then a window
254underflow condition results.  Just like the window overflow, the window
255underflow condition must be handled in software by a trap handler.  The window
256underflow trap handler is responsible for reloading the contents of the
257register window requested by the restore instruction from the program stack.
258
259The cansave, canrestore, otherwin, and cwp are used in conjunction to manage
260the finite set of register windows and detect the window overflow and underflow
261conditions. The first three of these registers must satisfy the invariant
262cansave + canrestore + otherwin = nwindow - 2, where nwindow is the number of
263register windows.  The cwp contains the index of the register window currently
264in use.  RTEMS does not use the cleanwin and otherwin registers.
265
266The save instruction increments the cwp modulo the number of register windows,
267and if cansave is 0 then it also generates a window overflow. Similarly, the
268restore instruction decrements the cwp modulo the number of register windows,
269and if canrestore is 0 then it also generates a window underflow.
270
271Unlike with the SPARC model, the SPARC-64 port does not assume that a register
272window is available for a trap. The window overflow and underflow conditions
273are not detected without hardware generating the trap. (These conditions can be
274detected by reading the register window registers and doing some simple
275arithmetic.)
276
277The window overflow and window underflow trap handlers are a critical part of
278the run-time environment for a SPARC application.  The SPARC architectural
279specification allows for the number of register windows to be any power of two
280less than or equal to 32.  The most common choice for SPARC implementations
281appears to be 8 register windows.  This results in the cwp ranging in value
282from 0 to 7 on most implementations.
283
284The second complicating factor is the sharing of registers between adjacent
285register windows.  While each register window has its own set of local
286registers, the input and output registers are shared between adjacent windows.
287The output registers for register window N are the same as the input registers
288for register window ((N + 1) modulo RW) where RW is the number of register
289windows.  An alternative way to think of this is to remember how parameters are
290passed to a subroutine on the SPARC.  The caller loads values into what are its
291output registers.  Then after the callee executes a save instruction, those
292parameters are available in its input registers.  This is a very efficient way
293to pass parameters as no data is actually moved by the save or restore
294instructions.
295
296Call and Return Mechanism
297-------------------------
298
299The SPARC architecture supports a simple yet effective call and return
300mechanism.  A subroutine is invoked via the call (call) instruction.  This
301instruction places the return address in the caller's output register 7 (o7).
302After the callee executes a save instruction, this value is available in input
303register 7 (i7) until the corresponding restore instruction is executed.
304
305The callee returns to the caller via a jmp to the return address.  There is a
306delay slot following this instruction which is commonly used to execute a
307restore instruction - if a register window was allocated by this subroutine.
308
309It is important to note that the SPARC subroutine call and return mechanism
310does not automatically save and restore any registers.  This is accomplished
311via the save and restore instructions which manage the set of registers
312windows.  This allows for the compiler to generate leaf-optimized functions
313that utilize the caller's output registers without using save and restore.
314
315Calling Mechanism
316-----------------
317
318All RTEMS directives are invoked using the regular SPARC calling convention via
319the call instruction.
320
321Register Usage
322--------------
323
324As discussed above, the call instruction does not automatically save any
325registers.  The save and restore instructions are used to allocate and
326deallocate register windows.  When a register window is allocated, the new set
327of local registers are available for the exclusive use of the subroutine which
328allocated this register set.
329
330Parameter Passing
331-----------------
332
333RTEMS assumes that arguments are placed in the caller's output registers with
334the first argument in output register 0 (o0), the second argument in output
335register 1 (o1), and so forth.  Until the callee executes a save instruction,
336the parameters are still visible in the output registers.  After the callee
337executes a save instruction, the parameters are visible in the corresponding
338input registers.  The following pseudo-code illustrates the typical sequence
339used to call a RTEMS directive with three (3) arguments:
340
341.. code-block:: c
342
343    load third argument into o2
344    load second argument into o1
345    load first argument into o0
346    invoke directive
347
348User-Provided Routines
349----------------------
350
351All user-provided routines invoked by RTEMS, such as user extensions, device
352drivers, and MPCI routines, must also adhere to these calling conventions.
353
354Memory Model
355============
356
357A processor may support any combination of memory models ranging from pure
358physical addressing to complex demand paged virtual memory systems.  RTEMS
359supports a flat memory model which ranges contiguously over the processor's
360allowable address space.  RTEMS does not support segmentation or virtual memory
361of any kind.  The appropriate memory model for RTEMS provided by the targeted
362processor and related characteristics of that model are described in this
363chapter.
364
365Flat Memory Model
366-----------------
367
368The SPARC-64 architecture supports a flat 64-bit address space with addresses
369ranging from 0x0000000000000000 to 0xFFFFFFFFFFFFFFFF.  Each address is
370represented by a 64-bit value (and an 8-bit address space identifider or ASI)
371and is byte addressable. The address may be used to reference a single byte,
372half-word (2-bytes), word (4 bytes), doubleword (8 bytes), or quad-word (16
373bytes).  Memory accesses within this address space are performed in big endian
374fashion by the SPARC. Memory accesses which are not properly aligned generate a
375"memory address not aligned" trap (type number 0x34). The following table lists
376the alignment requirements for a variety of data accesses:
377
378==============  ======================
379Data Type       Alignment Requirement
380==============  ======================
381byte            1
382half-word       2
383word            4
384doubleword      8
385quadword        16
386==============  ======================
387
388RTEMS currently does not support any SPARC Memory Management Units, therefore,
389virtual memory or segmentation systems involving the SPARC are not supported.
390
391Interrupt Processing
392====================
393
394RTEMS and associated documentation uses the terms interrupt and vector.  In the
395SPARC architecture, these terms correspond to traps and trap type,
396respectively.  The terms will be used interchangeably in this manual. Note that
397in the SPARC manuals, interrupts are a subset of the traps that are delivered
398to software interrupt handlers.
399
400Synchronous Versus Asynchronous Traps
401-------------------------------------
402
403The SPARC architecture includes two classes of traps: synchronous (precise) and
404asynchronous (deferred).  Asynchronous traps occur when an external event
405interrupts the processor.  These traps are not associated with any instruction
406executed by the processor and logically occur between instructions.  The
407instruction currently in the execute stage of the processor is allowed to
408complete although subsequent instructions are annulled.  The return address
409reported by the processor for asynchronous traps is the pair of instructions
410following the current instruction.
411
412Synchronous traps are caused by the actions of an instruction.  The trap
413stimulus in this case either occurs internally to the processor or is from an
414external signal that was provoked by the instruction.  These traps are taken
415immediately and the instruction that caused the trap is aborted before any
416state changes occur in the processor itself.  The return address reported by
417the processor for synchronous traps is the instruction which caused the trap
418and the following instruction.
419
420Vectoring of Interrupt Handler
421------------------------------
422
423Upon receipt of an interrupt the SPARC automatically performs the following
424actions:
425
426- The trap level is set. This provides access to a fresh set of privileged
427  trap-state registers used to save the current state, in effect, pushing a
428  frame on the trap stack.  TL <- TL + 1
429
430- Existing state is preserved
431  - TSTATE[TL].CCR <- CCR
432  - TSTATE[TL].ASI <- ASI
433  - TSTATE[TL].PSTATE <- PSTATE
434  - TSTATE[TL].CWP <- CWP
435  - TPC[TL] <- PC
436  - TNPC[TL] <- nPC
437
438- The trap type is preserved. TT[TL] <- the trap type
439
440- The PSTATE register is updated to a predefined state
441  - PSTATE.MM is unchanged
442  - PSTATE.RED <- 0
443  - PSTATE.PEF <- 1 if FPU is present, 0 otherwise
444  - PSTATE.AM <- 0 (address masking is turned off)
445  - PSTATE.PRIV <- 1 (the processor enters privileged mode)
446  - PSTATE.IE <- 0 (interrupts are disabled)
447  - PSTATE.AG <- 1 (global regs are replaced with alternate globals)
448  - PSTATE.CLE <- PSTATE.TLE (set endian mode for traps)
449
450- For a register-window trap only, CWP is set to point to the register
451  window that must be accessed by the trap-handler software, that is:
452
453  - If TT[TL] = 0x24 (a clean window trap), then CWP <- CWP + 1.
454  - If (0x80 <= TT[TL] <= 0xBF) (window spill trap), then CWP <- CWP +
455    CANSAVE + 2.
456  - If (0xC0 <= TT[TL] <= 0xFF) (window fill trap), then CWP <- CWP1.
457  - For non-register-window traps, CWP is not changed.
458
459- Control is transferred into the trap table:
460
461  - PC <- TBA<63:15> (TL>0) TT[TL] 0 0000
462  - nPC <- TBA<63:15> (TL>0) TT[TL] 0 0100
463  - where (TL>0) is 0 if TL = 0, and 1 if TL > 0.
464
465In order to safely invoke a subroutine during trap handling, traps must be
466enabled to allow for the possibility of register window overflow and underflow
467traps.
468
469If the interrupt handler was installed as an RTEMS interrupt handler, then upon
470receipt of the interrupt, the processor passes control to the RTEMS interrupt
471handler which performs the following actions:
472
473- saves the state of the interrupted task on it's stack,
474
475- switches the processor to trap level 0,
476
477- if this is the outermost (i.e. non-nested) interrupt, then the RTEMS
478  interrupt handler switches from the current stack to the interrupt stack,
479
480- enables traps,
481
482- invokes the vectors to a user interrupt service routine (ISR).
483
484Asynchronous interrupts are ignored while traps are disabled.  Synchronous
485traps which occur while traps are disabled may result in the CPU being forced
486into an error mode.
487
488A nested interrupt is processed similarly with the exception that the current
489stack need not be switched to the interrupt stack.
490
491Traps and Register Windows
492--------------------------
493
494XXX
495
496Interrupt Levels
497----------------
498
499Sixteen levels (0-15) of interrupt priorities are supported by the SPARC
500architecture with level fifteen (15) being the highest priority.  Level
501zero (0) indicates that interrupts are fully enabled.  Interrupt requests for
502interrupts with priorities less than or equal to the current interrupt mask
503level are ignored.
504
505Although RTEMS supports 256 interrupt levels, the SPARC only supports sixteen.
506RTEMS interrupt levels 0 through 15 directly correspond to SPARC processor
507interrupt levels.  All other RTEMS interrupt levels are undefined and their
508behavior is unpredictable.
509
510Disabling of Interrupts by RTEMS
511--------------------------------
512
513XXX
514
515Interrupt Stack
516---------------
517
518The SPARC architecture does not provide for a dedicated interrupt stack.  Thus
519by default, trap handlers would execute on the stack of the RTEMS task which
520they interrupted.  This artificially inflates the stack requirements for each
521task since EVERY task stack would have to include enough space to account for
522the worst case interrupt stack requirements in addition to it's own worst case
523usage.  RTEMS addresses this problem on the SPARC by providing a dedicated
524interrupt stack managed by software.
525
526During system initialization, RTEMS allocates the interrupt stack from the
527Workspace Area.  The amount of memory allocated for the interrupt stack is
528determined by the interrupt_stack_size field in the CPU Configuration Table.
529As part of processing a non-nested interrupt, RTEMS will switch to the
530interrupt stack before invoking the installed handler.
531
532Default Fatal Error Processing
533==============================
534
535Upon detection of a fatal error by either the application or RTEMS the fatal
536error manager is invoked.  The fatal error manager will invoke the
537user-supplied fatal error handlers.  If no user-supplied handlers are
538configured, the RTEMS provided default fatal error handler is invoked.  If the
539user-supplied fatal error handlers return to the executive the default fatal
540error handler is then invoked.  This chapter describes the precise operations
541of the default fatal error handler.
542
543Default Fatal Error Handler Operations
544--------------------------------------
545
546The default fatal error handler which is invoked by the fatal_error_occurred
547directive when there is no user handler configured or the user handler returns
548control to RTEMS.  The default fatal error handler disables processor
549interrupts to level 15, places the error code in g1, and goes into an infinite
550loop to simulate a halt processor instruction.
551
552Symmetric Multiprocessing
553=========================
554
555SMP is not supported.
556
557Thread-Local Storage
558====================
559
560Thread-local storage is supported.
561
562Board Support Packages
563======================
564
565An RTEMS Board Support Package (BSP) must be designed to support a particular
566processor and target board combination.  This chapter presents a discussion of
567SPARC specific BSP issues.  For more information on developing a BSP, refer to
568the chapter titled Board Support Packages in the RTEMS Applications User's
569Guide.
570
571HelenOS and Open Firmware
572-------------------------
573
574The provided BSPs make use of some bootstrap and low-level hardware code of the
575HelenOS operating system. These files can be found in the shared/helenos
576directory of the sparc64 bsp directory.  Consult the sources for more detailed
577information.
578
579The shared BSP code also uses the Open Firmware interface to re-use firmware
580code, primarily for console support and default trap handlers.
Note: See TracBrowser for help on using the repository browser.