Commit 233ccfc 1 parent 2528166 commit 233ccfc Copy full SHA for 233ccfc
File tree 8 files changed +78
-33
lines changed
8 files changed +78
-33
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ limitations under the License.
17
17
#define _KEVOS_ARCH_X86_X64_PROCESS_H_
18
18
19
19
#include < sys/types.h>
20
+ #include < kernel/multitask/process.h>
20
21
#include < arch/x86/x64/vm.h>
21
22
22
23
#include < list>
@@ -57,20 +58,6 @@ struct ProcessRegisters
57
58
uint32_t fpu[28 ];
58
59
};
59
60
60
- class Process
61
- {
62
- public:
63
- Process (void * entry,void * stack,uint64_t userProcess);
64
-
65
- ProcessRegisters* registers ()
66
- {
67
- return m_regs;
68
- }
69
-
70
- private:
71
- ProcessRegisters* m_regs;
72
- };
73
-
74
61
75
62
class ProcessManager
76
63
{
@@ -83,7 +70,7 @@ class ProcessManager
83
70
84
71
static void setInstructionPointer (Process* process,void * entry)
85
72
{
86
- process->registers ()->rip =(uint64_t )entry;
73
+ process->getRegisters <ProcessRegisters*> ()->rip =(uint64_t )entry;
87
74
}
88
75
89
76
static void setVirtualMemory (Process* process,const mm::vm::VirtualMemory& mm);
Original file line number Diff line number Diff line change
1
+ /* Copyright 2018 kevin Lau (http://github.com/stormycatcat)
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #ifndef _KEVOS_KERNEL_MULTITASK_PROCESS_H_
17
+ #define _KEVOS_KERNEL_MULTITASK_PROCESS_H_
18
+
19
+ #include < sys/types.h>
20
+
21
+ namespace multitask
22
+ {
23
+
24
+ inline pid_t generateNextPid ()
25
+ {
26
+ static pid_t cache=0 ;
27
+ return cache++;
28
+ }
29
+
30
+ class Process
31
+ {
32
+ public:
33
+ enum TYPE{KERNEL,USER};
34
+ enum STATE{RUNNING,WAITING,DEAD,READY};
35
+
36
+ Process (void * entry,void * stack,bool userProcess);
37
+
38
+ template <class T >
39
+ T getRegisters ()
40
+ {
41
+ return (T)regs;
42
+ }
43
+
44
+ void setState (STATE s){state=s;}
45
+
46
+ private:
47
+ pid_t pid;
48
+ TYPE type;
49
+ STATE state;
50
+ void * regs;
51
+ void * entry;
52
+ void * stack;
53
+ };
54
+
55
+ } // end of namespace kernel
56
+
57
+ #endif
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
==============================================================================*/
15
15
16
- #ifndef _KEVOS_KERNEL_SCHEDULER_H_
17
- #define _KEVOS_KERNEL_SCHEDULER_H_
16
+ #ifndef _KEVOS_KERNEL_MULTITASK_SCHEDULER_H_
17
+ #define _KEVOS_KERNEL_MULTITASK_SCHEDULER_H_
18
18
19
19
#include < sys/types.h>
20
20
Original file line number Diff line number Diff line change @@ -13,22 +13,18 @@ See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
==============================================================================*/
15
15
16
- #ifndef _KEVOS_KERNEL_PROCESS_H_
17
- #define _KEVOS_KERNEL_PROCESS_H_
16
+ #ifndef _KEVOS_KERNEL_MULTITASK_SPINLOCK_H_
17
+ #define _KEVOS_KERNEL_MULTITASK_SPINLOCK_H_
18
18
19
- #include < sys/types.h>
20
-
21
- namespace multitask
19
+ namespace multitask ::lock
22
20
{
23
21
24
- class Process
22
+ class SpinLock
25
23
{
26
24
public:
27
- enum TYPE{KERNEL,USER};
28
- private:
29
-
25
+
30
26
};
31
27
32
- } // end of namespace kernel
28
+ }
33
29
34
30
#endif
Original file line number Diff line number Diff line change @@ -23,4 +23,8 @@ limitations under the License.
23
23
#include < arch/x86/x64/types.h>
24
24
#endif
25
25
26
+ #include < cstddef>
27
+
28
+ using pid_t =std::size_t ;
29
+
26
30
#endif
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ limitations under the License.
23
23
24
24
void saveProcessRegisters (char * base)
25
25
{
26
- auto regs=multitask::ProcessManager::current ()->registers ();
26
+ auto regs=multitask::ProcessManager::current ()->getRegisters <multitask::ProcessRegisters*> ();
27
27
auto ssregs=reinterpret_cast <intr::SoftwareSavedRegisters*>(base);
28
28
regs->rax =ssregs->rax ;
29
29
regs->rbx =ssregs->rbx ;
@@ -52,7 +52,7 @@ void saveProcessRegisters(char* base)
52
52
53
53
void switchToContext ()
54
54
{
55
- auto regs=multitask::ProcessManager::current ()->registers ();
55
+ auto regs=multitask::ProcessManager::current ()->getRegisters <multitask::ProcessRegisters*> ();
56
56
// TSS::tss.rsp0=regs->rsp;
57
57
__asm__ (" movq %[cr3],%%cr3" : : [cr3]" r" (regs->cr3 ));
58
58
__asm__ (" pushq %[ss]" : : [ss]" m" (regs->ss ));
Original file line number Diff line number Diff line change @@ -25,12 +25,13 @@ limitations under the License.
25
25
namespace multitask
26
26
{
27
27
28
- Process::Process (void * entry,void * stack,uint64_t userProcess)
28
+ Process::Process (void * entry,void * stack,bool userProcess)
29
29
{
30
30
if (userProcess)
31
- m_regs= ProcessManager::createUserRegInfo (entry,stack,0 );
31
+ regs=( void *) ProcessManager::createUserRegInfo (entry,stack,0 );
32
32
else
33
- m_regs=ProcessManager::createKernelRegInfo (entry,stack);
33
+ regs=(void *)ProcessManager::createKernelRegInfo (entry,stack);
34
+ pid=generateNextPid ();
34
35
}
35
36
36
37
std::list<Process*> ProcessManager::s_processes (nullptr );
Original file line number Diff line number Diff line change @@ -13,6 +13,6 @@ See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
==============================================================================*/
15
15
16
- #include < kernel/scheduler.h>
16
+ #include < kernel/multitask/ scheduler.h>
17
17
18
18
You can’t perform that action at this time.
0 commit comments