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