summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-20 19:21:34 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-20 19:21:34 +0200
commit9836acd720988af30250c2c1ec18d618664dea4e (patch)
tree9e26d7d65e1693d1a7f9fd93c9fd33b41d175464
parent90b49b6f171108f272ff529f7546bd9625ca7d17 (diff)
downloadMelon-9836acd720988af30250c2c1ec18d618664dea4e.tar.gz
Melon-9836acd720988af30250c2c1ec18d618664dea4e.zip
Started working on a userland shell
This means I'll have to do syscalls for everything I need.
-rw-r--r--Makefile3
-rw-r--r--Source/Applications/Shell/Makefile31
-rw-r--r--Source/Applications/Shell/main.cpp13
-rw-r--r--Source/Kernel/Makefile1
-rw-r--r--Source/Kernel/SyscallManager/Res.ns.cpp2
-rw-r--r--Source/Kernel/VFS/FSNode-sc.proto.cpp34
-rw-r--r--Source/Kernel/VFS/FSNode.proto.h16
-rw-r--r--Source/Library/Common/String.class.cpp2
-rw-r--r--Source/Library/Common/String.class.h2
-rw-r--r--Source/Library/Interface/FSNode.iface.h14
-rw-r--r--Source/Library/Userland/Binding/FSNode.class.h23
-rw-r--r--Source/Library/Userland/Binding/VirtualTerminal.class.h6
12 files changed, 141 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 9bb7f84..1237ef8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
.PHONY: clean, mrproper, Init.rfs
-Projects = Kernel Library Tools/MakeRamFS Applications/SampleApps
+Projects = Kernel Library Tools/MakeRamFS Applications/Shell Applications/SampleApps
Kernel = Source/Kernel/Melon.ke
RamFS = Init.rfs
@@ -9,6 +9,7 @@ RamFSFiles = :/System :/System/Applications :/System/Configuration :/System/Keym
Source/Kernel/Ressources/Texts/Welcome.txt:/Welcome.txt \
Source/Applications/SampleApps/asmdemo:/ad \
Source/Applications/SampleApps/cxxdemo:/cd \
+ Source/Applications/Shell/Shell:/shell \
:/Useless \
Source/Kernel/Ressources/Texts/Info.txt:/Useless/Info.txt \
Source/Kernel/Ressources/Graphics/logo.text.cxd:/Useless/Melon-logo
diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile
new file mode 100644
index 0000000..205fc2f
--- /dev/null
+++ b/Source/Applications/Shell/Makefile
@@ -0,0 +1,31 @@
+.PHONY: clean, mrproper
+
+CXX = g++
+CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND
+
+LD = ld
+LDFLAGS = -T ../../Library/Link.ld
+
+Objects = main.o
+OutFile = Shell
+
+all: $(OutFile)
+ echo "* Done with $(OutFile)."
+
+rebuild: mrproper all
+
+$(OutFile): $(Objects)
+ echo "* Linking $@.o..."
+ $(LD) $(LDFLAGS) ../../Library/Melon.o $^ -o $@
+
+%.o: %.cpp
+ echo "* Compiling $<..."
+ $(CXX) $(CXXFLAGS) -c $< -o $@
+
+clean:
+ echo "* Removing object files..."
+ rm -rf *.o
+
+mrproper: clean
+ echo "* Removing applications..."
+ rm -rf $(OutFile)
diff --git a/Source/Applications/Shell/main.cpp b/Source/Applications/Shell/main.cpp
new file mode 100644
index 0000000..fabf30c
--- /dev/null
+++ b/Source/Applications/Shell/main.cpp
@@ -0,0 +1,13 @@
+#include <Binding/VirtualTerminal.class.h>
+#include <Binding/FSNode.class.h>
+#include <String.class.h>
+
+int main() {
+ VirtualTerminal vt = VirtualTerminal::get();
+ FSNode node = FSNode::getRoot();
+ while (1) {
+ vt << node.getName() << " : ";
+ String s = vt.readLine();
+ }
+ return 0;
+}
diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile
index 1c83e5a..55c5fb0 100644
--- a/Source/Kernel/Makefile
+++ b/Source/Kernel/Makefile
@@ -55,6 +55,7 @@ Objects = Core/loader.wtf.o \
VFS/Partition.class.o \
VFS/Part.ns.o \
VFS/VFS.ns.o \
+ VFS/FSNode-sc.proto.o \
VFS/File.class.o \
VFS/TextFile.class.o \
VFS/DirectoryNode.class.o \
diff --git a/Source/Kernel/SyscallManager/Res.ns.cpp b/Source/Kernel/SyscallManager/Res.ns.cpp
index 98d3ac3..048d17a 100644
--- a/Source/Kernel/SyscallManager/Res.ns.cpp
+++ b/Source/Kernel/SyscallManager/Res.ns.cpp
@@ -3,6 +3,7 @@
#include <VirtualTerminal.iface.h>
#include <Process.iface.h>
#include <Thread.iface.h>
+#include <FSNode.iface.h>
#include <TaskManager/Task.ns.h>
namespace Res {
@@ -18,6 +19,7 @@ static_call_t staticCalls[] = {
{VTIF_OBJTYPE, VirtualTerminal::scall},
{PRIF_OBJTYPE, Process::scall},
{THIF_OBJTYPE, Thread::scall},
+ {FNIF_OBJTYPE, FSNode::scall},
{0, 0}
};
diff --git a/Source/Kernel/VFS/FSNode-sc.proto.cpp b/Source/Kernel/VFS/FSNode-sc.proto.cpp
new file mode 100644
index 0000000..9e485e1
--- /dev/null
+++ b/Source/Kernel/VFS/FSNode-sc.proto.cpp
@@ -0,0 +1,34 @@
+#include "FSNode.proto.h"
+#include <VFS/VFS.ns.h>
+
+call_t FSNode::m_callTable[] = {
+ CALL0(FNIF_GETNAME, &FSNode::getNameSC),
+ CALL0(FNIF_TYPE, &FSNode::typeSC),
+ CALL0(FNIF_GETPARENT, &FSNode::getParentSC),
+ CALL0(FNIF_GETLENGTH, &FSNode::getLengthSC),
+ CALL0(0, 0)
+};
+
+u32int FSNode::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
+ if (wat == FNIF_SGETRFN) return VFS::getRootNode()->resId();
+ return (u32int) - 1;
+}
+
+u32int FSNode::getNameSC() {
+ return getName().serialize();
+}
+
+u32int FSNode::typeSC() {
+ return type();
+}
+
+u32int FSNode::getLengthSC() {
+ u64int* a = (u64int*)Mem::mkXchgSpace(sizeof(u64int));
+ *a = getLength();
+ return (u32int)a;
+}
+
+u32int FSNode::getParentSC() {
+ if (m_parent != 0) return m_parent->resId();
+ return (u32int) - 1;
+}
diff --git a/Source/Kernel/VFS/FSNode.proto.h b/Source/Kernel/VFS/FSNode.proto.h
index c3cd1c1..b648141 100644
--- a/Source/Kernel/VFS/FSNode.proto.h
+++ b/Source/Kernel/VFS/FSNode.proto.h
@@ -5,6 +5,9 @@
#include <String.class.h>
class FSNode;
#include <VFS/FileSystem.proto.h>
+#include <SyscallManager/Ressource.class.h>
+
+#include <FSNode.iface.h>
enum {
NT_FILE = 1,
@@ -13,18 +16,27 @@ enum {
NT_MOUNTPOINT = 4
};
-class FSNode {
+class FSNode : public Ressource {
protected:
String m_name;
u64int m_length;
u32int m_permissions, m_uid, m_gid;
FileSystem *m_fs;
FSNode *m_parent;
+
+ //Syscall related
+ static call_t m_callTable[];
+ u32int getNameSC();
+ u32int getLengthSC();
+ u32int typeSC();
+ u32int getParentSC();
public:
+ static u32int scall(u8int, u32int, u32int, u32int, u32int);
+
FSNode(String name, FileSystem* fs, FSNode* parent, u64int length = 0, u32int permissions = 0777,
u32int uid = 0, u32int gid = 0) :
- m_name(name), m_length(length), m_permissions(permissions),
+ Ressource(FNIF_OBJTYPE, m_callTable), m_name(name), m_length(length), m_permissions(permissions),
m_uid(uid), m_gid(gid), m_fs(fs), m_parent(parent) {}
virtual ~FSNode() {}
diff --git a/Source/Library/Common/String.class.cpp b/Source/Library/Common/String.class.cpp
index c217807..ac0eba0 100644
--- a/Source/Library/Common/String.class.cpp
+++ b/Source/Library/Common/String.class.cpp
@@ -60,7 +60,7 @@ String String::unserialize(u32int w) {
return ret;
}
-u32int String::serialize() {
+u32int String::serialize() const {
u32int* x = (u32int*)Mem::mkXchgSpace((m_length + 1) * sizeof(u32int));
x[0] = m_length;
for (u32int i = 0; i < m_length; i++) {
diff --git a/Source/Library/Common/String.class.h b/Source/Library/Common/String.class.h
index 5db9858..0d48ce6 100644
--- a/Source/Library/Common/String.class.h
+++ b/Source/Library/Common/String.class.h
@@ -10,7 +10,7 @@ class String : public BasicString<WChar> {
static String number(s32int number);
static String unserialize(u32int w);
- u32int serialize();
+ u32int serialize() const;
String(const char* string, u8int encoding = UE_UTF8);
String() : BasicString<WChar>() {}
diff --git a/Source/Library/Interface/FSNode.iface.h b/Source/Library/Interface/FSNode.iface.h
new file mode 100644
index 0000000..482ebd2
--- /dev/null
+++ b/Source/Library/Interface/FSNode.iface.h
@@ -0,0 +1,14 @@
+#ifndef DEF_FSNODE_IFACE_H
+#define DEF_FSNODE_IFACE_H
+
+#define FNIF_OBJTYPE 0x14
+
+//S : static, GET : get, R : root, FN : fsnode
+#define FNIF_SGETRFN 0
+
+#define FNIF_GETNAME 0x10
+#define FNIF_TYPE 0x11
+#define FNIF_GETPARENT 0x12
+#define FNIF_GETLENGTH 0x13
+
+#endif
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/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h
index 0da1be4..9d438c6 100644
--- a/Source/Library/Userland/Binding/VirtualTerminal.class.h
+++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h
@@ -37,8 +37,12 @@ class VirtualTerminal : public RessourceCaller {
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; }
};