Commit | Line | Data |
---|---|---|
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 | |
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 | |
e0001a05 NC |
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 a | |
41 | separate section in the output file. This allows the literal pool to be | |
43cd72b9 | 42 | placed in a data RAM/ROM. With @samp{--text-@-section-@-literals}, the |
e0001a05 NC |
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 | |
43cd72b9 BW |
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 | ||
50 | @item --absolute-literals | --no-absolute-literals | |
51 | @kindex --absolute-literals | |
52 | @kindex --no-absolute-literals | |
53 | Indicate to the assembler whether @code{L32R} instructions use absolute | |
54 | or PC-relative addressing. If the processor includes the absolute | |
55 | addressing option, the default is to use absolute @code{L32R} | |
56 | relocations. Otherwise, only the PC-relative @code{L32R} relocations | |
40e7b7b9 | 57 | can be used. |
e0001a05 NC |
58 | |
59 | @item --target-align | --no-target-align | |
60 | @kindex --target-align | |
61 | @kindex --no-target-align | |
62 | Enable or disable automatic alignment to reduce branch penalties at some | |
63 | expense in code size. @xref{Xtensa Automatic Alignment, ,Automatic | |
64 | Instruction Alignment}. This optimization is enabled by default. Note | |
65 | that the assembler will always align instructions like @code{LOOP} that | |
66 | have fixed alignment requirements. | |
67 | ||
68 | @item --longcalls | --no-longcalls | |
69 | @kindex --longcalls | |
70 | @kindex --no-longcalls | |
71 | Enable or disable transformation of call instructions to allow calls | |
72 | across a greater range of addresses. @xref{Xtensa Call Relaxation, | |
73 | ,Function Call Relaxation}. This option should be used when call | |
43cd72b9 BW |
74 | targets can potentially be out of range. It may degrade both code size |
75 | and performance, but the linker can generally optimize away the | |
76 | unnecessary 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 | |
82 | Enable or disable all assembler transformations of Xtensa instructions, | |
83 | including both relaxation and optimization. The default is | |
84 | @samp{--transform}; @samp{--no-transform} should only be used in the | |
85 | rare cases when the instructions must be exactly as specified in the | |
86 | assembly source. Using @samp{--no-transform} causes out of range | |
87 | instruction 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 | |
96 | Block comments are delimited by @samp{/*} and @samp{*/}. End of line | |
97 | comments may be introduced with either @samp{#} or @samp{//}. | |
98 | ||
99 | Instructions consist of a leading opcode or macro name followed by | |
100 | whitespace and an optional comma-separated list of operands: | |
101 | ||
102 | @smallexample | |
43cd72b9 | 103 | @var{opcode} [@var{operand}, @dots{}] |
e0001a05 NC |
104 | @end smallexample |
105 | ||
106 | Instructions must be separated by a newline or semicolon. | |
107 | ||
43cd72b9 BW |
108 | FLIX instructions, which bundle multiple opcodes together in a single |
109 | instruction, are specified by enclosing the bundled opcodes inside | |
110 | braces: | |
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 | ||
122 | The opcodes in a FLIX instruction are listed in the same order as the | |
123 | corresponding instruction slots in the TIE format declaration. | |
124 | Directives and labels are not allowed inside the braces of a FLIX | |
125 | instruction. A particular TIE format name can optionally be specified | |
126 | immediately after the opening brace, but this is usually unnecessary. | |
127 | The assembler will automatically search for a format that can encode the | |
128 | specified opcodes, so the format name need only be specified in rare | |
129 | cases where there is more than one applicable format and where it | |
130 | matters which of those formats is used. A FLIX instruction can also be | |
131 | specified 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 | ||
137 | The assembler can automatically bundle opcodes into FLIX instructions. | |
138 | It encodes the opcodes in order, one at a time, | |
139 | choosing the smallest format where each opcode can be encoded and | |
140 | filling 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 | |
152 | See the @cite{Xtensa Instruction Set Architecture (ISA) Reference | |
153 | Manual} for a complete list of opcodes and descriptions of their | |
154 | semantics. | |
155 | ||
e0001a05 | 156 | @cindex _ opcode prefix |
43cd72b9 BW |
157 | If an opcode name is prefixed with an underscore character (@samp{_}), |
158 | @command{@value{AS}} will not transform that instruction in any way. The | |
159 | underscore prefix disables both optimization (@pxref{Xtensa | |
160 | Optimizations, ,Xtensa Optimizations}) and relaxation (@pxref{Xtensa | |
161 | Relaxation, ,Xtensa Relaxation}) for that particular instruction. Only | |
162 | use the underscore prefix when it is essential to select the exact | |
163 | opcode produced by the assembler. Using this feature unnecessarily | |
164 | makes the code less efficient by disabling assembler optimization and | |
165 | less flexible by disabling relaxation. | |
e0001a05 NC |
166 | |
167 | Note that this special handling of underscore prefixes only applies to | |
168 | Xtensa opcodes, not to either built-in macros or user-defined macros. | |
43cd72b9 | 169 | When an underscore prefix is used with a macro (e.g., @code{_MOV}), it |
e0001a05 NC |
170 | refers to a different macro. The assembler generally provides built-in |
171 | macros both with and without the underscore prefix, where the underscore | |
172 | versions behave as if the underscore carries through to the instructions | |
43cd72b9 | 173 | in the macros. For example, @code{_MOV} may expand to @code{_MOV.N}@. |
e0001a05 NC |
174 | |
175 | The underscore prefix only applies to individual instructions, not to | |
176 | series of instructions. For example, if a series of instructions have | |
177 | underscore prefixes, the assembler will not transform the individual | |
178 | instructions, but it may insert other instructions between them (e.g., | |
179 | to align a @code{LOOP} instruction). To prevent the assembler from | |
180 | modifying 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 |
189 | The assembly syntax for a register file entry is the ``short'' name for |
190 | a TIE register file followed by the index into that register file. For | |
191 | example, 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}. | |
193 | As a special feature, @code{sp} is also supported as a synonym for | |
194 | @code{a1}. Additional registers may be added by processor configuration | |
195 | options and by designer-defined TIE extensions. An initial @samp{$} | |
196 | character is optional in all register names. | |
e0001a05 NC |
197 | |
198 | @node Xtensa Optimizations | |
199 | @section Xtensa Optimizations | |
200 | @cindex optimizations | |
201 | ||
43cd72b9 | 202 | The optimizations currently supported by @command{@value{AS}} are |
e0001a05 NC |
203 | generation of density instructions where appropriate and automatic |
204 | branch 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 | ||
215 | The Xtensa instruction set has a code density option that provides | |
216 | 16-bit versions of some of the most commonly used opcodes. Use of these | |
217 | opcodes can significantly reduce code size. When possible, the | |
43cd72b9 | 218 | assembler automatically translates instructions from the core |
e0001a05 | 219 | Xtensa instruction set into equivalent instructions from the Xtensa code |
43cd72b9 BW |
220 | density option. This translation can be disabled by using underscore |
221 | prefixes (@pxref{Xtensa Opcodes, ,Opcode Names}), by using the | |
222 | @samp{--no-transform} command-line option (@pxref{Xtensa Options, ,Command | |
223 | Line Options}), or by using the @code{no-transform} directive | |
224 | (@pxref{Transform Directive, ,transform}). | |
e0001a05 | 225 | |
60493797 | 226 | It is a good idea @emph{not} to use the density instructions directly. |
e0001a05 | 227 | The assembler will automatically select dense instructions where |
43cd72b9 BW |
228 | possible. If you later need to use an Xtensa processor without the code |
229 | density 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 | ||
240 | The Xtensa assembler will automatically align certain instructions, both | |
241 | to optimize performance and to satisfy architectural requirements. | |
242 | ||
43cd72b9 BW |
243 | As an optimization to improve performance, the assembler attempts to |
244 | align branch targets so they do not cross instruction fetch boundaries. | |
245 | (Xtensa processors can be configured with either 32-bit or 64-bit | |
246 | instruction fetch widths.) An | |
247 | instruction immediately following a call is treated as a branch target | |
248 | in this context, because it will be the target of a return from the | |
249 | call. This alignment has the potential to reduce branch penalties at | |
250 | some expense in code size. The assembler will not attempt to align | |
251 | labels with the prefixes @code{.Ln} and @code{.LM}, since these labels | |
252 | are used for debugging information and are not typically branch targets. | |
253 | This 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 | ||
257 | The target alignment optimization is done without adding instructions | |
258 | that could increase the execution time of the program. If there are | |
259 | density instructions in the code preceding a target, the assembler can | |
260 | change the target alignment by widening some of those instructions to | |
261 | the equivalent 24-bit instructions. Extra bytes of padding can be | |
262 | inserted immediately following unconditional jump and return | |
263 | instructions. | |
264 | This approach is usually successful in aligning many, but not all, | |
265 | branch targets. | |
266 | ||
267 | The @code{LOOP} family of instructions must be aligned such that the | |
268 | first instruction in the loop body does not cross an instruction fetch | |
269 | boundary (e.g., with a 32-bit fetch width, a @code{LOOP} instruction | |
270 | must be on either a 1 or 2 mod 4 byte boundary). The assembler knows | |
271 | about this restriction and inserts the minimal number of 2 or 3 byte | |
272 | no-op instructions to satisfy it. When no-op instructions are added, | |
273 | any label immediately preceding the original loop will be moved in order | |
274 | to refer to the loop instruction, not the newly generated no-op | |
275 | instruction. To preserve binary compatibility across processors with | |
276 | different fetch widths, the assembler conservatively assumes a 32-bit | |
277 | fetch width when aligning @code{LOOP} instructions (except if the first | |
278 | instruction in the loop is a 64-bit instruction). | |
e0001a05 NC |
279 | |
280 | Similarly, the @code{ENTRY} instruction must be aligned on a 0 mod 4 | |
281 | byte boundary. The assembler satisfies this requirement by inserting | |
282 | zero bytes when required. In addition, labels immediately preceding the | |
283 | @code{ENTRY} instruction will be moved to the newly aligned instruction | |
284 | location. | |
285 | ||
286 | @node Xtensa Relaxation | |
287 | @section Xtensa Relaxation | |
288 | @cindex relaxation | |
289 | ||
290 | When an instruction operand is outside the range allowed for that | |
43cd72b9 | 291 | particular instruction field, @command{@value{AS}} can transform the code |
e0001a05 NC |
292 | to use a functionally-equivalent instruction or sequence of |
293 | instructions. This process is known as @dfn{relaxation}. This is | |
294 | typically done for branch instructions because the distance of the | |
295 | branch targets is not known until assembly-time. The Xtensa assembler | |
296 | offers branch relaxation and also extends this concept to function | |
297 | calls, @code{MOVI} instructions and other instructions with immediate | |
298 | fields. | |
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 | ||
311 | When the target of a branch is too far away from the branch itself, | |
312 | i.e., when the offset from the branch to the target is too large to fit | |
313 | in the immediate field of the branch instruction, it may be necessary to | |
314 | replace the branch with a branch around a jump. For example, | |
315 | ||
316 | @smallexample | |
317 | beqz a2, L | |
318 | @end smallexample | |
319 | ||
320 | may result in: | |
321 | ||
322 | @smallexample | |
323 | bnez.n a2, M | |
324 | j L | |
325 | M: | |
326 | @end smallexample | |
327 | ||
328 | (The @code{BNEZ.N} instruction would be used in this example only if the | |
329 | density option is available. Otherwise, @code{BNEZ} would be used.) | |
330 | ||
43cd72b9 BW |
331 | This relaxation works well because the unconditional jump instruction |
332 | has a much larger offset range than the various conditional branches. | |
333 | However, an error will occur if a branch target is beyond the range of a | |
334 | jump instruction. @command{@value{AS}} cannot relax unconditional jumps. | |
335 | Similarly, an error will occur if the original input contains an | |
336 | unconditional jump to a target that is out of range. | |
337 | ||
338 | Branch relaxation is enabled by default. It can be disabled by using | |
339 | underscore 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 | ||
349 | Function calls may require relaxation because the Xtensa immediate call | |
350 | instructions (@code{CALL0}, @code{CALL4}, @code{CALL8} and | |
351 | @code{CALL12}) provide a PC-relative offset of only 512 Kbytes in either | |
352 | direction. For larger programs, it may be necessary to use indirect | |
353 | calls (@code{CALLX0}, @code{CALLX4}, @code{CALLX8} and @code{CALLX12}) | |
354 | where the target address is specified in a register. The Xtensa | |
355 | assembler can automatically relax immediate call instructions into | |
356 | indirect call instructions. This relaxation is done by loading the | |
357 | address of the called function into the callee's return address register | |
358 | and then using a @code{CALLX} instruction. So, for example: | |
359 | ||
360 | @smallexample | |
361 | call8 func | |
362 | @end smallexample | |
363 | ||
364 | might be relaxed to: | |
365 | ||
366 | @smallexample | |
367 | .literal .L1, func | |
368 | l32r a8, .L1 | |
369 | callx8 a8 | |
370 | @end smallexample | |
371 | ||
372 | Because the addresses of targets of function calls are not generally | |
373 | known until link-time, the assembler must assume the worst and relax all | |
374 | the calls to functions in other source files, not just those that really | |
375 | will be out of range. The linker can recognize calls that were | |
43cd72b9 BW |
376 | unnecessarily relaxed, and it will remove the overhead introduced by the |
377 | assembler for those cases where direct calls are sufficient. | |
e0001a05 | 378 | |
43cd72b9 BW |
379 | Call relaxation is disabled by default because it can have a negative |
380 | effect on both code size and performance, although the linker can | |
381 | usually eliminate the unnecessary overhead. If a program is too large | |
382 | and some of the calls are out of range, function call relaxation can be | |
383 | enabled 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 |
391 | The assembler normally performs the following other relaxations. They |
392 | can 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 | |
399 | The @code{MOVI} machine instruction can only materialize values in the | |
400 | range from -2048 to 2047. Values outside this range are best | |
60493797 | 401 | materialized with @code{L32R} instructions. Thus: |
e0001a05 NC |
402 | |
403 | @smallexample | |
404 | movi a0, 100000 | |
405 | @end smallexample | |
406 | ||
407 | is 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 | |
422 | The @code{L8UI} machine instruction can only be used with immediate | |
423 | offsets in the range from 0 to 255. The @code{L16SI} and @code{L16UI} | |
424 | machine 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 | |
426 | 1020. A load offset outside these ranges can be materalized with | |
427 | an @code{L32R} instruction if the destination register of the load | |
428 | is different than the source address register. For example: | |
429 | ||
430 | @smallexample | |
431 | l32i a1, a0, 2040 | |
432 | @end smallexample | |
433 | ||
434 | is 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 | |
444 | If the load destination and source address register are the same, an | |
445 | out-of-range offset causes an error. | |
446 | ||
447 | @cindex @code{ADDI} instructions, relaxation | |
448 | @cindex relaxation of @code{ADDI} instructions | |
449 | The Xtensa @code{ADDI} instruction only allows immediate operands in the | |
450 | range from -128 to 127. There are a number of alternate instruction | |
43cd72b9 | 451 | sequences for the @code{ADDI} operation. First, if the |
e0001a05 NC |
452 | immediate is 0, the @code{ADDI} will be turned into a @code{MOV.N} |
453 | instruction (or the equivalent @code{OR} instruction if the code density | |
454 | option is not available). If the @code{ADDI} immediate is outside of | |
455 | the range -128 to 127, but inside the range -32896 to 32639, an | |
456 | @code{ADDMI} instruction or @code{ADDMI}/@code{ADDI} sequence will be | |
457 | used. Finally, if the immediate is outside of this range and a free | |
458 | register is available, an @code{L32R}/@code{ADD} sequence will be used | |
459 | with a literal allocated from the literal pool. | |
460 | ||
461 | For 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 | ||
470 | is 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 | ||
487 | The 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 | ||
495 | All the Xtensa-specific directives that apply to a region of code use | |
496 | this syntax. | |
497 | ||
498 | The directive applies to code between the @code{.begin} and the | |
499 | @code{.end}. The state of the option after the @code{.end} reverts to | |
500 | what it was before the @code{.begin}. | |
501 | A nested @code{.begin}/@code{.end} region can further | |
502 | change the state of the directive without having to be aware of its | |
503 | outer state. For example, consider: | |
504 | ||
505 | @smallexample | |
43cd72b9 | 506 | .begin no-transform |
e0001a05 | 507 | L: add a0, a1, a2 |
43cd72b9 | 508 | .begin transform |
e0001a05 | 509 | M: add a0, a1, a2 |
43cd72b9 | 510 | .end transform |
e0001a05 | 511 | N: add a0, a1, a2 |
43cd72b9 | 512 | .end no-transform |
e0001a05 NC |
513 | @end smallexample |
514 | ||
43cd72b9 BW |
515 | The @code{ADD} opcodes at @code{L} and @code{N} in the outer |
516 | @code{no-transform} region both result in @code{ADD} machine instructions, | |
517 | but 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 | |
520 | The advantage of this style is that it works well inside macros which can | |
521 | preserve the context of their callers. | |
522 | ||
e0001a05 NC |
523 | The 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 |
540 | The @code{schedule} directive is recognized only for compatibility with |
541 | Tensilica's assembler. | |
e0001a05 NC |
542 | |
543 | @smallexample | |
43cd72b9 BW |
544 | .begin [no-]schedule |
545 | .end [no-]schedule | |
e0001a05 NC |
546 | @end smallexample |
547 | ||
43cd72b9 | 548 | This 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 | ||
555 | The @code{longcalls} directive enables or disables function call | |
556 | relaxation. @xref{Xtensa Call Relaxation, ,Function Call Relaxation}. | |
557 | ||
558 | @smallexample | |
559 | .begin [no-]longcalls | |
560 | .end [no-]longcalls | |
561 | @end smallexample | |
562 | ||
563 | Call relaxation is disabled by default unless the @samp{--longcalls} | |
43cd72b9 BW |
564 | command-line option is specified. The @code{longcalls} directive |
565 | overrides 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 | |
572 | This directive enables or disables all assembler transformation, | |
573 | including relaxation (@pxref{Xtensa Relaxation, ,Xtensa Relaxation}) and | |
574 | optimization (@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 |
581 | Transformations are enabled by default unless the @samp{--no-transform} |
582 | option is used. The @code{transform} directive overrides the default | |
583 | determined by the command-line options. An underscore opcode prefix, | |
584 | disabling transformation of that opcode, always takes precedence over | |
585 | both directives and command-line flags. | |
e0001a05 NC |
586 | |
587 | @node Literal Directive | |
588 | @subsection literal | |
589 | @cindex @code{literal} directive | |
590 | ||
591 | The @code{.literal} directive is used to define literal pool data, i.e., | |
592 | read-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 | ||
598 | This directive is similar to the standard @code{.word} directive, except | |
599 | that the actual location of the literal data is determined by the | |
600 | assembler and linker, not by the position of the @code{.literal} | |
601 | directive. Using this directive gives the assembler freedom to locate | |
602 | the literal data in the most appropriate place and possibly to combine | |
603 | identical literals. For example, the code: | |
604 | ||
605 | @smallexample | |
606 | entry sp, 40 | |
607 | .literal .L1, sym | |
608 | l32r a4, .L1 | |
609 | @end smallexample | |
610 | ||
611 | can 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 | |
614 | the data in a literal pool. | |
615 | ||
43cd72b9 | 616 | Literal 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} |
620 | section; however, when using the @samp{--text-@-section-@-literals} | |
621 | option (@pxref{Xtensa Options, ,Command Line Options}), the literal | |
622 | pools are placed in the current section. These text section literal | |
623 | pools are created automatically before @code{ENTRY} instructions and | |
624 | manually after @samp{.literal_position} directives (@pxref{Literal | |
625 | Position Directive, ,literal_position}). If there are no preceding | |
626 | @code{ENTRY} instructions, explicit @code{.literal_position} directives | |
627 | must 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 | ||
634 | When using @samp{--text-@-section-@-literals} to place literals inline | |
635 | in the section being assembled, the @code{.literal_position} directive | |
636 | can be used to mark a potential location for a literal pool. | |
637 | ||
638 | @smallexample | |
639 | .literal_position | |
640 | @end smallexample | |
641 | ||
642 | The @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 | |
646 | The assembler will automatically place text section literal pools | |
647 | before @code{ENTRY} instructions, so the @code{.literal_position} | |
648 | directive is only needed to specify some other location for a literal | |
649 | pool. You may need to add an explicit jump instruction to skip over an | |
650 | inline literal pool. | |
651 | ||
652 | For example, an interrupt vector does not begin with an @code{ENTRY} | |
653 | instruction so the assembler will be unable to automatically find a good | |
654 | place to put a literal pool. Moreover, the code for the interrupt | |
655 | vector must be at a specific starting address, so the literal pool | |
656 | cannot come before the start of the code. The literal pool for the | |
657 | vector must be explicitly positioned in the middle of the vector (before | |
43cd72b9 BW |
658 | any uses of the literals, due to the negative offsets used by |
659 | PC-relative @code{L32R} instructions). The @code{.literal_position} | |
e0001a05 NC |
660 | directive can be used to do this. In the following code, the literal |
661 | for @samp{M} will automatically be aligned correctly and is placed after | |
662 | the unconditional jump. | |
663 | ||
664 | @smallexample | |
665 | .global M | |
666 | code_start: | |
667 | j continue | |
668 | .literal_position | |
669 | .align 4 | |
670 | continue: | |
671 | movi a4, M | |
672 | @end smallexample | |
673 | ||
674 | @node Literal Prefix Directive | |
675 | @subsection literal_prefix | |
676 | @cindex @code{literal_prefix} directive | |
677 | ||
678 | The @code{literal_prefix} directive allows you to specify different | |
679 | sections to hold literals from different portions of an assembly file. | |
680 | With this directive, a single assembly file can be used to generate code | |
681 | into 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 |
688 | By default the assembler places literal pools in sections separate from |
689 | the 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 | |
692 | Literals Directive}). The @code{literal_prefix} directive causes | |
693 | different literal sections to be used for the code inside the delimited | |
694 | region. The new literal sections are determined by including @var{name} | |
695 | as a prefix to the default literal section names. If the @var{name} | |
696 | argument is omitted, the literal sections revert to the defaults. This | |
697 | directive has no effect when using the | |
698 | @samp{--text-@-section-@-literals} option (@pxref{Xtensa Options, | |
699 | ,Command Line Options}). | |
700 | ||
701 | Except for two special cases, the assembler determines the new literal | |
702 | sections by simply prepending @var{name} to the default section names, | |
703 | resulting in @code{@var{name}.literal} and @code{@var{name}.lit4} | |
704 | sections. The @code{literal_prefix} directive is often used with the | |
705 | name of the current text section as the prefix argument. To facilitate | |
706 | this 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. | |
709 | For example, if @var{name} is @code{.iram0.text}, then the literal | |
710 | sections will be @code{.iram0.literal} and @code{.iram0.lit4}. Second, | |
711 | if @var{name} begins with @code{.gnu.linkonce.t.}, then the literal | |
712 | section 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 |
722 | The @code{absolute-@-literals} and @code{no-@-absolute-@-literals} |
723 | directives control the absolute vs.@: PC-relative mode for @code{L32R} | |
724 | instructions. These are relevant only for Xtensa configurations that | |
725 | include 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 |
732 | These directives do not change the @code{L32R} mode---they only cause |
733 | the assembler to emit the appropriate kind of relocation for @code{L32R} | |
734 | instructions and to place the literal values in the appropriate section. | |
735 | To change the @code{L32R} mode, the program must write the | |
736 | @code{LITBASE} special register. It is the programmer's responsibility | |
737 | to keep track of the mode and indicate to the assembler which mode is | |
738 | used in each region of code. | |
739 | ||
43cd72b9 BW |
740 | If the Xtensa configuration includes the absolute @code{L32R} addressing |
741 | option, the default is to assume absolute @code{L32R} addressing unless | |
742 | the @samp{--no-@-absolute-@-literals} command-line option is specified. | |
743 | Otherwise, the default is to assume PC-relative @code{L32R} addressing. | |
744 | The @code{absolute-@-literals} directive can then be used to override | |
745 | the default determined by the command-line options. | |
e0001a05 NC |
746 | |
747 | @node Frame Directive | |
748 | @subsection frame | |
749 | @cindex @code{frame} directive | |
750 | ||
751 | This directive tells the assembler to emit information to allow the | |
752 | debugger to locate a function's stack frame. The syntax is: | |
753 | ||
754 | @smallexample | |
755 | .frame @var{reg}, @var{size} | |
756 | @end smallexample | |
757 | ||
758 | where @var{reg} is the register used to hold the frame pointer (usually | |
759 | the same as the stack pointer) and @var{size} is the size in bytes of | |
760 | the stack frame. The @code{.frame} directive is typically placed | |
43cd72b9 | 761 | near the @code{ENTRY} instruction for a function. |
e0001a05 | 762 | |
43cd72b9 | 763 | In many circumstances, this information just duplicates the |
e0001a05 NC |
764 | information given in the function's @code{ENTRY} instruction; however, |
765 | there are two cases where this is not true: | |
766 | ||
767 | @enumerate | |
768 | @item | |
769 | The size of the stack frame is too big to fit in the immediate field | |
770 | of the @code{ENTRY} instruction. | |
771 | ||
772 | @item | |
773 | The frame pointer is different than the stack pointer, as with functions | |
774 | that call @code{alloca}. | |
775 | @end enumerate | |
776 | ||
777 | @c Local Variables: | |
778 | @c fill-column: 72 | |
779 | @c End: |