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