feat: kprintf now goes into dedicated pseudo-dev rather than flooding the framebuffer
[lunaix-os.git] / lunaix-os / arch / i386 / proc.c
1 #include <lunaix/process.h>
2
3 #include <sys/mm/mempart.h>
4 #include <sys/x86_isa.h>
5
6 volatile struct x86_tss _tss = { .link = 0,
7                                  .esp0 = KERNEL_STACK_END,
8                                  .ss0 = KDATA_SEG };
9
10 void
11 proc_init_transfer(struct proc_info* proc,
12                    ptr_t stack_top,
13                    ptr_t target,
14                    int flags)
15 {
16     struct exec_param* execp =
17       (struct exec_param*)(stack_top - sizeof(struct exec_param));
18     isr_param* isrp = (isr_param*)((ptr_t)execp - sizeof(isr_param));
19
20     *execp = (struct exec_param){
21         .cs = KCODE_SEG, .ss = KDATA_SEG, .eip = target, .eflags = cpu_ldstate()
22     };
23
24     *isrp = (isr_param){ .registers = { .ds = KDATA_SEG,
25                                         .es = KDATA_SEG,
26                                         .fs = KDATA_SEG,
27                                         .gs = KDATA_SEG },
28                          .execp = execp };
29
30     if ((flags & TRANSFER_IE)) {
31         execp->eflags |= 0x200;
32     }
33
34     proc->intr_ctx = isrp;
35 }