1 #ifdef CONFIG_ARCH_I386
3 #include <lunaix/process.h>
4 #include <lunaix/hart_state.h>
5 #include <lunaix/mm/vmm.h>
6 #include <klibc/string.h>
8 #include <asm/mempart.h>
11 volatile struct x86_tss _tss = { .link = 0,
16 hart_prepare_transition(struct hart_transition* ht,
17 ptr_t kstack_tp, ptr_t ustack_pt,
18 ptr_t entry, bool to_user)
20 ptr_t offset = (ptr_t)&ht->transfer.eret - (ptr_t)&ht->transfer;
21 ht->inject = align_stack(kstack_tp - sizeof(ht->transfer));
23 ht->transfer.state = (struct hart_state){
30 .execp = (struct exec_param*)(ht->inject + offset)
33 int code_seg = KCODE_SEG, data_seg = KDATA_SEG;
34 int mstate = cpu_ldstate();
36 code_seg = UCODE_SEG, data_seg = UDATA_SEG;
37 mstate |= 0x200; // enable interrupt
40 ht->transfer.eret = (struct exec_param) {
41 .cs = code_seg, .eip = entry,
42 .ss = data_seg, .esp = align_stack(ustack_pt),