From 12f4afcba28931ea6f367e11abc2f27ba68ee7f9 Mon Sep 17 00:00:00 2001 From: Leslie Zhai Date: Thu, 14 Nov 2024 23:01:36 +0800 Subject: [LA64] Implement convert x64_va_list_t to sysv_varargs for float (#2025) (#2031) * [LA64] Implement convert x64_va_list_t to sysv_varargs for float (#2025) * [LA64] Implement myStackAlignGVariantNew (#2025) * [LA64] Limit the log to LOG_DEBUG (#2055) * [LA64] Add missing file (#2025) --- src/libtools/myalign.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/libtools') diff --git a/src/libtools/myalign.c b/src/libtools/myalign.c index d60070bd..796795c0 100644 --- a/src/libtools/myalign.c +++ b/src/libtools/myalign.c @@ -1139,6 +1139,66 @@ void myStackAlignScanfWValist(x64emu_t* emu, const char* fmt, uint64_t* mystack, } } +void myStackAlignGVariantNew(x64emu_t* emu, const char* fmt, uint64_t* scratch, x64_va_list_t* b) +{ + uintptr_t* p = (uintptr_t*)(emu->scratch); + uintptr_t* p2 = (uintptr_t*)scratch; + int n = (X64_VA_MAX_REG - (*b)->gp_offset)/8; + int m = (X64_VA_MAX_XMM - (*b)->fp_offset)/8; + if(n) memcpy(&p[0], (*b)->reg_save_area+X64_VA_MAX_REG-n*8, n*8+m*16); + memcpy(&p[n+m], (*b)->overflow_arg_area, 20*8); + if (box64_log == LOG_DEBUG) { + printf_log(LOG_DEBUG, "%s\n", __FUNCTION__); + for (int i = 0; i < n+m+20; i++) { + printf_log(LOG_DEBUG, "p%d: 0x%lx\n", i, p[i]); + } + } + int idx = 0; + int gr_offs = 0; // offset in the reg_save_area + int fr_offs = 0; + int oa_gr_offs = 0; // offset in the overflow_arg_area + int oa_fr_offs = 0; + const char* pfmt = fmt; + while (*pfmt) { + switch (*pfmt) { + case 'd': + // double + if (fr_offs > m-2) { + p2[idx] = p[n+m+oa_fr_offs]; + oa_gr_offs++; + oa_fr_offs++; + } else { + p2[idx] = p[n+fr_offs]; + fr_offs+=2; + } + idx++; + break; + case 'b': + case 'y': + case 'n': + case 'q': + case 'i': + case 'h': + case 'u': + case 'x': + case 't': + if (gr_offs > n-1) { + p2[idx] = p[n+m+oa_gr_offs]; + oa_gr_offs++; + oa_fr_offs++; + } else { + p2[idx] = p[gr_offs]; + gr_offs++; + } + idx++; + break; + default: + break; + } + pfmt++; + } +} + #endif #define MUTEX_SIZE_X64 40 -- cgit 1.4.1