Thanks for the reply!
By TSS, I meant the usage as here for software multitasking:
https://wiki.osdev.org/Task_State_SegmentIn my kernel, tasks are handled this way:
- A task is created and added into runq
--- task struct contains a frame
- It is scheduled by calling sched_yield
--- In this function a task's page table is loaded
--- Task's register state is popped by IRETQ
--- For now I'll not mention the other small things as status and run count and etc...
- On exit, a task interrupts and goes into kernel where kernel state is popped and kills the task by freeing and doing its thing.
When a userland task does a syscall, it can switch to kernel data segment, thus it can preserve its register state.
In my case, I can't find a way to save the register state because I am already running in ring 0, so I am already using kernel data segment with a private stack for the thread.
I can get the cpu core's stack by using `swapgs` instruction, otherwise I can't find a way to accomplish this. However, I couldn't go pass general protection faults when I try to swap back.
I guess basically I am lost on how to save a ring 0 task's register state and where to. I hope it is more clear now.
My use case is simply this:
Code:
void kthread_swap() {
page = get_page();
swap_disk_write();
if disk_idle: // If it is not done
sched_yield(); // So it does not block
else:
continue;
}