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