summaryrefslogtreecommitdiff
path: root/kernel/usermode.c
blob: 7153e29909af3fdfab4e7d637ffd6d8397773430 (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
#include "usermode.h"

#include "syscalls.h"
#include "kmalloc.h"

#include "asm/usermode.h"
#include "kernel.h"

#include <stddef.h>

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 usermode
    if(task_get_current_pid()==0)
    {
	    uint32_t alloc;
	    uint32_t entry_global=load_elf(BIN_INIT,&alloc);
	    task_set_brk(alloc);
	    asm_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)
    {
        task_syscall_worker();
    }
}