diff options
| author | rajdakin <rajdakin@gmail.com> | 2021-04-12 00:53:14 +0200 |
|---|---|---|
| committer | rajdakin <rajdakin@gmail.com> | 2021-04-14 13:11:51 +0200 |
| commit | 48d61351061dcf1ee3148c67d208f20bdf22a3b8 (patch) | |
| tree | 9859835d868d88cd8e151e0efd8308ac93581190 /src/emu | |
| parent | 0d38b1cd91d4265042396d3d1dbacac2e662ba00 (diff) | |
| download | box64-48d61351061dcf1ee3148c67d208f20bdf22a3b8.tar.gz box64-48d61351061dcf1ee3148c67d208f20bdf22a3b8.zip | |
First pass
Diffstat (limited to 'src/emu')
| -rwxr-xr-x | src/emu/x64emu.c | 9 | ||||
| -rwxr-xr-x | src/emu/x64int3.c | 8 | ||||
| -rwxr-xr-x | src/emu/x64primop.h | 4 | ||||
| -rw-r--r-- | src/emu/x64run64.c | 8 | ||||
| -rw-r--r-- | src/emu/x64run6766.c | 26 | ||||
| -rw-r--r-- | src/emu/x64run67660f.c | 26 | ||||
| -rwxr-xr-x | src/emu/x64run_private.c | 13 | ||||
| -rwxr-xr-x | src/emu/x64run_private.h | 8 | ||||
| -rw-r--r-- | src/emu/x64rundf.c | 4 | ||||
| -rw-r--r-- | src/emu/x64runf0.c | 4 | ||||
| -rwxr-xr-x | src/emu/x64syscall.c | 4 | ||||
| -rwxr-xr-x | src/emu/x64tls.c | 8 | ||||
| -rwxr-xr-x | src/emu/x87emu_private.h | 8 |
13 files changed, 71 insertions, 59 deletions
diff --git a/src/emu/x64emu.c b/src/emu/x64emu.c index c1f3946c..75ce18fd 100755 --- a/src/emu/x64emu.c +++ b/src/emu/x64emu.c @@ -109,6 +109,7 @@ EXPORTDYN void SetupX64Emu(x64emu_t *emu) { printf_log(LOG_DEBUG, "Setup X86_64 Emu\n"); + (void)emu; // Not doing much here... } #ifdef HAVE_TRACE @@ -130,6 +131,8 @@ void SetTraceEmu(uintptr_t start, uintptr_t end) void AddCleanup(x64emu_t *emu, void *p) { + (void)emu; + if(my_context->clean_sz == my_context->clean_cap) { my_context->clean_cap += 4; my_context->cleanups = (cleanup_t*)realloc(my_context->cleanups, sizeof(cleanup_t)*my_context->clean_cap); @@ -141,6 +144,8 @@ void AddCleanup(x64emu_t *emu, void *p) void AddCleanup1Arg(x64emu_t *emu, void *p, void* a) { + (void)emu; + if(my_context->clean_sz == my_context->clean_cap) { my_context->clean_cap += 4; my_context->cleanups = (cleanup_t*)realloc(my_context->cleanups, sizeof(cleanup_t)*my_context->clean_cap); @@ -473,7 +478,9 @@ void EmuCall(x64emu_t* emu, uintptr_t addr) uint64_t ReadTSC(x64emu_t* emu) { - //TODO: implement hardware counter read? + (void)emu; + + //TODO: implement hardware counter read? (only available in kernel space?) // Read the TimeStamp Counter as 64bits. // this is supposed to be the number of instructions executed since last reset // fall back to gettime... diff --git a/src/emu/x64int3.c b/src/emu/x64int3.c index 21d7d10b..4c9ceb3d 100755 --- a/src/emu/x64int3.c +++ b/src/emu/x64int3.c @@ -161,7 +161,7 @@ void x64Int3(x64emu_t* emu) pthread_mutex_lock(&emu->context->mutex_trace); if(post) switch(post) { - case 1: snprintf(buff2, 63, " [%d sec %d nsec]", pu32?pu32[0]:-1, pu32?pu32[1]:-1); + case 1: snprintf(buff2, 63, " [%d sec %d nsec]", pu32?pu32[0]:~0u, pu32?pu32[1]:~0u); break; case 2: snprintf(buff2, 63, "(%s)", R_RAX?((char*)R_RAX):"nil"); break; @@ -175,8 +175,8 @@ void x64Int3(x64emu_t* emu) snprintf(buff2, 63, " size=%dx%d, pitch=%d, pixels=%p", p[2], p[3], p[4], p+5); else snprintf(buff2, 63, "NULL Surface"); - } - break; + } + break; } if(perr==1 && ((int)R_EAX)<0) snprintf(buff3, 63, " (errno=%d:\"%s\")", errno, strerror(errno)); @@ -199,4 +199,4 @@ void x64Int3(x64emu_t* emu) int GetTID() { return syscall(SYS_gettid); -} \ No newline at end of file +} diff --git a/src/emu/x64primop.h b/src/emu/x64primop.h index e42c7062..ae2f9a02 100755 --- a/src/emu/x64primop.h +++ b/src/emu/x64primop.h @@ -235,21 +235,25 @@ static inline uint64_t neg64(x64emu_t *emu, uint64_t s) static inline uint8_t not8(x64emu_t *emu, uint8_t s) { + (void)emu; // No flags affected return ~s; } static inline uint16_t not16(x64emu_t *emu, uint16_t s) { + (void)emu; // No flags affected return ~s; } static inline uint32_t not32(x64emu_t *emu, uint32_t s) { + (void)emu; // No flags affected return ~s; } static inline uint64_t not64(x64emu_t *emu, uint64_t s) { + (void)emu; // No flags affected return ~s; } diff --git a/src/emu/x64run64.c b/src/emu/x64run64.c index 3e8bdbff..ae4dbe63 100644 --- a/src/emu/x64run64.c +++ b/src/emu/x64run64.c @@ -26,9 +26,9 @@ int Run64(x64emu_t *emu, rex_t rex) { uint8_t opcode; uint8_t nextop; - uint8_t tmp8u; - int16_t tmp16s; - uint16_t tmp16u; + uint8_t tmp8u; (void)tmp8u; + int16_t tmp16s; (void)tmp16s; + uint16_t tmp16u; (void)tmp16u; int32_t tmp32s; uint32_t tmp32u; uint64_t tmp64u; @@ -318,4 +318,4 @@ int Run64(x64emu_t *emu, rex_t rex) return 1; } return 0; -} \ No newline at end of file +} diff --git a/src/emu/x64run6766.c b/src/emu/x64run6766.c index 256a2671..2702012c 100644 --- a/src/emu/x64run6766.c +++ b/src/emu/x64run6766.c @@ -27,16 +27,18 @@ int Run6766(x64emu_t *emu, rex_t rex, int rep) { + // Hmmmm.... + (void)rep; uint8_t opcode; - uint8_t nextop; - int8_t tmp8s; - uint8_t tmp8u, tmp8u2; - int16_t tmp16s; - uint16_t tmp16u, tmp16u2; - int32_t tmp32s; - int64_t tmp64s; - uint64_t tmp64u, tmp64u2, tmp64u3; - reg64_t *oped, *opgd; + uint8_t nextop; (void)nextop; + int8_t tmp8s; (void)tmp8s; + uint8_t tmp8u, tmp8u2; (void)tmp8u; (void)tmp8u2; + int16_t tmp16s; (void)tmp16s; + uint16_t tmp16u, tmp16u2; (void)tmp16u; (void)tmp16u2; + int32_t tmp32s; (void)tmp32s; + int64_t tmp64s; (void)tmp64s; + uint64_t tmp64u, tmp64u2, tmp64u3; (void)tmp64u; (void)tmp64u2; (void)tmp64u3; + reg64_t *oped, *opgd; (void)oped; (void)opgd; opcode = F8; @@ -47,7 +49,7 @@ int Run6766(x64emu_t *emu, rex_t rex, int rep) rep = opcode-0xF1; opcode = F8; } - // REX prefix before the F0 are ignored + // REX prefix before the 66 are ignored rex.rex = 0; while(opcode>=0x40 && opcode<=0x4f) { rex.rex = opcode; @@ -56,11 +58,11 @@ int Run6766(x64emu_t *emu, rex_t rex, int rep) switch(opcode) { - case 0x0F: /* more opcdes */ + case 0x0F: /* more opcodes */ return Run67660F(emu, rex); default: return 1; } return 0; -} \ No newline at end of file +} diff --git a/src/emu/x64run67660f.c b/src/emu/x64run67660f.c index e5a9d1f8..6be0b044 100644 --- a/src/emu/x64run67660f.c +++ b/src/emu/x64run67660f.c @@ -26,22 +26,22 @@ int Run67660F(x64emu_t *emu, rex_t rex) { uint8_t opcode; uint8_t nextop; - uint8_t tmp8u; - int8_t tmp8s; - int16_t tmp16s; - uint16_t tmp16u; - int32_t tmp32s; - uint32_t tmp32u; - uint64_t tmp64u; - reg64_t *oped, *opgd; - sse_regs_t *opex, *opgx, eax1, *opex2; - mmx87_regs_t *opem, *opgm; + int8_t tmp8s; (void)tmp8s; + uint8_t tmp8u; (void)tmp8u; + int16_t tmp16s; (void)tmp16s; + uint16_t tmp16u; (void)tmp16u; + int32_t tmp32s; (void)tmp32s; + uint32_t tmp32u; (void)tmp32u; + int64_t tmp64s; (void)tmp64s; + uint64_t tmp64u; (void)tmp64u; + reg64_t *oped, *opgd; (void)oped; (void)opgd; + sse_regs_t *opex, *opgx; opcode = F8; switch(opcode) { - case 0x6F: /* MOVDQA Gx,Ex */ + case 0x6F: /* MOVDQA Gx,Ex */ nextop = F8; GETEX32(0); GETGX; @@ -49,7 +49,7 @@ int Run67660F(x64emu_t *emu, rex_t rex) GX->q[1] = EX->q[1]; break; - case 0x76: /* PCMPEQD Gx,Ex */ + case 0x76: /* PCMPEQD Gx,Ex */ nextop = F8; GETEX32(0); GETGX; @@ -61,4 +61,4 @@ int Run67660F(x64emu_t *emu, rex_t rex) return 1; } return 0; -} \ No newline at end of file +} diff --git a/src/emu/x64run_private.c b/src/emu/x64run_private.c index c6a7ac88..4eeddd06 100755 --- a/src/emu/x64run_private.c +++ b/src/emu/x64run_private.c @@ -30,6 +30,8 @@ int32_t EXPORT my___libc_start_main(x64emu_t* emu, int *(main) (int, char * *, char * *), int argc, char * * ubp_av, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void (* stack_end)) { + (void)argc; (void)ubp_av; (void)fini; (void)rtld_fini; (void)stack_end; + // let's cheat and set all args... if(init) { PushExit(emu); @@ -944,7 +946,7 @@ uintptr_t GetSegmentBaseEmu(x64emu_t* emu, int seg) const char* getAddrFunctionName(uintptr_t addr) { static char ret[1000]; - uint32_t sz = 0; + uint64_t sz = 0; uintptr_t start = 0; const char* symbname = FindNearestSymbolName(FindElfAddress(my_context, addr), (void*)addr, &start, &sz); if(symbname && addr>=start && (addr<(start+sz) || !sz)) { @@ -959,7 +961,7 @@ const char* getAddrFunctionName(uintptr_t addr) void printFunctionAddr(uintptr_t nextaddr, const char* text) { - uint32_t sz = 0; + uint64_t sz = 0; uintptr_t start = 0; const char* symbname = FindNearestSymbolName(FindElfAddress(my_context, nextaddr), (void*)nextaddr, &start, &sz); if(symbname && nextaddr>=start && (nextaddr<(start+sz) || !sz)) { @@ -991,6 +993,7 @@ void PrintTrace(x64emu_t* emu, uintptr_t ip, int dynarec) my_context->trace_dynarec = dynarec; } #else + (void)dynarec; if(my_context->trace_tid != tid) { printf_log(LOG_NONE, "Thread %04d|\n", tid); my_context->trace_tid = tid; @@ -1178,6 +1181,8 @@ reg64_t* GetEb32O(x64emu_t *emu, rex_t rex, uint8_t v, uint8_t delta, uintptr_t reg64_t* GetEw16(x64emu_t *emu, rex_t rex, uint8_t v) { + (void)rex; + uint8_t m = v&0xC7; // filter Ed if(m>=0xC0) { return &emu->regs[(m&0x07)]; @@ -1205,6 +1210,8 @@ reg64_t* GetEw16(x64emu_t *emu, rex_t rex, uint8_t v) reg64_t* GetEw16off(x64emu_t *emu, rex_t rex, uint8_t v, uintptr_t offset) { + (void)rex; + uint32_t m = v&0xC7; // filter Ed if(m>=0xC0) { return &emu->regs[(m&0x07)]; @@ -1279,6 +1286,8 @@ reg64_t* GetGb(x64emu_t *emu, rex_t rex, uint8_t v) mmx87_regs_t* GetGm(x64emu_t *emu, rex_t rex, uint8_t v) { + (void)rex; + uint8_t m = (v&0x38)>>3; return &emu->mmx87[m&7]; } diff --git a/src/emu/x64run_private.h b/src/emu/x64run_private.h index e30edbec..525771f2 100755 --- a/src/emu/x64run_private.h +++ b/src/emu/x64run_private.h @@ -123,12 +123,6 @@ int RunDF(x64emu_t *emu, rex_t rex); int RunF0(x64emu_t *emu, rex_t rex); int RunF20F(x64emu_t *emu, rex_t rex); int RunF30F(x64emu_t *emu, rex_t rex); -//void Run66D9(x64emu_t *emu); // x87 -//void Run6766(x64emu_t *emu); -//void RunGS(x64emu_t *emu); -//void RunFS(x64emu_t *emu); -//void RunFS66(x64emu_t *emu, uintptr_t tlsdata); -//void RunLock66(x64emu_t *emu); void x64Syscall(x64emu_t *emu); void x64Int3(x64emu_t* emu); @@ -146,4 +140,4 @@ const char* GetNativeName(void* p); void PrintTrace(x64emu_t* emu, uintptr_t ip, int dynarec); #endif -#endif //__X86RUN_PRIVATE_H_ \ No newline at end of file +#endif //__X86RUN_PRIVATE_H_ diff --git a/src/emu/x64rundf.c b/src/emu/x64rundf.c index 613c90f8..7abf665a 100644 --- a/src/emu/x64rundf.c +++ b/src/emu/x64rundf.c @@ -162,7 +162,7 @@ int RunDF(x64emu_t *emu, rex_t rex) break; case 7: /* FISTP i64 */ GETED(0); - if(STll(0).ref==ST(0).q) + if(STll(0).ref==ST(0).sq) ED->sq[0] = STll(0).ll; else { if(isgreater(ST0.d, (double)(int64_t)0x7fffffffffffffffLL) || isless(ST0.d, -(double)(int64_t)0x7fffffffffffffffLL) || !isfinite(ST0.d)) @@ -177,4 +177,4 @@ int RunDF(x64emu_t *emu, rex_t rex) } } return 0; -} \ No newline at end of file +} diff --git a/src/emu/x64runf0.c b/src/emu/x64runf0.c index 883b35ac..41b51362 100644 --- a/src/emu/x64runf0.c +++ b/src/emu/x64runf0.c @@ -31,7 +31,7 @@ int RunF0(x64emu_t *emu, rex_t rex) uint8_t opcode; uint8_t nextop; uint8_t tmp8u; - int32_t tmp32s; + int32_t tmp32s; (void)tmp32s; uint32_t tmp32u, tmp32u2; int64_t tmp64s; uint64_t tmp64u, tmp64u2; @@ -700,4 +700,4 @@ int RunF0(x64emu_t *emu, rex_t rex) return 1; } return 0; -} \ No newline at end of file +} diff --git a/src/emu/x64syscall.c b/src/emu/x64syscall.c index e4d167a0..681a5583 100755 --- a/src/emu/x64syscall.c +++ b/src/emu/x64syscall.c @@ -57,7 +57,7 @@ int fcntl(int fd, int cmd, ... /* arg */ ); // Syscall table for x86_64 can be found typedef struct scwrap_s { - int x64s; + uint32_t x64s; // 32 bits? int nats; int nbpars; } scwrap_t; @@ -135,7 +135,7 @@ struct mmap_arg_struct { void EXPORT x64Syscall(x64emu_t *emu) { RESET_FLAGS(emu); - uint32_t s = R_EAX; + uint32_t s = R_EAX; // EAX? (syscalls only go up to 547 anyways) printf_log(LOG_DEBUG, "%p: Calling syscall 0x%02X (%d) %p %p %p %p %p %p", (void*)R_RIP, s, s, (void*)R_RDI, (void*)R_RSI, (void*)R_RDX, (void*)R_R10, (void*)R_R8, (void*)R_R9); // check wrapper first int cnt = sizeof(syscallwrap) / sizeof(scwrap_t); diff --git a/src/emu/x64tls.c b/src/emu/x64tls.c index 2396eee6..783a1b2f 100755 --- a/src/emu/x64tls.c +++ b/src/emu/x64tls.c @@ -123,7 +123,7 @@ uint32_t my_modify_ldt(x64emu_t* emu, int op, thread_area_t* td, int size) pthread_setspecific(my_context->segtls[idx].key, (void*)my_context->segtls[idx].base); */ - ResetSegmentsCache(thread_get_emu()); + ResetSegmentsCache(emu); return 0; } @@ -148,11 +148,11 @@ static tlsdatasize_t* setupTLSData(box64context_t* context) uintptr_t dtp = (uintptr_t)ptr+context->tlssize+POS_TLS; memcpy((void*)(tlsptr+sizeof(void*)), &dtp, sizeof(void*)); if(dtsize) { - for (size_t i=0; i<context->elfsize; ++i) { + for (int i=0; i<context->elfsize; ++i) { // set pointer dtp = (uintptr_t)ptr + (context->tlssize + GetTLSBase(context->elfs[i])); - memcpy((void*)((uintptr_t)ptr+context->tlssize+POS_TLS+i*16), &dtp, sizeof(void*)); - memcpy((void*)((uintptr_t)ptr+context->tlssize+POS_TLS+i*16+8), &i, sizeof(void*)); // index + *(uint64_t*)((uintptr_t)ptr+context->tlssize+POS_TLS+i*16) = dtp; + *(uint64_t*)((uintptr_t)ptr+context->tlssize+POS_TLS+i*16+8) = i; // index } } memcpy((void*)((uintptr_t)ptr+context->tlssize+0x10), &context->vsyscall, sizeof(void*)); // address of vsyscall diff --git a/src/emu/x87emu_private.h b/src/emu/x87emu_private.h index f188187a..fc71b6d1 100755 --- a/src/emu/x87emu_private.h +++ b/src/emu/x87emu_private.h @@ -14,10 +14,6 @@ typedef struct x64emu_s x64emu_t; #define LN2 0.69314718055994531 #define LG2 0.3010299956639812 -//void Run66D9(x64emu_t *emu); -//void Run66DD(x64emu_t *emu); -//void RunDF(x64emu_t *emu); - #define ST0 emu->mmx87[emu->top] #define ST1 emu->mmx87[(emu->top+1)&7] #define ST(a) emu->mmx87[(emu->top+(a))&7] @@ -58,8 +54,8 @@ static inline void fpu_do_free(x64emu_t* emu, int i) { emu->p_regs[(emu->top+i)&7].tag = 0b11; // empty // check if all empty - for(int i=0; i<8; ++i) - if(emu->p_regs[i].tag != 0b11) + for(int j=0; j<8; ++j) + if(emu->p_regs[j].tag != 0b11) return; emu->fpu_stack = 0; } |