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