summaryrefslogtreecommitdiff
path: root/kernel/usermode.c
blob: 2455ba6fd1a8d16b9364e6cab317f3b5250113e0 (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
#define FOOLOS_MODULE_NAME "usermode"
#include "usermode.h"

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

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

#include "lib/logger/log.h"

#include <stddef.h>

//https://wiki.osdev.org/Task_State_Segment
tss_struct sys_tss; //Define the TSS as a global structure

void install_tss(int cpu_no){

    // now fill each value
    // set values necessary
    sys_tss.ss0 = 0x10;            //kernel data
    sys_tss.esp0 = kballoc(4);

    // now set the IO bitmap (not necessary, so set above limit)       
    // sys_tss.iomap = ( unsigned short ) sizeof( tss_struct ); 
}

// THIS IS THE FUNCTION TO BE RUN IN RING 3 // USER MODE
static void userfunc()
{
    syscall(SYSCALL_EXECVE,BIN_INIT,NULL,NULL); 
    while(1); // we should never get here.
}

void switch_to_user_mode() 
{
    usermode(&userfunc); 
}