libunwind-ia64.tex 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. \documentclass{article}
  2. \usepackage[fancyhdr,pdf]{latex2man}
  3. \input{common.tex}
  4. \begin{document}
  5. \begin{Name}{3}{libunwind-ia64}{David Mosberger-Tang}{Programming Library}{IA-64-specific support in libunwind}libunwind-ia64 -- IA-64-specific support in libunwind
  6. \end{Name}
  7. \section{Introduction}
  8. The IA-64 version of \Prog{libunwind} uses a platform-string of
  9. \texttt{ia64} and, at least in theory, should be able to support all
  10. operating systems adhering to the processor-specific ABI defined for
  11. the Itanium Processor Family. This includes both little-endian Linux
  12. and big-endian HP-UX. Furthermore, to make it possible for a single
  13. library to unwind both 32- and 64-bit targets, the type
  14. \Type{unw\_word\_t} is always defined to be 64 bits wide (independent
  15. of the natural word-size of the host). Having said that, the current
  16. implementation has been tested only with IA-64 Linux.
  17. When targeting IA-64, the \Prog{libunwind} header file defines the
  18. macro \Const{UNW\_TARGET\_IA64} as 1 and the macro \Const{UNW\_TARGET}
  19. as ``ia64'' (without the quotation marks). The former makes it
  20. possible for platform-dependent unwind code to use
  21. conditional-compilation to select an appropriate implementation. The
  22. latter is useful for stringification purposes and to construct
  23. target-platform-specific symbols.
  24. One special feature of IA-64 is the use of NaT bits to support
  25. speculative execution. Often, NaT bits are thought of as the ``65-th
  26. bit'' of a general register. However, to make everything fit into
  27. 64-bit wide \Type{unw\_word\_t} values, \Prog{libunwind} treats the
  28. NaT-bits like separate boolean registers, whose 64-bit value is either
  29. TRUE (non-zero) or FALSE (zero).
  30. \section{Machine-State}
  31. The machine-state (set of registers) that is accessible through
  32. \Prog{libunwind} depends on the type of stack frame that a cursor
  33. points to. For normal frames, all ``preserved'' (callee-saved)
  34. registers are accessible. For signal-trampoline frames, all registers
  35. (including ``scratch'' (caller-saved) registers) are accessible. Most
  36. applications do not have to worry a-priori about which registers are
  37. accessible when. In case of doubt, it is always safe to \emph{try} to
  38. access a register (via \Func{unw\_get\_reg}() or
  39. \Func{unw\_get\_fpreg}()) and if the register isn't accessible, the
  40. call will fail with a return-value of \texttt{-}\Const{UNW\_EBADREG}.
  41. As a special exception to the above general rule, scratch registers
  42. \texttt{r15}-\texttt{r18} are always accessible, even in normal
  43. frames. This makes it possible to pass arguments, e.g., to exception
  44. handlers.
  45. For a detailed description of the IA-64 register usage convention,
  46. please see the ``Itanium Software Conventions and Runtime Architecture
  47. Guide'', available at:
  48. \begin{center}
  49. \URL{http://www.intel.com/design/itanium/downloads/245358.htm}
  50. \end{center}
  51. \section{Register Names}
  52. The IA-64-version of \Prog{libunwind} defines three kinds of register
  53. name macros: frame-register macros, normal register macros, and
  54. convenience macros. Below, we describe each kind in turn:
  55. \subsection{Frame-register Macros}
  56. Frame-registers are special (pseudo) registers because they always
  57. have a valid value, even though sometimes they do not get saved
  58. explicitly (e.g., if a memory stack frame is 16 bytes in size, the
  59. previous stack-pointer value can be calculated simply as
  60. \texttt{sp+16}, so there is no need to save the stack-pointer
  61. explicitly). Moreover, the set of frame register values uniquely
  62. identifies a stack frame. The IA-64 architecture defines two stacks
  63. (a memory and a register stack). Including the instruction-pointer
  64. (IP), this means there are three frame registers:
  65. \begin{Description}
  66. \item[\Const{UNW\_IA64\_IP}:] Contains the instruction pointer (IP, or
  67. ``program counter'') of the current stack frame. Given this value,
  68. the remaining machine-state corresponds to the register-values that
  69. were present in the CPU when it was just about to execute the
  70. instruction pointed to by \Const{UNW\_IA64\_IP}. Bits 0 and 1 of
  71. this frame-register encode the slot number of the instruction.
  72. \textbf{Note:} Due to the way the call instruction works on IA-64,
  73. the slot number is usually zero, but can be non-zero, e.g., in the
  74. stack-frame of a signal-handler trampoline.
  75. \item[\Const{UNW\_IA64\_SP}:] Contains the (memory) stack-pointer
  76. value (SP).
  77. \item[\Const{UNW\_IA64\_BSP}:] Contains the register backing-store
  78. pointer (BSP). \textbf{Note:} the value in this register is equal
  79. to the contents of register \texttt{ar.bsp} at the time the
  80. instruction at \Const{UNW\_IA64\_IP} was about to begin execution.
  81. \end{Description}
  82. \subsection{Normal Register Macros}
  83. The following normal register name macros are available:
  84. \begin{Description}
  85. \item[\Const{UNW\_IA64\_GR}:] The base-index for general (integer)
  86. registers. Add an index in the range from 0..127 to get a
  87. particular general register. For example, to access \texttt{r4},
  88. the index \Const{UNW\_IA64\_GR}\texttt{+4} should be used.
  89. Registers \texttt{r0} and \texttt{r1} (\texttt{gp}) are read-only,
  90. and any attempt to write them will result in an error
  91. (\texttt{-}\Const{UNW\_EREADONLYREG}). Even though \texttt{r1} is
  92. read-only, \Prog{libunwind} will automatically adjust its value if
  93. the instruction-pointer (\Const{UNW\_IA64\_IP}) is modified. For
  94. example, if \Const{UNW\_IA64\_IP} is set to a value inside a
  95. function \Func{func}(), then reading
  96. \Const{UNW\_IA64\_GR}\texttt{+1} will return the global-pointer
  97. value for this function.
  98. \item[\Const{UNW\_IA64\_NAT}:] The base-index for the NaT bits of the
  99. general (integer) registers. A non-zero value in these registers
  100. corresponds to a set NaT-bit. Add an index in the range from 0..127
  101. to get a particular NaT-bit register. For example, to access the
  102. NaT bit of \texttt{r4}, the index \Const{UNW\_IA64\_NAT}\texttt{+4}
  103. should be used.
  104. \item[\Const{UNW\_IA64\_FR}:] The base-index for floating-point
  105. registers. Add an index in the range from 0..127 to get a
  106. particular floating-point register. For example, to access
  107. \texttt{f2}, the index \Const{UNW\_IA64\_FR}\texttt{+2} should be
  108. used. Registers \texttt{f0} and \texttt{f1} are read-only, and any
  109. attempt to write to indices \Const{UNW\_IA64\_FR}\texttt{+0} or
  110. \Const{UNW\_IA64\_FR}\texttt{+1} will result in an error
  111. (\texttt{-}\Const{UNW\_EREADONLYREG}).
  112. \item[\Const{UNW\_IA64\_AR}:] The base-index for application
  113. registers. Add an index in the range from 0..127 to get a
  114. particular application register. For example, to access
  115. \texttt{ar40}, the index \Const{UNW\_IA64\_AR}\texttt{+40} should be
  116. used. The IA-64 architecture defines several application registers
  117. as ``reserved for future use''. Attempting to access such registers
  118. results in an error (\texttt{-}\Const{UNW\_EBADREG}).
  119. \item[\Const{UNW\_IA64\_BR}:] The base-index for branch registers.
  120. Add an index in the range from 0..7 to get a particular branch
  121. register. For example, to access \texttt{b6}, the index
  122. \Const{UNW\_IA64\_BR}\texttt{+6} should be used.
  123. \item[\Const{UNW\_IA64\_PR}:] Contains the set of predicate registers.
  124. This 64-bit wide register contains registers \texttt{p0} through
  125. \texttt{p63} in the ``broad-side'' format. Just like with the
  126. ``move predicates'' instruction, the registers are mapped as if
  127. \texttt{CFM.rrb.pr} were set to 0. Thus, in general the value of
  128. predicate register \texttt{p}$N$ with $N$>=16 can be found
  129. in bit \texttt{16 + (($N$-16)+CFM.rrb.pr) \% 48}.
  130. \item[\Const{UNW\_IA64\_CFM}:] Contains the current-frame-mask
  131. register.
  132. \end{Description}
  133. \subsection{Convenience Macros}
  134. Convenience macros are simply aliases for certain frequently used
  135. registers:
  136. \begin{Description}
  137. \item[\Const{UNW\_IA64\_GP}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+1},
  138. the global-pointer register.
  139. \item[\Const{UNW\_IA64\_TP}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+13},
  140. the thread-pointer register.
  141. \item[\Const{UNW\_IA64\_AR\_RSC}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+16},
  142. the register-stack configuration register.
  143. \item[\Const{UNW\_IA64\_AR\_BSP}:] Alias for
  144. \Const{UNW\_IA64\_GR}\texttt{+17}. This register index accesses the
  145. value of register \texttt{ar.bsp} as of the time it was last saved
  146. explicitly. This is rarely what you want. Normally, you'll want to
  147. use \Const{UNW\_IA64\_BSP} instead.
  148. \item[\Const{UNW\_IA64\_AR\_BSPSTORE}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+18},
  149. the register-backing store write pointer.
  150. \item[\Const{UNW\_IA64\_AR\_RNAT}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+19},
  151. the register-backing store NaT-collection register.
  152. \item[\Const{UNW\_IA64\_AR\_CCV}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+32},
  153. the compare-and-swap value register.
  154. \item[\Const{UNW\_IA64\_AR\_CSD}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+25},
  155. the compare-and-swap-data register (used by 16-byte atomic operations).
  156. \item[\Const{UNW\_IA64\_AR\_UNAT}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+36},
  157. the user NaT-collection register.
  158. \item[\Const{UNW\_IA64\_AR\_FPSR}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+40},
  159. the floating-point status (and control) register.
  160. \item[\Const{UNW\_IA64\_AR\_PFS}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+64},
  161. the previous frame-state register.
  162. \item[\Const{UNW\_IA64\_AR\_LC}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+65}
  163. the loop-count register.
  164. \item[\Const{UNW\_IA64\_AR\_EC}:] Alias for \Const{UNW\_IA64\_GR}\texttt{+66},
  165. the epilogue-count register.
  166. \end{Description}
  167. \section{The Unwind-Context Type}
  168. On IA-64, \Type{unw\_context\_t} is simply an alias for
  169. \Type{ucontext\_t} (as defined by the Single UNIX Spec). This implies
  170. that it is possible to initialize a value of this type not just with
  171. \Func{unw\_getcontext}(), but also with \Func{getcontext}(), for
  172. example. However, since this is an IA-64-specific extension to
  173. \Prog{libunwind}, portable code should not rely on this equivalence.
  174. \section{See Also}
  175. \SeeAlso{libunwind(3)}
  176. \section{Author}
  177. \noindent
  178. David Mosberger-Tang\\
  179. Email: \Email{dmosberger@gmail.com}\\
  180. WWW: \URL{http://www.nongnu.org/libunwind/}.
  181. \LatexManEnd
  182. \end{document}