mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-17 23:54:16 +08:00
Revert "Add support to debug libtcc code" - not fully developed experimental feature This reverts commit1fe3e3bff5. This reverts commit4768b11737. Revert "tests: add test for x86_64 xor REX prefix bug in load()" - AI generated nonsense test This reverts commitd5ecb52a71. Revert "tccpp.c: Improve integer constant overflow warning" - Too long and confusing messages and comments for feature with questionable benefit. This reverts commit085bdf8997. riscv64-link: - cleanup "pair pcrel lo relocations by hi address" Fromfada98b1cetccgen.c: - Simplify "Cast signed pointer offset to ptrdiff_t before performing arithmetic" From5ad52cc1edlibtcc.c: - Revert "tcc options: document behavior and clashes (no-op)" a bit more information than one would like to have I think. (why try to understand that comments plus the extra script if one can as well just read the code itself ;) From234e2dd2bftccdefs.h: - Revert "Move lib/va_list.c into include/tccdefs.h" Lets not fill tccdefs.h with too much inline code Also, -nostdlib -run is no longer supported Fromfa6a6bfbbdarm64-gen.c: - cleanup "Implement TOK_NEG for floats natively" Also, make it "no lvalue" in tccgen.c/x86-64-gen.c Fromc39eaf10cflib/lib-arm64.c: - cleanup "Remove libc dependency from lib-arm64" using unions is much faster than some made up memcpy() From8c61b91de8
68 lines
1.9 KiB
C
68 lines
1.9 KiB
C
/* va_list.c - tinycc support for va_list on X86_64 */
|
|
|
|
#if defined __x86_64__
|
|
|
|
/* 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 */
|
|
enum __va_arg_type {
|
|
__va_gen_reg, __va_float_reg, __va_stack
|
|
};
|
|
|
|
/* GCC compatible definition of va_list. */
|
|
/*predefined by TCC (tcc_predefs.h):
|
|
typedef struct {
|
|
unsigned int gp_offset;
|
|
unsigned int fp_offset;
|
|
union {
|
|
unsigned int overflow_offset;
|
|
char *overflow_arg_area;
|
|
};
|
|
char *reg_save_area;
|
|
} __builtin_va_list[1];
|
|
*/
|
|
|
|
extern void *memcpy(void *dest, const void *src, unsigned long n);
|
|
|
|
void *__va_arg(__builtin_va_list ap,
|
|
int arg_type,
|
|
int size, int align)
|
|
{
|
|
size = (size + 7) & ~7;
|
|
align = (align + 7) & ~7;
|
|
switch ((enum __va_arg_type)arg_type) {
|
|
case __va_gen_reg:
|
|
if (ap->gp_offset + size <= 48) {
|
|
ap->gp_offset += size;
|
|
return ap->reg_save_area + ap->gp_offset - size;
|
|
}
|
|
goto use_overflow_area;
|
|
|
|
case __va_float_reg:
|
|
if (ap->fp_offset < 128 + 48) {
|
|
ap->fp_offset += 16;
|
|
if (size == 8)
|
|
return ap->reg_save_area + ap->fp_offset - 16;
|
|
if (ap->fp_offset < 128 + 48) {
|
|
memcpy(ap->reg_save_area + ap->fp_offset - 8,
|
|
ap->reg_save_area + ap->fp_offset, 8);
|
|
ap->fp_offset += 16;
|
|
return ap->reg_save_area + ap->fp_offset - 32;
|
|
}
|
|
}
|
|
goto use_overflow_area;
|
|
|
|
case __va_stack:
|
|
use_overflow_area:
|
|
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;
|
|
|
|
default: /* should never happen */
|
|
abort();
|
|
return 0;
|
|
}
|
|
}
|
|
#endif
|