refactor: decouple i386 specific instruction invocation
[lunaix-os.git] / lunaix-os / kernel / asm / i386 / proc.c
1 #include <lunaix/process.h>
2
3 void
4 proc_init_transfer(struct proc_info* proc,
5                    ptr_t stack_top,
6                    ptr_t target,
7                    int flags)
8 {
9     struct exec_param* execp =
10       (struct exec_param*)(stack_top - sizeof(struct exec_param));
11     isr_param* isrp = (isr_param*)((ptr_t)execp - sizeof(isr_param));
12
13     *execp = (struct exec_param){
14         .cs = KCODE_SEG, .ss = KDATA_SEG, .eip = target, .eflags = cpu_ldstate()
15     };
16
17     *isrp = (isr_param){ .registers = { .ds = KDATA_SEG,
18                                         .es = KDATA_SEG,
19                                         .fs = KDATA_SEG,
20                                         .gs = KDATA_SEG },
21                          .execp = execp };
22
23     if ((flags & TRANSFER_IE)) {
24         execp->eflags |= 0x200;
25     }
26
27     proc->intr_ctx = isrp;
28 }