2009-01-16 Andrew Stubbs <ams@codesourcery.com>
[deliverable/binutils-gdb.git] / gas / doc / c-arm.texi
1 @c Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2008
2 @c Free Software Foundation, Inc.
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
25 * ARM Mapping Symbols:: Mapping Symbols
26 * ARM Unwinding Tutorial:: Unwinding
27 @end menu
28
29 @node ARM Options
30 @section Options
31 @cindex ARM options (none)
32 @cindex options for ARM (none)
33
34 @table @code
35
36 @cindex @code{-mcpu=} command line option, ARM
37 @item -mcpu=@var{processor}[+@var{extension}@dots{}]
38 This option specifies the target processor. The assembler will issue an
39 error message if an attempt is made to assemble an instruction which
40 will not execute on the target processor. The following processor names are
41 recognized:
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},
71 @code{arm7tdmi-s},
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},
85 @code{fa526} (Faraday FA526 processor),
86 @code{fa626} (Faraday FA626 processor),
87 @code{arm9e},
88 @code{arm926e},
89 @code{arm926ej-s},
90 @code{arm946e-r0},
91 @code{arm946e},
92 @code{arm946e-s},
93 @code{arm966e-r0},
94 @code{arm966e},
95 @code{arm966e-s},
96 @code{arm968e-s},
97 @code{arm10t},
98 @code{arm10tdmi},
99 @code{arm10e},
100 @code{arm1020},
101 @code{arm1020t},
102 @code{arm1020e},
103 @code{arm1022e},
104 @code{arm1026ej-s},
105 @code{fa626te} (Faraday FA626TE processor),
106 @code{fa726te} (Faraday FA726TE processor),
107 @code{arm1136j-s},
108 @code{arm1136jf-s},
109 @code{arm1156t2-s},
110 @code{arm1156t2f-s},
111 @code{arm1176jz-s},
112 @code{arm1176jzf-s},
113 @code{mpcore},
114 @code{mpcorenovfp},
115 @code{cortex-a8},
116 @code{cortex-a9},
117 @code{cortex-r4},
118 @code{cortex-m3},
119 @code{ep9312} (ARM920 with Cirrus Maverick coprocessor),
120 @code{i80200} (Intel XScale processor)
121 @code{iwmmxt} (Intel(r) XScale processor with Wireless MMX(tm) technology coprocessor)
122 and
123 @code{xscale}.
124 The special name @code{all} may be used to allow the
125 assembler to accept instructions valid for any ARM processor.
126
127 In addition to the basic instruction set, the assembler can be told to
128 accept various extension mnemonics that extend the processor using the
129 co-processor instruction space. For example, @code{-mcpu=arm920+maverick}
130 is equivalent to specifying @code{-mcpu=ep9312}. The following extensions
131 are currently supported:
132 @code{+maverick}
133 @code{+iwmmxt}
134 and
135 @code{+xscale}.
136
137 @cindex @code{-march=} command line option, ARM
138 @item -march=@var{architecture}[+@var{extension}@dots{}]
139 This option specifies the target architecture. The assembler will issue
140 an error message if an attempt is made to assemble an instruction which
141 will not execute on the target architecture. The following architecture
142 names are recognized:
143 @code{armv1},
144 @code{armv2},
145 @code{armv2a},
146 @code{armv2s},
147 @code{armv3},
148 @code{armv3m},
149 @code{armv4},
150 @code{armv4xm},
151 @code{armv4t},
152 @code{armv4txm},
153 @code{armv5},
154 @code{armv5t},
155 @code{armv5txm},
156 @code{armv5te},
157 @code{armv5texp},
158 @code{armv6},
159 @code{armv6j},
160 @code{armv6k},
161 @code{armv6z},
162 @code{armv6zk},
163 @code{armv7},
164 @code{armv7-a},
165 @code{armv7-r},
166 @code{armv7-m},
167 @code{iwmmxt}
168 and
169 @code{xscale}.
170 If both @code{-mcpu} and
171 @code{-march} are specified, the assembler will use
172 the setting for @code{-mcpu}.
173
174 The architecture option can be extended with the same instruction set
175 extension options as the @code{-mcpu} option.
176
177 @cindex @code{-mfpu=} command line option, ARM
178 @item -mfpu=@var{floating-point-format}
179
180 This option specifies the floating point format to assemble for. The
181 assembler will issue an error message if an attempt is made to assemble
182 an instruction which will not execute on the target floating point unit.
183 The following format options are recognized:
184 @code{softfpa},
185 @code{fpe},
186 @code{fpe2},
187 @code{fpe3},
188 @code{fpa},
189 @code{fpa10},
190 @code{fpa11},
191 @code{arm7500fe},
192 @code{softvfp},
193 @code{softvfp+vfp},
194 @code{vfp},
195 @code{vfp10},
196 @code{vfp10-r0},
197 @code{vfp9},
198 @code{vfpxd},
199 @code{vfpv2}
200 @code{vfpv3}
201 @code{vfpv3-d16}
202 @code{arm1020t},
203 @code{arm1020e},
204 @code{arm1136jf-s},
205 @code{maverick}
206 and
207 @code{neon}.
208
209 In addition to determining which instructions are assembled, this option
210 also affects the way in which the @code{.double} assembler directive behaves
211 when assembling little-endian code.
212
213 The default is dependent on the processor selected. For Architecture 5 or
214 later, the default is to assembler for VFP instructions; for earlier
215 architectures the default is to assemble for FPA instructions.
216
217 @cindex @code{-mthumb} command line option, ARM
218 @item -mthumb
219 This option specifies that the assembler should start assembling Thumb
220 instructions; that is, it should behave as though the file starts with a
221 @code{.code 16} directive.
222
223 @cindex @code{-mthumb-interwork} command line option, ARM
224 @item -mthumb-interwork
225 This option specifies that the output generated by the assembler should
226 be marked as supporting interworking.
227
228 @cindex @code{-mapcs} command line option, ARM
229 @item -mapcs @code{[26|32]}
230 This option specifies that the output generated by the assembler should
231 be marked as supporting the indicated version of the Arm Procedure.
232 Calling Standard.
233
234 @cindex @code{-matpcs} command line option, ARM
235 @item -matpcs
236 This option specifies that the output generated by the assembler should
237 be marked as supporting the Arm/Thumb Procedure Calling Standard. If
238 enabled this option will cause the assembler to create an empty
239 debugging section in the object file called .arm.atpcs. Debuggers can
240 use this to determine the ABI being used by.
241
242 @cindex @code{-mapcs-float} command line option, ARM
243 @item -mapcs-float
244 This indicates the floating point variant of the APCS should be
245 used. In this variant floating point arguments are passed in FP
246 registers rather than integer registers.
247
248 @cindex @code{-mapcs-reentrant} command line option, ARM
249 @item -mapcs-reentrant
250 This indicates that the reentrant variant of the APCS should be used.
251 This variant supports position independent code.
252
253 @cindex @code{-mfloat-abi=} command line option, ARM
254 @item -mfloat-abi=@var{abi}
255 This option specifies that the output generated by the assembler should be
256 marked as using specified floating point ABI.
257 The following values are recognized:
258 @code{soft},
259 @code{softfp}
260 and
261 @code{hard}.
262
263 @cindex @code{-eabi=} command line option, ARM
264 @item -meabi=@var{ver}
265 This option specifies which EABI version the produced object files should
266 conform to.
267 The following values are recognized:
268 @code{gnu},
269 @code{4}
270 and
271 @code{5}.
272
273 @cindex @code{-EB} command line option, ARM
274 @item -EB
275 This option specifies that the output generated by the assembler should
276 be marked as being encoded for a big-endian processor.
277
278 @cindex @code{-EL} command line option, ARM
279 @item -EL
280 This option specifies that the output generated by the assembler should
281 be marked as being encoded for a little-endian processor.
282
283 @cindex @code{-k} command line option, ARM
284 @cindex PIC code generation for ARM
285 @item -k
286 This option specifies that the output of the assembler should be marked
287 as position-independent code (PIC).
288
289 @cindex @code{--fix-v4bx} command line option, ARM
290 @item --fix-v4bx
291 Allow @code{BX} instructions in ARMv4 code. This is intended for use with
292 the linker option of the same name.
293
294 @end table
295
296
297 @node ARM Syntax
298 @section Syntax
299 @menu
300 * ARM-Chars:: Special Characters
301 * ARM-Regs:: Register Names
302 * ARM-Relocations:: Relocations
303 @end menu
304
305 @node ARM-Chars
306 @subsection Special Characters
307
308 @cindex line comment character, ARM
309 @cindex ARM line comment character
310 The presence of a @samp{@@} on a line indicates the start of a comment
311 that extends to the end of the current line. If a @samp{#} appears as
312 the first character of a line, the whole line is treated as a comment.
313
314 @cindex line separator, ARM
315 @cindex statement separator, ARM
316 @cindex ARM line separator
317 The @samp{;} character can be used instead of a newline to separate
318 statements.
319
320 @cindex immediate character, ARM
321 @cindex ARM immediate character
322 Either @samp{#} or @samp{$} can be used to indicate immediate operands.
323
324 @cindex identifiers, ARM
325 @cindex ARM identifiers
326 *TODO* Explain about /data modifier on symbols.
327
328 @node ARM-Regs
329 @subsection Register Names
330
331 @cindex ARM register names
332 @cindex register names, ARM
333 *TODO* Explain about ARM register naming, and the predefined names.
334
335 @node ARM Floating Point
336 @section Floating Point
337
338 @cindex floating point, ARM (@sc{ieee})
339 @cindex ARM floating point (@sc{ieee})
340 The ARM family uses @sc{ieee} floating-point numbers.
341
342 @node ARM-Relocations
343 @subsection ARM relocation generation
344
345 @cindex data relocations, ARM
346 @cindex ARM data relocations
347 Specific data relocations can be generated by putting the relocation name
348 in parentheses after the symbol name. For example:
349
350 @smallexample
351 .word foo(TARGET1)
352 @end smallexample
353
354 This will generate an @samp{R_ARM_TARGET1} relocation against the symbol
355 @var{foo}.
356 The following relocations are supported:
357 @code{GOT},
358 @code{GOTOFF},
359 @code{TARGET1},
360 @code{TARGET2},
361 @code{SBREL},
362 @code{TLSGD},
363 @code{TLSLDM},
364 @code{TLSLDO},
365 @code{GOTTPOFF}
366 and
367 @code{TPOFF}.
368
369 For compatibility with older toolchains the assembler also accepts
370 @code{(PLT)} after branch targets. This will generate the deprecated
371 @samp{R_ARM_PLT32} relocation.
372
373 @cindex MOVW and MOVT relocations, ARM
374 Relocations for @samp{MOVW} and @samp{MOVT} instructions can be generated
375 by prefixing the value with @samp{#:lower16:} and @samp{#:upper16}
376 respectively. For example to load the 32-bit address of foo into r0:
377
378 @smallexample
379 MOVW r0, #:lower16:foo
380 MOVT r0, #:upper16:foo
381 @end smallexample
382
383 @node ARM Directives
384 @section ARM Machine Directives
385
386 @cindex machine directives, ARM
387 @cindex ARM machine directives
388 @table @code
389
390 @cindex @code{align} directive, ARM
391 @item .align @var{expression} [, @var{expression}]
392 This is the generic @var{.align} directive. For the ARM however if the
393 first argument is zero (ie no alignment is needed) the assembler will
394 behave as if the argument had been 2 (ie pad to the next four byte
395 boundary). This is for compatibility with ARM's own assembler.
396
397 @cindex @code{req} directive, ARM
398 @item @var{name} .req @var{register name}
399 This creates an alias for @var{register name} called @var{name}. For
400 example:
401
402 @smallexample
403 foo .req r0
404 @end smallexample
405
406 @cindex @code{unreq} directive, ARM
407 @item .unreq @var{alias-name}
408 This undefines a register alias which was previously defined using the
409 @code{req}, @code{dn} or @code{qn} directives. For example:
410
411 @smallexample
412 foo .req r0
413 .unreq foo
414 @end smallexample
415
416 An error occurs if the name is undefined. Note - this pseudo op can
417 be used to delete builtin in register name aliases (eg 'r0'). This
418 should only be done if it is really necessary.
419
420 @cindex @code{dn} and @code{qn} directives, ARM
421 @item @var{name} .dn @var{register name} [@var{.type}] [[@var{index}]]
422 @item @var{name} .qn @var{register name} [@var{.type}] [[@var{index}]]
423
424 The @code{dn} and @code{qn} directives are used to create typed
425 and/or indexed register aliases for use in Advanced SIMD Extension
426 (Neon) instructions. The former should be used to create aliases
427 of double-precision registers, and the latter to create aliases of
428 quad-precision registers.
429
430 If these directives are used to create typed aliases, those aliases can
431 be used in Neon instructions instead of writing types after the mnemonic
432 or after each operand. For example:
433
434 @smallexample
435 x .dn d2.f32
436 y .dn d3.f32
437 z .dn d4.f32[1]
438 vmul x,y,z
439 @end smallexample
440
441 This is equivalent to writing the following:
442
443 @smallexample
444 vmul.f32 d2,d3,d4[1]
445 @end smallexample
446
447 Aliases created using @code{dn} or @code{qn} can be destroyed using
448 @code{unreq}.
449
450 @cindex @code{code} directive, ARM
451 @item .code @code{[16|32]}
452 This directive selects the instruction set being generated. The value 16
453 selects Thumb, with the value 32 selecting ARM.
454
455 @cindex @code{thumb} directive, ARM
456 @item .thumb
457 This performs the same action as @var{.code 16}.
458
459 @cindex @code{arm} directive, ARM
460 @item .arm
461 This performs the same action as @var{.code 32}.
462
463 @cindex @code{force_thumb} directive, ARM
464 @item .force_thumb
465 This directive forces the selection of Thumb instructions, even if the
466 target processor does not support those instructions
467
468 @cindex @code{thumb_func} directive, ARM
469 @item .thumb_func
470 This directive specifies that the following symbol is the name of a
471 Thumb encoded function. This information is necessary in order to allow
472 the assembler and linker to generate correct code for interworking
473 between Arm and Thumb instructions and should be used even if
474 interworking is not going to be performed. The presence of this
475 directive also implies @code{.thumb}
476
477 This directive is not neccessary when generating EABI objects. On these
478 targets the encoding is implicit when generating Thumb code.
479
480 @cindex @code{thumb_set} directive, ARM
481 @item .thumb_set
482 This performs the equivalent of a @code{.set} directive in that it
483 creates a symbol which is an alias for another symbol (possibly not yet
484 defined). This directive also has the added property in that it marks
485 the aliased symbol as being a thumb function entry point, in the same
486 way that the @code{.thumb_func} directive does.
487
488 @cindex @code{.ltorg} directive, ARM
489 @item .ltorg
490 This directive causes the current contents of the literal pool to be
491 dumped into the current section (which is assumed to be the .text
492 section) at the current location (aligned to a word boundary).
493 @code{GAS} maintains a separate literal pool for each section and each
494 sub-section. The @code{.ltorg} directive will only affect the literal
495 pool of the current section and sub-section. At the end of assembly
496 all remaining, un-empty literal pools will automatically be dumped.
497
498 Note - older versions of @code{GAS} would dump the current literal
499 pool any time a section change occurred. This is no longer done, since
500 it prevents accurate control of the placement of literal pools.
501
502 @cindex @code{.pool} directive, ARM
503 @item .pool
504 This is a synonym for .ltorg.
505
506 @anchor{arm_fnstart}
507 @cindex @code{.fnstart} directive, ARM
508 @item .fnstart
509 Marks the start of a function with an unwind table entry.
510
511 @anchor{arm_fnend}
512 @cindex @code{.fnend} directive, ARM
513 @item .fnend
514 Marks the end of a function with an unwind table entry. The unwind index
515 table entry is created when this directive is processed.
516
517 If no personality routine has been specified then standard personality
518 routine 0 or 1 will be used, depending on the number of unwind opcodes
519 required.
520
521 @cindex @code{.cantunwind} directive, ARM
522 @item .cantunwind
523 Prevents unwinding through the current function. No personality routine
524 or exception table data is required or permitted.
525
526 @cindex @code{.personality} directive, ARM
527 @item .personality @var{name}
528 Sets the personality routine for the current function to @var{name}.
529
530 @cindex @code{.personalityindex} directive, ARM
531 @item .personalityindex @var{index}
532 Sets the personality routine for the current function to the EABI standard
533 routine number @var{index}
534
535 @cindex @code{.handlerdata} directive, ARM
536 @item .handlerdata
537 Marks the end of the current function, and the start of the exception table
538 entry for that function. Anything between this directive and the
539 @code{.fnend} directive will be added to the exception table entry.
540
541 Must be preceded by a @code{.personality} or @code{.personalityindex}
542 directive.
543
544 @anchor{arm_save}
545 @cindex @code{.save} directive, ARM
546 @item .save @var{reglist}
547 Generate unwinder annotations to restore the registers in @var{reglist}.
548 The format of @var{reglist} is the same as the corresponding store-multiple
549 instruction.
550
551 @smallexample
552 @exdent @emph{core registers}
553 .save @{r4, r5, r6, lr@}
554 stmfd sp!, @{r4, r5, r6, lr@}
555 @exdent @emph{FPA registers}
556 .save f4, 2
557 sfmfd f4, 2, [sp]!
558 @exdent @emph{VFP registers}
559 .save @{d8, d9, d10@}
560 fstmdx sp!, @{d8, d9, d10@}
561 @exdent @emph{iWMMXt registers}
562 .save @{wr10, wr11@}
563 wstrd wr11, [sp, #-8]!
564 wstrd wr10, [sp, #-8]!
565 or
566 .save wr11
567 wstrd wr11, [sp, #-8]!
568 .save wr10
569 wstrd wr10, [sp, #-8]!
570 @end smallexample
571
572 @cindex @code{.vsave} directive, ARM
573 @item .vsave @var{vfp-reglist}
574 Generate unwinder annotations to restore the VFP registers in @var{vfp-reglist}
575 using FLDMD. Also works for VFPv3 registers
576 that are to be restored using VLDM.
577 The format of @var{vfp-reglist} is the same as the corresponding store-multiple
578 instruction.
579
580 @smallexample
581 @exdent @emph{VFP registers}
582 .vsave @{d8, d9, d10@}
583 fstmdd sp!, @{d8, d9, d10@}
584 @exdent @emph{VFPv3 registers}
585 .vsave @{d15, d16, d17@}
586 vstm sp!, @{d15, d16, d17@}
587 @end smallexample
588
589 Since FLDMX and FSTMX are now deprecated, this directive should be
590 used in favour of @code{.save} for saving VFP registers for ARMv6 and above.
591
592 @anchor{arm_pad}
593 @cindex @code{.pad} directive, ARM
594 @item .pad #@var{count}
595 Generate unwinder annotations for a stack adjustment of @var{count} bytes.
596 A positive value indicates the function prologue allocated stack space by
597 decrementing the stack pointer.
598
599 @anchor{arm_movsp}
600 @cindex @code{.movsp} directive, ARM
601 @item .movsp @var{reg} [, #@var{offset}]
602 Tell the unwinder that @var{reg} contains an offset from the current
603 stack pointer. If @var{offset} is not specified then it is assumed to be
604 zero.
605
606 @anchor{arm_setfp}
607 @cindex @code{.setfp} directive, ARM
608 @item .setfp @var{fpreg}, @var{spreg} [, #@var{offset}]
609 Make all unwinder annotations relaive to a frame pointer. Without this
610 the unwinder will use offsets from the stack pointer.
611
612 The syntax of this directive is the same as the @code{sub} or @code{mov}
613 instruction used to set the frame pointer. @var{spreg} must be either
614 @code{sp} or mentioned in a previous @code{.movsp} directive.
615
616 @smallexample
617 .movsp ip
618 mov ip, sp
619 @dots{}
620 .setfp fp, ip, #4
621 sub fp, ip, #4
622 @end smallexample
623
624 @cindex @code{.unwind_raw} directive, ARM
625 @item .raw @var{offset}, @var{byte1}, @dots{}
626 Insert one of more arbitary unwind opcode bytes, which are known to adjust
627 the stack pointer by @var{offset} bytes.
628
629 For example @code{.unwind_raw 4, 0xb1, 0x01} is equivalent to
630 @code{.save @{r0@}}
631
632 @cindex @code{.cpu} directive, ARM
633 @item .cpu @var{name}
634 Select the target processor. Valid values for @var{name} are the same as
635 for the @option{-mcpu} commandline option.
636
637 @cindex @code{.arch} directive, ARM
638 @item .arch @var{name}
639 Select the target architecture. Valid values for @var{name} are the same as
640 for the @option{-march} commandline option.
641
642 @cindex @code{.object_arch} directive, ARM
643 @item .object_arch @var{name}
644 Override the architecture recorded in the EABI object attribute section.
645 Valid values for @var{name} are the same as for the @code{.arch} directive.
646 Typically this is useful when code uses runtime detection of CPU features.
647
648 @cindex @code{.fpu} directive, ARM
649 @item .fpu @var{name}
650 Select the floating point unit to assemble for. Valid values for @var{name}
651 are the same as for the @option{-mfpu} commandline option.
652
653 @cindex @code{.eabi_attribute} directive, ARM
654 @item .eabi_attribute @var{tag}, @var{value}
655 Set the EABI object attribute @var{tag} to @var{value}.
656
657 The @var{tag} is either an attribute number, or one of the following:
658 @code{Tag_CPU_raw_name}, @code{Tag_CPU_name}, @code{Tag_CPU_arch},
659 @code{Tag_CPU_arch_profile}, @code{Tag_ARM_ISA_use},
660 @code{Tag_THUMB_ISA_use}, @code{Tag_VFP_arch}, @code{Tag_WMMX_arch},
661 @code{Tag_Advanced_SIMD_arch}, @code{Tag_PCS_config},
662 @code{Tag_ABI_PCS_R9_use}, @code{Tag_ABI_PCS_RW_data},
663 @code{Tag_ABI_PCS_RO_data}, @code{Tag_ABI_PCS_GOT_use},
664 @code{Tag_ABI_PCS_wchar_t}, @code{Tag_ABI_FP_rounding},
665 @code{Tag_ABI_FP_denormal}, @code{Tag_ABI_FP_exceptions},
666 @code{Tag_ABI_FP_user_exceptions}, @code{Tag_ABI_FP_number_model},
667 @code{Tag_ABI_align8_needed}, @code{Tag_ABI_align8_preserved},
668 @code{Tag_ABI_enum_size}, @code{Tag_ABI_HardFP_use},
669 @code{Tag_ABI_VFP_args}, @code{Tag_ABI_WMMX_args},
670 @code{Tag_ABI_optimization_goals}, @code{Tag_ABI_FP_optimization_goals},
671 @code{Tag_compatibility}, @code{Tag_CPU_unaligned_access},
672 @code{Tag_VFP_HP_extension}, @code{Tag_ABI_FP_16bit_format},
673 @code{Tag_nodefaults}, @code{Tag_also_compatible_with},
674 @code{Tag_conformance}, @code{Tag_T2EE_use},
675 @code{Tag_Virtualization_use}, @code{Tag_MPextension_use}
676
677 The @var{value} is either a @code{number}, @code{"string"}, or
678 @code{number, "string"} depending on the tag.
679
680 @end table
681
682 @node ARM Opcodes
683 @section Opcodes
684
685 @cindex ARM opcodes
686 @cindex opcodes for ARM
687 @code{@value{AS}} implements all the standard ARM opcodes. It also
688 implements several pseudo opcodes, including several synthetic load
689 instructions.
690
691 @table @code
692
693 @cindex @code{NOP} pseudo op, ARM
694 @item NOP
695 @smallexample
696 nop
697 @end smallexample
698
699 This pseudo op will always evaluate to a legal ARM instruction that does
700 nothing. Currently it will evaluate to MOV r0, r0.
701
702 @cindex @code{LDR reg,=<label>} pseudo op, ARM
703 @item LDR
704 @smallexample
705 ldr <register> , = <expression>
706 @end smallexample
707
708 If expression evaluates to a numeric constant then a MOV or MVN
709 instruction will be used in place of the LDR instruction, if the
710 constant can be generated by either of these instructions. Otherwise
711 the constant will be placed into the nearest literal pool (if it not
712 already there) and a PC relative LDR instruction will be generated.
713
714 @cindex @code{ADR reg,<label>} pseudo op, ARM
715 @item ADR
716 @smallexample
717 adr <register> <label>
718 @end smallexample
719
720 This instruction will load the address of @var{label} into the indicated
721 register. The instruction will evaluate to a PC relative ADD or SUB
722 instruction depending upon where the label is located. If the label is
723 out of range, or if it is not defined in the same file (and section) as
724 the ADR instruction, then an error will be generated. This instruction
725 will not make use of the literal pool.
726
727 @cindex @code{ADRL reg,<label>} pseudo op, ARM
728 @item ADRL
729 @smallexample
730 adrl <register> <label>
731 @end smallexample
732
733 This instruction will load the address of @var{label} into the indicated
734 register. The instruction will evaluate to one or two PC relative ADD
735 or SUB instructions depending upon where the label is located. If a
736 second instruction is not needed a NOP instruction will be generated in
737 its place, so that this instruction is always 8 bytes long.
738
739 If the label is out of range, or if it is not defined in the same file
740 (and section) as the ADRL instruction, then an error will be generated.
741 This instruction will not make use of the literal pool.
742
743 @end table
744
745 For information on the ARM or Thumb instruction sets, see @cite{ARM
746 Software Development Toolkit Reference Manual}, Advanced RISC Machines
747 Ltd.
748
749 @node ARM Mapping Symbols
750 @section Mapping Symbols
751
752 The ARM ELF specification requires that special symbols be inserted
753 into object files to mark certain features:
754
755 @table @code
756
757 @cindex @code{$a}
758 @item $a
759 At the start of a region of code containing ARM instructions.
760
761 @cindex @code{$t}
762 @item $t
763 At the start of a region of code containing THUMB instructions.
764
765 @cindex @code{$d}
766 @item $d
767 At the start of a region of data.
768
769 @end table
770
771 The assembler will automatically insert these symbols for you - there
772 is no need to code them yourself. Support for tagging symbols ($b,
773 $f, $p and $m) which is also mentioned in the current ARM ELF
774 specification is not implemented. This is because they have been
775 dropped from the new EABI and so tools cannot rely upon their
776 presence.
777
778 @node ARM Unwinding Tutorial
779 @section Unwinding
780
781 The ABI for the ARM Architecture specifies a standard format for
782 exception unwind information. This information is used when an
783 exception is thrown to determine where control should be transferred.
784 In particular, the unwind information is used to determine which
785 function called the function that threw the exception, and which
786 function called that one, and so forth. This information is also used
787 to restore the values of callee-saved registers in the function
788 catching the exception.
789
790 If you are writing functions in assembly code, and those functions
791 call other functions that throw exceptions, you must use assembly
792 pseudo ops to ensure that appropriate exception unwind information is
793 generated. Otherwise, if one of the functions called by your assembly
794 code throws an exception, the run-time library will be unable to
795 unwind the stack through your assembly code and your program will not
796 behave correctly.
797
798 To illustrate the use of these pseudo ops, we will examine the code
799 that G++ generates for the following C++ input:
800
801 @verbatim
802 void callee (int *);
803
804 int
805 caller ()
806 {
807 int i;
808 callee (&i);
809 return i;
810 }
811 @end verbatim
812
813 This example does not show how to throw or catch an exception from
814 assembly code. That is a much more complex operation and should
815 always be done in a high-level language, such as C++, that directly
816 supports exceptions.
817
818 The code generated by one particular version of G++ when compiling the
819 example above is:
820
821 @verbatim
822 _Z6callerv:
823 .fnstart
824 .LFB2:
825 @ Function supports interworking.
826 @ args = 0, pretend = 0, frame = 8
827 @ frame_needed = 1, uses_anonymous_args = 0
828 stmfd sp!, {fp, lr}
829 .save {fp, lr}
830 .LCFI0:
831 .setfp fp, sp, #4
832 add fp, sp, #4
833 .LCFI1:
834 .pad #8
835 sub sp, sp, #8
836 .LCFI2:
837 sub r3, fp, #8
838 mov r0, r3
839 bl _Z6calleePi
840 ldr r3, [fp, #-8]
841 mov r0, r3
842 sub sp, fp, #4
843 ldmfd sp!, {fp, lr}
844 bx lr
845 .LFE2:
846 .fnend
847 @end verbatim
848
849 Of course, the sequence of instructions varies based on the options
850 you pass to GCC and on the version of GCC in use. The exact
851 instructions are not important since we are focusing on the pseudo ops
852 that are used to generate unwind information.
853
854 An important assumption made by the unwinder is that the stack frame
855 does not change during the body of the function. In particular, since
856 we assume that the assembly code does not itself throw an exception,
857 the only point where an exception can be thrown is from a call, such
858 as the @code{bl} instruction above. At each call site, the same saved
859 registers (including @code{lr}, which indicates the return address)
860 must be located in the same locations relative to the frame pointer.
861
862 The @code{.fnstart} (@pxref{arm_fnstart,,.fnstart pseudo op}) pseudo
863 op appears immediately before the first instruction of the function
864 while the @code{.fnend} (@pxref{arm_fnend,,.fnend pseudo op}) pseudo
865 op appears immediately after the last instruction of the function.
866 These pseudo ops specify the range of the function.
867
868 Only the order of the other pseudos ops (e.g., @code{.setfp} or
869 @code{.pad}) matters; their exact locations are irrelevant. In the
870 example above, the compiler emits the pseudo ops with particular
871 instructions. That makes it easier to understand the code, but it is
872 not required for correctness. It would work just as well to emit all
873 of the pseudo ops other than @code{.fnend} in the same order, but
874 immediately after @code{.fnstart}.
875
876 The @code{.save} (@pxref{arm_save,,.save pseudo op}) pseudo op
877 indicates registers that have been saved to the stack so that they can
878 be restored before the function returns. The argument to the
879 @code{.save} pseudo op is a list of registers to save. If a register
880 is ``callee-saved'' (as specified by the ABI) and is modified by the
881 function you are writing, then your code must save the value before it
882 is modified and restore the original value before the function
883 returns. If an exception is thrown, the run-time library restores the
884 values of these registers from their locations on the stack before
885 returning control to the exception handler. (Of course, if an
886 exception is not thrown, the function that contains the @code{.save}
887 pseudo op restores these registers in the function epilogue, as is
888 done with the @code{ldmfd} instruction above.)
889
890 You do not have to save callee-saved registers at the very beginning
891 of the function and you do not need to use the @code{.save} pseudo op
892 immediately following the point at which the registers are saved.
893 However, if you modify a callee-saved register, you must save it on
894 the stack before modifying it and before calling any functions which
895 might throw an exception. And, you must use the @code{.save} pseudo
896 op to indicate that you have done so.
897
898 The @code{.pad} (@pxref{arm_pad,,.pad}) pseudo op indicates a
899 modification of the stack pointer that does not save any registers.
900 The argument is the number of bytes (in decimal) that are subtracted
901 from the stack pointer. (On ARM CPUs, the stack grows downwards, so
902 subtracting from the stack pointer increases the size of the stack.)
903
904 The @code{.setfp} (@pxref{arm_setfp,,.setfp pseudo op}) pseudo op
905 indicates the register that contains the frame pointer. The first
906 argument is the register that is set, which is typically @code{fp}.
907 The second argument indicates the register from which the frame
908 pointer takes its value. The third argument, if present, is the value
909 (in decimal) added to the register specified by the second argument to
910 compute the value of the frame pointer. You should not modify the
911 frame pointer in the body of the function.
912
913 If you do not use a frame pointer, then you should not use the
914 @code{.setfp} pseudo op. If you do not use a frame pointer, then you
915 should avoid modifying the stack pointer outside of the function
916 prologue. Otherwise, the run-time library will be unable to find
917 saved registers when it is unwinding the stack.
918
919 The pseudo ops described above are sufficient for writing assembly
920 code that calls functions which may throw exceptions. If you need to
921 know more about the object-file format used to represent unwind
922 information, you may consult the @cite{Exception Handling ABI for the
923 ARM Architecture} available from @uref{http://infocenter.arm.com}.
This page took 0.048091 seconds and 5 git commands to generate.