about summary refs log tree commit diff stats
path: root/src/emu
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-01-21 23:13:51 +0800
committerGitHub <noreply@github.com>2025-01-21 16:13:51 +0100
commit044dec0bfa0f3f8f62f7703d6b0a8600c1354dc5 (patch)
treedc41c611965cec299dcb62185c5fba4935b6251f /src/emu
parented8b6fe9db863a8d9e473a645e84700c7291bb06 (diff)
downloadbox64-044dec0bfa0f3f8f62f7703d6b0a8600c1354dc5.tar.gz
box64-044dec0bfa0f3f8f62f7703d6b0a8600c1354dc5.zip
[ENV] Initial refactor of env variables infrastructure (#2274)
* [ENV] Initial refactor of env variables infrastructure

* Ported BOX64_DYNAREC_LOG

* Ported more options

* Ported BOX64_MALLOC_HACK

* Ported BOX64_DYNAREC_TEST

* Ported more options

* Ported more options

* Ported more options

* Ported all options

* Removed old rcfile parser

* Fix

* review

* fix

* fix

* more fixes
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/x64emu.c16
-rw-r--r--src/emu/x64int3.c30
-rw-r--r--src/emu/x64primop.c49
-rw-r--r--src/emu/x64run.c10
-rw-r--r--src/emu/x64run0f.c20
-rw-r--r--src/emu/x64run64.c8
-rw-r--r--src/emu/x64run660f.c8
-rw-r--r--src/emu/x64run_private.c53
-rw-r--r--src/emu/x64runavx0f.c2
-rw-r--r--src/emu/x64runf0.c12
-rw-r--r--src/emu/x64runf20f.c4
-rw-r--r--src/emu/x64syscall.c20
-rw-r--r--src/emu/x64test.c2
-rw-r--r--src/emu/x64tls.c2
-rwxr-xr-xsrc/emu/x86int3.c18
-rw-r--r--src/emu/x86syscall_32.c6
-rw-r--r--src/emu/x87emu_private.c12
17 files changed, 136 insertions, 136 deletions
diff --git a/src/emu/x64emu.c b/src/emu/x64emu.c
index e35f2608..daaf3a3a 100644
--- a/src/emu/x64emu.c
+++ b/src/emu/x64emu.c
@@ -415,7 +415,7 @@ const char* DumpCPURegs(x64emu_t* emu, uintptr_t ip, int is32bits)
     char tmp[160];
     buff[0] = '\0';
 #ifdef HAVE_TRACE
-    if(trace_emm) {
+    if(BOX64ENV(trace_emm)) {
         // do emm reg if needed
         for(int i=0; i<8; ++i) {
             sprintf(tmp, "mm%d:%016lx", i, emu->mmx[i].q);
@@ -423,10 +423,10 @@ const char* DumpCPURegs(x64emu_t* emu, uintptr_t ip, int is32bits)
             if ((i&3)==3) strcat(buff, "\n"); else strcat(buff, " ");
         }
     }
-    if(trace_xmm) {
+    if(BOX64ENV(trace_xmm)) {
         // do xmm reg if needed
         for(int i=0; i<(is32bits?8:16); ++i) {
-            if (trace_regsdiff && (emu->old_xmm[i].q[0] != emu->xmm[i].q[0] || emu->old_xmm[i].q[1] != emu->xmm[i].q[1])) {
+            if (BOX64ENV(trace_regsdiff) && (emu->old_xmm[i].q[0] != emu->xmm[i].q[0] || emu->old_xmm[i].q[1] != emu->xmm[i].q[1])) {
                 sprintf(tmp, "\e[1;35m%02d:%016lx-%016lx\e[m", i, emu->xmm[i].q[1], emu->xmm[i].q[0]);
                 emu->old_xmm[i].q[0] = emu->xmm[i].q[0];
                 emu->old_xmm[i].q[1] = emu->xmm[i].q[1];
@@ -434,8 +434,8 @@ const char* DumpCPURegs(x64emu_t* emu, uintptr_t ip, int is32bits)
                 sprintf(tmp, "%02d:%016lx-%016lx", i, emu->xmm[i].q[1], emu->xmm[i].q[0]);
             }
             strcat(buff, tmp);
-            if(box64_avx) {
-                if (trace_regsdiff && (emu->old_ymm[i].q[0] != emu->ymm[i].q[0] || emu->old_ymm[i].q[1] != emu->ymm[i].q[1])) {
+            if(BOX64ENV(avx)) {
+                if (BOX64ENV(trace_regsdiff) && (emu->old_ymm[i].q[0] != emu->ymm[i].q[0] || emu->old_ymm[i].q[1] != emu->ymm[i].q[1])) {
                     sprintf(tmp, "\e[1;35m-%016lx-%016lx\e[m", emu->ymm[i].q[1], emu->ymm[i].q[0]);
                     emu->old_ymm[i].q[0] = emu->ymm[i].q[0];
                     emu->old_ymm[i].q[1] = emu->ymm[i].q[1];
@@ -444,7 +444,7 @@ const char* DumpCPURegs(x64emu_t* emu, uintptr_t ip, int is32bits)
                 }
                 strcat(buff, tmp);
             }
-            if(box64_avx)
+            if(BOX64ENV(avx))
                 if ((i&1)==1) strcat(buff, "\n"); else strcat(buff, " ");
             else
                 if ((i&3)==3) strcat(buff, "\n"); else strcat(buff, " ");
@@ -477,7 +477,7 @@ const char* DumpCPURegs(x64emu_t* emu, uintptr_t ip, int is32bits)
     if(is32bits)
         for (int i=_AX; i<=_RDI; ++i) {
 #ifdef HAVE_TRACE
-            if (trace_regsdiff && (emu->regs[i].dword[0] != emu->oldregs[i].q[0])) {
+            if (BOX64ENV(trace_regsdiff) && (emu->regs[i].dword[0] != emu->oldregs[i].q[0])) {
                 sprintf(tmp, "\e[1;35m%s=%08x\e[m ", regname32[i], emu->regs[i].dword[0]);
                 emu->oldregs[i].q[0] = emu->regs[i].dword[0];
             } else {
@@ -505,7 +505,7 @@ const char* DumpCPURegs(x64emu_t* emu, uintptr_t ip, int is32bits)
     else
         for (int i=_AX; i<=_R15; ++i) {
 #ifdef HAVE_TRACE
-            if (trace_regsdiff && (emu->regs[i].q[0] != emu->oldregs[i].q[0])) {
+            if (BOX64ENV(trace_regsdiff) && (emu->regs[i].q[0] != emu->oldregs[i].q[0])) {
                 sprintf(tmp, "\e[1;35m%s=%016lx\e[m ", regname[i], emu->regs[i].q[0]);
                 emu->oldregs[i].q[0] = emu->regs[i].q[0];
             } else {
diff --git a/src/emu/x64int3.c b/src/emu/x64int3.c
index 9b468279..44d47a2f 100644
--- a/src/emu/x64int3.c
+++ b/src/emu/x64int3.c
@@ -110,17 +110,17 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr)
             elfheader_t *h = FindElfAddress(my_context, *(uintptr_t*)(R_ESP));
             int have_trace = 0;
             if(h && strstr(ElfName(h), "libMiles")) have_trace = 1;*/
-            if(box64_log>=LOG_DEBUG || cycle_log) {
+            if(BOX64ENV(log)>=LOG_DEBUG || BOX64ENV(rolling_log)) {
                 int tid = GetTID();
                 char t_buff[256] = "\0";
                 char buff2[64] = "\0";
                 char buff3[64] = "\0";
                 int cycle_line = my_context->current_line;
-                if(cycle_log) {
-                    my_context->current_line = (my_context->current_line+1)%cycle_log;
+                if(BOX64ENV(rolling_log)) {
+                    my_context->current_line = (my_context->current_line+1)%BOX64ENV(rolling_log);
                 }
-                char* buff = cycle_log?my_context->log_call[cycle_line]:t_buff;
-                char* buffret = cycle_log?my_context->log_ret[cycle_line]:NULL;
+                char* buff = BOX64ENV(rolling_log)?my_context->log_call[cycle_line]:t_buff;
+                char* buffret = BOX64ENV(rolling_log)?my_context->log_ret[cycle_line]:NULL;
                 if(buffret) buffret[0] = '\0';
                 char *tmp;
                 int post = 0;
@@ -132,7 +132,7 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr)
                 if(!s)
                     s = GetNativeName((void*)a);
                 if(a==(uintptr_t)PltResolver64) {
-                    if(cycle_log) {
+                    if(BOX64ENV(rolling_log)) {
                         uintptr_t addr = *((uint64_t*)(R_RSP));
                         int slot = *((uint64_t*)(R_RSP+8));
                         elfheader_t *h = (elfheader_t*)addr;
@@ -320,7 +320,7 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr)
                 } else {
                     snprintf(buff, 256, "%04d|%p: Calling %s(0x%lX, 0x%lX, 0x%lX, ...)", tid, *(void**)(R_RSP), s, R_RDI, R_RSI, R_RDX);
                 }
-                if(!cycle_log) {
+                if(!BOX64ENV(rolling_log)) {
                     mutex_lock(&emu->context->mutex_trace);
                     printf_log(LOG_NONE, "%s =>", buff);
                     mutex_unlock(&emu->context->mutex_trace);
@@ -372,7 +372,7 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr)
                 else if(perr==3 && (S_RAX)==-1)
                     snprintf(buff3, 64, " (errno=%d:\"%s\")", errno, strerror(errno));
 
-                if(cycle_log)
+                if(BOX64ENV(rolling_log))
                     snprintf(buffret, 128, "0x%lX%s%s", R_RAX, buff2, buff3);
                 else {
                     mutex_lock(&emu->context->mutex_trace);
@@ -389,7 +389,7 @@ void x64Int3(x64emu_t* emu, uintptr_t* addr)
         printf_log(LOG_DEBUG, "%04d|Warning, x64int3 with no CC opcode at %p?\n", GetTID(), (void*)R_RIP);
         return;
     }
-    if(!box64_ignoreint3 && my_context->signals[SIGTRAP]) {
+    if(!BOX64ENV(ignoreint3) && my_context->signals[SIGTRAP]) {
         R_RIP = *addr;  // update RIP
         emit_signal(emu, SIGTRAP, NULL, 3);
     } else {
@@ -404,12 +404,12 @@ int GetTID()
     return syscall(SYS_gettid);
 }
 
-void print_cycle_log(int loglevel) {
-    if(cycle_log) {
+void print_rolling_log(int loglevel) {
+    if(BOX64ENV(rolling_log)) {
         printf_log(loglevel, "Last calls\n");
-        int j = (my_context->current_line+1)%cycle_log;
-        for (int i=0; i<cycle_log; ++i) {
-            int k = (i+j)%cycle_log;
+        int j = (my_context->current_line+1)%BOX64ENV(rolling_log);
+        for (int i=0; i<BOX64ENV(rolling_log); ++i) {
+            int k = (i+j)%BOX64ENV(rolling_log);
             if(my_context->log_call[k][0]) {
                 printf_log(loglevel, "%s => return %s\n", my_context->log_call[k], my_context->log_ret[k]);
             }
@@ -423,4 +423,4 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
     printf_log(LOG_NONE, "Error: Calling 32bits wrapped function without box32 support built in\n");
     abort();
 }
-#endif
\ No newline at end of file
+#endif
diff --git a/src/emu/x64primop.c b/src/emu/x64primop.c
index 4898a0d8..129069ad 100644
--- a/src/emu/x64primop.c
+++ b/src/emu/x64primop.c
@@ -103,8 +103,9 @@
 
 #include "x64emu_private.h"
 #include "x64run_private.h"
+#include "env.h"
 
-extern int box64_dynarec_test;
+extern box64env_t box64env;
 
 /*------------------------- Global Variables ------------------------------*/
 
@@ -780,7 +781,7 @@ uint8_t rol8(x64emu_t *emu, uint8_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = CF _XOR_ MSB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG((d + (d >> 7)) & 1, F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -805,7 +806,7 @@ uint16_t rol16(x64emu_t *emu, uint16_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = CF _XOR_ MSB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG((d + (d >> 15)) & 1, F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -830,7 +831,7 @@ uint32_t rol32(x64emu_t *emu, uint32_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = CF _XOR_ MSB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG((d + (d >> 31)) & 1, F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -855,7 +856,7 @@ uint64_t rol64(x64emu_t *emu, uint64_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = CF _XOR_ MSB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG((d + (d >> 63)) & 1, F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -884,7 +885,7 @@ uint8_t ror8(x64emu_t *emu, uint8_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = MSB _XOR_ (M-1)SB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG(XOR2(d >> 6), F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -909,7 +910,7 @@ uint16_t ror16(x64emu_t *emu, uint16_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = MSB _XOR_ (M-1)SB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG(XOR2(d >> 14), F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -934,7 +935,7 @@ uint32_t ror32(x64emu_t *emu, uint32_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = MSB _XOR_ (M-1)SB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG(XOR2(d >> 30), F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -959,7 +960,7 @@ uint64_t ror64(x64emu_t *emu, uint64_t d, uint8_t s)
 	/* OF flag is set if s == 1; OF = MSB _XOR_ (M-1)SB of result */
 	if(s == 1) {
 	CONDITIONAL_SET_FLAG(XOR2(d >> 62), F_OF);
-	} else if(box64_dynarec_test) {
+	} else if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_OF);
 	}
 
@@ -1009,7 +1010,7 @@ uint16_t shld16 (x64emu_t *emu, uint16_t d, uint16_t fill, uint8_t s)
 		CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF);
 		CLEAR_FLAG(F_OF);
 	}
-	if(box64_dynarec_test)
+	if(BOX64ENV(dynarec_test))
 		CLEAR_FLAG(F_AF);
 	return (uint16_t)res;
 }
@@ -1038,7 +1039,7 @@ uint32_t shld32 (x64emu_t *emu, uint32_t d, uint32_t fill, uint8_t s)
 	} else {
 		CLEAR_FLAG(F_OF);
 	}
-	if(box64_dynarec_test)
+	if(BOX64ENV(dynarec_test))
 		CLEAR_FLAG(F_AF);
 	return res;
 }
@@ -1067,7 +1068,7 @@ uint64_t shld64 (x64emu_t *emu, uint64_t d, uint64_t fill, uint8_t s)
 	} else {
 		CLEAR_FLAG(F_OF);
 	}
-	if(box64_dynarec_test)
+	if(BOX64ENV(dynarec_test))
 		CLEAR_FLAG(F_AF);
 	return res;
 }
@@ -1122,7 +1123,7 @@ uint16_t shrd16 (x64emu_t *emu, uint16_t d, uint16_t fill, uint8_t s)
 		CLEAR_FLAG(F_PF);
 	#endif
     }
-	if(box64_dynarec_test)
+	if(BOX64ENV(dynarec_test))
 		CLEAR_FLAG(F_AF);
 	return (uint16_t)res;
 }
@@ -1151,7 +1152,7 @@ uint32_t shrd32 (x64emu_t *emu, uint32_t d, uint32_t fill, uint8_t s)
 	} else {
 		CLEAR_FLAG(F_OF);
 	}
-	if(box64_dynarec_test)
+	if(BOX64ENV(dynarec_test))
 		CLEAR_FLAG(F_AF);
 	return res;
 }
@@ -1181,7 +1182,7 @@ uint64_t shrd64 (x64emu_t *emu, uint64_t d, uint64_t fill, uint8_t s)
 	} else {
 		CLEAR_FLAG(F_OF);
 	}
-	if(box64_dynarec_test)
+	if(BOX64ENV(dynarec_test))
 		CLEAR_FLAG(F_AF);
 	return res;
 }
@@ -1345,12 +1346,12 @@ void test64(x64emu_t *emu, uint64_t d, uint64_t s)
 REMARKS:
 Implements the IDIV instruction and side effects.
 ****************************************************************************/
-extern int box64_dynarec_test;
+
 void idiv8(x64emu_t *emu, uint8_t s)
 {
     int32_t dvd, quot, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
@@ -1379,7 +1380,7 @@ void idiv16(x64emu_t *emu, uint16_t s)
 {
 	int32_t dvd, quot, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
@@ -1409,7 +1410,7 @@ void idiv32(x64emu_t *emu, uint32_t s)
 {
 	int64_t dvd, quot, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
@@ -1439,7 +1440,7 @@ void idiv64(x64emu_t *emu, uint64_t s)
 {
 	__int128 dvd, quot, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
@@ -1472,7 +1473,7 @@ void div8(x64emu_t *emu, uint8_t s)
 {
 	uint32_t dvd, div, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
@@ -1500,7 +1501,7 @@ void div16(x64emu_t *emu, uint16_t s)
 {
 	uint32_t dvd, div, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
@@ -1529,7 +1530,7 @@ void div32(x64emu_t *emu, uint32_t s)
 {
 	uint64_t dvd, div, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
@@ -1558,7 +1559,7 @@ void div64(x64emu_t *emu, uint64_t s)
 {
 	__int128 dvd, div, mod;
 	RESET_FLAGS(emu);
-	if(box64_dynarec_test) {
+	if(BOX64ENV(dynarec_test)) {
 		CLEAR_FLAG(F_CF);
 		CLEAR_FLAG(F_AF);
 		CLEAR_FLAG(F_PF);
diff --git a/src/emu/x64run.c b/src/emu/x64run.c
index 4a17ab55..c339dcf5 100644
--- a/src/emu/x64run.c
+++ b/src/emu/x64run.c
@@ -590,7 +590,7 @@ x64emurun:
         case 0x6E:                      /* OUTSB DX */
         case 0x6F:                      /* OUTSD DX */
 #ifndef TEST_INTERPRETER
-            if(rex.is32bits && box64_ignoreint3)
+            if(rex.is32bits && BOX64ENV(ignoreint3))
             {
             } else {
                 emit_signal(emu, SIGSEGV, (void*)R_RIP, 0xbad0);
@@ -1872,7 +1872,7 @@ x64emurun:
             // this is a privilege opcode...
             #ifndef TEST_INTERPRETER
             F8;
-            if(rex.is32bits && box64_ignoreint3)
+            if(rex.is32bits && BOX64ENV(ignoreint3))
             {} else
             emit_signal(emu, SIGSEGV, (void*)R_RIP, 0xbad0);
             STEP;
@@ -1912,7 +1912,7 @@ x64emurun:
         case 0xEF:                      /* OUT DX, EAX */
             // this is a privilege opcode...
             #ifndef TEST_INTERPRETER
-            if(rex.is32bits && box64_ignoreint3)
+            if(rex.is32bits && BOX64ENV(ignoreint3))
             {} else
             emit_signal(emu, SIGSEGV, (void*)R_RIP, 0xbad0);
             STEP;
@@ -2075,14 +2075,14 @@ x64emurun:
             break;
         case 0xFA:                      /* CLI */
             // this is a privilege opcode
-            if(rex.is32bits && box64_ignoreint3)
+            if(rex.is32bits && BOX64ENV(ignoreint3))
             {} else
             emit_signal(emu, SIGSEGV, (void*)R_RIP, 0xbad0);
             STEP;
             break;
         case 0xFB:                      /* STI */
             // this is a privilege opcode
-            if(rex.is32bits && box64_ignoreint3)
+            if(rex.is32bits && BOX64ENV(ignoreint3))
             {} else
             emit_signal(emu, SIGSEGV, (void*)R_RIP, 0xbad0);
             STEP;
diff --git a/src/emu/x64run0f.c b/src/emu/x64run0f.c
index 911d80b1..f156b3e2 100644
--- a/src/emu/x64run0f.c
+++ b/src/emu/x64run0f.c
@@ -1168,7 +1168,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                 else

                     CLEAR_FLAG(F_CF);

             }

-            if(box64_dynarec_test) {

+            if (BOX64ENV(dynarec_test)) {

                 CLEAR_FLAG(F_OF);

                 CLEAR_FLAG(F_SF);

                 CLEAR_FLAG(F_AF);

@@ -1255,7 +1255,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                 if(MODREG)

                     ED->dword[1] = 0;

             }

-            if(box64_dynarec_test) {

+            if (BOX64ENV(dynarec_test)) {

                 CLEAR_FLAG(F_OF);

                 CLEAR_FLAG(F_SF);

                 CLEAR_FLAG(F_AF);

@@ -1314,7 +1314,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                     GETED(0);

                     emu->mxcsr.x32 = ED->dword[0];

                     #ifndef TEST_INTERPRETER

-                    if(box64_sse_flushto0)

+                    if(BOX64ENV(sse_flushto0))

                         applyFlushTo0(emu);

                     #endif

                     break;

@@ -1337,7 +1337,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                 case 7:                 /* CLFLUSH Ed */

                     _GETED(0);

                     #if defined(DYNAREC) && !defined(TEST_INTERPRETER)

-                    if(box64_dynarec)

+                    if(BOX64ENV(dynarec))

                         cleanDBFromAddressRange((uintptr_t)ED, 8, 0);

                     #endif

                     break;

@@ -1424,7 +1424,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                 if(MODREG)

                     ED->dword[1] = 0;

             }

-            if(box64_dynarec_test) {

+            if (BOX64ENV(dynarec_test)) {

                 CLEAR_FLAG(F_OF);

                 CLEAR_FLAG(F_SF);

                 CLEAR_FLAG(F_AF);

@@ -1465,7 +1465,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                         else

                             CLEAR_FLAG(F_CF);

                     }

-                    if(box64_dynarec_test) {

+                    if (BOX64ENV(dynarec_test)) {

                         CLEAR_FLAG(F_OF);

                         CLEAR_FLAG(F_SF);

                         CLEAR_FLAG(F_AF);

@@ -1495,7 +1495,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                         if(MODREG)

                             ED->dword[1] = 0;

                     }

-                    if(box64_dynarec_test) {

+                    if (BOX64ENV(dynarec_test)) {

                         CLEAR_FLAG(F_OF);

                         CLEAR_FLAG(F_SF);

                         CLEAR_FLAG(F_AF);

@@ -1523,7 +1523,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                         if(MODREG)

                             ED->dword[1] = 0;

                     }

-                    if(box64_dynarec_test) {

+                    if (BOX64ENV(dynarec_test)) {

                         CLEAR_FLAG(F_OF);

                         CLEAR_FLAG(F_SF);

                         CLEAR_FLAG(F_AF);

@@ -1551,7 +1551,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                         if(MODREG)

                             ED->dword[1] = 0;

                     }

-                    if(box64_dynarec_test) {

+                    if (BOX64ENV(dynarec_test)) {

                         CLEAR_FLAG(F_OF);

                         CLEAR_FLAG(F_SF);

                         CLEAR_FLAG(F_AF);

@@ -1598,7 +1598,7 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
                 if(MODREG)

                     ED->dword[1] = 0;

             }

-            if(box64_dynarec_test) {

+            if (BOX64ENV(dynarec_test)) {

                 CLEAR_FLAG(F_OF);

                 CLEAR_FLAG(F_SF);

                 CLEAR_FLAG(F_AF);

diff --git a/src/emu/x64run64.c b/src/emu/x64run64.c
index 9d8b920e..0470d92a 100644
--- a/src/emu/x64run64.c
+++ b/src/emu/x64run64.c
@@ -321,7 +321,7 @@ uintptr_t Run64(x64emu_t *emu, rex_t rex, int seg, uintptr_t addr)
                                 else

                                     CLEAR_FLAG(F_CF);

                             }

-                            if(box64_dynarec_test) {

+                            if (BOX64ENV(dynarec_test)) {

                                 CLEAR_FLAG(F_OF);

                                 CLEAR_FLAG(F_SF);

                                 CLEAR_FLAG(F_AF);

@@ -351,7 +351,7 @@ uintptr_t Run64(x64emu_t *emu, rex_t rex, int seg, uintptr_t addr)
                                 if(MODREG)

                                     ED->dword[1] = 0;

                             }

-                            if(box64_dynarec_test) {

+                            if (BOX64ENV(dynarec_test)) {

                                 CLEAR_FLAG(F_OF);

                                 CLEAR_FLAG(F_SF);

                                 CLEAR_FLAG(F_AF);

@@ -379,7 +379,7 @@ uintptr_t Run64(x64emu_t *emu, rex_t rex, int seg, uintptr_t addr)
                                 if(MODREG)

                                     ED->dword[1] = 0;

                             }

-                            if(box64_dynarec_test) {

+                            if (BOX64ENV(dynarec_test)) {

                                 CLEAR_FLAG(F_OF);

                                 CLEAR_FLAG(F_SF);

                                 CLEAR_FLAG(F_AF);

@@ -407,7 +407,7 @@ uintptr_t Run64(x64emu_t *emu, rex_t rex, int seg, uintptr_t addr)
                                 if(MODREG)

                                     ED->dword[1] = 0;

                             }

-                            if(box64_dynarec_test) {

+                            if (BOX64ENV(dynarec_test)) {

                                 CLEAR_FLAG(F_OF);

                                 CLEAR_FLAG(F_SF);

                                 CLEAR_FLAG(F_AF);

diff --git a/src/emu/x64run660f.c b/src/emu/x64run660f.c
index 6bd25132..3889b189 100644
--- a/src/emu/x64run660f.c
+++ b/src/emu/x64run660f.c
@@ -1717,7 +1717,7 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr)
     case 0x78:  /* EXTRQ Ex, ib, ib */

         // AMD only

         nextop = F8;

-        if(!box64_cputype || (nextop&0xC0)>>3) {

+        if(!BOX64ENV(cputype) || (nextop&0xC0)>>3) {

             #ifndef TEST_INTERPRETER

             emit_signal(emu, SIGILL, (void*)R_RIP, 0);

             #endif

@@ -1732,7 +1732,7 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr)
     case 0x79:  /* EXTRQ Ex, Gx */

         // AMD only

         nextop = F8;

-        if(!box64_cputype || !(MODREG)) {

+        if(!BOX64ENV(cputype) || !(MODREG)) {

             #ifndef TEST_INTERPRETER

             emit_signal(emu, SIGILL, (void*)R_RIP, 0);

             #endif

@@ -1911,7 +1911,7 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr)
                 // same code and CLFLUSH, is it ok?

                 _GETED(0);

                 #if defined(DYNAREC) && !defined(TEST_INTERPRETER)

-                if(box64_dynarec)

+                if(BOX64ENV(dynarec))

                     cleanDBFromAddressRange((uintptr_t)ED, 8, 0);

                 #endif

                 break;

@@ -1919,7 +1919,7 @@ uintptr_t Run660F(x64emu_t *emu, rex_t rex, uintptr_t addr)
                 // same code and CLFLUSH, is it ok?

                 _GETED(0);

                 #if defined(DYNAREC) && !defined(TEST_INTERPRETER)

-                if(box64_dynarec)

+                if(BOX64ENV(dynarec))

                     cleanDBFromAddressRange((uintptr_t)ED, 8, 0);

                 #endif

                 break;

diff --git a/src/emu/x64run_private.c b/src/emu/x64run_private.c
index 5cfc4625..a82fc6f5 100644
--- a/src/emu/x64run_private.c
+++ b/src/emu/x64run_private.c
@@ -381,7 +381,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF);
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -400,7 +400,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF);
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -417,7 +417,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF); 
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -434,7 +434,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF);
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -451,7 +451,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF);
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -468,7 +468,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF);
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -484,7 +484,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF);
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -500,7 +500,7 @@ void UpdateFlags(x64emu_t *emu)
                 SET_FLAG(F_CF);
                 SET_FLAG(F_OF);
             }
-            if(box64_dynarec_test) {
+            if (BOX64ENV(dynarec_test)) {
                 // to avoid noise in tests
                 CLEAR_FLAG(F_SF);
                 CLEAR_FLAG(F_ZF);
@@ -589,7 +589,7 @@ void UpdateFlags(x64emu_t *emu)
                 } else {
                     CLEAR_FLAG(F_OF);
                 }
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -607,7 +607,7 @@ void UpdateFlags(x64emu_t *emu)
                 } else {
                     CLEAR_FLAG(F_OF);
                 }
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -626,7 +626,7 @@ void UpdateFlags(x64emu_t *emu)
                 } else {
                     CLEAR_FLAG(F_OF);
                 }
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -644,7 +644,7 @@ void UpdateFlags(x64emu_t *emu)
                 } else {
                     CLEAR_FLAG(F_OF);
                 }
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -656,9 +656,9 @@ void UpdateFlags(x64emu_t *emu)
                 CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF);
                 CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF);
                 CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF);
-                if(emu->op2.u8==1 || box64_dynarec_test)
+                if (emu->op2.u8 == 1 || BOX64ENV(dynarec_test))
                     CLEAR_FLAG(F_OF);
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -670,9 +670,9 @@ void UpdateFlags(x64emu_t *emu)
                 CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF);
                 CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF);
                 CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF);
-                if(emu->op2.u16==1 || box64_dynarec_test)
+                if (emu->op2.u16 == 1 || BOX64ENV(dynarec_test))
                     CLEAR_FLAG(F_OF);
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -684,9 +684,9 @@ void UpdateFlags(x64emu_t *emu)
                 CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF);
                 CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF);
                 CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF);
-                if(emu->op2.u32==1 || box64_dynarec_test)
+                if (emu->op2.u32 == 1 || BOX64ENV(dynarec_test))
                     CLEAR_FLAG(F_OF);
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -698,9 +698,9 @@ void UpdateFlags(x64emu_t *emu)
                 CONDITIONAL_SET_FLAG(!emu->res.u64, F_ZF);
                 CONDITIONAL_SET_FLAG(emu->res.u64 & 0x8000000000000000LL, F_SF);
                 CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF);
-                if(emu->op2.u64==1 || box64_dynarec_test)
+                if (emu->op2.u64 == 1 || BOX64ENV(dynarec_test))
                     CLEAR_FLAG(F_OF);
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                 }
             }
@@ -713,7 +713,7 @@ void UpdateFlags(x64emu_t *emu)
                 CONDITIONAL_SET_FLAG(!emu->res.u8, F_ZF);
                 CONDITIONAL_SET_FLAG(emu->res.u8 & 0x80, F_SF);
                 CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF);
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                     if(cnt>1) {
                         CLEAR_FLAG(F_OF);
@@ -732,7 +732,7 @@ void UpdateFlags(x64emu_t *emu)
                 CONDITIONAL_SET_FLAG(!emu->res.u16, F_ZF);
                 CONDITIONAL_SET_FLAG(emu->res.u16 & 0x8000, F_SF);
                 CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF);
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                     if(cnt>1) {
                         CLEAR_FLAG(F_OF);
@@ -751,7 +751,7 @@ void UpdateFlags(x64emu_t *emu)
                 CONDITIONAL_SET_FLAG(!emu->res.u32, F_ZF);
                 CONDITIONAL_SET_FLAG(emu->res.u32 & 0x80000000, F_SF);
                 CONDITIONAL_SET_FLAG(PARITY(emu->res.u8), F_PF);
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                     if(cnt>1) {
                         CLEAR_FLAG(F_OF);
@@ -773,7 +773,7 @@ void UpdateFlags(x64emu_t *emu)
                 if (cnt == 1) {
                     CONDITIONAL_SET_FLAG(emu->op1.u64 & 0x8000000000000000LL, F_OF);
                 }
-                if(box64_dynarec_test) {
+                if (BOX64ENV(dynarec_test)) {
                     CLEAR_FLAG(F_AF);
                     if(cnt>1) {
                         CLEAR_FLAG(F_OF);
@@ -1206,7 +1206,6 @@ int printFunctionAddr(uintptr_t nextaddr, const char* text)
 }
 
 #ifdef HAVE_TRACE
-extern uint64_t start_cnt;
 #define PK(a)     (*(uint8_t*)(ip+a))
 #define PKS(a)    (*(int8_t*)(ip+a))
 #define PK32(a)   (*(int32_t*)((uint8_t*)(ip+a)))
@@ -1215,8 +1214,8 @@ extern uint64_t start_cnt;
 void PrintTrace(x64emu_t* emu, uintptr_t ip, int dynarec)
 {
     int is32bits = (emu->segs[_CS]==0x23);
-    if(start_cnt) --start_cnt;
-    if(!start_cnt && my_context->dec && (
+    if(BOX64ENV(start_cnt)) SET_BOX64ENV(start_cnt, BOX64ENV(start_cnt)-1);
+    if(!BOX64ENV(start_cnt) && my_context->dec && (
             (trace_end == 0) 
             || ((ip >= trace_start) && (ip < trace_end))) ) {
         int tid = syscall(SYS_gettid);
diff --git a/src/emu/x64runavx0f.c b/src/emu/x64runavx0f.c
index 1b02989b..2b3f8189 100644
--- a/src/emu/x64runavx0f.c
+++ b/src/emu/x64runavx0f.c
@@ -529,7 +529,7 @@ uintptr_t RunAVX_0F(x64emu_t *emu, vex_t vex, uintptr_t addr, int *step)
                     GETED(0);
                     emu->mxcsr.x32 = ED->dword[0];
                     #ifndef TEST_INTERPRETER
-                    if(box64_sse_flushto0)
+                    if(BOX64ENV(sse_flushto0))
                         applyFlushTo0(emu);
                     #endif
                     break;
diff --git a/src/emu/x64runf0.c b/src/emu/x64runf0.c
index df381e5a..8a1c5d0a 100644
--- a/src/emu/x64runf0.c
+++ b/src/emu/x64runf0.c
@@ -290,7 +290,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
                 }

                 pthread_mutex_unlock(&my_context->mutex_lock);

 #endif

-                if(box64_dynarec_test) {

+                if(BOX64ENV(dynarec_test)) {

                     CLEAR_FLAG(F_OF);

                     CLEAR_FLAG(F_SF);

                     CLEAR_FLAG(F_AF);

@@ -478,7 +478,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
                     }

                     pthread_mutex_unlock(&my_context->mutex_lock);

 #endif

-                    if(box64_dynarec_test) {

+                    if(BOX64ENV(dynarec_test)) {

                         CLEAR_FLAG(F_OF);

                         CLEAR_FLAG(F_SF);

                         CLEAR_FLAG(F_AF);

@@ -506,7 +506,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
                                     else

                                         CLEAR_FLAG(F_CF);

                                 }

-                                if(box64_dynarec_test) {

+                                if(BOX64ENV(dynarec_test)) {

                                     CLEAR_FLAG(F_OF);

                                     CLEAR_FLAG(F_SF);

                                     CLEAR_FLAG(F_AF);

@@ -580,7 +580,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
                                 }

                                 pthread_mutex_unlock(&my_context->mutex_lock);

 #endif

-                                if(box64_dynarec_test) {

+                                if(BOX64ENV(dynarec_test)) {

                                     CLEAR_FLAG(F_OF);

                                     CLEAR_FLAG(F_SF);

                                     CLEAR_FLAG(F_AF);

@@ -638,7 +638,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
                                 }

                                 pthread_mutex_unlock(&my_context->mutex_lock);

 #endif

-                                if(box64_dynarec_test) {

+                                if(BOX64ENV(dynarec_test)) {

                                     CLEAR_FLAG(F_OF);

                                     CLEAR_FLAG(F_SF);

                                     CLEAR_FLAG(F_AF);

@@ -692,7 +692,7 @@ uintptr_t RunF0(x64emu_t *emu, rex_t rex, uintptr_t addr)
                                 }

                                 pthread_mutex_unlock(&my_context->mutex_lock);

 #endif

-                                if(box64_dynarec_test) {

+                                if(BOX64ENV(dynarec_test)) {

                                     CLEAR_FLAG(F_OF);

                                     CLEAR_FLAG(F_SF);

                                     CLEAR_FLAG(F_AF);

diff --git a/src/emu/x64runf20f.c b/src/emu/x64runf20f.c
index d9617461..c8b5e545 100644
--- a/src/emu/x64runf20f.c
+++ b/src/emu/x64runf20f.c
@@ -315,7 +315,7 @@ uintptr_t RunF20F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
     case 0x78:  /* INSERTQ Ex, Gx, ib, ib */

         // AMD only

         nextop = F8;

-        if(!box64_cputype || !(MODREG)) {

+        if(!BOX64ENV(cputype) || !(MODREG)) {

             #ifndef TEST_INTERPRETER

             emit_signal(emu, SIGILL, (void*)R_RIP, 0);

             #endif

@@ -332,7 +332,7 @@ uintptr_t RunF20F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
     case 0x79:  /* INSERTQ Ex, Gx */

         // AMD only

         nextop = F8;

-        if(!box64_cputype || !(MODREG)) {

+        if(!BOX64ENV(cputype) || !(MODREG)) {

             #ifndef TEST_INTERPRETER

             emit_signal(emu, SIGILL, (void*)R_RIP, 0);

             #endif

diff --git a/src/emu/x64syscall.c b/src/emu/x64syscall.c
index a912afcb..4c20bb9d 100644
--- a/src/emu/x64syscall.c
+++ b/src/emu/x64syscall.c
@@ -450,14 +450,14 @@ void EXPORT x64Syscall(x64emu_t *emu)
     char buff2[64] = "\0";
     char* buff = NULL;
     char* buffret = NULL;
-    if(box64_log>=LOG_DEBUG || cycle_log) {
+    if(BOX64ENV(log) >= LOG_DEBUG || BOX64ENV(rolling_log)) {
         log = 1;
-        buff = cycle_log?my_context->log_call[my_context->current_line]:t_buff;
-        buffret = cycle_log?my_context->log_ret[my_context->current_line]:t_buffret;
-        if(cycle_log)
-            my_context->current_line = (my_context->current_line+1)%cycle_log;
+        buff = BOX64ENV(rolling_log)?my_context->log_call[my_context->current_line]:t_buff;
+        buffret = BOX64ENV(rolling_log)?my_context->log_ret[my_context->current_line]:t_buffret;
+        if(BOX64ENV(rolling_log))
+            my_context->current_line = (my_context->current_line+1)%BOX64ENV(rolling_log);
         snprintf(buff, 255, "%04d|%p: Calling syscall 0x%02X (%d) %p %p %p %p %p %p", GetTID(), (void*)R_RIP, s, s, (void*)R_RDI, (void*)R_RSI, (void*)R_RDX, (void*)R_R10, (void*)R_R8, (void*)R_R9);
-        if(!cycle_log)
+        if(!BOX64ENV(rolling_log))
             printf_log(LOG_NONE, "%s", buff);
     }
     // check wrapper first
@@ -480,7 +480,7 @@ void EXPORT x64Syscall(x64emu_t *emu)
         if(S_RAX==-1 && errno>0)
             S_RAX = -errno;
         if(log) snprintf(buffret, 127, "0x%x%s", R_EAX, buff2);
-        if(log && !cycle_log) printf_log(LOG_NONE, "=> %s\n", buffret);
+        if(log && !BOX64ENV(rolling_log)) printf_log(LOG_NONE, "=> %s\n", buffret);
         return;
     }
     switch (s) {
@@ -838,7 +838,7 @@ void EXPORT x64Syscall(x64emu_t *emu)
         #endif
         case 449:
             #ifdef __NR_futex_waitv
-            if(box64_futex_waitv)
+            if(BOX64ENV(futex_waitv))
                 S_RAX = syscall(__NR_futex_waitv, R_RDI, R_RSI, R_RDX, R_R10, R_R8);
             else
             #endif
@@ -851,7 +851,7 @@ void EXPORT x64Syscall(x64emu_t *emu)
             return;
     }
     if(log) snprintf(buffret, 127, "0x%lx%s", R_RAX, buff2);
-    if(log && !cycle_log) printf_log(LOG_NONE, "=> %s\n", buffret);
+    if(log && !BOX64ENV(rolling_log)) printf_log(LOG_NONE, "=> %s\n", buffret);
 }
 
 #define stack(n) (R_RSP+8+n)
@@ -1116,7 +1116,7 @@ long EXPORT my_syscall(x64emu_t *emu)
         #endif
         case 449:
             #ifdef __NR_futex_waitv
-            if(box64_futex_waitv)
+            if(BOX64ENV(futex_waitv))
                 return syscall(__NR_futex_waitv, R_RSI, R_RDX, R_RCX, R_R8, R_R9);
             else
             #endif
diff --git a/src/emu/x64test.c b/src/emu/x64test.c
index 135a120c..b00fc060 100644
--- a/src/emu/x64test.c
+++ b/src/emu/x64test.c
@@ -106,7 +106,7 @@ void x64test_check(x64emu_t* ref, uintptr_t ip)
         BANNER;
         printf_log(LOG_NONE, "MXCSR: %x | %x\n", ref->mxcsr.x32, emu->mxcsr.x32);
     }
-    if(box64_avx)
+    if(BOX64ENV(avx))
         if(memcmp(ref->ymm, emu->ymm, sizeof(emu->ymm))) {
             BANNER;
             for(int i=0; i<16; ++i) {
diff --git a/src/emu/x64tls.c b/src/emu/x64tls.c
index 16d4193e..4902177e 100644
--- a/src/emu/x64tls.c
+++ b/src/emu/x64tls.c
@@ -257,7 +257,7 @@ static int sizeDTS(box64context_t* context)
 }
 static int sizeTLSData(int s)
 {
-    uint32_t mask = 0xffff/*box64_nogtk?0xffff:0x1fff*/;    // x86_64 does the mapping per 64K blocks, so it makes sense to have it this large
+    uint32_t mask = 0xffff/*BOX64ENV(nogtk)?0xffff:0x1fff*/;    // x86_64 does the mapping per 64K blocks, so it makes sense to have it this large
     return (s+mask)&~mask;
 }
 
diff --git a/src/emu/x86int3.c b/src/emu/x86int3.c
index 72494a24..0eae5dd7 100755
--- a/src/emu/x86int3.c
+++ b/src/emu/x86int3.c
@@ -64,17 +64,17 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
             elfheader_t *h = FindElfAddress(my_context, *(uintptr_t*)(R_ESP));
             int have_trace = 0;
             if(h && strstr(ElfName(h), "libMiles")) have_trace = 1;*/
-            if(box64_log>=LOG_DEBUG || cycle_log) {
+            if(BOX64ENV(log)>=LOG_DEBUG || BOX64ENV(rolling_log)) {
                 int tid = GetTID();
                 char t_buff[256] = "\0";
                 char buff2[64] = "\0";
                 char buff3[64] = "\0";
                 int cycle_line = my_context->current_line;
-                if(cycle_log) {
-                    my_context->current_line = (my_context->current_line+1)%cycle_log;
+                if(BOX64ENV(rolling_log)) {
+                    my_context->current_line = (my_context->current_line+1)%BOX64ENV(rolling_log);
                 }
-                char* buff = cycle_log?my_context->log_call[cycle_line]:t_buff;
-                char* buffret = cycle_log?my_context->log_ret[cycle_line]:NULL;
+                char* buff = BOX64ENV(rolling_log)?my_context->log_call[cycle_line]:t_buff;
+                char* buffret = BOX64ENV(rolling_log)?my_context->log_ret[cycle_line]:NULL;
                 if(buffret) buffret[0] = '\0';
                 char *tmp;
                 int post = 0;
@@ -87,7 +87,7 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
                 if(!s)
                     s = GetNativeName((void*)a);
                 if(a==(uintptr_t)PltResolver32) {
-                    if(cycle_log) {
+                    if(BOX64ENV(rolling_log)) {
                         ptr_t addr = *((uint32_t*)from_ptrv(R_ESP));
                         int slot = *((uint32_t*)from_ptrv(R_ESP+4));
                         elfheader_t *h = (elfheader_t*)from_ptrv(addr);
@@ -399,7 +399,7 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
                 } else {
                     snprintf(buff, 255, "%04d|%p: Calling %s (%08X, %08X, %08X...)", tid, from_ptriv(R_ESP), (char *)s, *(uint32_t*)from_ptr(R_ESP+4), *(uint32_t*)from_ptr(R_ESP+8), *(uint32_t*)from_ptr(R_ESP+12));
                 }
-                if(!cycle_log) {
+                if(!BOX64ENV(rolling_log)) {
                     mutex_lock(&emu->context->mutex_trace);
                     printf_log(LOG_NONE, "%s =>", buff);
                     mutex_unlock(&emu->context->mutex_trace);
@@ -462,7 +462,7 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
                     snprintf(buff3, 63, " (errno=%d:\"%s\")", errno, strerror(errno));
                 else if(perr==3 && (S_EAX)==-1)
                     snprintf(buff3, 63, " (errno=%d:\"%s\")", errno, strerror(errno));
-                if(cycle_log) {
+                if(BOX64ENV(rolling_log)) {
                     if(ret_fmt==1)
                         snprintf(buffret, 128, "%d%s%s", S_EAX, buff2, buff3);
                     else
@@ -480,7 +480,7 @@ void x86Int3(x64emu_t* emu, uintptr_t* addr)
         }
         return;
     }
-    if(!box64_ignoreint3 && my_context->signals[SIGTRAP]) {
+    if(!BOX64ENV(ignoreint3) && my_context->signals[SIGTRAP]) {
         R_RIP = *addr;  // update RIP
         emit_signal(emu, SIGTRAP, NULL, 3);
     } else {
diff --git a/src/emu/x86syscall_32.c b/src/emu/x86syscall_32.c
index dc2bf76c..31f07aad 100644
--- a/src/emu/x86syscall_32.c
+++ b/src/emu/x86syscall_32.c
@@ -491,7 +491,7 @@ void EXPORT x86Syscall(x64emu_t *emu)
             break;
         case 449:
             #ifdef __NR_futex_waitv
-            if(box64_futex_waitv)
+            if(BOX64ENV(futex_waitv))
                 S_RAX = syscall(__NR_futex_waitv, R_EBX, R_ECX, R_EDX, R_ESI, R_EDI);
             else
             #endif
@@ -715,7 +715,7 @@ uint32_t EXPORT my32_syscall(x64emu_t *emu, uint32_t s, ptr_t* b)
 #endif
         case 449:
             #ifdef __NR_futex_waitv
-            if(box64_futex_waitv)
+            if(BOX64ENV(futex_waitv))
                 return syscall(__NR_futex_waitv, u32(0), u32(4), u32(8), u32(12), u32(16));
             else
             #endif
@@ -737,4 +737,4 @@ uint32_t EXPORT my32_syscall(x64emu_t *emu, uint32_t s, ptr_t* b)
     }
     return 0;
 }
-#endif //BOX32
\ No newline at end of file
+#endif //BOX32
diff --git a/src/emu/x87emu_private.c b/src/emu/x87emu_private.c
index 260a2be1..5d95a8e5 100644
--- a/src/emu/x87emu_private.c
+++ b/src/emu/x87emu_private.c
@@ -81,7 +81,7 @@ void fpu_fbld(x64emu_t* emu, uint8_t* s) {
 // long double (80bits) -> double (64bits)
 void LD2D(void* ld, void* d)
 {
-    if(box64_x87_no80bits) {
+    if(BOX64ENV(x87_no80bits)) {
         *(uint64_t*)d = *(uint64_t*)ld;
         return;
     }
@@ -160,7 +160,7 @@ void LD2D(void* ld, void* d)
 // double (64bits) -> long double (80bits)
 void D2LD(void* d, void* ld)
 {
-    if(box64_x87_no80bits) {
+    if(BOX64ENV(x87_no80bits)) {
         *(uint64_t*)ld = *(uint64_t*)d;
         return;
     }
@@ -214,7 +214,7 @@ void D2LD(void* d, void* ld)
 
 double FromLD(void* ld)
 {
-    if(box64_x87_no80bits)
+    if(BOX64ENV(x87_no80bits))
         return *(double*)ld;
     double ret; // cannot add = 0; it break factorio (issue when calling fmodl)
     LD2D(ld, &ret);
@@ -379,7 +379,7 @@ void fpu_fxrstor32(x64emu_t* emu, void* ed)
     emu->cw.x16 = p->ControlWord;
     emu->sw.x16 = p->StatusWord;
     emu->mxcsr.x32 = p->MxCsr;
-    if(box64_sse_flushto0)
+    if(BOX64ENV(sse_flushto0))
         applyFlushTo0(emu);
     emu->top = emu->sw.f.F87_TOP;
     uint8_t tags = p->TagWord;
@@ -404,7 +404,7 @@ void fpu_fxrstor64(x64emu_t* emu, void* ed)
     emu->cw.x16 = p->ControlWord;
     emu->sw.x16 = p->StatusWord;
     emu->mxcsr.x32 = p->MxCsr;
-    if(box64_sse_flushto0)
+    if(BOX64ENV(sse_flushto0))
         applyFlushTo0(emu);
     emu->top = emu->sw.f.F87_TOP;
     uint8_t tags = p->TagWord;
@@ -488,7 +488,7 @@ void fpu_xrstor(x64emu_t* emu, void* ed, int is32bits)
         emu->cw.x16 = p->ControlWord;
         emu->sw.x16 = p->StatusWord;
         emu->mxcsr.x32 = p->MxCsr;
-        if(box64_sse_flushto0)
+        if(BOX64ENV(sse_flushto0))
             applyFlushTo0(emu);
         emu->top = emu->sw.f.F87_TOP;
         uint8_t tags = p->TagWord;