blob: 3befefdfda4a1de68965631df47367e67d56b264 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include "usermode.h"
#include "syscalls.h"
#include "kmalloc.h"
#include "asm/syscall.h"
#include "asm/usermode.h"
#include "kernel.h"
#include <stddef.h>
//https://wiki.osdev.org/Task_State_Segment
tss_struct sys_tss; //Define the TSS as a global structure
static volatile uint32_t c1;
static volatile uint32_t c2;
void install_tss(uint32_t esp0){
// now fill each value
// set values necessary
sys_tss.ss0 = 0x10; //kernel data
sys_tss.esp0 = esp0;
// now set the IO bitmap (not necessary, so set above limit)
// sys_tss.iomap = ( unsigned short ) sizeof( tss_struct );
}
void initfunc()
{
while(1)
{
c2++;
}
}
void userfunc()
{
// we need enable here again (since the pushed eflags have it disabled)!
x86_sti();
// if we are pid 0, replace ourselves with /bin/init and enter via usermode
if(task_get_current_pid()==0)
{
uint32_t alloc;
uint32_t entry_global=load_elf(BIN_INIT,&alloc);
task_set_brk(alloc);
usermode(entry_global);
}
// kernel worker thread: SLEEPER
if(task_get_current_pid()==1)
{
while(1)
{
__asm__("hlt");
}
}
// kernel worker thread: SYSCALL CHECKER
if(task_get_current_pid()==2)
{
while(1)
{
task_syscall_worker();
}
}
}
|