2009-11-17 Sebastian Pop <sebastian.pop@amd.com>
[deliverable/binutils-gdb.git] / gas / doc / c-arm.texi
CommitLineData
aa820537
AM
1@c Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2@c 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
252b5132
RH
3@c This is part of the GAS manual.
4@c For copying conditions, see the file as.texinfo.
5
6@ifset GENERIC
7@page
8@node ARM-Dependent
9@chapter ARM Dependent Features
10@end ifset
11
12@ifclear GENERIC
13@node Machine Dependencies
14@chapter ARM Dependent Features
15@end ifclear
16
17@cindex ARM support
18@cindex Thumb support
19@menu
20* ARM Options:: Options
21* ARM Syntax:: Syntax
22* ARM Floating Point:: Floating Point
23* ARM Directives:: ARM Machine Directives
24* ARM Opcodes:: Opcodes
6057a28f 25* ARM Mapping Symbols:: Mapping Symbols
7da4f750 26* ARM Unwinding Tutorial:: Unwinding
252b5132
RH
27@end menu
28
29@node ARM Options
30@section Options
31@cindex ARM options (none)
32@cindex options for ARM (none)
adcf07e6 33
252b5132 34@table @code
adcf07e6 35
03b1477f 36@cindex @code{-mcpu=} command line option, ARM
92081f48 37@item -mcpu=@var{processor}[+@var{extension}@dots{}]
252b5132
RH
38This option specifies the target processor. The assembler will issue an
39error message if an attempt is made to assemble an instruction which
03b1477f
RE
40will not execute on the target processor. The following processor names are
41recognized:
42@code{arm1},
43@code{arm2},
44@code{arm250},
45@code{arm3},
46@code{arm6},
47@code{arm60},
48@code{arm600},
49@code{arm610},
50@code{arm620},
51@code{arm7},
52@code{arm7m},
53@code{arm7d},
54@code{arm7dm},
55@code{arm7di},
56@code{arm7dmi},
57@code{arm70},
58@code{arm700},
59@code{arm700i},
60@code{arm710},
61@code{arm710t},
62@code{arm720},
63@code{arm720t},
64@code{arm740t},
65@code{arm710c},
66@code{arm7100},
67@code{arm7500},
68@code{arm7500fe},
69@code{arm7t},
70@code{arm7tdmi},
1ff4677c 71@code{arm7tdmi-s},
03b1477f
RE
72@code{arm8},
73@code{arm810},
74@code{strongarm},
75@code{strongarm1},
76@code{strongarm110},
77@code{strongarm1100},
78@code{strongarm1110},
79@code{arm9},
80@code{arm920},
81@code{arm920t},
82@code{arm922t},
83@code{arm940t},
84@code{arm9tdmi},
7fac0536
NC
85@code{fa526} (Faraday FA526 processor),
86@code{fa626} (Faraday FA626 processor),
03b1477f 87@code{arm9e},
7de9afa2 88@code{arm926e},
1ff4677c 89@code{arm926ej-s},
03b1477f
RE
90@code{arm946e-r0},
91@code{arm946e},
db8ac8f9 92@code{arm946e-s},
03b1477f
RE
93@code{arm966e-r0},
94@code{arm966e},
db8ac8f9
PB
95@code{arm966e-s},
96@code{arm968e-s},
03b1477f 97@code{arm10t},
db8ac8f9 98@code{arm10tdmi},
03b1477f
RE
99@code{arm10e},
100@code{arm1020},
101@code{arm1020t},
7de9afa2 102@code{arm1020e},
db8ac8f9 103@code{arm1022e},
1ff4677c 104@code{arm1026ej-s},
7fac0536
NC
105@code{fa626te} (Faraday FA626TE processor),
106@code{fa726te} (Faraday FA726TE processor),
1ff4677c
RE
107@code{arm1136j-s},
108@code{arm1136jf-s},
db8ac8f9
PB
109@code{arm1156t2-s},
110@code{arm1156t2f-s},
0dd132b6
NC
111@code{arm1176jz-s},
112@code{arm1176jzf-s},
113@code{mpcore},
114@code{mpcorenovfp},
b38f9f31 115@code{cortex-a5},
62b3e311 116@code{cortex-a8},
15290f0a 117@code{cortex-a9},
62b3e311 118@code{cortex-r4},
307c948d 119@code{cortex-r4f},
62b3e311 120@code{cortex-m3},
5b19eaba
NC
121@code{cortex-m1},
122@code{cortex-m0},
03b1477f
RE
123@code{ep9312} (ARM920 with Cirrus Maverick coprocessor),
124@code{i80200} (Intel XScale processor)
e16bb312 125@code{iwmmxt} (Intel(r) XScale processor with Wireless MMX(tm) technology coprocessor)
03b1477f
RE
126and
127@code{xscale}.
128The special name @code{all} may be used to allow the
129assembler to accept instructions valid for any ARM processor.
130
131In addition to the basic instruction set, the assembler can be told to
132accept various extension mnemonics that extend the processor using the
133co-processor instruction space. For example, @code{-mcpu=arm920+maverick}
134is equivalent to specifying @code{-mcpu=ep9312}. The following extensions
135are currently supported:
136@code{+maverick}
e16bb312 137@code{+iwmmxt}
03b1477f
RE
138and
139@code{+xscale}.
140
141@cindex @code{-march=} command line option, ARM
92081f48 142@item -march=@var{architecture}[+@var{extension}@dots{}]
252b5132
RH
143This option specifies the target architecture. The assembler will issue
144an error message if an attempt is made to assemble an instruction which
03b1477f
RE
145will not execute on the target architecture. The following architecture
146names are recognized:
147@code{armv1},
148@code{armv2},
149@code{armv2a},
150@code{armv2s},
151@code{armv3},
152@code{armv3m},
153@code{armv4},
154@code{armv4xm},
155@code{armv4t},
156@code{armv4txm},
157@code{armv5},
158@code{armv5t},
159@code{armv5txm},
160@code{armv5te},
09d92015 161@code{armv5texp},
c5f98204 162@code{armv6},
1ddd7f43 163@code{armv6j},
0dd132b6
NC
164@code{armv6k},
165@code{armv6z},
166@code{armv6zk},
62b3e311 167@code{armv7},
c450d570
PB
168@code{armv7-a},
169@code{armv7-r},
170@code{armv7-m},
9e3c6df6 171@code{armv7e-m},
e16bb312 172@code{iwmmxt}
03b1477f
RE
173and
174@code{xscale}.
175If both @code{-mcpu} and
176@code{-march} are specified, the assembler will use
177the setting for @code{-mcpu}.
178
179The architecture option can be extended with the same instruction set
180extension options as the @code{-mcpu} option.
181
182@cindex @code{-mfpu=} command line option, ARM
183@item -mfpu=@var{floating-point-format}
184
185This option specifies the floating point format to assemble for. The
186assembler will issue an error message if an attempt is made to assemble
187an instruction which will not execute on the target floating point unit.
188The following format options are recognized:
189@code{softfpa},
190@code{fpe},
bc89618b
RE
191@code{fpe2},
192@code{fpe3},
03b1477f
RE
193@code{fpa},
194@code{fpa10},
195@code{fpa11},
196@code{arm7500fe},
197@code{softvfp},
198@code{softvfp+vfp},
199@code{vfp},
200@code{vfp10},
201@code{vfp10-r0},
202@code{vfp9},
203@code{vfpxd},
62f3b8c8
PB
204@code{vfpv2},
205@code{vfpv3},
206@code{vfpv3-fp16},
207@code{vfpv3-d16},
208@code{vfpv3-d16-fp16},
209@code{vfpv3xd},
210@code{vfpv3xd-d16},
211@code{vfpv4},
212@code{vfpv4-d16},
09d92015
MM
213@code{arm1020t},
214@code{arm1020e},
b1cc4aeb 215@code{arm1136jf-s},
62f3b8c8
PB
216@code{maverick},
217@code{neon},
03b1477f 218and
62f3b8c8 219@code{neon-vfpv4}.
03b1477f
RE
220
221In addition to determining which instructions are assembled, this option
222also affects the way in which the @code{.double} assembler directive behaves
223when assembling little-endian code.
224
225The default is dependent on the processor selected. For Architecture 5 or
226later, the default is to assembler for VFP instructions; for earlier
227architectures the default is to assemble for FPA instructions.
adcf07e6 228
252b5132
RH
229@cindex @code{-mthumb} command line option, ARM
230@item -mthumb
03b1477f
RE
231This option specifies that the assembler should start assembling Thumb
232instructions; that is, it should behave as though the file starts with a
233@code{.code 16} directive.
adcf07e6 234
252b5132
RH
235@cindex @code{-mthumb-interwork} command line option, ARM
236@item -mthumb-interwork
237This option specifies that the output generated by the assembler should
238be marked as supporting interworking.
adcf07e6 239
52970753
NC
240@cindex @code{-mimplicit-it} command line option, ARM
241@item -mimplicit-it=never
242@itemx -mimplicit-it=always
243@itemx -mimplicit-it=arm
244@itemx -mimplicit-it=thumb
245The @code{-mimplicit-it} option controls the behavior of the assembler when
246conditional instructions are not enclosed in IT blocks.
247There are four possible behaviors.
248If @code{never} is specified, such constructs cause a warning in ARM
249code and an error in Thumb-2 code.
250If @code{always} is specified, such constructs are accepted in both
251ARM and Thumb-2 code, where the IT instruction is added implicitly.
252If @code{arm} is specified, such constructs are accepted in ARM code
253and cause an error in Thumb-2 code.
254If @code{thumb} is specified, such constructs cause a warning in ARM
255code and are accepted in Thumb-2 code. If you omit this option, the
256behavior is equivalent to @code{-mimplicit-it=arm}.
e07e6e58 257
5a5829dd
NS
258@cindex @code{-mapcs-26} command line option, ARM
259@cindex @code{-mapcs-32} command line option, ARM
260@item -mapcs-26
261@itemx -mapcs-32
262These options specify that the output generated by the assembler should
252b5132
RH
263be marked as supporting the indicated version of the Arm Procedure.
264Calling Standard.
adcf07e6 265
077b8428
NC
266@cindex @code{-matpcs} command line option, ARM
267@item -matpcs
268This option specifies that the output generated by the assembler should
269be marked as supporting the Arm/Thumb Procedure Calling Standard. If
270enabled this option will cause the assembler to create an empty
271debugging section in the object file called .arm.atpcs. Debuggers can
272use this to determine the ABI being used by.
273
adcf07e6 274@cindex @code{-mapcs-float} command line option, ARM
252b5132 275@item -mapcs-float
1be59579 276This indicates the floating point variant of the APCS should be
252b5132 277used. In this variant floating point arguments are passed in FP
550262c4 278registers rather than integer registers.
adcf07e6
NC
279
280@cindex @code{-mapcs-reentrant} command line option, ARM
252b5132
RH
281@item -mapcs-reentrant
282This indicates that the reentrant variant of the APCS should be used.
283This variant supports position independent code.
adcf07e6 284
33a392fb
PB
285@cindex @code{-mfloat-abi=} command line option, ARM
286@item -mfloat-abi=@var{abi}
287This option specifies that the output generated by the assembler should be
288marked as using specified floating point ABI.
289The following values are recognized:
290@code{soft},
291@code{softfp}
292and
293@code{hard}.
294
d507cf36
PB
295@cindex @code{-eabi=} command line option, ARM
296@item -meabi=@var{ver}
297This option specifies which EABI version the produced object files should
298conform to.
b45619c0 299The following values are recognized:
3a4a14e9
PB
300@code{gnu},
301@code{4}
d507cf36 302and
3a4a14e9 303@code{5}.
d507cf36 304
252b5132
RH
305@cindex @code{-EB} command line option, ARM
306@item -EB
307This option specifies that the output generated by the assembler should
308be marked as being encoded for a big-endian processor.
adcf07e6 309
252b5132
RH
310@cindex @code{-EL} command line option, ARM
311@item -EL
312This option specifies that the output generated by the assembler should
313be marked as being encoded for a little-endian processor.
adcf07e6 314
252b5132
RH
315@cindex @code{-k} command line option, ARM
316@cindex PIC code generation for ARM
317@item -k
a349d9dd
PB
318This option specifies that the output of the assembler should be marked
319as position-independent code (PIC).
adcf07e6 320
845b51d6
PB
321@cindex @code{--fix-v4bx} command line option, ARM
322@item --fix-v4bx
323Allow @code{BX} instructions in ARMv4 code. This is intended for use with
324the linker option of the same name.
325
278df34e
NS
326@cindex @code{-mwarn-deprecated} command line option, ARM
327@item -mwarn-deprecated
328@itemx -mno-warn-deprecated
329Enable or disable warnings about using deprecated options or
330features. The default is to warn.
331
252b5132
RH
332@end table
333
334
335@node ARM Syntax
336@section Syntax
337@menu
cab7e4d9 338* ARM-Instruction-Set:: Instruction Set
252b5132
RH
339* ARM-Chars:: Special Characters
340* ARM-Regs:: Register Names
b6895b4f 341* ARM-Relocations:: Relocations
252b5132
RH
342@end menu
343
cab7e4d9
NC
344@node ARM-Instruction-Set
345@subsection Instruction Set Syntax
346Two slightly different syntaxes are support for ARM and THUMB
347instructions. The default, @code{divided}, uses the old style where
348ARM and THUMB instructions had their own, separate syntaxes. The new,
349@code{unified} syntax, which can be selected via the @code{.syntax}
350directive, and has the following main features:
351
352@table @bullet
353@item
354Immediate operands do not require a @code{#} prefix.
355
356@item
357The @code{IT} instruction may appear, and if it does it is validated
358against subsequent conditional affixes. In ARM mode it does not
359generate machine code, in THUMB mode it does.
360
361@item
362For ARM instructions the conditional affixes always appear at the end
363of the instruction. For THUMB instructions conditional affixes can be
364used, but only inside the scope of an @code{IT} instruction.
365
366@item
367All of the instructions new to the V6T2 architecture (and later) are
368available. (Only a few such instructions can be written in the
369@code{divided} syntax).
370
371@item
372The @code{.N} and @code{.W} suffixes are recognized and honored.
373
374@item
375All instructions set the flags if and only if they have an @code{s}
376affix.
377@end table
378
252b5132
RH
379@node ARM-Chars
380@subsection Special Characters
381
382@cindex line comment character, ARM
383@cindex ARM line comment character
550262c4
NC
384The presence of a @samp{@@} on a line indicates the start of a comment
385that extends to the end of the current line. If a @samp{#} appears as
386the first character of a line, the whole line is treated as a comment.
387
388@cindex line separator, ARM
389@cindex statement separator, ARM
390@cindex ARM line separator
a349d9dd
PB
391The @samp{;} character can be used instead of a newline to separate
392statements.
550262c4
NC
393
394@cindex immediate character, ARM
395@cindex ARM immediate character
396Either @samp{#} or @samp{$} can be used to indicate immediate operands.
252b5132
RH
397
398@cindex identifiers, ARM
399@cindex ARM identifiers
400*TODO* Explain about /data modifier on symbols.
401
402@node ARM-Regs
403@subsection Register Names
404
405@cindex ARM register names
406@cindex register names, ARM
407*TODO* Explain about ARM register naming, and the predefined names.
408
409@node ARM Floating Point
410@section Floating Point
411
412@cindex floating point, ARM (@sc{ieee})
413@cindex ARM floating point (@sc{ieee})
414The ARM family uses @sc{ieee} floating-point numbers.
415
b6895b4f
PB
416@node ARM-Relocations
417@subsection ARM relocation generation
418
419@cindex data relocations, ARM
420@cindex ARM data relocations
421Specific data relocations can be generated by putting the relocation name
422in parentheses after the symbol name. For example:
423
424@smallexample
425 .word foo(TARGET1)
426@end smallexample
427
428This will generate an @samp{R_ARM_TARGET1} relocation against the symbol
429@var{foo}.
430The following relocations are supported:
431@code{GOT},
432@code{GOTOFF},
433@code{TARGET1},
434@code{TARGET2},
435@code{SBREL},
436@code{TLSGD},
437@code{TLSLDM},
438@code{TLSLDO},
439@code{GOTTPOFF}
440and
441@code{TPOFF}.
442
443For compatibility with older toolchains the assembler also accepts
444@code{(PLT)} after branch targets. This will generate the deprecated
445@samp{R_ARM_PLT32} relocation.
446
447@cindex MOVW and MOVT relocations, ARM
448Relocations for @samp{MOVW} and @samp{MOVT} instructions can be generated
449by prefixing the value with @samp{#:lower16:} and @samp{#:upper16}
b45619c0 450respectively. For example to load the 32-bit address of foo into r0:
252b5132 451
b6895b4f
PB
452@smallexample
453 MOVW r0, #:lower16:foo
454 MOVT r0, #:upper16:foo
455@end smallexample
252b5132
RH
456
457@node ARM Directives
458@section ARM Machine Directives
459
460@cindex machine directives, ARM
461@cindex ARM machine directives
462@table @code
463
4a6bc624
NS
464@c AAAAAAAAAAAAAAAAAAAAAAAAA
465
466@cindex @code{.2byte} directive, ARM
467@cindex @code{.4byte} directive, ARM
468@cindex @code{.8byte} directive, ARM
469@item .2byte @var{expression} [, @var{expression}]*
470@itemx .4byte @var{expression} [, @var{expression}]*
471@itemx .8byte @var{expression} [, @var{expression}]*
472These directives write 2, 4 or 8 byte values to the output section.
473
474@cindex @code{.align} directive, ARM
adcf07e6
NC
475@item .align @var{expression} [, @var{expression}]
476This is the generic @var{.align} directive. For the ARM however if the
477first argument is zero (ie no alignment is needed) the assembler will
478behave as if the argument had been 2 (ie pad to the next four byte
062b7c0c 479boundary). This is for compatibility with ARM's own assembler.
adcf07e6 480
4a6bc624
NS
481@cindex @code{.arch} directive, ARM
482@item .arch @var{name}
483Select the target architecture. Valid values for @var{name} are the same as
484for the @option{-march} commandline option.
252b5132 485
4a6bc624
NS
486@cindex @code{.arm} directive, ARM
487@item .arm
488This performs the same action as @var{.code 32}.
252b5132 489
4a6bc624
NS
490@anchor{arm_pad}
491@cindex @code{.pad} directive, ARM
492@item .pad #@var{count}
493Generate unwinder annotations for a stack adjustment of @var{count} bytes.
494A positive value indicates the function prologue allocated stack space by
495decrementing the stack pointer.
0bbf2aa4 496
4a6bc624 497@c BBBBBBBBBBBBBBBBBBBBBBBBBB
0bbf2aa4 498
4a6bc624
NS
499@cindex @code{.bss} directive, ARM
500@item .bss
501This directive switches to the @code{.bss} section.
0bbf2aa4 502
4a6bc624
NS
503@c CCCCCCCCCCCCCCCCCCCCCCCCCC
504
505@cindex @code{.cantunwind} directive, ARM
506@item .cantunwind
507Prevents unwinding through the current function. No personality routine
508or exception table data is required or permitted.
509
510@cindex @code{.code} directive, ARM
511@item .code @code{[16|32]}
512This directive selects the instruction set being generated. The value 16
513selects Thumb, with the value 32 selecting ARM.
514
515@cindex @code{.cpu} directive, ARM
516@item .cpu @var{name}
517Select the target processor. Valid values for @var{name} are the same as
518for the @option{-mcpu} commandline option.
519
520@c DDDDDDDDDDDDDDDDDDDDDDDDDD
521
522@cindex @code{.dn} and @code{.qn} directives, ARM
f467aa98
BE
523@item @var{name} .dn @var{register name} [@var{.type}] [[@var{index}]]
524@item @var{name} .qn @var{register name} [@var{.type}] [[@var{index}]]
23753660
JB
525
526The @code{dn} and @code{qn} directives are used to create typed
527and/or indexed register aliases for use in Advanced SIMD Extension
528(Neon) instructions. The former should be used to create aliases
529of double-precision registers, and the latter to create aliases of
530quad-precision registers.
531
532If these directives are used to create typed aliases, those aliases can
533be used in Neon instructions instead of writing types after the mnemonic
534or after each operand. For example:
535
536@smallexample
537 x .dn d2.f32
538 y .dn d3.f32
539 z .dn d4.f32[1]
540 vmul x,y,z
541@end smallexample
542
543This is equivalent to writing the following:
544
545@smallexample
546 vmul.f32 d2,d3,d4[1]
547@end smallexample
548
549Aliases created using @code{dn} or @code{qn} can be destroyed using
550@code{unreq}.
551
4a6bc624 552@c EEEEEEEEEEEEEEEEEEEEEEEEEE
252b5132 553
4a6bc624
NS
554@cindex @code{.eabi_attribute} directive, ARM
555@item .eabi_attribute @var{tag}, @var{value}
556Set the EABI object attribute @var{tag} to @var{value}.
252b5132 557
4a6bc624
NS
558The @var{tag} is either an attribute number, or one of the following:
559@code{Tag_CPU_raw_name}, @code{Tag_CPU_name}, @code{Tag_CPU_arch},
560@code{Tag_CPU_arch_profile}, @code{Tag_ARM_ISA_use},
561@code{Tag_THUMB_ISA_use}, @code{Tag_VFP_arch}, @code{Tag_WMMX_arch},
562@code{Tag_Advanced_SIMD_arch}, @code{Tag_PCS_config},
563@code{Tag_ABI_PCS_R9_use}, @code{Tag_ABI_PCS_RW_data},
564@code{Tag_ABI_PCS_RO_data}, @code{Tag_ABI_PCS_GOT_use},
565@code{Tag_ABI_PCS_wchar_t}, @code{Tag_ABI_FP_rounding},
566@code{Tag_ABI_FP_denormal}, @code{Tag_ABI_FP_exceptions},
567@code{Tag_ABI_FP_user_exceptions}, @code{Tag_ABI_FP_number_model},
568@code{Tag_ABI_align8_needed}, @code{Tag_ABI_align8_preserved},
569@code{Tag_ABI_enum_size}, @code{Tag_ABI_HardFP_use},
570@code{Tag_ABI_VFP_args}, @code{Tag_ABI_WMMX_args},
571@code{Tag_ABI_optimization_goals}, @code{Tag_ABI_FP_optimization_goals},
572@code{Tag_compatibility}, @code{Tag_CPU_unaligned_access},
573@code{Tag_VFP_HP_extension}, @code{Tag_ABI_FP_16bit_format},
574@code{Tag_nodefaults}, @code{Tag_also_compatible_with},
575@code{Tag_conformance}, @code{Tag_T2EE_use},
576@code{Tag_Virtualization_use}, @code{Tag_MPextension_use}
577
578The @var{value} is either a @code{number}, @code{"string"}, or
579@code{number, "string"} depending on the tag.
580
581@cindex @code{.even} directive, ARM
582@item .even
583This directive aligns to an even-numbered address.
584
585@cindex @code{.extend} directive, ARM
586@cindex @code{.ldouble} directive, ARM
587@item .extend @var{expression} [, @var{expression}]*
588@itemx .ldouble @var{expression} [, @var{expression}]*
589These directives write 12byte long double floating-point values to the
590output section. These are not compatible with current ARM processors
591or ABIs.
592
593@c FFFFFFFFFFFFFFFFFFFFFFFFFF
594
595@anchor{arm_fnend}
596@cindex @code{.fnend} directive, ARM
597@item .fnend
598Marks the end of a function with an unwind table entry. The unwind index
599table entry is created when this directive is processed.
252b5132 600
4a6bc624
NS
601If no personality routine has been specified then standard personality
602routine 0 or 1 will be used, depending on the number of unwind opcodes
603required.
604
605@anchor{arm_fnstart}
606@cindex @code{.fnstart} directive, ARM
607@item .fnstart
608Marks the start of a function with an unwind table entry.
609
610@cindex @code{.force_thumb} directive, ARM
252b5132
RH
611@item .force_thumb
612This directive forces the selection of Thumb instructions, even if the
613target processor does not support those instructions
614
4a6bc624
NS
615@cindex @code{.fpu} directive, ARM
616@item .fpu @var{name}
617Select the floating-point unit to assemble for. Valid values for @var{name}
618are the same as for the @option{-mfpu} commandline option.
252b5132 619
4a6bc624
NS
620@c GGGGGGGGGGGGGGGGGGGGGGGGGG
621@c HHHHHHHHHHHHHHHHHHHHHHHHHH
e1da3f5b 622
4a6bc624
NS
623@cindex @code{.handlerdata} directive, ARM
624@item .handlerdata
625Marks the end of the current function, and the start of the exception table
626entry for that function. Anything between this directive and the
627@code{.fnend} directive will be added to the exception table entry.
628
629Must be preceded by a @code{.personality} or @code{.personalityindex}
630directive.
631
632@c IIIIIIIIIIIIIIIIIIIIIIIIII
c921be7d
NC
633
634@cindex @code{.inst} directive, ARM
635@item .inst @var{opcode} [ , @dots{} ]
636@item .inst.n @var{opcode} [ , @dots{} ]
637@item .inst.w @var{opcode} [ , @dots{} ]
638Generates the instruction corresponding to the numerical value @var{opcode}.
639@code{.inst.n} and @code{.inst.w} allow the Thumb instruction size to be
640specified explicitly, overriding the normal encoding rules.
641
4a6bc624
NS
642@c JJJJJJJJJJJJJJJJJJJJJJJJJJ
643@c KKKKKKKKKKKKKKKKKKKKKKKKKK
644@c LLLLLLLLLLLLLLLLLLLLLLLLLL
645
646@item .ldouble @var{expression} [, @var{expression}]*
647See @code{.extend}.
5395a469 648
252b5132
RH
649@cindex @code{.ltorg} directive, ARM
650@item .ltorg
651This directive causes the current contents of the literal pool to be
652dumped into the current section (which is assumed to be the .text
653section) at the current location (aligned to a word boundary).
3d0c9500
NC
654@code{GAS} maintains a separate literal pool for each section and each
655sub-section. The @code{.ltorg} directive will only affect the literal
656pool of the current section and sub-section. At the end of assembly
657all remaining, un-empty literal pools will automatically be dumped.
658
659Note - older versions of @code{GAS} would dump the current literal
660pool any time a section change occurred. This is no longer done, since
661it prevents accurate control of the placement of literal pools.
252b5132 662
4a6bc624 663@c MMMMMMMMMMMMMMMMMMMMMMMMMM
252b5132 664
4a6bc624
NS
665@cindex @code{.movsp} directive, ARM
666@item .movsp @var{reg} [, #@var{offset}]
667Tell the unwinder that @var{reg} contains an offset from the current
668stack pointer. If @var{offset} is not specified then it is assumed to be
669zero.
7ed4c4c5 670
4a6bc624
NS
671@c NNNNNNNNNNNNNNNNNNNNNNNNNN
672@c OOOOOOOOOOOOOOOOOOOOOOOOOO
7ed4c4c5 673
4a6bc624
NS
674@cindex @code{.object_arch} directive, ARM
675@item .object_arch @var{name}
676Override the architecture recorded in the EABI object attribute section.
677Valid values for @var{name} are the same as for the @code{.arch} directive.
678Typically this is useful when code uses runtime detection of CPU features.
7ed4c4c5 679
4a6bc624
NS
680@c PPPPPPPPPPPPPPPPPPPPPPPPPP
681
682@cindex @code{.packed} directive, ARM
683@item .packed @var{expression} [, @var{expression}]*
684This directive writes 12-byte packed floating-point values to the
685output section. These are not compatible with current ARM processors
686or ABIs.
687
688@cindex @code{.pad} directive, ARM
689@item .pad #@var{count}
690Generate unwinder annotations for a stack adjustment of @var{count} bytes.
691A positive value indicates the function prologue allocated stack space by
692decrementing the stack pointer.
7ed4c4c5
NC
693
694@cindex @code{.personality} directive, ARM
695@item .personality @var{name}
696Sets the personality routine for the current function to @var{name}.
697
698@cindex @code{.personalityindex} directive, ARM
699@item .personalityindex @var{index}
700Sets the personality routine for the current function to the EABI standard
701routine number @var{index}
702
4a6bc624
NS
703@cindex @code{.pool} directive, ARM
704@item .pool
705This is a synonym for .ltorg.
7ed4c4c5 706
4a6bc624
NS
707@c QQQQQQQQQQQQQQQQQQQQQQQQQQ
708@c RRRRRRRRRRRRRRRRRRRRRRRRRR
709
710@cindex @code{.req} directive, ARM
711@item @var{name} .req @var{register name}
712This creates an alias for @var{register name} called @var{name}. For
713example:
714
715@smallexample
716 foo .req r0
717@end smallexample
718
719@c SSSSSSSSSSSSSSSSSSSSSSSSSS
7ed4c4c5 720
7da4f750 721@anchor{arm_save}
7ed4c4c5
NC
722@cindex @code{.save} directive, ARM
723@item .save @var{reglist}
724Generate unwinder annotations to restore the registers in @var{reglist}.
725The format of @var{reglist} is the same as the corresponding store-multiple
726instruction.
727
728@smallexample
729@exdent @emph{core registers}
730 .save @{r4, r5, r6, lr@}
731 stmfd sp!, @{r4, r5, r6, lr@}
732@exdent @emph{FPA registers}
733 .save f4, 2
734 sfmfd f4, 2, [sp]!
735@exdent @emph{VFP registers}
736 .save @{d8, d9, d10@}
fa073d69 737 fstmdx sp!, @{d8, d9, d10@}
7ed4c4c5
NC
738@exdent @emph{iWMMXt registers}
739 .save @{wr10, wr11@}
740 wstrd wr11, [sp, #-8]!
741 wstrd wr10, [sp, #-8]!
742or
743 .save wr11
744 wstrd wr11, [sp, #-8]!
745 .save wr10
746 wstrd wr10, [sp, #-8]!
747@end smallexample
748
7da4f750 749@anchor{arm_setfp}
7ed4c4c5
NC
750@cindex @code{.setfp} directive, ARM
751@item .setfp @var{fpreg}, @var{spreg} [, #@var{offset}]
4a6bc624 752Make all unwinder annotations relative to a frame pointer. Without this
7ed4c4c5
NC
753the unwinder will use offsets from the stack pointer.
754
755The syntax of this directive is the same as the @code{sub} or @code{mov}
756instruction used to set the frame pointer. @var{spreg} must be either
757@code{sp} or mentioned in a previous @code{.movsp} directive.
758
759@smallexample
760.movsp ip
761mov ip, sp
762@dots{}
763.setfp fp, ip, #4
764sub fp, ip, #4
765@end smallexample
766
4a6bc624
NS
767@cindex @code{.secrel32} directive, ARM
768@item .secrel32 @var{expression} [, @var{expression}]*
769This directive emits relocations that evaluate to the section-relative
770offset of each expression's symbol. This directive is only supported
771for PE targets.
772
cab7e4d9
NC
773@cindex @code{.syntax} directive, ARM
774@item .syntax [@code{unified} | @code{divided}]
775This directive sets the Instruction Set Syntax as described in the
776@ref{ARM-Instruction-Set} section.
777
4a6bc624
NS
778@c TTTTTTTTTTTTTTTTTTTTTTTTTT
779
780@cindex @code{.thumb} directive, ARM
781@item .thumb
782This performs the same action as @var{.code 16}.
783
784@cindex @code{.thumb_func} directive, ARM
785@item .thumb_func
786This directive specifies that the following symbol is the name of a
787Thumb encoded function. This information is necessary in order to allow
788the assembler and linker to generate correct code for interworking
789between Arm and Thumb instructions and should be used even if
790interworking is not going to be performed. The presence of this
791directive also implies @code{.thumb}
792
793This directive is not neccessary when generating EABI objects. On these
794targets the encoding is implicit when generating Thumb code.
795
796@cindex @code{.thumb_set} directive, ARM
797@item .thumb_set
798This performs the equivalent of a @code{.set} directive in that it
799creates a symbol which is an alias for another symbol (possibly not yet
800defined). This directive also has the added property in that it marks
801the aliased symbol as being a thumb function entry point, in the same
802way that the @code{.thumb_func} directive does.
803
804@c UUUUUUUUUUUUUUUUUUUUUUUUUU
805
806@cindex @code{.unreq} directive, ARM
807@item .unreq @var{alias-name}
808This undefines a register alias which was previously defined using the
809@code{req}, @code{dn} or @code{qn} directives. For example:
810
811@smallexample
812 foo .req r0
813 .unreq foo
814@end smallexample
815
816An error occurs if the name is undefined. Note - this pseudo op can
817be used to delete builtin in register name aliases (eg 'r0'). This
818should only be done if it is really necessary.
819
7ed4c4c5 820@cindex @code{.unwind_raw} directive, ARM
4a6bc624 821@item .unwind_raw @var{offset}, @var{byte1}, @dots{}
7ed4c4c5
NC
822Insert one of more arbitary unwind opcode bytes, which are known to adjust
823the stack pointer by @var{offset} bytes.
824
825For example @code{.unwind_raw 4, 0xb1, 0x01} is equivalent to
826@code{.save @{r0@}}
827
4a6bc624 828@c VVVVVVVVVVVVVVVVVVVVVVVVVV
ee065d83 829
4a6bc624
NS
830@cindex @code{.vsave} directive, ARM
831@item .vsave @var{vfp-reglist}
832Generate unwinder annotations to restore the VFP registers in @var{vfp-reglist}
833using FLDMD. Also works for VFPv3 registers
834that are to be restored using VLDM.
835The format of @var{vfp-reglist} is the same as the corresponding store-multiple
836instruction.
ee065d83 837
4a6bc624
NS
838@smallexample
839@exdent @emph{VFP registers}
840 .vsave @{d8, d9, d10@}
841 fstmdd sp!, @{d8, d9, d10@}
842@exdent @emph{VFPv3 registers}
843 .vsave @{d15, d16, d17@}
844 vstm sp!, @{d15, d16, d17@}
845@end smallexample
e04befd0 846
4a6bc624
NS
847Since FLDMX and FSTMX are now deprecated, this directive should be
848used in favour of @code{.save} for saving VFP registers for ARMv6 and above.
e04befd0 849
4a6bc624
NS
850@c WWWWWWWWWWWWWWWWWWWWWWWWWW
851@c XXXXXXXXXXXXXXXXXXXXXXXXXX
852@c YYYYYYYYYYYYYYYYYYYYYYYYYY
853@c ZZZZZZZZZZZZZZZZZZZZZZZZZZ
ee065d83 854
252b5132
RH
855@end table
856
857@node ARM Opcodes
858@section Opcodes
859
860@cindex ARM opcodes
861@cindex opcodes for ARM
49a5575c
NC
862@code{@value{AS}} implements all the standard ARM opcodes. It also
863implements several pseudo opcodes, including several synthetic load
864instructions.
252b5132 865
49a5575c
NC
866@table @code
867
868@cindex @code{NOP} pseudo op, ARM
869@item NOP
870@smallexample
871 nop
872@end smallexample
252b5132 873
49a5575c
NC
874This pseudo op will always evaluate to a legal ARM instruction that does
875nothing. Currently it will evaluate to MOV r0, r0.
252b5132 876
49a5575c
NC
877@cindex @code{LDR reg,=<label>} pseudo op, ARM
878@item LDR
252b5132
RH
879@smallexample
880 ldr <register> , = <expression>
881@end smallexample
882
883If expression evaluates to a numeric constant then a MOV or MVN
884instruction will be used in place of the LDR instruction, if the
885constant can be generated by either of these instructions. Otherwise
886the constant will be placed into the nearest literal pool (if it not
887already there) and a PC relative LDR instruction will be generated.
888
49a5575c
NC
889@cindex @code{ADR reg,<label>} pseudo op, ARM
890@item ADR
891@smallexample
892 adr <register> <label>
893@end smallexample
894
895This instruction will load the address of @var{label} into the indicated
896register. The instruction will evaluate to a PC relative ADD or SUB
897instruction depending upon where the label is located. If the label is
898out of range, or if it is not defined in the same file (and section) as
899the ADR instruction, then an error will be generated. This instruction
900will not make use of the literal pool.
901
902@cindex @code{ADRL reg,<label>} pseudo op, ARM
903@item ADRL
904@smallexample
905 adrl <register> <label>
906@end smallexample
907
908This instruction will load the address of @var{label} into the indicated
a349d9dd 909register. The instruction will evaluate to one or two PC relative ADD
49a5575c
NC
910or SUB instructions depending upon where the label is located. If a
911second instruction is not needed a NOP instruction will be generated in
912its place, so that this instruction is always 8 bytes long.
913
914If the label is out of range, or if it is not defined in the same file
915(and section) as the ADRL instruction, then an error will be generated.
916This instruction will not make use of the literal pool.
917
918@end table
919
252b5132
RH
920For information on the ARM or Thumb instruction sets, see @cite{ARM
921Software Development Toolkit Reference Manual}, Advanced RISC Machines
922Ltd.
923
6057a28f
NC
924@node ARM Mapping Symbols
925@section Mapping Symbols
926
927The ARM ELF specification requires that special symbols be inserted
928into object files to mark certain features:
929
930@table @code
931
932@cindex @code{$a}
933@item $a
934At the start of a region of code containing ARM instructions.
935
936@cindex @code{$t}
937@item $t
938At the start of a region of code containing THUMB instructions.
939
940@cindex @code{$d}
941@item $d
942At the start of a region of data.
943
944@end table
945
946The assembler will automatically insert these symbols for you - there
947is no need to code them yourself. Support for tagging symbols ($b,
948$f, $p and $m) which is also mentioned in the current ARM ELF
949specification is not implemented. This is because they have been
950dropped from the new EABI and so tools cannot rely upon their
951presence.
952
7da4f750
MM
953@node ARM Unwinding Tutorial
954@section Unwinding
955
956The ABI for the ARM Architecture specifies a standard format for
957exception unwind information. This information is used when an
958exception is thrown to determine where control should be transferred.
959In particular, the unwind information is used to determine which
960function called the function that threw the exception, and which
961function called that one, and so forth. This information is also used
962to restore the values of callee-saved registers in the function
963catching the exception.
964
965If you are writing functions in assembly code, and those functions
966call other functions that throw exceptions, you must use assembly
967pseudo ops to ensure that appropriate exception unwind information is
968generated. Otherwise, if one of the functions called by your assembly
969code throws an exception, the run-time library will be unable to
970unwind the stack through your assembly code and your program will not
971behave correctly.
972
973To illustrate the use of these pseudo ops, we will examine the code
974that G++ generates for the following C++ input:
975
976@verbatim
977void callee (int *);
978
979int
980caller ()
981{
982 int i;
983 callee (&i);
984 return i;
985}
986@end verbatim
987
988This example does not show how to throw or catch an exception from
989assembly code. That is a much more complex operation and should
990always be done in a high-level language, such as C++, that directly
991supports exceptions.
992
993The code generated by one particular version of G++ when compiling the
994example above is:
995
996@verbatim
997_Z6callerv:
998 .fnstart
999.LFB2:
1000 @ Function supports interworking.
1001 @ args = 0, pretend = 0, frame = 8
1002 @ frame_needed = 1, uses_anonymous_args = 0
1003 stmfd sp!, {fp, lr}
1004 .save {fp, lr}
1005.LCFI0:
1006 .setfp fp, sp, #4
1007 add fp, sp, #4
1008.LCFI1:
1009 .pad #8
1010 sub sp, sp, #8
1011.LCFI2:
1012 sub r3, fp, #8
1013 mov r0, r3
1014 bl _Z6calleePi
1015 ldr r3, [fp, #-8]
1016 mov r0, r3
1017 sub sp, fp, #4
1018 ldmfd sp!, {fp, lr}
1019 bx lr
1020.LFE2:
1021 .fnend
1022@end verbatim
1023
1024Of course, the sequence of instructions varies based on the options
1025you pass to GCC and on the version of GCC in use. The exact
1026instructions are not important since we are focusing on the pseudo ops
1027that are used to generate unwind information.
1028
1029An important assumption made by the unwinder is that the stack frame
1030does not change during the body of the function. In particular, since
1031we assume that the assembly code does not itself throw an exception,
1032the only point where an exception can be thrown is from a call, such
1033as the @code{bl} instruction above. At each call site, the same saved
1034registers (including @code{lr}, which indicates the return address)
1035must be located in the same locations relative to the frame pointer.
1036
1037The @code{.fnstart} (@pxref{arm_fnstart,,.fnstart pseudo op}) pseudo
1038op appears immediately before the first instruction of the function
1039while the @code{.fnend} (@pxref{arm_fnend,,.fnend pseudo op}) pseudo
1040op appears immediately after the last instruction of the function.
1041These pseudo ops specify the range of the function.
1042
1043Only the order of the other pseudos ops (e.g., @code{.setfp} or
1044@code{.pad}) matters; their exact locations are irrelevant. In the
1045example above, the compiler emits the pseudo ops with particular
1046instructions. That makes it easier to understand the code, but it is
1047not required for correctness. It would work just as well to emit all
1048of the pseudo ops other than @code{.fnend} in the same order, but
1049immediately after @code{.fnstart}.
1050
1051The @code{.save} (@pxref{arm_save,,.save pseudo op}) pseudo op
1052indicates registers that have been saved to the stack so that they can
1053be restored before the function returns. The argument to the
1054@code{.save} pseudo op is a list of registers to save. If a register
1055is ``callee-saved'' (as specified by the ABI) and is modified by the
1056function you are writing, then your code must save the value before it
1057is modified and restore the original value before the function
1058returns. If an exception is thrown, the run-time library restores the
1059values of these registers from their locations on the stack before
1060returning control to the exception handler. (Of course, if an
1061exception is not thrown, the function that contains the @code{.save}
1062pseudo op restores these registers in the function epilogue, as is
1063done with the @code{ldmfd} instruction above.)
1064
1065You do not have to save callee-saved registers at the very beginning
1066of the function and you do not need to use the @code{.save} pseudo op
1067immediately following the point at which the registers are saved.
1068However, if you modify a callee-saved register, you must save it on
1069the stack before modifying it and before calling any functions which
1070might throw an exception. And, you must use the @code{.save} pseudo
1071op to indicate that you have done so.
1072
1073The @code{.pad} (@pxref{arm_pad,,.pad}) pseudo op indicates a
1074modification of the stack pointer that does not save any registers.
1075The argument is the number of bytes (in decimal) that are subtracted
1076from the stack pointer. (On ARM CPUs, the stack grows downwards, so
1077subtracting from the stack pointer increases the size of the stack.)
1078
1079The @code{.setfp} (@pxref{arm_setfp,,.setfp pseudo op}) pseudo op
1080indicates the register that contains the frame pointer. The first
1081argument is the register that is set, which is typically @code{fp}.
1082The second argument indicates the register from which the frame
1083pointer takes its value. The third argument, if present, is the value
1084(in decimal) added to the register specified by the second argument to
1085compute the value of the frame pointer. You should not modify the
1086frame pointer in the body of the function.
1087
1088If you do not use a frame pointer, then you should not use the
1089@code{.setfp} pseudo op. If you do not use a frame pointer, then you
1090should avoid modifying the stack pointer outside of the function
1091prologue. Otherwise, the run-time library will be unable to find
1092saved registers when it is unwinding the stack.
1093
1094The pseudo ops described above are sufficient for writing assembly
1095code that calls functions which may throw exceptions. If you need to
1096know more about the object-file format used to represent unwind
1097information, you may consult the @cite{Exception Handling ABI for the
1098ARM Architecture} available from @uref{http://infocenter.arm.com}.
This page took 0.46259 seconds and 4 git commands to generate.