summaryrefslogtreecommitdiff
path: root/run/dos_emu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'run/dos_emu.cpp')
-rw-r--r--run/dos_emu.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/run/dos_emu.cpp b/run/dos_emu.cpp
new file mode 100644
index 0000000..f8e294d
--- /dev/null
+++ b/run/dos_emu.cpp
@@ -0,0 +1,49 @@
+#include "dos_emu.hpp"
+
+#include <cstdint>
+#include <cstdlib>
+#include <cstdio>
+
+#include <atomic>
+
+#include <ucontext.h>
+
+static void dos_functions(mcontext_t& mcontext);
+static void dpmi_functions(mcontext_t& mcontext);
+
+void dos_emu_handler(int, siginfo_t*, void* c) {
+ ucontext_t* context = (ucontext_t*) c;
+
+ uint8_t* instruction = (uint8_t*) context->uc_mcontext.gregs[REG_EIP];
+ fprintf(stderr, "eip: 0x%lx\n", instruction);
+ if (instruction[0] == 0xFB) //mnemonic STI
+ {
+ //we cant do this in user space so ignore for now.
+ context->uc_mcontext.gregs[REG_EIP] += 1;
+ }
+ else if (instruction[0] == 0xCD) //mnemonic INT
+ {
+ if(instruction[1] == 0x21) {
+ dos_functions(context->uc_mcontext);
+ }
+ if(instruction[1] == 0x31) {
+ dpmi_functions(context->uc_mcontext);
+ }
+
+ //skip the interrupt and hopefully we handled it owk.
+ context->uc_mcontext.gregs[REG_EIP] += 2;
+ } else {
+ //whoops we fucked up something fierce.
+ abort();
+ }
+
+ return;
+}
+
+static void dos_functions(mcontext_t&) {
+
+}
+
+static void dpmi_functions(mcontext_t&) {
+
+}