Make default compression gABI compliant
[binutils-gdb.git] / gas / doc / c-mips.texi
1 @c Copyright (C) 1991-2015 Free Software Foundation, Inc.
2 @c This is part of the GAS manual.
3 @c For copying conditions, see the file as.texinfo.
4 @ifset GENERIC
5 @page
6 @node MIPS-Dependent
7 @chapter MIPS Dependent Features
8 @end ifset
9 @ifclear GENERIC
10 @node Machine Dependencies
11 @chapter MIPS Dependent Features
12 @end ifclear
13
14 @cindex MIPS processor
15 @sc{gnu} @code{@value{AS}} for MIPS architectures supports several
16 different MIPS processors, and MIPS ISA levels I through V, MIPS32,
17 and MIPS64. For information about the MIPS instruction set, see
18 @cite{MIPS RISC Architecture}, by Kane and Heindrich (Prentice-Hall).
19 For an overview of MIPS assembly conventions, see ``Appendix D:
20 Assembly Language Programming'' in the same work.
21
22 @menu
23 * MIPS Options:: Assembler options
24 * MIPS Macros:: High-level assembly macros
25 * MIPS Symbol Sizes:: Directives to override the size of symbols
26 * MIPS Small Data:: Controlling the use of small data accesses
27 * MIPS ISA:: Directives to override the ISA level
28 * MIPS assembly options:: Directives to control code generation
29 * MIPS autoextend:: Directives for extending MIPS 16 bit instructions
30 * MIPS insn:: Directive to mark data as an instruction
31 * MIPS FP ABIs:: Marking which FP ABI is in use
32 * MIPS NaN Encodings:: Directives to record which NaN encoding is being used
33 * MIPS Option Stack:: Directives to save and restore options
34 * MIPS ASE Instruction Generation Overrides:: Directives to control
35 generation of MIPS ASE instructions
36 * MIPS Floating-Point:: Directives to override floating-point options
37 * MIPS Syntax:: MIPS specific syntactical considerations
38 @end menu
39
40 @node MIPS Options
41 @section Assembler options
42
43 The MIPS configurations of @sc{gnu} @code{@value{AS}} support these
44 special options:
45
46 @table @code
47 @cindex @code{-G} option (MIPS)
48 @item -G @var{num}
49 Set the ``small data'' limit to @var{n} bytes. The default limit is 8 bytes.
50 @xref{MIPS Small Data,, Controlling the use of small data accesses}.
51
52 @cindex @code{-EB} option (MIPS)
53 @cindex @code{-EL} option (MIPS)
54 @cindex MIPS big-endian output
55 @cindex MIPS little-endian output
56 @cindex big-endian output, MIPS
57 @cindex little-endian output, MIPS
58 @item -EB
59 @itemx -EL
60 Any MIPS configuration of @code{@value{AS}} can select big-endian or
61 little-endian output at run time (unlike the other @sc{gnu} development
62 tools, which must be configured for one or the other). Use @samp{-EB}
63 to select big-endian output, and @samp{-EL} for little-endian.
64
65 @item -KPIC
66 @cindex PIC selection, MIPS
67 @cindex @option{-KPIC} option, MIPS
68 Generate SVR4-style PIC. This option tells the assembler to generate
69 SVR4-style position-independent macro expansions. It also tells the
70 assembler to mark the output file as PIC.
71
72 @item -mvxworks-pic
73 @cindex @option{-mvxworks-pic} option, MIPS
74 Generate VxWorks PIC. This option tells the assembler to generate
75 VxWorks-style position-independent macro expansions.
76
77 @cindex MIPS architecture options
78 @item -mips1
79 @itemx -mips2
80 @itemx -mips3
81 @itemx -mips4
82 @itemx -mips5
83 @itemx -mips32
84 @itemx -mips32r2
85 @itemx -mips32r3
86 @itemx -mips32r5
87 @itemx -mips32r6
88 @itemx -mips64
89 @itemx -mips64r2
90 @itemx -mips64r3
91 @itemx -mips64r5
92 @itemx -mips64r6
93 Generate code for a particular MIPS Instruction Set Architecture level.
94 @samp{-mips1} corresponds to the R2000 and R3000 processors,
95 @samp{-mips2} to the R6000 processor, @samp{-mips3} to the
96 R4000 processor, and @samp{-mips4} to the R8000 and R10000 processors.
97 @samp{-mips5}, @samp{-mips32}, @samp{-mips32r2}, @samp{-mips32r3},
98 @samp{-mips32r5}, @samp{-mips32r6}, @samp{-mips64}, @samp{-mips64r2},
99 @samp{-mips64r3}, @samp{-mips64r5}, and @samp{-mips64r6} correspond to
100 generic MIPS V, MIPS32, MIPS32 Release 2, MIPS32 Release 3, MIPS32
101 Release 5, MIPS32 Release 6, MIPS64, and MIPS64 Release 2, MIPS64
102 Release 3, MIPS64 Release 5, and MIPS64 Release 6 ISA processors,
103 respectively. You can also switch instruction sets during the assembly;
104 see @ref{MIPS ISA, Directives to override the ISA level}.
105
106 @item -mgp32
107 @itemx -mfp32
108 Some macros have different expansions for 32-bit and 64-bit registers.
109 The register sizes are normally inferred from the ISA and ABI, but these
110 flags force a certain group of registers to be treated as 32 bits wide at
111 all times. @samp{-mgp32} controls the size of general-purpose registers
112 and @samp{-mfp32} controls the size of floating-point registers.
113
114 The @code{.set gp=32} and @code{.set fp=32} directives allow the size
115 of registers to be changed for parts of an object. The default value is
116 restored by @code{.set gp=default} and @code{.set fp=default}.
117
118 On some MIPS variants there is a 32-bit mode flag; when this flag is
119 set, 64-bit instructions generate a trap. Also, some 32-bit OSes only
120 save the 32-bit registers on a context switch, so it is essential never
121 to use the 64-bit registers.
122
123 @item -mgp64
124 @itemx -mfp64
125 Assume that 64-bit registers are available. This is provided in the
126 interests of symmetry with @samp{-mgp32} and @samp{-mfp32}.
127
128 The @code{.set gp=64} and @code{.set fp=64} directives allow the size
129 of registers to be changed for parts of an object. The default value is
130 restored by @code{.set gp=default} and @code{.set fp=default}.
131
132 @item -mfpxx
133 Make no assumptions about whether 32-bit or 64-bit floating-point
134 registers are available. This is provided to support having modules
135 compatible with either @samp{-mfp32} or @samp{-mfp64}. This option can
136 only be used with MIPS II and above.
137
138 The @code{.set fp=xx} directive allows a part of an object to be marked
139 as not making assumptions about 32-bit or 64-bit FP registers. The
140 default value is restored by @code{.set fp=default}.
141
142 @item -modd-spreg
143 @itemx -mno-odd-spreg
144 Enable use of floating-point operations on odd-numbered single-precision
145 registers when supported by the ISA. @samp{-mfpxx} implies
146 @samp{-mno-odd-spreg}, otherwise the default is @samp{-modd-spreg}
147
148 @item -mips16
149 @itemx -no-mips16
150 Generate code for the MIPS 16 processor. This is equivalent to putting
151 @code{.set mips16} at the start of the assembly file. @samp{-no-mips16}
152 turns off this option.
153
154 @item -mmicromips
155 @itemx -mno-micromips
156 Generate code for the microMIPS processor. This is equivalent to putting
157 @code{.set micromips} at the start of the assembly file. @samp{-mno-micromips}
158 turns off this option. This is equivalent to putting @code{.set nomicromips}
159 at the start of the assembly file.
160
161 @item -msmartmips
162 @itemx -mno-smartmips
163 Enables the SmartMIPS extensions to the MIPS32 instruction set, which
164 provides a number of new instructions which target smartcard and
165 cryptographic applications. This is equivalent to putting
166 @code{.set smartmips} at the start of the assembly file.
167 @samp{-mno-smartmips} turns off this option.
168
169 @item -mips3d
170 @itemx -no-mips3d
171 Generate code for the MIPS-3D Application Specific Extension.
172 This tells the assembler to accept MIPS-3D instructions.
173 @samp{-no-mips3d} turns off this option.
174
175 @item -mdmx
176 @itemx -no-mdmx
177 Generate code for the MDMX Application Specific Extension.
178 This tells the assembler to accept MDMX instructions.
179 @samp{-no-mdmx} turns off this option.
180
181 @item -mdsp
182 @itemx -mno-dsp
183 Generate code for the DSP Release 1 Application Specific Extension.
184 This tells the assembler to accept DSP Release 1 instructions.
185 @samp{-mno-dsp} turns off this option.
186
187 @item -mdspr2
188 @itemx -mno-dspr2
189 Generate code for the DSP Release 2 Application Specific Extension.
190 This option implies -mdsp.
191 This tells the assembler to accept DSP Release 2 instructions.
192 @samp{-mno-dspr2} turns off this option.
193
194 @item -mmt
195 @itemx -mno-mt
196 Generate code for the MT Application Specific Extension.
197 This tells the assembler to accept MT instructions.
198 @samp{-mno-mt} turns off this option.
199
200 @item -mmcu
201 @itemx -mno-mcu
202 Generate code for the MCU Application Specific Extension.
203 This tells the assembler to accept MCU instructions.
204 @samp{-mno-mcu} turns off this option.
205
206 @item -mmsa
207 @itemx -mno-msa
208 Generate code for the MIPS SIMD Architecture Extension.
209 This tells the assembler to accept MSA instructions.
210 @samp{-mno-msa} turns off this option.
211
212 @item -mxpa
213 @itemx -mno-xpa
214 Generate code for the MIPS eXtended Physical Address (XPA) Extension.
215 This tells the assembler to accept XPA instructions.
216 @samp{-mno-xpa} turns off this option.
217
218 @item -mvirt
219 @itemx -mno-virt
220 Generate code for the Virtualization Application Specific Extension.
221 This tells the assembler to accept Virtualization instructions.
222 @samp{-mno-virt} turns off this option.
223
224 @item -minsn32
225 @itemx -mno-insn32
226 Only use 32-bit instruction encodings when generating code for the
227 microMIPS processor. This option inhibits the use of any 16-bit
228 instructions. This is equivalent to putting @code{.set insn32} at
229 the start of the assembly file. @samp{-mno-insn32} turns off this
230 option. This is equivalent to putting @code{.set noinsn32} at the
231 start of the assembly file. By default @samp{-mno-insn32} is
232 selected, allowing all instructions to be used.
233
234 @item -mfix7000
235 @itemx -mno-fix7000
236 Cause nops to be inserted if the read of the destination register
237 of an mfhi or mflo instruction occurs in the following two instructions.
238
239 @item -mfix-rm7000
240 @itemx -mno-fix-rm7000
241 Cause nops to be inserted if a dmult or dmultu instruction is
242 followed by a load instruction.
243
244 @item -mfix-loongson2f-jump
245 @itemx -mno-fix-loongson2f-jump
246 Eliminate instruction fetch from outside 256M region to work around the
247 Loongson2F @samp{jump} instructions. Without it, under extreme cases,
248 the kernel may crash. The issue has been solved in latest processor
249 batches, but this fix has no side effect to them.
250
251 @item -mfix-loongson2f-nop
252 @itemx -mno-fix-loongson2f-nop
253 Replace nops by @code{or at,at,zero} to work around the Loongson2F
254 @samp{nop} errata. Without it, under extreme cases, the CPU might
255 deadlock. The issue has been solved in later Loongson2F batches, but
256 this fix has no side effect to them.
257
258 @item -mfix-vr4120
259 @itemx -mno-fix-vr4120
260 Insert nops to work around certain VR4120 errata. This option is
261 intended to be used on GCC-generated code: it is not designed to catch
262 all problems in hand-written assembler code.
263
264 @item -mfix-vr4130
265 @itemx -mno-fix-vr4130
266 Insert nops to work around the VR4130 @samp{mflo}/@samp{mfhi} errata.
267
268 @item -mfix-24k
269 @itemx -mno-fix-24k
270 Insert nops to work around the 24K @samp{eret}/@samp{deret} errata.
271
272 @item -mfix-cn63xxp1
273 @itemx -mno-fix-cn63xxp1
274 Replace @code{pref} hints 0 - 4 and 6 - 24 with hint 28 to work around
275 certain CN63XXP1 errata.
276
277 @item -m4010
278 @itemx -no-m4010
279 Generate code for the LSI R4010 chip. This tells the assembler to
280 accept the R4010-specific instructions (@samp{addciu}, @samp{ffc},
281 etc.), and to not schedule @samp{nop} instructions around accesses to
282 the @samp{HI} and @samp{LO} registers. @samp{-no-m4010} turns off this
283 option.
284
285 @item -m4650
286 @itemx -no-m4650
287 Generate code for the MIPS R4650 chip. This tells the assembler to accept
288 the @samp{mad} and @samp{madu} instruction, and to not schedule @samp{nop}
289 instructions around accesses to the @samp{HI} and @samp{LO} registers.
290 @samp{-no-m4650} turns off this option.
291
292 @item -m3900
293 @itemx -no-m3900
294 @itemx -m4100
295 @itemx -no-m4100
296 For each option @samp{-m@var{nnnn}}, generate code for the MIPS
297 R@var{nnnn} chip. This tells the assembler to accept instructions
298 specific to that chip, and to schedule for that chip's hazards.
299
300 @item -march=@var{cpu}
301 Generate code for a particular MIPS CPU. It is exactly equivalent to
302 @samp{-m@var{cpu}}, except that there are more value of @var{cpu}
303 understood. Valid @var{cpu} value are:
304
305 @quotation
306 2000,
307 3000,
308 3900,
309 4000,
310 4010,
311 4100,
312 4111,
313 vr4120,
314 vr4130,
315 vr4181,
316 4300,
317 4400,
318 4600,
319 4650,
320 5000,
321 rm5200,
322 rm5230,
323 rm5231,
324 rm5261,
325 rm5721,
326 vr5400,
327 vr5500,
328 6000,
329 rm7000,
330 8000,
331 rm9000,
332 10000,
333 12000,
334 14000,
335 16000,
336 4kc,
337 4km,
338 4kp,
339 4ksc,
340 4kec,
341 4kem,
342 4kep,
343 4ksd,
344 m4k,
345 m4kp,
346 m14k,
347 m14kc,
348 m14ke,
349 m14kec,
350 24kc,
351 24kf2_1,
352 24kf,
353 24kf1_1,
354 24kec,
355 24kef2_1,
356 24kef,
357 24kef1_1,
358 34kc,
359 34kf2_1,
360 34kf,
361 34kf1_1,
362 34kn,
363 74kc,
364 74kf2_1,
365 74kf,
366 74kf1_1,
367 74kf3_2,
368 1004kc,
369 1004kf2_1,
370 1004kf,
371 1004kf1_1,
372 p5600,
373 5kc,
374 5kf,
375 20kc,
376 25kf,
377 sb1,
378 sb1a,
379 i6400,
380 loongson2e,
381 loongson2f,
382 loongson3a,
383 octeon,
384 octeon+,
385 octeon2,
386 octeon3,
387 xlr,
388 xlp
389 @end quotation
390
391 For compatibility reasons, @samp{@var{n}x} and @samp{@var{b}fx} are
392 accepted as synonyms for @samp{@var{n}f1_1}. These values are
393 deprecated.
394
395 @item -mtune=@var{cpu}
396 Schedule and tune for a particular MIPS CPU. Valid @var{cpu} values are
397 identical to @samp{-march=@var{cpu}}.
398
399 @item -mabi=@var{abi}
400 Record which ABI the source code uses. The recognized arguments
401 are: @samp{32}, @samp{n32}, @samp{o64}, @samp{64} and @samp{eabi}.
402
403 @item -msym32
404 @itemx -mno-sym32
405 @cindex -msym32
406 @cindex -mno-sym32
407 Equivalent to adding @code{.set sym32} or @code{.set nosym32} to
408 the beginning of the assembler input. @xref{MIPS Symbol Sizes}.
409
410 @cindex @code{-nocpp} ignored (MIPS)
411 @item -nocpp
412 This option is ignored. It is accepted for command-line compatibility with
413 other assemblers, which use it to turn off C style preprocessing. With
414 @sc{gnu} @code{@value{AS}}, there is no need for @samp{-nocpp}, because the
415 @sc{gnu} assembler itself never runs the C preprocessor.
416
417 @item -msoft-float
418 @itemx -mhard-float
419 Disable or enable floating-point instructions. Note that by default
420 floating-point instructions are always allowed even with CPU targets
421 that don't have support for these instructions.
422
423 @item -msingle-float
424 @itemx -mdouble-float
425 Disable or enable double-precision floating-point operations. Note
426 that by default double-precision floating-point operations are always
427 allowed even with CPU targets that don't have support for these
428 operations.
429
430 @item --construct-floats
431 @itemx --no-construct-floats
432 The @code{--no-construct-floats} option disables the construction of
433 double width floating point constants by loading the two halves of the
434 value into the two single width floating point registers that make up
435 the double width register. This feature is useful if the processor
436 support the FR bit in its status register, and this bit is known (by
437 the programmer) to be set. This bit prevents the aliasing of the double
438 width register by the single width registers.
439
440 By default @code{--construct-floats} is selected, allowing construction
441 of these floating point constants.
442
443 @item --relax-branch
444 @itemx --no-relax-branch
445 The @samp{--relax-branch} option enables the relaxation of out-of-range
446 branches. Any branches whose target cannot be reached directly are
447 converted to a small instruction sequence including an inverse-condition
448 branch to the physically next instruction, and a jump to the original
449 target is inserted between the two instructions. In PIC code the jump
450 will involve further instructions for address calculation.
451
452 The @code{BC1ANY2F}, @code{BC1ANY2T}, @code{BC1ANY4F}, @code{BC1ANY4T},
453 @code{BPOSGE32} and @code{BPOSGE64} instructions are excluded from
454 relaxation, because they have no complementing counterparts. They could
455 be relaxed with the use of a longer sequence involving another branch,
456 however this has not been implemented and if their target turns out of
457 reach, they produce an error even if branch relaxation is enabled.
458
459 Also no MIPS16 branches are ever relaxed.
460
461 By default @samp{--no-relax-branch} is selected, causing any out-of-range
462 branches to produce an error.
463
464 @cindex @option{-mnan=} command line option, MIPS
465 @item -mnan=@var{encoding}
466 This option indicates whether the source code uses the IEEE 2008
467 NaN encoding (@option{-mnan=2008}) or the original MIPS encoding
468 (@option{-mnan=legacy}). It is equivalent to adding a @code{.nan}
469 directive to the beginning of the source file. @xref{MIPS NaN Encodings}.
470
471 @option{-mnan=legacy} is the default if no @option{-mnan} option or
472 @code{.nan} directive is used.
473
474 @item --trap
475 @itemx --no-break
476 @c FIXME! (1) reflect these options (next item too) in option summaries;
477 @c (2) stop teasing, say _which_ instructions expanded _how_.
478 @code{@value{AS}} automatically macro expands certain division and
479 multiplication instructions to check for overflow and division by zero. This
480 option causes @code{@value{AS}} to generate code to take a trap exception
481 rather than a break exception when an error is detected. The trap instructions
482 are only supported at Instruction Set Architecture level 2 and higher.
483
484 @item --break
485 @itemx --no-trap
486 Generate code to take a break exception rather than a trap exception when an
487 error is detected. This is the default.
488
489 @item -mpdr
490 @itemx -mno-pdr
491 Control generation of @code{.pdr} sections. Off by default on IRIX, on
492 elsewhere.
493
494 @item -mshared
495 @itemx -mno-shared
496 When generating code using the Unix calling conventions (selected by
497 @samp{-KPIC} or @samp{-mcall_shared}), gas will normally generate code
498 which can go into a shared library. The @samp{-mno-shared} option
499 tells gas to generate code which uses the calling convention, but can
500 not go into a shared library. The resulting code is slightly more
501 efficient. This option only affects the handling of the
502 @samp{.cpload} and @samp{.cpsetup} pseudo-ops.
503 @end table
504
505 @node MIPS Macros
506 @section High-level assembly macros
507
508 MIPS assemblers have traditionally provided a wider range of
509 instructions than the MIPS architecture itself. These extra
510 instructions are usually referred to as ``macro'' instructions
511 @footnote{The term ``macro'' is somewhat overloaded here, since
512 these macros have no relation to those defined by @code{.macro},
513 @pxref{Macro,, @code{.macro}}.}.
514
515 Some MIPS macro instructions extend an underlying architectural instruction
516 while others are entirely new. An example of the former type is @code{and},
517 which allows the third operand to be either a register or an arbitrary
518 immediate value. Examples of the latter type include @code{bgt}, which
519 branches to the third operand when the first operand is greater than
520 the second operand, and @code{ulh}, which implements an unaligned
521 2-byte load.
522
523 One of the most common extensions provided by macros is to expand
524 memory offsets to the full address range (32 or 64 bits) and to allow
525 symbolic offsets such as @samp{my_data + 4} to be used in place of
526 integer constants. For example, the architectural instruction
527 @code{lbu} allows only a signed 16-bit offset, whereas the macro
528 @code{lbu} allows code such as @samp{lbu $4,array+32769($5)}.
529 The implementation of these symbolic offsets depends on several factors,
530 such as whether the assembler is generating SVR4-style PIC (selected by
531 @option{-KPIC}, @pxref{MIPS Options,, Assembler options}), the size of symbols
532 (@pxref{MIPS Symbol Sizes,, Directives to override the size of symbols}),
533 and the small data limit (@pxref{MIPS Small Data,, Controlling the use
534 of small data accesses}).
535
536 @kindex @code{.set macro}
537 @kindex @code{.set nomacro}
538 Sometimes it is undesirable to have one assembly instruction expand
539 to several machine instructions. The directive @code{.set nomacro}
540 tells the assembler to warn when this happens. @code{.set macro}
541 restores the default behavior.
542
543 @cindex @code{at} register, MIPS
544 @kindex @code{.set at=@var{reg}}
545 Some macro instructions need a temporary register to store intermediate
546 results. This register is usually @code{$1}, also known as @code{$at},
547 but it can be changed to any core register @var{reg} using
548 @code{.set at=@var{reg}}. Note that @code{$at} always refers
549 to @code{$1} regardless of which register is being used as the
550 temporary register.
551
552 @kindex @code{.set at}
553 @kindex @code{.set noat}
554 Implicit uses of the temporary register in macros could interfere with
555 explicit uses in the assembly code. The assembler therefore warns
556 whenever it sees an explicit use of the temporary register. The directive
557 @code{.set noat} silences this warning while @code{.set at} restores
558 the default behavior. It is safe to use @code{.set noat} while
559 @code{.set nomacro} is in effect since single-instruction macros
560 never need a temporary register.
561
562 Note that while the @sc{gnu} assembler provides these macros for compatibility,
563 it does not make any attempt to optimize them with the surrounding code.
564
565 @node MIPS Symbol Sizes
566 @section Directives to override the size of symbols
567
568 @kindex @code{.set sym32}
569 @kindex @code{.set nosym32}
570 The n64 ABI allows symbols to have any 64-bit value. Although this
571 provides a great deal of flexibility, it means that some macros have
572 much longer expansions than their 32-bit counterparts. For example,
573 the non-PIC expansion of @samp{dla $4,sym} is usually:
574
575 @smallexample
576 lui $4,%highest(sym)
577 lui $1,%hi(sym)
578 daddiu $4,$4,%higher(sym)
579 daddiu $1,$1,%lo(sym)
580 dsll32 $4,$4,0
581 daddu $4,$4,$1
582 @end smallexample
583
584 whereas the 32-bit expansion is simply:
585
586 @smallexample
587 lui $4,%hi(sym)
588 daddiu $4,$4,%lo(sym)
589 @end smallexample
590
591 n64 code is sometimes constructed in such a way that all symbolic
592 constants are known to have 32-bit values, and in such cases, it's
593 preferable to use the 32-bit expansion instead of the 64-bit
594 expansion.
595
596 You can use the @code{.set sym32} directive to tell the assembler
597 that, from this point on, all expressions of the form
598 @samp{@var{symbol}} or @samp{@var{symbol} + @var{offset}}
599 have 32-bit values. For example:
600
601 @smallexample
602 .set sym32
603 dla $4,sym
604 lw $4,sym+16
605 sw $4,sym+0x8000($4)
606 @end smallexample
607
608 will cause the assembler to treat @samp{sym}, @code{sym+16} and
609 @code{sym+0x8000} as 32-bit values. The handling of non-symbolic
610 addresses is not affected.
611
612 The directive @code{.set nosym32} ends a @code{.set sym32} block and
613 reverts to the normal behavior. It is also possible to change the
614 symbol size using the command-line options @option{-msym32} and
615 @option{-mno-sym32}.
616
617 These options and directives are always accepted, but at present,
618 they have no effect for anything other than n64.
619
620 @node MIPS Small Data
621 @section Controlling the use of small data accesses
622
623 @c This section deliberately glosses over the possibility of using -G
624 @c in SVR4-style PIC, as could be done on IRIX. We don't support that.
625 @cindex small data, MIPS
626 @cindex @code{gp} register, MIPS
627 It often takes several instructions to load the address of a symbol.
628 For example, when @samp{addr} is a 32-bit symbol, the non-PIC expansion
629 of @samp{dla $4,addr} is usually:
630
631 @smallexample
632 lui $4,%hi(addr)
633 daddiu $4,$4,%lo(addr)
634 @end smallexample
635
636 The sequence is much longer when @samp{addr} is a 64-bit symbol.
637 @xref{MIPS Symbol Sizes,, Directives to override the size of symbols}.
638
639 In order to cut down on this overhead, most embedded MIPS systems
640 set aside a 64-kilobyte ``small data'' area and guarantee that all
641 data of size @var{n} and smaller will be placed in that area.
642 The limit @var{n} is passed to both the assembler and the linker
643 using the command-line option @option{-G @var{n}}, @pxref{MIPS Options,,
644 Assembler options}. Note that the same value of @var{n} must be used
645 when linking and when assembling all input files to the link; any
646 inconsistency could cause a relocation overflow error.
647
648 The size of an object in the @code{.bss} section is set by the
649 @code{.comm} or @code{.lcomm} directive that defines it. The size of
650 an external object may be set with the @code{.extern} directive. For
651 example, @samp{.extern sym,4} declares that the object at @code{sym}
652 is 4 bytes in length, while leaving @code{sym} otherwise undefined.
653
654 When no @option{-G} option is given, the default limit is 8 bytes.
655 The option @option{-G 0} prevents any data from being automatically
656 classified as small.
657
658 It is also possible to mark specific objects as small by putting them
659 in the special sections @code{.sdata} and @code{.sbss}, which are
660 ``small'' counterparts of @code{.data} and @code{.bss} respectively.
661 The toolchain will treat such data as small regardless of the
662 @option{-G} setting.
663
664 On startup, systems that support a small data area are expected to
665 initialize register @code{$28}, also known as @code{$gp}, in such a
666 way that small data can be accessed using a 16-bit offset from that
667 register. For example, when @samp{addr} is small data,
668 the @samp{dla $4,addr} instruction above is equivalent to:
669
670 @smallexample
671 daddiu $4,$28,%gp_rel(addr)
672 @end smallexample
673
674 Small data is not supported for SVR4-style PIC.
675
676 @node MIPS ISA
677 @section Directives to override the ISA level
678
679 @cindex MIPS ISA override
680 @kindex @code{.set mips@var{n}}
681 @sc{gnu} @code{@value{AS}} supports an additional directive to change
682 the MIPS Instruction Set Architecture level on the fly: @code{.set
683 mips@var{n}}. @var{n} should be a number from 0 to 5, or 32, 32r2, 32r3,
684 32r5, 32r6, 64, 64r2, 64r3, 64r5 or 64r6.
685 The values other than 0 make the assembler accept instructions
686 for the corresponding ISA level, from that point on in the
687 assembly. @code{.set mips@var{n}} affects not only which instructions
688 are permitted, but also how certain macros are expanded. @code{.set
689 mips0} restores the ISA level to its original level: either the
690 level you selected with command line options, or the default for your
691 configuration. You can use this feature to permit specific MIPS III
692 instructions while assembling in 32 bit mode. Use this directive with
693 care!
694
695 @cindex MIPS CPU override
696 @kindex @code{.set arch=@var{cpu}}
697 The @code{.set arch=@var{cpu}} directive provides even finer control.
698 It changes the effective CPU target and allows the assembler to use
699 instructions specific to a particular CPU. All CPUs supported by the
700 @samp{-march} command line option are also selectable by this directive.
701 The original value is restored by @code{.set arch=default}.
702
703 The directive @code{.set mips16} puts the assembler into MIPS 16 mode,
704 in which it will assemble instructions for the MIPS 16 processor. Use
705 @code{.set nomips16} to return to normal 32 bit mode.
706
707 Traditional MIPS assemblers do not support this directive.
708
709 The directive @code{.set micromips} puts the assembler into microMIPS mode,
710 in which it will assemble instructions for the microMIPS processor. Use
711 @code{.set nomicromips} to return to normal 32 bit mode.
712
713 Traditional MIPS assemblers do not support this directive.
714
715 @node MIPS assembly options
716 @section Directives to control code generation
717
718 @cindex MIPS directives to override command line options
719 @kindex @code{.module}
720 The @code{.module} directive allows command line options to be set directly
721 from assembly. The format of the directive matches the @code{.set}
722 directive but only those options which are relevant to a whole module are
723 supported. The effect of a @code{.module} directive is the same as the
724 corresponding command line option. Where @code{.set} directives support
725 returning to a default then the @code{.module} directives do not as they
726 define the defaults.
727
728 These module-level directives must appear first in assembly.
729
730 Traditional MIPS assemblers do not support this directive.
731
732 @cindex MIPS 32-bit microMIPS instruction generation override
733 @kindex @code{.set insn32}
734 @kindex @code{.set noinsn32}
735 The directive @code{.set insn32} makes the assembler only use 32-bit
736 instruction encodings when generating code for the microMIPS processor.
737 This directive inhibits the use of any 16-bit instructions from that
738 point on in the assembly. The @code{.set noinsn32} directive allows
739 16-bit instructions to be accepted.
740
741 Traditional MIPS assemblers do not support this directive.
742
743 @node MIPS autoextend
744 @section Directives for extending MIPS 16 bit instructions
745
746 @kindex @code{.set autoextend}
747 @kindex @code{.set noautoextend}
748 By default, MIPS 16 instructions are automatically extended to 32 bits
749 when necessary. The directive @code{.set noautoextend} will turn this
750 off. When @code{.set noautoextend} is in effect, any 32 bit instruction
751 must be explicitly extended with the @code{.e} modifier (e.g.,
752 @code{li.e $4,1000}). The directive @code{.set autoextend} may be used
753 to once again automatically extend instructions when necessary.
754
755 This directive is only meaningful when in MIPS 16 mode. Traditional
756 MIPS assemblers do not support this directive.
757
758 @node MIPS insn
759 @section Directive to mark data as an instruction
760
761 @kindex @code{.insn}
762 The @code{.insn} directive tells @code{@value{AS}} that the following
763 data is actually instructions. This makes a difference in MIPS 16 and
764 microMIPS modes: when loading the address of a label which precedes
765 instructions, @code{@value{AS}} automatically adds 1 to the value, so
766 that jumping to the loaded address will do the right thing.
767
768 @kindex @code{.global}
769 The @code{.global} and @code{.globl} directives supported by
770 @code{@value{AS}} will by default mark the symbol as pointing to a
771 region of data not code. This means that, for example, any
772 instructions following such a symbol will not be disassembled by
773 @code{objdump} as it will regard them as data. To change this
774 behavior an optional section name can be placed after the symbol name
775 in the @code{.global} directive. If this section exists and is known
776 to be a code section, then the symbol will be marked as pointing at
777 code not data. Ie the syntax for the directive is:
778
779 @code{.global @var{symbol}[ @var{section}][, @var{symbol}[ @var{section}]] ...},
780
781 Here is a short example:
782
783 @example
784 .global foo .text, bar, baz .data
785 foo:
786 nop
787 bar:
788 .word 0x0
789 baz:
790 .word 0x1
791
792 @end example
793
794 @node MIPS FP ABIs
795 @section Directives to control the FP ABI
796 @menu
797 * MIPS FP ABI History:: History of FP ABIs
798 * MIPS FP ABI Variants:: Supported FP ABIs
799 * MIPS FP ABI Selection:: Automatic selection of FP ABI
800 * MIPS FP ABI Compatibility:: Linking different FP ABI variants
801 @end menu
802
803 @node MIPS FP ABI History
804 @subsection History of FP ABIs
805 @cindex @code{.gnu_attribute 4, @var{n}} directive, MIPS
806 @cindex @code{.gnu_attribute Tag_GNU_MIPS_ABI_FP, @var{n}} directive, MIPS
807 The MIPS ABIs support a variety of different floating-point extensions
808 where calling-convention and register sizes vary for floating-point data.
809 The extensions exist to support a wide variety of optional architecture
810 features. The resulting ABI variants are generally incompatible with each
811 other and must be tracked carefully.
812
813 Traditionally the use of an explicit @code{.gnu_attribute 4, @var{n}}
814 directive is used to indicate which ABI is in use by a specific module.
815 It was then left to the user to ensure that command line options and the
816 selected ABI were compatible with some potential for inconsistencies.
817
818 @node MIPS FP ABI Variants
819 @subsection Supported FP ABIs
820 The supported floating-point ABI variants are:
821
822 @table @code
823 @item 0 - No floating-point
824 This variant is used to indicate that floating-point is not used within
825 the module at all and therefore has no impact on the ABI. This is the
826 default.
827
828 @item 1 - Double-precision
829 This variant indicates that double-precision support is used. For 64-bit
830 ABIs this means that 64-bit wide floating-point registers are required.
831 For 32-bit ABIs this means that 32-bit wide floating-point registers are
832 required and double-precision operations use pairs of registers.
833
834 @item 2 - Single-precision
835 This variant indicates that single-precision support is used. Double
836 precision operations will be supported via soft-float routines.
837
838 @item 3 - Soft-float
839 This variant indicates that although floating-point support is used all
840 operations are emulated in software. This means the ABI is modified to
841 pass all floating-point data in general-purpose registers.
842
843 @item 4 - Deprecated
844 This variant existed as an initial attempt at supporting 64-bit wide
845 floating-point registers for O32 ABI on a MIPS32r2 CPU. This has been
846 superseded by 5, 6 and 7.
847
848 @item 5 - Double-precision 32-bit CPU, 32-bit or 64-bit FPU
849 This variant is used by 32-bit ABIs to indicate that the floating-point
850 code in the module has been designed to operate correctly with either
851 32-bit wide or 64-bit wide floating-point registers. Double-precision
852 support is used. Only O32 currently supports this variant and requires
853 a minimum architecture of MIPS II.
854
855 @item 6 - Double-precision 32-bit FPU, 64-bit FPU
856 This variant is used by 32-bit ABIs to indicate that the floating-point
857 code in the module requires 64-bit wide floating-point registers.
858 Double-precision support is used. Only O32 currently supports this
859 variant and requires a minimum architecture of MIPS32r2.
860
861 @item 7 - Double-precision compat 32-bit FPU, 64-bit FPU
862 This variant is used by 32-bit ABIs to indicate that the floating-point
863 code in the module requires 64-bit wide floating-point registers.
864 Double-precision support is used. This differs from the previous ABI
865 as it restricts use of odd-numbered single-precision registers. Only
866 O32 currently supports this variant and requires a minimum architecture
867 of MIPS32r2.
868 @end table
869
870 @node MIPS FP ABI Selection
871 @subsection Automatic selection of FP ABI
872 @cindex @code{.module fp=@var{nn}} directive, MIPS
873 In order to simplify and add safety to the process of selecting the
874 correct floating-point ABI, the assembler will automatically infer the
875 correct @code{.gnu_attribute 4, @var{n}} directive based on command line
876 options and @code{.module} overrides. Where an explicit
877 @code{.gnu_attribute 4, @var{n}} directive has been seen then a warning
878 will be raised if it does not match an inferred setting.
879
880 The floating-point ABI is inferred as follows. If @samp{-msoft-float}
881 has been used the module will be marked as soft-float. If
882 @samp{-msingle-float} has been used then the module will be marked as
883 single-precision. The remaining ABIs are then selected based
884 on the FP register width. Double-precision is selected if the width
885 of GP and FP registers match and the special double-precision variants
886 for 32-bit ABIs are then selected depending on @samp{-mfpxx},
887 @samp{-mfp64} and @samp{-mno-odd-spreg}.
888
889 @node MIPS FP ABI Compatibility
890 @subsection Linking different FP ABI variants
891 Modules using the default FP ABI (no floating-point) can be linked with
892 any other (singular) FP ABI variant.
893
894 Special compatibility support exists for O32 with the four
895 double-precision FP ABI variants. The @samp{-mfpxx} FP ABI is specifically
896 designed to be compatible with the standard double-precision ABI and the
897 @samp{-mfp64} FP ABIs. This makes it desirable for O32 modules to be
898 built as @samp{-mfpxx} to ensure the maximum compatibility with other
899 modules produced for more specific needs. The only FP ABIs which cannot
900 be linked together are the standard double-precision ABI and the full
901 @samp{-mfp64} ABI with @samp{-modd-spreg}.
902
903 @node MIPS NaN Encodings
904 @section Directives to record which NaN encoding is being used
905
906 @cindex MIPS IEEE 754 NaN data encoding selection
907 @cindex @code{.nan} directive, MIPS
908 The IEEE 754 floating-point standard defines two types of not-a-number
909 (NaN) data: ``signalling'' NaNs and ``quiet'' NaNs. The original version
910 of the standard did not specify how these two types should be
911 distinguished. Most implementations followed the i387 model, in which
912 the first bit of the significand is set for quiet NaNs and clear for
913 signalling NaNs. However, the original MIPS implementation assigned the
914 opposite meaning to the bit, so that it was set for signalling NaNs and
915 clear for quiet NaNs.
916
917 The 2008 revision of the standard formally suggested the i387 choice
918 and as from Sep 2012 the current release of the MIPS architecture
919 therefore optionally supports that form. Code that uses one NaN encoding
920 would usually be incompatible with code that uses the other NaN encoding,
921 so MIPS ELF objects have a flag (@code{EF_MIPS_NAN2008}) to record which
922 encoding is being used.
923
924 Assembly files can use the @code{.nan} directive to select between the
925 two encodings. @samp{.nan 2008} says that the assembly file uses the
926 IEEE 754-2008 encoding while @samp{.nan legacy} says that the file uses
927 the original MIPS encoding. If several @code{.nan} directives are given,
928 the final setting is the one that is used.
929
930 The command-line options @option{-mnan=legacy} and @option{-mnan=2008}
931 can be used instead of @samp{.nan legacy} and @samp{.nan 2008}
932 respectively. However, any @code{.nan} directive overrides the
933 command-line setting.
934
935 @samp{.nan legacy} is the default if no @code{.nan} directive or
936 @option{-mnan} option is given.
937
938 Note that @sc{gnu} @code{@value{AS}} does not produce NaNs itself and
939 therefore these directives do not affect code generation. They simply
940 control the setting of the @code{EF_MIPS_NAN2008} flag.
941
942 Traditional MIPS assemblers do not support these directives.
943
944 @node MIPS Option Stack
945 @section Directives to save and restore options
946
947 @cindex MIPS option stack
948 @kindex @code{.set push}
949 @kindex @code{.set pop}
950 The directives @code{.set push} and @code{.set pop} may be used to save
951 and restore the current settings for all the options which are
952 controlled by @code{.set}. The @code{.set push} directive saves the
953 current settings on a stack. The @code{.set pop} directive pops the
954 stack and restores the settings.
955
956 These directives can be useful inside an macro which must change an
957 option such as the ISA level or instruction reordering but does not want
958 to change the state of the code which invoked the macro.
959
960 Traditional MIPS assemblers do not support these directives.
961
962 @node MIPS ASE Instruction Generation Overrides
963 @section Directives to control generation of MIPS ASE instructions
964
965 @cindex MIPS MIPS-3D instruction generation override
966 @kindex @code{.set mips3d}
967 @kindex @code{.set nomips3d}
968 The directive @code{.set mips3d} makes the assembler accept instructions
969 from the MIPS-3D Application Specific Extension from that point on
970 in the assembly. The @code{.set nomips3d} directive prevents MIPS-3D
971 instructions from being accepted.
972
973 @cindex SmartMIPS instruction generation override
974 @kindex @code{.set smartmips}
975 @kindex @code{.set nosmartmips}
976 The directive @code{.set smartmips} makes the assembler accept
977 instructions from the SmartMIPS Application Specific Extension to the
978 MIPS32 ISA from that point on in the assembly. The
979 @code{.set nosmartmips} directive prevents SmartMIPS instructions from
980 being accepted.
981
982 @cindex MIPS MDMX instruction generation override
983 @kindex @code{.set mdmx}
984 @kindex @code{.set nomdmx}
985 The directive @code{.set mdmx} makes the assembler accept instructions
986 from the MDMX Application Specific Extension from that point on
987 in the assembly. The @code{.set nomdmx} directive prevents MDMX
988 instructions from being accepted.
989
990 @cindex MIPS DSP Release 1 instruction generation override
991 @kindex @code{.set dsp}
992 @kindex @code{.set nodsp}
993 The directive @code{.set dsp} makes the assembler accept instructions
994 from the DSP Release 1 Application Specific Extension from that point
995 on in the assembly. The @code{.set nodsp} directive prevents DSP
996 Release 1 instructions from being accepted.
997
998 @cindex MIPS DSP Release 2 instruction generation override
999 @kindex @code{.set dspr2}
1000 @kindex @code{.set nodspr2}
1001 The directive @code{.set dspr2} makes the assembler accept instructions
1002 from the DSP Release 2 Application Specific Extension from that point
1003 on in the assembly. This directive implies @code{.set dsp}. The
1004 @code{.set nodspr2} directive prevents DSP Release 2 instructions from
1005 being accepted.
1006
1007 @cindex MIPS MT instruction generation override
1008 @kindex @code{.set mt}
1009 @kindex @code{.set nomt}
1010 The directive @code{.set mt} makes the assembler accept instructions
1011 from the MT Application Specific Extension from that point on
1012 in the assembly. The @code{.set nomt} directive prevents MT
1013 instructions from being accepted.
1014
1015 @cindex MIPS MCU instruction generation override
1016 @kindex @code{.set mcu}
1017 @kindex @code{.set nomcu}
1018 The directive @code{.set mcu} makes the assembler accept instructions
1019 from the MCU Application Specific Extension from that point on
1020 in the assembly. The @code{.set nomcu} directive prevents MCU
1021 instructions from being accepted.
1022
1023 @cindex MIPS SIMD Architecture instruction generation override
1024 @kindex @code{.set msa}
1025 @kindex @code{.set nomsa}
1026 The directive @code{.set msa} makes the assembler accept instructions
1027 from the MIPS SIMD Architecture Extension from that point on
1028 in the assembly. The @code{.set nomsa} directive prevents MSA
1029 instructions from being accepted.
1030
1031 @cindex Virtualization instruction generation override
1032 @kindex @code{.set virt}
1033 @kindex @code{.set novirt}
1034 The directive @code{.set virt} makes the assembler accept instructions
1035 from the Virtualization Application Specific Extension from that point
1036 on in the assembly. The @code{.set novirt} directive prevents Virtualization
1037 instructions from being accepted.
1038
1039 @cindex MIPS eXtended Physical Address (XPA) instruction generation override
1040 @kindex @code{.set xpa}
1041 @kindex @code{.set noxpa}
1042 The directive @code{.set xpa} makes the assembler accept instructions
1043 from the XPA Extension from that point on in the assembly. The
1044 @code{.set noxpa} directive prevents XPA instructions from being accepted.
1045
1046 Traditional MIPS assemblers do not support these directives.
1047
1048 @node MIPS Floating-Point
1049 @section Directives to override floating-point options
1050
1051 @cindex Disable floating-point instructions
1052 @kindex @code{.set softfloat}
1053 @kindex @code{.set hardfloat}
1054 The directives @code{.set softfloat} and @code{.set hardfloat} provide
1055 finer control of disabling and enabling float-point instructions.
1056 These directives always override the default (that hard-float
1057 instructions are accepted) or the command-line options
1058 (@samp{-msoft-float} and @samp{-mhard-float}).
1059
1060 @cindex Disable single-precision floating-point operations
1061 @kindex @code{.set singlefloat}
1062 @kindex @code{.set doublefloat}
1063 The directives @code{.set singlefloat} and @code{.set doublefloat}
1064 provide finer control of disabling and enabling double-precision
1065 float-point operations. These directives always override the default
1066 (that double-precision operations are accepted) or the command-line
1067 options (@samp{-msingle-float} and @samp{-mdouble-float}).
1068
1069 Traditional MIPS assemblers do not support these directives.
1070
1071 @node MIPS Syntax
1072 @section Syntactical considerations for the MIPS assembler
1073 @menu
1074 * MIPS-Chars:: Special Characters
1075 @end menu
1076
1077 @node MIPS-Chars
1078 @subsection Special Characters
1079
1080 @cindex line comment character, MIPS
1081 @cindex MIPS line comment character
1082 The presence of a @samp{#} on a line indicates the start of a comment
1083 that extends to the end of the current line.
1084
1085 If a @samp{#} appears as the first character of a line, the whole line
1086 is treated as a comment, but in this case the line can also be a
1087 logical line number directive (@pxref{Comments}) or a
1088 preprocessor control command (@pxref{Preprocessing}).
1089
1090 @cindex line separator, MIPS
1091 @cindex statement separator, MIPS
1092 @cindex MIPS line separator
1093 The @samp{;} character can be used to separate statements on the same
1094 line.