

When system/init launched, the init goes into user mode. system/init calls the system call fork. Then either the child breaks down or works correctly. In 3, the fork is called again.
Code:
void switch_to_user_mode(uintptr_t location)
{
asm volatile("sti");
set_kernel_stack(current_task->kernel_stack);
asm volatile( "mov $0x23, %%ax\n"
"mov %%ax, %%ds\n"
"mov %%ax, %%es\n"
"mov %%ax, %%fs\n"
"mov %%ax, %%gs\n"
"mov %%esp, %%eax\n"
"pushl $0x23\n"
"pushl %%eax\n"
"pushf\n"
"popl %%eax\n"
"orl $0x200, %%eax\n"
"pushl %%eax\n"
"pushl $0x1B\n"
"pushl %0\n"
"iret\n"
: : "m"(location));
}