abi 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. IQ2000 ABI
  2. =========
  3. Sizes and alignments
  4. --------------------
  5. Type Size (bytes) Alignment (bytes)
  6. char 1 1
  7. short 2 2
  8. int 4 4
  9. unsigned 4 4
  10. long 4 4
  11. long long 8 8
  12. float 4 4
  13. double 8 8
  14. pointers 4 4
  15. * alignment within aggregates (structs and unions) is as above, with
  16. padding added if needed
  17. * aggregates have alignment equal to that of their most aligned
  18. member
  19. * aggregates have sizes which are a multiple of their alignment
  20. Floating point
  21. --------------
  22. All emulated using IEEE floating point conventions.
  23. Registers
  24. ----------------
  25. %0 always zero
  26. %1 call clobbered
  27. %2 return value
  28. %3 return value
  29. %4 argument register 1
  30. %5 argument register 2
  31. %6 argument register 3
  32. %7 argument register 4
  33. %8 argument register 5
  34. %9 argument register 6
  35. %10 argument register 7
  36. %11 argument register 8
  37. %12 call clobbered
  38. %13 call clobbered
  39. %14 call clobbered
  40. %15 call clobbered
  41. %16 call saved
  42. %17 call saved
  43. %18 call saved
  44. %19 call saved
  45. %20 call saved
  46. %21 call saved
  47. %22 call saved
  48. %23 call saved
  49. %24 call clobbered
  50. %25 call clobbered
  51. %26 reserved
  52. %27 frame ptr
  53. %28 global ptr
  54. %29 stack ptr
  55. %30 reserved
  56. %31 return address
  57. Stack alignment 8 bytes
  58. Structures passed <= 32 bits as values, else as pointers
  59. The IQ2000 Stack
  60. ---------------
  61. Space is allocated as needed in the stack frame for the following at compile
  62. time:
  63. * Outgoing parameters beyond the eighth
  64. * All automatic arrays, automatic data aggregates, automatic
  65. scalars which must be addressable, and automatic scalars for
  66. which there is no room in registers
  67. * Compiler-generated temporary values (typically when there are
  68. too many for the compiler to keep them all in registers)
  69. Space can be allocated dynamically (at runtime) in the stack frame for the
  70. following:
  71. * Memory allocated using the alloca() function of the C library
  72. Addressable automatic variables on the stack are addressed with positive
  73. offsets relative to %27; dynamically allocated space is addressed with positive
  74. offsets from the pointer returned by alloca().
  75. Stack Frame
  76. -----------
  77. +-----------------------+
  78. | Caller memory args |
  79. +-----------------------+ <-sp
  80. | Return address |
  81. +-----------------------+
  82. | Previous FP |
  83. +-----------------------+
  84. | Saved Registers |
  85. +-----------------------+
  86. | ... |
  87. +-----------------------+
  88. | Local Variables |
  89. +-----------------------+ <-fp
  90. | Alloca |
  91. +-----------------------+
  92. | ... |
  93. +-----------------------+
  94. | Parameter Word 2 |
  95. +-----------------------+
  96. | Parameter Word 1 |
  97. +-----------------------+ <-sp
  98. Parameter Assignment to Registers
  99. ---------------------------------
  100. Consider the parameters in a function call as ordered from left (first
  101. parameter) to right. GR contains the number of the next available
  102. general-purpose register. STARG is the address of the next available stack
  103. parameter word.
  104. INITIALIZE:
  105. Set GR=r4 and STARG to point to parameter word 1.
  106. SCAN:
  107. If there are no more parameters, terminate.
  108. Otherwise, select one of the following depending on the type
  109. of the next parameter:
  110. SIMPLE ARG:
  111. A SIMPLE ARG is one of the following:
  112. * One of the simple integer types which will fit into a
  113. general-purpose register,
  114. * A pointer to an object of any type,
  115. * A struct or union small enough to fit in a register (<= 32 bits)
  116. * A larger struct or union, which shall be treated as a
  117. pointer to the object or to a copy of the object.
  118. (See below for when copies are made.)
  119. If GR > r11, go to STACK. Otherwise, load the parameter value into
  120. general-purpose register GR and advance GR to the next general-purpose
  121. register. Values shorter than the register size are sign-extended or
  122. zero-extended depending on whether they are signed or unsigned. Then
  123. go to SCAN.
  124. DOUBLE or LONG LONG
  125. If GR > r10, go to STACK. Otherwise, if GR is odd, advance GR to the
  126. next register. Load the 64-bit long long or double value into register
  127. pair GR and GR+1. Advance GR to GR+2 and go to SCAN.
  128. STACK:
  129. Parameters not otherwise handled above are passed in the parameter
  130. words of the caller's stack frame. SIMPLE ARGs, as defined above, are
  131. considered to have size and alignment equal to the size of a
  132. general-purpose register, with simple argument types shorter than this
  133. sign- or zero-extended to this width. Round STARG up to a multiple of
  134. the alignment requirement of the parameter and copy the argument
  135. byte-for-byte into STARG, STARG+1, ... STARG+size-1. Set STARG to
  136. STARG+size and go to SCAN.
  137. Structure passing
  138. -----------------
  139. As noted above, code which passes structures and unions by value is implemented
  140. specially. (In this section, "struct" will refer to structs and unions
  141. inclusively.) Structs small enough to fit in a register are passed by value in
  142. a single register or in a stack frame slot the size of a register. Structs
  143. containing a single double or long long component are passed by value in two
  144. registers or in a stack frame slot the size of two registers. Other structs
  145. are handled by passing the address of the structure. In this case, a copy of
  146. the structure will be made if necessary in order to preserve the pass-by-value
  147. semantics.
  148. Copies of large structs are made under the following rules:
  149. ANSI mode K&R Mode
  150. --------- --------
  151. Normal param Callee copies if needed Caller copies
  152. Varargs (...) param Caller copies Caller copies
  153. In the case of normal (non-varargs) large-struct parameters in ANSI mode, the
  154. callee is responsible for producing the same effect as if a copy of the
  155. structure were passed, preserving the pass-by-value semantics. This may be
  156. accomplished by having the callee make a copy, but in some cases the callee may
  157. be able to determine that a copy is not necessary in order to produce the same
  158. results. In such cases, the callee may choose to avoid making a copy of the
  159. parameter.
  160. Varargs handling
  161. ----------------
  162. No special changes are needed for handling varargs parameters other than the
  163. caller knowing that a copy is needed on struct parameters larger than a
  164. register (see above).
  165. The varargs macros set up a register save area for the general-purpose
  166. registers to be saved. Because the save area lies between the caller and
  167. callee stack frames, the saved register parameters are contiguous with
  168. parameters passed on the stack. A pointer advances from the register save area
  169. into the caller's stack frame.
  170. Function return values
  171. ----------------------
  172. Type Register
  173. ---- --------
  174. int r2
  175. short r2
  176. long r2
  177. long long r2-r3
  178. float r2
  179. double r2-r3
  180. struct/union see below
  181. Structs/unions which will fit into two general-purpose registers are returned
  182. in r2, or in r2-r3 if necessary. Larger structs/unions are handled by the
  183. caller passing as a "hidden" first argument a pointer to space allocated to
  184. receive the return value.
  185. Copyright (C) 2003-2015 Free Software Foundation, Inc.
  186. Copying and distribution of this file, with or without modification,
  187. are permitted in any medium without royalty provided the copyright
  188. notice and this notice are preserved.