From 866580161b826443bed3862b8315cefd505de37c Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Tue, 20 Oct 2009 18:10:29 +0200 Subject: We now have call tables for ressources. instead of adding calls to ressource in the constructor. --- Source/Kernel/SyscallManager/Res.ns.cpp | 6 +- Source/Kernel/SyscallManager/Ressource.class.cpp | 68 +++++++--------------- Source/Kernel/SyscallManager/Ressource.class.h | 18 +++--- Source/Kernel/TaskManager/Process.class.cpp | 14 +++-- Source/Kernel/TaskManager/Process.class.h | 9 +-- Source/Kernel/TaskManager/Thread.class.cpp | 15 +++-- Source/Kernel/TaskManager/Thread.class.h | 9 +-- .../Kernel/VTManager/VirtualTerminal-sc.proto.cpp | 30 ++++++++-- Source/Kernel/VTManager/VirtualTerminal.proto.cpp | 20 +++++-- Source/Kernel/VTManager/VirtualTerminal.proto.h | 5 ++ Source/Library/Interface/Process.iface.h | 8 +-- Source/Library/Interface/Thread.iface.h | 6 +- Source/Library/Interface/VirtualTerminal.iface.h | 17 ++++-- Source/Library/Userland/Binding/Process.class.h | 10 ++-- Source/Library/Userland/Binding/Thread.class.h | 8 +-- .../Userland/Binding/VirtualTerminal.class.h | 27 ++++++--- 16 files changed, 153 insertions(+), 117 deletions(-) (limited to 'Source') diff --git a/Source/Kernel/SyscallManager/Res.ns.cpp b/Source/Kernel/SyscallManager/Res.ns.cpp index 1779a00..7902f2d 100644 --- a/Source/Kernel/SyscallManager/Res.ns.cpp +++ b/Source/Kernel/SyscallManager/Res.ns.cpp @@ -43,9 +43,9 @@ void unregisterRes(u32int id) { u32int call(u32int ressource, u8int wat, u32int a, u32int b, u32int c, u32int d, u32int e) { if (ressource == 0xFFFFFE) { //TODO : return ressource id for some stuff for current process - if (a == VT_IFACE_OBJTYPE) return Task::currProcess()->getVirtualTerminal()->resId(); - if (a == PR_IFACE_OBJTYPE) return Task::currProcess()->resId(); - if (a == TH_IFACE_OBJTYPE) return Task::currThread()->resId(); + if (a == VTIF_OBJTYPE) return Task::currProcess()->getVirtualTerminal()->resId(); + if (a == PRIF_OBJTYPE) return Task::currProcess()->resId(); + if (a == THIF_OBJTYPE) return Task::currThread()->resId(); return 0; } else { if (ressource > size or ressources[ressource] == 0) { diff --git a/Source/Kernel/SyscallManager/Ressource.class.cpp b/Source/Kernel/SyscallManager/Ressource.class.cpp index 4e62d79..f2aaccb 100644 --- a/Source/Kernel/SyscallManager/Ressource.class.cpp +++ b/Source/Kernel/SyscallManager/Ressource.class.cpp @@ -1,64 +1,40 @@ #include "Ressource.class.h" #include -Ressource::Ressource(u8int type) { +Ressource::Ressource(u8int type, call_t* callTable) { m_id = Res::registerRes(this); m_type = type; - m_calls = 0; + m_callTables = 0; - addCall0(0, (call0)&Ressource::resType); + addCallTable(callTable); } Ressource::~Ressource() { Res::unregisterRes(m_id); - delete m_calls; + delete m_callTables; } -void Ressource::addCall0(u8int id, call0 c) { - call_t e = {0, id, {c}}; - m_calls = m_calls->cons(e); -} - -void Ressource::addCall1(u8int id, call1 c) { - call_t e = {1, id, {0}}; - e.c1 = c; - m_calls = m_calls->cons(e); -} - -void Ressource::addCall2(u8int id, call2 c) { - call_t e = {2, id, {0}}; - e.c2 = c; - m_calls = m_calls->cons(e); -} - -void Ressource::addCall3(u8int id, call3 c) { - call_t e = {3, id, {0}}; - e.c3 = c; - m_calls = m_calls->cons(e); -} - -void Ressource::addCall4(u8int id, call4 c) { - call_t e = {4, id, {0}}; - e.c4 = c; - m_calls = m_calls->cons(e); -} - -void Ressource::addCall5(u8int id, call5 c) { - call_t e = {5, id, {0}}; - e.c5 = c; - m_calls = m_calls->cons(e); +void Ressource::addCallTable(call_t* callTable) { + if (callTable != 0) m_callTables = m_callTables->cons(callTable); } u32int Ressource::doCall(u8int id, u32int a, u32int b, u32int c, u32int d, u32int e) { - for (SimpleList *iter = m_calls; iter != 0; iter = iter->next()) { - call_t &ce = iter->v(); - if (ce.id == id) { - if (ce.params == 0) return (this->*(ce.c0))(); - if (ce.params == 1) return (this->*(ce.c1))(a); - if (ce.params == 2) return (this->*(ce.c2))(a, b); - if (ce.params == 3) return (this->*(ce.c3))(a, b, c); - if (ce.params == 4) return (this->*(ce.c4))(a, b, c, d); - if (ce.params == 5) return (this->*(ce.c5))(a, b, c, d, e); + if (id == 0) return m_type; + + for (SimpleList *iter = m_callTables; iter != 0; iter = iter->next()) { + call_t* ct = iter->v(); + u32int i = 0; + while (ct[i].id != 0) { + call_t &ce = ct[i]; + if (ce.id == id) { + if (ce.params == 0) return (this->*(ce.c0))(); + if (ce.params == 1) return (this->*(ce.c1))(a); + if (ce.params == 2) return (this->*(ce.c2))(a, b); + if (ce.params == 3) return (this->*(ce.c3))(a, b, c); + if (ce.params == 4) return (this->*(ce.c4))(a, b, c, d); + if (ce.params == 5) return (this->*(ce.c5))(a, b, c, d, e); + } + i++; } } return (u32int) - 1; diff --git a/Source/Kernel/SyscallManager/Ressource.class.h b/Source/Kernel/SyscallManager/Ressource.class.h index 5f4e6bf..f58276b 100644 --- a/Source/Kernel/SyscallManager/Ressource.class.h +++ b/Source/Kernel/SyscallManager/Ressource.class.h @@ -12,6 +12,13 @@ typedef u32int (Ressource::*call3)(u32int, u32int, u32int); typedef u32int (Ressource::*call4)(u32int, u32int, u32int, u32int); typedef u32int (Ressource::*call5)(u32int, u32int, u32int, u32int, u32int); +#define CALL0(id, ptr) {0, id, {(call0)ptr}} +#define CALL1(id, ptr) {1, id, {c1: (call1)ptr}} +#define CALL2(id, ptr) {2, id, {c2: (call2)ptr}} +#define CALL3(id, ptr) {3, id, {c3: (call3)ptr}} +#define CALL4(id, ptr) {4, id, {c4: (call4)ptr}} +#define CALL5(id, ptr) {5, id, {c5: (call5)ptr}} + struct call_t { u8int params; u8int id; @@ -32,18 +39,13 @@ class Ressource { u32int m_id; u32int m_type; - SimpleList *m_calls; + SimpleList *m_callTables; protected: - Ressource(u8int type); + Ressource(u8int type, call_t* callTable = 0); ~Ressource(); - void addCall0(u8int id, call0 c); - void addCall1(u8int id, call1 c); - void addCall2(u8int id, call2 c); - void addCall3(u8int id, call3 c); - void addCall4(u8int id, call4 c); - void addCall5(u8int id, call5 c); + void addCallTable(call_t* callTable); public: u32int doCall(u8int id, u32int a, u32int b, u32int c, u32int d, u32int e); diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp index aae8fce..7ebac72 100644 --- a/Source/Kernel/TaskManager/Process.class.cpp +++ b/Source/Kernel/TaskManager/Process.class.cpp @@ -9,7 +9,14 @@ namespace Mem { extern Heap kheap; } -Process::Process() : Ressource(PR_IFACE_OBJTYPE) { //Private constructor, does nothing +call_t Process::m_callTable[] = { + CALL0(PRIF_EXIT, &Process::exitSC), + CALL1(PRIF_ALLOCPAGE, &Process::allocPageSC), + CALL1(PRIF_FREEPAGE, &Process::freePageSC), + CALL0(0, 0) +}; + +Process::Process() : Ressource(PRIF_OBJTYPE, m_callTable) { //Private constructor, does nothing } Process* Process::createKernel(String cmdline, VirtualTerminal *vt) { @@ -54,10 +61,7 @@ Process* Process::run(String filename, FSNode* cwd, u32int uid) { } } -Process::Process(String cmdline, u32int uid) : Ressource(PR_IFACE_OBJTYPE) { - addCall0(PR_IFACE_EXIT, (call0)&Process::exitSC); - addCall1(PR_IFACE_ALLOCPAGE, (call1)&Process::allocPageSC); - addCall1(PR_IFACE_FREEPAGE, (call1)&Process::freePageSC); +Process::Process(String cmdline, u32int uid) : Ressource(PRIF_OBJTYPE, m_callTable) { m_pid = Task::nextPid(); m_cmdline = cmdline; m_retval = 0; diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h index afdfe20..0013dfb 100644 --- a/Source/Kernel/TaskManager/Process.class.h +++ b/Source/Kernel/TaskManager/Process.class.h @@ -46,6 +46,11 @@ class Process : public Ressource { Vector m_threads; SimpleList *m_fileDescriptors; + + //System calls + static call_t m_callTable[]; + u32int exitSC(); + u32int allocPageSC(u32int); public: static Process* createKernel(String cmdline, VirtualTerminal *vt); //Also creates a Thread for what's curently happening @@ -68,10 +73,6 @@ class Process : public Ressource { VirtualTerminal* getVirtualTerminal(); void setVirtualTerminal(VirtualTerminal* vt); u32int getState() { return m_state; } - - //System calls - u32int exitSC(); - u32int allocPageSC(u32int); u32int freePageSC(u32int); }; diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp index 98fa32d..d846630 100644 --- a/Source/Kernel/TaskManager/Thread.class.cpp +++ b/Source/Kernel/TaskManager/Thread.class.cpp @@ -6,6 +6,12 @@ #include +call_t Thread::m_callTable[] = { + CALL1(THIF_SLEEP, &Thread::sleepSC), + CALL1(THIF_FINISH, &Thread::finishSC), + CALL0(0, 0) +}; + void runThread(Thread* thread, void* data, thread_entry_t entry_point) { if (thread->m_isKernel) { asm volatile("sti"); @@ -51,11 +57,11 @@ void runThread(Thread* thread, void* data, thread_entry_t entry_point) { } } -Thread::Thread() : Ressource(TH_IFACE_OBJTYPE) { //Private constructor, does nothing +Thread::Thread() : Ressource(THIF_OBJTYPE, m_callTable) { //Private constructor, does nothing m_xchgspace = 0; } -Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) : Ressource(TH_IFACE_OBJTYPE) { +Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) : Ressource(THIF_OBJTYPE, m_callTable) { if (iskernel) { setup(Task::getKernelProcess(), entry_point, data, true); } else { @@ -63,7 +69,7 @@ Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) : Ressourc } } -Thread::Thread(Process* process, thread_entry_t entry_point, void* data) : Ressource(TH_IFACE_OBJTYPE) { +Thread::Thread(Process* process, thread_entry_t entry_point, void* data) : Ressource(THIF_OBJTYPE, m_callTable) { setup(process, entry_point, data, false); } @@ -81,9 +87,6 @@ Thread::~Thread() { } void Thread::setup(Process* process, thread_entry_t entry_point, void* data, bool isKernel) { - addCall1(TH_IFACE_SLEEP, (call1)&Thread::sleepSC); - addCall1(TH_IFACE_FINISH, (call1)&Thread::finishSC); - m_xchgspace = 0; m_isKernel = isKernel; m_process = process; diff --git a/Source/Kernel/TaskManager/Thread.class.h b/Source/Kernel/TaskManager/Thread.class.h index 42baa86..5938e2e 100644 --- a/Source/Kernel/TaskManager/Thread.class.h +++ b/Source/Kernel/TaskManager/Thread.class.h @@ -37,6 +37,11 @@ class Thread : public Ressource { void setup(Process* process, thread_entry_t entry_point, void* data, bool isKernel); + //Syscalls + static call_t m_callTable[]; + u32int sleepSC(u32int msecs); + u32int finishSC(u32int errcode); + public: Thread(thread_entry_t entry_point, void* data, bool iskernel = false); //Assumes process is current process, or is kprocess if isk Thread(Process* process, thread_entry_t entry_point, void* data); @@ -63,10 +68,6 @@ class Thread : public Ressource { } return false; } - - //Syscalls - u32int sleepSC(u32int msecs); - u32int finishSC(u32int errcode); }; #endif diff --git a/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp index e0c6e8d..0a4e14b 100644 --- a/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp @@ -5,17 +5,18 @@ u32int VirtualTerminal::writeHexSC(u32int number) { return 0; } -u32int VirtualTerminal::writeSC(u32int wat) { - write(String::unserialize(wat)); - return 0; -} - u32int VirtualTerminal::writeDecSC(u32int n_hi, u32int n_lo) { s64int n = ((u64int)n_hi << 32) | n_lo; writeDec(n); return 0; } +u32int VirtualTerminal::writeSC(u32int wat) { + String *s = (String*)wat; + write(*s); + return 0; +} + u32int VirtualTerminal::putSC(u32int code) { put(WChar(code)); return 0; @@ -24,3 +25,22 @@ u32int VirtualTerminal::putSC(u32int code) { u32int VirtualTerminal::readLineSC() { return readLine().serialize(); } + +u32int VirtualTerminal::setColorSC(u32int x) { + setColor((x >> 8) & 0xFF, x & 0xFF); + return 0; +} + +u32int VirtualTerminal::setCursorLineSC(u32int l) { + setCursorLine(l); + return 0; +} + +u32int VirtualTerminal::setCursorColSC(u32int c) { + setCursorCol(c); + return 0; +} + +u32int VirtualTerminal::isBoxedSC() { + return (isBoxed() ? 1 : 0); +} diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp index dfd8f84..348113d 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp @@ -4,13 +4,21 @@ #include +call_t VirtualTerminal::m_callTable[] = { + CALL1(VTIF_WRITEHEX, &VirtualTerminal::writeHexSC), + CALL2(VTIF_WRITEDEC, &VirtualTerminal::writeDecSC), + CALL1(VTIF_WRITE, &VirtualTerminal::writeSC), + CALL1(VTIF_PUT, &VirtualTerminal::putSC), + CALL0(VTIF_READLINE, &VirtualTerminal::readLineSC), + CALL1(VTIF_SETCOLOR, &VirtualTerminal::setColorSC), + CALL1(VTIF_SETCSRLINE, &VirtualTerminal::setCursorLineSC), + CALL1(VTIF_SETCSRCOL, &VirtualTerminal::setCursorColSC), + CALL0(VTIF_ISBOXED, &VirtualTerminal::isBoxedSC), + CALL0(0, 0) +}; + VirtualTerminal::VirtualTerminal() : - Ressource(VT_IFACE_OBJTYPE), m_kbdMutex(false), m_kbdbuffMutex(false), m_kbdbuff() { - addCall1(VT_IFACE_WRITEHEX, (call1)&VirtualTerminal::writeHexSC); - addCall2(VT_IFACE_WRITEDEC, (call2)&VirtualTerminal::writeDecSC); - addCall1(VT_IFACE_WRITE, (call1)&VirtualTerminal::writeSC); - addCall1(VT_IFACE_PUT, (call1)&VirtualTerminal::putSC); - addCall0(VT_IFACE_READLINE, (call0)&VirtualTerminal::readLineSC); + Ressource(VTIF_OBJTYPE, m_callTable), m_kbdMutex(false), m_kbdbuffMutex(false), m_kbdbuff() { } VirtualTerminal::~VirtualTerminal() { diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.h b/Source/Kernel/VTManager/VirtualTerminal.proto.h index b0cd224..c81cf1a 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.proto.h +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.h @@ -20,11 +20,16 @@ class VirtualTerminal : public Ressource { Vector m_kbdbuff; //Key press events buffer //SYSCALLS : + static call_t m_callTable[]; u32int writeHexSC(u32int); u32int writeDecSC(u32int, u32int); u32int writeSC(u32int); u32int putSC(u32int); u32int readLineSC(); + u32int setColorSC(u32int); + u32int setCursorLineSC(u32int); + u32int setCursorColSC(u32int); + u32int isBoxedSC(); public: VirtualTerminal(); diff --git a/Source/Library/Interface/Process.iface.h b/Source/Library/Interface/Process.iface.h index 0956679..fe70833 100644 --- a/Source/Library/Interface/Process.iface.h +++ b/Source/Library/Interface/Process.iface.h @@ -1,9 +1,9 @@ #ifndef DEF_PROCESS_IFACE_H #define DEF_PROCESS_IFACE_H -#define PR_IFACE_OBJTYPE 0x20 -#define PR_IFACE_EXIT 0x01 -#define PR_IFACE_ALLOCPAGE 0x02 -#define PR_IFACE_FREEPAGE 0x03 +#define PRIF_OBJTYPE 0x20 +#define PRIF_EXIT 0x01 +#define PRIF_ALLOCPAGE 0x02 +#define PRIF_FREEPAGE 0x03 #endif diff --git a/Source/Library/Interface/Thread.iface.h b/Source/Library/Interface/Thread.iface.h index 2a64924..ac572b4 100644 --- a/Source/Library/Interface/Thread.iface.h +++ b/Source/Library/Interface/Thread.iface.h @@ -1,8 +1,8 @@ #ifndef DEF_THREAD_IFACE_H #define DEF_THREAD_IFACE_H -#define TH_IFACE_OBJTYPE 0x21 -#define TH_IFACE_SLEEP 0x01 -#define TH_IFACE_FINISH 0x02 +#define THIF_OBJTYPE 0x21 +#define THIF_SLEEP 0x01 +#define THIF_FINISH 0x02 #endif diff --git a/Source/Library/Interface/VirtualTerminal.iface.h b/Source/Library/Interface/VirtualTerminal.iface.h index 1525b6c..528e9e5 100644 --- a/Source/Library/Interface/VirtualTerminal.iface.h +++ b/Source/Library/Interface/VirtualTerminal.iface.h @@ -1,12 +1,17 @@ #ifndef DEF_VITRUALTERMINAL_IFACE_H #define DEF_VITRUALTERMINAL_IFACE_H -#define VT_IFACE_OBJTYPE 0x10 -#define VT_IFACE_PUT 0x01 -#define VT_IFACE_WRITEHEX 0x02 -#define VT_IFACE_WRITEDEC 0x03 -#define VT_IFACE_WRITE 0x04 +#define VTIF_OBJTYPE 0x10 +#define VTIF_PUT 0x01 +#define VTIF_WRITEHEX 0x02 +#define VTIF_WRITEDEC 0x03 +#define VTIF_WRITE 0x04 -#define VT_IFACE_READLINE 0x05 +#define VTIF_READLINE 0x05 + +#define VTIF_SETCOLOR 0x10 +#define VTIF_SETCSRLINE 0x11 +#define VTIF_SETCSRCOL 0x12 +#define VTIF_ISBOXED 0x13 #endif diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h index 88af9d6..e532ad3 100644 --- a/Source/Library/Userland/Binding/Process.class.h +++ b/Source/Library/Userland/Binding/Process.class.h @@ -5,18 +5,18 @@ class Process : public RessourceCaller { public: static Process get() { - u32int id = RessourceCaller::getObjId(PR_IFACE_OBJTYPE); + u32int id = RessourceCaller::getObjId(PRIF_OBJTYPE); return Process(id); } - Process(u32int id) : RessourceCaller(id, PR_IFACE_OBJTYPE) {} + Process(u32int id) : RessourceCaller(id, PRIF_OBJTYPE) {} void exit() { - doCall(PR_IFACE_EXIT); + doCall(PRIF_EXIT); } void allocPage(u32int pos) { - doCall(PR_IFACE_ALLOCPAGE, pos); + doCall(PRIF_ALLOCPAGE, pos); } void freePage(u32int pos) { - doCall(PR_IFACE_FREEPAGE, pos); + doCall(PRIF_FREEPAGE, pos); } }; diff --git a/Source/Library/Userland/Binding/Thread.class.h b/Source/Library/Userland/Binding/Thread.class.h index beef9c5..1a354d3 100644 --- a/Source/Library/Userland/Binding/Thread.class.h +++ b/Source/Library/Userland/Binding/Thread.class.h @@ -5,15 +5,15 @@ class Thread : public RessourceCaller { public: static Thread get() { - u32int id = RessourceCaller::getObjId(TH_IFACE_OBJTYPE); + u32int id = RessourceCaller::getObjId(THIF_OBJTYPE); return Thread(id); } - Thread(u32int id) : RessourceCaller(id, TH_IFACE_OBJTYPE) {} + Thread(u32int id) : RessourceCaller(id, THIF_OBJTYPE) {} void sleep(u32int msecs) { - doCall(TH_IFACE_SLEEP, msecs); + doCall(THIF_SLEEP, msecs); } void finish(u32int errcode) { - doCall(TH_IFACE_FINISH, errcode); + doCall(THIF_FINISH, errcode); } }; diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h index 67683b8..4329c86 100644 --- a/Source/Library/Userland/Binding/VirtualTerminal.class.h +++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h @@ -8,26 +8,37 @@ class VirtualTerminal : public RessourceCaller { public: static VirtualTerminal get() { - u32int id = RessourceCaller::getObjId(VT_IFACE_OBJTYPE); + u32int id = RessourceCaller::getObjId(VTIF_OBJTYPE); return VirtualTerminal(id); } - VirtualTerminal(u32int id) : RessourceCaller(id, VT_IFACE_OBJTYPE) {} + VirtualTerminal(u32int id) : RessourceCaller(id, VTIF_OBJTYPE) {} void writeHex(u32int number) { - doCall(VT_IFACE_WRITEHEX, number); + doCall(VTIF_WRITEHEX, number); } void writeDec(s64int number) { - doCall(VT_IFACE_WRITEDEC, (number >> 32), number); + doCall(VTIF_WRITEDEC, (number >> 32), number); } void write(String s) { - Serialized a = s.serialize(); - doCall(VT_IFACE_WRITE, a); + doCall(VTIF_WRITE, (u32int)&s); } String readLine() { - return String::unserialize(doCall(VT_IFACE_READLINE)); + return String::unserialize(doCall(VTIF_READLINE)); + } + void setColor(u8int fg, u8int bg = 0xFF) { + doCall(VTIF_SETCOLOR, (fg << 8) | bg); + } + void setCsrLine(u32int line) { + doCall(VTIF_SETCSRLINE, line); + } + void setCsrCol(u32int col) { + doCall(VTIF_SETCSRCOL, col); + } + bool isBoxed() { + return doCall(VTIF_ISBOXED) != 0; } void put(WChar c) { - doCall(VT_IFACE_PUT, c); + doCall(VTIF_PUT, c); } }; -- cgit v1.2.3