Changeset 1c43e8c in rtems-docs


Ignore:
Timestamp:
Nov 19, 2018, 9:35:59 PM (5 months ago)
Author:
Marçal Comajoan Cara <mcomajoancara@…>
Branches:
master
Children:
80a2b75
Parents:
cf5f95e
git-author:
Marçal Comajoan Cara <mcomajoancara@…> (11/19/18 21:35:59)
git-committer:
Joel Sherrill <joel@…> (11/20/18 16:16:30)
Message:

cpu-supplement/sparc_v8_stacks_regwin.rst: Complete Formatting

This work was part of GCI 2018.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpu-supplement/sparc_v8_stacks_regwin.rst

    rcf5f95e r1c43e8c  
    2929current window pointer (CWP) which is part of the processor status
    3030register (PSR). This is a five bit value that can be decremented or
    31 incremented by the SAVE and RESTORE instructions, respectively. These
     31incremented by the ``save`` and ``restore`` instructions, respectively. These
    3232instructions are generally executed on procedure call and return
    3333(respectively). The idea is that the ``in`` registers contain incoming
     
    3535registers contain outgoing parameters, and the ``global`` registers contain
    3636values that vary little between executions. The register windows overlap
    37 partially, thus the ``out`` registers become renamed by SAVE to become the
     37partially, thus the ``out`` registers become renamed by ``save`` to become the
    3838``in`` registers of the called procedure. Thus, the memory traffic is reduced
    3939when going up and down the procedure call. Since this is a frequent
     
    5454.. table:: Table 1 - Visible Registers
    5555
    56     +----------------+------------+---------------+
    57     |   Register     |  Mnemonic  |   Register    |
    58     |   Group        |            |   Address     |
    59     +================+============+===============+
    60     +   ``global``   +  %g0-%g7   + r[0] - r[7]   +
    61     +----------------+------------+---------------+
    62     +    ``out``     +  %o0-%o7   + r[8] - r[15]  +
    63     +----------------+------------+---------------+
    64     +   ``local``    +  %l0-%l7   + r[16] - r[23] +
    65     +----------------+------------+---------------+
    66     +    ``in``      +  %i0-%i7   + r[24] - r[31] +
    67     +----------------+------------+---------------+
     56    +----------------+-------------------+------------------------+
     57    |   Register     |      Mnemonic     |        Register        |
     58    |   Group        |                   |        Address         |
     59    +================+===================+========================+
     60    +   ``global``   +  ``%g0``-``%g7``  +  ``r[0]`` - ``r[7]``   +
     61    +----------------+-------------------+------------------------+
     62    +    ``out``     +  ``%o0``-``%o7``  +  ``r[8]`` - ``r[15]``  +
     63    +----------------+-------------------+------------------------+
     64    +   ``local``    +  ``%l0``-``%l7``  +  ``r[16]`` - ``r[23]`` +
     65    +----------------+-------------------+------------------------+
     66    +    ``in``      +  ``%i0``-``%i7``  +  ``r[24]`` - ``r[31]`` +
     67    +----------------+-------------------+------------------------+
    6868
    6969
     
    7474wrap-around manner, thus window number 0 borders window number 7. The
    7575common cause of changing the current window, as pointed to by CWP, is
    76 the RESTORE and SAVE instructions, shown in the middle. Less common is
    77 the supervisor RETT instruction (return from trap) and the trap event
    78 (interrupt, exception, or TRAP instruction).
     76the ``restore`` and ``save`` instructions, shown in the middle. Less common is
     77the supervisor ``rett`` instruction (return from trap) and the trap event
     78(interrupt, exception, or ``trap`` instruction).
    7979
    8080.. figure:: ../images/cpu_supplement/sparcwin.png
     
    155155Particular compilers are likely to vary slightly.
    156156
    157 Note that globals %g2-%g4 are reserved for the "application", which
     157Note that globals ``%g2``-``%g4`` are reserved for the "application", which
    158158includes libraries and compiler. Thus, for example, libraries may
    159159overwrite these registers unless they've been compiled with suitable
    160160flags. Also, the "reserved" registers are presumed to be allocated
    161 (in the future) bottom-up, i.e. %g7 is currently the "safest" to use.
     161(in the future) bottom-up, i.e. ``%g7`` is currently the "safest" to use.
    162162
    163163Optimizing linkers and interpreters are examples that use global registers.
     
    167167
    168168The SPARC register windows are, naturally, intimately related to the
    169 stack. In particular, the stack pointer (%sp or %o6) must always point
     169stack. In particular, the stack pointer (``%sp`` or ``%o6``) must always point
    170170to a free block of 64 bytes. This area is used by the operating system
    171171(Solaris, SunOS, and Linux at least) to save the current ``local`` and
    172 ``in`` registers upon a system interrupt, exception, or trap instruction.
     172``in`` registers upon a system interrupt, exception, or ``trap`` instruction.
    173173(Note that this can occur at any time.)
    174174
     
    182182
    183183Note that the top boxes of figure 3 are addressed via the stack pointer
    184 (%sp), as positive offsets (including zero), and the bottom boxes are
     184(``%sp``), as positive offsets (including zero), and the bottom boxes are
    185185accessed over the frame pointer using negative offsets (excluding zero),
    186186and that the frame pointer is the old stack pointer. This scheme allows
     
    192192
    193193The clever nature of the stack and frame pointers is that they are always
    194 16 registers apart in the register windows. Thus, a SAVE instruction will
    195 make the current stack pointer into the frame pointer and, since the SAVE
    196 instruction also doubles as an ADD, create a new stack pointer. Figure 4
     19416 registers apart in the register windows. Thus, a ``save`` instruction will
     195make the current stack pointer into the frame pointer and, since the ``save``
     196instruction also doubles as an ``add``, create a new stack pointer. Figure 4
    197197illustrates what the top of a stack might look like during execution. (The
    198 listing is from the "pwin" command in the SimICS simulator.)
     198listing is from the ``pwin`` command in the SimICS simulator.)
    199199
    200200.. figure:: ../images/cpu_supplement/sample_stack_contents.png
     
    205205registers. Various events can cause the register windows to be "flushed"
    206206to memory, including most system calls. A programmer can force this
    207 update by using ST_FLUSH_WINDOWS trap, which also reduces the number of
     207update by using ``ST_FLUSH_WINDOWS`` trap, which also reduces the number of
    208208valid windows to the minimum of 1.
    209209
     
    230230*Figure 5 - Epilogue/prologue in procedures*
    231231
    232 The SAVE instruction decrements the CWP, as discussed earlier, and also
    233 performs an addition. The constant "C" that is used in the figure to
     232The ``save`` instruction decrements the CWP, as discussed earlier, and also
     233performs an addition. The constant ``C`` that is used in the figure to
    234234indicate the amount of space to make on the stack, and thus corresponds
    235235to the frame contents in Figure 3. The minimum is therefore the 16 words
    236 for the LOCAL and IN registers, i.e. (hex) 0x40 bytes.
    237 
    238 A confusing element of the SAVE instruction is that the source operands
     236for the ``local`` and ``in`` registers, i.e. (hex) 0x40 bytes.
     237
     238A confusing element of the ``save`` instruction is that the source operands
    239239(the first two parameters) are read from the old register window, and
    240240the destination operand (the rightmost parameter) is written to the new
    241 window. Thus, although "%sp" is indicated as both source and destination,
     241window. Thus, although ``%sp`` is indicated as both source and destination,
    242242the result is actually written into the stack pointer of the new window
    243243(the source stack pointer becomes renamed and is now the frame pointer).
     
    245245The return instructions are also a bit particular. ``ret`` is a synthetic
    246246instruction, corresponding to ``jmpl`` (jump linked). This instruction
    247 jumps to the address resulting from adding 8 to the %i7 register. The
     247jumps to the address resulting from adding 8 to the ``%i7`` register. The
    248248source instruction address (the address of the ``ret`` instruction itself)
    249 is written to the %g0 register, i.e. it is discarded.
     249is written to the ``%g0`` register, i.e. it is discarded.
    250250
    251251The ``restore`` instruction is similarly a synthetic instruction and is
     
    261261Again, the ``call`` instruction is synthetic, and is actually the same
    262262instruction that performs the return. This time, however, it is interested
    263 in saving the return address, into register %o7. Note that the delay
     263in saving the return address, into register ``%o7``. Note that the delay
    264264slot is often filled with an instruction related to the parameters,
    265265in this example it sets the first parameter to zero.
    266266
    267 Note also that the return value is also generally passed in %o0.
     267Note also that the return value is also generally passed in ``%o0``.
    268268
    269269Leaf procedures are different. A leaf procedure is an optimization that
     
    274274registers actually belong to the caller). See Figure 6.
    275275
    276 .. comment XXX FIX FORMATTING
    277 
    278276.. code-block:: c
    279277
     
    291289Note in the figure that there is only one instruction overhead, namely the
    292290``retl`` instruction. ``retl`` is also synthetic (return from leaf subroutine),
    293 is again a variant of the ``jmpl`` instruction, this time with %o7+8 as target.
     291is again a variant of the ``jmpl`` instruction, this time with ``%o7+8``
     292as target.
    294293
    295294Yet another variation of epilogue is caused by tail call elimination,
     
    320319*Figure 7 - Example of tail call elimination*
    321320
    322 Note that the call instruction overwrites register ``%o7`` with the program
     321Note that the ``call`` instruction overwrites register ``%o7`` with the program
    323322counter. Therefore the above code saves the old value of ``%o7``, and restores
    324 it in the delay slot of the call instruction. If the function ``call`` is
     323it in the delay slot of the ``call`` instruction. If the function ``call`` is
    325324register indirect, this twiddling with ``%o7`` can be avoided, but of course
    326 that form of call is slower on modern processors.
     325that form of ``call`` is slower on modern processors.
    327326
    328327The benefit of tail call elimination is to remove an indirection upon
     
    372371situations during execution. For example, GCC/GDB makes sure original
    373372parameter values are kept intact somewhere for future parsing of
    374 the procedure call stack. The live ``in`` registers other than %i0 are
    375 not touched. %i0 itself is copied into a free ``local`` register, and its
     373the procedure call stack. The live ``in`` registers other than ``%i0`` are
     374not touched. ``%i0`` itself is copied into a free ``local`` register, and its
    376375location is noted in the symbol file. (You can find out where variables
    377 reside by using the "info address" command in GDB.)
     376reside by using the ``info address`` command in GDB.)
    378377
    379378Given that much of the semantics relating to stack handling and procedure
     
    389388---------------------------------------
    390389
    391 When the SAVE instruction decrements the current window pointer (CWP)
     390When the ``save`` instruction decrements the current window pointer (CWP)
    392391so that it coincides with the invalid window in the window invalid mask
    393 (WIM), a window overflow trap occurs. Conversely, when the RESTORE or
    394 RETT instructions increment the CWP to coincide with the invalid window,
     392(WIM), a window overflow trap occurs. Conversely, when the ``restore`` or
     393``rett`` instructions increment the CWP to coincide with the invalid window,
    395394a window underflow trap occurs.
    396395
     
    403402works. (As far as I know, these are minimalistic handlers for SPARC
    404403V8). Note that there is no way to directly access window registers
    405 other than the current one, hence the code does additional save/restore
     404other than the current one, hence the code does additional ``save``/``restore``
    406405instructions. It's pretty tricky to understand the code, but figure 1
    407406should be of help.
Note: See TracChangeset for help on using the changeset viewer.