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