diff options
author | Alexis211 <alexis211@gmail.com> | 2009-11-08 17:23:46 +0100 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-11-08 17:23:46 +0100 |
commit | 87a1dd39d0036f55f5bdbf4ef8921a4767d95825 (patch) | |
tree | 3eeb650ec3f12c031a0aa0d8b2571c6b15427d86 /Source/Kernel | |
parent | c712d7f6f801b073920c7b914ee1b95358113893 (diff) | |
download | Melon-87a1dd39d0036f55f5bdbf4ef8921a4767d95825.tar.gz Melon-87a1dd39d0036f55f5bdbf4ef8921a4767d95825.zip |
Nothing, really : put some utility functions in V86.ns
Diffstat (limited to 'Source/Kernel')
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 14 | ||||
-rw-r--r-- | Source/Kernel/Makefile | 1 | ||||
-rw-r--r-- | Source/Kernel/TaskManager/V86/V86.ns.cpp | 29 | ||||
-rw-r--r-- | Source/Kernel/TaskManager/V86/V86.ns.h | 36 | ||||
-rw-r--r-- | Source/Kernel/TaskManager/V86/V86Thread.class.cpp | 28 | ||||
-rw-r--r-- | Source/Kernel/TaskManager/V86/V86Thread.class.h | 21 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp | 2 |
7 files changed, 82 insertions, 49 deletions
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 26afdfd..afb22aa 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -31,18 +31,6 @@ #include <Ressources/Graphics/logo.text.cxd> -#include <TaskManager/V86/V86Thread.class.h> -extern v86_function_t v86test; - -void testV86() { - VirtualTerminal* vt = new ScrollableVT(15, 76, 200, SHELL_FGCOLOR, SHELL_BGCOLOR); - Task::currProcess()->setOutVT(vt); - v86_retval_t r; - new V86Thread(&v86test, &r, 0); - while (!r.finished); - PANIC("V86 TEST END"); -} - extern u32int end; //Placement address extern "C" void kmain(multiboot_info_t* mbd, u32int magic); @@ -196,8 +184,6 @@ void kmain(multiboot_info_t* mbd, u32int magic) { Sys::halt(); */ - testV86(); - Process* p = Process::run("/System/Applications/PaperWork.app", 0); if (p == 0) { PANIC("Could not launch PaperWork !"); diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile index 506faf4..218ae39 100644 --- a/Source/Kernel/Makefile +++ b/Source/Kernel/Makefile @@ -29,6 +29,7 @@ Objects = Core/loader.wtf.o \ TaskManager/Process-sc.class.o \ TaskManager/Thread.class.o \ TaskManager/V86/V86Thread.class.o \ + TaskManager/V86/V86.ns.o \ TaskManager/V86/v86.wtf.o \ TaskManager/Task.ns.o \ TaskManager/Task.wtf.o \ 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 ®s, u32int data) { + v86_retval_t ret; + ret.regs = ®s; + 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 ®s, 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: diff --git a/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp index b5ed9c3..9f3e349 100644 --- a/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp @@ -63,7 +63,7 @@ String VirtualTerminal::readLine(bool show) { while (!(tmp.hascmd && !tmp.haschar && tmp.command == KBDC_ENTER)) { if (tmp.hascmd && !tmp.haschar && tmp.command == KBDC_BACKSPACE) { if (!ret.empty()) ret = ret.substr(0, ret.size() - 1); - else put(" "); //Put a space so that cursor stays at same place + else if (show) put(" "); //Put a space so that cursor stays at same place } else if (tmp.hascmd && !tmp.haschar && tmp.command == KBDC_TAB) { ret += "\t"; } else if (tmp.haschar && !tmp.hascmd) { |