[UPDATE]
So now it works, sort of...
What's weird is that:
I have ubuntu linux 64 bit, and if I test it in virtualbox or qemu, I get general protection fault.
My friend also has ubuntu linux and it works for him on bochs, qemu and virtualbox.
What I'm doing now:
in kernel main:
- I load the 2 processes and add them to the list
- I call scheduler_install
In scheduler_install:
- I set the switch_task as the callback for the PIT
- I do this:
Code: Select all
while (true)
{
if (need_switch)
{
process_execute(current_process);
need_switch = false;
}
}
need_switch is set by the switch_task.
My switch_task:
Code: Select all
void switch_task(regs_t * regs)
{
// Copy if usermode
if (regs->cs == 0x1b)
memcpy(¤t_process->frame, regs, sizeof(regs_t));
if (current_process->next_proc == NULL)
{
need_switch = true;
}
else
{
current_process = current_process->next_proc;
}
// Set regs
memcpy(regs, ¤t_thread->frame, sizeof(regs_t));
}
And finally my process_execute:
Code: Select all
void process_execute(process_t * process)
{
int entry_point = process->main_thread->frame.eip;
unsigned int proc_stack = process->main_thread->frame.esp;
cli();
int stack = 0;
__asm__ __volatile__("movl %%esp, %0" : "=r"(stack));
tss_set_stack(0x10, stack);
__asm__ __volatile__(
".intel_syntax noprefix\n"
"mov ax, 0x23\n"
"mov ds, ax\n"
"mov es, ax\n"
"mov fs, ax\n"
"mov gs, ax\n"
"push 0x23\n"
"push %0\n"
"push 0x200\n"
"push 0x1b\n"
"push %1\n"
"iretd\n"
".att_syntax\n"
:
: "r"(proc_stack), "r"(entry_point)
: "ax"
);
}
So I get General Protection fault error code: 44488 and my friend does not. Also I'm sure that this task switching design has a lot of bleeding edges, please tell me if you see one.
Edit: nevermind, it works, I was stupid...