! Fixed the root Makefile
[lightOS.git] / kernel / x86 / thread.cpp
blob0270e3a5a58a326c3a4db890b6770e3cc3512f33
1 /*
2 lightOS kernel
3 Copyright (C) 2006-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <cstring>
20 #include <kernel/thread.hpp>
21 #include <kernel/scheduler.hpp>
22 using namespace std;
23 using namespace kernel;
25 thread::thread( process &Process,
26 uintptr_t entryPoint,
27 void *stack,
28 size_t stacksize,
29 size_t param1,
30 size_t param2,
31 libkernel::thread_id_t id)
32 : tid(id), Process(Process), threadStack(stack), threadStackSize(stacksize), State(run), mFpuState(0), mFpuState2(0)
34 mCpuState.eax = param1;
35 mCpuState.ebx = param2;
36 mCpuState.ecx = 0;
37 mCpuState.edx = 0;
38 mCpuState.edi = 0;
39 mCpuState.esi = 0;
40 mCpuState.ebp = 0;
41 mCpuState.esp = reinterpret_cast<uint32_t>(stack);
42 mCpuState.eflags = 0x202;
43 mCpuState.eip = entryPoint;
45 void thread::grantIOAccess()
47 mCpuState.eflags |= 0x3000;
49 void thread::unblock( libkernel::port_id_t port,
50 libkernel::port_id_t source,
51 size_t param1,
52 size_t param2,
53 size_t param3,
54 size_t param4)
56 mCpuState.eax = port;
57 mCpuState.ebx = source;
58 mCpuState.ecx = param1;
59 mCpuState.edx = param2;
60 mCpuState.esi = param3;
61 mCpuState.edi = param4;
63 unblock();
65 void thread::set_cpu_state(interrupt_stackframe &frame)
67 mCpuState.eax = frame.eax;
68 mCpuState.ebx = frame.ebx;
69 mCpuState.ecx = frame.ecx;
70 mCpuState.edx = frame.edx;
71 mCpuState.edi = frame.edi;
72 mCpuState.esi = frame.esi;
73 mCpuState.ebp = frame.ebp;
74 mCpuState.esp = frame.esp;
75 mCpuState.eip = frame.eip;
76 mCpuState.eflags = frame.eflags;