diff options
-rwxr-xr-x | CopyToFDD.sh | 14 | ||||
-rw-r--r-- | Source/Applications/Demos/GOL.cpp | 14 | ||||
-rw-r--r-- | Source/Applications/Demos/cxxdemo.cpp | 14 | ||||
-rw-r--r-- | Source/Applications/PaperWork/Makefile | 2 | ||||
-rw-r--r-- | Source/Applications/PaperWork/PaperWork.cpp (renamed from Source/Applications/PaperWork/main.cpp) | 13 | ||||
-rw-r--r-- | Source/Applications/Shell/Makefile | 5 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell-fs.class.cpp (renamed from Source/Applications/Shell/Shell-fs.ns.cpp) | 22 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.class.cpp (renamed from Source/Applications/Shell/Shell.ns.cpp) | 32 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.class.h | 28 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.ns.h | 18 | ||||
-rw-r--r-- | Source/Library/Userland/App/Application.proto.h | 41 | ||||
-rw-r--r-- | Source/Library/Userland/App/ShellApp.proto.h | 18 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/VirtualTerminal.class.h | 2 | ||||
-rw-r--r-- | Source/Library/Userland/Start.cpp | 37 |
14 files changed, 167 insertions, 93 deletions
diff --git a/CopyToFDD.sh b/CopyToFDD.sh index f5d93d6..7b8459a 100755 --- a/CopyToFDD.sh +++ b/CopyToFDD.sh @@ -7,10 +7,14 @@ cp Grub-menu-fdd.cfg Mount/boot/menu.cfg # Create directories mkdir Mount/{System,Applications,Volumes} -mkdir Mount/Applications/Shell +mkdir Mount/Applications/{Shell,Demos} mkdir Mount/System/{Applications,Logs,Configuration} mkdir Mount/Volumes/{HDD,InitRFS} +# Copy kernel and ramfs +cp Source/Kernel/Melon.ke Mount/System +cp Init.rfs Mount/System + # Copy system files cp Source/Kernel/Ressources/Configuration/* Mount/System/Configuration cp Source/Applications/PaperWork/PaperWork Mount/System/Applications/PaperWork.app @@ -21,12 +25,8 @@ echo "/Volumes/InitRFS:ramfs:0" > Mount/System/Configuration/Mount echo "/Volumes/HDD:block.ata:0:1" >> Mount/System/Configuration/Mount # Copy demo apps -cp Source/Applications/Demos/GOL Mount/Apps/GOL.app -cp Source/Applications/Demos/asmdemo Mount/Apps/ASM.dem - -# Copy kernel and ramfs -cp Source/Kernel/Melon.ke Mount/System -cp Init.rfs Mount/System +cp Source/Applications/Demos/GOL Mount/Applications/Demos/GOL.app +cp Source/Applications/Demos/asmdemo Mount/Applications/Demos/ASM.dem #echo "*** Launching a BASH shell, if you want to do any maintenance ***" #bash || exit 0 diff --git a/Source/Applications/Demos/GOL.cpp b/Source/Applications/Demos/GOL.cpp index e6da3a6..cd6e719 100644 --- a/Source/Applications/Demos/GOL.cpp +++ b/Source/Applications/Demos/GOL.cpp @@ -1,10 +1,18 @@ -#include <Binding/VirtualTerminal.class.h> #include <Binding/Thread.class.h> -#include <String.class.h> #include <ByteArray.class.h> #include <Rand.ns.h> -int main(Vector<String> args) { +#include <App/ShellApp.proto.h> + +class GOL : public ShellApp { + public: + GOL() : ShellApp() {} + int run(); +}; + +APP(GOL); + +int GOL::run() { if (!outvt.isBoxed()) { outvt << "Error : cannot display GOL on a non-boxed terminal.\n"; return 1; diff --git a/Source/Applications/Demos/cxxdemo.cpp b/Source/Applications/Demos/cxxdemo.cpp index 3d452e7..372e69f 100644 --- a/Source/Applications/Demos/cxxdemo.cpp +++ b/Source/Applications/Demos/cxxdemo.cpp @@ -1,10 +1,18 @@ #include <Syscall/Syscall.wtf.h> -#include <String.class.h> -#include <Binding/VirtualTerminal.class.h> #include <Binding/Thread.class.h> #include <Binding/File.class.h> -int main(const Vector<String>& args) { +#include <App/ShellApp.proto.h> + +class CPPDemo : public ShellApp { + public: + CPPDemo() : ShellApp() {} + int run(); +}; + +APP(CPPDemo); + +int CPPDemo::run() { outvt << "Enter some text plz : "; String s = invt.readLine(); outvt << s; diff --git a/Source/Applications/PaperWork/Makefile b/Source/Applications/PaperWork/Makefile index fe8d564..d3203cf 100644 --- a/Source/Applications/PaperWork/Makefile +++ b/Source/Applications/PaperWork/Makefile @@ -6,7 +6,7 @@ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I . LD = ld LDFLAGS = -T ../../Library/Link.ld -L ../../Library -Objects = main.o +Objects = PaperWork.o OutFile = PaperWork all: $(OutFile) diff --git a/Source/Applications/PaperWork/main.cpp b/Source/Applications/PaperWork/PaperWork.cpp index 2fb40df..0d6a821 100644 --- a/Source/Applications/PaperWork/main.cpp +++ b/Source/Applications/PaperWork/PaperWork.cpp @@ -1,9 +1,16 @@ -#include <Binding/Process.class.h> -#include <String.class.h> +#include <App/ShellApp.proto.h> #define DEFAULT_SHELL "/Applications/Shell/Shell.app" -int main(Vector<String> args) { +class PaperWork : public ShellApp { + public: + PaperWork() : ShellApp() {} + int run(); +}; + +APP(PaperWork); + +int PaperWork::run() { String act = "init"; if (args.size() == 2) { if (args[1] == "login") { diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile index bf81af6..d546a15 100644 --- a/Source/Applications/Shell/Makefile +++ b/Source/Applications/Shell/Makefile @@ -6,9 +6,8 @@ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I . LD = ld LDFLAGS = -T ../../Library/Link.ld -L ../../Library -Objects = main.o \ - Shell.ns.o \ - Shell-fs.ns.o +Objects = Shell.class.o \ + Shell-fs.class.o OutFile = Shell all: $(OutFile) diff --git a/Source/Applications/Shell/Shell-fs.ns.cpp b/Source/Applications/Shell/Shell-fs.class.cpp index 0b51299..150b877 100644 --- a/Source/Applications/Shell/Shell-fs.ns.cpp +++ b/Source/Applications/Shell/Shell-fs.class.cpp @@ -1,10 +1,8 @@ -#include "Shell.ns.h" +#include "Shell.class.h" #include <TextFile.class.h> #include <Binding/Process.class.h> -namespace Shell { - -void ls(Vector<String>& args) { +void Shell::ls(Vector<String>& args) { FSNode d = cwd; if (args.size() == 2) { FSNode n = FS::find(args[1], cwd); @@ -41,7 +39,7 @@ void ls(Vector<String>& args) { } } -void cd(Vector<String>& args) { +void Shell::cd(Vector<String>& args) { if (args.size() != 2) { outvt << "Invalid argument count.\n"; } else { @@ -57,11 +55,11 @@ void cd(Vector<String>& args) { } } -void pwd(Vector<String>& args) { +void Shell::pwd(Vector<String>& args) { outvt << "Current directory : " << cwd.path() << "\n"; } -void rm(Vector<String>& args) { +void Shell::rm(Vector<String>& args) { if (args.size() == 1) outvt << "No file to remove.\n"; for (u32int i = 1; i < args.size(); i++) { if (!FS::find(args[i], cwd).remove()) { @@ -70,7 +68,7 @@ void rm(Vector<String>& args) { } } -void mkdir(Vector<String>& args) { +void Shell::mkdir(Vector<String>& args) { if (args.size() == 1) outvt << "No directory to create.\n"; for (u32int i = 1; i < args.size(); i++) { if (!FS::mkdir(args[i], cwd).valid()) { @@ -79,7 +77,7 @@ void mkdir(Vector<String>& args) { } } -void cat(Vector<String>& args) { +void Shell::cat(Vector<String>& args) { if (args.size() == 1) outvt << "Meow.\n"; for (u32int i = 1; i < args.size(); i++) { TextFile f(args[i], FM_READ, cwd); @@ -94,7 +92,7 @@ void cat(Vector<String>& args) { } } -void wf(Vector<String>& args) { +void Shell::wf(Vector<String>& args) { if (args.size() == 1) { outvt << "No file to write !\n"; } else { @@ -113,7 +111,7 @@ void wf(Vector<String>& args) { } } -void run(Vector<String>& args) { +void Shell::run(Vector<String>& args) { if (args.size() == 1) { outvt << "Nothing to run...\n"; } else { @@ -132,5 +130,3 @@ void run(Vector<String>& args) { } } } - -} diff --git a/Source/Applications/Shell/Shell.ns.cpp b/Source/Applications/Shell/Shell.class.cpp index 56a6b5f..42743e7 100644 --- a/Source/Applications/Shell/Shell.ns.cpp +++ b/Source/Applications/Shell/Shell.class.cpp @@ -1,25 +1,25 @@ -#include "Shell.ns.h" +#include "Shell.class.h" #include <Binding/Sys.ns.h> #include <Binding/Process.class.h> -namespace Shell { - -FSNode cwd(0); +APP(Shell); +Shell::Shell() : ShellApp(), cwd(FS::cwdNode()) { +} -u32int run() { +int Shell::run() { struct { //Command list String name; - void (*cmd)(Vector<String>&); + void (Shell::*cmd)(Vector<String>&); } commands[] = { - {"ls", ls}, - {"cd", cd}, - {"pwd", pwd}, - {"rm", rm}, - {"mkdir", mkdir}, - {"cat", cat}, - {"wf", wf}, - {"run", run}, + {"ls", &Shell::ls}, + {"cd", &Shell::cd}, + {"pwd", &Shell::pwd}, + {"rm", &Shell::rm}, + {"mkdir", &Shell::mkdir}, + {"cat", &Shell::cat}, + {"wf", &Shell::wf}, + {"run", &Shell::run}, {"", 0} }; @@ -80,7 +80,7 @@ u32int run() { if (commands[i].cmd == 0) { outvt << "Not implemented yet.\n"; } else { - commands[i].cmd(cmd); + (this->*(commands[i].cmd))(cmd); } break; } @@ -91,6 +91,4 @@ u32int run() { } } -} - diff --git a/Source/Applications/Shell/Shell.class.h b/Source/Applications/Shell/Shell.class.h new file mode 100644 index 0000000..7c0c324 --- /dev/null +++ b/Source/Applications/Shell/Shell.class.h @@ -0,0 +1,28 @@ +#ifndef DEF_SHELL_CLASS_H +#define DEF_SHELL_CLASS_H + +#include <Binding/VirtualTerminal.class.h> +#include <Binding/FSNode.class.h> +#include <String.class.h> + +#include <App/ShellApp.proto.h> + +class Shell : public ShellApp { + public: + Shell(); + + int run(); + + FSNode cwd; + + void ls(Vector<String>& args); + void cd(Vector<String>& args); + void pwd(Vector<String>& args); + void rm(Vector<String>& args); + void mkdir(Vector<String>& args); + void cat(Vector<String>& args); + void wf(Vector<String>& args); + void run(Vector<String>& args); +}; + +#endif diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h deleted file mode 100644 index b2dd587..0000000 --- a/Source/Applications/Shell/Shell.ns.h +++ /dev/null @@ -1,18 +0,0 @@ -#include <Binding/VirtualTerminal.class.h> -#include <Binding/FSNode.class.h> -#include <String.class.h> - -namespace Shell { - u32int run(); - - extern FSNode cwd; - - extern void ls(Vector<String>& args); - extern void cd(Vector<String>& args); - extern void pwd(Vector<String>& args); - extern void rm(Vector<String>& args); - extern void mkdir(Vector<String>& args); - extern void cat(Vector<String>& args); - extern void wf(Vector<String>& args); - extern void run(Vector<String>& args); -} diff --git a/Source/Library/Userland/App/Application.proto.h b/Source/Library/Userland/App/Application.proto.h new file mode 100644 index 0000000..1f3a963 --- /dev/null +++ b/Source/Library/Userland/App/Application.proto.h @@ -0,0 +1,41 @@ +#ifndef DEF_APPLICATION_PROTO_H +#define DEF_APPLICATION_PROTO_H + +#include <Binding/Process.class.h> +#include <String.class.h> + +extern u32int start_dtors, end_dtors; + +#define APP(t) static t the_app; \ + Application *app = &the_app; + +class Application { + public: + Process pr; + Vector<String> args; + + Application() : pr(Process::get()), args(pr.argc()) { + for (u32int i = 0; i < args.size(); i++) args[i] = pr.argv(i); + //TODO : add default signal handlers + } + virtual ~Application() {} + + virtual int run() = 0; //Application's main loop + + virtual void doEvents() { + //TODO : handle signals (IPC featurs to come) + } + + void exit(u32int ret) { + //Call static destructors + for(u32int * call = &start_dtors; call < &end_dtors; call++) { + ((void (*)(void))*call)(); + } + threadFinishedSyscall(ret); + } +}; + +extern Application *app; + +#endif + diff --git a/Source/Library/Userland/App/ShellApp.proto.h b/Source/Library/Userland/App/ShellApp.proto.h new file mode 100644 index 0000000..846f2b1 --- /dev/null +++ b/Source/Library/Userland/App/ShellApp.proto.h @@ -0,0 +1,18 @@ +#ifndef DEF_SHELLAPP_CLASS_H +#define DEF_SHELLAPP_CLASS_H + +#include <App/Application.proto.h> +#include <Binding/VirtualTerminal.class.h> + +class ShellApp : public Application { + public: + VirtualTerminal invt, outvt; + + ShellApp() : Application(), invt(VirtualTerminal::getIn()), outvt(VirtualTerminal::getOut()) { + if (!invt.valid()) exit(1); + if (!outvt.valid()) exit(2); + } +}; + +#endif + diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h index c8a4123..70c6b23 100644 --- a/Source/Library/Userland/Binding/VirtualTerminal.class.h +++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h @@ -71,6 +71,4 @@ class VirtualTerminal : public RessourceCaller { inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; } }; -extern VirtualTerminal invt, outvt; - #endif diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp index f1d1771..cb9faf9 100644 --- a/Source/Library/Userland/Start.cpp +++ b/Source/Library/Userland/Start.cpp @@ -1,46 +1,37 @@ #include <types.h> #include <Syscall/Syscall.wtf.h> -#include <Binding/VirtualTerminal.class.h> + +#include <App/Application.proto.h> #include <Heap.class.h> -extern u32int start_ctors, end_ctors, start_dtors, end_dtors; +extern u32int start_ctors, end_ctors; -Heap heap; +Heap *heap; VirtualTerminal invt(0), outvt(0); int main(const Vector<String>& args); extern "C" void start() { - heap.create(0x40000000, 0x00040000, 0x00004000); //Initially create a 256ko heap with 16ko index + Heap h; + h.create(0x40000000, 0x00040000, 0x00004000); //Initially create a 256ko heap with 16ko index + heap = &h; - //Call static constructors + //Call static constructors (this will construct the Application object and get some stuff (arguments, ...)) u32int i = 0; for(u32int * call = &start_ctors; call < &end_ctors; call++) { ((void (*)(void))*call)(); } - invt = VirtualTerminal::getIn(); outvt = VirtualTerminal::getOut(); - if (!invt.valid()) threadFinishedSyscall(1); - if (!outvt.valid()) threadFinishedSyscall(2); - - 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++) { - ((void (*)(void))*call)(); - } - - threadFinishedSyscall(r); + app->doEvents(); + u32int r = app->run(); + app->doEvents(); + app->exit(r); //Will call static destructors } namespace Mem { - void* alloc (size_t sz) { return heap.alloc(sz); } - void free(void* ptr) { heap.free(ptr); } + void* alloc (size_t sz) { return heap->alloc(sz); } + void free(void* ptr) { heap->free(ptr); } void* mkXchgSpace (size_t sz) { return alloc(sz); } } |