diff options
23 files changed, 97 insertions, 34 deletions
@@ -1,4 +1,5 @@ *.swp *.o +Init.rfs Source/Kernel/Map.txt Source/Kernel/Melon.ke Binary files differ@@ -1,12 +1,13 @@ .PHONY: clean, mrproper, Init.rfs -Projects = Kernel Tools/MakeRamFS +Projects = Kernel Tools/MakeRamFS Applications/ASMApps Kernel = Source/Kernel/Melon.ke RamFS = Init.rfs RamFSFiles = :/System :/System/Applications :/System/Configuration :/System/Keymaps \ Source/Kernel/Ressources/Keymaps/fr.mkm:/System/Keymaps/fr.mkm \ Source/Kernel/Ressources/Texts/Welcome.txt:/Welcome.txt \ + Source/Applications/ASMApps/test:/System/Applications/Test \ :/Useless \ Source/Kernel/Ressources/Texts/Info.txt:/Useless/Info.txt \ Source/Kernel/Ressources/Graphics/logo.text.cxd:/Useless/Melon-logo diff --git a/Media/Screenshots/2009-10-17-225953_728x426_scrot.png b/Media/Screenshots/2009-10-17-225953_728x426_scrot.png Binary files differnew file mode 100644 index 0000000..7c86436 --- /dev/null +++ b/Media/Screenshots/2009-10-17-225953_728x426_scrot.png diff --git a/Media/Screenshots/2009-10-17-230014_728x426_scrot.png b/Media/Screenshots/2009-10-17-230014_728x426_scrot.png Binary files differnew file mode 100644 index 0000000..be4404c --- /dev/null +++ b/Media/Screenshots/2009-10-17-230014_728x426_scrot.png diff --git a/Source/Applications/ASMApps/Makefile b/Source/Applications/ASMApps/Makefile new file mode 100644 index 0000000..8cc8bfd --- /dev/null +++ b/Source/Applications/ASMApps/Makefile @@ -0,0 +1,20 @@ +.PHONY: clean, mrproper + +ASM = nasm + +Applications = test + +all: $(Applications) + echo "* Done with ASM applications : $(Applications)" + +rebuild: mrproper all + +%: %.asm + echo "* Compiling $<..." + $(ASM) -o $@ $< + +clean: + echo "* Removing files..." + rm -rf $(Applications) + +mrproper: clean diff --git a/Source/Applications/ASMApps/syscalls.asm b/Source/Applications/ASMApps/syscalls.asm new file mode 100644 index 0000000..cdd5cc6 --- /dev/null +++ b/Source/Applications/ASMApps/syscalls.asm @@ -0,0 +1,7 @@ +[bits 32] + +dd 0xFEEDBEEF ; magic number ^^ +dd end - start + +%define SC_PUTCH 0xFFFFFF01 +%define SC_SLEEP 0xFFFFFF02 diff --git a/Source/Applications/ASMApps/test b/Source/Applications/ASMApps/test Binary files differnew file mode 100644 index 0000000..397abf1 --- /dev/null +++ b/Source/Applications/ASMApps/test diff --git a/Source/Applications/ASMApps/test.asm b/Source/Applications/ASMApps/test.asm new file mode 100644 index 0000000..80965b4 --- /dev/null +++ b/Source/Applications/ASMApps/test.asm @@ -0,0 +1,20 @@ +%include "syscalls.asm" + +start: + mov ecx, ' ' + loop: + inc ecx + mov eax, SC_PUTCH ;temporarily defined for writing one char to screen + mov ebx, ecx + int 64 + mov eax, SC_SLEEP ;temporary syscall for sleeping + mov ebx, 30 ;20ms + int 64 + cmp ecx, 127 + jnz loop + mov eax, 0 + mov eax, SC_PUTCH + mov ebx, 10 ;newline + int 64 + int 66 ;finish task +end: diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 655bd8b..87e95de 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -35,9 +35,6 @@ extern u32int end; //Placement address extern "C" void kmain(multiboot_info_t* mbd, u32int magic); -extern "C" void sample_task(); -extern u32int sample_task_size; - #define INFO(vt) vt->setColor(KVT_FGCOLOR); *vt << " - "; vt->setColor(KVT_LIGHTCOLOR); #define PROCESSING(vt, m) vt->setColor(KVT_BLECOLOR); *vt << " > "; vt->setColor(KVT_FGCOLOR); *vt << m; \ vt->setCursorCol(60); vt->setColor(KVT_LIGHTCOLOR); *vt << ": "; @@ -167,20 +164,12 @@ void kmain(multiboot_info_t* mbd, u32int magic) { FloppyController::detect(); Log::log(KL_STATUS, "kmain : Floppy drives detected"); - //Create dummy process, for testing user mode - Process* p; - p = new Process("dummy task", 0); - u8int *ptr = (u8int*)p->heap().alloc(sample_task_size); - memcpy(ptr, (const u8int*)sample_task, sample_task_size); - new Thread(p, (thread_entry_t)ptr, 0); - kernelPageDirectory->switchTo(); - asm volatile("sti"); Log::log(KL_STATUS, "kmain : Interrupts enabled."); new KernelShell(cwd); //No need to save that in a var, it is automatically destroyed anyways Log::log(KL_STATUS, "kmain : Kernel shell launched"); - kvt->unmap(); + //kvt->unmap(); while (KernelShell::getInstances() > 0) { Task::currThread()->sleep(100); diff --git a/Source/Kernel/MemoryManager/Heap.class.cpp b/Source/Kernel/MemoryManager/Heap.class.cpp index 7331cd0..365b4f0 100644 --- a/Source/Kernel/MemoryManager/Heap.class.cpp +++ b/Source/Kernel/MemoryManager/Heap.class.cpp @@ -27,6 +27,7 @@ void Heap::create(u32int start, u32int size, u32int idxsize, PageDirectory* page for (u32int i = start ; i < m_end; i += 0x1000) { m_pagedir->allocFrame(i, m_user, m_rw); } + m_pagedir->switchTo(); m_index.data = (heap_header_t **)start; //Set index start. start == start of all heap m_index.size = 0; diff --git a/Source/Kernel/Shell/KernelShell-fs.class.cpp b/Source/Kernel/Shell/KernelShell-fs.class.cpp index 3ac7b20..b34fa7f 100644 --- a/Source/Kernel/Shell/KernelShell-fs.class.cpp +++ b/Source/Kernel/Shell/KernelShell-fs.class.cpp @@ -1,6 +1,8 @@ #include "KernelShell.class.h" #include <VFS/VFS.ns.h> #include <VFS/File.class.h> +#include <TaskManager/Task.ns.h> +#include <MemoryManager/PhysMem.ns.h> void KernelShell::ls(Vector<String>& args) { DirectoryNode* d = m_cwd; @@ -102,3 +104,32 @@ void KernelShell::wf(Vector<String>& args) { } } } + +void KernelShell::run(Vector<String>& args) { + if (args.size() == 1) { + *m_vt << "No app to run !\n"; + } else { + File f(args[1], FM_READ, m_cwd); + if (f.valid()) { + u32int magic = 0; + f.read<u32int>(&magic); + if (magic == 0xFEEDBEEF) { + u32int size; + f.read<u32int>(&size); + Process* p; + p = new Process(args[1], 0); + p->setVirtualTerminal(m_vt); + u8int *ptr = (u8int*)p->heap().alloc(size); + f.read(size, ptr); + new Thread(p, (thread_entry_t)ptr, 0); + kernelPageDirectory->switchTo(); + while (p->getState() != P_FINISHED) Task::currThread()->sleep(10); + delete p; + } else { + *m_vt << "Bad magic number : " << (u32int)magic << "\n"; + } + } else { + *m_vt << "Unable to read from file.\n"; + } + } +} diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp index e2fbb69..ac89b68 100644 --- a/Source/Kernel/Shell/KernelShell.class.cpp +++ b/Source/Kernel/Shell/KernelShell.class.cpp @@ -3,7 +3,9 @@ #include <DeviceManager/Kbd.ns.h> #include <Library/Rand.ns.h> #include <Library/SimpleList.class.h> +#include <MemoryManager/PhysMem.ns.h> #include <VFS/VFS.ns.h> +#include <TaskManager/Task.ns.h> u32int KernelShell::m_instances = 0; @@ -51,6 +53,7 @@ u32int KernelShell::run() { {"mkdir", &KernelShell::mkdir}, {"rm", &KernelShell::rm}, {"wf", &KernelShell::wf}, + {"run", &KernelShell::run}, {"devices", &KernelShell::devices}, {"loadkeys", &KernelShell::loadkeys}, diff --git a/Source/Kernel/Shell/KernelShell.class.h b/Source/Kernel/Shell/KernelShell.class.h index 39e1ebd..48d9704 100644 --- a/Source/Kernel/Shell/KernelShell.class.h +++ b/Source/Kernel/Shell/KernelShell.class.h @@ -26,6 +26,7 @@ class KernelShell { void mkdir(Vector<String>& args); void rm(Vector<String>& args); void wf(Vector<String>& args); + void run(Vector<String>& args); //in KernelShell-sys void devices(Vector<String>& args); diff --git a/Source/Kernel/SyscallManager/IDT.ns.cpp b/Source/Kernel/SyscallManager/IDT.ns.cpp index fcdf2ff..0744e56 100644 --- a/Source/Kernel/SyscallManager/IDT.ns.cpp +++ b/Source/Kernel/SyscallManager/IDT.ns.cpp @@ -75,9 +75,9 @@ extern "C" void interrupt_handler(registers_t regs) { doSwitch = doSwitch or Task::IRQwakeup(regs.int_no - 32); } if (regs.int_no == 64) { - if (regs.eax == 1) { + if (regs.eax == 0xFFFFFF01) { Task::currProcess()->getVirtualTerminal()->put(WChar(regs.ebx)); - } else if (regs.eax == 2) { + } else if (regs.eax == 0xFFFFFF02) { Task::currThread()->sleep(regs.ebx); } } diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp index cf8f00a..9fdad96 100644 --- a/Source/Kernel/TaskManager/Process.class.cpp +++ b/Source/Kernel/TaskManager/Process.class.cpp @@ -42,6 +42,7 @@ Process::Process(String cmdline, u32int uid) { m_state = P_RUNNING; m_uid = uid; m_vt = Task::currProcess()->getVirtualTerminal(); + m_fileDescriptors = 0; //Create page directory and user heap m_pagedir = new PageDirectory(kernelPageDirectory); m_pagedir->switchTo(); @@ -65,7 +66,7 @@ void Process::exit() { iter->v()->close(false); delete iter->v(); } - delete m_fileDescriptors; //Will recursively delete whole list + if (m_fileDescriptors != 0) delete m_fileDescriptors; //Will recursively delete whole list m_state = P_FINISHED; } diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h index ac9614e..73421a9 100644 --- a/Source/Kernel/TaskManager/Process.class.h +++ b/Source/Kernel/TaskManager/Process.class.h @@ -61,6 +61,7 @@ class Process { VirtualTerminal* getVirtualTerminal(); void setVirtualTerminal(VirtualTerminal* vt); + u32int getState() { return m_state; } }; diff --git a/Source/Kernel/TaskManager/Task.ns.cpp b/Source/Kernel/TaskManager/Task.ns.cpp index 1d1676e..437d5b4 100644 --- a/Source/Kernel/TaskManager/Task.ns.cpp +++ b/Source/Kernel/TaskManager/Task.ns.cpp @@ -141,6 +141,7 @@ void currThreadExitProceed(u32int errcode) { } void currentThreadExits(u32int errcode) { //Call currThreadExitProceed with a working stack (we use temp_stack) + asm volatile("cli"); u32int* stack = &temp_stack[TEMP_STACK_SIZE]; stack--; *stack = errcode; @@ -149,7 +150,6 @@ void currentThreadExits(u32int errcode) { //Call currThreadExitProceed with a wo u32int esp = (u32int)(stack), ebp = (u32int)(stack + 1), eip = (u32int)currThreadExitProceed; asm volatile(" \ - cli; \ mov %0, %%ebp; \ mov %1, %%esp; \ mov %2, %%ecx; \ diff --git a/Source/Kernel/TaskManager/Task.wtf.asm b/Source/Kernel/TaskManager/Task.wtf.asm index 2e5b9f8..36c1ade 100644 --- a/Source/Kernel/TaskManager/Task.wtf.asm +++ b/Source/Kernel/TaskManager/Task.wtf.asm @@ -49,16 +49,3 @@ copy_page_physical: ret -[GLOBAL sample_task] -sample_task: - mov eax, 0x00000001 ;temporarily defined as syscall id for writing one char to screen - mov ebx, 'a' ;loopingly write a's to screen - int 64 - mov eax, 0x00000002 ;temporary syscall for sleeping - mov ebx, 20 ;20ms - int 64 - jmp sample_task - int 66 ;finish task - will never happen since we have an infinite loop -[GLOBAL sample_task_size] -sample_task_size: - dd sample_task_size - sample_task diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp index 63d8160..8b4845e 100644 --- a/Source/Kernel/TaskManager/Thread.class.cpp +++ b/Source/Kernel/TaskManager/Thread.class.cpp @@ -75,7 +75,6 @@ Thread::~Thread() { } void Thread::setup(Process* process, thread_entry_t entry_point, void* data, bool isKernel) { - DEBUG("new Thread :: setup"); m_isKernel = isKernel; m_process = process; m_kernelStack.addr = Mem::kalloc(STACKSIZE); diff --git a/Source/Kernel/VTManager/SimpleVT.class.cpp b/Source/Kernel/VTManager/SimpleVT.class.cpp index 89391b2..d304a5f 100644 --- a/Source/Kernel/VTManager/SimpleVT.class.cpp +++ b/Source/Kernel/VTManager/SimpleVT.class.cpp @@ -132,5 +132,5 @@ void SimpleVT::put(WChar c, bool updatecsr) { void SimpleVT::hexDump(u8int *ptr, u32int sz, bool addnl) { if (m_cols < 76) return; //Not enough space - VirtualTerminal::hexDump(ptr, sz, (m_cols == 76)); + VirtualTerminal::hexDump(ptr, sz, (m_cols > 76)); } diff --git a/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp index 59f66a6..b5ed9c3 100644 --- a/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp @@ -28,8 +28,9 @@ keypress_t VirtualTerminal::getKeypress(bool show, bool block) { return keypress_t(); } - while (m_kbdbuff.empty()) + while (m_kbdbuff.empty()) { Task::currThread()->sleep(10); + } m_kbdbuffMutex.waitLock(); keypress_t ret = m_kbdbuff[0]; diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp index 7a9ffa8..0612f1d 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp @@ -2,7 +2,7 @@ #include <DeviceManager/Disp.ns.h> #include <VTManager/VT.ns.h> -VirtualTerminal::VirtualTerminal() : m_kbdMutex(false), m_kbdbuffMutex(false) { +VirtualTerminal::VirtualTerminal() : m_kbdMutex(false), m_kbdbuffMutex(false), m_kbdbuff() { } VirtualTerminal::~VirtualTerminal() { |