summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/proc/process.c
blob: b10d538778ae8463fa0a5e3bea82ae35745f7a5e (plain) (blame)
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
73
74
75
76
77
78
79
80
81
82
83
#include "process.h"
#include "hal/memory.h"
#include "proc/process.h"
#include "arch/x86_64/hal/obj.h"
#include "arch/x86_64/hal/smp.h"
#include "arch/x86_64/hal/paging.h"
#include "hal/obj.h"
#include "hal/smp.h"
#include "lib/string.h"
#include "proc/init.h"
#include "jove.h"
#include "proc/scheduler.h"

PAGEALIGN uint8_t s_init_iopb[0x2000];
PAGEALIGN char _init_pcb_bytes[0x1000] = { 0 };

int
_pcb_new_arch(pcb_t *pcb)
{
    return 0;
}

void
processing_setup(void (*process_main))
{
    jove_owned_obj_t *init_pcb_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_PCB_I);
    obj_settype(init_pcb_obj, JOVE_OBJ_PCB);
    obj_setvalue(init_pcb_obj, phys_fromvirt((uintptr_t)&_init_pcb_bytes));
    
    pcb_new(init_pcb_obj, sizeof(_init_pcb_bytes), _rootdir_obj);

    jove_owned_obj_t *iopb_obj = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_IOPB_I);
    obj_settype(iopb_obj, JOVE_OBJ_IOPB);
    obj_setvalue(iopb_obj, (uintptr_t)s_init_iopb);

    memset(s_init_iopb, 0xFF, 0x2000);
    pcb_t *init_pcb = obj_deref(init_pcb_obj);

    init_pcb->iopb = obj_release(iopb_obj);

    scheduler_init(init_pcb_obj, process_main);
}

inline physaddr_t 
pcb_get_syscall_stack(pcb_t *pcb)
{
    return pcb->syscall_page.pfn << 12;
}

inline physaddr_t 
pcb_get_interrupt_stack(pcb_t *pcb)
{
    return pcb->interrupt_page.pfn << 12;
}

physaddr_t 
pcb_set_syscall_stack(pcb_t *pcb, physaddr_t page)
{
    physaddr_t old_page = pcb_get_syscall_stack(pcb);
    pcb->syscall_page.pfn = page >> 12;
    pcb->syscall_page.p = 1;
    pcb->syscall_page.rw = 1;
    return old_page;
}
physaddr_t 
pcb_set_interrupt_stack(pcb_t *pcb, physaddr_t page)
{
    physaddr_t old_page = pcb_get_interrupt_stack(pcb);
    pcb->interrupt_page.pfn = page >> 12;
    pcb->interrupt_page.p = 1;
    pcb->interrupt_page.rw = 1;
    return old_page;
}

inline void pcb_map_syscall_stack(pcb_t *pcb)
{
    *__syscall_stack_mapping = pcb->syscall_page.value;
}

inline void pcb_map_interrupt_stack(pcb_t *pcb)
{
    *__interrupt_stack_mapping = pcb->interrupt_page.value;
}