c-sparc.texi 28 KB

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