about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-03-04 20:11:06 +0100
committerptitSeb <sebastien.chev@gmail.com>2021-03-04 20:11:06 +0100
commitf2a9066697b86d2764a73bba8e63d626814be5bc (patch)
tree2396825ed78a7bcb9d2950e302decbe0ec702cf3 /src
parentad05515b70dfa5c28dbd1552b4bc9df9bf98788c (diff)
downloadbox64-f2a9066697b86d2764a73bba8e63d626814be5bc.tar.gz
box64-f2a9066697b86d2764a73bba8e63d626814be5bc.zip
Added 0F 1F NOP opcode
Diffstat (limited to 'src')
-rwxr-xr-xsrc/emu/x64run.c10
-rw-r--r--src/emu/x64run0f.c70
-rwxr-xr-xsrc/main.c10
3 files changed, 87 insertions, 3 deletions
diff --git a/src/emu/x64run.c b/src/emu/x64run.c
index 34502ca5..5d37c153 100755
--- a/src/emu/x64run.c
+++ b/src/emu/x64run.c
@@ -146,6 +146,16 @@ x64emurun:
         GO(0x30, xor)                   /* XOR 0x30 -> 0x35 */
         #undef GO
 
+        case 0x0F:                      /* More instructions */
+            if(Run0F(emu)) {
+                unimp = 1;
+                goto fini;
+            }
+            if(emu->quit)
+                goto fini;
+            break;
+
+
         case 0x40:
         case 0x41:
         case 0x42:
diff --git a/src/emu/x64run0f.c b/src/emu/x64run0f.c
new file mode 100644
index 00000000..07eab35e
--- /dev/null
+++ b/src/emu/x64run0f.c
@@ -0,0 +1,70 @@
+#define _GNU_SOURCE

+#include <stdint.h>

+#include <stdio.h>

+#include <stdlib.h>

+#include <math.h>

+#include <string.h>

+#include <signal.h>

+#include <sys/types.h>

+#include <unistd.h>

+

+#include "debug.h"

+#include "box64stack.h"

+#include "x64emu.h"

+#include "x64run.h"

+#include "x64emu_private.h"

+#include "x64run_private.h"

+#include "x64primop.h"

+#include "x64trace.h"

+#include "x87emu_private.h"

+#include "box64context.h"

+//#include "my_cpuid.h"

+#include "bridge.h"

+//#include "signals.h"

+#ifdef DYNAREC

+#include "../dynarec/arm_lock_helper.h"

+#endif

+

+#define F8      *(uint8_t*)(R_RIP++)

+#define F8S     *(int8_t*)(R_RIP++)

+#define F16     *(uint16_t*)(R_RIP+=2, R_RIP-2)

+#define F32     *(uint32_t*)(R_RIP+=4, R_RIP-4)

+#define F32S    *(int32_t*)(R_RIP+=4, R_RIP-4)

+#define F64     *(uint64_t*)(R_RIP+=8, R_RIP-8)

+#define F64S    *(int64_t*)(R_RIP+=8, R_RIP-8)

+#define PK(a)   *(uint8_t*)(R_RIP+a)

+

+#define GETED oped=GetEd(emu, rex, nextop)

+#define GETGD opgd=GetGd(emu, rex, nextop)

+#define GETEB oped=GetEb(emu, rex, nextop)

+#define GETGB oped=GetGb(emu, rex, nextop)

+#define ED  oped

+#define GD  opgd

+#define EB  oped

+#define GB  oped->byte[0]

+

+int Run0F(x64emu_t *emu)

+{

+    uint8_t opcode;

+    uint8_t nextop;

+    reg64_t *oped, *opgd;

+    rex_t rex = {0};

+

+    opcode = F8;

+    while(opcode>=0x40 && opcode<=0x4f) {

+        rex.rex = opcode;

+        opcode = F8;

+    }

+

+    switch(opcode) {

+

+        case 0x1F:                      /* NOP (multi-byte) */

+            nextop = F8;

+            GETED;

+            break;

+        

+        default:

+            return 1;

+    }

+    return 0;

+}
\ No newline at end of file
diff --git a/src/main.c b/src/main.c
index 92b3c0e6..cf7af7ce 100755
--- a/src/main.c
+++ b/src/main.c
@@ -826,8 +826,9 @@ int main(int argc, const char **argv, const char **env) {
     // stack setup is much more complicated then just that!
     SetupInitialStack(emu); // starting here, the argv[] don't need free anymore
     SetupX64Emu(emu);
-    SetRAX(emu, my_context->argc);
-    SetRBX(emu, (uintptr_t)my_context->argv);
+    SetRSI(emu, my_context->argc);
+    SetRDX(emu, (uint64_t)my_context->argv);
+    SetRCX(emu, (uint64_t)my_context->envv);
 
     // child fork to handle traces
     pthread_atfork(NULL, NULL, my_child_fork);
@@ -894,9 +895,12 @@ int main(int argc, const char **argv, const char **env) {
 
     // emulate!
     printf_log(LOG_DEBUG, "Start x64emu on Main\n");
-    SetRAX(emu, my_context->argc);
+    SetRSI(emu, my_context->argc);
     SetRDX(emu, (uint64_t)my_context->argv);
+    SetRCX(emu, (uint64_t)my_context->envv);
     SetRIP(emu, my_context->ep);
+    PushExit(emu);
+    *(uint64_t*)GetRSP(emu) = my_context->argc;
     ResetFlags(emu);
     Run(emu, 0);
     // Get EAX