1 @c Copyright (C) 2002-2025 Free Software Foundation, Inc.
2 @c This is part of the GAS manual.
3 @c For copying conditions, see the file as.texinfo.
9 @chapter Xtensa Dependent Features
12 @node Machine Dependencies
13 @chapter Xtensa Dependent Features
16 @cindex Xtensa architecture
17 This chapter covers features of the @sc{gnu} assembler that are specific
18 to the Xtensa architecture. For details about the Xtensa instruction
19 set, please consult the @cite{Xtensa Instruction Set Architecture (ISA)
23 * Xtensa Options:: Command-line Options.
24 * Xtensa Syntax:: Assembler Syntax for Xtensa Processors.
25 * Xtensa Optimizations:: Assembler Optimizations.
26 * Xtensa Relaxation:: Other Automatic Transformations.
27 * Xtensa Directives:: Directives for Xtensa Processors.
31 @section Command-line Options
36 @item --text-section-literals | --no-text-section-literals
37 @kindex --text-section-literals
38 @kindex --no-text-section-literals
39 Control the treatment of literal pools. The default is
40 @samp{--no-@-text-@-section-@-literals}, which places literals in
41 separate sections in the output file. This allows the literal pool to be
42 placed in a data RAM/ROM. With @samp{--text-@-section-@-literals}, the
43 literals are interspersed in the text section in order to keep them as
44 close as possible to their references. This may be necessary for large
45 assembly files, where the literals would otherwise be out of range of the
46 @code{L32R} instructions in the text section. Literals are grouped into
47 pools following @code{.literal_position} directives or preceding
48 @code{ENTRY} instructions. These options only affect literals referenced
49 via PC-relative @code{L32R} instructions; literals for absolute mode
50 @code{L32R} instructions are handled separately.
51 @xref{Literal Directive, ,literal}.
53 @item --auto-litpools | --no-auto-litpools
54 @kindex --auto-litpools
55 @kindex --no-auto-litpools
56 Control the treatment of literal pools. The default is
57 @samp{--no-@-auto-@-litpools}, which in the absence of
58 @samp{--text-@-section-@-literals} places literals in separate sections
59 in the output file. This allows the literal pool to be placed in a data
60 RAM/ROM. With @samp{--auto-@-litpools}, the literals are interspersed
61 in the text section in order to keep them as close as possible to their
62 references, explicit @code{.literal_position} directives are not
63 required. This may be necessary for very large functions, where single
64 literal pool at the beginning of the function may not be reachable by
65 @code{L32R} instructions at the end. These options only affect
66 literals referenced via PC-relative @code{L32R} instructions; literals
67 for absolute mode @code{L32R} instructions are handled separately.
68 When used together with @samp{--text-@-section-@-literals},
69 @samp{--auto-@-litpools} takes precedence.
70 @xref{Literal Directive, ,literal}.
72 @item --absolute-literals | --no-absolute-literals
73 @kindex --absolute-literals
74 @kindex --no-absolute-literals
75 Indicate to the assembler whether @code{L32R} instructions use absolute
76 or PC-relative addressing. If the processor includes the absolute
77 addressing option, the default is to use absolute @code{L32R}
78 relocations. Otherwise, only the PC-relative @code{L32R} relocations
81 @item --target-align | --no-target-align
82 @kindex --target-align
83 @kindex --no-target-align
84 Enable or disable automatic alignment to reduce branch penalties at some
85 expense in code size. @xref{Xtensa Automatic Alignment, ,Automatic
86 Instruction Alignment}. This optimization is enabled by default. Note
87 that the assembler will always align instructions like @code{LOOP} that
88 have fixed alignment requirements.
90 @item --longcalls | --no-longcalls
92 @kindex --no-longcalls
93 Enable or disable transformation of call instructions to allow calls
94 across a greater range of addresses. @xref{Xtensa Call Relaxation,
95 ,Function Call Relaxation}. This option should be used when call
96 targets can potentially be out of range. It may degrade both code size
97 and performance, but the linker can generally optimize away the
98 unnecessary overhead when a call ends up within range. The default is
99 @samp{--no-@-longcalls}.
101 @item --transform | --no-transform
103 @kindex --no-transform
104 Enable or disable all assembler transformations of Xtensa instructions,
105 including both relaxation and optimization. The default is
106 @samp{--transform}; @samp{--no-transform} should only be used in the
107 rare cases when the instructions must be exactly as specified in the
108 assembly source. Using @samp{--no-transform} causes out of range
109 instruction operands to be errors.
111 @item --rename-section @var{oldname}=@var{newname}
112 @kindex --rename-section
113 Rename the @var{oldname} section to @var{newname}. This option can be used
114 multiple times to rename multiple sections.
116 @item --trampolines | --no-trampolines
117 @kindex --trampolines
118 @kindex --no-trampolines
119 Enable or disable transformation of jump instructions to allow jumps
120 across a greater range of addresses. @xref{Xtensa Jump Relaxation,
121 ,Jump Trampolines}. This option should be used when jump targets can
122 potentially be out of range. In the absence of such jumps this option
123 does not affect code size or performance. The default is
124 @samp{--trampolines}.
126 @item --abi-windowed | --abi-call0
127 @kindex --abi-windowed
129 Choose ABI tag written to the @code{.xtensa.info} section. ABI tag
130 indicates ABI of the assembly code. A warning is issued by the linker
131 on an attempt to link object files with inconsistent ABI tags.
132 Default ABI is chosen by the Xtensa core configuration.
138 @section Assembler Syntax
139 @cindex syntax, Xtensa assembler
140 @cindex Xtensa assembler syntax
143 Block comments are delimited by @samp{/*} and @samp{*/}. End of line
144 comments may be introduced with either @samp{#} or @samp{//}.
146 If a @samp{#} appears as the first character of a line then the whole
147 line is treated as a comment, but in this case the line could also be
148 a logical line number directive (@pxref{Comments}) or a preprocessor
149 control command (@pxref{Preprocessing}).
151 Instructions consist of a leading opcode or macro name followed by
152 whitespace and an optional comma-separated list of operands:
155 @var{opcode} [@var{operand}, @dots{}]
158 Instructions must be separated by a newline or semicolon (@samp{;}).
160 FLIX instructions, which bundle multiple opcodes together in a single
161 instruction, are specified by enclosing the bundled opcodes inside
168 @var{opcode0} [@var{operands}]
170 @var{opcode1} [@var{operands}]
172 @var{opcode2} [@var{operands}]
178 The opcodes in a FLIX instruction are listed in the same order as the
179 corresponding instruction slots in the TIE format declaration.
180 Directives and labels are not allowed inside the braces of a FLIX
181 instruction. A particular TIE format name can optionally be specified
182 immediately after the opening brace, but this is usually unnecessary.
183 The assembler will automatically search for a format that can encode the
184 specified opcodes, so the format name need only be specified in rare
185 cases where there is more than one applicable format and where it
186 matters which of those formats is used. A FLIX instruction can also be
187 specified on a single line by separating the opcodes with semicolons:
190 @{ [@var{format};] @var{opcode0} [@var{operands}]; @var{opcode1} [@var{operands}]; @var{opcode2} [@var{operands}]; @dots{} @}
193 If an opcode can only be encoded in a FLIX instruction but is not
194 specified as part of a FLIX bundle, the assembler will choose the
195 smallest format where the opcode can be encoded and
196 will fill unused instruction slots with no-ops.
199 * Xtensa Opcodes:: Opcode Naming Conventions.
200 * Xtensa Registers:: Register Naming.
204 @subsection Opcode Names
205 @cindex Xtensa opcode names
206 @cindex opcode names, Xtensa
208 See the @cite{Xtensa Instruction Set Architecture (ISA) Reference
209 Manual} for a complete list of opcodes and descriptions of their
212 @cindex _ opcode prefix
213 If an opcode name is prefixed with an underscore character (@samp{_}),
214 @command{@value{AS}} will not transform that instruction in any way. The
215 underscore prefix disables both optimization (@pxref{Xtensa
216 Optimizations, ,Xtensa Optimizations}) and relaxation (@pxref{Xtensa
217 Relaxation, ,Xtensa Relaxation}) for that particular instruction. Only
218 use the underscore prefix when it is essential to select the exact
219 opcode produced by the assembler. Using this feature unnecessarily
220 makes the code less efficient by disabling assembler optimization and
221 less flexible by disabling relaxation.
223 Note that this special handling of underscore prefixes only applies to
224 Xtensa opcodes, not to either built-in macros or user-defined macros.
225 When an underscore prefix is used with a macro (e.g., @code{_MOV}), it
226 refers to a different macro. The assembler generally provides built-in
227 macros both with and without the underscore prefix, where the underscore
228 versions behave as if the underscore carries through to the instructions
229 in the macros. For example, @code{_MOV} may expand to @code{_MOV.N}@.
231 The underscore prefix only applies to individual instructions, not to
232 series of instructions. For example, if a series of instructions have
233 underscore prefixes, the assembler will not transform the individual
234 instructions, but it may insert other instructions between them (e.g.,
235 to align a @code{LOOP} instruction). To prevent the assembler from
236 modifying a series of instructions as a whole, use the
237 @code{no-transform} directive. @xref{Transform Directive, ,transform}.
239 @node Xtensa Registers
240 @subsection Register Names
241 @cindex Xtensa register names
242 @cindex register names, Xtensa
245 The assembly syntax for a register file entry is the ``short'' name for
246 a TIE register file followed by the index into that register file. For
247 example, the general-purpose @code{AR} register file has a short name of
248 @code{a}, so these registers are named @code{a0}@dots{}@code{a15}.
249 As a special feature, @code{sp} is also supported as a synonym for
250 @code{a1}. Additional registers may be added by processor configuration
251 options and by designer-defined TIE extensions. An initial @samp{$}
252 character is optional in all register names.
254 @node Xtensa Optimizations
255 @section Xtensa Optimizations
256 @cindex optimizations
258 The optimizations currently supported by @command{@value{AS}} are
259 generation of density instructions where appropriate and automatic
260 branch target alignment.
263 * Density Instructions:: Using Density Instructions.
264 * Xtensa Automatic Alignment:: Automatic Instruction Alignment.
267 @node Density Instructions
268 @subsection Using Density Instructions
269 @cindex density instructions
271 The Xtensa instruction set has a code density option that provides
272 16-bit versions of some of the most commonly used opcodes. Use of these
273 opcodes can significantly reduce code size. When possible, the
274 assembler automatically translates instructions from the core
275 Xtensa instruction set into equivalent instructions from the Xtensa code
276 density option. This translation can be disabled by using underscore
277 prefixes (@pxref{Xtensa Opcodes, ,Opcode Names}), by using the
278 @samp{--no-transform} command-line option (@pxref{Xtensa Options, ,Command
279 Line Options}), or by using the @code{no-transform} directive
280 (@pxref{Transform Directive, ,transform}).
282 It is a good idea @emph{not} to use the density instructions directly.
283 The assembler will automatically select dense instructions where
284 possible. If you later need to use an Xtensa processor without the code
285 density option, the same assembly code will then work without modification.
287 @node Xtensa Automatic Alignment
288 @subsection Automatic Instruction Alignment
289 @cindex alignment of @code{LOOP} instructions
290 @cindex alignment of branch targets
291 @cindex @code{LOOP} instructions, alignment
292 @cindex branch target alignment
294 The Xtensa assembler will automatically align certain instructions, both
295 to optimize performance and to satisfy architectural requirements.
297 As an optimization to improve performance, the assembler attempts to
298 align branch targets so they do not cross instruction fetch boundaries.
299 (Xtensa processors can be configured with either 32-bit or 64-bit
300 instruction fetch widths.) An
301 instruction immediately following a call is treated as a branch target
302 in this context, because it will be the target of a return from the
303 call. This alignment has the potential to reduce branch penalties at
304 some expense in code size.
305 This optimization is enabled by default. You can disable it with the
306 @samp{--no-target-@-align} command-line option (@pxref{Xtensa Options,
307 ,Command-line Options}).
309 The target alignment optimization is done without adding instructions
310 that could increase the execution time of the program. If there are
311 density instructions in the code preceding a target, the assembler can
312 change the target alignment by widening some of those instructions to
313 the equivalent 24-bit instructions. Extra bytes of padding can be
314 inserted immediately following unconditional jump and return
316 This approach is usually successful in aligning many, but not all,
319 The @code{LOOP} family of instructions must be aligned such that the
320 first instruction in the loop body does not cross an instruction fetch
321 boundary (e.g., with a 32-bit fetch width, a @code{LOOP} instruction
322 must be on either a 1 or 2 mod 4 byte boundary). The assembler knows
323 about this restriction and inserts the minimal number of 2 or 3 byte
324 no-op instructions to satisfy it. When no-op instructions are added,
325 any label immediately preceding the original loop will be moved in order
326 to refer to the loop instruction, not the newly generated no-op
327 instruction. To preserve binary compatibility across processors with
328 different fetch widths, the assembler conservatively assumes a 32-bit
329 fetch width when aligning @code{LOOP} instructions (except if the first
330 instruction in the loop is a 64-bit instruction).
332 Previous versions of the assembler automatically aligned @code{ENTRY}
333 instructions to 4-byte boundaries, but that alignment is now the
334 programmer's responsibility.
336 @node Xtensa Relaxation
337 @section Xtensa Relaxation
340 When an instruction operand is outside the range allowed for that
341 particular instruction field, @command{@value{AS}} can transform the code
342 to use a functionally-equivalent instruction or sequence of
343 instructions. This process is known as @dfn{relaxation}. This is
344 typically done for branch instructions because the distance of the
345 branch targets is not known until assembly-time. The Xtensa assembler
346 offers branch relaxation and also extends this concept to function
347 calls, @code{MOVI} instructions and other instructions with immediate
351 * Xtensa Branch Relaxation:: Relaxation of Branches.
352 * Xtensa Call Relaxation:: Relaxation of Function Calls.
353 * Xtensa Jump Relaxation:: Relaxation of Jumps.
354 * Xtensa Immediate Relaxation:: Relaxation of other Immediate Fields.
357 @node Xtensa Branch Relaxation
358 @subsection Conditional Branch Relaxation
359 @cindex relaxation of branch instructions
360 @cindex branch instructions, relaxation
362 When the target of a branch is too far away from the branch itself,
363 i.e., when the offset from the branch to the target is too large to fit
364 in the immediate field of the branch instruction, it may be necessary to
365 replace the branch with a branch around a jump. For example,
381 (The @code{BNEZ.N} instruction would be used in this example only if the
382 density option is available. Otherwise, @code{BNEZ} would be used.)
384 This relaxation works well because the unconditional jump instruction
385 has a much larger offset range than the various conditional branches.
386 However, an error will occur if a branch target is beyond the range of a
387 jump instruction. @command{@value{AS}} cannot relax unconditional jumps.
388 Similarly, an error will occur if the original input contains an
389 unconditional jump to a target that is out of range.
391 Branch relaxation is enabled by default. It can be disabled by using
392 underscore prefixes (@pxref{Xtensa Opcodes, ,Opcode Names}), the
393 @samp{--no-transform} command-line option (@pxref{Xtensa Options,
394 ,Command-line Options}), or the @code{no-transform} directive
395 (@pxref{Transform Directive, ,transform}).
397 @node Xtensa Call Relaxation
398 @subsection Function Call Relaxation
399 @cindex relaxation of call instructions
400 @cindex call instructions, relaxation
402 Function calls may require relaxation because the Xtensa immediate call
403 instructions (@code{CALL0}, @code{CALL4}, @code{CALL8} and
404 @code{CALL12}) provide a PC-relative offset of only 512 Kbytes in either
405 direction. For larger programs, it may be necessary to use indirect
406 calls (@code{CALLX0}, @code{CALLX4}, @code{CALLX8} and @code{CALLX12})
407 where the target address is specified in a register. The Xtensa
408 assembler can automatically relax immediate call instructions into
409 indirect call instructions. This relaxation is done by loading the
410 address of the called function into the callee's return address register
411 and then using a @code{CALLX} instruction. So, for example:
427 Because the addresses of targets of function calls are not generally
428 known until link-time, the assembler must assume the worst and relax all
429 the calls to functions in other source files, not just those that really
430 will be out of range. The linker can recognize calls that were
431 unnecessarily relaxed, and it will remove the overhead introduced by the
432 assembler for those cases where direct calls are sufficient.
434 Call relaxation is disabled by default because it can have a negative
435 effect on both code size and performance, although the linker can
436 usually eliminate the unnecessary overhead. If a program is too large
437 and some of the calls are out of range, function call relaxation can be
438 enabled using the @samp{--longcalls} command-line option or the
439 @code{longcalls} directive (@pxref{Longcalls Directive, ,longcalls}).
441 @node Xtensa Jump Relaxation
442 @subsection Jump Relaxation
443 @cindex relaxation of jump instructions
444 @cindex jump instructions, relaxation
446 Jump instruction may require relaxation because the Xtensa jump instruction
447 (@code{J}) provide a PC-relative offset of only 128 Kbytes in either
448 direction. One option is to use jump long (@code{J.L}) instruction, which
449 depending on jump distance may be assembled as jump (@code{J}) or indirect
450 jump (@code{JX}). However it needs a free register. When there's no spare
451 register it is possible to plant intermediate jump sites (trampolines)
452 between the jump instruction and its target. These sites may be located in
453 areas unreachable by normal code execution flow, in that case they only
454 contain intermediate jumps, or they may be inserted in the middle of code
455 block, in which case there's an additional jump from the beginning of the
456 trampoline to the instruction past its end. So, for example:
510 The Xtensa assembler uses trampolines with jump around only when it cannot
511 find suitable unreachable trampoline. There may be multiple trampolines
512 between the jump instruction and its target.
514 This relaxation does not apply to jumps to undefined symbols, assuming they
515 will reach their targets once resolved.
517 Jump relaxation is enabled by default because it does not affect code size
518 or performance while the code itself is small. This relaxation may be
519 disabled completely with @samp{--no-trampolines} or @samp{--no-transform}
520 command-line options (@pxref{Xtensa Options, ,Command-line Options}).
522 @node Xtensa Immediate Relaxation
523 @subsection Other Immediate Field Relaxation
524 @cindex immediate fields, relaxation
525 @cindex relaxation of immediate fields
527 The assembler normally performs the following other relaxations. They
528 can be disabled by using underscore prefixes (@pxref{Xtensa Opcodes,
529 ,Opcode Names}), the @samp{--no-transform} command-line option
530 (@pxref{Xtensa Options, ,Command-line Options}), or the
531 @code{no-transform} directive (@pxref{Transform Directive, ,transform}).
533 @cindex @code{MOVI} instructions, relaxation
534 @cindex relaxation of @code{MOVI} instructions
535 The @code{MOVI} machine instruction can only materialize values in the
536 range from -2048 to 2047. Values outside this range are best
537 materialized with @code{L32R} instructions. Thus:
543 is assembled into the following machine code:
552 @cindex @code{L8UI} instructions, relaxation
553 @cindex @code{L16SI} instructions, relaxation
554 @cindex @code{L16UI} instructions, relaxation
555 @cindex @code{L32I} instructions, relaxation
556 @cindex relaxation of @code{L8UI} instructions
557 @cindex relaxation of @code{L16SI} instructions
558 @cindex relaxation of @code{L16UI} instructions
559 @cindex relaxation of @code{L32I} instructions
560 The @code{L8UI} machine instruction can only be used with immediate
561 offsets in the range from 0 to 255. The @code{L16SI} and @code{L16UI}
562 machine instructions can only be used with offsets from 0 to 510. The
563 @code{L32I} machine instruction can only be used with offsets from 0 to
564 1020. A load offset outside these ranges can be materialized with
565 an @code{L32R} instruction if the destination register of the load
566 is different than the source address register. For example:
586 If the load destination and source address register are the same, an
587 out-of-range offset causes an error.
589 @cindex @code{ADDI} instructions, relaxation
590 @cindex relaxation of @code{ADDI} instructions
591 The Xtensa @code{ADDI} instruction only allows immediate operands in the
592 range from -128 to 127. There are a number of alternate instruction
593 sequences for the @code{ADDI} operation. First, if the
594 immediate is 0, the @code{ADDI} will be turned into a @code{MOV.N}
595 instruction (or the equivalent @code{OR} instruction if the code density
596 option is not available). If the @code{ADDI} immediate is outside of
597 the range -128 to 127, but inside the range -32896 to 32639, an
598 @code{ADDMI} instruction or @code{ADDMI}/@code{ADDI} sequence will be
599 used. Finally, if the immediate is outside of this range and a free
600 register is available, an @code{L32R}/@code{ADD} sequence will be used
601 with a literal allocated from the literal pool.
616 is assembled into the following:
632 @node Xtensa Directives
634 @cindex Xtensa directives
635 @cindex directives, Xtensa
637 The Xtensa assembler supports a region-based directive syntax:
641 .begin @var{directive} [@var{options}]
647 All the Xtensa-specific directives that apply to a region of code use
650 The directive applies to code between the @code{.begin} and the
651 @code{.end}. The state of the option after the @code{.end} reverts to
652 what it was before the @code{.begin}.
653 A nested @code{.begin}/@code{.end} region can further
654 change the state of the directive without having to be aware of its
655 outer state. For example, consider:
671 The @code{ADD} opcodes at @code{L} and @code{N} in the outer
672 @code{no-transform} region both result in @code{ADD} machine instructions,
673 but the assembler selects an @code{ADD.N} instruction for the
674 @code{ADD} at @code{M} in the inner @code{transform} region.
676 The advantage of this style is that it works well inside macros which can
677 preserve the context of their callers.
679 The following directives are available:
681 * Schedule Directive:: Enable instruction scheduling.
682 * Longcalls Directive:: Use Indirect Calls for Greater Range.
683 * Transform Directive:: Disable All Assembler Transformations.
684 * Literal Directive:: Intermix Literals with Instructions.
685 * Literal Position Directive:: Specify Inline Literal Pool Locations.
686 * Literal Prefix Directive:: Specify Literal Section Name Prefix.
687 * Absolute Literals Directive:: Control PC-Relative vs. Absolute Literals.
690 @node Schedule Directive
692 @cindex @code{schedule} directive
693 @cindex @code{no-schedule} directive
695 The @code{schedule} directive is recognized only for compatibility with
696 Tensilica's assembler.
705 This directive is ignored and has no effect on @command{@value{AS}}.
707 @node Longcalls Directive
708 @subsection longcalls
709 @cindex @code{longcalls} directive
710 @cindex @code{no-longcalls} directive
712 The @code{longcalls} directive enables or disables function call
713 relaxation. @xref{Xtensa Call Relaxation, ,Function Call Relaxation}.
717 .begin [no-]longcalls
722 Call relaxation is disabled by default unless the @samp{--longcalls}
723 command-line option is specified. The @code{longcalls} directive
724 overrides the default determined by the command-line options.
726 @node Transform Directive
727 @subsection transform
728 @cindex @code{transform} directive
729 @cindex @code{no-transform} directive
731 This directive enables or disables all assembler transformation,
732 including relaxation (@pxref{Xtensa Relaxation, ,Xtensa Relaxation}) and
733 optimization (@pxref{Xtensa Optimizations, ,Xtensa Optimizations}).
737 .begin [no-]transform
742 Transformations are enabled by default unless the @samp{--no-transform}
743 option is used. The @code{transform} directive overrides the default
744 determined by the command-line options. An underscore opcode prefix,
745 disabling transformation of that opcode, always takes precedence over
746 both directives and command-line flags.
748 @node Literal Directive
750 @cindex @code{literal} directive
752 The @code{.literal} directive is used to define literal pool data, i.e.,
753 read-only 32-bit data accessed via @code{L32R} instructions.
756 .literal @var{label}, @var{value}[, @var{value}@dots{}]
759 This directive is similar to the standard @code{.word} directive, except
760 that the actual location of the literal data is determined by the
761 assembler and linker, not by the position of the @code{.literal}
762 directive. Using this directive gives the assembler freedom to locate
763 the literal data in the most appropriate place and possibly to combine
764 identical literals. For example, the code:
774 can be used to load a pointer to the symbol @code{sym} into register
775 @code{a4}. The value of @code{sym} will not be placed between the
776 @code{ENTRY} and @code{L32R} instructions; instead, the assembler puts
777 the data in a literal pool.
779 Literal pools are placed by default in separate literal sections;
780 however, when using the @samp{--text-@-section-@-literals}
781 option (@pxref{Xtensa Options, ,Command-line Options}), the literal
782 pools for PC-relative mode @code{L32R} instructions
783 are placed in the current section.@footnote{Literals for the
784 @code{.init} and @code{.fini} sections are always placed in separate
785 sections, even when @samp{--text-@-section-@-literals} is enabled.}
786 These text section literal
787 pools are created automatically before @code{ENTRY} instructions and
788 manually after @samp{.literal_position} directives (@pxref{Literal
789 Position Directive, ,literal_position}). If there are no preceding
790 @code{ENTRY} instructions, explicit @code{.literal_position} directives
791 must be used to place the text section literal pools; otherwise,
792 @command{@value{AS}} will report an error.
794 When literals are placed in separate sections, the literal section names
795 are derived from the names of the sections where the literals are
796 defined. The base literal section names are @code{.literal} for
797 PC-relative mode @code{L32R} instructions and @code{.lit4} for absolute
798 mode @code{L32R} instructions (@pxref{Absolute Literals Directive,
799 ,absolute-literals}). These base names are used for literals defined in
800 the default @code{.text} section. For literals defined in other
801 sections or within the scope of a @code{literal_prefix} directive
802 (@pxref{Literal Prefix Directive, ,literal_prefix}), the following rules
803 determine the literal section name:
807 If the current section is a member of a section group, the literal
808 section name includes the group name as a suffix to the base
809 @code{.literal} or @code{.lit4} name, with a period to separate the base
810 name and group name. The literal section is also made a member of the
814 If the current section name (or @code{literal_prefix} value) begins with
815 ``@code{.gnu.linkonce.@var{kind}.}'', the literal section name is formed
816 by replacing ``@code{.@var{kind}}'' with the base @code{.literal} or
817 @code{.lit4} name. For example, for literals defined in a section named
818 @code{.gnu.linkonce.t.func}, the literal section will be
819 @code{.gnu.linkonce.literal.func} or @code{.gnu.linkonce.lit4.func}.
822 If the current section name (or @code{literal_prefix} value) ends with
823 @code{.text}, the literal section name is formed by replacing that
824 suffix with the base @code{.literal} or @code{.lit4} name. For example,
825 for literals defined in a section named @code{.iram0.text}, the literal
826 section will be @code{.iram0.literal} or @code{.iram0.lit4}.
829 If none of the preceding conditions apply, the literal section name is
830 formed by adding the base @code{.literal} or @code{.lit4} name as a
831 suffix to the current section name (or @code{literal_prefix} value).
834 @node Literal Position Directive
835 @subsection literal_position
836 @cindex @code{literal_position} directive
838 When using @samp{--text-@-section-@-literals} to place literals inline
839 in the section being assembled, the @code{.literal_position} directive
840 can be used to mark a potential location for a literal pool.
846 The @code{.literal_position} directive is ignored when the
847 @samp{--text-@-section-@-literals} option is not used or when
848 @code{L32R} instructions use the absolute addressing mode.
850 The assembler will automatically place text section literal pools
851 before @code{ENTRY} instructions, so the @code{.literal_position}
852 directive is only needed to specify some other location for a literal
853 pool. You may need to add an explicit jump instruction to skip over an
856 For example, an interrupt vector does not begin with an @code{ENTRY}
857 instruction so the assembler will be unable to automatically find a good
858 place to put a literal pool. Moreover, the code for the interrupt
859 vector must be at a specific starting address, so the literal pool
860 cannot come before the start of the code. The literal pool for the
861 vector must be explicitly positioned in the middle of the vector (before
862 any uses of the literals, due to the negative offsets used by
863 PC-relative @code{L32R} instructions). The @code{.literal_position}
864 directive can be used to do this. In the following code, the literal
865 for @samp{M} will automatically be aligned correctly and is placed after
866 the unconditional jump.
882 @node Literal Prefix Directive
883 @subsection literal_prefix
884 @cindex @code{literal_prefix} directive
886 The @code{literal_prefix} directive allows you to override the default
887 literal section names, which are derived from the names of the sections
888 where the literals are defined.
892 .begin literal_prefix [@var{name}]
897 For literals defined within the delimited region, the literal section
898 names are derived from the @var{name} argument instead of the name of
899 the current section. The rules used to derive the literal section names
900 do not change. @xref{Literal Directive, ,literal}. If the @var{name}
901 argument is omitted, the literal sections revert to the defaults. This
902 directive has no effect when using the
903 @samp{--text-@-section-@-literals} option (@pxref{Xtensa Options,
904 ,Command-line Options}).
906 @node Absolute Literals Directive
907 @subsection absolute-literals
908 @cindex @code{absolute-literals} directive
909 @cindex @code{no-absolute-literals} directive
911 The @code{absolute-@-literals} and @code{no-@-absolute-@-literals}
912 directives control the absolute vs.@: PC-relative mode for @code{L32R}
913 instructions. These are relevant only for Xtensa configurations that
914 include the absolute addressing option for @code{L32R} instructions.
918 .begin [no-]absolute-literals
919 .end [no-]absolute-literals
923 These directives do not change the @code{L32R} mode---they only cause
924 the assembler to emit the appropriate kind of relocation for @code{L32R}
925 instructions and to place the literal values in the appropriate section.
926 To change the @code{L32R} mode, the program must write the
927 @code{LITBASE} special register. It is the programmer's responsibility
928 to keep track of the mode and indicate to the assembler which mode is
929 used in each region of code.
931 If the Xtensa configuration includes the absolute @code{L32R} addressing
932 option, the default is to assume absolute @code{L32R} addressing unless
933 the @samp{--no-@-absolute-@-literals} command-line option is specified.
934 Otherwise, the default is to assume PC-relative @code{L32R} addressing.
935 The @code{absolute-@-literals} directive can then be used to override
936 the default determined by the command-line options.