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