2017-05-07 13:41:29 +03:00
|
|
|
/* va_list.c - tinycc support for va_list on X86_64 */
|
|
|
|
|
2017-07-23 22:24:11 +03:00
|
|
|
#if defined __x86_64__
|
2017-05-07 13:41:29 +03:00
|
|
|
|
|
|
|
/* Avoid include files, they may not be available when cross compiling */
|
|
|
|
extern void abort(void);
|
|
|
|
|
|
|
|
/* This should be in sync with our include/stdarg.h */
|
2020-04-15 05:13:05 +03:00
|
|
|
enum __va_arg_type {
|
|
|
|
__va_gen_reg, __va_float_reg, __va_stack
|
|
|
|
};
|
2017-05-07 13:41:29 +03:00
|
|
|
|
|
|
|
/* GCC compatible definition of va_list. */
|
2017-12-25 23:32:27 +03:00
|
|
|
/*predefined by TCC (tcc_predefs.h):
|
2017-05-07 13:41:29 +03:00
|
|
|
typedef struct {
|
|
|
|
unsigned int gp_offset;
|
|
|
|
unsigned int fp_offset;
|
|
|
|
union {
|
|
|
|
unsigned int overflow_offset;
|
|
|
|
char *overflow_arg_area;
|
|
|
|
};
|
|
|
|
char *reg_save_area;
|
2017-12-25 23:32:27 +03:00
|
|
|
} __builtin_va_list[1];
|
|
|
|
*/
|
2017-05-07 13:41:29 +03:00
|
|
|
|
2017-12-25 23:32:27 +03:00
|
|
|
void *__va_arg(__builtin_va_list ap,
|
2020-04-12 01:39:47 +03:00
|
|
|
int arg_type,
|
2017-05-07 13:41:29 +03:00
|
|
|
int size, int align)
|
|
|
|
{
|
|
|
|
size = (size + 7) & ~7;
|
|
|
|
align = (align + 7) & ~7;
|
2017-12-25 23:32:27 +03:00
|
|
|
switch ((enum __va_arg_type)arg_type) {
|
2020-04-15 05:13:05 +03:00
|
|
|
case __va_gen_reg:
|
|
|
|
if (ap->gp_offset + size <= 48) {
|
|
|
|
ap->gp_offset += size;
|
|
|
|
return ap->reg_save_area + ap->gp_offset - size;
|
2017-05-07 13:41:29 +03:00
|
|
|
}
|
|
|
|
goto use_overflow_area;
|
|
|
|
|
2020-04-15 05:13:05 +03:00
|
|
|
case __va_float_reg:
|
|
|
|
if (ap->fp_offset < 128 + 48) {
|
|
|
|
ap->fp_offset += 16;
|
|
|
|
return ap->reg_save_area + ap->fp_offset - 16;
|
2017-05-07 13:41:29 +03:00
|
|
|
}
|
|
|
|
size = 8;
|
|
|
|
goto use_overflow_area;
|
|
|
|
|
2020-04-15 05:13:05 +03:00
|
|
|
case __va_stack:
|
2017-05-07 13:41:29 +03:00
|
|
|
use_overflow_area:
|
2020-04-15 05:13:05 +03:00
|
|
|
ap->overflow_arg_area += size;
|
|
|
|
ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align);
|
|
|
|
return ap->overflow_arg_area - size;
|
2017-05-07 13:41:29 +03:00
|
|
|
|
2020-04-15 05:13:05 +03:00
|
|
|
default: /* should never happen */
|
2017-05-07 13:41:29 +03:00
|
|
|
abort();
|
2019-04-29 14:53:07 +03:00
|
|
|
return 0;
|
2017-05-07 13:41:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|