dyngen-exec.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * dyngen defines for micro operation code
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
  19. */
  20. #if !defined(__DYNGEN_EXEC_H__)
  21. #define __DYNGEN_EXEC_H__
  22. /* prevent Solaris from trying to typedef FILE in gcc's
  23. include/floatingpoint.h which will conflict with the
  24. definition down below */
  25. #ifdef __sun__
  26. #define _FILEDEFED
  27. #endif
  28. /* NOTE: standard headers should be used with special care at this
  29. point because host CPU registers are used as global variables. Some
  30. host headers do not allow that. */
  31. #include <stddef.h>
  32. #ifdef __OpenBSD__
  33. #include <sys/types.h>
  34. #else
  35. typedef unsigned char uint8_t;
  36. typedef unsigned short uint16_t;
  37. typedef unsigned int uint32_t;
  38. // Linux/Sparc64 defines uint64_t
  39. #if !(defined (__sparc_v9__) && defined(__linux__)) && !(defined(__APPLE__) && defined(__x86_64__))
  40. /* XXX may be done for all 64 bits targets ? */
  41. #if defined (__x86_64__) || defined(__ia64) || defined(__s390x__) || defined(__alpha__) || defined(_ARCH_PPC64)
  42. typedef unsigned long uint64_t;
  43. #else
  44. typedef unsigned long long uint64_t;
  45. #endif
  46. #endif
  47. /* if Solaris/__sun__, don't typedef int8_t, as it will be typedef'd
  48. prior to this and will cause an error in compliation, conflicting
  49. with /usr/include/sys/int_types.h, line 75 */
  50. #ifndef __sun__
  51. typedef signed char int8_t;
  52. #endif
  53. typedef signed short int16_t;
  54. typedef signed int int32_t;
  55. // Linux/Sparc64 defines int64_t
  56. #if !(defined (__sparc_v9__) && defined(__linux__)) && !(defined(__APPLE__) && defined(__x86_64__))
  57. #if defined (__x86_64__) || defined(__ia64) || defined(__s390x__) || defined(__alpha__) || defined(_ARCH_PPC64)
  58. typedef signed long int64_t;
  59. #else
  60. typedef signed long long int64_t;
  61. #endif
  62. #endif
  63. #endif
  64. /* XXX: This may be wrong for 64-bit ILP32 hosts. */
  65. typedef void * host_reg_t;
  66. #define INT8_MIN (-128)
  67. #define INT16_MIN (-32767-1)
  68. #define INT32_MIN (-2147483647-1)
  69. #define INT64_MIN (-(int64_t)(9223372036854775807)-1)
  70. #define INT8_MAX (127)
  71. #define INT16_MAX (32767)
  72. #define INT32_MAX (2147483647)
  73. #define INT64_MAX ((int64_t)(9223372036854775807))
  74. #define UINT8_MAX (255)
  75. #define UINT16_MAX (65535)
  76. #define UINT32_MAX (4294967295U)
  77. #define UINT64_MAX ((uint64_t)(18446744073709551615))
  78. #ifdef _BSD
  79. typedef struct __sFILE FILE;
  80. #else
  81. typedef struct FILE FILE;
  82. #endif
  83. extern int fprintf(FILE *, const char *, ...);
  84. extern int fputs(const char *, FILE *);
  85. extern int printf(const char *, ...);
  86. #undef NULL
  87. #define NULL 0
  88. #if defined(__i386__)
  89. #define AREG0 "ebp"
  90. #define AREG1 "ebx"
  91. #define AREG2 "esi"
  92. #define AREG3 "edi"
  93. #elif defined(__x86_64__)
  94. #define AREG0 "r14"
  95. #define AREG1 "r15"
  96. #define AREG2 "r12"
  97. #define AREG3 "r13"
  98. //#define AREG4 "rbp"
  99. //#define AREG5 "rbx"
  100. #elif defined(_ARCH_PPC)
  101. #define AREG0 "r27"
  102. #define AREG1 "r24"
  103. #define AREG2 "r25"
  104. #define AREG3 "r26"
  105. /* XXX: suppress this hack */
  106. #if defined(CONFIG_USER_ONLY)
  107. #define AREG4 "r16"
  108. #define AREG5 "r17"
  109. #define AREG6 "r18"
  110. #define AREG7 "r19"
  111. #define AREG8 "r20"
  112. #define AREG9 "r21"
  113. #define AREG10 "r22"
  114. #define AREG11 "r23"
  115. #endif
  116. #elif defined(__arm__)
  117. #define AREG0 "r7"
  118. #define AREG1 "r4"
  119. #define AREG2 "r5"
  120. #define AREG3 "r6"
  121. #elif defined(__hppa__)
  122. #define AREG0 "r17"
  123. #define AREG1 "r14"
  124. #define AREG2 "r15"
  125. #define AREG3 "r16"
  126. #elif defined(__mips__)
  127. #define AREG0 "fp"
  128. #define AREG1 "s0"
  129. #define AREG2 "s1"
  130. #define AREG3 "s2"
  131. #define AREG4 "s3"
  132. #define AREG5 "s4"
  133. #define AREG6 "s5"
  134. #define AREG7 "s6"
  135. #define AREG8 "s7"
  136. #elif defined(__sparc__)
  137. #ifdef HOST_SOLARIS
  138. #define AREG0 "g2"
  139. #define AREG1 "g3"
  140. #define AREG2 "g4"
  141. #define AREG3 "g5"
  142. #define AREG4 "g6"
  143. #else
  144. #ifdef __sparc_v9__
  145. #define AREG0 "g5"
  146. #define AREG1 "g6"
  147. #define AREG2 "g7"
  148. #else
  149. #define AREG0 "g6"
  150. #define AREG1 "g1"
  151. #define AREG2 "g2"
  152. #define AREG3 "g3"
  153. #define AREG4 "l0"
  154. #define AREG5 "l1"
  155. #define AREG6 "l2"
  156. #define AREG7 "l3"
  157. #define AREG8 "l4"
  158. #define AREG9 "l5"
  159. #define AREG10 "l6"
  160. #define AREG11 "l7"
  161. #endif
  162. #endif
  163. #elif defined(__s390__)
  164. #define AREG0 "r10"
  165. #define AREG1 "r7"
  166. #define AREG2 "r8"
  167. #define AREG3 "r9"
  168. #elif defined(__alpha__)
  169. /* Note $15 is the frame pointer, so anything in op-i386.c that would
  170. require a frame pointer, like alloca, would probably loose. */
  171. #define AREG0 "$15"
  172. #define AREG1 "$9"
  173. #define AREG2 "$10"
  174. #define AREG3 "$11"
  175. #define AREG4 "$12"
  176. #define AREG5 "$13"
  177. #define AREG6 "$14"
  178. #elif defined(__mc68000)
  179. #define AREG0 "%a5"
  180. #define AREG1 "%a4"
  181. #define AREG2 "%d7"
  182. #define AREG3 "%d6"
  183. #define AREG4 "%d5"
  184. #elif defined(__ia64__)
  185. #define AREG0 "r7"
  186. #define AREG1 "r4"
  187. #define AREG2 "r5"
  188. #define AREG3 "r6"
  189. #else
  190. #error unsupported CPU
  191. #endif
  192. #define xglue(x, y) x ## y
  193. #define glue(x, y) xglue(x, y)
  194. #define stringify(s) tostring(s)
  195. #define tostring(s) #s
  196. /* The return address may point to the start of the next instruction.
  197. Subtracting one gets us the call instruction itself. */
  198. #if defined(__s390__)
  199. # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0) & 0x7fffffffUL) - 1))
  200. #elif defined(__arm__)
  201. /* Thumb return addresses have the low bit set, so we need to subtract two.
  202. This is still safe in ARM mode because instructions are 4 bytes. */
  203. # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 2))
  204. #else
  205. # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 1))
  206. #endif
  207. #endif /* !defined(__DYNGEN_EXEC_H__) */