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