From e589a45295a871f38d4a1d1f23b370b612f99be5 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 18 Oct 2009 17:17:36 +0200 Subject: Syscall interface starts being implemented ! --- Source/Library/Userland/Start.cpp | 8 ++++++++ .../Userland/Syscall/RessourceCaller.class.cpp | 18 +++++++++++++++++ .../Userland/Syscall/RessourceCaller.class.h | 22 +++++++++++++++++++++ Source/Library/Userland/Syscall/Syscall.wtf.cpp | 23 +++++++++++----------- Source/Library/Userland/Syscall/Syscall.wtf.h | 6 +++++- Source/Library/Userland/VirtualTerminal.class.h | 22 +++++++++++++++++++++ 6 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 Source/Library/Userland/Start.cpp create mode 100644 Source/Library/Userland/Syscall/RessourceCaller.class.cpp create mode 100644 Source/Library/Userland/Syscall/RessourceCaller.class.h create mode 100644 Source/Library/Userland/VirtualTerminal.class.h (limited to 'Source/Library/Userland') diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp new file mode 100644 index 0000000..02eb951 --- /dev/null +++ b/Source/Library/Userland/Start.cpp @@ -0,0 +1,8 @@ +#include + +int main(); + +extern "C" void start() { + u32int r = main(); + asm volatile("int $66" : : "a"(r)); +} diff --git a/Source/Library/Userland/Syscall/RessourceCaller.class.cpp b/Source/Library/Userland/Syscall/RessourceCaller.class.cpp new file mode 100644 index 0000000..2d7b6ba --- /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::getObjId(u32int type) { + return syscall(0xFFFFFE00, type); +} + +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..3ad8900 --- /dev/null +++ b/Source/Library/Userland/Syscall/RessourceCaller.class.h @@ -0,0 +1,22 @@ +#ifndef DEF_RESSOURCECALLER_CLASS_H +#define DEF_RESSOURCECALLER_CLASS_H + +#include + +class RessourceCaller { + private: + u32int m_id; + u32int m_type; + + protected: + RessourceCaller(u32int id, u32int type); + static u32int getObjId(u32int type); + 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 index 2c03b20..a28c202 100644 --- a/Source/Library/Userland/Syscall/Syscall.wtf.cpp +++ b/Source/Library/Userland/Syscall/Syscall.wtf.cpp @@ -1,20 +1,21 @@ #include "Syscall.wtf.h" -int main(); - -unsigned int syscall(unsigned int n, unsigned int a, unsigned int b, unsigned int c) { - unsigned int r; +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)); + : "=a"(r) : "a"(n), "b"(a), "c"(b), "d"(c), "D"(d), "S"(e)); return r; } -extern "C" void start() { - unsigned int r = main(); - asm volatile("int $66" : : "a"(r)); -} - void putch(char c) { - unsigned int x = 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 index b220d14..0401a89 100644 --- a/Source/Library/Userland/Syscall/Syscall.wtf.h +++ b/Source/Library/Userland/Syscall/Syscall.wtf.h @@ -3,7 +3,11 @@ #include +//Three basic syscalls, just for testing void putch(char); -unsigned int syscall(unsigned int n, unsigned int a, unsigned int b = 0, unsigned int c = 0); +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/VirtualTerminal.class.h b/Source/Library/Userland/VirtualTerminal.class.h new file mode 100644 index 0000000..a7bb4c2 --- /dev/null +++ b/Source/Library/Userland/VirtualTerminal.class.h @@ -0,0 +1,22 @@ +#include + +#include + +#include + +class VirtualTerminal : public RessourceCaller { + public: + static VirtualTerminal get() { + u32int id = RessourceCaller::getObjId(VT_IFACE_OBJTYPE); + return VirtualTerminal(id); + } + VirtualTerminal(u32int id) : RessourceCaller(id, VT_IFACE_OBJTYPE) {} + + void writeHex(u32int number) { + doCall(VT_IFACE_WRITEHEX, number); + } + + void put(WChar c) { + doCall(VT_IFACE_PUT, c); + } +}; -- cgit v1.2.3