Skip to content

Commit 233ccfc

Browse files
committed
😧
1 parent 2528166 commit 233ccfc

File tree

8 files changed

+78
-33
lines changed

8 files changed

+78
-33
lines changed

kevos/include/arch/x86/x64/process.h

+2-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
#define _KEVOS_ARCH_X86_X64_PROCESS_H_
1818

1919
#include <sys/types.h>
20+
#include <kernel/multitask/process.h>
2021
#include <arch/x86/x64/vm.h>
2122

2223
#include <list>
@@ -57,20 +58,6 @@ struct ProcessRegisters
5758
uint32_t fpu[28];
5859
};
5960

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-
7461

7562
class ProcessManager
7663
{
@@ -83,7 +70,7 @@ class ProcessManager
8370

8471
static void setInstructionPointer(Process* process,void* entry)
8572
{
86-
process->registers()->rip=(uint64_t)entry;
73+
process->getRegisters<ProcessRegisters*>()->rip=(uint64_t)entry;
8774
}
8875

8976
static void setVirtualMemory(Process* process,const mm::vm::VirtualMemory& mm);
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

kevos/include/kernel/scheduler.h kevos/include/kernel/multitask/scheduler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

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_
1818

1919
#include <sys/types.h>
2020

kevos/include/kernel/process.h kevos/include/kernel/multitask/spinlock.h

+6-10
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

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_
1818

19-
#include <sys/types.h>
20-
21-
namespace multitask
19+
namespace multitask::lock
2220
{
2321

24-
class Process
22+
class SpinLock
2523
{
2624
public:
27-
enum TYPE{KERNEL,USER};
28-
private:
29-
25+
3026
};
3127

32-
} // end of namespace kernel
28+
}
3329

3430
#endif

kevos/include/sys/types.h

+4
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ limitations under the License.
2323
#include <arch/x86/x64/types.h>
2424
#endif
2525

26+
#include <cstddef>
27+
28+
using pid_t=std::size_t;
29+
2630
#endif

kevos/src/arch/x86/x64/interrupt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ limitations under the License.
2323

2424
void saveProcessRegisters(char* base)
2525
{
26-
auto regs=multitask::ProcessManager::current()->registers();
26+
auto regs=multitask::ProcessManager::current()->getRegisters<multitask::ProcessRegisters*>();
2727
auto ssregs=reinterpret_cast<intr::SoftwareSavedRegisters*>(base);
2828
regs->rax=ssregs->rax;
2929
regs->rbx=ssregs->rbx;
@@ -52,7 +52,7 @@ void saveProcessRegisters(char* base)
5252

5353
void switchToContext()
5454
{
55-
auto regs=multitask::ProcessManager::current()->registers();
55+
auto regs=multitask::ProcessManager::current()->getRegisters<multitask::ProcessRegisters*>();
5656
// TSS::tss.rsp0=regs->rsp;
5757
__asm__ ("movq %[cr3],%%cr3" : : [cr3]"r"(regs->cr3));
5858
__asm__ ("pushq %[ss]" : : [ss]"m"(regs->ss));

kevos/src/arch/x86/x64/process.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ limitations under the License.
2525
namespace multitask
2626
{
2727

28-
Process::Process(void* entry,void* stack,uint64_t userProcess)
28+
Process::Process(void* entry,void* stack,bool userProcess)
2929
{
3030
if(userProcess)
31-
m_regs=ProcessManager::createUserRegInfo(entry,stack,0);
31+
regs=(void*)ProcessManager::createUserRegInfo(entry,stack,0);
3232
else
33-
m_regs=ProcessManager::createKernelRegInfo(entry,stack);
33+
regs=(void*)ProcessManager::createKernelRegInfo(entry,stack);
34+
pid=generateNextPid();
3435
}
3536

3637
std::list<Process*> ProcessManager::s_processes(nullptr);

kevos/src/kernel/scheduler.cpp kevos/src/kernel/multitask/scheduler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
#include <kernel/scheduler.h>
16+
#include <kernel/multitask/scheduler.h>
1717

1818

0 commit comments

Comments
 (0)