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