summaryrefslogtreecommitdiff
path: root/Source/Kernel/TaskManager
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/TaskManager')
-rw-r--r--Source/Kernel/TaskManager/V86/V86.ns.cpp29
-rw-r--r--Source/Kernel/TaskManager/V86/V86.ns.h36
-rw-r--r--Source/Kernel/TaskManager/V86/V86Thread.class.cpp28
-rw-r--r--Source/Kernel/TaskManager/V86/V86Thread.class.h21
4 files changed, 80 insertions, 34 deletions
diff --git a/Source/Kernel/TaskManager/V86/V86.ns.cpp b/Source/Kernel/TaskManager/V86/V86.ns.cpp
new file mode 100644
index 0000000..11a1626
--- /dev/null
+++ b/Source/Kernel/TaskManager/V86/V86.ns.cpp
@@ -0,0 +1,29 @@
+#include "V86.ns.h"
+#include <TaskManager/Task.ns.h>
+
+namespace V86 {
+
+u16int seg = V86_ALLOC_START;
+
+void run(v86_function_t& entry, registers_t &regs, u32int data) {
+ v86_retval_t ret;
+ ret.regs = &regs;
+ new V86Thread(&entry, &ret, data);
+ while (!ret.finished) Task::currThread()->sleep(10);
+}
+
+u16int allocSeg(u16int length) {
+ if (length & 0xF) length = (length & 0xFFFF0) + 0x10;
+ u16int segments = length / 16;
+ if (seg < V86_ALLOC_START) seg = V86_ALLOC_START;
+ if (seg + segments > V86_ALLOC_END) seg = V86_ALLOC_START;
+ u16int ret = seg;
+ seg += segments;
+ return ret;
+}
+
+void* alloc(u32int length) {
+ return FP_TO_LINEAR(allocSeg(length), 0);
+}
+
+}
diff --git a/Source/Kernel/TaskManager/V86/V86.ns.h b/Source/Kernel/TaskManager/V86/V86.ns.h
new file mode 100644
index 0000000..6e8797a
--- /dev/null
+++ b/Source/Kernel/TaskManager/V86/V86.ns.h
@@ -0,0 +1,36 @@
+#ifndef DEF_V86_NS_H
+#define DEF_V86_NS_H
+
+#include <TaskManager/V86/V86Thread.class.h>
+
+//For tweaking with far/linear pointers
+typedef u32int FARPTR;
+#define MK_FP(seg, off) ((FARPTR)(((u32int)(seg) << 16) | (u16int) (off)))
+#define FP_SEG(fp) (((FARPTR)fp) >> 16)
+#define FP_OFF(fp) (((FARPTR)fp) & 0xFFFF)
+#define LIN_SEG(ptr) (((size_t) ptr - ((size_t) ptr & 0xF)) / 16)
+#define LIN_OFF(ptr) (((size_t) ptr) & 0xF)
+#define FP_TO_LINEAR(seg, off) ((void*)((((u16int)(seg)) << 4) + ((u16int)(off))))
+inline FARPTR LINEAR_TO_FP(void* ptr) {
+ u32int seg, off;
+ off = LIN_OFF(ptr);
+ seg = LIN_SEG(ptr);
+ return MK_FP(seg, off);
+}
+
+// (in segments)
+#define V86_ALLOC_START 0x1000
+#define V86_ALLOC_END 0x9000
+
+
+//This sample V86 function switches to graphical mode 13. Useless.
+extern "C" v86_function_t v86test;
+
+namespace V86 {
+ void run(v86_function_t& entry, registers_t &regs, u32int data);
+
+ u16int allocSeg(u16int size);
+ void* alloc(u16int size);
+}
+
+#endif
diff --git a/Source/Kernel/TaskManager/V86/V86Thread.class.cpp b/Source/Kernel/TaskManager/V86/V86Thread.class.cpp
index babf5b6..7eab887 100644
--- a/Source/Kernel/TaskManager/V86/V86Thread.class.cpp
+++ b/Source/Kernel/TaskManager/V86/V86Thread.class.cpp
@@ -1,17 +1,7 @@
#include "V86Thread.class.h"
#include <TaskManager/Task.ns.h>
-u16int V86Thread::allocSeg = V86_ALLOC_START;
-
-u16int V86Thread::alloc(u16int length) {
- if (length & 0xF) length = (length & 0xFFFF0) + 0x10;
- u16int segments = length / 16;
- if (allocSeg < V86_ALLOC_START) allocSeg = V86_ALLOC_START;
- if (allocSeg + segments > V86_ALLOC_END) allocSeg = V86_ALLOC_START;
- u16int ret = allocSeg;
- allocSeg += segments;
- return ret;
-}
+#include <TaskManager/V86/V86.ns.h>
void V86Thread::runV86(V86Thread* thread, u32int data, u32int ss, u32int cs) {
thread->m_process->getPagedir()->switchTo();
@@ -75,14 +65,14 @@ V86Thread::V86Thread(v86_function_t* entry, v86_retval_t* ret, u32int data) : Th
m_process->getPagedir()->allocFrame(i, true, true);
}
- u16int cs = alloc(entry->size); //Alocate segments for the code to run in
+ u16int cs = V86::allocSeg(entry->size); //Alocate segments for the code to run in
u8int* codeptr = (u8int*)(FP_TO_LINEAR(cs, 0));
for (u32int i = ((u32int)(codeptr) & 0xFFFFF000); i < (u32int)(codeptr) + entry->size; i += 0x1000) {
m_process->getPagedir()->allocFrame(i, true, true);
}
memcpy(codeptr, entry->data, entry->size); //Copy the code there
- u16int ss = alloc(V86_STACKSIZE);
+ u16int ss = V86::allocSeg(V86_STACKSIZE);
u8int* stackptr = (u8int*)(FP_TO_LINEAR(ss, 0));
for (u32int i = ((u32int)stackptr & 0xFFFFF000); i < (u32int)stackptr + V86_STACKSIZE; i += 0x1000) {
m_process->getPagedir()->allocFrame(i, true, true);
@@ -154,6 +144,16 @@ bool V86Thread::handleV86GPF(registers_t *regs) {
return true;
case 0xCD: // INT N
if (ip[1] == 3) return false; //Breakpoint exception, here used for telling that thread has ended
+ if (ip[1] == 60) { //INT 60 is used so that the real mode code can retrieve some regs from caller
+ regs->eax = m_ret->regs->eax;
+ regs->ebx = m_ret->regs->ebx;
+ regs->ecx = m_ret->regs->ecx;
+ regs->edx = m_ret->regs->edx;
+ regs->edi = m_ret->regs->edi;
+ regs->esi = m_ret->regs->esi;
+ regs->eip = (u16int)(regs->eip + 2);
+ return true;
+ }
stack -= 3;
regs->useresp = ((regs->useresp & 0xFFFF) - 6) & 0xFFFF;
@@ -190,7 +190,7 @@ void V86Thread::handleException(registers_t *regs, int no) {
if (no == 13) { //General protection fault
if (!handleV86GPF(regs)) {
m_ret->finished = true;
- m_ret->regs = *regs;
+ *(m_ret->regs) = *regs;
Task::currentThreadExits(0);
return;
}
diff --git a/Source/Kernel/TaskManager/V86/V86Thread.class.h b/Source/Kernel/TaskManager/V86/V86Thread.class.h
index b14670b..591bea6 100644
--- a/Source/Kernel/TaskManager/V86/V86Thread.class.h
+++ b/Source/Kernel/TaskManager/V86/V86Thread.class.h
@@ -3,20 +3,8 @@
#include <TaskManager/Thread.class.h>
-typedef u32int FARPTR;
-#define MK_FP(seg, off) ((FARPTR)(((u32int)(seg) << 16) | (u16int) (off)))
-#define FP_SEG(fp) (((FARPTR)fp) >> 16)
-#define FP_OFF(fp) (((FARPTR)fp) & 0xFFFF)
-#define FP_TO_LINEAR(seg, off) ((void*)((((u16int)(seg)) << 4) + ((u16int)(off))))
-inline FARPTR LINEAR_TO_FP(void* ptr) {
- u32int seg, off;
- off = ((size_t) ptr) & 0xF;
- seg = ((size_t) ptr - ((size_t) ptr & 0xF)) / 16;
- return MK_FP(seg, off);
-}
-
struct v86_retval_t {
- registers_t regs;
+ registers_t *regs;
bool finished;
};
@@ -27,10 +15,6 @@ struct v86_function_t {
#define V86_STACKSIZE 1024
-// (in segments)
-#define V86_ALLOC_START 0x1000
-#define V86_ALLOC_END 0x9000
-
#define EFLAGS_IF 0x200
#define EFLAGS_VM 0x20000
#define VALID_FLAGS 0xDFF
@@ -44,9 +28,6 @@ class V86Thread : public Thread {
bool m_if; //V86 IF flag
- static u16int allocSeg;
- static u16int alloc(u16int length); //Returns a segment number
-
static void runV86(V86Thread* t, u32int data, u32int ss, u32int cs);
public: