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