va-sh.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* This is just like the default gvarargs.h
  2. except for differences described below. */
  3. /* Define __gnuc_va_list. */
  4. #ifndef __GNUC_VA_LIST
  5. #define __GNUC_VA_LIST
  6. #ifdef __SH3E__
  7. typedef long __va_greg;
  8. typedef double __va_freg;
  9. typedef struct {
  10. __va_greg * __va_next_o; /* next available register */
  11. __va_greg * __va_next_o_limit; /* past last available register */
  12. __va_freg * __va_next_fp; /* next available fp register */
  13. __va_freg * __va_next_fp_limit; /* last available fp register */
  14. __va_greg * __va_next_stack; /* next extended word on stack */
  15. } __gnuc_va_list;
  16. #else /* ! SH3E */
  17. typedef void *__gnuc_va_list;
  18. #endif /* ! SH3E */
  19. #endif /* __GNUC_VA_LIST */
  20. /* If this is for internal libc use, don't define anything but
  21. __gnuc_va_list. */
  22. #if defined (_STDARG_H) || defined (_VARARGS_H)
  23. #ifdef _STDARG_H
  24. #ifdef __SH3E__
  25. #define va_start(AP, LASTARG) \
  26. __extension__ \
  27. ({ \
  28. AP.__va_next_fp = (__va_freg *) __builtin_saveregs (); \
  29. AP.__va_next_fp_limit = (AP.__va_next_fp + \
  30. (__builtin_args_info (1) < 8 ? 8 - __builtin_args_info (1) : 0)); \
  31. AP.__va_next_o = (__va_greg *) AP.__va_next_fp_limit; \
  32. AP.__va_next_o_limit = (AP.__va_next_o + \
  33. (__builtin_args_info (0) < 4 ? 4 - __builtin_args_info (0) : 0)); \
  34. AP.__va_next_stack = (__va_greg *) __builtin_next_arg (LASTARG); \
  35. })
  36. #else /* ! SH3E */
  37. #define va_start(AP, LASTARG) \
  38. do { \
  39. __builtin_saveregs();\
  40. (AP = ((__gnuc_va_list) __builtin_next_arg (LASTARG))); \
  41. } while (0)
  42. #endif /* ! SH3E */
  43. #else /* _VARARGS_H */
  44. #define va_alist __builtin_va_alist
  45. #define va_dcl int __builtin_va_alist;...
  46. #ifdef __SH3E__
  47. #define va_start(AP) \
  48. __extension__ \
  49. ({ \
  50. AP.__va_next_fp = (__va_freg *) __builtin_saveregs (); \
  51. AP.__va_next_fp_limit = (AP.__va_next_fp + \
  52. (__builtin_args_info (1) < 8 ? 8 - __builtin_args_info (1) : 0)); \
  53. AP.__va_next_o = (__va_greg *) AP.__va_next_fp_limit; \
  54. AP.__va_next_o_limit = (AP.__va_next_o + \
  55. (__builtin_args_info (0) < 4 ? 4 - __builtin_args_info (0) : 0)); \
  56. AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
  57. - (__builtin_args_info (0) >= 4 || __builtin_args_info (1) >= 8 ? 1 : 0); \
  58. })
  59. #else /* ! SH3E */
  60. #define va_start(AP) AP=(char *) &__builtin_va_alist
  61. #endif /* ! SH3E */
  62. #endif /* _STDARG */
  63. #ifndef va_end
  64. void va_end (__gnuc_va_list); /* Defined in libgcc.a */
  65. /* Values returned by __builtin_classify_type. */
  66. enum __va_type_classes {
  67. __no_type_class = -1,
  68. __void_type_class,
  69. __integer_type_class,
  70. __char_type_class,
  71. __enumeral_type_class,
  72. __boolean_type_class,
  73. __pointer_type_class,
  74. __reference_type_class,
  75. __offset_type_class,
  76. __real_type_class,
  77. __complex_type_class,
  78. __function_type_class,
  79. __method_type_class,
  80. __record_type_class,
  81. __union_type_class,
  82. __array_type_class,
  83. __string_type_class,
  84. __set_type_class,
  85. __file_type_class,
  86. __lang_type_class
  87. };
  88. #endif
  89. #define va_end(pvar) ((void)0)
  90. #ifdef __LITTLE_ENDIAN__
  91. #define __LITTLE_ENDIAN_P 1
  92. #else
  93. #define __LITTLE_ENDIAN_P 0
  94. #endif
  95. #define __SCALAR_TYPE(TYPE) \
  96. ((TYPE) == __integer_type_class \
  97. || (TYPE) == __char_type_class \
  98. || (TYPE) == __enumeral_type_class)
  99. /* RECORD_TYPE args passed using the C calling convention are
  100. passed by invisible reference. ??? RECORD_TYPE args passed
  101. in the stack are made to be word-aligned; for an aggregate that is
  102. not word-aligned, we advance the pointer to the first non-reg slot. */
  103. /* When this is a smaller-than-int integer, using
  104. auto-increment in the promoted (SImode) is fastest;
  105. however, there is no way to express that is C. Therefore,
  106. we use an asm.
  107. We want the MEM_IN_STRUCT_P bit set in the emitted RTL, therefore we
  108. use unions even when it would otherwise be unnecessary. */
  109. #define __va_arg_sh1(AP, TYPE) __extension__ \
  110. __extension__ \
  111. ({(sizeof (TYPE) == 1 \
  112. ? ({union {TYPE t; char c;} __t; \
  113. __asm("" \
  114. : "=r" (__t.c) \
  115. : "0" ((((union { int i, j; } *) (AP))++)->i)); \
  116. __t.t;}) \
  117. : sizeof (TYPE) == 2 \
  118. ? ({union {TYPE t; short s;} __t; \
  119. __asm("" \
  120. : "=r" (__t.s) \
  121. : "0" ((((union { int i, j; } *) (AP))++)->i)); \
  122. __t.t;}) \
  123. : sizeof (TYPE) >= 4 || __LITTLE_ENDIAN_P \
  124. ? (((union { TYPE t; int i;} *) (AP))++)->t \
  125. : ((union {TYPE t;TYPE u;}*) ((char *)++(int *)(AP) - sizeof (TYPE)))->t);})
  126. #ifdef __SH3E__
  127. #define __PASS_AS_FLOAT(TYPE_CLASS,SIZE) \
  128. (TYPE_CLASS == __real_type_class && SIZE == 4)
  129. #define va_arg(pvar,TYPE) \
  130. __extension__ \
  131. ({int __type = __builtin_classify_type (* (TYPE *) 0); \
  132. void * __result_p; \
  133. if (__PASS_AS_FLOAT (__type, sizeof(TYPE))) \
  134. { \
  135. if (pvar.__va_next_fp < pvar.__va_next_fp_limit) \
  136. { \
  137. __result_p = &pvar.__va_next_fp; \
  138. } \
  139. else \
  140. __result_p = &pvar.__va_next_stack; \
  141. } \
  142. else \
  143. { \
  144. if (pvar.__va_next_o + ((sizeof (TYPE) + 3) / 4) \
  145. <= pvar.__va_next_o_limit) \
  146. __result_p = &pvar.__va_next_o; \
  147. else \
  148. { \
  149. if (sizeof (TYPE) > 4) \
  150. pvar.__va_next_o = pvar.__va_next_o_limit; \
  151. \
  152. __result_p = &pvar.__va_next_stack; \
  153. } \
  154. } \
  155. __va_arg_sh1(*(void **)__result_p, TYPE);})
  156. #else /* ! SH3E */
  157. #define va_arg(AP, TYPE) __va_arg_sh1((AP), TYPE)
  158. #endif /* SH3E */
  159. /* Copy __gnuc_va_list into another variable of this type. */
  160. #define __va_copy(dest, src) (dest) = (src)
  161. #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */