From 0cca2d68451849b5ea96a3620566fd0b42dde3c0 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 18 Oct 2009 21:56:26 +0200 Subject: More work on syscalls --- Source/Applications/SampleApps/cxxdemo.cpp | 3 +++ Source/Kernel/MemoryManager/Mem.ns.cpp | 5 +++++ Source/Kernel/MemoryManager/Mem.ns.h | 2 ++ Source/Kernel/TaskManager/Thread.class.cpp | 13 ++++++++++++- Source/Kernel/TaskManager/Thread.class.h | 4 ++++ Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp | 15 +++++++++++++++ Source/Kernel/VTManager/VirtualTerminal.proto.cpp | 3 +++ Source/Kernel/VTManager/VirtualTerminal.proto.h | 3 +++ Source/Library/Common/String.class.cpp | 20 ++++++++++++++++++++ Source/Library/Common/String.class.h | 5 ++++- Source/Library/Interface/VirtualTerminal.iface.h | 4 ++++ .../Library/Userland/Binding/VirtualTerminal.class.h | 11 +++++++++++ Source/Library/Userland/Start.cpp | 3 ++- .../Library/Userland/Syscall/RessourceCaller.class.h | 11 +++++++++++ Source/Library/Userland/common.h | 1 + 15 files changed, 100 insertions(+), 3 deletions(-) (limited to 'Source') diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/SampleApps/cxxdemo.cpp index 8da475a..01644a8 100644 --- a/Source/Applications/SampleApps/cxxdemo.cpp +++ b/Source/Applications/SampleApps/cxxdemo.cpp @@ -5,12 +5,15 @@ int main() { VirtualTerminal x = VirtualTerminal::get(); + String s = x.readLine(); + x.write(s); Thread t = Thread::get(); for (char c = ' '; c <= 'z'; c++) { t.sleep((u32int)c / 4); x.put(c); } x.put("\n"); + x.write("Salut les gens ! c'est le progrès !!!\nLe boeuf mort est juste là : "); x.writeHex(0xDEADBEEF); x.put("\n"); } diff --git a/Source/Kernel/MemoryManager/Mem.ns.cpp b/Source/Kernel/MemoryManager/Mem.ns.cpp index c7f07f0..144b9f3 100644 --- a/Source/Kernel/MemoryManager/Mem.ns.cpp +++ b/Source/Kernel/MemoryManager/Mem.ns.cpp @@ -1,5 +1,6 @@ #include #include +#include #include namespace Mem { @@ -50,6 +51,10 @@ void free(void *ptr) { kheap.free(ptr); } +void* mkXchgSpace(u32int sz) { + return Task::currThread()->mkXchgSpace(sz); +} + u32int kheapSize() { return kheap.size(); } diff --git a/Source/Kernel/MemoryManager/Mem.ns.h b/Source/Kernel/MemoryManager/Mem.ns.h index 0d2b1da..b06ab79 100644 --- a/Source/Kernel/MemoryManager/Mem.ns.h +++ b/Source/Kernel/MemoryManager/Mem.ns.h @@ -11,6 +11,8 @@ namespace Mem { void *alloc(u32int sz, bool align = false); void free(void *ptr); + void* mkXchgSpace(u32int sz); //This creates a space between userland and kernel land where data can be exchanged + u32int kheapSize(), kheapFree(); } diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp index 315eae2..98fa32d 100644 --- a/Source/Kernel/TaskManager/Thread.class.cpp +++ b/Source/Kernel/TaskManager/Thread.class.cpp @@ -52,6 +52,7 @@ void runThread(Thread* thread, void* data, thread_entry_t entry_point) { } Thread::Thread() : Ressource(TH_IFACE_OBJTYPE) { //Private constructor, does nothing + m_xchgspace = 0; } Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) : Ressource(TH_IFACE_OBJTYPE) { @@ -69,10 +70,13 @@ Thread::Thread(Process* process, thread_entry_t entry_point, void* data) : Resso Thread::~Thread() { Task::unregisterThread(this); Mem::free(m_kernelStack.addr); + m_process->getPagedir()->switchTo(); if (m_userStack.addr != 0) { - m_process->getPagedir()->switchTo(); m_process->heap().free(m_userStack.addr); } + if (m_xchgspace != 0) { + m_process->heap().free(m_xchgspace); + } //Don't unregister thread in process, it has probably already been done } @@ -80,6 +84,7 @@ void Thread::setup(Process* process, thread_entry_t entry_point, void* data, boo addCall1(TH_IFACE_SLEEP, (call1)&Thread::sleepSC); addCall1(TH_IFACE_FINISH, (call1)&Thread::finishSC); + m_xchgspace = 0; m_isKernel = isKernel; m_process = process; m_kernelStack.addr = Mem::alloc(STACKSIZE); @@ -181,6 +186,12 @@ u32int Thread::getEip() { return m_eip; } Process* Thread::getProcess() { return m_process; } +void* Thread::mkXchgSpace(u32int sz) { + if (m_xchgspace != 0) m_process->heap().free(m_xchgspace); + m_xchgspace = m_process->heap().alloc(sz); + return m_xchgspace; +} + void Thread::sleep(u32int msecs) { m_state = T_SLEEPING; waitfor.m_time = Time::time() + msecs; diff --git a/Source/Kernel/TaskManager/Thread.class.h b/Source/Kernel/TaskManager/Thread.class.h index 8a7d45e..42baa86 100644 --- a/Source/Kernel/TaskManager/Thread.class.h +++ b/Source/Kernel/TaskManager/Thread.class.h @@ -22,6 +22,8 @@ class Thread : public Ressource { u32int m_esp, m_ebp, m_eip; u8int m_state; //Is one of T_* defined above + void* m_xchgspace; + union { //What the thread might be waiting for u32int m_time; u8int m_irq; //An IRQ number @@ -49,6 +51,8 @@ class Thread : public Ressource { u32int getEip(); Process* getProcess(); + void* mkXchgSpace(u32int sz); + void sleep(u32int msecs); void waitIRQ(u8int irq); bool runnable(); //Called by scheduler diff --git a/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp index 8948657..e0c6e8d 100644 --- a/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal-sc.proto.cpp @@ -5,7 +5,22 @@ 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::putSC(u32int code) { put(WChar(code)); return 0; } + +u32int VirtualTerminal::readLineSC() { + return readLine().serialize(); +} diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp index b7c7340..dfd8f84 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp @@ -7,7 +7,10 @@ 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); } VirtualTerminal::~VirtualTerminal() { diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.h b/Source/Kernel/VTManager/VirtualTerminal.proto.h index b9d0eb8..b0cd224 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.proto.h +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.h @@ -21,7 +21,10 @@ class VirtualTerminal : public Ressource { //SYSCALLS : u32int writeHexSC(u32int); + u32int writeDecSC(u32int, u32int); + u32int writeSC(u32int); u32int putSC(u32int); + u32int readLineSC(); public: VirtualTerminal(); diff --git a/Source/Library/Common/String.class.cpp b/Source/Library/Common/String.class.cpp index d8913d9..c217807 100644 --- a/Source/Library/Common/String.class.cpp +++ b/Source/Library/Common/String.class.cpp @@ -49,6 +49,26 @@ String String::number(s32int number) { return ret; } +String String::unserialize(u32int w) { + u32int* a = (u32int*)w; + String ret; + ret.m_length = a[0]; + ret.m_string = (WChar*)Mem::alloc(a[0] * sizeof(WChar)); + for (u32int i = 0; i < a[0]; i++) { + ret[i] = a[i + 1]; + } + return ret; +} + +u32int String::serialize() { + u32int* x = (u32int*)Mem::mkXchgSpace((m_length + 1) * sizeof(u32int)); + x[0] = m_length; + for (u32int i = 0; i < m_length; i++) { + x[i + 1] = m_string[i]; + } + return (u32int)x; +} + String::String(const char* string, u8int encoding) { m_string = 0; m_length = 0; diff --git a/Source/Library/Common/String.class.h b/Source/Library/Common/String.class.h index 3e50d35..5db9858 100644 --- a/Source/Library/Common/String.class.h +++ b/Source/Library/Common/String.class.h @@ -9,6 +9,9 @@ class String : public BasicString { static String hex(u32int number); static String number(s32int number); + static String unserialize(u32int w); + u32int serialize(); + String(const char* string, u8int encoding = UE_UTF8); String() : BasicString() {} String(const String &other) : BasicString (other) {} @@ -34,7 +37,7 @@ class String : public BasicString { String operator+ (const String &other) const { return concat(other); } String operator+ (const char* other) const { return concat(other); } String operator+ (WChar other) const { return concat(other); } - + s64int toInt() const; //Convert from DEC u64int toInt16() const; //Convert from HEX diff --git a/Source/Library/Interface/VirtualTerminal.iface.h b/Source/Library/Interface/VirtualTerminal.iface.h index 661162f..1525b6c 100644 --- a/Source/Library/Interface/VirtualTerminal.iface.h +++ b/Source/Library/Interface/VirtualTerminal.iface.h @@ -4,5 +4,9 @@ #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 VT_IFACE_READLINE 0x05 #endif diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h index a7bb4c2..67683b8 100644 --- a/Source/Library/Userland/Binding/VirtualTerminal.class.h +++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h @@ -2,6 +2,7 @@ #include +#include #include class VirtualTerminal : public RessourceCaller { @@ -15,6 +16,16 @@ class VirtualTerminal : public RessourceCaller { void writeHex(u32int number) { doCall(VT_IFACE_WRITEHEX, number); } + void writeDec(s64int number) { + doCall(VT_IFACE_WRITEDEC, (number >> 32), number); + } + void write(String s) { + Serialized a = s.serialize(); + doCall(VT_IFACE_WRITE, a); + } + String readLine() { + return String::unserialize(doCall(VT_IFACE_READLINE)); + } void put(WChar c) { doCall(VT_IFACE_PUT, c); diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp index e185189..639210f 100644 --- a/Source/Library/Userland/Start.cpp +++ b/Source/Library/Userland/Start.cpp @@ -18,7 +18,7 @@ extern "C" void start() { ((void (*)(void))*call)(); } - heap.create(0x40000000, 0x00100000, 0x00003000); //Initially create a 1M heap with 12ko index + heap.create(0x40000000, 0x00100000, 0x00004000); //Initially create a 1M heap with 16ko index u32int r = main(); //Call static destructors @@ -32,4 +32,5 @@ extern "C" void start() { namespace Mem { void* alloc (u32int sz) { return heap.alloc(sz); } void free(void* ptr) { heap.free(ptr); } + void* mkXchgSpace (u32int sz) { return alloc(sz); } } diff --git a/Source/Library/Userland/Syscall/RessourceCaller.class.h b/Source/Library/Userland/Syscall/RessourceCaller.class.h index 3ad8900..3602ef0 100644 --- a/Source/Library/Userland/Syscall/RessourceCaller.class.h +++ b/Source/Library/Userland/Syscall/RessourceCaller.class.h @@ -2,6 +2,17 @@ #define DEF_RESSOURCECALLER_CLASS_H #include +#include + +class Serialized { + private: + u32int m_value; + + public: + Serialized(u32int v) : m_value(v) {} + ~Serialized() { Mem::free( (void*)m_value); } + operator u32int () { return m_value; } +}; class RessourceCaller { private: diff --git a/Source/Library/Userland/common.h b/Source/Library/Userland/common.h index 3508513..6257841 100644 --- a/Source/Library/Userland/common.h +++ b/Source/Library/Userland/common.h @@ -10,6 +10,7 @@ namespace Mem { void* alloc(u32int); void free(void*); + void* mkXchgSpace(u32int sz); } //Standard implemenations of operator new/delete -- cgit v1.2.3