Home | History | Annotate | Line # | Download | only in doc
c-xtensa.texi revision 1.1.1.6.2.1
      1  1.1.1.6.2.1    martin @c Copyright (C) 2002-2020 Free Software Foundation, Inc.
      2          1.1     skrll @c This is part of the GAS manual.
      3          1.1     skrll @c For copying conditions, see the file as.texinfo.
      4          1.1     skrll @c
      5      1.1.1.3  christos @c man end
      6          1.1     skrll @ifset GENERIC
      7          1.1     skrll @page
      8          1.1     skrll @node Xtensa-Dependent
      9          1.1     skrll @chapter Xtensa Dependent Features
     10          1.1     skrll @end ifset
     11          1.1     skrll @ifclear GENERIC
     12          1.1     skrll @node Machine Dependencies
     13          1.1     skrll @chapter Xtensa Dependent Features
     14          1.1     skrll @end ifclear
     15          1.1     skrll 
     16          1.1     skrll @cindex Xtensa architecture
     17          1.1     skrll This chapter covers features of the @sc{gnu} assembler that are specific
     18          1.1     skrll to the Xtensa architecture.  For details about the Xtensa instruction
     19          1.1     skrll set, please consult the @cite{Xtensa Instruction Set Architecture (ISA)
     20          1.1     skrll Reference Manual}.
     21          1.1     skrll 
     22          1.1     skrll @menu
     23          1.1     skrll * Xtensa Options::              Command-line Options.
     24          1.1     skrll * Xtensa Syntax::               Assembler Syntax for Xtensa Processors.
     25          1.1     skrll * Xtensa Optimizations::        Assembler Optimizations.
     26          1.1     skrll * Xtensa Relaxation::           Other Automatic Transformations.
     27          1.1     skrll * Xtensa Directives::           Directives for Xtensa Processors.
     28          1.1     skrll @end menu
     29          1.1     skrll 
     30          1.1     skrll @node Xtensa Options
     31  1.1.1.6.2.1    martin @section Command-line Options
     32          1.1     skrll 
     33      1.1.1.3  christos @c man begin OPTIONS
     34      1.1.1.3  christos @table @gcctabopt
     35          1.1     skrll 
     36          1.1     skrll @item --text-section-literals | --no-text-section-literals
     37          1.1     skrll @kindex --text-section-literals
     38          1.1     skrll @kindex --no-text-section-literals
     39          1.1     skrll Control the treatment of literal pools.  The default is
     40          1.1     skrll @samp{--no-@-text-@-section-@-literals}, which places literals in
     41          1.1     skrll separate sections in the output file.  This allows the literal pool to be
     42          1.1     skrll placed in a data RAM/ROM.  With @samp{--text-@-section-@-literals}, the
     43          1.1     skrll literals are interspersed in the text section in order to keep them as
     44          1.1     skrll close as possible to their references.  This may be necessary for large
     45          1.1     skrll assembly files, where the literals would otherwise be out of range of the
     46      1.1.1.4  christos @code{L32R} instructions in the text section.  Literals are grouped into
     47      1.1.1.4  christos pools following @code{.literal_position} directives or preceding
     48      1.1.1.4  christos @code{ENTRY} instructions.  These options only affect literals referenced
     49      1.1.1.4  christos via PC-relative @code{L32R} instructions; literals for absolute mode
     50      1.1.1.4  christos @code{L32R} instructions are handled separately.
     51      1.1.1.4  christos @xref{Literal Directive, ,literal}.
     52      1.1.1.4  christos 
     53      1.1.1.4  christos @item --auto-litpools | --no-auto-litpools
     54      1.1.1.4  christos @kindex --auto-litpools
     55      1.1.1.4  christos @kindex --no-auto-litpools
     56      1.1.1.4  christos Control the treatment of literal pools.  The default is
     57      1.1.1.4  christos @samp{--no-@-auto-@-litpools}, which in the absence of
     58      1.1.1.4  christos @samp{--text-@-section-@-literals} places literals in separate sections
     59      1.1.1.4  christos in the output file.  This allows the literal pool to be placed in a data
     60      1.1.1.4  christos RAM/ROM.  With @samp{--auto-@-litpools}, the literals are interspersed
     61      1.1.1.4  christos in the text section in order to keep them as close as possible to their
     62      1.1.1.4  christos references, explicit @code{.literal_position} directives are not
     63      1.1.1.4  christos required.  This may be necessary for very large functions, where single
     64      1.1.1.4  christos literal pool at the beginning of the function may not be reachable by
     65      1.1.1.4  christos @code{L32R} instructions at the end.  These options only affect
     66          1.1     skrll literals referenced via PC-relative @code{L32R} instructions; literals
     67          1.1     skrll for absolute mode @code{L32R} instructions are handled separately.
     68      1.1.1.4  christos When used together with @samp{--text-@-section-@-literals},
     69      1.1.1.4  christos @samp{--auto-@-litpools} takes precedence.
     70          1.1     skrll @xref{Literal Directive, ,literal}.
     71          1.1     skrll 
     72          1.1     skrll @item --absolute-literals | --no-absolute-literals
     73          1.1     skrll @kindex --absolute-literals
     74          1.1     skrll @kindex --no-absolute-literals
     75          1.1     skrll Indicate to the assembler whether @code{L32R} instructions use absolute
     76          1.1     skrll or PC-relative addressing.  If the processor includes the absolute
     77          1.1     skrll addressing option, the default is to use absolute @code{L32R}
     78          1.1     skrll relocations.  Otherwise, only the PC-relative @code{L32R} relocations
     79          1.1     skrll can be used.
     80          1.1     skrll 
     81          1.1     skrll @item --target-align | --no-target-align
     82          1.1     skrll @kindex --target-align
     83          1.1     skrll @kindex --no-target-align
     84          1.1     skrll Enable or disable automatic alignment to reduce branch penalties at some
     85          1.1     skrll expense in code size.  @xref{Xtensa Automatic Alignment, ,Automatic
     86          1.1     skrll Instruction Alignment}.  This optimization is enabled by default.  Note
     87          1.1     skrll that the assembler will always align instructions like @code{LOOP} that
     88          1.1     skrll have fixed alignment requirements.
     89          1.1     skrll 
     90          1.1     skrll @item --longcalls | --no-longcalls
     91          1.1     skrll @kindex --longcalls
     92          1.1     skrll @kindex --no-longcalls
     93          1.1     skrll Enable or disable transformation of call instructions to allow calls
     94          1.1     skrll across a greater range of addresses.  @xref{Xtensa Call Relaxation,
     95          1.1     skrll ,Function Call Relaxation}.  This option should be used when call
     96          1.1     skrll targets can potentially be out of range.  It may degrade both code size
     97          1.1     skrll and performance, but the linker can generally optimize away the
     98          1.1     skrll unnecessary overhead when a call ends up within range.  The default is
     99          1.1     skrll @samp{--no-@-longcalls}.
    100          1.1     skrll 
    101          1.1     skrll @item --transform | --no-transform
    102          1.1     skrll @kindex --transform
    103          1.1     skrll @kindex --no-transform
    104          1.1     skrll Enable or disable all assembler transformations of Xtensa instructions,
    105          1.1     skrll including both relaxation and optimization.  The default is
    106          1.1     skrll @samp{--transform}; @samp{--no-transform} should only be used in the
    107          1.1     skrll rare cases when the instructions must be exactly as specified in the
    108          1.1     skrll assembly source.  Using @samp{--no-transform} causes out of range
    109          1.1     skrll instruction operands to be errors.
    110          1.1     skrll 
    111          1.1     skrll @item --rename-section @var{oldname}=@var{newname}
    112          1.1     skrll @kindex --rename-section
    113          1.1     skrll Rename the @var{oldname} section to @var{newname}.  This option can be used
    114          1.1     skrll multiple times to rename multiple sections.
    115      1.1.1.4  christos 
    116      1.1.1.4  christos @item --trampolines | --no-trampolines
    117      1.1.1.4  christos @kindex --trampolines
    118      1.1.1.4  christos @kindex --no-trampolines
    119      1.1.1.4  christos Enable or disable transformation of jump instructions to allow jumps
    120      1.1.1.4  christos across a greater range of addresses.  @xref{Xtensa Jump Relaxation,
    121      1.1.1.4  christos ,Jump Trampolines}.  This option should be used when jump targets can
    122      1.1.1.4  christos potentially be out of range.  In the absence of such jumps this option
    123      1.1.1.4  christos does not affect code size or performance.  The default is
    124      1.1.1.4  christos @samp{--trampolines}.
    125          1.1     skrll @end table
    126          1.1     skrll 
    127      1.1.1.3  christos @c man end
    128      1.1.1.3  christos 
    129          1.1     skrll @node Xtensa Syntax
    130          1.1     skrll @section Assembler Syntax
    131          1.1     skrll @cindex syntax, Xtensa assembler
    132          1.1     skrll @cindex Xtensa assembler syntax
    133          1.1     skrll @cindex FLIX syntax
    134          1.1     skrll 
    135          1.1     skrll Block comments are delimited by @samp{/*} and @samp{*/}.  End of line
    136          1.1     skrll comments may be introduced with either @samp{#} or @samp{//}.
    137          1.1     skrll 
    138      1.1.1.3  christos If a @samp{#} appears as the first character of a line then the whole
    139      1.1.1.3  christos line is treated as a comment, but in this case the line could also be
    140      1.1.1.3  christos a logical line number directive (@pxref{Comments}) or a preprocessor
    141      1.1.1.3  christos control command (@pxref{Preprocessing}).
    142      1.1.1.3  christos 
    143          1.1     skrll Instructions consist of a leading opcode or macro name followed by
    144          1.1     skrll whitespace and an optional comma-separated list of operands:
    145          1.1     skrll 
    146          1.1     skrll @smallexample
    147          1.1     skrll @var{opcode} [@var{operand}, @dots{}]
    148          1.1     skrll @end smallexample
    149          1.1     skrll 
    150      1.1.1.3  christos Instructions must be separated by a newline or semicolon (@samp{;}).
    151          1.1     skrll 
    152          1.1     skrll FLIX instructions, which bundle multiple opcodes together in a single
    153          1.1     skrll instruction, are specified by enclosing the bundled opcodes inside
    154          1.1     skrll braces:
    155          1.1     skrll 
    156          1.1     skrll @smallexample
    157          1.1     skrll @group
    158          1.1     skrll @{
    159          1.1     skrll [@var{format}]
    160          1.1     skrll @var{opcode0} [@var{operands}]
    161          1.1     skrll @end group
    162          1.1     skrll @var{opcode1} [@var{operands}]
    163          1.1     skrll @group
    164          1.1     skrll @var{opcode2} [@var{operands}]
    165          1.1     skrll @dots{}
    166          1.1     skrll @}
    167          1.1     skrll @end group
    168          1.1     skrll @end smallexample
    169          1.1     skrll 
    170          1.1     skrll The opcodes in a FLIX instruction are listed in the same order as the
    171          1.1     skrll corresponding instruction slots in the TIE format declaration.
    172          1.1     skrll Directives and labels are not allowed inside the braces of a FLIX
    173          1.1     skrll instruction.  A particular TIE format name can optionally be specified
    174          1.1     skrll immediately after the opening brace, but this is usually unnecessary.
    175          1.1     skrll The assembler will automatically search for a format that can encode the
    176          1.1     skrll specified opcodes, so the format name need only be specified in rare
    177          1.1     skrll cases where there is more than one applicable format and where it
    178          1.1     skrll matters which of those formats is used.  A FLIX instruction can also be
    179          1.1     skrll specified on a single line by separating the opcodes with semicolons:
    180          1.1     skrll 
    181          1.1     skrll @smallexample
    182          1.1     skrll @{ [@var{format};] @var{opcode0} [@var{operands}]; @var{opcode1} [@var{operands}]; @var{opcode2} [@var{operands}]; @dots{} @}
    183          1.1     skrll @end smallexample
    184          1.1     skrll 
    185          1.1     skrll If an opcode can only be encoded in a FLIX instruction but is not
    186          1.1     skrll specified as part of a FLIX bundle, the assembler will choose the
    187          1.1     skrll smallest format where the opcode can be encoded and
    188          1.1     skrll will fill unused instruction slots with no-ops.
    189          1.1     skrll 
    190          1.1     skrll @menu
    191          1.1     skrll * Xtensa Opcodes::              Opcode Naming Conventions.
    192          1.1     skrll * Xtensa Registers::            Register Naming.
    193          1.1     skrll @end menu
    194          1.1     skrll 
    195          1.1     skrll @node Xtensa Opcodes
    196          1.1     skrll @subsection Opcode Names
    197          1.1     skrll @cindex Xtensa opcode names
    198          1.1     skrll @cindex opcode names, Xtensa
    199          1.1     skrll 
    200          1.1     skrll See the @cite{Xtensa Instruction Set Architecture (ISA) Reference
    201          1.1     skrll Manual} for a complete list of opcodes and descriptions of their
    202          1.1     skrll semantics.
    203          1.1     skrll 
    204          1.1     skrll @cindex _ opcode prefix
    205          1.1     skrll If an opcode name is prefixed with an underscore character (@samp{_}),
    206          1.1     skrll @command{@value{AS}} will not transform that instruction in any way.  The
    207          1.1     skrll underscore prefix disables both optimization (@pxref{Xtensa
    208          1.1     skrll Optimizations, ,Xtensa Optimizations}) and relaxation (@pxref{Xtensa
    209          1.1     skrll Relaxation, ,Xtensa Relaxation}) for that particular instruction.  Only
    210          1.1     skrll use the underscore prefix when it is essential to select the exact
    211          1.1     skrll opcode produced by the assembler.  Using this feature unnecessarily
    212          1.1     skrll makes the code less efficient by disabling assembler optimization and
    213          1.1     skrll less flexible by disabling relaxation.
    214          1.1     skrll 
    215          1.1     skrll Note that this special handling of underscore prefixes only applies to
    216          1.1     skrll Xtensa opcodes, not to either built-in macros or user-defined macros.
    217          1.1     skrll When an underscore prefix is used with a macro (e.g., @code{_MOV}), it
    218          1.1     skrll refers to a different macro.  The assembler generally provides built-in
    219          1.1     skrll macros both with and without the underscore prefix, where the underscore
    220          1.1     skrll versions behave as if the underscore carries through to the instructions
    221          1.1     skrll in the macros.  For example, @code{_MOV} may expand to @code{_MOV.N}@.
    222          1.1     skrll 
    223          1.1     skrll The underscore prefix only applies to individual instructions, not to
    224          1.1     skrll series of instructions.  For example, if a series of instructions have
    225          1.1     skrll underscore prefixes, the assembler will not transform the individual
    226          1.1     skrll instructions, but it may insert other instructions between them (e.g.,
    227          1.1     skrll to align a @code{LOOP} instruction).  To prevent the assembler from
    228          1.1     skrll modifying a series of instructions as a whole, use the
    229          1.1     skrll @code{no-transform} directive.  @xref{Transform Directive, ,transform}.
    230          1.1     skrll 
    231          1.1     skrll @node Xtensa Registers
    232          1.1     skrll @subsection Register Names
    233          1.1     skrll @cindex Xtensa register names
    234          1.1     skrll @cindex register names, Xtensa
    235          1.1     skrll @cindex sp register
    236          1.1     skrll 
    237          1.1     skrll The assembly syntax for a register file entry is the ``short'' name for
    238          1.1     skrll a TIE register file followed by the index into that register file.  For
    239          1.1     skrll example, the general-purpose @code{AR} register file has a short name of
    240          1.1     skrll @code{a}, so these registers are named @code{a0}@dots{}@code{a15}.
    241          1.1     skrll As a special feature, @code{sp} is also supported as a synonym for
    242          1.1     skrll @code{a1}.  Additional registers may be added by processor configuration
    243          1.1     skrll options and by designer-defined TIE extensions.  An initial @samp{$}
    244          1.1     skrll character is optional in all register names.
    245          1.1     skrll 
    246          1.1     skrll @node Xtensa Optimizations
    247          1.1     skrll @section Xtensa Optimizations
    248          1.1     skrll @cindex optimizations
    249          1.1     skrll 
    250          1.1     skrll The optimizations currently supported by @command{@value{AS}} are
    251          1.1     skrll generation of density instructions where appropriate and automatic
    252          1.1     skrll branch target alignment.
    253          1.1     skrll 
    254          1.1     skrll @menu
    255          1.1     skrll * Density Instructions::        Using Density Instructions.
    256          1.1     skrll * Xtensa Automatic Alignment::  Automatic Instruction Alignment.
    257          1.1     skrll @end menu
    258          1.1     skrll 
    259          1.1     skrll @node Density Instructions
    260          1.1     skrll @subsection Using Density Instructions
    261          1.1     skrll @cindex density instructions
    262          1.1     skrll 
    263          1.1     skrll The Xtensa instruction set has a code density option that provides
    264          1.1     skrll 16-bit versions of some of the most commonly used opcodes.  Use of these
    265          1.1     skrll opcodes can significantly reduce code size.  When possible, the
    266          1.1     skrll assembler automatically translates instructions from the core
    267          1.1     skrll Xtensa instruction set into equivalent instructions from the Xtensa code
    268          1.1     skrll density option.  This translation can be disabled by using underscore
    269          1.1     skrll prefixes (@pxref{Xtensa Opcodes, ,Opcode Names}), by using the
    270          1.1     skrll @samp{--no-transform} command-line option (@pxref{Xtensa Options, ,Command
    271          1.1     skrll Line Options}), or by using the @code{no-transform} directive
    272          1.1     skrll (@pxref{Transform Directive, ,transform}).
    273          1.1     skrll 
    274          1.1     skrll It is a good idea @emph{not} to use the density instructions directly.
    275          1.1     skrll The assembler will automatically select dense instructions where
    276          1.1     skrll possible.  If you later need to use an Xtensa processor without the code
    277          1.1     skrll density option, the same assembly code will then work without modification.
    278          1.1     skrll 
    279          1.1     skrll @node Xtensa Automatic Alignment
    280          1.1     skrll @subsection Automatic Instruction Alignment
    281          1.1     skrll @cindex alignment of @code{LOOP} instructions
    282          1.1     skrll @cindex alignment of branch targets
    283          1.1     skrll @cindex @code{LOOP} instructions, alignment
    284          1.1     skrll @cindex branch target alignment
    285          1.1     skrll 
    286          1.1     skrll The Xtensa assembler will automatically align certain instructions, both
    287          1.1     skrll to optimize performance and to satisfy architectural requirements.
    288          1.1     skrll 
    289          1.1     skrll As an optimization to improve performance, the assembler attempts to
    290          1.1     skrll align branch targets so they do not cross instruction fetch boundaries.
    291          1.1     skrll (Xtensa processors can be configured with either 32-bit or 64-bit
    292          1.1     skrll instruction fetch widths.)  An
    293          1.1     skrll instruction immediately following a call is treated as a branch target
    294          1.1     skrll in this context, because it will be the target of a return from the
    295          1.1     skrll call.  This alignment has the potential to reduce branch penalties at
    296          1.1     skrll some expense in code size.
    297          1.1     skrll This optimization is enabled by default.  You can disable it with the
    298          1.1     skrll @samp{--no-target-@-align} command-line option (@pxref{Xtensa Options,
    299  1.1.1.6.2.1    martin ,Command-line Options}).
    300          1.1     skrll 
    301          1.1     skrll The target alignment optimization is done without adding instructions
    302          1.1     skrll that could increase the execution time of the program.  If there are
    303          1.1     skrll density instructions in the code preceding a target, the assembler can
    304          1.1     skrll change the target alignment by widening some of those instructions to
    305          1.1     skrll the equivalent 24-bit instructions.  Extra bytes of padding can be
    306          1.1     skrll inserted immediately following unconditional jump and return
    307          1.1     skrll instructions.
    308          1.1     skrll This approach is usually successful in aligning many, but not all,
    309          1.1     skrll branch targets.
    310          1.1     skrll 
    311          1.1     skrll The @code{LOOP} family of instructions must be aligned such that the
    312          1.1     skrll first instruction in the loop body does not cross an instruction fetch
    313          1.1     skrll boundary (e.g., with a 32-bit fetch width, a @code{LOOP} instruction
    314          1.1     skrll must be on either a 1 or 2 mod 4 byte boundary).  The assembler knows
    315          1.1     skrll about this restriction and inserts the minimal number of 2 or 3 byte
    316          1.1     skrll no-op instructions to satisfy it.  When no-op instructions are added,
    317          1.1     skrll any label immediately preceding the original loop will be moved in order
    318          1.1     skrll to refer to the loop instruction, not the newly generated no-op
    319          1.1     skrll instruction.  To preserve binary compatibility across processors with
    320          1.1     skrll different fetch widths, the assembler conservatively assumes a 32-bit
    321          1.1     skrll fetch width when aligning @code{LOOP} instructions (except if the first
    322          1.1     skrll instruction in the loop is a 64-bit instruction).
    323          1.1     skrll 
    324          1.1     skrll Previous versions of the assembler automatically aligned @code{ENTRY}
    325          1.1     skrll instructions to 4-byte boundaries, but that alignment is now the
    326          1.1     skrll programmer's responsibility.
    327          1.1     skrll 
    328          1.1     skrll @node Xtensa Relaxation
    329          1.1     skrll @section Xtensa Relaxation
    330          1.1     skrll @cindex relaxation
    331          1.1     skrll 
    332          1.1     skrll When an instruction operand is outside the range allowed for that
    333          1.1     skrll particular instruction field, @command{@value{AS}} can transform the code
    334          1.1     skrll to use a functionally-equivalent instruction or sequence of
    335          1.1     skrll instructions.  This process is known as @dfn{relaxation}.  This is
    336          1.1     skrll typically done for branch instructions because the distance of the
    337          1.1     skrll branch targets is not known until assembly-time.  The Xtensa assembler
    338          1.1     skrll offers branch relaxation and also extends this concept to function
    339          1.1     skrll calls, @code{MOVI} instructions and other instructions with immediate
    340          1.1     skrll fields.
    341          1.1     skrll 
    342          1.1     skrll @menu
    343          1.1     skrll * Xtensa Branch Relaxation::        Relaxation of Branches.
    344          1.1     skrll * Xtensa Call Relaxation::          Relaxation of Function Calls.
    345      1.1.1.4  christos * Xtensa Jump Relaxation::          Relaxation of Jumps.
    346          1.1     skrll * Xtensa Immediate Relaxation::     Relaxation of other Immediate Fields.
    347          1.1     skrll @end menu
    348          1.1     skrll 
    349          1.1     skrll @node Xtensa Branch Relaxation
    350          1.1     skrll @subsection Conditional Branch Relaxation
    351          1.1     skrll @cindex relaxation of branch instructions
    352          1.1     skrll @cindex branch instructions, relaxation
    353          1.1     skrll 
    354          1.1     skrll When the target of a branch is too far away from the branch itself,
    355          1.1     skrll i.e., when the offset from the branch to the target is too large to fit
    356          1.1     skrll in the immediate field of the branch instruction, it may be necessary to
    357          1.1     skrll replace the branch with a branch around a jump.  For example,
    358          1.1     skrll 
    359          1.1     skrll @smallexample
    360          1.1     skrll     beqz    a2, L
    361          1.1     skrll @end smallexample
    362          1.1     skrll 
    363          1.1     skrll may result in:
    364          1.1     skrll 
    365          1.1     skrll @smallexample
    366          1.1     skrll @group
    367          1.1     skrll     bnez.n  a2, M
    368          1.1     skrll     j L
    369          1.1     skrll M:
    370          1.1     skrll @end group
    371          1.1     skrll @end smallexample
    372          1.1     skrll 
    373          1.1     skrll (The @code{BNEZ.N} instruction would be used in this example only if the
    374          1.1     skrll density option is available.  Otherwise, @code{BNEZ} would be used.)
    375          1.1     skrll 
    376          1.1     skrll This relaxation works well because the unconditional jump instruction
    377          1.1     skrll has a much larger offset range than the various conditional branches.
    378          1.1     skrll However, an error will occur if a branch target is beyond the range of a
    379          1.1     skrll jump instruction.  @command{@value{AS}} cannot relax unconditional jumps.
    380          1.1     skrll Similarly, an error will occur if the original input contains an
    381          1.1     skrll unconditional jump to a target that is out of range.
    382          1.1     skrll 
    383          1.1     skrll Branch relaxation is enabled by default.  It can be disabled by using
    384          1.1     skrll underscore prefixes (@pxref{Xtensa Opcodes, ,Opcode Names}), the
    385          1.1     skrll @samp{--no-transform} command-line option (@pxref{Xtensa Options,
    386  1.1.1.6.2.1    martin ,Command-line Options}), or the @code{no-transform} directive
    387          1.1     skrll (@pxref{Transform Directive, ,transform}).
    388          1.1     skrll 
    389          1.1     skrll @node Xtensa Call Relaxation
    390          1.1     skrll @subsection Function Call Relaxation
    391          1.1     skrll @cindex relaxation of call instructions
    392          1.1     skrll @cindex call instructions, relaxation
    393          1.1     skrll 
    394          1.1     skrll Function calls may require relaxation because the Xtensa immediate call
    395          1.1     skrll instructions (@code{CALL0}, @code{CALL4}, @code{CALL8} and
    396          1.1     skrll @code{CALL12}) provide a PC-relative offset of only 512 Kbytes in either
    397          1.1     skrll direction.  For larger programs, it may be necessary to use indirect
    398          1.1     skrll calls (@code{CALLX0}, @code{CALLX4}, @code{CALLX8} and @code{CALLX12})
    399          1.1     skrll where the target address is specified in a register.  The Xtensa
    400          1.1     skrll assembler can automatically relax immediate call instructions into
    401          1.1     skrll indirect call instructions.  This relaxation is done by loading the
    402          1.1     skrll address of the called function into the callee's return address register
    403          1.1     skrll and then using a @code{CALLX} instruction.  So, for example:
    404          1.1     skrll 
    405          1.1     skrll @smallexample
    406          1.1     skrll     call8 func
    407          1.1     skrll @end smallexample
    408          1.1     skrll 
    409          1.1     skrll might be relaxed to:
    410          1.1     skrll 
    411          1.1     skrll @smallexample
    412          1.1     skrll @group
    413          1.1     skrll     .literal .L1, func
    414          1.1     skrll     l32r    a8, .L1
    415          1.1     skrll     callx8  a8
    416          1.1     skrll @end group
    417          1.1     skrll @end smallexample
    418          1.1     skrll 
    419          1.1     skrll Because the addresses of targets of function calls are not generally
    420          1.1     skrll known until link-time, the assembler must assume the worst and relax all
    421          1.1     skrll the calls to functions in other source files, not just those that really
    422          1.1     skrll will be out of range.  The linker can recognize calls that were
    423          1.1     skrll unnecessarily relaxed, and it will remove the overhead introduced by the
    424          1.1     skrll assembler for those cases where direct calls are sufficient.
    425          1.1     skrll 
    426          1.1     skrll Call relaxation is disabled by default because it can have a negative
    427          1.1     skrll effect on both code size and performance, although the linker can
    428          1.1     skrll usually eliminate the unnecessary overhead.  If a program is too large
    429          1.1     skrll and some of the calls are out of range, function call relaxation can be
    430          1.1     skrll enabled using the @samp{--longcalls} command-line option or the
    431          1.1     skrll @code{longcalls} directive (@pxref{Longcalls Directive, ,longcalls}).
    432          1.1     skrll 
    433      1.1.1.4  christos @node Xtensa Jump Relaxation
    434      1.1.1.4  christos @subsection Jump Relaxation
    435      1.1.1.4  christos @cindex relaxation of jump instructions
    436      1.1.1.4  christos @cindex jump instructions, relaxation
    437      1.1.1.4  christos 
    438      1.1.1.4  christos Jump instruction may require relaxation because the Xtensa jump instruction
    439      1.1.1.4  christos (@code{J}) provide a PC-relative offset of only 128 Kbytes in either
    440      1.1.1.4  christos direction.  One option is to use jump long (@code{J.L}) instruction, which
    441      1.1.1.4  christos depending on jump distance may be assembled as jump (@code{J}) or indirect
    442      1.1.1.4  christos jump (@code{JX}).  However it needs a free register.  When there's no spare
    443      1.1.1.4  christos register it is possible to plant intermediate jump sites (trampolines)
    444      1.1.1.4  christos between the jump instruction and its target.  These sites may be located in
    445      1.1.1.4  christos areas unreachable by normal code execution flow, in that case they only
    446      1.1.1.4  christos contain intermediate jumps, or they may be inserted in the middle of code
    447      1.1.1.4  christos block, in which case there's an additional jump from the beginning of the
    448      1.1.1.4  christos trampoline to the instruction past its end.  So, for example:
    449      1.1.1.4  christos 
    450      1.1.1.4  christos @smallexample
    451      1.1.1.4  christos @group
    452      1.1.1.4  christos     j 1f
    453      1.1.1.4  christos     ...
    454      1.1.1.4  christos     retw
    455      1.1.1.4  christos     ...
    456      1.1.1.4  christos     mov a10, a2
    457      1.1.1.4  christos     call8 func
    458      1.1.1.4  christos     ...
    459      1.1.1.4  christos 1:
    460      1.1.1.4  christos     ...
    461      1.1.1.4  christos @end group
    462      1.1.1.4  christos @end smallexample
    463      1.1.1.4  christos 
    464      1.1.1.4  christos might be relaxed to:
    465      1.1.1.4  christos 
    466      1.1.1.4  christos @smallexample
    467      1.1.1.4  christos @group
    468      1.1.1.4  christos     j .L0_TR_1
    469      1.1.1.4  christos     ...
    470      1.1.1.4  christos     retw
    471      1.1.1.4  christos .L0_TR_1:
    472      1.1.1.4  christos     j 1f
    473      1.1.1.4  christos     ...
    474      1.1.1.4  christos     mov a10, a2
    475      1.1.1.4  christos     call8 func
    476      1.1.1.4  christos     ...
    477      1.1.1.4  christos 1:
    478      1.1.1.4  christos     ...
    479      1.1.1.4  christos @end group
    480      1.1.1.4  christos @end smallexample
    481      1.1.1.4  christos 
    482      1.1.1.4  christos or to:
    483      1.1.1.4  christos 
    484      1.1.1.4  christos @smallexample
    485      1.1.1.4  christos @group
    486      1.1.1.4  christos     j .L0_TR_1
    487      1.1.1.4  christos     ...
    488      1.1.1.4  christos     retw
    489      1.1.1.4  christos     ...
    490      1.1.1.4  christos     mov a10, a2
    491      1.1.1.4  christos     j .L0_TR_0
    492      1.1.1.4  christos .L0_TR_1:
    493      1.1.1.4  christos     j 1f
    494      1.1.1.4  christos .L0_TR_0:
    495      1.1.1.4  christos     call8 func
    496      1.1.1.4  christos     ...
    497      1.1.1.4  christos 1:
    498      1.1.1.4  christos     ...
    499      1.1.1.4  christos @end group
    500      1.1.1.4  christos @end smallexample
    501      1.1.1.4  christos 
    502      1.1.1.6  christos The Xtensa assembler uses trampolines with jump around only when it cannot
    503      1.1.1.4  christos find suitable unreachable trampoline.  There may be multiple trampolines
    504      1.1.1.4  christos between the jump instruction and its target.
    505      1.1.1.4  christos 
    506      1.1.1.4  christos This relaxation does not apply to jumps to undefined symbols, assuming they
    507      1.1.1.4  christos will reach their targets once resolved.
    508      1.1.1.4  christos 
    509      1.1.1.4  christos Jump relaxation is enabled by default because it does not affect code size
    510      1.1.1.4  christos or performance while the code itself is small.  This relaxation may be
    511      1.1.1.4  christos disabled completely with @samp{--no-trampolines} or @samp{--no-transform}
    512  1.1.1.6.2.1    martin command-line options (@pxref{Xtensa Options, ,Command-line Options}).
    513      1.1.1.4  christos 
    514          1.1     skrll @node Xtensa Immediate Relaxation
    515          1.1     skrll @subsection Other Immediate Field Relaxation
    516          1.1     skrll @cindex immediate fields, relaxation
    517          1.1     skrll @cindex relaxation of immediate fields
    518          1.1     skrll 
    519          1.1     skrll The assembler normally performs the following other relaxations.  They
    520          1.1     skrll can be disabled by using underscore prefixes (@pxref{Xtensa Opcodes,
    521          1.1     skrll ,Opcode Names}), the @samp{--no-transform} command-line option
    522  1.1.1.6.2.1    martin (@pxref{Xtensa Options, ,Command-line Options}), or the
    523          1.1     skrll @code{no-transform} directive (@pxref{Transform Directive, ,transform}).
    524          1.1     skrll 
    525          1.1     skrll @cindex @code{MOVI} instructions, relaxation
    526          1.1     skrll @cindex relaxation of @code{MOVI} instructions
    527          1.1     skrll The @code{MOVI} machine instruction can only materialize values in the
    528          1.1     skrll range from -2048 to 2047.  Values outside this range are best
    529          1.1     skrll materialized with @code{L32R} instructions.  Thus:
    530          1.1     skrll 
    531          1.1     skrll @smallexample
    532          1.1     skrll     movi a0, 100000
    533          1.1     skrll @end smallexample
    534          1.1     skrll 
    535          1.1     skrll is assembled into the following machine code:
    536          1.1     skrll 
    537          1.1     skrll @smallexample
    538          1.1     skrll @group
    539          1.1     skrll     .literal .L1, 100000
    540          1.1     skrll     l32r a0, .L1
    541          1.1     skrll @end group
    542          1.1     skrll @end smallexample
    543          1.1     skrll 
    544          1.1     skrll @cindex @code{L8UI} instructions, relaxation
    545          1.1     skrll @cindex @code{L16SI} instructions, relaxation
    546          1.1     skrll @cindex @code{L16UI} instructions, relaxation
    547          1.1     skrll @cindex @code{L32I} instructions, relaxation
    548          1.1     skrll @cindex relaxation of @code{L8UI} instructions
    549          1.1     skrll @cindex relaxation of @code{L16SI} instructions
    550          1.1     skrll @cindex relaxation of @code{L16UI} instructions
    551          1.1     skrll @cindex relaxation of @code{L32I} instructions
    552          1.1     skrll The @code{L8UI} machine instruction can only be used with immediate
    553          1.1     skrll offsets in the range from 0 to 255. The @code{L16SI} and @code{L16UI}
    554          1.1     skrll machine instructions can only be used with offsets from 0 to 510.  The
    555          1.1     skrll @code{L32I} machine instruction can only be used with offsets from 0 to
    556          1.1     skrll 1020.  A load offset outside these ranges can be materialized with
    557          1.1     skrll an @code{L32R} instruction if the destination register of the load
    558          1.1     skrll is different than the source address register.  For example:
    559          1.1     skrll 
    560          1.1     skrll @smallexample
    561          1.1     skrll     l32i a1, a0, 2040
    562          1.1     skrll @end smallexample
    563          1.1     skrll 
    564          1.1     skrll is translated to:
    565          1.1     skrll 
    566          1.1     skrll @smallexample
    567          1.1     skrll @group
    568          1.1     skrll     .literal .L1, 2040
    569          1.1     skrll     l32r a1, .L1
    570          1.1     skrll @end group
    571          1.1     skrll @group
    572          1.1     skrll     add a1, a0, a1
    573          1.1     skrll     l32i a1, a1, 0
    574          1.1     skrll @end group
    575          1.1     skrll @end smallexample
    576          1.1     skrll 
    577          1.1     skrll @noindent
    578          1.1     skrll If the load destination and source address register are the same, an
    579          1.1     skrll out-of-range offset causes an error.
    580          1.1     skrll 
    581          1.1     skrll @cindex @code{ADDI} instructions, relaxation
    582          1.1     skrll @cindex relaxation of @code{ADDI} instructions
    583          1.1     skrll The Xtensa @code{ADDI} instruction only allows immediate operands in the
    584          1.1     skrll range from -128 to 127.  There are a number of alternate instruction
    585          1.1     skrll sequences for the @code{ADDI} operation.  First, if the
    586          1.1     skrll immediate is 0, the @code{ADDI} will be turned into a @code{MOV.N}
    587          1.1     skrll instruction (or the equivalent @code{OR} instruction if the code density
    588          1.1     skrll option is not available).  If the @code{ADDI} immediate is outside of
    589          1.1     skrll the range -128 to 127, but inside the range -32896 to 32639, an
    590          1.1     skrll @code{ADDMI} instruction or @code{ADDMI}/@code{ADDI} sequence will be
    591          1.1     skrll used.  Finally, if the immediate is outside of this range and a free
    592          1.1     skrll register is available, an @code{L32R}/@code{ADD} sequence will be used
    593          1.1     skrll with a literal allocated from the literal pool.
    594          1.1     skrll 
    595          1.1     skrll For example:
    596          1.1     skrll 
    597          1.1     skrll @smallexample
    598          1.1     skrll @group
    599          1.1     skrll     addi    a5, a6, 0
    600          1.1     skrll     addi    a5, a6, 512
    601          1.1     skrll @end group
    602          1.1     skrll @group
    603          1.1     skrll     addi    a5, a6, 513
    604          1.1     skrll     addi    a5, a6, 50000
    605          1.1     skrll @end group
    606          1.1     skrll @end smallexample
    607          1.1     skrll 
    608          1.1     skrll is assembled into the following:
    609          1.1     skrll 
    610          1.1     skrll @smallexample
    611          1.1     skrll @group
    612          1.1     skrll     .literal .L1, 50000
    613          1.1     skrll     mov.n   a5, a6
    614          1.1     skrll @end group
    615          1.1     skrll     addmi   a5, a6, 0x200
    616          1.1     skrll     addmi   a5, a6, 0x200
    617          1.1     skrll     addi    a5, a5, 1
    618          1.1     skrll @group
    619          1.1     skrll     l32r    a5, .L1
    620          1.1     skrll     add     a5, a6, a5
    621          1.1     skrll @end group
    622          1.1     skrll @end smallexample
    623          1.1     skrll 
    624          1.1     skrll @node Xtensa Directives
    625          1.1     skrll @section Directives
    626          1.1     skrll @cindex Xtensa directives
    627          1.1     skrll @cindex directives, Xtensa
    628          1.1     skrll 
    629          1.1     skrll The Xtensa assembler supports a region-based directive syntax:
    630          1.1     skrll 
    631          1.1     skrll @smallexample
    632          1.1     skrll @group
    633          1.1     skrll     .begin @var{directive} [@var{options}]
    634          1.1     skrll     @dots{}
    635          1.1     skrll     .end @var{directive}
    636          1.1     skrll @end group
    637          1.1     skrll @end smallexample
    638          1.1     skrll 
    639          1.1     skrll All the Xtensa-specific directives that apply to a region of code use
    640          1.1     skrll this syntax.
    641          1.1     skrll 
    642          1.1     skrll The directive applies to code between the @code{.begin} and the
    643          1.1     skrll @code{.end}.  The state of the option after the @code{.end} reverts to
    644          1.1     skrll what it was before the @code{.begin}.
    645          1.1     skrll A nested @code{.begin}/@code{.end} region can further
    646          1.1     skrll change the state of the directive without having to be aware of its
    647          1.1     skrll outer state.  For example, consider:
    648          1.1     skrll 
    649          1.1     skrll @smallexample
    650          1.1     skrll @group
    651          1.1     skrll     .begin no-transform
    652          1.1     skrll L:  add a0, a1, a2
    653          1.1     skrll @end group
    654          1.1     skrll     .begin transform
    655          1.1     skrll M:  add a0, a1, a2
    656          1.1     skrll     .end transform
    657          1.1     skrll @group
    658          1.1     skrll N:  add a0, a1, a2
    659          1.1     skrll     .end no-transform
    660          1.1     skrll @end group
    661          1.1     skrll @end smallexample
    662          1.1     skrll 
    663          1.1     skrll The @code{ADD} opcodes at @code{L} and @code{N} in the outer
    664          1.1     skrll @code{no-transform} region both result in @code{ADD} machine instructions,
    665          1.1     skrll but the assembler selects an @code{ADD.N} instruction for the
    666          1.1     skrll @code{ADD} at @code{M} in the inner @code{transform} region.
    667          1.1     skrll 
    668          1.1     skrll The advantage of this style is that it works well inside macros which can
    669          1.1     skrll preserve the context of their callers.
    670          1.1     skrll 
    671          1.1     skrll The following directives are available:
    672          1.1     skrll @menu
    673          1.1     skrll * Schedule Directive::         Enable instruction scheduling.
    674          1.1     skrll * Longcalls Directive::        Use Indirect Calls for Greater Range.
    675          1.1     skrll * Transform Directive::        Disable All Assembler Transformations.
    676          1.1     skrll * Literal Directive::          Intermix Literals with Instructions.
    677          1.1     skrll * Literal Position Directive:: Specify Inline Literal Pool Locations.
    678          1.1     skrll * Literal Prefix Directive::   Specify Literal Section Name Prefix.
    679          1.1     skrll * Absolute Literals Directive:: Control PC-Relative vs. Absolute Literals.
    680          1.1     skrll @end menu
    681          1.1     skrll 
    682          1.1     skrll @node Schedule Directive
    683          1.1     skrll @subsection schedule
    684          1.1     skrll @cindex @code{schedule} directive
    685          1.1     skrll @cindex @code{no-schedule} directive
    686          1.1     skrll 
    687          1.1     skrll The @code{schedule} directive is recognized only for compatibility with
    688          1.1     skrll Tensilica's assembler.
    689          1.1     skrll 
    690          1.1     skrll @smallexample
    691          1.1     skrll @group
    692          1.1     skrll     .begin [no-]schedule
    693          1.1     skrll     .end [no-]schedule
    694          1.1     skrll @end group
    695          1.1     skrll @end smallexample
    696          1.1     skrll 
    697          1.1     skrll This directive is ignored and has no effect on @command{@value{AS}}.
    698          1.1     skrll 
    699          1.1     skrll @node Longcalls Directive
    700          1.1     skrll @subsection longcalls
    701          1.1     skrll @cindex @code{longcalls} directive
    702          1.1     skrll @cindex @code{no-longcalls} directive
    703          1.1     skrll 
    704          1.1     skrll The @code{longcalls} directive enables or disables function call
    705          1.1     skrll relaxation.  @xref{Xtensa Call Relaxation, ,Function Call Relaxation}.
    706          1.1     skrll 
    707          1.1     skrll @smallexample
    708          1.1     skrll @group
    709          1.1     skrll     .begin [no-]longcalls
    710          1.1     skrll     .end [no-]longcalls
    711          1.1     skrll @end group
    712          1.1     skrll @end smallexample
    713          1.1     skrll 
    714          1.1     skrll Call relaxation is disabled by default unless the @samp{--longcalls}
    715          1.1     skrll command-line option is specified.  The @code{longcalls} directive
    716          1.1     skrll overrides the default determined by the command-line options.
    717          1.1     skrll 
    718          1.1     skrll @node Transform Directive
    719          1.1     skrll @subsection transform
    720          1.1     skrll @cindex @code{transform} directive
    721          1.1     skrll @cindex @code{no-transform} directive
    722          1.1     skrll 
    723          1.1     skrll This directive enables or disables all assembler transformation,
    724          1.1     skrll including relaxation (@pxref{Xtensa Relaxation, ,Xtensa Relaxation}) and
    725          1.1     skrll optimization (@pxref{Xtensa Optimizations, ,Xtensa Optimizations}).
    726          1.1     skrll 
    727          1.1     skrll @smallexample
    728          1.1     skrll @group
    729          1.1     skrll     .begin [no-]transform
    730          1.1     skrll     .end [no-]transform
    731          1.1     skrll @end group
    732          1.1     skrll @end smallexample
    733          1.1     skrll 
    734          1.1     skrll Transformations are enabled by default unless the @samp{--no-transform}
    735          1.1     skrll option is used.  The @code{transform} directive overrides the default
    736          1.1     skrll determined by the command-line options.  An underscore opcode prefix,
    737          1.1     skrll disabling transformation of that opcode, always takes precedence over
    738          1.1     skrll both directives and command-line flags.
    739          1.1     skrll 
    740          1.1     skrll @node Literal Directive
    741          1.1     skrll @subsection literal
    742          1.1     skrll @cindex @code{literal} directive
    743          1.1     skrll 
    744      1.1.1.4  christos The @code{.literal} directive is used to define literal pool data, i.e.,
    745          1.1     skrll read-only 32-bit data accessed via @code{L32R} instructions.
    746          1.1     skrll 
    747          1.1     skrll @smallexample
    748          1.1     skrll     .literal @var{label}, @var{value}[, @var{value}@dots{}]
    749          1.1     skrll @end smallexample
    750          1.1     skrll 
    751          1.1     skrll This directive is similar to the standard @code{.word} directive, except
    752          1.1     skrll that the actual location of the literal data is determined by the
    753          1.1     skrll assembler and linker, not by the position of the @code{.literal}
    754          1.1     skrll directive.  Using this directive gives the assembler freedom to locate
    755          1.1     skrll the literal data in the most appropriate place and possibly to combine
    756          1.1     skrll identical literals.  For example, the code:
    757          1.1     skrll 
    758          1.1     skrll @smallexample
    759          1.1     skrll @group
    760          1.1     skrll     entry sp, 40
    761          1.1     skrll     .literal .L1, sym
    762          1.1     skrll     l32r    a4, .L1
    763          1.1     skrll @end group
    764          1.1     skrll @end smallexample
    765          1.1     skrll 
    766          1.1     skrll can be used to load a pointer to the symbol @code{sym} into register
    767          1.1     skrll @code{a4}.  The value of @code{sym} will not be placed between the
    768          1.1     skrll @code{ENTRY} and @code{L32R} instructions; instead, the assembler puts
    769          1.1     skrll the data in a literal pool.
    770          1.1     skrll 
    771          1.1     skrll Literal pools are placed by default in separate literal sections;
    772          1.1     skrll however, when using the @samp{--text-@-section-@-literals}
    773  1.1.1.6.2.1    martin option (@pxref{Xtensa Options, ,Command-line Options}), the literal
    774          1.1     skrll pools for PC-relative mode @code{L32R} instructions
    775          1.1     skrll are placed in the current section.@footnote{Literals for the
    776          1.1     skrll @code{.init} and @code{.fini} sections are always placed in separate
    777          1.1     skrll sections, even when @samp{--text-@-section-@-literals} is enabled.}
    778          1.1     skrll These text section literal
    779          1.1     skrll pools are created automatically before @code{ENTRY} instructions and
    780          1.1     skrll manually after @samp{.literal_position} directives (@pxref{Literal
    781          1.1     skrll Position Directive, ,literal_position}).  If there are no preceding
    782          1.1     skrll @code{ENTRY} instructions, explicit @code{.literal_position} directives
    783          1.1     skrll must be used to place the text section literal pools; otherwise,
    784          1.1     skrll @command{@value{AS}} will report an error.
    785          1.1     skrll 
    786          1.1     skrll When literals are placed in separate sections, the literal section names
    787          1.1     skrll are derived from the names of the sections where the literals are
    788          1.1     skrll defined.  The base literal section names are @code{.literal} for
    789          1.1     skrll PC-relative mode @code{L32R} instructions and @code{.lit4} for absolute
    790          1.1     skrll mode @code{L32R} instructions (@pxref{Absolute Literals Directive,
    791          1.1     skrll ,absolute-literals}).  These base names are used for literals defined in
    792          1.1     skrll the default @code{.text} section.  For literals defined in other
    793          1.1     skrll sections or within the scope of a @code{literal_prefix} directive
    794          1.1     skrll (@pxref{Literal Prefix Directive, ,literal_prefix}), the following rules
    795          1.1     skrll determine the literal section name:
    796          1.1     skrll 
    797          1.1     skrll @enumerate
    798          1.1     skrll @item
    799          1.1     skrll If the current section is a member of a section group, the literal
    800          1.1     skrll section name includes the group name as a suffix to the base
    801          1.1     skrll @code{.literal} or @code{.lit4} name, with a period to separate the base
    802          1.1     skrll name and group name.  The literal section is also made a member of the
    803          1.1     skrll group.
    804          1.1     skrll 
    805          1.1     skrll @item
    806          1.1     skrll If the current section name (or @code{literal_prefix} value) begins with
    807          1.1     skrll ``@code{.gnu.linkonce.@var{kind}.}'', the literal section name is formed
    808          1.1     skrll by replacing ``@code{.@var{kind}}'' with the base @code{.literal} or
    809          1.1     skrll @code{.lit4} name.  For example, for literals defined in a section named
    810          1.1     skrll @code{.gnu.linkonce.t.func}, the literal section will be
    811          1.1     skrll @code{.gnu.linkonce.literal.func} or @code{.gnu.linkonce.lit4.func}.
    812          1.1     skrll 
    813          1.1     skrll @item
    814          1.1     skrll If the current section name (or @code{literal_prefix} value) ends with
    815          1.1     skrll @code{.text}, the literal section name is formed by replacing that
    816          1.1     skrll suffix with the base @code{.literal} or @code{.lit4} name.  For example,
    817          1.1     skrll for literals defined in a section named @code{.iram0.text}, the literal
    818          1.1     skrll section will be @code{.iram0.literal} or @code{.iram0.lit4}.
    819          1.1     skrll 
    820          1.1     skrll @item
    821          1.1     skrll If none of the preceding conditions apply, the literal section name is
    822          1.1     skrll formed by adding the base @code{.literal} or @code{.lit4} name as a
    823          1.1     skrll suffix to the current section name (or @code{literal_prefix} value).
    824          1.1     skrll @end enumerate
    825          1.1     skrll 
    826          1.1     skrll @node Literal Position Directive
    827          1.1     skrll @subsection literal_position
    828          1.1     skrll @cindex @code{literal_position} directive
    829          1.1     skrll 
    830          1.1     skrll When using @samp{--text-@-section-@-literals} to place literals inline
    831          1.1     skrll in the section being assembled, the @code{.literal_position} directive
    832          1.1     skrll can be used to mark a potential location for a literal pool.
    833          1.1     skrll 
    834          1.1     skrll @smallexample
    835          1.1     skrll     .literal_position
    836          1.1     skrll @end smallexample
    837          1.1     skrll 
    838          1.1     skrll The @code{.literal_position} directive is ignored when the
    839          1.1     skrll @samp{--text-@-section-@-literals} option is not used or when
    840          1.1     skrll @code{L32R} instructions use the absolute addressing mode.
    841          1.1     skrll 
    842      1.1.1.4  christos The assembler will automatically place text section literal pools
    843          1.1     skrll before @code{ENTRY} instructions, so the @code{.literal_position}
    844          1.1     skrll directive is only needed to specify some other location for a literal
    845          1.1     skrll pool.  You may need to add an explicit jump instruction to skip over an
    846          1.1     skrll inline literal pool.
    847          1.1     skrll 
    848          1.1     skrll For example, an interrupt vector does not begin with an @code{ENTRY}
    849          1.1     skrll instruction so the assembler will be unable to automatically find a good
    850          1.1     skrll place to put a literal pool.  Moreover, the code for the interrupt
    851          1.1     skrll vector must be at a specific starting address, so the literal pool
    852          1.1     skrll cannot come before the start of the code.  The literal pool for the
    853          1.1     skrll vector must be explicitly positioned in the middle of the vector (before
    854          1.1     skrll any uses of the literals, due to the negative offsets used by
    855          1.1     skrll PC-relative @code{L32R} instructions).  The @code{.literal_position}
    856          1.1     skrll directive can be used to do this.  In the following code, the literal
    857          1.1     skrll for @samp{M} will automatically be aligned correctly and is placed after
    858          1.1     skrll the unconditional jump.
    859          1.1     skrll 
    860          1.1     skrll @smallexample
    861          1.1     skrll @group
    862          1.1     skrll     .global M
    863          1.1     skrll code_start:
    864          1.1     skrll @end group
    865          1.1     skrll     j continue
    866          1.1     skrll     .literal_position
    867          1.1     skrll     .align 4
    868          1.1     skrll @group
    869          1.1     skrll continue:
    870          1.1     skrll     movi    a4, M
    871          1.1     skrll @end group
    872          1.1     skrll @end smallexample
    873          1.1     skrll 
    874          1.1     skrll @node Literal Prefix Directive
    875          1.1     skrll @subsection literal_prefix
    876          1.1     skrll @cindex @code{literal_prefix} directive
    877          1.1     skrll 
    878          1.1     skrll The @code{literal_prefix} directive allows you to override the default
    879          1.1     skrll literal section names, which are derived from the names of the sections
    880          1.1     skrll where the literals are defined.
    881          1.1     skrll 
    882          1.1     skrll @smallexample
    883          1.1     skrll @group
    884          1.1     skrll     .begin literal_prefix [@var{name}]
    885          1.1     skrll     .end literal_prefix
    886          1.1     skrll @end group
    887          1.1     skrll @end smallexample
    888          1.1     skrll 
    889          1.1     skrll For literals defined within the delimited region, the literal section
    890          1.1     skrll names are derived from the @var{name} argument instead of the name of
    891          1.1     skrll the current section.  The rules used to derive the literal section names
    892          1.1     skrll do not change.  @xref{Literal Directive, ,literal}.  If the @var{name}
    893          1.1     skrll argument is omitted, the literal sections revert to the defaults.  This
    894          1.1     skrll directive has no effect when using the
    895          1.1     skrll @samp{--text-@-section-@-literals} option (@pxref{Xtensa Options,
    896  1.1.1.6.2.1    martin ,Command-line Options}).
    897          1.1     skrll 
    898          1.1     skrll @node Absolute Literals Directive
    899          1.1     skrll @subsection absolute-literals
    900          1.1     skrll @cindex @code{absolute-literals} directive
    901          1.1     skrll @cindex @code{no-absolute-literals} directive
    902          1.1     skrll 
    903          1.1     skrll The @code{absolute-@-literals} and @code{no-@-absolute-@-literals}
    904          1.1     skrll directives control the absolute vs.@: PC-relative mode for @code{L32R}
    905          1.1     skrll instructions.  These are relevant only for Xtensa configurations that
    906          1.1     skrll include the absolute addressing option for @code{L32R} instructions.
    907          1.1     skrll 
    908          1.1     skrll @smallexample
    909          1.1     skrll @group
    910          1.1     skrll     .begin [no-]absolute-literals
    911          1.1     skrll     .end [no-]absolute-literals
    912          1.1     skrll @end group
    913          1.1     skrll @end smallexample
    914          1.1     skrll 
    915          1.1     skrll These directives do not change the @code{L32R} mode---they only cause
    916          1.1     skrll the assembler to emit the appropriate kind of relocation for @code{L32R}
    917          1.1     skrll instructions and to place the literal values in the appropriate section.
    918          1.1     skrll To change the @code{L32R} mode, the program must write the
    919          1.1     skrll @code{LITBASE} special register.  It is the programmer's responsibility
    920          1.1     skrll to keep track of the mode and indicate to the assembler which mode is
    921          1.1     skrll used in each region of code.
    922          1.1     skrll 
    923          1.1     skrll If the Xtensa configuration includes the absolute @code{L32R} addressing
    924          1.1     skrll option, the default is to assume absolute @code{L32R} addressing unless
    925          1.1     skrll the @samp{--no-@-absolute-@-literals} command-line option is specified.
    926          1.1     skrll Otherwise, the default is to assume PC-relative @code{L32R} addressing.
    927          1.1     skrll The @code{absolute-@-literals} directive can then be used to override
    928          1.1     skrll the default determined by the command-line options.
    929          1.1     skrll 
    930          1.1     skrll @c Local Variables:
    931          1.1     skrll @c fill-column: 72
    932          1.1     skrll @c End:
    933