GAS: Add ECOFF `.aent' pseudo-op support
[deliverable/binutils-gdb.git] / gas / doc / c-sparc.texi
CommitLineData
2571583a 1@c Copyright (C) 1991-2017 Free Software Foundation, Inc.
252b5132
RH
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 Sparc-Dependent
7@chapter SPARC Dependent Features
8@end ifset
9@ifclear GENERIC
10@node Machine Dependencies
11@chapter SPARC Dependent Features
12@end ifclear
13
14@cindex SPARC support
15@menu
16* Sparc-Opts:: Options
17* Sparc-Aligned-Data:: Option to enforce aligned data
c15295d5 18* Sparc-Syntax:: Syntax
252b5132
RH
19* Sparc-Float:: Floating Point
20* Sparc-Directives:: Sparc Machine Directives
21@end menu
22
23@node Sparc-Opts
24@section Options
25
26@cindex options for SPARC
27@cindex SPARC options
28@cindex architectures, SPARC
29@cindex SPARC architectures
f04d18b7 30The SPARC chip family includes several successive versions, using the same
252b5132 31core instruction set, but including a few additional instructions at
f04d18b7 32each version. There are exceptions to this however. For details on what
252b5132
RH
33instructions each variant supports, please see the chip's architecture
34reference manual.
35
36By default, @code{@value{AS}} assumes the core instruction set (SPARC
37v6), but ``bumps'' the architecture level as needed: it switches to
38successively higher architectures as it encounters instructions that
39only exist in the higher levels.
40
41If not configured for SPARC v9 (@code{sparc64-*-*}) GAS will not bump
f04d18b7 42past sparclite by default, an option must be passed to enable the
252b5132
RH
43v9 instructions.
44
45GAS treats sparclite as being compatible with v8, unless an architecture
46is explicitly requested. SPARC v9 is always incompatible with sparclite.
47
48@c The order here is the same as the order of enum sparc_opcode_arch_val
49@c to give the user a sense of the order of the "bumping".
50
51@table @code
52@kindex -Av6
4bafe00e 53@kindex -Av7
252b5132 54@kindex -Av8
d6787ef9 55@kindex -Aleon
252b5132
RH
56@kindex -Asparclet
57@kindex -Asparclite
58@kindex -Av9
59@kindex -Av9a
4bafe00e
DM
60@kindex -Av9b
61@kindex -Av9c
62@kindex -Av9d
3d68f91c 63@kindex -Av9e
4bafe00e 64@kindex -Av9v
3d68f91c 65@kindex -Av9m
4bafe00e
DM
66@kindex -Asparc
67@kindex -Asparcvis
68@kindex -Asparcvis2
69@kindex -Asparcfmaf
70@kindex -Asparcima
71@kindex -Asparcvis3
72@kindex -Asparcvis3r
d6787ef9 73@item -Av6 | -Av7 | -Av8 | -Aleon | -Asparclet | -Asparclite
46a2d504 74@itemx -Av8plus | -Av8plusa | -Av8plusb | -Av8plusc | -Av8plusd | -Av8plusv | -Av8plusm
3d68f91c 75@itemx -Av9 | -Av9a | -Av9b | -Av9c | -Av9d | -Av9e | -Av9v | -Av9m
4bafe00e 76@itemx -Asparc | -Asparcvis | -Asparcvis2 | -Asparcfmaf | -Asparcima
46a2d504 77@itemx -Asparcvis3 | -Asparcvis3r | -Asparc5
252b5132
RH
78Use one of the @samp{-A} options to select one of the SPARC
79architectures explicitly. If you select an architecture explicitly,
80@code{@value{AS}} reports a fatal error if it encounters an instruction
81or feature requiring an incompatible or higher level.
82
4bafe00e
DM
83@samp{-Av8plus}, @samp{-Av8plusa}, @samp{-Av8plusb}, @samp{-Av8plusc},
84@samp{-Av8plusd}, and @samp{-Av8plusv} select a 32 bit environment.
252b5132 85
3d68f91c
JM
86@samp{-Av9}, @samp{-Av9a}, @samp{-Av9b}, @samp{-Av9c}, @samp{-Av9d},
87@samp{-Av9e}, @samp{-Av9v} and @samp{-Av9m} select a 64 bit
88environment and are not available unless GAS is explicitly configured
89with 64 bit environment support.
252b5132
RH
90
91@samp{-Av8plusa} and @samp{-Av9a} enable the SPARC V9 instruction set with
4bafe00e 92UltraSPARC VIS 1.0 extensions.
252b5132 93
4bafe00e
DM
94@samp{-Av8plusb} and @samp{-Av9b} enable the UltraSPARC VIS 2.0 instructions,
95as well as the instructions enabled by @samp{-Av8plusa} and @samp{-Av9a}.
96
97@samp{-Av8plusc} and @samp{-Av9c} enable the UltraSPARC Niagara instructions,
98as well as the instructions enabled by @samp{-Av8plusb} and @samp{-Av9b}.
99
100@samp{-Av8plusd} and @samp{-Av9d} enable the floating point fused
101multiply-add, VIS 3.0, and HPC extension instructions, as well as the
102instructions enabled by @samp{-Av8plusc} and @samp{-Av9c}.
103
3d68f91c
JM
104@samp{-Av8pluse} and @samp{-Av9e} enable the cryptographic
105instructions, as well as the instructions enabled by @samp{-Av8plusd}
106and @samp{-Av9d}.
107
108@samp{-Av8plusv} and @samp{-Av9v} enable floating point unfused
109multiply-add, and integer multiply-add, as well as the instructions
110enabled by @samp{-Av8pluse} and @samp{-Av9e}.
111
112@samp{-Av8plusm} and @samp{-Av9m} enable the VIS 4.0, subtract extended,
113xmpmul, xmontmul and xmontsqr instructions, as well as the instructions
114enabled by @samp{-Av8plusv} and @samp{-Av9v}.
4bafe00e
DM
115
116@samp{-Asparc} specifies a v9 environment. It is equivalent to
117@samp{-Av9} if the word size is 64-bit, and @samp{-Av8plus} otherwise.
118
119@samp{-Asparcvis} specifies a v9a environment. It is equivalent to
120@samp{-Av9a} if the word size is 64-bit, and @samp{-Av8plusa} otherwise.
121
122@samp{-Asparcvis2} specifies a v9b environment. It is equivalent to
123@samp{-Av9b} if the word size is 64-bit, and @samp{-Av8plusb} otherwise.
124
125@samp{-Asparcfmaf} specifies a v9b environment with the floating point
126fused multiply-add instructions enabled.
127
128@samp{-Asparcima} specifies a v9b environment with the integer
129multiply-add instructions enabled.
130
131@samp{-Asparcvis3} specifies a v9b environment with the VIS 3.0,
132HPC , and floating point fused multiply-add instructions enabled.
133
3d68f91c
JM
134@samp{-Asparcvis3r} specifies a v9b environment with the VIS 3.0, HPC,
135and floating point unfused multiply-add instructions enabled.
136
137@samp{-Asparc5} is equivalent to @samp{-Av9m}.
4bafe00e
DM
138
139@item -xarch=v8plus | -xarch=v8plusa | -xarch=v8plusb | -xarch=v8plusc
46a2d504 140@itemx -xarch=v8plusd | -xarch=v8plusv | -xarch=v8plusm | -xarch=v9 | -xarch=v9a
3d68f91c 141@itemx -xarch=v9b | -xarch=v9c | -xarch=v9d | -xarch=v9e | -xarch=v9v | -xarch=v9m
4bafe00e
DM
142@itemx -xarch=sparc | -xarch=sparcvis | -xarch=sparcvis2
143@itemx -xarch=sparcfmaf | -xarch=sparcima | -xarch=sparcvis3
3d68f91c 144@itemx -xarch=sparcvis3r | -xarch=sparc5
f04d18b7 145For compatibility with the SunOS v9 assembler. These options are
4bafe00e 146equivalent to -Av8plus, -Av8plusa, -Av8plusb, -Av8plusc, -Av8plusd,
46a2d504 147-Av8plusv, -Av8plusm, -Av9, -Av9a, -Av9b, -Av9c, -Av9d, -Av9e, -Av9v, -Av9m,
3d68f91c
JM
148-Asparc, -Asparcvis, -Asparcvis2, -Asparcfmaf, -Asparcima,
149-Asparcvis3, and -Asparcvis3r, respectively.
252b5132
RH
150
151@item -bump
152Warn whenever it is necessary to switch to another level.
153If an architecture level is explicitly requested, GAS will not issue
154warnings until that level is reached, and will then bump the level
155as required (except between incompatible levels).
156
157@item -32 | -64
158Select the word size, either 32 bits or 64 bits.
159These options are only available with the ELF object file format,
160and require that the necessary BFD support has been included.
46a2d504
JM
161
162@item --dcti-couples-detect
163Warn if a DCTI (delayed control transfer instruction) couple is found
164when generating code for a variant of the SPARC architecture in which
165the execution of the couple is unpredictable, or very slow. This is
166disabled by default.
252b5132
RH
167@end table
168
169@node Sparc-Aligned-Data
170@section Enforcing aligned data
171
172@cindex data alignment on SPARC
173@cindex SPARC data alignment
174SPARC GAS normally permits data to be misaligned. For example, it
175permits the @code{.long} pseudo-op to be used on a byte boundary.
f04d18b7
DM
176However, the native SunOS assemblers issue an error when they see
177misaligned data.
252b5132
RH
178
179@kindex --enforce-aligned-data
180You can use the @code{--enforce-aligned-data} option to make SPARC GAS
f04d18b7 181also issue an error about misaligned data, just as the SunOS
252b5132
RH
182assemblers do.
183
184The @code{--enforce-aligned-data} option is not the default because gcc
185issues misaligned data pseudo-ops when it initializes certain packed
186data structures (structures defined using the @code{packed} attribute).
187You may have to assemble with GAS in order to initialize packed data
188structures in your own code.
189
c15295d5
DM
190@cindex SPARC syntax
191@cindex syntax, SPARC
192@node Sparc-Syntax
193@section Sparc Syntax
194The assembler syntax closely follows The Sparc Architecture Manual,
195versions 8 and 9, as well as most extensions defined by Sun
196for their UltraSPARC and Niagara line of processors.
197
198@menu
199* Sparc-Chars:: Special Characters
200* Sparc-Regs:: Register Names
1a6b486f 201* Sparc-Constants:: Constant Names
c15295d5 202* Sparc-Relocs:: Relocations
f04d18b7 203* Sparc-Size-Translations:: Size Translations
c15295d5
DM
204@end menu
205
206@node Sparc-Chars
207@subsection Special Characters
208
209@cindex line comment character, Sparc
210@cindex Sparc line comment character
7c31ae13
NC
211A @samp{!} character appearing anywhere on a line indicates the start
212of a comment that extends to the end of that line.
213
214If a @samp{#} appears as the first character of a line then the whole
215line is treated as a comment, but in this case the line could also be
216a logical line number directive (@pxref{Comments}) or a preprocessor
217control command (@pxref{Preprocessing}).
c15295d5
DM
218
219@cindex line separator, Sparc
220@cindex statement separator, Sparc
221@cindex Sparc line separator
222@samp{;} can be used instead of a newline to separate statements.
223
224@node Sparc-Regs
225@subsection Register Names
226@cindex Sparc registers
227@cindex register names, Sparc
228
229The Sparc integer register file is broken down into global,
230outgoing, local, and incoming.
231
232@itemize @bullet
233@item
234The 8 global registers are referred to as @samp{%g@var{n}}.
235
236@item
237The 8 outgoing registers are referred to as @samp{%o@var{n}}.
238
239@item
240The 8 local registers are referred to as @samp{%l@var{n}}.
241
242@item
243The 8 incoming registers are referred to as @samp{%i@var{n}}.
244
245@item
246The frame pointer register @samp{%i6} can be referenced using
247the alias @samp{%fp}.
248
249@item
250The stack pointer register @samp{%o6} can be referenced using
251the alias @samp{%sp}.
252@end itemize
253
254Floating point registers are simply referred to as @samp{%f@var{n}}.
255When assembling for pre-V9, only 32 floating point registers
256are available. For V9 and later there are 64, but there are
257restrictions when referencing the upper 32 registers. They
258can only be accessed as double or quad, and thus only even
259or quad numbered accesses are allowed. For example, @samp{%f34}
260is a legal floating point register, but @samp{%f35} is not.
261
7039122d
JM
262Floating point registers accessed as double can also be referred using
263the @samp{%d@var{n}} notation, where @var{n} is even. Similarly,
264floating point registers accessed as quad can be referred using the
265@samp{%q@var{n}} notation, where @var{n} is a multiple of 4. For
266example, @samp{%f4} can be denoted as both @samp{%d4} and @samp{%q4}.
267On the other hand, @samp{%f2} can be denoted as @samp{%d2} but not as
268@samp{%q2}.
269
c15295d5
DM
270Certain V9 instructions allow access to ancillary state registers.
271Most simply they can be referred to as @samp{%asr@var{n}} where
f04d18b7 272@var{n} can be from 16 to 31. However, there are some aliases
c15295d5
DM
273defined to reference ASR registers defined for various UltraSPARC
274processors:
275
276@itemize @bullet
277@item
278The tick compare register is referred to as @samp{%tick_cmpr}.
279
280@item
1a6b486f
DM
281The system tick register is referred to as @samp{%stick}. An alias,
282@samp{%sys_tick}, exists but is deprecated and should not be used
283by new software.
c15295d5
DM
284
285@item
1a6b486f
DM
286The system tick compare register is referred to as @samp{%stick_cmpr}.
287An alias, @samp{%sys_tick_cmpr}, exists but is deprecated and should
288not be used by new software.
c15295d5
DM
289
290@item
291The software interrupt register is referred to as @samp{%softint}.
292
293@item
294The set software interrupt register is referred to as @samp{%set_softint}.
f04d18b7 295The mnemonic @samp{%softint_set} is provided as an alias.
c15295d5
DM
296
297@item
298The clear software interrupt register is referred to as
f04d18b7
DM
299@samp{%clear_softint}. The mnemonic @samp{%softint_clear} is provided
300as an alias.
c15295d5
DM
301
302@item
303The performance instrumentation counters register is referred to as
304@samp{%pic}.
305
306@item
307The performance control register is referred to as @samp{%pcr}.
308
309@item
310The graphics status register is referred to as @samp{%gsr}.
311
312@item
f04d18b7 313The V9 dispatch control register is referred to as @samp{%dcr}.
c15295d5
DM
314@end itemize
315
316Various V9 branch and conditional move instructions allow
317specification of which set of integer condition codes to
318test. These are referred to as @samp{%xcc} and @samp{%icc}.
319
f9911beb
JM
320Additionally, GAS supports the so-called ``natural'' condition codes;
321these are referred to as @samp{%ncc} and reference to @samp{%icc} if
322the word size is 32, @samp{%xcc} if the word size is 64.
323
c15295d5
DM
324In V9, there are 4 sets of floating point condition codes
325which are referred to as @samp{%fcc@var{n}}.
326
327Several special privileged and non-privileged registers
328exist:
329
330@itemize @bullet
331@item
332The V9 address space identifier register is referred to as @samp{%asi}.
333
334@item
335The V9 restorable windows register is referred to as @samp{%canrestore}.
336
337@item
338The V9 savable windows register is referred to as @samp{%cansave}.
339
340@item
341The V9 clean windows register is referred to as @samp{%cleanwin}.
342
343@item
344The V9 current window pointer register is referred to as @samp{%cwp}.
345
346@item
347The floating-point queue register is referred to as @samp{%fq}.
348
349@item
f04d18b7 350The V8 co-processor queue register is referred to as @samp{%cq}.
c15295d5
DM
351
352@item
353The floating point status register is referred to as @samp{%fsr}.
354
355@item
356The other windows register is referred to as @samp{%otherwin}.
357
358@item
359The V9 program counter register is referred to as @samp{%pc}.
360
361@item
362The V9 next program counter register is referred to as @samp{%npc}.
363
364@item
365The V9 processor interrupt level register is referred to as @samp{%pil}.
366
367@item
368The V9 processor state register is referred to as @samp{%pstate}.
369
370@item
371The trap base address register is referred to as @samp{%tba}.
372
373@item
374The V9 tick register is referred to as @samp{%tick}.
375
376@item
377The V9 trap level is referred to as @samp{%tl}.
378
379@item
380The V9 trap program counter is referred to as @samp{%tpc}.
381
382@item
383The V9 trap next program counter is referred to as @samp{%tnpc}.
384
385@item
386The V9 trap state is referred to as @samp{%tstate}.
387
388@item
389The V9 trap type is referred to as @samp{%tt}.
390
391@item
392The V9 condition codes is referred to as @samp{%ccr}.
393
394@item
395The V9 floating-point registers state is referred to as @samp{%fprs}.
396
397@item
398The V9 version register is referred to as @samp{%ver}.
399
400@item
401The V9 window state register is referred to as @samp{%wstate}.
402
403@item
404The Y register is referred to as @samp{%y}.
405
406@item
407The V8 window invalid mask register is referred to as @samp{%wim}.
408
409@item
410The V8 processor state register is referred to as @samp{%psr}.
411
412@item
f04d18b7 413The V9 global register level register is referred to as @samp{%gl}.
c15295d5
DM
414@end itemize
415
416Several special register names exist for hypervisor mode code:
417
418@itemize @bullet
419@item
420The hyperprivileged processor state register is referred to as
421@samp{%hpstate}.
422
423@item
424The hyperprivileged trap state register is referred to as @samp{%htstate}.
425
426@item
427The hyperprivileged interrupt pending register is referred to as
428@samp{%hintp}.
429
430@item
431The hyperprivileged trap base address register is referred to as
432@samp{%htba}.
433
434@item
435The hyperprivileged implementation version register is referred
436to as @samp{%hver}.
437
ec92c392
JM
438@item
439The hyperprivileged system tick offset register is referred to as
440@samp{%hstick_offset}. Note that there is no @samp{%hstick} register,
441the normal @samp{%stick} is used.
442
443@item
444The hyperprivileged system tick enable register is referred to as
445@samp{%hstick_enable}.
446
c15295d5
DM
447@item
448The hyperprivileged system tick compare register is referred
ec92c392 449to as @samp{%hstick_cmpr}.
1a6b486f
DM
450@end itemize
451
452@node Sparc-Constants
453@subsection Constants
454@cindex Sparc constants
455@cindex constants, Sparc
456
457Several Sparc instructions take an immediate operand field for
458which mnemonic names exist. Two such examples are @samp{membar}
459and @samp{prefetch}. Another example are the set of V9
460memory access instruction that allow specification of an
461address space identifier.
462
463The @samp{membar} instruction specifies a memory barrier that is
464the defined by the operand which is a bitmask. The supported
465mask mnemonics are:
466
467@itemize @bullet
468@item
469@samp{#Sync} requests that all operations (including nonmemory
470reference operations) appearing prior to the @code{membar} must have
471been performed and the effects of any exceptions become visible before
472any instructions after the @code{membar} may be initiated. This
473corresponds to @code{membar} cmask field bit 2.
474
475@item
476@samp{#MemIssue} requests that all memory reference operations
477appearing prior to the @code{membar} must have been performed before
478any memory operation after the @code{membar} may be initiated. This
479corresponds to @code{membar} cmask field bit 1.
480
481@item
482@samp{#Lookaside} requests that a store appearing prior to the
483@code{membar} must complete before any load following the
484@code{membar} referencing the same address can be initiated. This
485corresponds to @code{membar} cmask field bit 0.
486
487@item
488@samp{#StoreStore} defines that the effects of all stores appearing
489prior to the @code{membar} instruction must be visible to all
490processors before the effect of any stores following the
491@code{membar}. Equivalent to the deprecated @code{stbar} instruction.
492This corresponds to @code{membar} mmask field bit 3.
493
494@item
495@samp{#LoadStore} defines all loads appearing prior to the
496@code{membar} instruction must have been performed before the effect
497of any stores following the @code{membar} is visible to any other
498processor. This corresponds to @code{membar} mmask field bit 2.
499
500@item
501@samp{#StoreLoad} defines that the effects of all stores appearing
502prior to the @code{membar} instruction must be visible to all
503processors before loads following the @code{membar} may be performed.
504This corresponds to @code{membar} mmask field bit 1.
505
506@item
507@samp{#LoadLoad} defines that all loads appearing prior to the
508@code{membar} instruction must have been performed before any loads
509following the @code{membar} may be performed. This corresponds to
510@code{membar} mmask field bit 0.
511
512@end itemize
513
514These values can be ored together, for example:
515
516@example
517membar #Sync
518membar #StoreLoad | #LoadLoad
519membar #StoreLoad | #StoreStore
520@end example
521
522The @code{prefetch} and @code{prefetcha} instructions take a prefetch
523function code. The following prefetch function code constant
524mnemonics are available:
525
526@itemize @bullet
527@item
528@samp{#n_reads} requests a prefetch for several reads, and corresponds
529to a prefetch function code of 0.
530
531@samp{#one_read} requests a prefetch for one read, and corresponds
532to a prefetch function code of 1.
533
534@samp{#n_writes} requests a prefetch for several writes (and possibly
535reads), and corresponds to a prefetch function code of 2.
536
537@samp{#one_write} requests a prefetch for one write, and corresponds
538to a prefetch function code of 3.
539
540@samp{#page} requests a prefetch page, and corresponds to a prefetch
541function code of 4.
542
543@samp{#invalidate} requests a prefetch invalidate, and corresponds to
544a prefetch function code of 16.
545
546@samp{#unified} requests a prefetch to the nearest unified cache, and
547corresponds to a prefetch function code of 17.
548
549@samp{#n_reads_strong} requests a strong prefetch for several reads,
550and corresponds to a prefetch function code of 20.
551
552@samp{#one_read_strong} requests a strong prefetch for one read,
553and corresponds to a prefetch function code of 21.
554
555@samp{#n_writes_strong} requests a strong prefetch for several writes,
556and corresponds to a prefetch function code of 22.
557
558@samp{#one_write_strong} requests a strong prefetch for one write,
559and corresponds to a prefetch function code of 23.
560
561Onle one prefetch code may be specified. Here are some examples:
562
563@example
564prefetch [%l0 + %l2], #one_read
565prefetch [%g2 + 8], #n_writes
566prefetcha [%g1] 0x8, #unified
567prefetcha [%o0 + 0x10] %asi, #n_reads
568@end example
569
570The actual behavior of a given prefetch function code is processor
571specific. If a processor does not implement a given prefetch
572function code, it will treat the prefetch instruction as a nop.
573
574For instructions that accept an immediate address space identifier,
575@code{@value{AS}} provides many mnemonics corresponding to
576V9 defined as well as UltraSPARC and Niagara extended values.
577For example, @samp{#ASI_P} and @samp{#ASI_BLK_INIT_QUAD_LDD_AIUS}.
578See the V9 and processor specific manuals for details.
579
c15295d5
DM
580@end itemize
581
582@node Sparc-Relocs
583@subsection Relocations
584@cindex Sparc relocations
585@cindex relocations, Sparc
586
587ELF relocations are available as defined in the 32-bit and 64-bit
588Sparc ELF specifications.
589
590@code{R_SPARC_HI22} is obtained using @samp{%hi} and @code{R_SPARC_LO10}
591is obtained using @samp{%lo}. Likewise @code{R_SPARC_HIX22} is
592obtained from @samp{%hix} and @code{R_SPARC_LOX10} is obtained
593using @samp{%lox}. For example:
594
595@example
596sethi %hi(symbol), %g1
597or %g1, %lo(symbol), %g1
598
599sethi %hix(symbol), %g1
600xor %g1, %lox(symbol), %g1
601@end example
602
603These ``high'' mnemonics extract bits 31:10 of their operand,
604and the ``low'' mnemonics extract bits 9:0 of their operand.
605
606V9 code model relocations can be requested as follows:
607
608@itemize @bullet
609@item
610@code{R_SPARC_HH22} is requested using @samp{%hh}. It can
611also be generated using @samp{%uhi}.
612@item
613@code{R_SPARC_HM10} is requested using @samp{%hm}. It can
614also be generated using @samp{%ulo}.
615@item
616@code{R_SPARC_LM22} is requested using @samp{%lm}.
617
618@item
619@code{R_SPARC_H44} is requested using @samp{%h44}.
620@item
621@code{R_SPARC_M44} is requested using @samp{%m44}.
622@item
2755f698
DM
623@code{R_SPARC_L44} is requested using @samp{%l44} or @samp{%l34}.
624@item
625@code{R_SPARC_H34} is requested using @samp{%h34}.
c15295d5
DM
626@end itemize
627
2755f698
DM
628The @samp{%l34} generates a @code{R_SPARC_L44} relocation because it
629calculates the necessary value, and therefore no explicit
630@code{R_SPARC_L34} relocation needed to be created for this purpose.
631
632The @samp{%h34} and @samp{%l34} relocations are used for the abs34 code
633model. Here is an example abs34 address generation sequence:
634
635@example
636sethi %h34(symbol), %g1
637sllx %g1, 2, %g1
638or %g1, %l34(symbol), %g1
639@end example
640
c15295d5
DM
641The PC relative relocation @code{R_SPARC_PC22} can be obtained by
642enclosing an operand inside of @samp{%pc22}. Likewise, the
643@code{R_SPARC_PC10} relocation can be obtained using @samp{%pc10}.
644These are mostly used when assembling PIC code. For example, the
645standard PIC sequence on Sparc to get the base of the global offset
646table, PC relative, into a register, can be performed as:
647
648@example
649sethi %pc22(_GLOBAL_OFFSET_TABLE_-4), %l7
650add %l7, %pc10(_GLOBAL_OFFSET_TABLE_+4), %l7
651@end example
652
653Several relocations exist to allow the link editor to potentially
654optimize GOT data references. The @code{R_SPARC_GOTDATA_OP_HIX22}
655relocation can obtained by enclosing an operand inside of
656@samp{%gdop_hix22}. The @code{R_SPARC_GOTDATA_OP_LOX10}
657relocation can obtained by enclosing an operand inside of
658@samp{%gdop_lox10}. Likewise, @code{R_SPARC_GOTDATA_OP} can be
659obtained by enclosing an operand inside of @samp{%gdop}.
660For example, assuming the GOT base is in register @code{%l7}:
661
662@example
663sethi %gdop_hix22(symbol), %l1
664xor %l1, %gdop_lox10(symbol), %l1
665ld [%l7 + %l1], %l2, %gdop(symbol)
666@end example
667
668There are many relocations that can be requested for access to
669thread local storage variables. All of the Sparc TLS mnemonics
670are supported:
671
672@itemize @bullet
673@item
674@code{R_SPARC_TLS_GD_HI22} is requested using @samp{%tgd_hi22}.
675@item
676@code{R_SPARC_TLS_GD_LO10} is requested using @samp{%tgd_lo10}.
677@item
678@code{R_SPARC_TLS_GD_ADD} is requested using @samp{%tgd_add}.
679@item
680@code{R_SPARC_TLS_GD_CALL} is requested using @samp{%tgd_call}.
681
682@item
683@code{R_SPARC_TLS_LDM_HI22} is requested using @samp{%tldm_hi22}.
684@item
685@code{R_SPARC_TLS_LDM_LO10} is requested using @samp{%tldm_lo10}.
686@item
687@code{R_SPARC_TLS_LDM_ADD} is requested using @samp{%tldm_add}.
688@item
689@code{R_SPARC_TLS_LDM_CALL} is requested using @samp{%tldm_call}.
690
691@item
692@code{R_SPARC_TLS_LDO_HIX22} is requested using @samp{%tldo_hix22}.
693@item
694@code{R_SPARC_TLS_LDO_LOX10} is requested using @samp{%tldo_lox10}.
695@item
696@code{R_SPARC_TLS_LDO_ADD} is requested using @samp{%tldo_add}.
697
698@item
699@code{R_SPARC_TLS_IE_HI22} is requested using @samp{%tie_hi22}.
700@item
701@code{R_SPARC_TLS_IE_LO10} is requested using @samp{%tie_lo10}.
702@item
703@code{R_SPARC_TLS_IE_LD} is requested using @samp{%tie_ld}.
704@item
705@code{R_SPARC_TLS_IE_LDX} is requested using @samp{%tie_ldx}.
706@item
707@code{R_SPARC_TLS_IE_ADD} is requested using @samp{%tie_add}.
708
709@item
710@code{R_SPARC_TLS_LE_HIX22} is requested using @samp{%tle_hix22}.
711@item
712@code{R_SPARC_TLS_LE_LOX10} is requested using @samp{%tle_lox10}.
713@end itemize
714
715Here are some example TLS model sequences.
716
717First, General Dynamic:
718
719@example
720sethi %tgd_hi22(symbol), %l1
721add %l1, %tgd_lo10(symbol), %l1
722add %l7, %l1, %o0, %tgd_add(symbol)
723call __tls_get_addr, %tgd_call(symbol)
724nop
725@end example
726
727Local Dynamic:
728
729@example
730sethi %tldm_hi22(symbol), %l1
731add %l1, %tldm_lo10(symbol), %l1
732add %l7, %l1, %o0, %tldm_add(symbol)
733call __tls_get_addr, %tldm_call(symbol)
734nop
735
736sethi %tldo_hix22(symbol), %l1
737xor %l1, %tldo_lox10(symbol), %l1
738add %o0, %l1, %l1, %tldo_add(symbol)
739@end example
740
741Initial Exec:
742
743@example
744sethi %tie_hi22(symbol), %l1
745add %l1, %tie_lo10(symbol), %l1
746ld [%l7 + %l1], %o0, %tie_ld(symbol)
747add %g7, %o0, %o0, %tie_add(symbol)
748
749sethi %tie_hi22(symbol), %l1
750add %l1, %tie_lo10(symbol), %l1
751ldx [%l7 + %l1], %o0, %tie_ldx(symbol)
752add %g7, %o0, %o0, %tie_add(symbol)
753@end example
754
755And finally, Local Exec:
756
757@example
758sethi %tle_hix22(symbol), %l1
759add %l1, %tle_lox10(symbol), %l1
760add %g7, %l1, %l1
761@end example
762
763When assembling for 64-bit, and a secondary constant addend is
764specified in an address expression that would normally generate
765an @code{R_SPARC_LO10} relocation, the assembler will emit an
766@code{R_SPARC_OLO10} instead.
252b5132 767
f04d18b7
DM
768@node Sparc-Size-Translations
769@subsection Size Translations
770@cindex Sparc size translations
771@cindex size, translations, Sparc
772
773Often it is desirable to write code in an operand size agnostic
774manner. @code{@value{AS}} provides support for this via
775operand size opcode translations. Translations are supported
776for loads, stores, shifts, compare-and-swap atomics, and the
777@samp{clr} synthetic instruction.
778
779If generating 32-bit code, @code{@value{AS}} will generate the
78032-bit opcode. Whereas if 64-bit code is being generated,
781the 64-bit opcode will be emitted. For example @code{ldn}
782will be transformed into @code{ld} for 32-bit code and
783@code{ldx} for 64-bit code.
784
785Here is an example meant to demonstrate all the supported
786opcode translations:
787
788@example
789ldn [%o0], %o1
790ldna [%o0] %asi, %o2
791stn %o1, [%o0]
792stna %o2, [%o0] %asi
793slln %o3, 3, %o3
794srln %o4, 8, %o4
795sran %o5, 12, %o5
796casn [%o0], %o1, %o2
797casna [%o0] %asi, %o1, %o2
798clrn %g1
799@end example
800
801In 32-bit mode @code{@value{AS}} will emit:
802
803@example
804ld [%o0], %o1
805lda [%o0] %asi, %o2
806st %o1, [%o0]
807sta %o2, [%o0] %asi
808sll %o3, 3, %o3
809srl %o4, 8, %o4
810sra %o5, 12, %o5
811cas [%o0], %o1, %o2
812casa [%o0] %asi, %o1, %o2
813clr %g1
814@end example
815
816And in 64-bit mode @code{@value{AS}} will emit:
817
818@example
819ldx [%o0], %o1
820ldxa [%o0] %asi, %o2
821stx %o1, [%o0]
822stxa %o2, [%o0] %asi
823sllx %o3, 3, %o3
824srlx %o4, 8, %o4
825srax %o5, 12, %o5
826casx [%o0], %o1, %o2
827casxa [%o0] %asi, %o1, %o2
828clrx %g1
829@end example
830
831Finally, the @samp{.nword} translating directive is supported
832as well. It is documented in the section on Sparc machine
833directives.
834
252b5132
RH
835@node Sparc-Float
836@section Floating Point
837
838@cindex floating point, SPARC (@sc{ieee})
839@cindex SPARC floating point (@sc{ieee})
840The Sparc uses @sc{ieee} floating-point numbers.
841
842@node Sparc-Directives
843@section Sparc Machine Directives
844
845@cindex SPARC machine directives
846@cindex machine directives, SPARC
847The Sparc version of @code{@value{AS}} supports the following additional
848machine directives:
849
850@table @code
851@cindex @code{align} directive, SPARC
852@item .align
853This must be followed by the desired alignment in bytes.
854
855@cindex @code{common} directive, SPARC
856@item .common
857This must be followed by a symbol name, a positive number, and
858@code{"bss"}. This behaves somewhat like @code{.comm}, but the
859syntax is different.
860
861@cindex @code{half} directive, SPARC
862@item .half
863This is functionally identical to @code{.short}.
864
e06510e6
RH
865@cindex @code{nword} directive, SPARC
866@item .nword
867On the Sparc, the @code{.nword} directive produces native word sized value,
868ie. if assembling with -32 it is equivalent to @code{.word}, if assembling
869with -64 it is equivalent to @code{.xword}.
870
252b5132
RH
871@cindex @code{proc} directive, SPARC
872@item .proc
873This directive is ignored. Any text following it on the same
874line is also ignored.
875
e06510e6
RH
876@cindex @code{register} directive, SPARC
877@item .register
878This directive declares use of a global application or system register.
879It must be followed by a register name %g2, %g3, %g6 or %g7, comma and
6d8809aa 880the symbol name for that register. If symbol name is @code{#scratch},
062b7c0c 881it is a scratch register, if it is @code{#ignore}, it just suppresses any
6d8809aa
RH
882errors about using undeclared global register, but does not emit any
883information about it into the object file. This can be useful e.g. if you
884save the register before use and restore it after.
e06510e6 885
252b5132
RH
886@cindex @code{reserve} directive, SPARC
887@item .reserve
888This must be followed by a symbol name, a positive number, and
889@code{"bss"}. This behaves somewhat like @code{.lcomm}, but the
890syntax is different.
891
892@cindex @code{seg} directive, SPARC
893@item .seg
894This must be followed by @code{"text"}, @code{"data"}, or
895@code{"data1"}. It behaves like @code{.text}, @code{.data}, or
896@code{.data 1}.
897
898@cindex @code{skip} directive, SPARC
899@item .skip
900This is functionally identical to the @code{.space} directive.
901
902@cindex @code{word} directive, SPARC
903@item .word
904On the Sparc, the @code{.word} directive produces 32 bit values,
905instead of the 16 bit values it produces on many other machines.
906
907@cindex @code{xword} directive, SPARC
908@item .xword
909On the Sparc V9 processor, the @code{.xword} directive produces
91064 bit values.
911@end table
This page took 0.830724 seconds and 4 git commands to generate.