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