diff options
Diffstat (limited to 'Source/Library/Userland')
-rw-r--r-- | Source/Library/Userland/Binding/FSNode.class.h | 1 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/File.class.h | 68 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/Process.class.h | 7 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/Sys.ns.cpp | 15 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/Sys.ns.h | 26 | ||||
-rw-r--r-- | Source/Library/Userland/Start.cpp | 8 |
6 files changed, 104 insertions, 21 deletions
diff --git a/Source/Library/Userland/Binding/FSNode.class.h b/Source/Library/Userland/Binding/FSNode.class.h index 6a860ea..a7adbc0 100644 --- a/Source/Library/Userland/Binding/FSNode.class.h +++ b/Source/Library/Userland/Binding/FSNode.class.h @@ -2,6 +2,7 @@ #define DEF_FSNODE_CLASS_H #include <Syscall/RessourceCaller.class.h> +#include <String.class.h> #include <FSNode.iface.h> class FSNode : public RessourceCaller { diff --git a/Source/Library/Userland/Binding/File.class.h b/Source/Library/Userland/Binding/File.class.h new file mode 100644 index 0000000..4d1ac16 --- /dev/null +++ b/Source/Library/Userland/Binding/File.class.h @@ -0,0 +1,68 @@ +#ifndef DEF_FILE_CLASS_H +#define DEF_FILE_CLASS_H + +#include <File.iface.h> +#include <Binding/FSNode.class.h> +#include <Syscall/RessourceCaller.class.h> +#include <Binding/VirtualTerminal.class.h> +#include <ByteArray.class.h> + +class File : public RessourceCaller { + public: + File(String name, u8int mode, FSNode start = FSNode(0)) : + RessourceCaller(sCall(FLIF_OBJTYPE, FLIF_SOPEN, (u32int)&name, mode, start.resId()), FLIF_OBJTYPE) { + } + File(u32int id) : RessourceCaller(id, FLIF_OBJTYPE) {} + + void close() { + doCall(FLIF_CLOSE); + } + bool validOpened() { + return (doCall(FLIF_VALID) != 0); + } + u32int read(u32int max_length, u8int *ptr) { + return (doCall(FLIF_READ, max_length, (u32int)ptr)); + } + bool write(u32int length, u8int* ptr) { + return (doCall(FLIF_WRITE, length, (u32int)ptr) != 0); + } + u32int read(ByteArray &data) { + if (!valid()) { + data.clear(); + return 0; + } + u32int l = read(data.size(), (u8int*)data); + if (l != data.size()) data.resize(l); + return l; + } + bool write(ByteArray &data) { + if (!valid()) return false; + return write(data.size(), (u8int*)data); + } + + template <typename T> bool read(T* elem) { + return (read(sizeof(T), (u8int*)elem) == sizeof(T)); + } + template <typename T> bool write(T* elem) { + return write(sizeof(T), (u8int*)elem); + } + + bool seek(u64int count, u8int mode) { + union { + u64int x; + u32int a[2]; + } wat = {count}; + return (doCall(FLIF_SEEK, wat.a[0], wat.a[1], mode) != 0); + } + u64int position() { + return *((u64int*)doCall(FLIF_POSITION)); + } + u64int length() { + return *((u64int*)doCall(FLIF_LENGTH)); + } + bool eof() { + return (doCall(FLIF_EOF) != 0); + } +}; + +#endif diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h index ddca6be..9687ea9 100644 --- a/Source/Library/Userland/Binding/Process.class.h +++ b/Source/Library/Userland/Binding/Process.class.h @@ -29,8 +29,11 @@ class Process : public RessourceCaller { u32int getPpid() { return doCall(PRIF_GETPPID); } - String getCmdline() { - return String::unserialize(doCall(PRIF_GETCMDLINE)); + u32int argc() { + return doCall(PRIF_ARGC); + } + String argv(u32int idx) { + return String::unserialize(doCall(PRIF_ARGV, idx)); } }; diff --git a/Source/Library/Userland/Binding/Sys.ns.cpp b/Source/Library/Userland/Binding/Sys.ns.cpp deleted file mode 100644 index 7083e56..0000000 --- a/Source/Library/Userland/Binding/Sys.ns.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include <Sys.iface.h> -#include "Sys.ns.h" -#include <Syscall/RessourceCaller.class.h> - -namespace Sys { - -void halt() { - RessourceCaller::sCall(SYIF_IFID, SYIF_HALT); -} - -void reboot() { - RessourceCaller::sCall(SYIF_IFID, SYIF_REBOOT); -} - -} diff --git a/Source/Library/Userland/Binding/Sys.ns.h b/Source/Library/Userland/Binding/Sys.ns.h index 3a8426b..eb09504 100644 --- a/Source/Library/Userland/Binding/Sys.ns.h +++ b/Source/Library/Userland/Binding/Sys.ns.h @@ -1,9 +1,31 @@ #ifndef DEF_SYS_NS_H #define DEF_SYS_NS_H +#include <Sys.iface.h> +#include <Syscall/RessourceCaller.class.h> + namespace Sys { - void halt(); - void reboot(); + +inline void halt() { + RessourceCaller::sCall(SYIF_IFID, SYIF_HALT); +} + +inline void reboot() { + RessourceCaller::sCall(SYIF_IFID, SYIF_REBOOT); +} + +inline u32int uptime() { //Returns uptime in seconds + return RessourceCaller::sCall(SYIF_IFID, SYIF_UPTIME); +} + +inline u32int totalRam() { //Returns total amount of RAM in Ko + return RessourceCaller::sCall(SYIF_IFID, SYIF_TOTALRAM); +} + +inline u32int freeRam() { //Returns free amount of RAM in Ko + return RessourceCaller::sCall(SYIF_IFID, SYIF_FREERAM); +} + } #endif diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp index dee7da6..be4f81e 100644 --- a/Source/Library/Userland/Start.cpp +++ b/Source/Library/Userland/Start.cpp @@ -13,7 +13,7 @@ Heap heap; VirtualTerminal invt(0), outvt(0); -int main(); +int main(const Vector<String>& args); extern "C" void start() { //Call static constructors @@ -24,7 +24,11 @@ extern "C" void start() { heap.create(0x40000000, 0x00100000, 0x00004000); //Initially create a 1M heap with 16ko index invt = VirtualTerminal::getIn(); outvt = VirtualTerminal::getOut(); - u32int r = main(); + u32int argc = Process::get().argc(); + Vector<String> args(argc); + for (u32int i = 0; i < argc; i++) args[i] = Process::get().argv(i); + + u32int r = main(args); //Call static destructors for(u32int * call = &start_dtors; call < &end_dtors; call++) { |