mirror of
https://github.com/ptitSeb/box64.git
synced 2024-11-27 00:30:32 +00:00
Attempts at conversion of va_list
This commit is contained in:
parent
23eef578f7
commit
62c22e55e7
@ -321,6 +321,11 @@ add_test(test13 ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX64}
|
||||
# -D TEST_REFERENCE=${CMAKE_SOURCE_DIR}/tests/ref14.txt
|
||||
# -P ${CMAKE_SOURCE_DIR}/runTest.cmake )
|
||||
|
||||
add_test(test15 ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX64}
|
||||
-D TEST_ARGS=${CMAKE_SOURCE_DIR}/tests/test15 -D TEST_OUTPUT=tmpfile.txt
|
||||
-D TEST_REFERENCE=${CMAKE_SOURCE_DIR}/tests/ref15.txt
|
||||
-P ${CMAKE_SOURCE_DIR}/runTest.cmake )
|
||||
|
||||
file(GLOB extension_tests "${CMAKE_SOURCE_DIR}/tests/extensions/*.c")
|
||||
foreach(file ${extension_tests})
|
||||
get_filename_component(testname "${file}" NAME_WE)
|
||||
|
@ -1,5 +1,15 @@
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct x64_va_list_s {
|
||||
unsigned int gp_offset;
|
||||
unsigned int fp_offset;
|
||||
void *overflow_arg_area;
|
||||
void *reg_save_area;
|
||||
} x64_va_list_t[1];
|
||||
|
||||
#define X64_VA_MAX_REG (6*8)
|
||||
#define X64_VA_MAX_XMM ((6*8)+(8*16))
|
||||
|
||||
#ifdef __x86_64__
|
||||
// x86_64, 6 64bits general regs and 16 or 8? 128bits float regs
|
||||
/*
|
||||
@ -13,10 +23,19 @@ typedef struct {
|
||||
*/
|
||||
#define CREATE_SYSV_VALIST(A) \
|
||||
va_list sysv_varargs; \
|
||||
sysv_varargs->gp_offset=(6*8); \
|
||||
sysv_varargs->fp_offset=(6*8)+(16*16); \
|
||||
sysv_varargs->gp_offset=X64_VA_MAX_REG; \
|
||||
sysv_varargs->fp_offset=X64_VA_MAX_XMM; \
|
||||
sysv_varargs->reg_save_area=A; \
|
||||
sysv_varargs->overflow_arg_area=A;
|
||||
|
||||
#define CONVERT_VALIST(A) \
|
||||
va_list sysv_varargs; \
|
||||
sysv_varargs->gp_offset=A->gp_offset; \
|
||||
sysv_varargs->fp_offset=A->fp_offset; \
|
||||
sysv_varargs->reg_save_area=A->reg_save_area; \
|
||||
sysv_varargs->overflow_arg_area=A->overflow_arg_area;
|
||||
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
// aarch64: 8 64bits general regs and 8 128bits float regs
|
||||
/*
|
||||
@ -34,6 +53,15 @@ typedef struct va_list {
|
||||
sysv_varargs.__gr_offs=(8*8); \
|
||||
sysv_varargs.__vr_offs=(8*16); \
|
||||
sysv_varargs.__stack=A;
|
||||
|
||||
#define CONVERT_VALIST(A) \
|
||||
va_list sysv_varargs; \
|
||||
sysv_varargs.__gr_offs=(2+A->gp_offset)*8; \
|
||||
sysv_varargs.__vr_offs=A->fp_offset; \
|
||||
sysv_varargs.stack=A->overflow_arg_area; \
|
||||
sysv_varargs.gr_top=A->reg_save_area + X64_VA_MAX_REG; \
|
||||
sysv_varargs.vr_top=A->reg_save_area + X64_VA_MAX_XMM;
|
||||
|
||||
#elif defined(__powerpc64__)
|
||||
// TODO, is this correct?
|
||||
#define CREATE_SYSV_VALIST(A) \
|
||||
@ -41,6 +69,9 @@ typedef struct va_list {
|
||||
sysv_varargs->gpr=8; \
|
||||
sysv_varargs->fpr=8; \
|
||||
sysv_varargs->overflow_arg_area=A;
|
||||
|
||||
#define CONVERT_VALIST(A) \
|
||||
#error TODO!
|
||||
#else
|
||||
#error Unknown architecture!
|
||||
#endif
|
||||
|
@ -136,6 +136,7 @@ void myStackAlign(x64emu_t* emu, const char* fmt, uint64_t* st, uint64_t* mystac
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void myStackAlignGVariantNew(const char* fmt, uint32_t* st, uint32_t* mystack)
|
||||
{
|
||||
|
@ -575,22 +575,14 @@ EXPORT int my_printf(x64emu_t *emu, void* fmt, void* b) {
|
||||
return vprintf((const char*)fmt, VARARGS);
|
||||
}
|
||||
EXPORT int my___printf_chk(x64emu_t *emu, void* fmt, void* b) __attribute__((alias("my_printf")));
|
||||
#if 0
|
||||
EXPORT int my_vprintf(x64emu_t *emu, void* fmt, void* b, va_list V) {
|
||||
#ifndef NOALIGN
|
||||
// need to align on arm
|
||||
myStackAlign((const char*)fmt, (uint32_t*)b, emu->scratch);
|
||||
PREPARE_VALIST;
|
||||
void* f = vprintf;
|
||||
return ((iFpp_t)f)(fmt, VARARGS);
|
||||
#else
|
||||
// other platform don't need that
|
||||
void* f = vprintf;
|
||||
return ((iFpp_t)f)(fmt, (uint32_t*)b);
|
||||
#endif
|
||||
}
|
||||
EXPORT int my___vprintf_chk(x64emu_t *emu, void* fmt, void* b, va_list V) __attribute__((alias("my_vprintf")));
|
||||
|
||||
EXPORT int my_vprintf(x64emu_t *emu, void* fmt, x64_va_list_t b) {
|
||||
CONVERT_VALIST(b);
|
||||
return vprintf(fmt, VARARGS);
|
||||
}
|
||||
EXPORT int my___vprintf_chk(x64emu_t *emu, void* fmt, x64_va_list_t b) __attribute__((alias("my_vprintf")));
|
||||
|
||||
#if 0
|
||||
EXPORT int my_vfprintf(x64emu_t *emu, void* F, void* fmt, void* b) {
|
||||
#ifndef NOALIGN
|
||||
// need to align on arm
|
||||
|
@ -2055,7 +2055,7 @@ GO(usleep, iFu)
|
||||
//GO(vhangup,
|
||||
//GO(vlimit,
|
||||
//GO(vmsplice,
|
||||
//GO(vprintf,
|
||||
GOM(vprintf, iFEpp)
|
||||
//GO(__vprintf_chk,
|
||||
//GOW(vscanf,
|
||||
//GOW(__vsnprintf,
|
||||
|
1
tests/ref15.txt
Normal file
1
tests/ref15.txt
Normal file
@ -0,0 +1 @@
|
||||
Hello x86_64 World, pi=3.14159!
|
BIN
tests/test15
Executable file
BIN
tests/test15
Executable file
Binary file not shown.
24
tests/test15.c
Normal file
24
tests/test15.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int my_func(const char* fmt, va_list a)
|
||||
{
|
||||
return vprintf(fmt, a);
|
||||
}
|
||||
|
||||
int my_func1(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = my_func(fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = my_func1("Hello %s World, pi=%g!\n", "x86_64", 3.14159265);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user