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