source: rtems-docs/cpu-supplement/sparc64.rst

Last change on this file was fa5a960, checked in by Sebastian Huber <sebastian.huber@…>, on 02/05/19 at 10:43:10

Add copyright notices

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