summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-21 17:33:12 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-21 17:33:12 +0200
commitdc37d089e8ca98ff2dc8a320c21fc3ac0a87eaa6 (patch)
tree8ddb55ee633a70ea298a812d5ffec97373631534
parent768ada13917aeda373e6ff5fee21faf90c963746 (diff)
parent7708a5f335c6b3256290775e7f5deb43b681bf03 (diff)
downloadMelon-dc37d089e8ca98ff2dc8a320c21fc3ac0a87eaa6.tar.gz
Melon-dc37d089e8ca98ff2dc8a320c21fc3ac0a87eaa6.zip
Merge branch 'usermode_syscalls'
-rw-r--r--Source/Applications/SampleApps/cxxdemo.cpp15
-rw-r--r--Source/Applications/Shell/Makefile3
-rw-r--r--Source/Applications/Shell/Shell.ns.cpp15
-rw-r--r--Source/Applications/Shell/Shell.ns.h9
-rw-r--r--Source/Applications/Shell/main.cpp12
-rw-r--r--Source/Kernel/Shell/KernelShell-fs.class.cpp3
-rw-r--r--Source/Kernel/Shell/KernelShell.class.cpp3
-rw-r--r--Source/Kernel/SyscallManager/IDT.ns.cpp4
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp21
-rw-r--r--Source/Kernel/TaskManager/Process.class.h8
-rw-r--r--Source/Kernel/TaskManager/Thread.class.cpp22
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal.proto.cpp3
-rw-r--r--Source/Library/Interface/VirtualTerminal.iface.h5
-rw-r--r--Source/Library/Userland/Binding/VirtualTerminal.class.h10
-rw-r--r--Source/Library/Userland/Start.cpp5
15 files changed, 91 insertions, 47 deletions
diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/SampleApps/cxxdemo.cpp
index 01644a8..cf297ec 100644
--- a/Source/Applications/SampleApps/cxxdemo.cpp
+++ b/Source/Applications/SampleApps/cxxdemo.cpp
@@ -4,16 +4,15 @@
#include <Binding/Thread.class.h>
int main() {
- VirtualTerminal x = VirtualTerminal::get();
- String s = x.readLine();
- x.write(s);
+ String s = invt.readLine();
+ outvt << s;
Thread t = Thread::get();
for (char c = ' '; c <= 'z'; c++) {
t.sleep((u32int)c / 4);
- x.put(c);
+ outvt.put(c);
}
- x.put("\n");
- x.write("Salut les gens ! c'est le progrès !!!\nLe boeuf mort est juste là : ");
- x.writeHex(0xDEADBEEF);
- x.put("\n");
+ outvt << "\n";
+ outvt << "Salut les gens ! c'est le progrès !!!\nLe boeuf mort est juste là : ";
+ outvt << 0xDEADBEEF;
+ outvt << "\n";
}
diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile
index 205fc2f..b33b067 100644
--- a/Source/Applications/Shell/Makefile
+++ b/Source/Applications/Shell/Makefile
@@ -6,7 +6,8 @@ CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I ../../Library/Co
LD = ld
LDFLAGS = -T ../../Library/Link.ld
-Objects = main.o
+Objects = main.o \
+ Shell.ns.o
OutFile = Shell
all: $(OutFile)
diff --git a/Source/Applications/Shell/Shell.ns.cpp b/Source/Applications/Shell/Shell.ns.cpp
new file mode 100644
index 0000000..e2433cb
--- /dev/null
+++ b/Source/Applications/Shell/Shell.ns.cpp
@@ -0,0 +1,15 @@
+#include "Shell.ns.h"
+
+namespace Shell {
+
+FSNode node(0);
+
+u32int run() {
+ node = FSNode::getRoot();
+ while (1) {
+ outvt << node.getName() << " : ";
+ String s = invt.readLine();
+ }
+}
+
+}
diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h
new file mode 100644
index 0000000..7d76b33
--- /dev/null
+++ b/Source/Applications/Shell/Shell.ns.h
@@ -0,0 +1,9 @@
+#include <Binding/VirtualTerminal.class.h>
+#include <Binding/FSNode.class.h>
+#include <String.class.h>
+
+namespace Shell {
+ u32int run();
+
+ extern FSNode cwd;
+}
diff --git a/Source/Applications/Shell/main.cpp b/Source/Applications/Shell/main.cpp
index fabf30c..70da17b 100644
--- a/Source/Applications/Shell/main.cpp
+++ b/Source/Applications/Shell/main.cpp
@@ -1,13 +1,5 @@
-#include <Binding/VirtualTerminal.class.h>
-#include <Binding/FSNode.class.h>
-#include <String.class.h>
+#include "Shell.ns.h"
int main() {
- VirtualTerminal vt = VirtualTerminal::get();
- FSNode node = FSNode::getRoot();
- while (1) {
- vt << node.getName() << " : ";
- String s = vt.readLine();
- }
- return 0;
+ return Shell::run();
}
diff --git a/Source/Kernel/Shell/KernelShell-fs.class.cpp b/Source/Kernel/Shell/KernelShell-fs.class.cpp
index cd52810..a13ae6e 100644
--- a/Source/Kernel/Shell/KernelShell-fs.class.cpp
+++ b/Source/Kernel/Shell/KernelShell-fs.class.cpp
@@ -113,7 +113,8 @@ void KernelShell::run(Vector<String>& args) {
if (p == 0) {
*m_vt << "Error while launching process.\n";
} else {
- p->setVirtualTerminal(m_vt);
+ p->setInVT(m_vt);
+ p->setOutVT(m_vt);
p->start();
while (p->getState() != P_FINISHED) Task::currThread()->sleep(10);
delete p;
diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp
index d90fc4c..232facf 100644
--- a/Source/Kernel/Shell/KernelShell.class.cpp
+++ b/Source/Kernel/Shell/KernelShell.class.cpp
@@ -19,7 +19,8 @@ u32int shellRun(void* ks) {
void KernelShell::setup(DirectoryNode* cwd, VirtualTerminal *vt) {
m_vt = vt;
- Task::currProcess()->setVirtualTerminal(vt);
+ Task::currProcess()->setInVT(vt);
+ Task::currProcess()->setOutVT(vt);
((ScrollableVT*)m_vt)->map(9);
Kbd::setFocus(m_vt);
m_cwd = cwd;
diff --git a/Source/Kernel/SyscallManager/IDT.ns.cpp b/Source/Kernel/SyscallManager/IDT.ns.cpp
index 63b340a..f447e6f 100644
--- a/Source/Kernel/SyscallManager/IDT.ns.cpp
+++ b/Source/Kernel/SyscallManager/IDT.ns.cpp
@@ -80,11 +80,11 @@ extern "C" void interrupt_handler(registers_t regs) {
u8int wat = (regs.eax & 0xFF);
if (res == 0xFFFFFF) {
if (regs.eax == 0xFFFFFF01) {
- Task::currProcess()->getVirtualTerminal()->put(WChar(regs.ebx));
+ Task::currProcess()->getOutVT()->put(WChar(regs.ebx));
} else if (regs.eax == 0xFFFFFF02) {
Task::currThread()->sleep(regs.ebx);
} else if (regs.eax == 0xFFFFFF03) {
- Task::currProcess()->getVirtualTerminal()->writeHex(regs.ebx);
+ Task::currProcess()->getOutVT()->writeHex(regs.ebx);
}
} else {
regs.eax = Res::call(res, wat, regs.ebx, regs.ecx, regs.edx, regs.edi, regs.esi);
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
index a2bbfb4..5256b48 100644
--- a/Source/Kernel/TaskManager/Process.class.cpp
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -33,7 +33,7 @@ Process* Process::createKernel(String cmdline, VirtualTerminal *vt) {
p->m_pagedir = kernelPageDirectory;
p->m_uid = 0;
p->m_userHeap = &Mem::kheap;
- p->m_vt = vt;
+ p->m_inVT = p->m_outVT = vt;
Thread* t = new Thread();
t->m_process = p;
@@ -72,7 +72,8 @@ Process::Process(String cmdline, u32int uid) : Ressource(PRIF_OBJTYPE, m_callTab
m_retval = 0;
m_state = P_STARTING;
m_uid = uid;
- m_vt = Task::currProcess()->getVirtualTerminal();
+ m_inVT = Task::currProcess()->getInVT();
+ m_outVT = Task::currProcess()->getOutVT();
m_fileDescriptors = 0;
//Create page directory and user heap
m_pagedir = new PageDirectory(kernelPageDirectory);
@@ -139,12 +140,20 @@ PageDirectory* Process::getPagedir() {
return m_pagedir;
}
-VirtualTerminal* Process::getVirtualTerminal() {
- return m_vt;
+VirtualTerminal* Process::getInVT() {
+ return m_inVT;
}
-void Process::setVirtualTerminal(VirtualTerminal* vt) {
- m_vt = vt;
+VirtualTerminal* Process::getOutVT() {
+ return m_outVT;
+}
+
+void Process::setInVT(VirtualTerminal* vt) {
+ m_inVT = vt;
+}
+
+void Process::setOutVT(VirtualTerminal* vt) {
+ m_outVT = vt;
}
u32int Process::exitSC() {
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index 89efd0c..eda5fc6 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -40,7 +40,7 @@ class Process : public Ressource {
u8int m_state; //Is one of P_* defined above
PageDirectory* m_pagedir;
u32int m_uid; //User ID
- VirtualTerminal *m_vt;
+ VirtualTerminal *m_inVT, *m_outVT;
Heap *m_userHeap;
@@ -72,8 +72,10 @@ class Process : public Ressource {
PageDirectory* getPagedir();
- VirtualTerminal* getVirtualTerminal();
- void setVirtualTerminal(VirtualTerminal* vt);
+ VirtualTerminal* getInVT();
+ VirtualTerminal* getOutVT();
+ void setInVT(VirtualTerminal* vt);
+ void setOutVT(VirtualTerminal* vt);
u32int getState() { return m_state; }
u32int freePageSC(u32int);
};
diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp
index 21ef954..419a954 100644
--- a/Source/Kernel/TaskManager/Thread.class.cpp
+++ b/Source/Kernel/TaskManager/Thread.class.cpp
@@ -152,7 +152,9 @@ void Thread::handleException(registers_t regs, int no) {
"", "", "",
"", ""};
- *(m_process->m_vt) << "\nUnhandled exception " << (s32int)no << " at " << (u32int)regs.cs << ":" <<
+ VirtualTerminal &vt = *(m_process->m_outVT);
+
+ vt << "\nUnhandled exception " << (s32int)no << " at " << (u32int)regs.cs << ":" <<
(u32int)regs.eip << "\n:: " << exceptions[no];
if (m_isKernel) PANIC_DUMP("Exception in kernel thread", &regs);
@@ -163,18 +165,18 @@ void Thread::handleException(registers_t regs, int no) {
int rsvd = regs.err_code & 0x8;
u32int faddr;
asm volatile("mov %%cr2, %0" : "=r"(faddr));
- *(m_process->m_vt) << "\n ";
- if (present) *(m_process->m_vt) << "Present ";
- if (rw) *(m_process->m_vt) << "R/W ";
- if (us) *(m_process->m_vt) << "User ";
- if (rsvd) *(m_process->m_vt) << "Rsvd ";
- *(m_process->m_vt) << "At:" << (u32int)faddr;
-
- *(m_process->m_vt) << "\nThread finishing.\n";
+ vt << "\n ";
+ if (present) vt << "Present ";
+ if (rw) vt << "R/W ";
+ if (us) vt << "User ";
+ if (rsvd) vt << "Rsvd ";
+ vt << "At:" << (u32int)faddr;
+
+ vt << "\nThread finishing.\n";
Task::currentThreadExits(E_PAGEFAULT); //Calling this will setup a new stack
return;
}
- *(m_process->m_vt) << "\nThread finishing.\n";
+ vt << "\nThread finishing.\n";
Task::currentThreadExits(E_UNHANDLED_EXCEPTION);
}
diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp
index 9b0b862..2587369 100644
--- a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp
+++ b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp
@@ -19,7 +19,8 @@ call_t VirtualTerminal::m_callTable[] = {
};
u32int VirtualTerminal::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
- if (wat == VTIF_SGETPRVT) return Task::currProcess()->getVirtualTerminal()->resId();
+ if (wat == VTIF_SGETPRINVT) return Task::currProcess()->getInVT()->resId();
+ if (wat == VTIF_SGETPROUTVT) return Task::currProcess()->getOutVT()->resId();
return (u32int) - 1;
}
diff --git a/Source/Library/Interface/VirtualTerminal.iface.h b/Source/Library/Interface/VirtualTerminal.iface.h
index 412cf8f..c6388e6 100644
--- a/Source/Library/Interface/VirtualTerminal.iface.h
+++ b/Source/Library/Interface/VirtualTerminal.iface.h
@@ -3,8 +3,9 @@
#define VTIF_OBJTYPE 0x10
-//S = static, GET = get, PR = process, VT = virtualterminal
-#define VTIF_SGETPRVT 0
+//S = static, GET = get, PR = process, IN/OUT : in/out, VT = virtualterminal
+#define VTIF_SGETPRINVT 6
+#define VTIF_SGETPROUTVT 7
#define VTIF_PUT 0x01
#define VTIF_WRITEHEX 0x02
diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h
index 9d438c6..06a8dd7 100644
--- a/Source/Library/Userland/Binding/VirtualTerminal.class.h
+++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h
@@ -7,8 +7,12 @@
class VirtualTerminal : public RessourceCaller {
public:
- static VirtualTerminal get() {
- u32int id = RessourceCaller::sCall(VTIF_OBJTYPE, VTIF_SGETPRVT);
+ static VirtualTerminal getIn() {
+ u32int id = RessourceCaller::sCall(VTIF_OBJTYPE, VTIF_SGETPRINVT);
+ return VirtualTerminal(id);
+ }
+ static VirtualTerminal getOut() {
+ u32int id = RessourceCaller::sCall(VTIF_OBJTYPE, VTIF_SGETPROUTVT);
return VirtualTerminal(id);
}
VirtualTerminal(u32int id) : RessourceCaller(id, VTIF_OBJTYPE) {}
@@ -46,3 +50,5 @@ class VirtualTerminal : public RessourceCaller {
inline VirtualTerminal& operator<<(s64int i) { writeDec(i); return *this; }
inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; }
};
+
+extern VirtualTerminal invt, outvt;
diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp
index 639210f..dee7da6 100644
--- a/Source/Library/Userland/Start.cpp
+++ b/Source/Library/Userland/Start.cpp
@@ -1,4 +1,5 @@
#include <types.h>
+#include <Binding/VirtualTerminal.class.h>
#include <Heap.class.h>
@@ -10,6 +11,8 @@ extern u32int start_ctors, end_ctors, start_dtors, end_dtors;
Heap heap;
+VirtualTerminal invt(0), outvt(0);
+
int main();
extern "C" void start() {
@@ -19,6 +22,8 @@ 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();
//Call static destructors