diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-20 19:23:33 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-20 19:23:33 +0200 |
commit | 768ada13917aeda373e6ff5fee21faf90c963746 (patch) | |
tree | 9e26d7d65e1693d1a7f9fd93c9fd33b41d175464 /Source/Library/Userland | |
parent | 6ec4b3d31080f90393e72989d559cfb76eff6f9d (diff) | |
parent | 9836acd720988af30250c2c1ec18d618664dea4e (diff) | |
download | Melon-768ada13917aeda373e6ff5fee21faf90c963746.tar.gz Melon-768ada13917aeda373e6ff5fee21faf90c963746.zip |
Merge branch 'usermode_syscalls'
Conflicts:
Source/Kernel/Makefile
Diffstat (limited to 'Source/Library/Userland')
-rw-r--r-- | Source/Library/Userland/Binding/FSNode.class.h | 23 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/Process.class.h | 22 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/Thread.class.h | 19 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/VirtualTerminal.class.h | 48 | ||||
-rw-r--r-- | Source/Library/Userland/Start.cpp | 36 | ||||
-rw-r--r-- | Source/Library/Userland/Syscall/RessourceCaller.class.cpp | 18 | ||||
-rw-r--r-- | Source/Library/Userland/Syscall/RessourceCaller.class.h | 36 | ||||
-rw-r--r-- | Source/Library/Userland/Syscall/Syscall.wtf.cpp | 21 | ||||
-rw-r--r-- | Source/Library/Userland/Syscall/Syscall.wtf.h | 13 | ||||
-rw-r--r-- | Source/Library/Userland/common.h | 27 |
10 files changed, 263 insertions, 0 deletions
diff --git a/Source/Library/Userland/Binding/FSNode.class.h b/Source/Library/Userland/Binding/FSNode.class.h new file mode 100644 index 0000000..eb25782 --- /dev/null +++ b/Source/Library/Userland/Binding/FSNode.class.h @@ -0,0 +1,23 @@ +#include <Syscall/RessourceCaller.class.h> +#include <FSNode.iface.h> + +class FSNode : public RessourceCaller { + public: + static FSNode getRoot() { + return FSNode(RessourceCaller::sCall(FNIF_OBJTYPE, FNIF_SGETRFN)); + } + FSNode(u32int id) : RessourceCaller(id, FNIF_OBJTYPE) {} + + String getName() { + return String::unserialize(doCall(FNIF_GETNAME)); + } + u8int type() { + return doCall(FNIF_TYPE); + } + FSNode getParent() { + return FSNode(doCall(FNIF_GETPARENT)); + } + u64int getLength() { + return *((u64int*)doCall(FNIF_GETLENGTH)); + } +}; diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h new file mode 100644 index 0000000..00afe27 --- /dev/null +++ b/Source/Library/Userland/Binding/Process.class.h @@ -0,0 +1,22 @@ +#include <Syscall/RessourceCaller.class.h> + +#include <Process.iface.h> + +class Process : public RessourceCaller { + public: + static Process get() { + u32int id = RessourceCaller::sCall(PRIF_OBJTYPE, PRIF_SGETCPR); + return Process(id); + } + Process(u32int id) : RessourceCaller(id, PRIF_OBJTYPE) {} + + void exit() { + doCall(PRIF_EXIT); + } + void allocPage(u32int pos) { + doCall(PRIF_ALLOCPAGE, pos); + } + void freePage(u32int pos) { + doCall(PRIF_FREEPAGE, pos); + } +}; diff --git a/Source/Library/Userland/Binding/Thread.class.h b/Source/Library/Userland/Binding/Thread.class.h new file mode 100644 index 0000000..a19c256 --- /dev/null +++ b/Source/Library/Userland/Binding/Thread.class.h @@ -0,0 +1,19 @@ +#include <Syscall/RessourceCaller.class.h> + +#include <Thread.iface.h> + +class Thread : public RessourceCaller { + public: + static Thread get() { + u32int id = RessourceCaller::sCall(THIF_OBJTYPE, THIF_SGETCTH); + return Thread(id); + } + Thread(u32int id) : RessourceCaller(id, THIF_OBJTYPE) {} + + void sleep(u32int msecs) { + doCall(THIF_SLEEP, msecs); + } + void finish(u32int errcode) { + doCall(THIF_FINISH, errcode); + } +}; diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h new file mode 100644 index 0000000..9d438c6 --- /dev/null +++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h @@ -0,0 +1,48 @@ +#include <Syscall/RessourceCaller.class.h> + +#include <VirtualTerminal.iface.h> + +#include <String.class.h> +#include <WChar.class.h> + +class VirtualTerminal : public RessourceCaller { + public: + static VirtualTerminal get() { + u32int id = RessourceCaller::sCall(VTIF_OBJTYPE, VTIF_SGETPRVT); + return VirtualTerminal(id); + } + VirtualTerminal(u32int id) : RessourceCaller(id, VTIF_OBJTYPE) {} + + void writeHex(u32int number) { + doCall(VTIF_WRITEHEX, number); + } + void writeDec(s64int number) { + doCall(VTIF_WRITEDEC, (number >> 32), number); + } + void write(String s) { + doCall(VTIF_WRITE, (u32int)&s); + } + String 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(VTIF_PUT, c); + } + + inline VirtualTerminal& operator<<(const String& s) { write(s); return *this; } + inline VirtualTerminal& operator<<(s32int i) { writeDec(i); return *this; } + inline VirtualTerminal& operator<<(s64int i) { writeDec(i); return *this; } + inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; } +}; diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp new file mode 100644 index 0000000..639210f --- /dev/null +++ b/Source/Library/Userland/Start.cpp @@ -0,0 +1,36 @@ +#include <types.h> + +#include <Heap.class.h> + +extern "C" void __cxa_pure_virtual() {} //Required when using abstract classes +void *__dso_handle; //Required when using global objects +extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; } + +extern u32int start_ctors, end_ctors, start_dtors, end_dtors; + +Heap heap; + +int main(); + +extern "C" void start() { + //Call static constructors + for(u32int * call = &start_ctors; call < &end_ctors; call++) { + ((void (*)(void))*call)(); + } + + heap.create(0x40000000, 0x00100000, 0x00004000); //Initially create a 1M heap with 16ko index + u32int r = main(); + + //Call static destructors + for(u32int * call = &start_dtors; call < &end_dtors; call++) { + ((void (*)(void))*call)(); + } + + asm volatile("int $66" : : "a"(r)); +} + +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.cpp b/Source/Library/Userland/Syscall/RessourceCaller.class.cpp new file mode 100644 index 0000000..f3b61a8 --- /dev/null +++ b/Source/Library/Userland/Syscall/RessourceCaller.class.cpp @@ -0,0 +1,18 @@ +#include "RessourceCaller.class.h" + +RessourceCaller::RessourceCaller(u32int id, u32int type) { + m_id = id; + m_type = 1; + m_type = doCall(0); + if (m_type != type) m_type = 0; +} + +u32int RessourceCaller::sCall(u32int type, u8int wat, u32int a, u32int b, u32int c, u32int d) { + return syscall(0xFFFFFE00 | wat, type, a, b, c, d); +} + +u32int RessourceCaller::doCall(u8int call, u32int a, u32int b, u32int c, u32int d, u32int e) { + if (m_type == 0) return (u32int) - 1; //Type 0 = invalid object + u32int x = ((m_id << 8) | call); + return syscall(x, a, b, c, d, e); +} diff --git a/Source/Library/Userland/Syscall/RessourceCaller.class.h b/Source/Library/Userland/Syscall/RessourceCaller.class.h new file mode 100644 index 0000000..85beacf --- /dev/null +++ b/Source/Library/Userland/Syscall/RessourceCaller.class.h @@ -0,0 +1,36 @@ +#ifndef DEF_RESSOURCECALLER_CLASS_H +#define DEF_RESSOURCECALLER_CLASS_H + +#include <Syscall/Syscall.wtf.h> +#include <common.h> + +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: + u32int m_id; + u32int m_type; + + protected: + RessourceCaller(u32int id, u32int type); + + //Static call -- a call specific to a class and not an object + static u32int sCall(u32int type, u8int wat, u32int a = 0, u32int b = 0, u32int c = 0, u32int d = 0); + + u32int doCall(u8int call, u32int a = 0, u32int b = 0, u32int c = 0, u32int d = 0, u32int e = 0); + + public: + u32int resId() { return m_id; } + u32int resType() { return m_type; } + bool valid() { return m_type != 0; } +}; + +#endif diff --git a/Source/Library/Userland/Syscall/Syscall.wtf.cpp b/Source/Library/Userland/Syscall/Syscall.wtf.cpp new file mode 100644 index 0000000..a28c202 --- /dev/null +++ b/Source/Library/Userland/Syscall/Syscall.wtf.cpp @@ -0,0 +1,21 @@ +#include "Syscall.wtf.h" + +u32int syscall(u32int n, u32int a, u32int b, u32int c, u32int d, u32int e) { + u32int r; + asm volatile ("int $64;" + : "=a"(r) : "a"(n), "b"(a), "c"(b), "d"(c), "D"(d), "S"(e)); + return r; +} + +void putch(char c) { + u32int x = c; + syscall(0xFFFFFF01, x); +} + +void sleep(u32int t) { + syscall(0xFFFFFF02, t); +} + +void write_hex(u32int n) { + syscall(0XFFFFFF03, n); +} diff --git a/Source/Library/Userland/Syscall/Syscall.wtf.h b/Source/Library/Userland/Syscall/Syscall.wtf.h new file mode 100644 index 0000000..0401a89 --- /dev/null +++ b/Source/Library/Userland/Syscall/Syscall.wtf.h @@ -0,0 +1,13 @@ +#ifndef DEF_SYSCALL_WTF_H +#define DEF_SYSCALL_WTF_H + +#include <types.h> + +//Three basic syscalls, just for testing +void putch(char); +void sleep(u32int); +void write_hex(u32int); + +u32int syscall(u32int n, u32int a, u32int b = 0, u32int c = 0, u32int d = 0, u32int e = 0); + +#endif diff --git a/Source/Library/Userland/common.h b/Source/Library/Userland/common.h new file mode 100644 index 0000000..6257841 --- /dev/null +++ b/Source/Library/Userland/common.h @@ -0,0 +1,27 @@ +#ifndef DEF_COMMON +#define DEF_COMMON + +#define NULL 0 + +#include <types.h> + +#include <CMem.ns.h> + +namespace Mem { + void* alloc(u32int); + void free(void*); + void* mkXchgSpace(u32int sz); +} + +//Standard implemenations of operator new/delete +inline void* operator new(u32int, void *p) { return p; } +inline void* operator new[](u32int, void *p) { return p; } +inline void operator delete(void*, void*) { } +inline void operator delete[](void*, void*) { } + +inline void* operator new(u32int sz) { return Mem::alloc(sz); } +inline void* operator new[](u32int sz) { return Mem::alloc(sz); } +inline void operator delete(void *ptr) { Mem::free(ptr); } +inline void operator delete[](void *ptr) { Mem::free(ptr); } + +#endif |