diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-17 16:40:56 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-17 16:40:56 +0200 |
commit | 9520a1a101b264abe700c3f7753f5f55bba4c681 (patch) | |
tree | 2d73552c689c4de39b28c0e9930bc135b199a273 /Source/Kernel | |
parent | 45fcf4cc7ddacd93df2dd4d88ad31f6061e8d4a8 (diff) | |
download | Melon-9520a1a101b264abe700c3f7753f5f55bba4c681.tar.gz Melon-9520a1a101b264abe700c3f7753f5f55bba4c681.zip |
Each thread now has a kernel stack and an user stack
Diffstat (limited to 'Source/Kernel')
-rw-r--r-- | Source/Kernel/Makefile | 2 | ||||
-rw-r--r-- | Source/Kernel/MemoryManager/GDT.ns.cpp | 6 | ||||
-rw-r--r-- | Source/Kernel/TaskManager/Process.class.cpp | 4 | ||||
-rw-r--r-- | Source/Kernel/TaskManager/Thread.class.cpp | 37 | ||||
-rw-r--r-- | Source/Kernel/TaskManager/Thread.class.h | 8 | ||||
-rw-r--r-- | Source/Kernel/VFS/VFS.ns.h | 2 |
6 files changed, 36 insertions, 23 deletions
diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile index 56754d0..118ea29 100644 --- a/Source/Kernel/Makefile +++ b/Source/Kernel/Makefile @@ -5,7 +5,7 @@ CXX = g++ LD = ld LDFLAGS = -T Link.ld -Map Map.txt --oformat=elf32-i386 CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra -Werror -I . -CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I . -Wall -Werror -Wno-write-strings -funsigned-char -D THIS_IS_MELON -D RANDOM_SEED=1`date +%N`LL +CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I . -Wall -Werror -Wno-write-strings -funsigned-char -D THIS_IS_MELON -D RANDOM_SEED=1`date +%N`LL -g ASM = nasm ASMFLAGS = -f elf diff --git a/Source/Kernel/MemoryManager/GDT.ns.cpp b/Source/Kernel/MemoryManager/GDT.ns.cpp index 4fb9803..0bb606d 100644 --- a/Source/Kernel/MemoryManager/GDT.ns.cpp +++ b/Source/Kernel/MemoryManager/GDT.ns.cpp @@ -2,9 +2,11 @@ extern "C" void gdt_flush(u32int); +#define GDT_ENTRIES 6 + namespace GDT { -gdt_entry_t gdt_entries[5]; +gdt_entry_t gdt_entries[GDT_ENTRIES]; gdt_ptr_t gdt_ptr; void setGate(s32int num, u32int base, u32int limit, u8int access, u8int gran) { @@ -19,7 +21,7 @@ void setGate(s32int num, u32int base, u32int limit, u8int access, u8int gran) { } void init() { - gdt_ptr.limit = (sizeof(gdt_entry_t) * 5) - 1; + gdt_ptr.limit = (sizeof(gdt_entry_t) * GDT_ENTRIES) - 1; gdt_ptr.base = (u32int)&gdt_entries; setGate(0, 0, 0, 0, 0); //Null segment diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp index d7fba80..cf8f00a 100644 --- a/Source/Kernel/TaskManager/Process.class.cpp +++ b/Source/Kernel/TaskManager/Process.class.cpp @@ -25,7 +25,8 @@ Process* Process::createKernel(String cmdline, VirtualTerminal *vt) { t->m_process = p; t->m_state = T_RUNNING; t->m_isKernel = true; - t->m_kernelStackFrame = 0; + t->m_kernelStack.addr = 0; + t->m_kernelStack.size = 0; p->registerThread(t); Task::registerProcess(p); @@ -43,6 +44,7 @@ Process::Process(String cmdline, u32int uid) { m_vt = Task::currProcess()->getVirtualTerminal(); //Create page directory and user heap m_pagedir = new PageDirectory(kernelPageDirectory); + m_pagedir->switchTo(); m_userHeap = new Heap(); u32int heapIdxSize = PhysMem::total() * 16 + 0x10000; m_userHeap->create(USERHEAPSTART, USERHEAPINITSIZE + heapIdxSize, heapIdxSize, m_pagedir, true, true); diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp index 20d6cd4..6d62474 100644 --- a/Source/Kernel/TaskManager/Thread.class.cpp +++ b/Source/Kernel/TaskManager/Thread.class.cpp @@ -14,35 +14,40 @@ Thread::Thread() { //Private constructor, does nothing Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) { if (iskernel) { - m_isKernel = true; - u32int tmp; - m_kernelStackFrame = (u32int)PageAlloc::alloc(&tmp); - m_process = Task::getKernelProcess(); - setup(entry_point, data, m_kernelStackFrame + 0x1000); //A kernel stack always is 1 frame, meaning 0x1000 bytes + setup(Task::getKernelProcess(), entry_point, data, true); } else { - m_isKernel = false; - m_process = Task::currProcess(); - setup(entry_point, data, (u32int)(m_process->heap().alloc(STACKSIZE)) + STACKSIZE); + setup(Task::currProcess(), entry_point, data, false); } } Thread::Thread(Process* process, thread_entry_t entry_point, void* data) { - m_isKernel = false; - m_process = process; - setup(entry_point, data, (u32int)(m_process->heap().alloc(STACKSIZE)) + STACKSIZE); + setup(process, entry_point, data, false); } Thread::~Thread() { Task::unregisterThread(this); - if (m_isKernel) { - PageAlloc::free((void*)m_kernelStackFrame); - } + Mem::kfree(m_kernelStack.addr); + if (!m_isKernel) m_process->heap().free(m_userStack.addr); //Don't unregister thread in process, it has probably already been done } -void Thread::setup(thread_entry_t entry_point, void* data, u32int esp) { +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); + m_kernelStack.size = STACKSIZE; + + if (m_isKernel) { + m_userStack.size = 0; + m_userStack.addr = 0; + } else { + m_userStack.addr = m_process->heap().alloc(STACKSIZE); + m_userStack.size = STACKSIZE; + } + u32int* stack = (u32int*)((u32int)(m_kernelStack.addr) + m_kernelStack.size); + //Pass function parameters for runThread() - u32int *stack = (u32int*)esp; stack--; *stack = (u32int)entry_point; //Push entry point (function parameter) stack--; diff --git a/Source/Kernel/TaskManager/Thread.class.h b/Source/Kernel/TaskManager/Thread.class.h index 369f62f..9c8fa26 100644 --- a/Source/Kernel/TaskManager/Thread.class.h +++ b/Source/Kernel/TaskManager/Thread.class.h @@ -13,6 +13,7 @@ typedef u32int(*thread_entry_t)(void*); class Thread { friend class Process; //This might be useful + friend void runThread(Thread*, void*, thread_entry_t); private: Thread(); //Creates a thread without initializing anything. Used by Process::createKernel(); @@ -27,9 +28,12 @@ class Thread { } waitfor; bool m_isKernel; //Says if stack is in kernel pagedir, and if thread should run in ring 0 - u32int m_kernelStackFrame; //Used for allocating and freeing a frame used as a stack + struct { + void* addr; + u32int size; + } m_userStack, m_kernelStack; - void setup(thread_entry_t entry_point, void* data, u32int esp); //Sets up stack, called by both constructors + void setup(Process* process, thread_entry_t entry_point, void* data, bool isKernel); public: Thread(thread_entry_t entry_point, void* data, bool iskernel = false); //Assumes process is current process, or is kprocess if isk diff --git a/Source/Kernel/VFS/VFS.ns.h b/Source/Kernel/VFS/VFS.ns.h index 1021d7c..94ddad9 100644 --- a/Source/Kernel/VFS/VFS.ns.h +++ b/Source/Kernel/VFS/VFS.ns.h @@ -8,7 +8,7 @@ typedef FileSystem* (* mountcallback)(Partition* partition); namespace VFS { void registerMountCallback(mountcallback mcb); - bool mount(Partition* partition, DirectoryNode mountpoint); + bool mount(Partition* partition, DirectoryNode *mountpoint); bool setRootNode(DirectoryNode* root); DirectoryNode* getRootNode(); |