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