| 1 |
/* This header file defines a set of macros to be used in the construction |
| 2 |
of parameter passing and/or va_arg code gen tests during the |
| 3 |
pre-processing stage. It is included inside abitest.h. |
| 4 |
|
| 5 |
The following macros are defined here: |
| 6 |
|
| 7 |
LAST_ARG |
| 8 |
ARG |
| 9 |
DOTS |
| 10 |
ANON |
| 11 |
LAST_ANON |
| 12 |
PTR |
| 13 |
PTR_ANON |
| 14 |
LAST_ANONPTR |
| 15 |
|
| 16 |
These macros are given different definitions depending on which one of |
| 17 |
the following macros is defined. |
| 18 |
|
| 19 |
AARCH64_MACRO_DEF_CHECK_INCOMING_ARGS |
| 20 |
AARCH64_MACRO_DEF_GEN_PARAM_TYPE_LIST |
| 21 |
AARCH64_MACRO_DEF_GEN_ARGUMENT_LIST |
| 22 |
AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST |
| 23 |
AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST_WITH_IDENT |
| 24 |
AARCH64_VARIADIC_MACRO_DEF_ASSIGN_LOCAL_VARS_WITH_ARGS |
| 25 |
AARCH64_VARIADIC_MACRO_DEF_GEN_ARGUMENT_LIST |
| 26 |
|
| 27 |
Do not define more than one of the above macros. */ |
| 28 |
|
| 29 |
|
| 30 |
/* AARCH64_MACRO_DEF_CHECK_INCOMING_ARGS |
| 31 |
Define macros to check the incoming arguments. */ |
| 32 |
|
| 33 |
#ifdef AARCH64_MACRO_DEF_CHECK_INCOMING_ARGS |
| 34 |
|
| 35 |
#undef LAST_ARG |
| 36 |
#undef ARG |
| 37 |
#undef DOTS |
| 38 |
#undef ANON |
| 39 |
#undef LAST_ANON |
| 40 |
#undef PTR |
| 41 |
#undef PTR_ANON |
| 42 |
#undef LAST_ANONPTR |
| 43 |
#undef ANON_PROMOTED |
| 44 |
|
| 45 |
/* Generate memcmp to check if the incoming args have the expected values. */ |
| 46 |
#define LAST_ARG_NONFLAT(type, val, offset, layout, ...) \ |
| 47 |
{ \ |
| 48 |
type __x = val; \ |
| 49 |
DUMP_ARG(type,val); \ |
| 50 |
if (validate_memory (&__x, stack + offset, sizeof (type), layout) != 0) \ |
| 51 |
abort(); \ |
| 52 |
} |
| 53 |
#define LAST_ARG(type,val,offset,...) LAST_ARG_NONFLAT (type, val, offset, \ |
| 54 |
flat,__VA_ARGS__) |
| 55 |
#define ARG_NONFLAT(type,val,offset,layout,...) LAST_ARG_NONFLAT (type, val, \ |
| 56 |
offset, \ |
| 57 |
layout, \ |
| 58 |
__VA_ARGS__) |
| 59 |
#define ARG(type,val,offset,...) LAST_ARG_NONFLAT(type, val, offset, \ |
| 60 |
flat, __VA_ARGS__) |
| 61 |
#define ANON(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 62 |
#define LAST_ANON(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 63 |
#define ANON_PROMOTED(type,val,type_promoted, val_promoted, offset,...) \ |
| 64 |
ANON(type_promoted, val_promoted, offset, __VA_ARGS__) |
| 65 |
/* Composite larger than 16 bytes is replaced by a pointer to a copy prepared |
| 66 |
by the caller, so here we extract the pointer, deref it and compare the |
| 67 |
content with that of the original one. */ |
| 68 |
#define PTR(type, val, offset, ...) { \ |
| 69 |
type * ptr; \ |
| 70 |
DUMP_ARG(type,val); \ |
| 71 |
ptr = *(type **)(stack + offset); \ |
| 72 |
if (memcmp (ptr, &val, sizeof (type)) != 0) abort (); \ |
| 73 |
} |
| 74 |
#define PTR_ANON(type, val, offset, ...) PTR(type, val, offset, __VA_ARGS__) |
| 75 |
#define LAST_ANONPTR(type, val, offset, ...) PTR(type, val, offset, __VA_ARGS__) |
| 76 |
#define DOTS |
| 77 |
|
| 78 |
#endif /* AARCH64_MACRO_DEF_CHECK_INCOMING_ARGS */ |
| 79 |
|
| 80 |
|
| 81 |
/* AARCH64_MACRO_DEF_GEN_PARAM_TYPE_LIST |
| 82 |
Define macros to generate parameter type list. */ |
| 83 |
|
| 84 |
#ifdef AARCH64_MACRO_DEF_GEN_PARAM_TYPE_LIST |
| 85 |
|
| 86 |
#undef LAST_ARG |
| 87 |
#undef ARG |
| 88 |
#undef DOTS |
| 89 |
#undef ANON |
| 90 |
#undef LAST_ANON |
| 91 |
#undef PTR |
| 92 |
#undef PTR_ANON |
| 93 |
#undef LAST_ANONPTR |
| 94 |
|
| 95 |
/* Generate parameter type list (without identifiers). */ |
| 96 |
#define LAST_ARG(type,val,offset) type |
| 97 |
#define LAST_ARG_NONFLAT(type, val, offset, layout) type |
| 98 |
#define ARG(type,val,offset) LAST_ARG(type, val, offset), |
| 99 |
#define ARG_NONFLAT(type, val, offset, layout) LAST_ARG (type, val, offset), |
| 100 |
#define DOTS ... |
| 101 |
#define ANON(type,val, offset) |
| 102 |
#define LAST_ANON(type,val, offset) |
| 103 |
#define PTR(type, val, offset) LAST_ARG(type, val, offset), |
| 104 |
#define PTR_ANON(type, val, offset) |
| 105 |
#define LAST_ANONPTR(type, val, offset) |
| 106 |
|
| 107 |
#endif /* AARCH64_MACRO_DEF_GEN_PARAM_TYPE_LIST */ |
| 108 |
|
| 109 |
|
| 110 |
/* AARCH64_MACRO_DEF_GEN_ARGUMENT_LIST |
| 111 |
Define macros to generate argument list. */ |
| 112 |
|
| 113 |
#ifdef AARCH64_MACRO_DEF_GEN_ARGUMENT_LIST |
| 114 |
|
| 115 |
#undef LAST_ARG |
| 116 |
#undef ARG |
| 117 |
#undef DOTS |
| 118 |
#undef ANON |
| 119 |
#undef LAST_ANON |
| 120 |
#undef PTR |
| 121 |
#undef PTR_ANON |
| 122 |
#undef LAST_ANONPTR |
| 123 |
#undef ANON_PROMOTED |
| 124 |
|
| 125 |
/* Generate the argument list; use VAL as the argument name. */ |
| 126 |
#define LAST_ARG(type,val,offset,...) val |
| 127 |
#define LAST_ARG_NONFLAT(type,val,offset,layout,...) val |
| 128 |
#define ARG(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 129 |
#define ARG_NONFLAT(type, val, offset, layout,...) LAST_ARG (type, val, \ |
| 130 |
offset, \ |
| 131 |
__VA_ARGS__), |
| 132 |
#define DOTS |
| 133 |
#define LAST_ANON(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 134 |
#define ANON(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 135 |
#define PTR(type, val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 136 |
#define PTR_ANON(type, val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 137 |
#define LAST_ANONPTR(type, val, offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 138 |
#define ANON_PROMOTED(type,val,type_promoted, val_promoted, offset,...) \ |
| 139 |
LAST_ARG(type, val, offset, __VA_ARGS__), |
| 140 |
|
| 141 |
#endif /* AARCH64_MACRO_DEF_GEN_ARGUMENT_LIST */ |
| 142 |
|
| 143 |
|
| 144 |
/* AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST |
| 145 |
Define variadic macros to generate parameter type list. */ |
| 146 |
|
| 147 |
#ifdef AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST |
| 148 |
|
| 149 |
#undef LAST_ARG |
| 150 |
#undef ARG |
| 151 |
#undef DOTS |
| 152 |
#undef ANON |
| 153 |
#undef LAST_ANON |
| 154 |
#undef PTR |
| 155 |
#undef PTR_ANON |
| 156 |
#undef LAST_ANONPTR |
| 157 |
#undef ANON_PROMOTED |
| 158 |
|
| 159 |
/* Generate parameter type list (without identifiers). */ |
| 160 |
#define LAST_ARG(type,val,offset,...) type |
| 161 |
#define LAST_ARG_NONFLAT(type, val, offset, layout, ...) type |
| 162 |
#define ARG(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 163 |
#define ARG_NONFLAT(type, val, offset, layout, ...) LAST_ARG (type, val, \ |
| 164 |
offset, \ |
| 165 |
__VA_ARGS__), |
| 166 |
#define DOTS |
| 167 |
#define ANON(type,val, offset,...) ARG(type,val,offset, __VA_ARGS__) |
| 168 |
#define LAST_ANON(type,val, offset,...) LAST_ARG(type,val, offset, __VA_ARGS__) |
| 169 |
#define PTR(type, val, offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 170 |
#define PTR_ANON(type, val, offset,...) PTR(type, val, offset, __VA_ARGS__) |
| 171 |
#define LAST_ANONPTR(type, val, offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 172 |
#define ANON_PROMOTED(type,val,type_promoted, val_promoted, offset,...) \ |
| 173 |
LAST_ARG(type_promoted, val_promoted, offset, __VA_ARGS__), |
| 174 |
|
| 175 |
#endif /* AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST */ |
| 176 |
|
| 177 |
|
| 178 |
/* AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST_WITH_IDENT |
| 179 |
Define variadic macros to generate parameter type list with |
| 180 |
identifiers. */ |
| 181 |
|
| 182 |
#ifdef AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST_WITH_IDENT |
| 183 |
|
| 184 |
#undef LAST_ARG |
| 185 |
#undef ARG |
| 186 |
#undef DOTS |
| 187 |
#undef ANON |
| 188 |
#undef LAST_ANON |
| 189 |
#undef PTR |
| 190 |
#undef PTR_ANON |
| 191 |
#undef LAST_ANONPTR |
| 192 |
#undef ANON_PROMOTED |
| 193 |
|
| 194 |
/* Generate parameter type list (with identifiers). |
| 195 |
The identifiers are named with prefix _f and suffix of the value of |
| 196 |
__VA_ARGS__. */ |
| 197 |
#define LAST_ARG(type,val,offset,...) type _f##__VA_ARGS__ |
| 198 |
#define LAST_ARG_NONFLAT(type, val, offset, layout, ...) type _f##__VA_ARGS__ |
| 199 |
#define ARG(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 200 |
#define ARG_NONFLAT(type, val, offset, layout, ...) LAST_ARG (type, val, \ |
| 201 |
offset, \ |
| 202 |
__VA_ARGS__), |
| 203 |
#define DOTS ... |
| 204 |
#define ANON(type,val, offset,...) |
| 205 |
#define LAST_ANON(type,val, offset,...) |
| 206 |
#define PTR(type, val, offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 207 |
#define PTR_ANON(type, val, offset,...) |
| 208 |
#define LAST_ANONPTR(type, val, offset,...) |
| 209 |
#define ANON_PROMOTED(type,val,type_promoted, val_promoted, offset,...) |
| 210 |
|
| 211 |
#endif /* AARCH64_VARIADIC_MACRO_DEF_GEN_PARAM_TYPE_LIST_WITH_IDENT */ |
| 212 |
|
| 213 |
|
| 214 |
/* AARCH64_VARIADIC_MACRO_DEF_ASSIGN_LOCAL_VARS_WITH_ARGS |
| 215 |
Define variadic macros to generate assignment from the function |
| 216 |
incoming arguments to local variables. */ |
| 217 |
|
| 218 |
#ifdef AARCH64_VARIADIC_MACRO_DEF_ASSIGN_LOCAL_VARS_WITH_ARGS |
| 219 |
|
| 220 |
#undef LAST_ARG |
| 221 |
#undef ARG |
| 222 |
#undef DOTS |
| 223 |
#undef ANON |
| 224 |
#undef LAST_ANON |
| 225 |
#undef PTR |
| 226 |
#undef PTR_ANON |
| 227 |
#undef LAST_ANONPTR |
| 228 |
#undef ANON_PROMOTED |
| 229 |
|
| 230 |
/* Generate assignment statements. For named args, direct assignment from |
| 231 |
the formal parameter is generated; for unnamed args, va_arg is used. |
| 232 |
The names of the local variables start with _x and end with the value of |
| 233 |
__VA_ARGS__. */ |
| 234 |
#define LAST_ARG(type,val,offset,...) type _x##__VA_ARGS__ = _f##__VA_ARGS__; |
| 235 |
#define LAST_ARG_NONFLAT(type, val, offset, layout, ...) \ |
| 236 |
type _x##__VA_ARGS__ = _f##__VA_ARGS__; |
| 237 |
#define ARG(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 238 |
#define ARG_NONFLAT(type,val,offset,layout,...) \ |
| 239 |
LAST_ARG (type, val, offset, __VA_ARGS__) |
| 240 |
#define ANON(type,val,offset,...) type _x##__VA_ARGS__ = va_arg (ap, type); |
| 241 |
#define LAST_ANON(type,val,offset,...) ANON(type, val, offset, __VA_ARGS__) |
| 242 |
#define PTR(type, val,offset,...) ARG(type, val, offset, __VA_ARGS__) |
| 243 |
#define PTR_ANON(type, val, offset,...) ANON(type, val,offset, __VA_ARGS__) |
| 244 |
#define LAST_ANONPTR(type, val, offset,...) ANON(type, val, offset, __VA_ARGS__) |
| 245 |
#define ANON_PROMOTED(type,val,type_promoted, val_promoted, offset,...) \ |
| 246 |
ANON(type_promoted, val_promoted, offset, __VA_ARGS__) |
| 247 |
|
| 248 |
#define DOTS |
| 249 |
|
| 250 |
#endif /* AARCH64_VARIADIC_MACRO_DEF_ASSIGN_LOCAL_VARS_WITH_ARGS */ |
| 251 |
|
| 252 |
|
| 253 |
/* AARCH64_VARIADIC_MACRO_DEF_GEN_ARGUMENT_LIST |
| 254 |
Define variadic macros to generate argument list using the variables |
| 255 |
generated during AARCH64_VARIADIC_MACRO_DEF_ASSIGN_LOCAL_VARS_WITH_ARGS. */ |
| 256 |
|
| 257 |
#ifdef AARCH64_VARIADIC_MACRO_DEF_GEN_ARGUMENT_LIST |
| 258 |
|
| 259 |
#undef LAST_ARG |
| 260 |
#undef ARG |
| 261 |
#undef DOTS |
| 262 |
#undef ANON |
| 263 |
#undef LAST_ANON |
| 264 |
#undef PTR |
| 265 |
#undef PTR_ANON |
| 266 |
#undef LAST_ANONPTR |
| 267 |
#undef ANON_PROMOTED |
| 268 |
|
| 269 |
/* Generate the argument list; the names start with _x and end with the value of |
| 270 |
__VA_ARGS__. All arguments (named or unnamed) in stdarg_func are passed to |
| 271 |
myfunc as named arguments. */ |
| 272 |
#define LAST_ARG(type,val,offset,...) _x##__VA_ARGS__ |
| 273 |
#define LAST_ARG_NONFLAT(type, val, offset, layout, ...) _x##__VA_ARGS__ |
| 274 |
#define ARG(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 275 |
#define ARG_NONFLAT(type, val, offset, layout, ...) \ |
| 276 |
LAST_ARG_NONFLAT (type, val, offset, layout, __VA_ARGS__), |
| 277 |
#define DOTS |
| 278 |
#define LAST_ANON(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 279 |
#define ANON(type,val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 280 |
#define PTR(type, val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 281 |
#define PTR_ANON(type, val,offset,...) LAST_ARG(type, val, offset, __VA_ARGS__), |
| 282 |
#define LAST_ANONPTR(type, val, offset,...) LAST_ARG(type, val, offset, __VA_ARGS__) |
| 283 |
#define ANON_PROMOTED(type,val,type_promoted, val_promoted, offset,...) \ |
| 284 |
ANON(type_promoted, val_promoted, offset, __VA_ARGS__) |
| 285 |
|
| 286 |
#endif /* AARCH64_VARIADIC_MACRO_DEF_GEN_ARGUMENT_LIST */ |