summaryrefslogtreecommitdiff
path: root/Source/Kernel
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-20 18:10:29 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-20 18:10:29 +0200
commit866580161b826443bed3862b8315cefd505de37c (patch)
tree23c3f87fe43d82c47af01c908d8a056785f9217f /Source/Kernel
parent0cca2d68451849b5ea96a3620566fd0b42dde3c0 (diff)
downloadMelon-866580161b826443bed3862b8315cefd505de37c.tar.gz
Melon-866580161b826443bed3862b8315cefd505de37c.zip
We now have call tables for ressources.
instead of adding calls to ressource in the constructor.
Diffstat (limited to 'Source/Kernel')
-rw-r--r--Source/Kernel/SyscallManager/Res.ns.cpp6
-rw-r--r--Source/Kernel/SyscallManager/Ressource.class.cpp68
-rw-r--r--Source/Kernel/SyscallManager/Ressource.class.h18
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp14
-rw-r--r--Source/Kernel/TaskManager/Process.class.h9
-rw-r--r--Source/Kernel/TaskManager/Thread.class.cpp15
-rw-r--r--Source/Kernel/TaskManager/Thread.class.h9
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp30
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal.proto.cpp20
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal.proto.h5
10 files changed, 107 insertions, 87 deletions
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 <SyscallManager/Res.ns.h>
-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<call_t> *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<call_t*> *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<call_t> *m_calls;
+ SimpleList<call_t*> *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<Thread*> m_threads;
SimpleList<File*> *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 <Thread.iface.h>
+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 <VirtualTerminal.iface.h>
+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<Kbd::keypress_t> 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();